Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

FrameworkPacket Class Reference
[GanefCommon]

This class is a UDP-packet, partly read by the framework, This gives us some knowledge of what is inside the packet. More...

#include <frameworkpacket.h>

Inheritance diagram for FrameworkPacket:

ClientPacket ServerPacket List of all members.

Readers

Exceptions:
PacketError is thrown if you try to read beyond the size of the packet.
The following methods are used when reading from a packet.

int readInt32 ()
unsigned int readUInt32 ()
short readInt16 ()
unsigned short readUInt16 ()
char readInt8 ()
unsigned char readUInt8 ()
float readFloat32 ()
double readDouble64 ()
bool readBool8 ()
void readData (void *dstbuff, unsigned int bytes)
std::string readString ()

Writers

Exceptions:
PacketError is thrown if you try to write beyond the hard-coded max-size of the packet.
The following methods are used when writing to a packet.

void writeInt32 (const int &i)
void writeInt16 (const short &i)
void writeInt8 (const char &i)
void writeUInt32 (const unsigned int &i)
void writeUInt16 (const unsigned short &i)
void writeUInt8 (const unsigned char &i)
void writeFloat32 (const float &f)
void writeDouble64 (const double &d)
void writeBool8 (const bool &b)
void writeString (const std::string &s)
void writeData (const void *srcdata, unsigned int bytes)
void appendData (FrameworkPacket *packet)
 Will append the data of the given packet to this packets data, using memcpy(...).
void writePacket (FrameworkPacket *packet)

Public Types

enum  PacketState {
  STATE_NEW = 1000, STATE_QUEUED_OUT = 1001, STATE_SENT = 1002, STATE_ABORTED = 1003,
  STATE_RECEIVED = 2000, STATE_QUEUED_IN = 2001, STATE_DELIVERED = 2002
}
 This enum is used to keep track of the state of the packet. More...
enum  SpecialReceivers {
  DUMMY_PACKET = 666, HANDSHAKE_INIT = 10001, DISCONTINUE_CLIENT = 10002, SETUP_DESCRIPTION = 10003,
  DISCONTINUE_SERVER = 10004, READY_CLIENT = 10005, PACKET_ACK = 20001, PACKET_HEARTBEAT = 30001
}
 Special constants used when sending system-packets. More...

Public Member Functions

 FrameworkPacket (char *data, unsigned int size)
 Constructor used when receiving packets.
 ~FrameworkPacket ()
 Destructor, will delete allocated "data" of the packet.
void copyData (FrameworkPacket *packet)
 Will copy the data from an other packet, this method relies on the fact that they are duplicates, hence you may not call this method unless the header of the two are identical.
unsigned int getSize () const
 Used when sending the packet, or receiving.
unsigned int getDataSize () const
 Used to get the size of the data only.
char * getData () const
 Used when sending the packet.
void setPeer (const ipaddress &host, const int port)
 Used when receiving or sending packets.
void setPeerFromPacket (FrameworkPacket *packet)
 Used to reply other packets.
virtual void makeSendReady ()=0
 This method makes the packet ready for sending (htonl(...) is called on header fields).
void setSequenceNumber (unsigned int seq_no)
 This sets the sequence number for the packet.
Header Status Methods
These methods are used to check things about what kind of packet this is, a lot of them are just convienent ways of combining checks on the header.

From header: reliable

bool isReliable () const
unsigned char getType () const
 From header: type.
unsigned char getPriority () const
 From header: priority.
unsigned int getReceiver () const
 From header: receiver.
unsigned int getSequenceNumber () const
 From header: packet_id.
bool isIncomming () const
 true if the packet is incomming
bool hasBeenSent () const
 return true if the packet has left the queue and entered the network.
bool isQueued () const
 Will return true if the last thing that happened to a packet was insertion into a queue.
bool isAborted () const
 Will return true if the packet has been aborted (this happens while in the out-queue).
bool isPluginPacket () const
 true if this packet is a plugin-packet
bool isHeartBeatPacket () const
bool isHandshakeInitPacket () const
bool isAckPacket () const
 Will return true if the packet is an ACK-packet.
Packet State Methods
These will change the state of the packet.

void setStateQueued ()
void setStateSent ()
void setStateAborted ()

Public Attributes

FrameworkPacket::PeerStruct peer
 This holds info about who the message is for or who it is from, depending on `incomming`.

Protected Member Functions

 FrameworkPacket (unsigned int receiver, unsigned char type=1, unsigned char priority=0, unsigned int bodysize=INITIAL_BODY_SIZE, bool reliable=false)
 Internal constructor: sets everything.
void resetPosition ()
 Will set the position to just after the header (ready for reading/writing).
void before_read_check (unsigned int s)
void before_write_check (unsigned int s)

Protected Attributes

char * data
 Pointer to the actual packet data.
unsigned int realsize
 Allocated size of the actual packet data.
unsigned int pos
 The internal position (when reading/writing).
PacketState state
 True if the packet is incomming, false otherwise.
bool packet_ready_to_transmit
 True if the Packet is ready to transmit (htonl/htons).
Headerheader

Friends

class PacketSender< class PacketType, class SocketType >
class Framework< class PacketType, class SocketType >
std::ostream & operator<< (std::ostream &o, FrameworkPacket &packet)
 Just a method for outputting a packet to standard out.

Classes

struct  Header
 Structure describing the "header" of the packet. More...
struct  PeerStruct
 This holds info about who the message is for or who it is from, depending on `incomming`. More...

Detailed Description

This class is a UDP-packet, partly read by the framework, This gives us some knowledge of what is inside the packet.

Here is the format of the packet:

header
[1 unsigned byte] reliable (0: unreliable, 1-255: reliable)
[1 unsigned byte] type (0:system, 1:plugin, 2:new object, 3:detroy object, 4-255: userdefined update of object)
[1 unsigned byte] priority (0: high, 255: low)
[32 bit unsigned int]receiver (plugin_id or object_id)
[32 bit unsigned int]packet_seq_number: used to determine if a packet should overwrite a new one, and to discard old packets that arrive very late.
body
unsigned char[size - sizeof(Header)]the actual data

Author:
Lars Langer and Emanuel Greisen

Definition at line 75 of file frameworkpacket.h.


Member Enumeration Documentation

enum FrameworkPacket::PacketState
 

This enum is used to keep track of the state of the packet.

Enumerator:
STATE_NEW  The packet has just been create (for sending).
STATE_QUEUED_OUT  The packet has been queued (for sending).
STATE_SENT  The packet has been sent (for sending).
STATE_ABORTED  The packet has been aborted (when we should send one of these, it is deleted instead).
STATE_RECEIVED  We just received this packet (Receiving side).
STATE_QUEUED_IN  We have queued the packet in the inqueue, ready to be handled in "keepAlive(...)" (Receiving side).
STATE_DELIVERED  The packet has been delivered to the ClientFramework (Receiving side).

Definition at line 83 of file frameworkpacket.h.

enum FrameworkPacket::SpecialReceivers
 

Special constants used when sending system-packets.

Enumerator:
DUMMY_PACKET  May never be sent (only used to write a packet for later appending it to a real packet).
HANDSHAKE_INIT  Used with handshaking.
DISCONTINUE_CLIENT  Used with handshaking.
SETUP_DESCRIPTION  Used with handshaking.
DISCONTINUE_SERVER  Used with handshaking.
READY_CLIENT  Used with handshaking.
PACKET_ACK  An ACK packet.
PACKET_HEARTBEAT  A Heartbeat packet.

Definition at line 138 of file frameworkpacket.h.


Member Function Documentation

void FrameworkPacket::before_read_check unsigned int  s  )  [protected]
 

Will check sanity of read.

Exceptions:
PacketError 

Definition at line 91 of file frameworkpacket.cpp.

References isIncomming(), pos, and realsize.

Referenced by readData(), ServerPacket::readPacket(), ClientPacket::readPacket(), and readString().

void FrameworkPacket::before_write_check unsigned int  s  )  [protected]
 

Will check sanity of write.

Exceptions:
PacketError 

Definition at line 99 of file frameworkpacket.cpp.

References data, header, isIncomming(), pos, and realsize.

Referenced by appendData(), writeData(), writePacket(), and writeString().


The documentation for this class was generated from the following files:
Generated on Mon Feb 6 12:24:52 2006 for Ganef by  doxygen 1.4.4