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);
46 // Class-specific ////////////////////////////////////////////////////////////////////////////////////
49 * Type of timestamps (NTP since 0h on 1 January 1900 UTC, UNIX since 0h on 1 January 1970 UTC)
58 * Timestamp type description
59 * @param v Timestamp type
60 * @return Timestamp description
62 static const char* asText(const Timestamp::_v v) throw() { // anna_declare_enum is not safe, because labels don't have to match a sequence
63 if(v == Timestamp::NTP) return "NTP";
64 else if(v == Timestamp::UNIX) return "UNIX";
71 * Gets the timestamp value
73 * @param timestampType Timestamp reference (NTP/Unix)
75 * @return timestamp value
77 U32 getTimestamp(Timestamp::_v timestampType = Timestamp::NTP) const throw();
80 * Sets the timestamp value
82 * @param timestamp timestamp value
83 * @param timestampType Timestamp reference (NTP/Unix)
85 void setTimestamp(const U32& timestamp, Timestamp::_v timestampType = Timestamp::NTP) throw();
87 //////////////////////////////////////////////////////////////////////////////////////////////////////
91 std::string getFormatName() const throw() { return "Time"; }
96 std::string asPrintableString() throw(anna::RuntimeException) {
97 return anna::functions::asString(a_ntpTimestamp);
100 std::string asString() throw(anna::RuntimeException);
105 void decode(const char* buffer, const int size) throw(anna::RuntimeException);
108 // exports /////////////////////////////
109 using AvpData::getSize;
111 //using OctetString::asPrintableString;
112 using AvpData::asDataBlockString;
113 //using OctetString::asString;
114 using AvpData::asHexString;
115 //using OctetString::decode;
116 using AvpData::fromPrintableString;
117 using AvpData::fromHexString;