distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::RawMessageQueue Class Reference

RawMessageQueue class is very similar to MessageQueue, but optimized for binary serializable types (like POD types). More...

#include <RawMessageQueue.hpp>

Inheritance diagram for distortos::RawMessageQueue:
[legend]
Collaboration diagram for distortos::RawMessageQueue:
[legend]

Public Types

using EntryStorage = internal::MessageQueueBase::EntryStorage
 type of uninitialized storage for Entry with link More...
 
using EntryStorageUniquePointer = internal::MessageQueueBase::EntryStorageUniquePointer
 import EntryStorageUniquePointer type from internal::MessageQueueBase class More...
 
template<typename T >
using ValueStorage = internal::MessageQueueBase::ValueStorage< T >
 
using ValueStorageUniquePointer = internal::MessageQueueBase::ValueStorageUniquePointer
 

Public Member Functions

 RawMessageQueue (EntryStorageUniquePointer &&entryStorageUniquePointer, ValueStorageUniquePointer &&valueStorageUniquePointer, size_t elementSize, size_t maxElements)
 RawMessageQueue's constructor. More...
 
int pop (uint8_t &priority, void *buffer, size_t size)
 Pops oldest element with highest priority from the queue. More...
 
template<typename T >
int pop (uint8_t &priority, T &buffer)
 Pops oldest element with highest priority from the queue. More...
 
int push (uint8_t priority, const void *data, size_t size)
 Pushes the element to the queue. More...
 
template<typename T >
int push (const uint8_t priority, const T &data)
 Pushes the element to the queue. More...
 
int tryPop (uint8_t &priority, void *buffer, size_t size)
 Tries to pop the oldest element with highest priority from the queue. More...
 
template<typename T >
int tryPop (uint8_t &priority, T &buffer)
 Tries to pop the oldest element with highest priority from the queue. More...
 
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. More...
 
template<typename Rep , typename Period >
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. More...
 
template<typename Rep , typename Period , typename T >
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. More...
 
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. More...
 
template<typename Duration >
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. More...
 
template<typename Duration , typename T >
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. More...
 
int tryPush (uint8_t priority, const void *data, size_t size)
 Tries to push the element to the queue. More...
 
template<typename T >
int tryPush (const uint8_t priority, const T &data)
 Tries to push the element to the queue. More...
 
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. More...
 
template<typename Rep , typename Period >
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. More...
 
template<typename Rep , typename Period , typename T >
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. More...
 
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. More...
 
template<typename Duration >
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. More...
 
template<typename Duration , typename T >
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. More...
 

Private Member Functions

int popInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, uint8_t &priority, void *buffer, size_t size)
 Pops oldest element with highest priority from the queue. More...
 
int pushInternal (const internal::SemaphoreFunctor &waitSemaphoreFunctor, uint8_t priority, const void *data, size_t size)
 Pushes the element to the queue. More...
 

Private Attributes

internal::MessageQueueBase messageQueueBase_
 contained internal::MessageQueueBase object which implements base functionality More...
 
const size_t elementSize_
 size of single queue element, bytes More...
 

Detailed Description

RawMessageQueue class is very similar to MessageQueue, but optimized for binary serializable types (like POD types).

Type T can be used with both RawMessageQueue and MessageQueue only when std::is_trivially_copyable<T>::value == true, otherwise only MessageQueue use is safe, while using RawMessageQueue results in undefined behavior.

Similar to POSIX mqd_t - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/mqueue.h.html

Member Typedef Documentation

◆ EntryStorage

type of uninitialized storage for Entry with link

◆ EntryStorageUniquePointer

◆ ValueStorage

type of uninitialized storage for value

Template Parameters
Tis the type of data in queue

Constructor & Destructor Documentation

◆ RawMessageQueue()

distortos::RawMessageQueue::RawMessageQueue ( EntryStorageUniquePointer &&  entryStorageUniquePointer,
ValueStorageUniquePointer &&  valueStorageUniquePointer,
size_t  elementSize,
size_t  maxElements 
)

RawMessageQueue's constructor.

Parameters
[in]entryStorageUniquePointeris a rvalue reference to EntryStorageUniquePointer with storage for queue entries (sufficiently large for maxElements EntryStorage objects) and appropriate deleter
[in]valueStorageUniquePointeris a rvalue reference to ValueStorageUniquePointer with storage for queue elements (sufficiently large for maxElements, each elementSize bytes long) and appropriate deleter
[in]elementSizeis the size of single queue element, bytes
[in]maxElementsis the number of elements in entryStorage array and valueStorage memory block

Member Function Documentation

◆ pop() [1/2]

int distortos::RawMessageQueue::pop ( uint8_t &  priority,
void *  buffer,
size_t  size 
)

Pops oldest element with highest priority from the queue.

Similar to mq_receive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

Warning
This function must not be called from interrupt context!
Parameters
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop() [2/2]

template<typename T >
int distortos::RawMessageQueue::pop ( uint8_t &  priority,
T &  buffer 
)
inline

Pops oldest element with highest priority from the queue.

Similar to mq_receive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

Warning
This function must not be called from interrupt context!
Template Parameters
Tis the type of data popped from the queue
Parameters
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a reference to object that will be used to return popped value
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ popInternal()

int distortos::RawMessageQueue::popInternal ( const internal::SemaphoreFunctor waitSemaphoreFunctor,
uint8_t &  priority,
void *  buffer,
size_t  size 
)
private

Pops oldest element with highest priority from the queue.

Internal version - builds the Functor object.

Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with popSemaphore_
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was popped successfully, error code otherwise:
  • EMSGSIZE - size doesn't match the elementSize attribute of RawMessageQueue;
  • error codes returned by waitSemaphoreFunctor's operator() call;
  • error codes returned by Semaphore::post();
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push() [1/2]

int distortos::RawMessageQueue::push ( uint8_t  priority,
const void *  data,
size_t  size 
)

Pushes the element to the queue.

Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#

Warning
This function must not be called from interrupt context!
Parameters
[in]priorityis the priority of new element
[in]datais a pointer to data that will be pushed to RawMessageQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push() [2/2]

template<typename T >
int distortos::RawMessageQueue::push ( const uint8_t  priority,
const T &  data 
)
inline

Pushes the element to the queue.

Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#

Warning
This function must not be called from interrupt context!
Template Parameters
Tis the type of data pushed to the queue
Parameters
[in]priorityis the priority of new element
[in]datais a reference to data that will be pushed to RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ pushInternal()

int distortos::RawMessageQueue::pushInternal ( const internal::SemaphoreFunctor waitSemaphoreFunctor,
uint8_t  priority,
const void *  data,
size_t  size 
)
private

Pushes the element to the queue.

Internal version - builds the Functor object.

Parameters
[in]waitSemaphoreFunctoris a reference to SemaphoreFunctor which will be executed with pushSemaphore_
[in]priorityis the priority of new element
[in]datais a pointer to data that will be pushed to RawMessageQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
  • EMSGSIZE - size doesn't match the elementSize attribute of RawMessageQueue;
  • error codes returned by waitSemaphoreFunctor's operator() call;
  • error codes returned by Semaphore::post();
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPop() [1/2]

int distortos::RawMessageQueue::tryPop ( uint8_t &  priority,
void *  buffer,
size_t  size 
)

Tries to pop the oldest element with highest priority from the queue.

Similar to mq_receive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

Parameters
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPop() [2/2]

template<typename T >
int distortos::RawMessageQueue::tryPop ( uint8_t &  priority,
T &  buffer 
)
inline

Tries to pop the oldest element with highest priority from the queue.

Similar to mq_receive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

Template Parameters
Tis the type of data popped from the queue
Parameters
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a reference to object that will be used to return popped value
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPopFor() [1/3]

int distortos::RawMessageQueue::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.

Similar to mq_timedreceive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

Warning
This function must not be called from interrupt context!
Parameters
[in]durationis the duration after which the call will be terminated without popping the element
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPopFor() [2/3]

template<typename Rep , typename Period >
int distortos::RawMessageQueue::tryPopFor ( const std::chrono::duration< Rep, Period >  duration,
uint8_t &  priority,
void *const  buffer,
const size_t  size 
)
inline

Tries to pop the oldest element with highest priority from the queue for a given duration of time.

Template variant of tryPopFor(TickClock::duration, uint8_t&, void*, size_t).

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Parameters
[in]durationis the duration after which the call will be terminated without popping the element
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPopFor() [3/3]

template<typename Rep , typename Period , typename T >
int distortos::RawMessageQueue::tryPopFor ( const std::chrono::duration< Rep, Period >  duration,
uint8_t &  priority,
T &  buffer 
)
inline

Tries to pop the oldest element with highest priority from the queue for a given duration of time.

Similar to mq_timedreceive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Tis the type of data popped from the queue
Parameters
[in]durationis the duration after which the call will be terminated without popping the element
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a reference to object that will be used to return popped value
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPopUntil() [1/3]

int distortos::RawMessageQueue::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.

Similar to mq_timedreceive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

Warning
This function must not be called from interrupt context!
Parameters
[in]timePointis the time point at which the call will be terminated without popping the element
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPopUntil() [2/3]

template<typename Duration >
int distortos::RawMessageQueue::tryPopUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
uint8_t &  priority,
void *const  buffer,
const size_t  size 
)
inline

Tries to pop the oldest element with highest priority from the queue until a given time point.

Template variant of tryPopUntil(TickClock::time_point, uint8_t&, void*, size_t).

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Parameters
[in]timePointis the time point at which the call will be terminated without popping the element
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a pointer to buffer for popped element
[in]sizeis the size of buffer, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPopUntil() [3/3]

template<typename Duration , typename T >
int distortos::RawMessageQueue::tryPopUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
uint8_t &  priority,
T &  buffer 
)
inline

Tries to pop the oldest element with highest priority from the queue until a given time point.

Similar to mq_timedreceive() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Tis the type of data popped from the queue
Parameters
[in]timePointis the time point at which the call will be terminated without popping the element
[out]priorityis a reference to variable that will be used to return priority of popped value
[out]bufferis a reference to object that will be used to return popped value
Returns
zero if element was popped successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPush() [1/2]

int distortos::RawMessageQueue::tryPush ( uint8_t  priority,
const void *  data,
size_t  size 
)

Tries to push the element to the queue.

Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#

Parameters
[in]priorityis the priority of new element
[in]datais a pointer to data that will be pushed to RawMessageQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPush() [2/2]

template<typename T >
int distortos::RawMessageQueue::tryPush ( const uint8_t  priority,
const T &  data 
)
inline

Tries to push the element to the queue.

Similar to mq_send() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#

Template Parameters
Tis the type of data pushed to the queue
Parameters
[in]priorityis the priority of new element
[in]datais a reference to data that will be pushed to RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPushFor() [1/3]

int distortos::RawMessageQueue::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.

Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#

Warning
This function must not be called from interrupt context!
Parameters
[in]durationis the duration after which the wait will be terminated without pushing the element
[in]priorityis the priority of new element
[in]datais a pointer to data that will be pushed to RawMessageQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPushFor() [2/3]

template<typename Rep , typename Period >
int distortos::RawMessageQueue::tryPushFor ( const std::chrono::duration< Rep, Period >  duration,
const uint8_t  priority,
const void *const  data,
const size_t  size 
)
inline

Tries to push the element to the queue for a given duration of time.

Template variant of tryPushFor(TickClock::duration, uint8_t, const void*, size_t).

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Parameters
[in]durationis the duration after which the wait will be terminated without pushing the element
[in]priorityis the priority of new element
[in]datais a pointer to data that will be pushed to RawMessageQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPushFor() [3/3]

template<typename Rep , typename Period , typename T >
int distortos::RawMessageQueue::tryPushFor ( const std::chrono::duration< Rep, Period >  duration,
const uint8_t  priority,
const T &  data 
)
inline

Tries to push the element to the queue for a given duration of time.

Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Tis the type of data pushed to the queue
Parameters
[in]durationis the duration after which the wait will be terminated without pushing the element
[in]priorityis the priority of new element
[in]datais a reference to data that will be pushed to RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPushUntil() [1/3]

int distortos::RawMessageQueue::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.

Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#

Warning
This function must not be called from interrupt context!
Parameters
[in]timePointis the time point at which the call will be terminated without pushing the element
[in]priorityis the priority of new element
[in]datais a pointer to data that will be pushed to RawMessageQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryPushUntil() [2/3]

template<typename Duration >
int distortos::RawMessageQueue::tryPushUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
const uint8_t  priority,
const void *const  data,
const size_t  size 
)
inline

Tries to push the element to the queue until a given time point.

Template variant of tryPushUntil(TickClock::time_point, uint8_t, const void*, size_t).

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Parameters
[in]timePointis the time point at which the call will be terminated without pushing the element
[in]priorityis the priority of new element
[in]datais a pointer to data that will be pushed to RawMessageQueue
[in]sizeis the size of data, bytes - must be equal to the elementSize attribute of RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

◆ tryPushUntil() [3/3]

template<typename Duration , typename T >
int distortos::RawMessageQueue::tryPushUntil ( const std::chrono::time_point< TickClock, Duration >  timePoint,
const uint8_t  priority,
const T &  data 
)
inline

Tries to push the element to the queue until a given time point.

Similar to mq_timedsend() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html#

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Tis the type of data pushed to the queue
Parameters
[in]timePointis the time point at which the call will be terminated without pushing the element
[in]priorityis the priority of new element
[in]datais a reference to data that will be pushed to RawMessageQueue
Returns
zero if element was pushed successfully, error code otherwise:
Here is the call graph for this function:

Member Data Documentation

◆ elementSize_

const size_t distortos::RawMessageQueue::elementSize_
private

size of single queue element, bytes

◆ messageQueueBase_

internal::MessageQueueBase distortos::RawMessageQueue::messageQueueBase_
private

contained internal::MessageQueueBase object which implements base functionality


The documentation for this class was generated from the following files: