distortos  v0.4.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 
52  using ValueStorageUniquePointer = internal::MessageQueueBase::ValueStorageUniquePointer;
53 
65  RawMessageQueue(EntryStorageUniquePointer&& entryStorageUniquePointer,
66  ValueStorageUniquePointer&& valueStorageUniquePointer, size_t elementSize, size_t maxElements);
67 
86  int pop(uint8_t& priority, void* buffer, size_t size);
87 
106  template<typename T>
107  int pop(uint8_t& priority, T& buffer)
108  {
109  return pop(priority, &buffer, sizeof(buffer));
110  }
111 
129  int push(uint8_t priority, const void* data, size_t size);
130 
149  template<typename T>
150  int push(const uint8_t priority, const T& data)
151  {
152  return push(priority, &data, sizeof(data));
153  }
154 
171  int tryPop(uint8_t& priority, void* buffer, size_t size);
172 
189  template<typename T>
190  int tryPop(uint8_t& priority, T& buffer)
191  {
192  return tryPop(priority, &buffer, sizeof(buffer));
193  }
194 
214  int tryPopFor(TickClock::duration duration, uint8_t& priority, void* buffer, size_t size);
215 
238  template<typename Rep, typename Period>
239  int tryPopFor(const std::chrono::duration<Rep, Period> duration, uint8_t& priority, void* const buffer,
240  const size_t size)
241  {
242  return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), priority, buffer, size);
243  }
244 
266  template<typename Rep, typename Period, typename T>
267  int tryPopFor(const std::chrono::duration<Rep, Period> duration, uint8_t& priority, T& buffer)
268  {
269  return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), priority, &buffer, sizeof(buffer));
270  }
271 
291  int tryPopUntil(TickClock::time_point timePoint, uint8_t& priority, void* buffer, size_t size);
292 
314  template<typename Duration>
315  int tryPopUntil(const std::chrono::time_point<TickClock, Duration> timePoint, uint8_t& priority, void* const buffer,
316  const size_t size)
317  {
318  return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), priority, buffer, size);
319  }
320 
341  template<typename Duration, typename T>
342  int tryPopUntil(const std::chrono::time_point<TickClock, Duration> timePoint, uint8_t& priority, T& buffer)
343  {
344  return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), priority, &buffer,
345  sizeof(buffer));
346  }
347 
363  int tryPush(uint8_t priority, const void* data, size_t size);
364 
381  template<typename T>
382  int tryPush(const uint8_t priority, const T& data)
383  {
384  return tryPush(priority, &data, sizeof(data));
385  }
386 
405  int tryPushFor(TickClock::duration duration, uint8_t priority, const void* data, size_t size);
406 
428  template<typename Rep, typename Period>
429  int tryPushFor(const std::chrono::duration<Rep, Period> duration, const uint8_t priority, const void* const data,
430  const size_t size)
431  {
432  return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), priority, data, size);
433  }
434 
456  template<typename Rep, typename Period, typename T>
457  int tryPushFor(const std::chrono::duration<Rep, Period> duration, const uint8_t priority, const T& data)
458  {
459  return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), priority, &data, sizeof(data));
460  }
461 
480  int tryPushUntil(TickClock::time_point timePoint, uint8_t priority, const void* data, size_t size);
481 
502  template<typename Duration>
503  int tryPushUntil(const std::chrono::time_point<TickClock, Duration> timePoint, const uint8_t priority,
504  const void* const data, const size_t size)
505  {
506  return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), priority, data, size);
507  }
508 
529  template<typename Duration, typename T>
530  int tryPushUntil(const std::chrono::time_point<TickClock, Duration> timePoint, const uint8_t priority,
531  const T& data)
532  {
533  return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), priority, &data,
534  sizeof(data));
535  }
536 
537 private:
538 
556  int popInternal(const internal::SemaphoreFunctor& waitSemaphoreFunctor, uint8_t& priority, void* buffer,
557  size_t size);
558 
575  int pushInternal(const internal::SemaphoreFunctor& waitSemaphoreFunctor, uint8_t priority, const void* data,
576  size_t size);
577 
580 
582  const size_t elementSize_;
583 };
584 
585 } // namespace distortos
586 
587 #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:503
RawMessageQueue(EntryStorageUniquePointer &&entryStorageUniquePointer, ValueStorageUniquePointer &&valueStorageUniquePointer, size_t elementSize, size_t maxElements)
RawMessageQueue&#39;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:530
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
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:342
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:382
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:267
internal::MessageQueueBase messageQueueBase_
contained internal::MessageQueueBase object which implements base functionality
Definition: RawMessageQueue.hpp:579
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
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:582
Top-level namespace of distortos project.
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:239
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:107
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:457
int push(const uint8_t priority, const T &data)
Pushes the element to the queue.
Definition: RawMessageQueue.hpp:150
int tryPop(uint8_t &priority, T &buffer)
Tries to pop the oldest element with highest priority from the queue.
Definition: RawMessageQueue.hpp:190
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:315
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:429