cluster::DataPacket Class Reference

Cluster data packet. More...

#include <cluster/Packets/DataPacket.h>

Inheritance diagram for cluster::DataPacket:

Inheritance graph
[legend]
Collaboration diagram for cluster::DataPacket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DataPacket ()
 Default constructor used by the PacketFactory.
 DataPacket (const vpr::GUID &plugin_id, const vpr::GUID &object_id, std::vector< vpr::Uint8 > *data)
 Create a DataPacket to send raw data accross the network.
virtual ~DataPacket ()
 Clean up all unused memory.
void serialize ()
 Serializes member variables into a data stream.
virtual void parse (vpr::BufferObjectReader *reader)
 Parses the data stream into the local member variables.
virtual void printData (int debug_level)
 Print the data to the screen in a readable form.
vpr::GUID getObjectId ()
 Return the GUID of the object that we are sending raw data for.
std::vector< vpr::Uint8 > * getDeviceData ()
 Return a pointer to the raw data that we are sending across the network.

Static Public Member Functions

static vpr::Uint16 getPacketFactoryType ()
 Return the type of this packet.

Detailed Description

Cluster data packet.

Definition at line 50 of file DataPacket.h.


Constructor & Destructor Documentation

cluster::DataPacket::DataPacket (  ) 

Default constructor used by the PacketFactory.

Definition at line 48 of file DataPacket.cpp.

00048                           : mDeviceData(NULL)
00049    {;}

cluster::DataPacket::DataPacket ( const vpr::GUID &  plugin_id,
const vpr::GUID &  object_id,
std::vector< vpr::Uint8 > *  data 
)

Create a DataPacket to send raw data accross the network.

Parameters:
plugin_id GUID of the ClusterPlugin that should handle this packet.
object_id GUID of the object that we are acknowledging.
data Pointer to the raw data that we want to send across the network

Definition at line 51 of file DataPacket.cpp.

References cluster::Packet::mHeader, cluster::Packet::mPluginId, cluster::Header::RIM_DATA_PACKET, cluster::Header::RIM_PACKET, cluster::Header::RIM_PACKET_HEAD_SIZE, and serialize().

00052          : mObjectId(object_id), mDeviceData(data)
00053    {      
00054       mPluginId = plugin_id;
00055 
00056       // Create a Header for this packet with the correect type and size.
00057       mHeader = new Header(Header::RIM_PACKET,
00058                                       Header::RIM_DATA_PACKET,
00059                                       Header::RIM_PACKET_HEAD_SIZE 
00060                                        + 16 /*Plugin GUID*/
00061                                        + 16 /*Plugin GUID*/
00062                                        + mDeviceData->size(),
00063                                       0/*Field not curently used*/);
00064       // Serialize the given data.
00065       serialize();
00066    }

virtual cluster::DataPacket::~DataPacket (  )  [inline, virtual]

Clean up all unused memory.

Definition at line 73 of file DataPacket.h.

00074    {
00075       delete mDeviceData;
00076    }


Member Function Documentation

void cluster::DataPacket::serialize (  ) 

Serializes member variables into a data stream.

Definition at line 68 of file DataPacket.cpp.

References cluster::Packet::mHeader, cluster::Packet::mPacketWriter, cluster::Packet::mPluginId, and cluster::Header::serializeHeader().

Referenced by DataPacket().

00069    {
00070       // Clear the data stream.
00071       mPacketWriter->getData()->clear();
00072       mPacketWriter->setCurPos(0);
00073 
00074       // Serialize the header.
00075       mHeader->serializeHeader();
00076       
00077       // Serialize plugin GUID.
00078       mPluginId.writeObject(mPacketWriter);
00079       
00080       // Serialize device GUID.
00081       mObjectId.writeObject(mPacketWriter);
00082       
00083       // mDeviceData is a pointer that points at the DeviceData located in the DeviceServer
00084       // this data will be updated every frame before sent.
00085    }

void cluster::DataPacket::parse ( vpr::BufferObjectReader *  reader  )  [virtual]

Parses the data stream into the local member variables.

Implements cluster::Packet.

Definition at line 87 of file DataPacket.cpp.

References cluster::Header::getPacketLength(), cluster::Packet::mHeader, cluster::Packet::mPluginId, and cluster::Header::RIM_PACKET_HEAD_SIZE.

00088    {
00089       // De-Serialize plugin GUID
00090       mPluginId.readObject(reader);
00091 
00092       // De-Serialize plugin GUID
00093       mObjectId.readObject(reader);
00094             
00095       mDeviceData = new std::vector<vpr::Uint8>();
00096 
00097       unsigned int data_size = mHeader->getPacketLength() - Header::RIM_PACKET_HEAD_SIZE - 32;
00098       for(unsigned int i = 0 ; i < data_size ; i++)
00099       {
00100          mDeviceData->push_back(*(reader->readRaw(1)));
00101       }
00102    }

void cluster::DataPacket::printData ( int  debug_level  )  [virtual]

Print the data to the screen in a readable form.

Implements cluster::Packet.

Definition at line 104 of file DataPacket.cpp.

00105    {
00106       // NOTE: This should be removed if any of the below code ever puts
00107       // debug_level to use.
00108       
00109       boost::ignore_unused_variable_warning(debug_level);
00110       
00111       /*
00112       vprDEBUG_BEGIN(gadgetDBG_RIM,debug_level) 
00113          <<  clrOutBOLD(clrYELLOW,"==== Device Data Packet ====\n") << vprDEBUG_FLUSH;
00114       
00115       Packet::printData(debug_level);
00116 
00117       vprDEBUG(gadgetDBG_RIM,debug_level) 
00118          << clrOutBOLD(clrYELLOW, "Plugin ID: ") << mPluginId.toString()
00119          << std::endl << vprDEBUG_FLUSH;
00120       vprDEBUG(gadgetDBG_RIM,debug_level) 
00121          << clrOutBOLD(clrYELLOW, "Object ID: ") << mObjectId.toString()
00122          << std::endl << vprDEBUG_FLUSH;
00123 
00124       vprDEBUG_END(gadgetDBG_RIM,debug_level) 
00125          <<  clrOutBOLD(clrYELLOW,"============================\n") << vprDEBUG_FLUSH;
00126       */
00127    }  

static vpr::Uint16 cluster::DataPacket::getPacketFactoryType (  )  [inline, static]

Return the type of this packet.

Definition at line 96 of file DataPacket.h.

References cluster::Header::RIM_DATA_PACKET.

00097    {
00098       return(Header::RIM_DATA_PACKET);
00099    }

vpr::GUID cluster::DataPacket::getObjectId (  )  [inline]

Return the GUID of the object that we are sending raw data for.

Definition at line 104 of file DataPacket.h.

Referenced by gadget::RemoteInputManager::handlePacket().

00105    {
00106       return mObjectId;
00107    }

std::vector<vpr::Uint8>* cluster::DataPacket::getDeviceData (  )  [inline]

Return a pointer to the raw data that we are sending across the network.

Definition at line 112 of file DataPacket.h.

Referenced by gadget::RemoteInputManager::handlePacket(), and gadget::Node::send().

00113    {
00114       return mDeviceData;
00115    }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:44:21 2007 for Gadgeteer by  doxygen 1.5.1