AURobotServers
4
|
#include <umsgqueue.h>
Public Member Functions | |
bool | addMessage (unsigned char msg[], int size) |
bool | clear () |
bool | create (int iElements, int iElementSize) |
void | freeQueue () |
int | getElements () |
int | getElementSize () |
int | getNextOut () |
unsigned char * | getOutMessageRef () |
int | getUsedMsgCnt () |
bool | isEmpty () |
bool | isFull () |
bool | isValid () |
unsigned char * | skipToNextMessage (bool checkForDublicates) |
UMsgQueue () | |
~UMsgQueue () | |
Public Member Functions inherited from ULock | |
bool | lock () |
void | lockInit () |
void | post () |
bool | tryLock () |
bool | tryWait () |
ULock () | |
void | unlock () |
bool | wait () |
~ULock () | |
Protected Member Functions | |
unsigned char * | getMsg (int i) |
Protected Attributes | |
int | elements |
int | elementSize |
int | justIn |
int | nextOut |
unsigned char ** | pMsg |
bool | valid |
UMsgQueue::UMsgQueue | ( | ) |
Constructor
References valid.
UMsgQueue::~UMsgQueue | ( | ) |
Destructor
References freeQueue().
bool UMsgQueue::addMessage | ( | unsigned char | msg[], |
int | size | ||
) |
Add a message to the queue. Returns true if added. owerwrites an old message if no space left.
References elements, elementSize, getMsg(), isFull(), justIn, ULock::lock(), nextOut, ULock::unlock(), and valid.
bool UMsgQueue::clear | ( | void | ) |
Clears the queue to an empty state. Returns true if the queue is valid.
References justIn, and nextOut.
Referenced by create(), and UCmdExe::stop().
bool UMsgQueue::create | ( | int | iElements, |
int | iElementSize | ||
) |
Allocate queue space for a queue of this size. NB! allocates memory on heap, so do not allocate and free too much, if a real-time system is desired. Returns true if allocated.
References clear(), elements, elementSize, pMsg, and valid.
Referenced by UProbPolyQueue::UProbPolyQueue().
void UMsgQueue::freeQueue | ( | ) |
Deallocate memory occupied by queue
References elements, pMsg, and valid.
Referenced by ~UMsgQueue().
int UMsgQueue::getElements | ( | ) |
Get number of elements. Returns size of queue in elements.
References elements, and valid.
Referenced by UServerPort::messageReceived(), and UProbPolyQueue::print().
int UMsgQueue::getElementSize | ( | ) |
Returns size of each element.
References elementSize, and valid.
Referenced by UProbPolyQueue::print().
|
protected |
Get a reference to queue element 'i'. Returns a pointer to the message queue if 'i' is valid, else Returns NULL requested element is invalid (or queue not allocated)
References elements, pMsg, and valid.
Referenced by addMessage(), getNextOut(), getOutMessageRef(), UProbPolyQueue::lockNextIn(), UProbPolyQueue::print(), skipToNextMessage(), and UProbPolyQueue::unlockNextIn().
|
inline |
Get queue element index number for next message to read
References getMsg(), and nextOut.
Referenced by UCmdExe::executeFunction(), UCmdExe::handleOneMessageFromQueue(), UCmdExe::handleOneServerPushMessage(), and UCmdExe::handleServerCommand().
unsigned char * UMsgQueue::getOutMessageRef | ( | ) |
int UMsgQueue::getUsedMsgCnt | ( | ) |
Returns number of elements waiting in queue Returns -1 if queue is not valid.
References elements, justIn, nextOut, and valid.
Referenced by UCmdExe::executeFunction(), UCmdExe::handleOneMessageFromQueue(), UCmdExe::handleOneServerPushMessage(), UCmdExe::handleServerCommand(), isValid(), UServerPort::messageReceived(), and UProbPolyQueue::print().
bool UMsgQueue::isEmpty | ( | ) |
Returns true if queue is empty or not valid. Returns false if not empty.
References justIn, nextOut, and valid.
Referenced by getOutMessageRef(), UCmdExe::isRxQueueEmpty(), isValid(), UProbPolyQueue::lockNextOut(), UProbPolyQueue::print(), skipToNextMessage(), and testServerPort().
bool UMsgQueue::isFull | ( | ) |
Returns true if queue is full. Returns false if queue is not empty or invalid.
References elements, justIn, nextOut, and valid.
Referenced by addMessage(), UCmdExe::isRxQueueFull(), isValid(), and UProbPolyQueue::lockNextIn().
|
inline |
Returns true if the queue is valid
References getUsedMsgCnt(), isEmpty(), isFull(), and valid.
unsigned char * UMsgQueue::skipToNextMessage | ( | bool | checkForDublicates | ) |
Actual message is delt with, skip to next unread message. Return pointer to next message or Returns NULL if no next message or the queue is invalid. Actual message is delt with, skip to next unread message. Return pointer to next message or Returns NULL if no next message or the queue is invalid. If 'checkForDublicates' then the message queue is inspected for diplicates ignoring the sequence number in msg[2], but comparing length msg[0..1] and msg[3..length]. if a duplicate is found, the this first message is skipped and the next is serviced (and checked for dublicates).
References elements, getMsg(), isEmpty(), justIn, nextOut, and valid.
Referenced by UProbPolyQueue::skipToNext(), and UServerInQueue::skipToNextMessage().
|
protected |
Number of elements (buffers) available (filled or not) in queue
Referenced by addMessage(), create(), freeQueue(), getElements(), getMsg(), getUsedMsgCnt(), isFull(), UProbPolyQueue::lockNextIn(), UProbPolyQueue::print(), skipToNextMessage(), and UProbPolyQueue::unlockNextIn().
|
protected |
Size of each element in queue
Referenced by addMessage(), create(), and getElementSize().
|
protected |
Number of queue element just inserted
Referenced by addMessage(), clear(), getUsedMsgCnt(), isEmpty(), isFull(), UProbPolyQueue::lockNextIn(), UProbPolyQueue::print(), skipToNextMessage(), and UProbPolyQueue::unlockNextIn().
|
protected |
Next element to use
Referenced by addMessage(), clear(), getNextOut(), getOutMessageRef(), getUsedMsgCnt(), isEmpty(), isFull(), UProbPolyQueue::lockNextIn(), UProbPolyQueue::print(), and skipToNextMessage().
|
protected |
Lock the queue pointers. Returns true if locked. Unlocks the queue. Mutex lock for meassge queue Array of pointers to messages
Referenced by create(), freeQueue(), and getMsg().
|
protected |
Queue is created successfully
Referenced by addMessage(), create(), freeQueue(), getElements(), getElementSize(), getMsg(), getOutMessageRef(), getUsedMsgCnt(), isEmpty(), isFull(), isValid(), UProbPolyQueue::lockNextIn(), UProbPolyQueue::lockNextOut(), skipToNextMessage(), UMsgQueue(), and UProbPolyQueue::unlockNextIn().