4S Device Communication Module Collection  Version 0.6-SNAPSHOT
Full documentation of the modules in the 4SDC collection (aimed at 4SDC module developers)
FSYS::MsgQueue Class Reference

This is a wrapper class for the class that does all the hard work. More...

#include <msgqueue.h>

+ Collaboration diagram for FSYS::MsgQueue:

Static Public Member Functions

static void addListenerToQueue (MsgAddr &receiverAddr, const std::type_info &typeOfMsg, MsgCallBack *msgCallBack)
 Function that registers a listener to the message queue. More...
 
static void removeListenerFromQueue (MsgCallBack *msgCallBack)
 Function that unregisters a listener from the message queue. More...
 
static void waitUntilQueueHasData (void)
 Function that halts the current thread execution. More...
 
static void emptyMsgQueue (int maxTimeMs=-1)
 The function will process messages on the message queue. More...
 
static void breakEmptyMsgQueue (void)
 Breaks out of emptyMsgQueue. More...
 
static bool isEmpty (void)
 Function to determine if there is data on the msg queue. More...
 
static Handle getHandle (void)
 Retrieves the handle of the queue for the current thread. More...
 

Detailed Description

The MsgQueue class is a wrapper class with the public interface for the message queue. It contains the functions that gives the caller the ability to:

  • Register listeners (a listener being the ability for a given instance of a given class to recevie a specific message type).
  • Unregister listeners (like right before an instance of a class is destroyed)
  • Checking if the message queue has data for the current thread that needs to be processed
  • Stopping the current thread until there is a message being sent to it
  • Stopping the process of emptying the queue, like for breaking out of the internal message loop, say if a class keeps sending messages to it self
  • Emptying the message queue, either it can start a loop that terminates when the queue is empty, after a given time, or after all the messages that were in the queue at the time of the call has been processed

Member Function Documentation

void FSYS::MsgQueue::addListenerToQueue ( MsgAddr receiverAddr,
const std::type_info &  typeOfMsg,
MsgCallBack msgCallBack 
)
static

This function registers a listener (the ability of a class to receive a given type of message) with the queue of the thread that the function is called from.

Parameters
receiverAddrAddress of the receiver
typeOfMsg
msgCallBack

+ Here is the caller graph for this function:

void FSYS::MsgQueue::breakEmptyMsgQueue ( void  )
static

Function must be called from a message handler (directly or indirectly) and will cause the message loop internal to the emptyMsgQueue function to break.

This function is used in the case where you have a component that as part of its operation sends messages to it self.

Usually the emptyMsgQueue function will only return when the message is queue is empty, but in the case where components on the queue keeps sending to other components in the same thread, the queue will never be empty and hence will never terminate.

Calling this function will break the msg loop.

+ Here is the call graph for this function:

void FSYS::MsgQueue::emptyMsgQueue ( int  maxTimeMs = -1)
static

This function is used for processing messages from the message queue of the thread that this function is called from.

The default behavior is for the function to run until there are no more messages on the queue at which point the function will return.

It is possible to give an optional argument to the function limiting the time it will run.

Parameters
maxTimeMsThe maximum time in MS that will pass before the function breaks the loop that empties the queue.

maxTimeMs < 0 => Run until the queue is empty or breakEmptyMsgQueue() is called

maxTimeMS == 0 => Run until all messages on the queue at the time of the call are processed

maxTimeMS > 0 => Run approximately until maxTimeMS have passed

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FSYS::Handle FSYS::MsgQueue::getHandle ( void  )
static

This function can be used by threads to identify which queue they belong to.

Returns
The handle of the queue for the current thread.

+ Here is the call graph for this function:

bool FSYS::MsgQueue::isEmpty ( void  )
static

Call this function to determine if there are messages waiting to be processed on the queue.

Returns
true if there is messages waiting to be processd, false if not

+ Here is the call graph for this function:

void FSYS::MsgQueue::removeListenerFromQueue ( MsgCallBack msgCallBack)
static

This function removes a listener from the internal datastructures of the message queue.

Parameters
msgCallBackPointer to the callback that should be removed

+ Here is the caller graph for this function:

void FSYS::MsgQueue::waitUntilQueueHasData ( void  )
static

This function halts the current thread until someone sends a message to the thread. Be careful not the halt all of your threads, since in that case no-one will be able to send any messages to wake the system up again.

+ Here is the caller graph for this function:


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