distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
RawMessageQueue.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_RAWMESSAGEQUEUE_HPP_
13 #define INCLUDE_DISTORTOS_RAWMESSAGEQUEUE_HPP_
14 
16 
17 namespace distortos
18 {
19 
34 {
35 public:
36 
39 
42 
49  template<typename T>
51 
54 
66  RawMessageQueue(EntryStorageUniquePointer&& entryStorageUniquePointer,
67  ValueStorageUniquePointer&& valueStorageUniquePointer, size_t elementSize, size_t maxElements);
68 
73  size_t getCapacity() const
74  {
76  }
77 
82  size_t getElementSize() const
83  {
84  return elementSize_;
85  }
86 
105  int pop(uint8_t& priority, void* buffer, size_t size);
106 
125  template<typename T>
126  int pop(uint8_t& priority, T& buffer)
127  {
128  return pop(priority, &buffer, sizeof(buffer));
129  }
130 
148  int push(uint8_t priority, const void* data, size_t size);
149 
168  template<typename T>
169  int push(const uint8_t priority, const T& data)
170  {
171  return push(priority, &data, sizeof(data));
172  }
173 
190  int tryPop(uint8_t& priority, void* buffer, size_t size);
191 
208  template<typename T>
209  int tryPop(uint8_t& priority, T& buffer)
210  {
211  return tryPop(priority, &buffer, sizeof(buffer));
212  }
213 
233  int tryPopFor(TickClock::duration duration, uint8_t& priority, void* buffer, size_t size);
234 
257  template<typename Rep, typename Period>
258  int tryPopFor(const std::chrono::duration<Rep, Period> duration, uint8_t& priority, void* const buffer,
259  const size_t size)
260  {
261  return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), priority, buffer, size);
262  }
263 
285  template<typename Rep, typename Period, typename T>
286  int tryPopFor(const std::chrono::duration<Rep, Period> duration, uint8_t& priority, T& buffer)
287  {
288  return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), priority, &buffer, sizeof(buffer));
289  }
290 
310  int tryPopUntil(TickClock::time_point timePoint, uint8_t& priority, void* buffer, size_t size);
311 
333  template<typename Duration>
334  int tryPopUntil(const std::chrono::time_point<TickClock, Duration> timePoint, uint8_t& priority, void* const buffer,
335  const size_t size)
336  {
337  return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), priority, buffer, size);
338  }
339 
360  template<typename Duration, typename T>
361  int tryPopUntil(const std::chrono::time_point<TickClock, Duration> timePoint, uint8_t& priority, T& buffer)
362  {
363  return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), priority, &buffer,
364  sizeof(buffer));
365  }
366 
382  int tryPush(uint8_t priority, const void* data, size_t size);
383 
400  template<typename T>
401  int tryPush(const uint8_t priority, const T& data)
402  {
403  return tryPush(priority, &data, sizeof(data));
404  }
405 
424  int tryPushFor(TickClock::duration duration, uint8_t priority, const void* data, size_t size);
425 
447  template<typename Rep, typename Period>
448  int tryPushFor(const std::chrono::duration<Rep, Period> duration, const uint8_t priority, const void* const data,
449  const size_t size)
450  {
451  return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), priority, data, size);
452  }
453 
475  template<typename Rep, typename Period, typename T>
476  int tryPushFor(const std::chrono::duration<Rep, Period> duration, const uint8_t priority, const T& data)
477  {
478  return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), priority, &data, sizeof(data));
479  }
480 
499  int tryPushUntil(TickClock::time_point timePoint, uint8_t priority, const void* data, size_t size);
500 
521  template<typename Duration>
522  int tryPushUntil(const std::chrono::time_point<TickClock, Duration> timePoint, const uint8_t priority,
523  const void* const data, const size_t size)
524  {
525  return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), priority, data, size);
526  }
527 
548  template<typename Duration, typename T>
549  int tryPushUntil(const std::chrono::time_point<TickClock, Duration> timePoint, const uint8_t priority,
550  const T& data)
551  {
552  return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), priority, &data,
553  sizeof(data));
554  }
555 
556 private:
557 
575  int popInternal(const internal::SemaphoreFunctor& waitSemaphoreFunctor, uint8_t& priority, void* buffer,
576  size_t size);
577 
594  int pushInternal(const internal::SemaphoreFunctor& waitSemaphoreFunctor, uint8_t priority, const void* data,
595  size_t size);
596 
599 
601  const size_t elementSize_;
602 };
603 
604 } // namespace distortos
605 
606 #endif // INCLUDE_DISTORTOS_RAWMESSAGEQUEUE_HPP_
int tryPushUntil(const std::chrono::time_point< TickClock, Duration > timePoint, const uint8_t priority, const void *const data, const size_t size)
Tries to push the element to the queue until a given time point.
Definition: RawMessageQueue.hpp:522
RawMessageQueue(EntryStorageUniquePointer &&entryStorageUniquePointer, ValueStorageUniquePointer &&valueStorageUniquePointer, size_t elementSize, size_t maxElements)
RawMessageQueue's constructor.
Definition: RawMessageQueue.cpp:33
RawMessageQueue class is very similar to MessageQueue, but optimized for binary serializable types (l...
Definition: RawMessageQueue.hpp:33
int tryPopFor(TickClock::duration duration, uint8_t &priority, void *buffer, size_t size)
Tries to pop the oldest element with highest priority from the queue for a given duration of time.
Definition: RawMessageQueue.cpp:64
int tryPushUntil(const std::chrono::time_point< TickClock, Duration > timePoint, const uint8_t priority, const T &data)
Tries to push the element to the queue until a given time point.
Definition: RawMessageQueue.hpp:549
internal::MessageQueueBase::ValueStorageUniquePointer ValueStorageUniquePointer
unique_ptr (with deleter) to storage for value
Definition: RawMessageQueue.hpp:53
internal::MessageQueueBase::EntryStorageUniquePointer EntryStorageUniquePointer
import EntryStorageUniquePointer type from internal::MessageQueueBase class
Definition: RawMessageQueue.hpp:41
MessageQueueBase class implements basic functionality of MessageQueue template class.
Definition: MessageQueueBase.hpp:31
internal::MessageQueueBase::ValueStorage< T > ValueStorage
Definition: RawMessageQueue.hpp:50
size_t getCapacity() const
Definition: MessageQueueBase.hpp:151
int tryPopUntil(const std::chrono::time_point< TickClock, Duration > timePoint, uint8_t &priority, T &buffer)
Tries to pop the oldest element with highest priority from the queue until a given time point.
Definition: RawMessageQueue.hpp:361
int tryPushFor(TickClock::duration duration, uint8_t priority, const void *data, size_t size)
Tries to push the element to the queue for a given duration of time.
Definition: RawMessageQueue.cpp:88
std::chrono::time_point< TickClock > time_point
basic time_point type of clock
Definition: TickClock.hpp:42
int tryPush(const uint8_t priority, const T &data)
Tries to push the element to the queue.
Definition: RawMessageQueue.hpp:401
int tryPopFor(const std::chrono::duration< Rep, Period > duration, uint8_t &priority, T &buffer)
Tries to pop the oldest element with highest priority from the queue for a given duration of time.
Definition: RawMessageQueue.hpp:286
internal::MessageQueueBase messageQueueBase_
contained internal::MessageQueueBase object which implements base functionality
Definition: RawMessageQueue.hpp:598
int tryPush(uint8_t priority, const void *data, size_t size)
Tries to push the element to the queue.
Definition: RawMessageQueue.cpp:82
int tryPop(uint8_t &priority, void *buffer, size_t size)
Tries to pop the oldest element with highest priority from the queue.
Definition: RawMessageQueue.cpp:58
internal::MessageQueueBase::EntryStorage EntryStorage
type of uninitialized storage for Entry with link
Definition: RawMessageQueue.hpp:38
int tryPopUntil(TickClock::time_point timePoint, uint8_t &priority, void *buffer, size_t size)
Tries to pop the oldest element with highest priority from the queue until a given time point.
Definition: RawMessageQueue.cpp:73
size_t getCapacity() const
Definition: RawMessageQueue.hpp:73
int pushInternal(const internal::SemaphoreFunctor &waitSemaphoreFunctor, uint8_t priority, const void *data, size_t size)
Pushes the element to the queue.
Definition: RawMessageQueue.cpp:120
const size_t elementSize_
size of single queue element, bytes
Definition: RawMessageQueue.hpp:601
Top-level namespace of distortos project.
Definition: buttons.hpp:33
int tryPopFor(const std::chrono::duration< Rep, Period > duration, uint8_t &priority, void *const buffer, const size_t size)
Tries to pop the oldest element with highest priority from the queue for a given duration of time.
Definition: RawMessageQueue.hpp:258
int pop(uint8_t &priority, void *buffer, size_t size)
Pops oldest element with highest priority from the queue.
Definition: RawMessageQueue.cpp:42
typename std::aligned_storage< sizeof(T), alignof(T)>::type ValueStorage
Definition: MessageQueueBase.hpp:76
int pop(uint8_t &priority, T &buffer)
Pops oldest element with highest priority from the queue.
Definition: RawMessageQueue.hpp:126
MessageQueueBase class header.
int tryPushFor(const std::chrono::duration< Rep, Period > duration, const uint8_t priority, const T &data)
Tries to push the element to the queue for a given duration of time.
Definition: RawMessageQueue.hpp:476
int push(const uint8_t priority, const T &data)
Pushes the element to the queue.
Definition: RawMessageQueue.hpp:169
int tryPop(uint8_t &priority, T &buffer)
Tries to pop the oldest element with highest priority from the queue.
Definition: RawMessageQueue.hpp:209
SemaphoreFunctor is a type-erased interface for functors which execute some action on semaphore (wait...
Definition: SemaphoreFunctor.hpp:34
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition: TickClock.hpp:39
int tryPopUntil(const std::chrono::time_point< TickClock, Duration > timePoint, uint8_t &priority, void *const buffer, const size_t size)
Tries to pop the oldest element with highest priority from the queue until a given time point.
Definition: RawMessageQueue.hpp:334
std::unique_ptr< EntryStorage[], void(&)(EntryStorage *)> EntryStorageUniquePointer
unique_ptr (with deleter) to EntryStorage[]
Definition: MessageQueueBase.hpp:67
typename std::aligned_storage< sizeof(Entry), alignof(Entry)>::type EntryStorage
type of uninitialized storage for Entry
Definition: MessageQueueBase.hpp:64
int tryPushUntil(TickClock::time_point timePoint, uint8_t priority, const void *data, size_t size)
Tries to push the element to the queue until a given time point.
Definition: RawMessageQueue.cpp:97
int popInternal(const internal::SemaphoreFunctor &waitSemaphoreFunctor, uint8_t &priority, void *buffer, size_t size)
Pops oldest element with highest priority from the queue.
Definition: RawMessageQueue.cpp:110
int push(uint8_t priority, const void *data, size_t size)
Pushes the element to the queue.
Definition: RawMessageQueue.cpp:50
std::unique_ptr< void, void(&)(void *)> ValueStorageUniquePointer
unique_ptr (with deleter) to storage
Definition: MessageQueueBase.hpp:79
int tryPushFor(const std::chrono::duration< Rep, Period > duration, const uint8_t priority, const void *const data, const size_t size)
Tries to push the element to the queue for a given duration of time.
Definition: RawMessageQueue.hpp:448
size_t getElementSize() const
Definition: RawMessageQueue.hpp:82