distortos  v0.7.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 
52  size_t getCapacity() const
53  {
54  return fifoQueueBase_.getCapacity();
55  }
56 
61  size_t getElementSize() const
62  {
64  }
65 
80  int pop(void* buffer, size_t size);
81 
97  template<typename T>
98  int pop(T& buffer)
99  {
100  return pop(&buffer, sizeof(buffer));
101  }
102 
117  int push(const void* data, size_t size);
118 
134  template<typename T>
135  int push(const T& data)
136  {
137  return push(&data, sizeof(data));
138  }
139 
152  int tryPop(void* buffer, size_t size);
153 
167  template<typename T>
168  int tryPop(T& buffer)
169  {
170  return tryPop(&buffer, sizeof(buffer));
171  }
172 
188  int tryPopFor(TickClock::duration duration, void* buffer, size_t size);
189 
210  template<typename Rep, typename Period>
211  int tryPopFor(const std::chrono::duration<Rep, Period> duration, void* const buffer, const size_t size)
212  {
213  return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), buffer, size);
214  }
215 
234  template<typename Rep, typename Period, typename T>
235  int tryPopFor(const std::chrono::duration<Rep, Period> duration, T& buffer)
236  {
237  return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), &buffer, sizeof(buffer));
238  }
239 
255  int tryPopUntil(TickClock::time_point timePoint, void* buffer, size_t size);
256 
276  template<typename Duration>
277  int tryPopUntil(const std::chrono::time_point<TickClock, Duration> timePoint, void* const buffer, const size_t size)
278  {
279  return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), buffer, size);
280  }
281 
299  template<typename Duration, typename T>
300  int tryPopUntil(const std::chrono::time_point<TickClock, Duration> timePoint, T& buffer)
301  {
302  return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), &buffer, sizeof(buffer));
303  }
304 
317  int tryPush(const void* data, size_t size);
318 
332  template<typename T>
333  int tryPush(const T& data)
334  {
335  return tryPush(&data, sizeof(data));
336  }
337 
353  int tryPushFor(TickClock::duration duration, const void* data, size_t size);
354 
375  template<typename Rep, typename Period>
376  int tryPushFor(const std::chrono::duration<Rep, Period> duration, const void* const data, const size_t size)
377  {
378  return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), data, size);
379  }
380 
399  template<typename Rep, typename Period, typename T>
400  int tryPushFor(const std::chrono::duration<Rep, Period> duration, const T& data)
401  {
402  return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), &data, sizeof(data));
403  }
404 
420  int tryPushUntil(TickClock::time_point timePoint, const void* data, size_t size);
421 
441  template<typename Duration>
442  int tryPushUntil(const std::chrono::time_point<TickClock, Duration> timePoint, const void* const data,
443  const size_t size)
444  {
445  return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), data, size);
446  }
447 
465  template<typename Duration, typename T>
466  int tryPushUntil(const std::chrono::time_point<TickClock, Duration> timePoint, const T& data)
467  {
468  return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), &data, sizeof(data));
469  }
470 
471 private:
472 
488  int popInternal(const internal::SemaphoreFunctor& waitSemaphoreFunctor, void* buffer, size_t size);
489 
505  int pushInternal(const internal::SemaphoreFunctor& waitSemaphoreFunctor, const void* data, size_t size);
506 
509 };
510 
511 } // namespace distortos
512 
513 #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:400
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:442
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:277
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:508
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'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
size_t getCapacity() const
Definition: RawFifoQueue.hpp:52
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:376
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:98
int tryPush(const T &data)
Tries to push the element to the queue.
Definition: RawFifoQueue.hpp:333
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:235
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:211
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:300
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:466
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.
Definition: buttons.hpp:33
size_t getElementSize() const
Definition: FifoQueueBase.hpp:66
size_t getElementSize() const
Definition: RawFifoQueue.hpp:61
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:168
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
size_t getCapacity() const
Definition: FifoQueueBase.hpp:57
int push(const T &data)
Pushes the element to the queue.
Definition: RawFifoQueue.hpp:135
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