Main Page | Class Hierarchy | Class List | File List | Class Members

Packet Class Reference

A Packet class. More...

#include <common.h>

List of all members.

Public Member Functions

 Packet (int buffer_length)
int fillPayload (int size, char *inputstream)
char * getPayload ()
void setPayloadSize (int size)
int getBufferSize ()
int getPayloadSize ()

Static Public Attributes

static const int DEFAULT_PAYLOAD_SIZE = 512


Detailed Description

A Packet class.

Packet is an entity which contains a set of ordered information bits. This packet object only carries a pointer to payload information, not any socket address information.

Definition at line 29 of file common.h.


Constructor & Destructor Documentation

Packet::Packet int  buffer_length  ) 
 

Alternate Packet Constructor: Specify a large buffer.... This is useful to define a packet receiving buffer.

Definition at line 22 of file common.cpp.

00023 {
00024   size_ = 0;
00025   length_ = buffer_length;
00026   payload_ = new char[buffer_length];
00027 }


Member Function Documentation

int Packet::fillPayload int  size,
char *  inputstream
 

A function to fill payload. user can specify the content of payload for applications like audio/video playback...

Definition at line 53 of file common.cpp.

References setPayloadSize().

Referenced by ReceivingPort::receivePacket().

00054 {
00055   setPayloadSize(size);
00056   if (memcpy((char *)payload_, (char *)inputstream,  size) == NULL) {
00057     throw "Fill payload Failed";
00058   }
00059   return 0;
00060 }

int Packet::getBufferSize  )  [inline]
 

get the size of packet buffer where payload is stored.

Definition at line 47 of file common.h.

00047 {return length_;}

char* Packet::getPayload  )  [inline]
 

get a pointer to the payload

Returns:
a char pointer

Definition at line 42 of file common.h.

Referenced by SendingPort::sendPacket().

00042 { return payload_;} 

int Packet::getPayloadSize  )  [inline]
 

get the size of the packet

Definition at line 51 of file common.h.

Referenced by SendingPort::sendPacket().

00051 { return size_;}

void Packet::setPayloadSize int  size  ) 
 

set packet size. As packet already has a default buffer, there are two ways to determine the payload

  • set size only, let the payload be as it is --> SetPayloadSize
    1. if necessary, adjust the payload buffer size.
  • set size and also fill the payload with speficic data (e.g. for Audio and Video Applications...)
    See also:
    fillPayload

Definition at line 39 of file common.cpp.

Referenced by fillPayload().

00040 {
00041   size_ =  size;
00042   if (size > length_) {
00043     if (payload_ != NULL) delete [] payload_;
00044     length_ = (int)(1.5 * size);
00045     payload_ =  new char[length_];
00046   }
00047 }


Member Data Documentation

const int Packet::DEFAULT_PAYLOAD_SIZE = 512 [static]
 

Default payload size is 512 Bytes

Definition at line 35 of file common.h.


The documentation for this class was generated from the following files:
Generated on Thu Jan 26 17:08:01 2006 for Common_Classes_Projects_ECE544 by  doxygen 1.4.2