AURobotServers  4
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
UMsgQueue Class Reference

#include <umsgqueue.h>

Inheritance diagram for UMsgQueue:
Inheritance graph

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
 

Detailed Description

Author
Christian Andersen

Constructor & Destructor Documentation

UMsgQueue::UMsgQueue ( )

Constructor

References valid.

UMsgQueue::~UMsgQueue ( )

Destructor

References freeQueue().

Member Function Documentation

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().

unsigned char * UMsgQueue::getMsg ( int  i)
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().

int UMsgQueue::getNextOut ( )
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 ( )

Returns a reference to the next available message. Returns NULL if queue is empty. NB! the message until 'skipMessage()' is called.

References getMsg(), isEmpty(), nextOut, and valid.

int UMsgQueue::getUsedMsgCnt ( )
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().

bool UMsgQueue::isValid ( )
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).

Note
UMsgQueue::skipToNextMessage no longer locks the queue while getting pointer to next message. This must be done by the funsction using the pointer to the data. 13 feb 2005/chr

References elements, getMsg(), isEmpty(), justIn, nextOut, and valid.

Referenced by UProbPolyQueue::skipToNext(), and UServerInQueue::skipToNextMessage().

Member Data Documentation

int UMsgQueue::elements
protected
int UMsgQueue::elementSize
protected

Size of each element in queue

Referenced by addMessage(), create(), and getElementSize().

int UMsgQueue::justIn
protected
int UMsgQueue::nextOut
protected
unsigned char** UMsgQueue::pMsg
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().

bool UMsgQueue::valid
protected

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