Remove warnings
[anna.git] / include / anna / diameter / codec / basetypes / Time.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #ifndef anna_diameter_codec_basetypes_Time_hpp
10 #define anna_diameter_codec_basetypes_Time_hpp
11
12
13 // Local
14 #include <anna/diameter/codec/basetypes/OctetString.hpp>
15
16 #include <anna/config/defines.hpp>
17 //#include <anna.time.Date.h> // TIMESTAMP_OFFSET_NTP1900_OVER_UNIX1970
18
19
20 namespace anna {
21
22 namespace diameter {
23
24 namespace codec {
25
26 class Avp;
27
28 namespace basetypes {
29
30 /**
31 * Diameter Time container (NTP timestamp)
32 */
33 class Time : OctetString {
34
35   U32 a_ntpTimestamp; // NTP
36
37
38   // Only for derived diameter type:
39   void updateBasic() throw(anna::RuntimeException);
40   void setPrintableString(const char * printableString) throw(anna::RuntimeException);
41
42
43 public:
44
45   virtual ~Time() {;}
46
47   // Class-specific ////////////////////////////////////////////////////////////////////////////////////
48   //
49   /**
50   * Type of timestamps (NTP since 0h on 1 January 1900 UTC, UNIX since 0h on 1 January 1970 UTC)
51   */
52   struct Timestamp {
53     enum _v {
54       NTP = 0,
55       UNIX = 1
56     };
57
58     /**
59     * Timestamp type description
60     * @param v Timestamp type
61     * @return Timestamp description
62     */
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";
66
67       return NULL;
68     }
69   };
70
71   /**
72   * Gets the timestamp value
73   *
74   * @param timestampType Timestamp reference (NTP/Unix)
75   *
76   * @return timestamp value
77   */
78   U32 getTimestamp(Timestamp::_v timestampType = Timestamp::NTP) const throw();
79
80   /**
81   * Sets the timestamp value
82   *
83   * @param timestamp timestamp value
84   * @param timestampType Timestamp reference (NTP/Unix)
85   */
86   void setTimestamp(const U32& timestamp, Timestamp::_v timestampType = Timestamp::NTP) throw();
87   //
88   //////////////////////////////////////////////////////////////////////////////////////////////////////
89
90   // gets
91
92   std::string getFormatName() const throw() { return "Time"; }
93
94
95   // helpers
96
97   std::string asPrintableString() throw(anna::RuntimeException) {
98     return anna::functions::asString(a_ntpTimestamp);
99   }
100
101   std::string asString() throw(anna::RuntimeException);
102
103
104   // sets
105
106   void decode(const char* buffer, const int size) throw(anna::RuntimeException);
107
108
109   // exports /////////////////////////////
110   using AvpData::getSize;
111   using AvpData::code;
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;
119 };
120
121 }
122 }
123 }
124 }
125
126 #endif
127