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/reportidentification.h" 00041 00042 using namespace JAUS; 00043 00044 00053 ReportIdentification::ReportIdentification(const Address& dest, 00054 const Address& src) : Message(REPORT_IDENTIFICATION, dest, src) 00055 { 00056 mQueryType = ComponentIdentification; 00057 mIdentificationType = Vehicle; 00058 } 00059 00060 00066 ReportIdentification::ReportIdentification(const ReportIdentification& message) : Message(REPORT_IDENTIFICATION) 00067 { 00068 mQueryType = ComponentIdentification; 00069 mIdentificationType = Vehicle; 00070 *this = message; 00071 } 00072 00073 00079 ReportIdentification::~ReportIdentification() 00080 { 00081 00082 } 00083 00084 00095 bool ReportIdentification::SetIdentification(const std::string& identification) 00096 { 00097 if(identification.size() <= 255) 00098 { 00099 mIdentification = identification; 00100 return true; 00101 } 00102 return false; 00103 } 00104 00105 00117 int ReportIdentification::WriteMessageBody(Packet& packet) const 00118 { 00119 int total = 0; 00120 int expected = BYTE_SIZE*2 + USHORT_SIZE; 00121 total += packet.WriteByte((Byte)mQueryType); 00122 total += packet.Write((UShort)mIdentificationType); 00123 total += packet.WriteByte((Byte)mIdentification.size()); 00124 if(mIdentification.size() > 0) 00125 { 00126 expected += (int)mIdentification.size(); 00127 total += packet.Write(mIdentification); 00128 } 00129 return total == expected ? total : -1; 00130 } 00131 00132 00144 int ReportIdentification::ReadMessageBody(const Packet& packet) 00145 { 00146 int total = 0; 00147 int expected = BYTE_SIZE*2 + USHORT_SIZE; 00148 Byte count; 00149 total += packet.Read((Byte &)mQueryType); 00150 total += packet.Read((UShort&)mIdentificationType); 00151 total += packet.Read(count); 00152 if(count > 0) 00153 { 00154 expected += count; 00155 total += packet.Read(mIdentification, (unsigned int)count); 00156 } 00157 return total == expected ? total : -1; 00158 } 00159 00160 00166 void ReportIdentification::ClearMessageBody() 00167 { 00168 mQueryType = ComponentIdentification; 00169 mIdentificationType = Vehicle; 00170 mIdentification.clear(); 00171 } 00172 00173 00179 ReportIdentification& ReportIdentification::operator =(const ReportIdentification& message) 00180 { 00181 if(this != &message) 00182 { 00183 CopyHeaderData(&message); 00184 mQueryType = message.mQueryType; 00185 mIdentificationType = message.mIdentificationType; 00186 mIdentification = message.mIdentification; 00187 } 00188 return *this; 00189 } 00190 00191 00192 /* End of File */