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

Protocol_Stack Class Reference

#include <Protocol_Stack.h>

Collaboration diagram for Protocol_Stack:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Protocol Stack class supports definition of a layered stack of protocol layers.

Protocol Stack on the fly addition and deletion of protocol layers (defined by the Protocol_Layer class). This flexibile layering architecture has several advantages:

See also:
Protocol Stack Design Pattern

Definition at line 36 of file Protocol_Stack.h.

Public Types

enum  Placement
 Specifies if the new layer has to be added before or after the existing layer.


Public Member Functions

void Handle_Transmit (Protocol_Packet *p_Packet)
 This handler is invoked by the application to transmit messages using the protocol stack.

void Handle_Receive (Protocol_Packet *p_Packet)
 This handler is invoked by the device to pass received messages to the protocol stack.

void Add_Layer (Protocol_Layer *p_Layer, Placement placement=TOP, Protocol_Layer *p_Existing_Layer=NULL)
 Add a protocol layer at a specific position in the protocol stack.

void Remove_Layer (Protocol_Layer *p_Layer)
 Remove a layer from the protocol stack.

 Protocol_Stack ()
 Create a protocol stack.


Private Attributes

Protocol_Layerm_p_Highest_Layer
 The highest layer present in the protocol stack.

Protocol_Layerm_p_Lowest_Layer
 The lowest layer present in the protocol stack.


Constructor & Destructor Documentation

Protocol_Stack::Protocol_Stack  ) 
 

Create a protocol stack.

The stack is created with no layers. Layers should be added using the Add_Layer method.

Definition at line 202 of file Protocol_Stack.cpp.

00203 {
00204     m_p_Highest_Layer = NULL;
00205     m_p_Lowest_Layer = NULL;
00206 }


Member Function Documentation

void Protocol_Stack::Handle_Transmit Protocol_Packetp_Packet  ) 
 

This handler is invoked by the application to transmit messages using the protocol stack.

Protocol packets received from the application are passed to the highest protocol layer. The highest layer will pass the packets to the lower layers. Finally, the lowest layer will transmit the packet to the device.

Parameters:
p_Packet Application packet that needs to be transmitted using the Protocol Stack.
See also:
Protocol Stack Design Pattern

Definition at line 22 of file Protocol_Stack.cpp.

00023 {
00024     if (m_p_Highest_Layer)
00025     {
00026         m_p_Highest_Layer->Transmit(p_Packet);
00027     }
00028 }

void Protocol_Stack::Handle_Receive Protocol_Packetp_Packet  ) 
 

This handler is invoked by the device to pass received messages to the protocol stack.

Protocol packets received from the device are passed to the lowest layer protocol layer. The lowest layer will pass the packets to the higher layers. Finally, the highest layer will pass on the received packet to the application.

Parameters:
p_Packet Received device level packet that needs to be processed by the Protocol Stack before passing it to the application.
See also:
Protocol Stack Design Pattern

Definition at line 40 of file Protocol_Stack.cpp.

00041 {
00042     if (m_p_Lowest_Layer)
00043     {
00044         m_p_Lowest_Layer->Handle_Receive(p_Packet);
00045     }
00046 }

void Protocol_Stack::Add_Layer Protocol_Layerp_Layer,
Placement placement = TOP,
Protocol_Layerp_Existing_Layer = NULL
 

Add a protocol layer at a specific position in the protocol stack.

This method supports addition of a protocol layer in following ways:

  • Add a layer at the top of the stack.
  • Add a layer above an existing layer.
  • Add a layer below an existing layer.

The method maintains a doubly linked list of layers. The layer is inserted according to the specified placement.

Parameters:
p_Layer Protocol layer to be added.
placement Specifies if the new layer has to be added before or after the existing layer (specified in the third parameter). This parameter defaults to END.
p_Existing_Layer The reference protocol layer that identifies the placement of the new protocol layer. This parameter defaults to NULL.

Definition at line 62 of file Protocol_Stack.cpp.

00063 {
00064     // Start with a clean slate. Initialize the upper and lower protocol
00065     // layers to NULL. The pointers will be suitably initialized after insertion.
00066 
00067     p_Layer->Set_Lower_Layer(NULL);
00068     p_Layer->Set_Upper_Layer(NULL);
00069 
00070     // Check if some other layer is already present in the protocol stack. 
00071     // The placement processing applies only if this is not the first layer 
00072     // being added to the stack.
00073     if (m_p_Highest_Layer)
00074     {
00075         // This is not the first layer
00076 
00077         switch (placement)
00078         {
00079         case TOP:   // Add the layer at the top
00080             assert(p_Existing_Layer == NULL);
00081             m_p_Highest_Layer->Set_Upper_Layer(p_Layer);
00082             p_Layer->Set_Lower_Layer(m_p_Highest_Layer);
00083             m_p_Highest_Layer = p_Layer;
00084             break;
00085 
00086         case ABOVE: // Place the layer above the existing layer
00087             assert(p_Existing_Layer);
00088 
00089             Protocol_Layer *p_Previous_Upper_Layer;
00090 
00091             // Linking up the new layer above the existing layer
00092             p_Previous_Upper_Layer = p_Existing_Layer->Get_Upper_Layer();
00093             p_Layer->Set_Upper_Layer(p_Previous_Upper_Layer);
00094             p_Layer->Set_Lower_Layer(p_Existing_Layer);
00095             p_Existing_Layer->Set_Upper_Layer(p_Layer);
00096 
00097             // Check if the existing layer was the highest layer
00098             if (p_Existing_Layer == m_p_Highest_Layer)
00099             {
00100                 // If it was, make the new layer the highest layer
00101                 m_p_Highest_Layer = p_Layer;
00102             }
00103             else
00104             {
00105                 // Change the pointer of the existing layer's upper layer
00106                 // to point to the newly inserted layer.
00107                 p_Previous_Upper_Layer->Set_Lower_Layer(p_Layer);
00108             }
00109             break;
00110 
00111         case BELOW:    // Place the layer below the existing layer
00112 
00113             assert(p_Existing_Layer);
00114             Protocol_Layer *p_Previous_Lower_Layer;
00115 
00116             // Linking up the new layer below the existing layer
00117             p_Previous_Lower_Layer = p_Existing_Layer->Get_Lower_Layer();
00118             p_Layer->Set_Upper_Layer(p_Existing_Layer);
00119             p_Layer->Set_Lower_Layer(p_Previous_Lower_Layer);
00120             p_Existing_Layer->Set_Lower_Layer(p_Layer);
00121 
00122             // Check if the existing layer was the lowest layer
00123             if (p_Existing_Layer == m_p_Lowest_Layer)
00124             {
00125                 // If it was, make the new layer the lowest layer
00126                 m_p_Lowest_Layer = p_Layer;
00127             }
00128             else
00129             {
00130                 // Change the pointer of the existing layer's lower layer
00131                 // to point to the newly inserted layer.
00132                 p_Previous_Lower_Layer->Set_Upper_Layer(p_Layer);
00133             }
00134             break;
00135 
00136         }
00137     }
00138     else  // The highest layer is NULL
00139     {
00140         // This means that this is the first layer in the protocol stack.
00141         assert(p_Existing_Layer == NULL);
00142         m_p_Highest_Layer = p_Layer;
00143         m_p_Lowest_Layer = p_Layer;
00144     }
00145 }

void Protocol_Stack::Remove_Layer Protocol_Layerp_Layer  ) 
 

Remove a layer from the protocol stack.

The layer is removed from the doubly linked list of layers.

Parameters:
p_Layer The layer to be removed from the protocol stack.

Definition at line 151 of file Protocol_Stack.cpp.

00152 {
00153     // Check if the layer to be removed is the highest layer.
00154     if (p_Layer == m_p_Highest_Layer)
00155     {
00156         // Yes it is, so set the removed layer's lower layer as the highest layer
00157         // in the protocol stack.
00158         m_p_Highest_Layer = p_Layer->Get_Lower_Layer();
00159 
00160         // If this was not the only layer in the stack, set the
00161         // upper layer of this layer as NULL.
00162         if (m_p_Highest_Layer)
00163         {
00164             m_p_Highest_Layer->Set_Upper_Layer(NULL);
00165         }
00166     }
00167     else // Not the highest layer
00168     {
00169         // Stitch the upper layer to lower layer link after the layer is removed.
00170         (p_Layer->Get_Upper_Layer())->Set_Lower_Layer(p_Layer->Get_Lower_Layer());
00171     }
00172 
00173     // Check if the layer to be removed is the lowest layer.
00174     if (p_Layer == m_p_Lowest_Layer)
00175     {
00176         // Yes it is, so set the removed layer's upper layer as the lowest layer
00177         // in the protocol stack.
00178         m_p_Lowest_Layer = p_Layer->Get_Upper_Layer();
00179 
00180         // If this was not the only layer in the stack, set the
00181         // lower layer of this layer as NULL.
00182         if (m_p_Lowest_Layer)
00183         {
00184             m_p_Lowest_Layer->Set_Lower_Layer(NULL);
00185         }
00186     }
00187     else
00188     {
00189         // Stitch the lower layer to upper layer link after the layer is removed.
00190         (p_Layer->Get_Lower_Layer())->Set_Upper_Layer(p_Layer->Get_Upper_Layer());
00191     }
00192 
00193     // Set the upper and lower layer pointers of the removed layer as NULL.
00194     // This is a safety measure.
00195     p_Layer->Set_Lower_Layer(NULL);
00196     p_Layer->Set_Upper_Layer(NULL);
00197 }


Member Data Documentation

Protocol_Layer* Protocol_Stack::m_p_Highest_Layer [private]
 

The highest layer present in the protocol stack.

A NULL value specifies that no layers are present in the stack. Protocol packets received from the application are passed to the highest protocol layer. The highest layer will pass the packets to the lower layers.

Definition at line 61 of file Protocol_Stack.h.

Protocol_Layer* Protocol_Stack::m_p_Lowest_Layer [private]
 

The lowest layer present in the protocol stack.

A NULL value specifies that no layers are present in the stack. Protocol packets received from the device are passed to the lowest protocol layer. The lowest layer will pass the packets to the higher layers.

Definition at line 66 of file Protocol_Stack.h.


The documentation for this class was generated from the following files:
Generated on Sun Feb 13 21:30:35 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.