| EventStudio 2.5 Sequence diagram based system design and modeling | |
#include <Packet_Queue.h> Inheritance diagram for Packet_Queue< Packet >:

Packet Queues are a very important design pattern in embedded and real-time systems. Here we implement the Packet 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 29 of file Packet_Queue.h.
Public Member Functions | |
| void | Add (Packet *p_Packet) |
| Add a message to the end of the queue. | |
| Packet * | Remove () |
| Remove a message from the head of the queue. | |
| size_t | Get_Length () const |
| Obtain the length of the queue. | |
Private Types | |
| typedef queue< Packet *, list< Packet * > > | Packet_Queue_Type |
| Declaring the type for a queue. | |
Private Attributes | |
| Packet_Queue_Type | m_packet_Queue |
| Declaration of the message queue based on the type declaration Packet_Queue_Type. | |
| |||||
Declaring the type for a queue. Here we are specifying a queue of message pointers organized as a linked list. Definition at line 33 of file Packet_Queue.h. |
| ||||||||||
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.
Definition at line 45 of file Packet_Queue.h. 00046 {
00047 // Insert the element at the end of the queue
00048 m_packet_Queue.push(p_Packet);
00049 }
|
| |||||||||
Remove a message from the head of the queue. Returns NULL if no message is found. This method performs the following steps:
retval Packet Pointer to the message removed from the queue. Returns NULL if no message is found in the queue. Definition at line 61 of file Packet_Queue.h. 00062 {
00063 Packet *p_Packet = NULL;
00064
00065 // Check if the message queue is not empty
00066 if (!m_packet_Queue.empty())
00067 {
00068 // Queue is not empty so get a pointer to the
00069 // first message in the queue
00070 p_Packet = m_packet_Queue.front();
00071
00072 // Now remove the pointer from the message queue
00073 m_packet_Queue.pop();
00074 }
00075 return p_Packet;
00076 }
|
| |||||||||
Obtain the length of the queue. The size method is used to obtain the queue length.
Definition at line 81 of file Packet_Queue.h. 00082 {
00083 return m_packet_Queue.size();
00084 }
|
1.3.4 | |
| Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved. |