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 00034 00035 00036 00037 00038 00039 00040 #include "jaus/core/discovery/queryservices.h" 00041 00042 using namespace JAUS; 00043 00052 QueryServices::QueryServices(const Address& dest, 00053 const Address& src) : Message(QUERY_SERVICES, dest, src) 00054 { 00055 } 00056 00057 00063 QueryServices::QueryServices(const QueryServices& message) : Message(QUERY_SERVICES) 00064 { 00065 *this = message; 00066 } 00067 00068 00074 QueryServices::~QueryServices() 00075 { 00076 00077 } 00078 00079 00091 int QueryServices::WriteMessageBody(Packet& packet) const 00092 { 00093 int total = 0; 00094 int expected = BYTE_SIZE; 00095 Byte count = (Byte)mNodeList.size(); 00096 total += packet.WriteByte(count); 00097 00098 List::const_iterator node; 00099 for(node = mNodeList.begin(); 00100 node != mNodeList.end(); 00101 node++) 00102 { 00103 expected += BYTE_SIZE*2; 00104 Byte count2 = (Byte)node->second.size(); 00105 total += packet.Write(node->first); 00106 total += packet.Write(count2); 00107 00108 std::vector<Byte>::const_iterator component; 00109 for(component = node->second.begin(); 00110 component != node->second.end(); 00111 component++) 00112 { 00113 expected += BYTE_SIZE; 00114 total += packet.Write(*component); 00115 } 00116 } 00117 00118 return total == expected ? total : -1; 00119 } 00120 00121 00133 int QueryServices::ReadMessageBody(const Packet& packet) 00134 { 00135 int total = 0; 00136 int expected = BYTE_SIZE; 00137 Byte count = 0; 00138 00139 total += packet.Read(count); 00140 00141 for(Byte i = 0; i < count; i++) 00142 { 00143 expected += BYTE_SIZE*2; 00144 Byte node = 0, count2 = 0; 00145 std::vector<Byte> components; 00146 00147 total += packet.Read(node); 00148 total += packet.Read(count2); 00149 00150 for(Byte j = 0; j < count2; j++) 00151 { 00152 expected += BYTE_SIZE; 00153 Byte component = 0; 00154 total += packet.Read(component); 00155 components.push_back(component); 00156 } 00157 mNodeList[node] = components; 00158 } 00159 00160 return total == expected ? total : -1; 00161 } 00162 00163 00169 void QueryServices::ClearMessageBody() 00170 { 00171 mNodeList.clear(); 00172 } 00173 00174 00175 00181 QueryServices& QueryServices::operator =(const QueryServices& message) 00182 { 00183 if(this != &message) 00184 { 00185 CopyHeaderData(&message); 00186 mNodeList = message.mNodeList; 00187 } 00188 return *this; 00189 } 00190 00191 00192 /* End of File */