Skip to content

Message Queues

Rich Neswold edited this page Apr 1, 2022 · 3 revisions

NOTE: Starting with v2.7, we introduced a nested, version namespace to enforce matching APIs when building and deploying. In the following code examples, we refer to the namespace as "VWPP". This translates to vwpp for pre-2.7 libraries and to vwpp::v2_7 for v2.7.

The VWPP::Queue API

This API consists of a C++ template class that wraps the message queue interface with type-safety. This class uses the VxWorks message queue primitives. Since VxWorks message queues copy data into internal memory, they don't follow C++ object semantics (i.e. copy constructors won't get called.) Due to this limitation, only primitive data types should be placed in the message queues. Primitive data types include scalars, pointers, and structures that don't define constructors, destructors, etc. The STL containers should be preferred over this class.


Constructor

VWPP::Queue<class T, size_t nn>()

Creates a queue that contains nn slots of data of type T. For instance, the following example creates a queue with space for 100 integers:

VWPP::Queue<int, 100> myQueue;

The source can sometimes be read easier by defining a type definition rather than use the more verbose template notation:

typedef VWPP::Queue<int, 100> IntQueue;

These queues can now be created with the new type name:

IntQueue myQueue;

Queue objects don't support copying, so if a function needs to take a Queue as a parameter, it needs to be passed by reference:

void useQueue(IntQueue&);

or, if you don't want the queue to be modified by the called function:

void useQueue(IntQueue const&);

bool VWPP::Queue<>::pop_front(T& t, int tmo = WAIT_FOREVER)

Pulls the next value from the queue and stores it in t. If the message queue is empty the calling task will block. This function returns true if it successfully pulls a value from the queue. It returns false if it times out. This method can also throw a std::logic_error due to programming errors.

This function cannot be called from an interrupt routine.


bool VWPP::Queue<>::push_back(T const& t, int tmo = WAIT_FOREVER)

Puts the value t at the end of the queue. If the message queue is already full, the calling task will block. This function returns true if it successfully places the value in the queue. It returns false if it times out. This method can also throw a std::logic_error due to programming errors.

This function cannot be called from an interrupt routine.


bool VWPP::Queue<>::push_front(T const& t, int tmo = WAIT_FOREVER)

Puts the value t at the front of the queue. If the message queue is already full, the calling task will block. This function returns true if it successfully places the value in the queue. It returns false if it times out. This method can also throw a std::logic_error due to programming errors.

This function cannot be called from an interrupt routine.


size_t VWPP::Queue<>::total() const

Returns the number of entries in the queue.

Clone this wiki locally