1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_diameter_codec_basetypes_Time_hpp
10 #define anna_diameter_codec_basetypes_Time_hpp
14 #include <anna/diameter/codec/basetypes/OctetString.hpp>
16 #include <anna/config/defines.hpp>
17 //#include <anna.time.Date.h> // TIMESTAMP_OFFSET_NTP1900_OVER_UNIX1970
31 * Diameter Time container (NTP timestamp)
33 class Time : OctetString {
35 U32 a_ntpTimestamp; // NTP
38 // Only for derived diameter type:
39 void updateBasic() throw(anna::RuntimeException);
40 void setPrintableString(const char * printableString) throw(anna::RuntimeException);
47 // Class-specific ////////////////////////////////////////////////////////////////////////////////////
50 * Type of timestamps (NTP since 0h on 1 January 1900 UTC, UNIX since 0h on 1 January 1970 UTC)
59 * Timestamp type description
60 * @param v Timestamp type
61 * @return Timestamp description
63 static const char* asText(const Timestamp::_v v) throw() { // anna_declare_enum is not safe, because labels don't have to match a sequence
64 if(v == Timestamp::NTP) return "NTP";
65 else if(v == Timestamp::UNIX) return "UNIX";
72 * Gets the timestamp value
74 * @param timestampType Timestamp reference (NTP/Unix)
76 * @return timestamp value
78 U32 getTimestamp(Timestamp::_v timestampType = Timestamp::NTP) const throw();
81 * Sets the timestamp value
83 * @param timestamp timestamp value
84 * @param timestampType Timestamp reference (NTP/Unix)
86 void setTimestamp(const U32& timestamp, Timestamp::_v timestampType = Timestamp::NTP) throw();
88 //////////////////////////////////////////////////////////////////////////////////////////////////////
92 std::string getFormatName() const throw() { return "Time"; }
97 std::string asPrintableString() throw(anna::RuntimeException) {
98 return anna::functions::asString(a_ntpTimestamp);
101 std::string asString() throw(anna::RuntimeException);
106 void decode(const char* buffer, const int size) throw(anna::RuntimeException);
109 // exports /////////////////////////////
110 using AvpData::getSize;
112 //using OctetString::asPrintableString;
113 using AvpData::asDataBlockString;
114 //using OctetString::asString;
115 using AvpData::asHexString;
116 //using OctetString::decode;
117 using AvpData::fromPrintableString;
118 using AvpData::fromHexString;