root/juggler/branches/2.2/modules/gadgeteer/cluster/Packets/DataPacket.cpp

Revision 19729, 4.1 kB (checked in by patrick, 2 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2007 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  *************** <auto-copyright.pl END do not edit this line> ***************/
26
27 #include <gadget/gadgetConfig.h>
28 #include <boost/concept_check.hpp>
29 #include <gadget/Util/Debug.h>
30
31 #include <cluster/Packets/DataPacket.h>
32 #include <cluster/Packets/PacketFactory.h>
33
34 #include <vpr/System.h>
35 #include <vpr/Util/Assert.h>
36
37
38 namespace cluster
39 {
40    CLUSTER_REGISTER_CLUSTER_PACKET_CREATOR(DataPacket);
41    
42    DataPacket::DataPacket() : mDeviceData(NULL)
43    {;}
44
45    DataPacket::DataPacket(const vpr::GUID& plugin_id, const vpr::GUID& object_id, std::vector<vpr::Uint8>* data)
46          : mObjectId(object_id), mDeviceData(data)
47    {     
48       mPluginId = plugin_id;
49
50       // Create a Header for this packet with the correect type and size.
51       mHeader = new Header(Header::RIM_PACKET,
52                                       Header::RIM_DATA_PACKET,
53                                       Header::RIM_PACKET_HEAD_SIZE
54                                        + 16 /*Plugin GUID*/
55                                        + 16 /*Plugin GUID*/
56                                        + mDeviceData->size(),
57                                       0/*Field not curently used*/);
58       // Serialize the given data.
59       serialize();
60    }
61
62    void DataPacket::serialize()
63    {
64       // Clear the data stream.
65       mPacketWriter->getData()->clear();
66       mPacketWriter->setCurPos(0);
67
68       // Serialize the header.
69       mHeader->serializeHeader();
70      
71       // Serialize plugin GUID.
72       mPluginId.writeObject(mPacketWriter);
73      
74       // Serialize device GUID.
75       mObjectId.writeObject(mPacketWriter);
76      
77       // mDeviceData is a pointer that points at the DeviceData located in the DeviceServer
78       // this data will be updated every frame before sent.
79    }
80
81    void DataPacket::parse(vpr::BufferObjectReader* reader)
82    {
83       // De-Serialize plugin GUID
84       mPluginId.readObject(reader);
85
86       // De-Serialize plugin GUID
87       mObjectId.readObject(reader);
88            
89       mDeviceData = new std::vector<vpr::Uint8>();
90
91       unsigned int data_size = mHeader->getPacketLength() - Header::RIM_PACKET_HEAD_SIZE - 32;
92       for(unsigned int i = 0 ; i < data_size ; i++)
93       {
94          mDeviceData->push_back(*(reader->readRaw(1)));
95       }
96    }
97
98    void DataPacket::printData(int debug_level)
99    {
100       // NOTE: This should be removed if any of the below code ever puts
101       // debug_level to use.
102       
103       boost::ignore_unused_variable_warning(debug_level);
104      
105       /*
106       vprDEBUG_BEGIN(gadgetDBG_RIM,debug_level)
107          <<  clrOutBOLD(clrYELLOW,"==== Device Data Packet ====\n") << vprDEBUG_FLUSH;
108       
109       Packet::printData(debug_level);
110
111       vprDEBUG(gadgetDBG_RIM,debug_level)
112          << clrOutBOLD(clrYELLOW, "Plugin ID: ") << mPluginId.toString()
113          << std::endl << vprDEBUG_FLUSH;
114       vprDEBUG(gadgetDBG_RIM,debug_level)
115          << clrOutBOLD(clrYELLOW, "Object ID: ") << mObjectId.toString()
116          << std::endl << vprDEBUG_FLUSH;
117
118       vprDEBUG_END(gadgetDBG_RIM,debug_level)
119          <<  clrOutBOLD(clrYELLOW,"============================\n") << vprDEBUG_FLUSH;
120       */
121    } 
122 }// end namespace cluster
123
Note: See TracBrowser for help on using the browser.