Main Page   Modules   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members   Related Pages  

GNE::PacketParser Namespace Reference
[Mid-Level API]


Compounds

struct  PacketFuncs

Typedefs

typedef Packet *(* PacketCreateFunc )()
 A function pointer to a function that creates a new subclass of a Packet.

typedef Packet *(* PacketCloneFunc )(const Packet *)
 A function pointer to a function to clone a Packet.

typedef void(* PacketDestroyFunc )(Packet *)
 A function pointer to a function to destroy a Packet.


Functions

void registerGNEPackets ()
void registerPacket (guint8 id, PacketCreateFunc createFunc, PacketCloneFunc cloneFunc, PacketDestroyFunc destroyFunc)
 Registers a new type of packet, so GNE can recognize it.

PacketcreatePacket (guint8 id)
 Calls the packet creation function registered for the given ID.

PacketclonePacket (const Packet *p)
 Calls the packet clone function registered for the passed packet type.

void destroyPacket (Packet *p)
 Calls the packet deletion function registered for the passed packet type.

PacketparseNextPacket (Buffer &raw)
 Parses the next packet from the given Buffer.

template<class T> PacketdefaultPacketCreateFunc ()
 Default packet creation function using the "new" operator and the default constructor.

template<class T> PacketdefaultPacketCloneFunc (const Packet *p)
 Default packet clone function using the "new" operator and the copy constructor.

template<class T> void defaultPacketDestroyFunc (Packet *p)
 Default packet destroy function using the "delete" operator.

template<class T> void defaultRegisterPacket ()
 Default registration function that works for typical packets without any custom memory allocation.


Variables

const guint8 MIN_USER_ID = 16
 The first number suitable for the user to give IDs to their packets.

const guint8 MAX_USER_ID = 254
const guint8 END_OF_PACKET = 255
 The network packet ends with this byte, meaning that no more GNE packets exist in this network packet (end-of-data).


Detailed Description

A namespace containing functions handling the parsing of packets. Also contains important constants to be aware of for assigning your packets IDs.


Typedef Documentation

typedef Packet*(* GNE::PacketParser::PacketCloneFunc)( const Packet* )
 

A function pointer to a function to clone a Packet.

NULL must not be passed into this function. The passed Packet must be of the type registered with this function.

typedef Packet*(* GNE::PacketParser::PacketCreateFunc)()
 

A function pointer to a function that creates a new subclass of a Packet.

The return type is of the type registered with this function.

typedef void(* GNE::PacketParser::PacketDestroyFunc)( Packet* )
 

A function pointer to a function to destroy a Packet.

The passed Packet must be of the type registered with this function.


Function Documentation

Packet * GNE::PacketParser::clonePacket const Packet p  ) 
 

Calls the packet clone function registered for the passed packet type.

This is based on the Packet::getType() method.

Packet * GNE::PacketParser::createPacket guint8  id  ) 
 

Calls the packet creation function registered for the given ID.

The ID passed MUST be registered.

template<class T>
void defaultRegisterPacket  ) 
 

Default registration function that works for typical packets without any custom memory allocation.

This function is a template, and is equivalent to:

registerPacket( T::id, defaultPacketCreateFunc<T>, defaultPacketCloneFunc<T>, defaultPacketDestroyFunc<T> );

void GNE::PacketParser::destroyPacket Packet p  ) 
 

Calls the packet deletion function registered for the passed packet type.

This is based on the Packet::getType() method.

Packet * GNE::PacketParser::parseNextPacket Buffer raw  ) 
 

Parses the next packet from the given Buffer.

Returns NULL if no more packets remain in the Buffer.

Exceptions:
Error if the next packet's type is unknown, or an error occurs during the readPacket method.
Returns:
a newly allocated Packet of the type of the next packet in the Buffer, else NULL on end of Buffer.

void GNE::PacketParser::registerGNEPackets  ) 
 

Todo:
GNE authors -- don't forget to add additional packets to this function as GNE expands.

void GNE::PacketParser::registerPacket guint8  id,
PacketCreateFunc  createFunc,
PacketCloneFunc  cloneFunc,
PacketDestroyFunc  destroyFunc
 

Registers a new type of packet, so GNE can recognize it.

In order for GNE to recognize, create, and parse your packets derived from the Packet class, you should register it here, preferably right after initalizing GNE.

You can only register packets from MIN_USER_ID to MAX_USER_ID, inclusive. You may not register a packet multiple times.

Unless you want to create your own memory allocation system, you should consider using the defaultRegisterPacket function.


Variable Documentation

const guint8 GNE::PacketParser::MAX_USER_ID = 254
 

See also:
MIN_USER_ID

const guint8 GNE::PacketParser::MIN_USER_ID = 16
 

The first number suitable for the user to give IDs to their packets.

Any numbers between MIN_USER_ID and MAX_USER_ID inclusive belong to the user. It is suggested that the user assign packet numbers by adding to MIN_USER_ID. (i.e. MIN_USER_ID + 5)


Generated on Fri Aug 22 13:40:07 2003 for GNE by doxygen1.3