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 #ifndef __JAUS_CORE_TIME_REPORT_TIME__H 00041 #define __JAUS_CORE_TIME_REPORT_TIME__H 00042 00043 #include "jaus/core/corecodes.h" 00044 #include "jaus/core/message.h" 00045 00046 namespace JAUS 00047 { 00054 class ReportTime : public Message 00055 { 00056 public: 00064 class JAUS_CORE_DLL PresenceVector : public JAUS::PresenceVector 00065 { 00066 public: 00067 const static Byte Time = 0x01; 00068 const static Byte Date = 0x02; 00069 }; 00070 ReportTime(const Address& dest = Address(), 00071 const Address& src = Address()) : Message(REPORT_TIME, dest, src) 00072 { 00073 mPresenceVector = 0; 00074 } 00075 ReportTime(const ReportTime& message) : Message(REPORT_TIME) 00076 { 00077 *this = message; 00078 } 00079 ~ReportTime() 00080 { 00081 } 00082 void SetTimeStamp(const Time& time) 00083 { 00084 mTime = time; 00085 mPresenceVector |= PresenceVector::Time; 00086 } 00087 void SetDateStamp(const Date& date) 00088 { 00089 mDate = date; 00090 mPresenceVector |= PresenceVector::Date; 00091 } 00092 inline Time GetTimeStamp() const { return mTime; } 00093 inline Date GetDateStamp() const { return mDate; } 00094 // Return true if a command message, otherwise false. 00095 virtual bool IsCommand() const { return false; } 00096 // Writes message payload data to the packet at the current write position. 00097 virtual int WriteMessageBody(Packet& packet) const 00098 { 00099 int expected = BYTE_SIZE; 00100 int written = 0; 00101 00102 written += packet.Write(mPresenceVector); 00103 if( (mPresenceVector & PresenceVector::Time) > 0) 00104 { 00105 expected += UINT_SIZE; 00106 written += packet.Write(mTime.ToUInt()); 00107 } 00108 if( (mPresenceVector & PresenceVector::Date) > 0) 00109 { 00110 expected += USHORT_SIZE; 00111 written += packet.Write(mDate.ToUShort()); 00112 } 00113 return expected == written ? expected : -1; 00114 } 00115 // Reads message payload data from the packets current read position. 00116 virtual int ReadMessageBody(const Packet& packet) 00117 { 00118 int expected = BYTE_SIZE; 00119 int read = 0; 00120 00121 read += packet.Read(mPresenceVector); 00122 if( (mPresenceVector & PresenceVector::Time) > 0) 00123 { 00124 expected += UINT_SIZE; 00125 UInt tstamp = 0; 00126 read += packet.Read(tstamp); 00127 mTime.SetTime(tstamp); 00128 } 00129 if( (mPresenceVector & PresenceVector::Date) > 0) 00130 { 00131 expected += USHORT_SIZE; 00132 UShort dstamp = 0; 00133 read += packet.Read(dstamp); 00134 mDate.FromUShort(dstamp); 00135 } 00136 return expected == read ? expected : -1; 00137 } 00138 // Make a copy of the message and returns pointer to it. 00139 virtual Message* Clone() const { return new ReportTime(*this); } 00140 // Gets the presence vector data for the message. 00141 virtual UInt GetPresenceVector() const { return mPresenceVector; } 00142 // Get the size of the message presence vector. 0 value indicates no presence vector. 00143 virtual UInt GetPresenceVectorSize() const { return BYTE_SIZE; } 00144 // Get the mask associated with presence vector. Indicates what bits are used. 00145 virtual UInt GetPresenceVectorMask() const { return 0x03; } 00146 // Gets the response type to the associated message, 0 if message is a response type. 00147 virtual UShort GetMessageCodeOfResponse() const { return 0; } 00148 // Gets the name of the message in human readable format (for logging, etc.) 00149 virtual std::string GetMessageName() const { return "Report Time"; } 00150 // Clears only message body information. 00151 virtual void ClearMessageBody() { mPresenceVector = 0;} 00152 // Return true if payload is greater than maxPaylodSize (payload == message data only). 00153 virtual bool IsLargeDataSet(const unsigned int maxPayloadSize) const { return false; } 00154 ReportTime& operator=(const ReportTime& message) 00155 { 00156 CopyHeaderData(&message); 00157 mPresenceVector = message.mPresenceVector; 00158 mTime = message.mTime; 00159 mDate = message.mDate; 00160 return *this; 00161 } 00162 protected: 00163 Byte mPresenceVector; 00164 Time mTime; 00165 Date mDate; 00166 }; 00167 } 00168 00169 #endif 00170 /* End of File */