OverSim
RealWorldTestPacketParser Class Reference

A message parser for RealWorldTestMessages. More...

#include <RealWorldTestPacketParser.h>

Inheritance diagram for RealWorldTestPacketParser:
PacketParser

Public Member Functions

char * encapsulatePayload (cPacket *msg, unsigned int *length)
 Convert a cMessage to a data block for sending it to the tun device.
cPacket * decapsulatePayload (char *buf, unsigned int length)
 Parses a block of data received from the tun device.
- Public Member Functions inherited from PacketParser
virtual void initialize ()
 Called on initialisation.
virtual void handleMessage (cMessage *msg)
 Is called if the modules receives a message.

Detailed Description

A message parser for RealWorldTestMessages.

Author
Stephan Krause

Definition at line 40 of file RealWorldTestPacketParser.h.

Member Function Documentation

cPacket * RealWorldTestPacketParser::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
bufThe data to be parsed
lengthThe length of the data
Returns
A cMessage containing the parsed data

Implements PacketParser.

Definition at line 40 of file RealWorldTestPacketParser.cc.

{
buf[length-1] = 0;
msg->setMsg(buf);
return msg;
}
char * RealWorldTestPacketParser::encapsulatePayload ( cPacket *  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
msgA pointer to the message to be converted
lengthA pointer to an integer that will hold the length of the data
Returns
A pointer to the converted data

Implements PacketParser.

Definition at line 30 of file RealWorldTestPacketParser.cc.

{
const char* data = dynamic_cast<RealWorldTestMessage*> (msg)->getMsg();
*length = strlen(data)+1;
char* buf = new char[*length];
strncpy(buf, data, *length);
buf[*length-1] = '\n';
return buf;
}

The documentation for this class was generated from the following files: