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