00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <gadget/Util/Debug.h>
00034 #include <cluster/Packets/ConnectionRequest.h>
00035 #include <cluster/Packets/PacketFactory.h>
00036
00037 namespace cluster
00038 {
00039 CLUSTER_REGISTER_CLUSTER_PACKET_CREATOR(ConnectionRequest);
00040
00041 ConnectionRequest::ConnectionRequest(std::string host_name, vpr::Uint16 port)
00042 {
00043
00044 mHostname = host_name;
00045 mPort = port;
00046
00047
00048 mHeader = new Header(Header::RIM_PACKET,
00049 Header::RIM_CONNECTION_REQ,
00050 Header::RIM_PACKET_HEAD_SIZE
00051 + 2
00052 + mHostname.size()
00053 + 2
00054 ,0);
00055
00056 serialize();
00057 }
00058
00059 void ConnectionRequest::serialize()
00060 {
00061
00062 mPacketWriter->getData()->clear();
00063 mPacketWriter->setCurPos(0);
00064
00065
00066 mHeader->serializeHeader();
00067
00068
00069 mPacketWriter->writeString(mHostname);
00070
00071
00072 mPacketWriter->writeUint16(mPort);
00073 }
00074
00075 void ConnectionRequest::parse(vpr::BufferObjectReader* reader)
00076 {
00077
00078 mHostname = reader->readString();
00079
00080
00081 mPort = reader->readUint16();
00082 }
00083
00084 void ConnectionRequest::printData(int debug_level)
00085 {
00086 vprDEBUG_BEGIN(gadgetDBG_RIM,debug_level)
00087 << clrOutBOLD(clrYELLOW,"==== Connection Request Packet Data ====\n") << vprDEBUG_FLUSH;
00088
00089 Packet::printData(debug_level);
00090
00091 vprDEBUG(gadgetDBG_RIM,debug_level)
00092 << clrOutBOLD(clrYELLOW, "Host Name: ") << mHostname
00093 << std::endl << vprDEBUG_FLUSH;
00094 vprDEBUG(gadgetDBG_RIM,debug_level)
00095 << clrOutBOLD(clrYELLOW, "Port: ") << mPort
00096 << std::endl << vprDEBUG_FLUSH;
00097
00098 vprDEBUG_END(gadgetDBG_RIM,debug_level)
00099 << clrOutBOLD(clrYELLOW,"========================================\n") << vprDEBUG_FLUSH;
00100 }
00101 }