EventHelix.com: CASE Tools; Real-time and Embedded System Design; Object Oriented Design EventStudio 2.0: System Engineering CASE ToolEventStudio 2.5
Sequence diagram based system design and modeling
Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Message_Queue Class Reference

#include <Message_Queue.h>

List of all members.


Detailed Description

This class demonstrates the use of the STL queue container adaptor in implementing a message queue.

Message Queues are a very important design pattern in embedded and real-time systems. Here we implement the Message Queue class as a very thin wrapper over the STL queue container adaptor.

STL queue container adaptor supports the standard queue operations, viz. add to queue, remove from queue. STL allows you to specify the underlying container used for implementing the queue. By changing one line of code you could change from a linked list implementation to an array like double ended queue In this example we will be implementing the queue using the list. This organizes the message queue as a linked list of nodes containing pointers to the message.

Definition at line 28 of file Message_Queue.h.

Public Member Functions

void Add (Message *pMsg)
 Add a message to the end of the queue.

Message * Remove ()
 Remove a message from the head of the queue.

int GetLength () const
 Obtain the length of the queue.


Private Types

typedef queue< Message *,
list< Message * > > 
MsgQueType
 Declaring the type for a queue.


Private Attributes

MsgQueType m_msgQueue
 Declaration of the message queue based on the type declaration MsgQueType.


Member Typedef Documentation

typedef queue<Message *, list<Message *> > Message_Queue::MsgQueType [private]
 

Declaring the type for a queue.

Here we are specifying a queue of message pointers organized as a linked list.

Definition at line 32 of file Message_Queue.h.


Member Function Documentation

void Message_Queue::Add Message * pMsg  ) [inline]
 

Add a message to the end of the queue.

The push method supported by queue is used to add the message to the end of the queue. Note that all the memory management associated with the queue container management is taken care by STL.

Parameters:
pMsg Pointer to the message that needs to be added to the queue.

Definition at line 44 of file Message_Queue.h.

00045    {
00046       // Insert the element at the end of the queue
00047       m_msgQueue.push(pMsg);
00048    }

Message* Message_Queue::Remove  ) [inline]
 

Remove a message from the head of the queue.

Returns NULL if no message is found. This method performs the following steps:

  • Make sure that the queue is not empty
  • If so, get a pointer to the message at the head of the queue.
  • Now pop the message out of the queue.

retval Message Pointer to the message removed from the queue. Returns NULL if no message is found in the queue.

Definition at line 60 of file Message_Queue.h.

00061    {
00062       Message *pMsg = NULL;
00063       
00064       // Check if the message queue is not empty
00065       if (!m_msgQueue.empty())
00066       {
00067          // Queue is not empty so get a pointer to the
00068          // first message in the queue
00069          pMsg = m_msgQueue.front();
00070          
00071          // Now remove the pointer from the message queue
00072          m_msgQueue.pop();
00073       }
00074       return pMsg;
00075    }

int Message_Queue::GetLength  ) const [inline]
 

Obtain the length of the queue.

The size method is used to obtain the queue length.

Return values:
int Total number of messages in the queue.

Definition at line 80 of file Message_Queue.h.

00081    {
00082       return m_msgQueue.size();
00083    }   


The documentation for this class was generated from the following file:
Generated on Sun Feb 13 21:30:33 2005 for Object Oriented Design Examples by doxygen 1.3.4
 Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved.