ANNA Suite  2020b
Multipurpose development suite for Telco applications
Time.hpp
Go to the documentation of this file.
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
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 
33 class Time : OctetString {
34 
35  U32 a_ntpTimestamp; // NTP
36 
37 
38  // Only for derived diameter type:
39  void updateBasic() noexcept(false);
40  void setPrintableString(const char * printableString) noexcept(false);
41 
42 
43 public:
44 
45  virtual ~Time() {;}
46 
47  // Class-specific ////////////////////////////////////////////////////////////////////////////////////
48  //
52  struct Timestamp {
53  enum _v {
54  NTP = 0,
55  UNIX = 1
56  };
57 
63  static const char* asText(const Timestamp::_v v) { // 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 
78  U32 getTimestamp(Timestamp::_v timestampType = Timestamp::NTP) const ;
79 
86  void setTimestamp(const U32& timestamp, Timestamp::_v timestampType = Timestamp::NTP) ;
87  //
89 
90  // gets
91 
92  std::string getFormatName() const { return "Time"; }
93 
94 
95  // helpers
96 
97  std::string asPrintableString() noexcept(false) {
98  return anna::functions::asString(a_ntpTimestamp);
99  }
100 
101  std::string asString() noexcept(false);
102 
103 
104  // sets
105 
106  void decode(const char* buffer, const int size) noexcept(false);
107 
108 
109  // exports /////////////////////////////
110  using AvpData::getSize;
111  using AvpData::code;
112  //using OctetString::asPrintableString;
114  //using OctetString::asString;
115  using AvpData::asHexString;
116  //using OctetString::decode;
119 };
120 
121 }
122 }
123 }
124 }
125 
126 #endif
127 
static const char * asText(const Timestamp::_v v)
Definition: Time.hpp:63
void decode(const char *buffer, const int size) noexcept(false)
U32 getTimestamp(Timestamp::_v timestampType=Timestamp::NTP) const
std::string getFormatName() const
Definition: Time.hpp:92
void setTimestamp(const U32 &timestamp, Timestamp::_v timestampType=Timestamp::NTP)
void fromPrintableString(const char *printableString) noexcept(false)
Definition: AvpData.hpp:224
static std::string asString(const int number)
uint32_t U32
Definition: defines.hpp:75
Definition: OctetString.hpp:30
virtual ~Time()
Definition: Time.hpp:45
std::string asDataBlockString() noexcept(false)
Definition: AvpData.hpp:171
std::string asHexString() noexcept(false)
Definition: AvpData.hpp:196
Definition: app.hpp:12
std::string asString() noexcept(false)
void code(char *buffer, int &size) noexcept(false)
Definition: AvpData.hpp:147
void fromHexString(const std::string &hexString) noexcept(false)
Definition: AvpData.hpp:240
std::string asPrintableString() noexcept(false)
Definition: Time.hpp:97