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

Revision 19729, 3.5 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/Util/Debug.h>
28 #include <cluster/Packets/ConnectionRequest.h>
29 #include <cluster/Packets/PacketFactory.h>
30
31 namespace cluster
32 {
33    CLUSTER_REGISTER_CLUSTER_PACKET_CREATOR(ConnectionRequest);
34
35    ConnectionRequest::ConnectionRequest(std::string host_name, vpr::Uint16 port)
36    {
37       // Set the local member variables using the given values.
38       mHostname = host_name;
39       mPort = port;
40            
41       // Create a Header for this packet with the correect type and size.
42       mHeader = new Header(Header::RIM_PACKET,
43                                       Header::RIM_CONNECTION_REQ,
44                                       Header::RIM_PACKET_HEAD_SIZE
45                                       + vpr::BufferObjectReader::STRING_LENGTH_SIZE
46                                       + mHostname.size()
47                                       + 2 /*mPort*/
48                                       ,0/*Field not curently used*/);
49       // Serialize the given data.
50       serialize();
51    }
52
53    void ConnectionRequest::serialize()
54    {
55       // Clear the data stream.
56       mPacketWriter->getData()->clear();
57       mPacketWriter->setCurPos(0);
58
59       // Serialize the header.
60       mHeader->serializeHeader();
61      
62       // Serialize the hostname of the requesting machine.
63       mPacketWriter->writeString(mHostname);
64                
65       // Serialize the listening port of the requesting machine
66       mPacketWriter->writeUint16(mPort);                 
67    }
68    
69    void ConnectionRequest::parse(vpr::BufferObjectReader* reader)
70    {
71       // De-Serialize the hostname of the requesting machine.
72       mHostname = reader->readString();
73          
74       // De-Serialize the listening port of the requesting machine
75       mPort = reader->readUint16();
76    }
77
78    void ConnectionRequest::printData(int debug_level)
79    {
80       vprDEBUG_BEGIN(gadgetDBG_RIM,debug_level)
81          <<  clrOutBOLD(clrYELLOW,"==== Connection Request Packet Data ====\n") << vprDEBUG_FLUSH;
82      
83       Packet::printData(debug_level);
84
85       vprDEBUG(gadgetDBG_RIM,debug_level)
86          << clrOutBOLD(clrYELLOW, "Host Name:    ") << mHostname
87          << std::endl << vprDEBUG_FLUSH;
88       vprDEBUG(gadgetDBG_RIM,debug_level)
89          << clrOutBOLD(clrYELLOW, "Port:         ") << mPort
90          << std::endl << vprDEBUG_FLUSH;
91
92       vprDEBUG_END(gadgetDBG_RIM,debug_level)
93          <<  clrOutBOLD(clrYELLOW,"========================================\n") << vprDEBUG_FLUSH;
94    }
95 }   // end namespace gadget
96
Note: See TracBrowser for help on using the browser.