Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# MessageQueue Class Reference

A queue for size varying, time stamped and type safe messages. More...

`#include <MessageQueue.h>`

Inheritance diagram for MessageQueue:

[legend]
Collaboration diagram for MessageQueue:

[legend]
List of all members.

## Public Member Functions
| MessageQueue ()
| Default constructor.
void | setSize (int size)
| Sets the size of memory which is allocated for the queue.
int | getStreamedSize ()
| Returns the size of memory which is needed to write the queue to a stream.
void | setPlayerForNewMessages (const Player &player)
| Specifies a team color and a player number that is atached to every new message.
void | handleSpecificMessages (MessageID id, MessageHandler &handler)
| Calls a given MessageHandler for all messages of a kind in the queue.
void | handleAllMessages (MessageHandler &handler)
| Calls a given MessageHandler for all messages in the queue.
void | copyAllMessages (MessageQueue &other)
| Copies all messages from this queue to another queue.
void | moveAllMessages (MessageQueue &other)
| Moves all messages from this queue to another queue.
void | removeRepetitions ()
| Deletes all older messages from the queue if a newer message of same type is already in the queue.
void | clear ()
| Removes all messages from the queue.
bool | isEmpty () const
| Returns if the queue contains no messages.
## Public Attributes
InMessage | in
| An interface for reading messages from the queue.
OutMessage | out
| An interface for writing messages to the queue.
## Protected Member Functions
void | copyMessage (int message, MessageQueue &other)
| Copies a single message to another queue.
## Protected Attributes
MessageQueueBase | queue
| the system dependend message queue base which is responsible for the data storage
## Friends
class | CRemoteCamToolBar
In & | operator>> (In &stream, MessageQueue &messageQueue)
| Gives the stream operator access to protected members.
Out & | operator<< (Out &stream, const MessageQueue &messageQueue)
| Gives the stream operator access to protected members.

## Detailed Description

A queue for size varying, time stamped and type safe messages.

It can be used to collect very different types of messages for exchange between different threads, processes or systems.

Author:
  Martin Lötzsch

Usage:

     MessageQueue myQueue;
     myQueue.setSize(100000); // set the size of data that can be stored in the queue
     Image image1;
     myQueue.out.bin << image1; // write the binary message
     myQueue.out.finishMessage(idImage); // finish the message, set the type id of the message
     //
     // ... copy the queue between processes, systems
     //
     if (myQueue.in.getMessageID() == idImage) // check for the type of the next message
     {
       Image image2;
       myQueue.in.bin >> image2;  // read the image from the queue
     }

Definition at line 43 of file MessageQueue.h.

## Constructor & Destructor Documentation

MessageQueue::MessageQueue | ( |  | ) |

| Default constructor. Definition at line 12 of file MessageQueue.cpp. References ASSERT, idJPEGImage, in, and out.

## Member Function Documentation

void MessageQueue::setSize | ( | int | size | ) |

  | Sets the size of memory which is allocated for the queue. Ignored on the Win32 platform (dynamic allocation). Parameters:
  size | The maximum size of the queue in Bytes.
Definition at line 18 of file MessageQueue.cpp. References MessageQueueBase::setSize(). Referenced by Cognition::Cognition(), Debug::Debug(), and Motion::Motion().

Here is the call graph for this function:

int MessageQueue::getStreamedSize | ( |  | ) |

| Returns the size of memory which is needed to write the queue to a stream. Definition at line 141 of file MessageQueue.cpp. References InMessage::getMessageSize(), MessageQueueBase::getNumberOfMessages(), in, and MessageQueueBase::setSelectedMessageForReading(). Referenced by NetDebugSender::send().

Here is the call graph for this function:

void MessageQueue::setPlayerForNewMessages | ( | const Player & | player | ) |

| Specifies a team color and a player number that is atached to every new message. If not set, Player::undefinedTeamColor and Player::undefinedPlayerNumber is used. Definition at line 23 of file MessageQueue.cpp. References Player::getPlayerNumber(), Player::getTeamColor(), out, OutMessage::playerNumberForNewMessages, and OutMessage::teamColorForNewMessages. Referenced by Process::processMain().

Here is the call graph for this function:

void MessageQueue::handleSpecificMessages | ( | MessageID | id,
|  | MessageHandler & | handler
| ) |

  | Calls a given MessageHandler for all messages of a kind in the queue. Note that the messages still remain in the queue and have to be removed manually with clear(). Parameters:
  id | handle only messages with this MessageID
  handler | a reference to a MessageHandler derivate
Definition at line 29 of file MessageQueue.cpp. References InMessage::config, InMessage::getMessageID(), MessageQueueBase::getNumberOfMessages(), MessageHandler::handleMessage(), in, InText::reset(), MessageQueueBase::setSelectedMessageForReading(), and InMessage::text.

Here is the call graph for this function:

void MessageQueue::handleAllMessages | ( | MessageHandler & | handler | ) |

  | Calls a given MessageHandler for all messages in the queue. Note that the messages still remain in the queue and have to be removed manually with clear(). Parameters:
  handler | a reference to a MessageHandler derivate
Definition at line 43 of file MessageQueue.cpp. References InMessage::config, MessageQueueBase::getNumberOfMessages(), MessageHandler::handleMessage(), in, InText::reset(), MessageQueueBase::setSelectedMessageForReading(), and InMessage::text. Referenced by Debug::init(), and Process::processMain().

Here is the call graph for this function:

void MessageQueue::copyAllMessages | ( | MessageQueue & | other | ) |

  | Copies all messages from this queue to another queue. Parameters:
  other | the destination queue.
Definition at line 54 of file MessageQueue.cpp. References copyMessage(), and MessageQueueBase::getNumberOfMessages(). Referenced by moveAllMessages().

Here is the call graph for this function:

void MessageQueue::moveAllMessages | ( | MessageQueue & | other | ) |

  | Moves all messages from this queue to another queue. Parameters:
  other | the destination queue.
Definition at line 62 of file MessageQueue.cpp. References clear(), and copyAllMessages(). Referenced by LogPlayer::keep(), and LogPlayer::remove().

Here is the call graph for this function:

void MessageQueue::removeRepetitions | ( |  | ) | `[inline]`

| Deletes all older messages from the queue if a newer message of same type is already in the queue. This method should not be called during message handling. Definition at line 108 of file MessageQueue.h. References MessageQueueBase::removeRepetitions(). Referenced by LogPlayer::onIdle().

Here is the call graph for this function:

void MessageQueue::clear | ( |  | ) |

| Removes all messages from the queue. Definition at line 68 of file MessageQueue.cpp. References MessageQueueBase::clear(). Referenced by LogPlayer::_new(), moveAllMessages(), LogPlayer::open(), Process::processMain(), and CLogAnalyzerBase::reset().

Here is the call graph for this function:

bool MessageQueue::isEmpty | ( |  | ) | const

| Returns if the queue contains no messages. Definition at line 73 of file MessageQueue.cpp. References MessageQueueBase::getNumberOfMessages().

Here is the call graph for this function:

void MessageQueue::copyMessage | ( | int | message,
|  | MessageQueue & | other
| ) | `[protected]`

  | Copies a single message to another queue. Parameters:
  message | The number of the message
  other | The other queue.
Definition at line 78 of file MessageQueue.cpp. References OutMessage::bin, OutMessage::finishMessage(), MessageQueueBase::getData(), MessageQueueBase::getMessageID(), MessageQueueBase::getMessageSize(), MessageQueueBase::getMessageWasSentFromAPhysicalRobot(), MessageQueueBase::getPlayerNumber(), MessageQueueBase::getTeamColor(), MessageQueueBase::getTimeStamp(), out, MessageQueueBase::setSelectedMessageForReading(), and OutStream< OutMessageQueue, OutBinary >::write(). Referenced by copyAllMessages(), LogPlayer::jumpFrame(), LogPlayer::onIdle(), LogPlayer::saveSynchronized(), LogPlayer::stepBackward(), LogPlayer::stepForward(), and LogPlayer::stepRepeat().

Here is the call graph for this function:

## Friends And Related Function Documentation

friend class CRemoteCamToolBar`[friend]`

| Reimplemented in LogPlayer. Definition at line 49 of file MessageQueue.h.

In& operator>> | ( | In & | stream,
|  | MessageQueue & | messageQueue
| ) | `[friend]`

  | Gives the stream operator access to protected members. Parameters:
  stream | The stream from which is read.
  messageQueue | The MessageQueue object.
Returns: The stream. Definition at line 104 of file MessageQueue.cpp.

Out& operator<< | ( | Out & | stream,
|  | const MessageQueue & | messageQueue
| ) | `[friend]`

  | Gives the stream operator access to protected members. Parameters:
  stream | The stream to write on.
  messageQueue | The MessageQueue object.
Returns: The stream. Definition at line 153 of file MessageQueue.cpp.

## Member Data Documentation

MessageQueueBase MessageQueue::queue`[protected]`

| the system dependend message queue base which is responsible for the data storage Definition at line 47 of file MessageQueue.h. Referenced by LogPlayer::keep(), operator<<(), CLogAnalyzerBase::readLogfile(), LogPlayer::remove(), and LogPlayer::saveSynchronized().

InMessage MessageQueue::in

| An interface for reading messages from the queue. Definition at line 53 of file MessageQueue.h. Referenced by getStreamedSize(), handleAllMessages(), handleSpecificMessages(), operator<<(), CLogAnalyzerBase::readLogfile(), CLogAnalyzerBase::readPercepts(), CLogAnalyzerBase::readRemoteCamWorldState(), CLogAnalyzerBase::readWorldState(), LogPlayer::saveAMV(), LogPlayer::saveCSV(), LogPlayer::saveImages(), and LogPlayer::saveSynchronized().

OutMessage MessageQueue::out

| An interface for writing messages to the queue. Definition at line 56 of file MessageQueue.h. Referenced by copyMessage(), operator>>(), Process::processMain(), LogPlayer::saveSynchronized(), and setPlayerForNewMessages().

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

- Tools/MessageQueue/MessageQueue.h
- Tools/MessageQueue/MessageQueue.cpp