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