GenericPacketParser Class Reference

#include <GenericPacketParser.h>

Inheritance diagram for GenericPacketParser:

PacketParser List of all members.

Detailed Description

A message parser using the cMemCommBuffer to serialize cmessages.

Author:
Bernhard Heep


Public Member Functions

char * encapsulatePayload (cMessage *msg, unsigned int *length)
 Convert a cMessage to a data block for sending it to the tun device.
cMessage * decapsulatePayload (char *buf, unsigned int length)
 Parses a block of data received from the tun device.

Private Attributes

cNetCommBuffer commBuffer


Member Function Documentation

cMessage * GenericPacketParser::decapsulatePayload ( char *  buf,
unsigned int  length 
) [virtual]

Parses a block of data received from the tun device.

Pure virtual function, has to be implemented by inherited classes.

Parameters:
buf The data to be parsed
length The length of the data
Returns:
A cMessage containing the parsed data

Implements PacketParser.

00043 {
00044     commBuffer.reset();
00045     commBuffer.pack(buf, length);
00046     cMessage* msg;
00047 
00048     try {
00049         msg = check_and_cast<cMessage*>(commBuffer.unpackObject());
00050 //    } catch (cRuntimeError err) {
00051 //    FIXME:
00052 //    the above does, for some reason, not work. So we catch everyting, 
00053 //    which may prevent the simulation from terminating corectly while
00054 //    parsing a message.
00055     } catch (...) {
00056         ev << "GenericPacketParser: parsing of payload failed.\n";
00057         return NULL;
00058     }
00059     
00060     return msg;
00061 }

char * GenericPacketParser::encapsulatePayload ( cMessage *  msg,
unsigned int *  length 
) [virtual]

Convert a cMessage to a data block for sending it to the tun device.

Pure virtual function, has to be implemented by inherited classes.

Parameters:
msg A pointer to the message to be converted
length A pointer to an integer that will hold the length of the data
Returns:
A pointer to the converted data

Implements PacketParser.

00031 {
00032     commBuffer.reset();
00033     commBuffer.packObject(msg);
00034 
00035     *length = commBuffer.getMessageSize();    
00036     char* byte_buf = new char[*length];
00037     memcpy(byte_buf, commBuffer.getBuffer(), *length);
00038 
00039     return byte_buf;
00040 }


Member Data Documentation

cNetCommBuffer GenericPacketParser::commBuffer [private]


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:37:06 2007 for ITM OverSim by  doxygen 1.4.7