timestamp_pos.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Platform Check
10 *****************************************************************************/
11 
12 #include <ecl/config.hpp>
13 #if defined(ECL_IS_POSIX)
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <sstream>
20 #include <errno.h>
21 #include <sys/time.h>
22 #include <ecl/config/ecl.hpp>
24 #include "../../include/ecl/time/timestamp_pos.hpp"
26 
27 /*****************************************************************************
28 ** Namespaces
29 *****************************************************************************/
30 
31 namespace ecl {
32 
33 /*****************************************************************************
34 ** Implementation [TimeStamp]
35 *****************************************************************************/
36 
37 TimeStamp::TimeStamp() {
38  stamp();
39 }
40 
41 TimeStamp::TimeStamp (const double& decimal_time_value) :
42  TimeStampBase(decimal_time_value)
43 {}
44 
45 TimeStamp::TimeStamp (const time_t& seconds, const long& nanoseconds) :
46  TimeStampBase(seconds, nanoseconds)
47 {}
48 
49 TimeStamp::TimeStamp(const TimeStampBase& base) : TimeStampBase(base) {}
50 
51 /*****************************************************************************
52 ** Implementation [Stamps]
53 *****************************************************************************/
54 
55 const TimeStamp& TimeStamp::stamp() {
56  if ( epoch_time(time).flag() != NoError ) {
57  ecl_debug_throw(time::throwTimeStampException(LOC));
58  }
59  return (*this);
60 }
61 
62 #if defined(ECL_HAS_RT_TIMERS)
63 TimeStamp TimeStamp::realtime_now() {
64  TimeStructure time;
65  if ( realtime_epoch_time(time).flag() != NoError ) {
66  ecl_debug_throw(time::throwTimeStampException(LOC));
67  }
68  return TimeStamp(time.tv_sec, time.tv_nsec);
69 }
70 #endif
71 }; // namespace ecl
72 
73 /*****************************************************************************
74 ** Implementation [Exceptions]
75 *****************************************************************************/
76 
77 #ifdef ECL_HAS_EXCEPTIONS
78 namespace ecl {
79 namespace time {
80 
81 StandardException throwTimeStampException(const char* loc) {
82  int error_result = errno;
83  switch (error_result) {
84  case ( EINVAL ) : return ecl::StandardException(loc, ecl::NotSupportedError, "The requested clock is not supported on this system.");
85  case ( EFAULT ) : return ecl::StandardException(loc, ecl::OutOfRangeError, "The timespec pointer points outside the address space.");
86  default :
87  {
88  std::ostringstream ostream;
89  ostream << "Unknown posix error " << error_result << ": " << strerror(error_result) << ".";
90  return StandardException(loc, ecl::UnknownError, ostream.str());
91  }
92  }
93 }
94 
95 }; // namespace time
96 }; // namespace ecl
97 
98 #endif /* ECL_HAS_EXCEPTIONS */
99 #endif /* ECL_IS_POSIX */
ecl::StandardException
functions.hpp
config.hpp
ecl::UnknownError
UnknownError
ecl::NotSupportedError
NotSupportedError
macros.hpp
ecl::OutOfRangeError
OutOfRangeError
ecl
Embedded control libraries.
ecl_debug_throw
#define ecl_debug_throw(exception)


ecl_time
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:19