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_Packet.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00031 
00032 #ifndef PROTOCOL_PACKET_H
00033 #define PROTOCOL_PACKET_H
00034 
00035 class Protocol_Packet
00036 {
00039     enum { MAXIMUM_PACKET_LENGTH = 1500};
00040 
00042     struct Region
00043     {
00046         int offset;
00047 
00049         int length;
00050     };
00051 
00054     Region m_header;
00055 
00058     Region m_body;
00059 
00062     Region m_trailer;
00063 
00066     char m_buffer[MAXIMUM_PACKET_LENGTH];
00067 public:
00068 
00094 
00095     Protocol_Packet(int body_Length, int body_Offset)
00096     {
00097         m_header.length = 0;
00098         m_trailer.length = 0;
00099         m_body.offset = body_Offset;
00100         m_body.length = body_Length;
00101     }
00102 
00112 
00113     void Add_Header(int length)
00114     {
00115         // Consider the header of the higher layer to be a part of
00116         // the body for the this layer.
00117         m_body.offset -= m_header.length;
00118         m_body.length += m_header.length;
00119 
00120         // Save the length and header offset of the new layer. Addition
00121         // of the header would move up the header offset.
00122         m_header.length = length;
00123         m_header.offset = m_body.offset - length;      
00124     }
00125 
00134 
00135     void Add_Trailer(int length)
00136     {
00137         // Consider the trailer of the higher layer to be a part of
00138         // the body of this layer.
00139         m_body.length += m_trailer.length;
00140 
00141         // Now add the trailer at the end of the updated body.
00142         m_trailer.length = length;
00143         m_trailer.offset = m_body.offset + m_body.length;
00144     }
00145 
00156 
00157     void Extract_Header(int length)
00158     {
00159         // Update the new header. The header begins at current
00160         // body start offset.
00161         m_header.offset = m_body.offset;
00162         m_header.length = length;
00163 
00164         // Reduce the body size to account for the removed header.
00165         m_body.offset += length;
00166         m_body.length -= length;
00167     }
00168 
00177 
00178     void Extract_Trailer(int length)
00179     {
00180         // Reduce the length to adjust for the extracted trailer.
00181         m_body.length -= length;
00182 
00183         // Setup the trailer to start at the end of the body.
00184         m_trailer.offset = m_body.offset + m_body.length;
00185         m_trailer.length = length;
00186     }
00187 
00189     char *Get_Header()
00190     {
00191         return (&m_buffer[m_header.offset]);
00192     }
00193 
00195     char *Get_Body()
00196     {
00197         return (&m_buffer[m_body.offset]);
00198     }
00199 
00201     char *Get_Trailer()
00202     {
00203         return (&m_buffer[m_trailer.offset]);
00204     }
00205 
00208     int Get_Length()
00209     {
00210         return (m_header.length + m_body.length + m_trailer.length);
00211     }
00212 };
00213 
00214 #endif

Generated on Sun Feb 13 21:30:17 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.