EPICS Base  7.0.7.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | List of all members
epicsMessageQueue Class Reference

#include <epicsMessageQueue.h>

Public Member Functions

 epicsMessageQueue (unsigned int capacity, unsigned int maximumMessageSize)
 Constructor. More...
 
 ~epicsMessageQueue ()
 Destructor.
 
int trySend (void *message, unsigned int messageSize)
 Try to send a message. More...
 
int send (void *message, unsigned int messageSize)
 Send a message. More...
 
int send (void *message, unsigned int messageSize, double timeout)
 Send a message or timeout. More...
 
int tryReceive (void *message, unsigned int size)
 Try to receive a message. More...
 
int receive (void *message, unsigned int size)
 Fetch the next message on the queue. More...
 
int receive (void *message, unsigned int size, double timeout)
 Wait for and fetch the next message. More...
 
void show (unsigned int level=0)
 Displays some information about the message queue. More...
 
unsigned int pending ()
 How many messages are queued. More...
 

Detailed Description

Provides methods for sending messages between threads on a first in, first out basis. It is designed so that a single message queue can be used with multiple writer and reader threads.

A C++ epicsMessageQueue cannot be assigned to, copy-constructed, or constructed without giving the capacity and max-imumMessageSize arguments.

The C++ compiler will object to some of the statements below:

epicsMessageQueue mq0(); // Error: default constructor is private
epicsMessageQueue mq1(10, 20); // OK
epicsMessageQueue mq2(t1); // Error: copy constructor is private
epicsMessageQueue*pmq; // OK, pointer
*pmq = mq1; // Error: assignment operator is private
pmq = &mq1; // OK, pointer assignment and address-of

Definition at line 48 of file epicsMessageQueue.h.

Constructor & Destructor Documentation

epicsMessageQueue::epicsMessageQueue ( unsigned int  capacity,
unsigned int  maximumMessageSize 
)
Parameters
capacityMaximum number of messages to queue
maximumMessageSizeNumber of bytes of the largest message that may be queued

Member Function Documentation

int epicsMessageQueue::trySend ( void *  message,
unsigned int  messageSize 
)
Note
On VxWorks and RTEMS this method may be called from an interrupt handler.
Returns
0 if the message was sent to a receiver or queued for future delivery.
-1 if no more messages can be queued or if the message is larger than the queue's maximum message size.
int epicsMessageQueue::send ( void *  message,
unsigned int  messageSize 
)
Returns
0 if the message was sent to a receiver or queued for future delivery.
-1 if the message is larger than the queue's maximum message size.
int epicsMessageQueue::send ( void *  message,
unsigned int  messageSize,
double  timeout 
)
Parameters
messagePointer to the message to be sent
messageSizeThe size of message
timeoutThe timeout delay in seconds. A timeout of zero is equivalent to calling trySend(); NaN or any value too large to be represented to the target OS is equivalent to no timeout.
Returns
0 if the message was sent to a receiver or queued for future delivery.
-1 if the timeout was reached before the message could be sent or queued, or if the message is larger than the queue's maximum message size.
int epicsMessageQueue::tryReceive ( void *  message,
unsigned int  size 
)
Parameters
[out]messageOutput buffer to store the received message
sizeSize of the buffer pointed to by message

If the queue holds at least one message, the first message on the queue is moved to the specified location and the length of that message is returned.

If the received message is larger than the specified message size the implementation may either return -1, or truncate the message. It is most efficient if the messageBufferSize is equal to the maximumMessageSize with which the message queue was created.

Returns
Number of bytes in the message.
-1 if the message queue is empty, or the buffer too small.
int epicsMessageQueue::receive ( void *  message,
unsigned int  size 
)
Parameters
[out]messageOutput buffer to store the received message
sizeSize of the buffer pointed to by message

Wait for a message to be sent if the queue is empty, then move the first message queued to the specified location.

If the received message is larger than the specified message size the implementation may either return -1, or truncate the message. It is most efficient if the messageBufferSize is equal to the maximumMessageSize with which the message queue was created.

Returns
Number of bytes in the message.
-1 if the buffer is too small for the message.
int epicsMessageQueue::receive ( void *  message,
unsigned int  size,
double  timeout 
)
Parameters
[out]messageOutput buffer to store the received message
sizeSize of the buffer pointed to by message
timeoutThe timeout delay in seconds. A timeout of zero is equivalent to calling tryReceive(); NaN or any value too large to be represented to the target OS is equivalent to no timeout.

Waits up to timeout seconds for a message to arrive if the queue is empty, then moves the first message to the message buffer.

If the received message is larger than the buffer size the implementation may either return -1, or truncate the message. It is most efficient if the messageBufferSize is equal to the maximumMessageSize with which the message queue was created.

Returns
Number of bytes in the message.
-1 if a message is not received within the timeout interval.
void epicsMessageQueue::show ( unsigned int  level = 0)
Parameters
levelControls the amount of information displayed.
unsigned int epicsMessageQueue::pending ( )
Returns
The number of messages presently in the queue.

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