libglass::Packet Class Reference

#include <packet.h>

List of all members.

Public Member Functions

 Packet ()
virtual ~Packet ()
void setData (unsigned char *data, unsigned int length)
void setData (const char *data, unsigned int length)
void setData (chain &s)
void appendData (unsigned char *data, unsigned int length)
void appendData (const char *data, unsigned int length)
void appendData (string &s)
void appendData (chain &s)
unsigned int getDataLength (void) const
void getData (chain &s)
void setPluginId (PluginId id)
PluginId getPluginId (void) const
void setTargetNodes (nodeId id)
void setTargetNodes (std::set< nodeId > &id_set)
void setTargetNodes (std::vector< nodeId > &id_set)
void addTargetNodes (nodeId id)
void addTargetNodes (std::set< nodeId > &id_set)
std::set< nodeId > & getTargetNodes (void)
void clearTargetNodes (void)
void setSenderNode (nodeId id)
bool isReliable (void) const
void setReliable (bool reliable)
nodeId getSenderNode (void) const
void setTargetFDs (nodeFD fd)
void setTargetFDs (std::set< nodeFD > &fds)
std::set< nodeFD > & getTargetFDs (void)
virtual chain encode (unsigned int *len=NULL)
bool decode (chain &s)
bool decode (unsigned char *buffer, unsigned int length)
bool decode (unsigned char *header, unsigned int headerlen, unsigned char *databuf, unsigned int datalen)
virtual std::ostream & print (std::ostream &o)

Friends

class Glass
class Protocol
std::ostream & operator<< (std::ostream &o, Packet &p)


Detailed Description

Definition at line 34 of file packet.h.


Constructor & Destructor Documentation

libglass::Packet::Packet (  ) 

Constructor.

virtual libglass::Packet::~Packet (  )  [virtual]

Destructor.


Member Function Documentation

void libglass::Packet::addTargetNodes ( std::set< nodeId > &  id_set  ) 

Sets the target node id field.

Parameters:
id_set The target node ids set.
See also:
getTargetNodes().

void libglass::Packet::addTargetNodes ( nodeId  id  ) 

Sets the target node id field.

Parameters:
id The target node id.
See also:
getTargetNodes().

void libglass::Packet::appendData ( chain s  ) 

void libglass::Packet::appendData ( string s  ) 

void libglass::Packet::appendData ( const char *  data,
unsigned int  length 
)

Appends to the data field.

Parameters:
data The data. May contain '\0's.
length The length of data.
See also:
setData().

void libglass::Packet::appendData ( unsigned char *  data,
unsigned int  length 
)

Appends to the data field.

Parameters:
data The data. May contain ''s.
length The length of data.
See also:
setData().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
s The data.

void libglass::Packet::clearTargetNodes ( void   ) 

Clears the list of target nodes.

See also:
setTargetNodes(), addTargetNodes().

bool libglass::Packet::decode ( unsigned char *  header,
unsigned int  headerlen,
unsigned char *  databuf,
unsigned int  datalen 
)

bool libglass::Packet::decode ( unsigned char *  buffer,
unsigned int  length 
)

bool libglass::Packet::decode ( chain s  ) 

Decodes a string to a packet.

The from field (which you can get with getSenderNode()) is set with the id of the sender.

The target field (getTargetNode()) is NOT set, and its value is meaningless. This behaviour may change in future versions.

The caller should always pass a valid packet, but checks are made to avoid buffer security attacks. If the packet does not pass these tests, false is returned. Obviously, no checks are made on the data field.

Parameters:
s The data to decode.
Return values:
true If correctly decoded. This doesn't mean that the values are meaningful.
false Otherwise.
See also:
encode().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
buffer The buffer to decode
length The buffer length.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
header The packet header. User is responsible for freeing this buffer.
headerlen The header length.
databuf The data packet. This buffer is freed by libGlass.
datalen The data packet length.

virtual chain libglass::Packet::encode ( unsigned int *  len = NULL  )  [virtual]

Encodes the packet to a string that can be sent over the network.

The from field (which you can get with getSenderNode()) is automatically set. You must set the target node, since the default is nobodyId.

See also:
decode().
Parameters:
len A pointer to a variable.
Returns:
The encoded data, and the total length in the len argument, if not NULL.

void libglass::Packet::getData ( chain s  ) 

Gets data.

See also:
setData(), appendData(), getDataLength().

unsigned int libglass::Packet::getDataLength ( void   )  const

Gets data length.

See also:
setData(), appendData(), getData().
Returns:
The data length.

PluginId libglass::Packet::getPluginId ( void   )  const

Gets the plugin id field.

Returns:
The plugin id.
See also:
setPluginId().

nodeId libglass::Packet::getSenderNode ( void   )  const

Gets the sender node id field.

Returns:
The target node id.
See also:
setSenderNodes().

std::set<nodeFD>& libglass::Packet::getTargetFDs ( void   ) 

std::set<nodeId>& libglass::Packet::getTargetNodes ( void   ) 

Gets the target node list.

Returns:
The target node id.
See also:
setTargetNodes(), addTargetNodes().

bool libglass::Packet::isReliable ( void   )  const

Sets if this packet must be sent reliably (i.e., guaranteeing delivery) or not.

See the protocol documentation to see if this field is supported. Not all protocols may support this flag.

Returns:
true if is a reliable packet, false otherwise.

virtual std::ostream& libglass::Packet::print ( std::ostream &  o  )  [virtual]

A nice outputter, for debugging purposes.

void libglass::Packet::setData ( chain s  ) 

void libglass::Packet::setData ( const char *  data,
unsigned int  length 
)

Sets the data field.

Parameters:
data The data. May contain '\0's.
length The length of data.

void libglass::Packet::setData ( unsigned char *  data,
unsigned int  length 
)

Sets the data field.

Parameters:
data The data. May contain ''s.
length The length of data.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
s The data.

void libglass::Packet::setPluginId ( PluginId  id  ) 

Sets the plugin id field.

Parameters:
id The plugin id.
See also:
getPluginId().

void libglass::Packet::setReliable ( bool  reliable  ) 

Sets if this packet must be sent reliably (i.e., guaranteeing delivery) or not.

See the protocol documentation to see if this field is supported.

Parameters:
reliable True if it must, false otherwise.

void libglass::Packet::setSenderNode ( nodeId  id  ) 

Sets the sender node id field.

Parameters:
id The sender node id.
See also:
setSenderNode().

void libglass::Packet::setTargetFDs ( std::set< nodeFD > &  fds  ) 

Parameters:
fds 

void libglass::Packet::setTargetFDs ( nodeFD  fd  ) 

Parameters:
fd 

void libglass::Packet::setTargetNodes ( std::vector< nodeId > &  id_set  ) 

Sets the target node id field.

Parameters:
id_set The target node ids set.
See also:
getTargetNodes().

void libglass::Packet::setTargetNodes ( std::set< nodeId > &  id_set  ) 

Sets the target node id field.

Parameters:
id_set The target node ids set.
See also:
getTargetNodes().

void libglass::Packet::setTargetNodes ( nodeId  id  ) 

Sets the target node id field.

Parameters:
id The target node id.
See also:
getTargetNodes().


Friends And Related Function Documentation

friend class Glass [friend]

Definition at line 45 of file packet.h.

std::ostream& operator<< ( std::ostream &  o,
Packet p 
) [friend]

friend class Protocol [friend]

Definition at line 46 of file packet.h.


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

Generated on Fri May 28 13:19:01 2010 for libGlass by  doxygen 1.5.8