distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
RawFifoQueue.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_RAWFIFOQUEUE_HPP_
13 #define INCLUDE_DISTORTOS_RAWFIFOQUEUE_HPP_
14 
16 
17 namespace distortos
18 {
19 
31 {
32 public:
33 
36 
46  RawFifoQueue(StorageUniquePointer&& storageUniquePointer, size_t elementSize, size_t maxElements);
47 
62  int pop(void* buffer, size_t size);
63 
79  template<typename T>
80  int pop(T& buffer)
81  {
82  return pop(&buffer, sizeof(buffer));
83  }
84 
99  int push(const void* data, size_t size);
100 
116  template<typename T>
117  int push(const T& data)
118  {
119  return push(&data, sizeof(data));
120  }
121 
134  int tryPop(void* buffer, size_t size);
135 
149  template<typename T>
150  int tryPop(T& buffer)
151  {
152  return tryPop(&buffer, sizeof(buffer));
153  }
154 
170  int tryPopFor(TickClock::duration duration, void* buffer, size_t size);
171 
192  template<typename Rep, typename Period>
193  int tryPopFor(const std::chrono::duration<Rep, Period> duration, void* const buffer, const size_t size)
194  {
195  return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), buffer, size);
196  }
197 
216  template<typename Rep, typename Period, typename T>
217  int tryPopFor(const std::chrono::duration<Rep, Period> duration, T& buffer)
218  {
219  return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), &buffer, sizeof(buffer));
220  }
221 
237  int tryPopUntil(TickClock::time_point timePoint, void* buffer, size_t size);
238 
258  template<typename Duration>
259  int tryPopUntil(const std::chrono::time_point<TickClock, Duration> timePoint, void* const buffer, const size_t size)
260  {
261  return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), buffer, size);
262  }
263 
281  template<typename Duration, typename T>
282  int tryPopUntil(const std::chrono::time_point<TickClock, Duration> timePoint, T& buffer)
283  {
284  return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), &buffer, sizeof(buffer));
285  }
286 
299  int tryPush(const void* data, size_t size);
300 
314  template<typename T>
315  int tryPush(const T& data)
316  {
317  return tryPush(&data, sizeof(data));
318  }
319 
335  int tryPushFor(TickClock::duration duration, const void* data, size_t size);
336 
357  template<typename Rep, typename Period>
358  int tryPushFor(const std::chrono::duration<Rep, Period> duration, const void* const data, const size_t size)
359  {
360  return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), data, size);
361  }
362 
381  template<typename Rep, typename Period, typename T>
382  int tryPushFor(const std::chrono::duration<Rep, Period> duration, const T& data)
383  {
384  return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), &data, sizeof(data));
385  }
386 
402  int tryPushUntil(TickClock::time_point timePoint, const void* data, size_t size);
403 
423  template<typename Duration>
424  int tryPushUntil(const std::chrono::time_point<TickClock, Duration> timePoint, const void* const data,
425  const size_t size)
426  {
427  return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), data, size);
428  }
429 
447  template<typename Duration, typename T>
448  int tryPushUntil(const std::chrono::time_point<TickClock, Duration> timePoint, const T& data)
449  {
450  return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), &data, sizeof(data));
451  }
452 
453 private:
454 
470  int popInternal(const internal::SemaphoreFunctor& waitSemaphoreFunctor, void* buffer, size_t size);
471 
487  int pushInternal(const internal::SemaphoreFunctor& waitSemaphoreFunctor, const void* data, size_t size);
488 
491 };
492 
493 } // namespace distortos
494 
495 #endif // INCLUDE_DISTORTOS_RAWFIFOQUEUE_HPP_
int tryPushFor(const std::chrono::duration< Rep, Period > duration, const T &data)
Tries to push the element to the queue for a given duration of time.
Definition: RawFifoQueue.hpp:382
int tryPushUntil(const std::chrono::time_point< TickClock, Duration > timePoint, const void *const data, const size_t size)
Tries to push the element to the queue until a given time point.
Definition: RawFifoQueue.hpp:424
int tryPopUntil(const std::chrono::time_point< TickClock, Duration > timePoint, void *const buffer, const size_t size)
Tries to pop the oldest (first) element from the queue until a given time point.
Definition: RawFifoQueue.hpp:259
int push(const void *data, size_t size)
Pushes the element to the queue.
Definition: RawFifoQueue.cpp:48
internal::FifoQueueBase fifoQueueBase_
contained internal::FifoQueueBase object which implements base functionality
Definition: RawFifoQueue.hpp:490
int tryPopFor(TickClock::duration duration, void *buffer, size_t size)
Tries to pop the oldest (first) element from the queue for a given duration of time.
Definition: RawFifoQueue.cpp:62
RawFifoQueue class is very similar to FifoQueue, but optimized for binary serializable types (like PO...
Definition: RawFifoQueue.hpp:30
int popInternal(const internal::SemaphoreFunctor &waitSemaphoreFunctor, void *buffer, size_t size)
Pops the oldest (first) element from the queue.
Definition: RawFifoQueue.cpp:104
RawFifoQueue(StorageUniquePointer &&storageUniquePointer, size_t elementSize, size_t maxElements)
RawFifoQueue&#39;s constructor.
Definition: RawFifoQueue.cpp:33
int tryPushFor(TickClock::duration duration, const void *data, size_t size)
Tries to push the element to the queue for a given duration of time.
Definition: RawFifoQueue.cpp:84
int tryPushFor(const std::chrono::duration< Rep, Period > duration, const void *const data, const size_t size)
Tries to push the element to the queue for a given duration of time.
Definition: RawFifoQueue.hpp:358
int pushInternal(const internal::SemaphoreFunctor &waitSemaphoreFunctor, const void *data, size_t size)
Pushes the element to the queue.
Definition: RawFifoQueue.cpp:114
int pop(T &buffer)
Pops the oldest (first) element from the queue.
Definition: RawFifoQueue.hpp:80
int tryPush(const T &data)
Tries to push the element to the queue.
Definition: RawFifoQueue.hpp:315
std::chrono::time_point< TickClock > time_point
basic time_point type of clock
Definition: TickClock.hpp:42
FifoQueueBase class header.
int tryPopFor(const std::chrono::duration< Rep, Period > duration, T &buffer)
Tries to pop the oldest (first) element from the queue for a given duration of time.
Definition: RawFifoQueue.hpp:217
int tryPopFor(const std::chrono::duration< Rep, Period > duration, void *const buffer, const size_t size)
Tries to pop the oldest (first) element from the queue for a given duration of time.
Definition: RawFifoQueue.hpp:193
int tryPopUntil(const std::chrono::time_point< TickClock, Duration > timePoint, T &buffer)
Tries to pop the oldest (first) element from the queue until a given time point.
Definition: RawFifoQueue.hpp:282
internal::FifoQueueBase::StorageUniquePointer StorageUniquePointer
unique_ptr (with deleter) to storage
Definition: RawFifoQueue.hpp:35
int tryPushUntil(const std::chrono::time_point< TickClock, Duration > timePoint, const T &data)
Tries to push the element to the queue until a given time point.
Definition: RawFifoQueue.hpp:448
FifoQueueBase class implements basic functionality of FifoQueue template class.
Definition: FifoQueueBase.hpp:29
std::unique_ptr< void, void(&)(void *)> StorageUniquePointer
unique_ptr (with deleter) to storage
Definition: FifoQueueBase.hpp:34
Top-level namespace of distortos project.
int tryPushUntil(TickClock::time_point timePoint, const void *data, size_t size)
Tries to push the element to the queue until a given time point.
Definition: RawFifoQueue.cpp:92
int tryPop(T &buffer)
Tries to pop the oldest (first) element from the queue.
Definition: RawFifoQueue.hpp:150
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 tryPop(void *buffer, size_t size)
Tries to pop the oldest (first) element from the queue.
Definition: RawFifoQueue.cpp:56
int push(const T &data)
Pushes the element to the queue.
Definition: RawFifoQueue.hpp:117
int pop(void *buffer, size_t size)
Pops the oldest (first) element from the queue.
Definition: RawFifoQueue.cpp:40
int tryPush(const void *data, size_t size)
Tries to push the element to the queue.
Definition: RawFifoQueue.cpp:78
int tryPopUntil(TickClock::time_point timePoint, void *buffer, size_t size)
Tries to pop the oldest (first) element from the queue until a given time point.
Definition: RawFifoQueue.cpp:70