Go to the documentation of this file.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/reportservices.h"
00041
00042 using namespace JAUS;
00043
00044
00053 ReportServices::ReportServices(const Address& dest,
00054 const Address& src) : Message(REPORT_SERVICES, dest, src)
00055 {
00056 }
00057
00058
00064 ReportServices::ReportServices(const ReportServices& message) : Message(REPORT_SERVICES)
00065 {
00066 *this = message;
00067 }
00068
00069
00075 ReportServices::~ReportServices()
00076 {
00077
00078 }
00079
00080
00092 int ReportServices::WriteMessageBody(Packet& packet) const
00093 {
00094 int total = 0;
00095 total += packet.WriteByte((Byte)mServices.size());
00096
00097 Services::const_iterator node;
00098 for(node = mServices.begin();
00099 node != mServices.end();
00100 node++)
00101 {
00102 total += packet.Write(node->first);
00103 total += packet.WriteByte((Byte)node->second.size());
00104
00105 Record::List::const_iterator component;
00106 for(component = node->second.begin();
00107 component != node->second.end();
00108 component++)
00109 {
00110 total += packet.Write(component->mComponent);
00111 total += packet.Write(component->mInstance);
00112 total += packet.WriteByte((Byte)component->mServices.size());
00113
00114 Service::ID::Set::const_iterator s;
00115 for(s = component->mServices.begin();
00116 s != component->mServices.end();
00117 s++)
00118 {
00119 total += s->Write(packet);
00120 }
00121 }
00122 }
00123
00124 return total;
00125 }
00126
00127
00139 int ReportServices::ReadMessageBody(const Packet& packet)
00140 {
00141 int total = 0;
00142 Byte count1 = 0;
00143
00144 total += packet.Read(count1);
00145 for(Byte i = 0; i < count1; i++)
00146 {
00147 Byte node = 0;
00148 Byte count2 = 0;
00149 Record::List components;
00150
00151 total += packet.Read(node);
00152 total += packet.Read(count2);
00153 for(Byte j = 0; j < count2; j++)
00154 {
00155 Byte count3 = 0;
00156 Record record;
00157
00158 total += packet.Read(record.mComponent);
00159 total += packet.Read(record.mInstance);
00160 total += packet.Read(count3);
00161
00162 for(Byte k = 0; k < count3; k++)
00163 {
00164 Service::ID id;
00165 total += id.Read(packet);
00166 record.mServices.insert(id);
00167 }
00168 components.push_back(record);
00169 }
00170 mServices[node] = components;
00171 }
00172
00173 return total;
00174 }
00175
00176
00182 void ReportServices::ClearMessageBody()
00183 {
00184 mServices.clear();
00185 }
00186
00187
00194 bool ReportServices::IsLargeDataSet(const unsigned int maxPayloadSize) const
00195 {
00196 unsigned int size = BYTE_SIZE;
00197 Services::const_iterator node;
00198 for(node = mServices.begin();
00199 node != mServices.end();
00200 node++)
00201 {
00202 size += BYTE_SIZE*2;
00203 Record::List::const_iterator component;
00204 for(component = node->second.begin();
00205 component != node->second.end();
00206 component++)
00207 {
00208 size += BYTE_SIZE*3;
00209 Service::ID::Set::const_iterator s;
00210 for(s = component->mServices.begin();
00211 s != component->mServices.end();
00212 s++)
00213 {
00214 size += (unsigned int)(BYTE_SIZE + s->mName.size() + BYTE_SIZE*2);
00215 }
00216 }
00217 }
00218 return size > maxPayloadSize;
00219 }
00220
00221
00227 ReportServices& ReportServices::operator =(const ReportServices& message)
00228 {
00229 if(this != &message)
00230 {
00231 CopyHeaderData(&message);
00232 mServices = message.mServices;
00233 }
00234 return *this;
00235 }
00236
00237
00238