CppELib 1.7.0
Loading...
Searching...
No Matches
OSWrapper::MessageQueue< T > Class Template Reference

Class template of message queue. More...

#include <MessageQueue.h>

Public Member Functions

Error send (const T &msg)
 Send the message.
 
Error trySend (const T &msg)
 Send the message without blocking.
 
Error timedSend (const T &msg, Timeout tmout)
 Send the message within the limited time.
 
Error receive (T *msg)
 Receive the message.
 
Error tryReceive (T *msg)
 Receive the message without blocking.
 
Error timedReceive (T *msg, Timeout tmout)
 Receive the message within the limited time.
 
std::size_t getSize () const
 Get the queue size.
 
std::size_t getMaxSize () const
 Get the max queue size.
 

Static Public Member Functions

static MessageQueuecreate (std::size_t maxSize)
 Create a MessageQueue object.
 
static void destroy (MessageQueue *m)
 Destroy a MessageQueue object.
 

Detailed Description

template<typename T>
class OSWrapper::MessageQueue< T >

Class template of message queue.

Template Parameters
TType of element
Note
All the methods are thread-safe.

Member Function Documentation

◆ create()

template<typename T >
static MessageQueue * OSWrapper::MessageQueue< T >::create ( std::size_t  maxSize)
inlinestatic

Create a MessageQueue object.

Parameters
maxSizeMax queue size
Returns
If this method succeeds then returns a pointer of MessageQueue object, else returns null pointer

◆ destroy()

template<typename T >
static void OSWrapper::MessageQueue< T >::destroy ( MessageQueue< T > *  m)
inlinestatic

Destroy a MessageQueue object.

Parameters
mPointer of MessageQueue object created by MessageQueue<T>::create()
Note
If m is null pointer, do nothing.

◆ getMaxSize()

template<typename T >
std::size_t OSWrapper::MessageQueue< T >::getMaxSize ( ) const
inline

Get the max queue size.

Returns
Max queue size

◆ getSize()

template<typename T >
std::size_t OSWrapper::MessageQueue< T >::getSize ( ) const
inline

Get the queue size.

Returns
Queue size

◆ receive()

template<typename T >
Error OSWrapper::MessageQueue< T >::receive ( T *  msg)
inline

Receive the message.

This method dequeues the message from this queue. If this queue is empty, block the current thread until to be enqueued by send methods.

Parameters
msgPointer of variable that stores the message received. If null pointer, not accessed
Return values
OKSuccess. The message was received
CalledByNonThreadCalled from non thread context (interrupt handler, timer, etc)
Note
Same as timedReceive(msg, Timeout::FOREVER)

◆ send()

template<typename T >
Error OSWrapper::MessageQueue< T >::send ( const T &  msg)
inline

Send the message.

This method enqueues the message into this queue. If this queue is full, block the current thread until to be dequeued by receive methods.

Parameters
msgMessage to send
Return values
OKSuccess. The message was sent
CalledByNonThreadCalled from non thread context (interrupt handler, timer, etc)
Note
Same as timedSend(msg, Timeout::FOREVER)

◆ timedReceive()

template<typename T >
Error OSWrapper::MessageQueue< T >::timedReceive ( T *  msg,
Timeout  tmout 
)
inline

Receive the message within the limited time.

This method dequeues the message from this queue. If this queue is empty, block the current thread until to be enqueued by send methods but only within the limited time.

Parameters
msgPointer of variable that stores the message received. If null pointer, not accessed
tmoutThe limited time
Return values
OKSuccess. The message was received
TimedOutThe limited time was elapsed
CalledByNonThreadCalled from non thread context (interrupt handler, timer, etc)
Note
If tmout is Timeout::POLLING then this method tries to receive the message without blocking.
If tmout is Timeout::FOREVER then this method waits forever until has received the message.

◆ timedSend()

template<typename T >
Error OSWrapper::MessageQueue< T >::timedSend ( const T &  msg,
Timeout  tmout 
)
inline

Send the message within the limited time.

This method enqueues the message into this queue. If this queue is full, block the current thread until to be dequeued by receive methods but only within the limited time.

Parameters
msgMessage to send
tmoutThe limited time
Return values
OKSuccess. The message was sent
TimedOutThe limited time was elapsed
CalledByNonThreadCalled from non thread context (interrupt handler, timer, etc)
Note
If tmout is Timeout::POLLING then this method tries to send the message without blocking.
If tmout is Timeout::FOREVER then this method waits forever until has sent the message.

◆ tryReceive()

template<typename T >
Error OSWrapper::MessageQueue< T >::tryReceive ( T *  msg)
inline

Receive the message without blocking.

This method dequeues the message from this queue. If this queue is empty, returns TimedOut immediately.

Parameters
msgPointer of variable that stores the message received. If null pointer, not accessed
Return values
OKSuccess. The message was received
TimedOutThis queue is empty
Note
Same as timedReceive(msg, Timeout::POLLING)

◆ trySend()

template<typename T >
Error OSWrapper::MessageQueue< T >::trySend ( const T &  msg)
inline

Send the message without blocking.

This method enqueues the message into this queue. If this queue is full, returns TimedOut immediately.

Parameters
msgMessage to send
Return values
OKSuccess. The message was sent
TimedOutThis queue is full
Note
Same as timedSend(msg, Timeout::POLLING)

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