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