sleep_pos.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_TIME_SLEEP_POS_HPP_
13 #define ECL_TIME_SLEEP_POS_HPP_
14 
15 /*****************************************************************************
16 ** Platform Check
17 *****************************************************************************/
18 
19 #include <ecl/config.hpp>
20 #if defined(ECL_IS_POSIX)
21 
22 /*****************************************************************************
23 ** Includes
24 *****************************************************************************/
25 
26 #include <sstream>
27 #include <time.h>
28 #include <errno.h>
29 #include <ecl/config/macros.hpp>
32 #include "duration.hpp"
33 #include "macros.hpp"
34 
35 /*****************************************************************************
36 ** Namespaces
37 *****************************************************************************/
38 
39 namespace ecl {
40 
41 /*****************************************************************************
42 ** Interface [Sleep]
43 *****************************************************************************/
61 class ecl_time_PUBLIC Sleep {
62 public:
72  Sleep(const Duration &duration);
82  Sleep(const unsigned long &seconds = 0);
83  virtual ~Sleep() {}
84 
92  void operator()();
100  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
101 
111  void operator()(const unsigned long &seconds);
121  void operator()(const Duration &duration);
122 
123 private:
124  timespec required, remaining;
125 };
126 
142 class ecl_time_PUBLIC MilliSleep {
143 public:
153  MilliSleep(const unsigned long &milliseconds = 0);
154 
155  virtual ~MilliSleep() {}
156 
164  void operator()();
172  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
173 
183  void operator()(const unsigned long &milliseconds);
184 private:
185  timespec required, remaining;
186 };
187 
203 class ecl_time_PUBLIC MicroSleep {
204 public:
214  MicroSleep(const unsigned long &microseconds = 0);
215 
216  virtual ~MicroSleep() {}
217 
218 
226  void operator()();
234  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
244  void operator()(const unsigned long &micro_seconds);
245 private:
246  timespec required, remaining;
247 };
248 
264 class ecl_time_PUBLIC NanoSleep {
265 public:
275  NanoSleep(const unsigned long &nanoseconds = 0);
276 
277  virtual ~NanoSleep() {}
278 
279 
287  void operator()();
295  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
305  void operator()(const unsigned long &nanoseconds);
306 private:
307  timespec required, remaining;
308 };
309 
310 
311 } // namespace ecl
312 
313 /*****************************************************************************
314 ** Interface [Exceptions][Sleeper Classes]
315 *****************************************************************************/
316 
317 #if defined(ECL_HAS_EXCEPTIONS)
318 namespace ecl {
319 namespace time {
320 
321 
322 /*****************************************************************************
323 ** Interface [Sleep Exceptions]
324 *****************************************************************************/
331 inline ecl::StandardException throwSleepException(const char* loc ) {
332  int error_result = errno;
333  switch (error_result) {
334  case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, "A posix signal interrupted the sleep.");
335  case ( EINVAL ) : return StandardException(loc, ecl::InvalidInputError, "Specified value was negative or exceeded resolution range.\n\n Sleep: [N/A]\n MilliSleep: [0-1000]\n MicroSleep: [0-1x10^6]\n NanoSleep: [0-1x10^9]\n");
336  case ( EFAULT ) : return StandardException(loc, ecl::MemoryError, "Internal posix issue copying information from user space.");
337  default :
338  {
339  std::ostringstream ostream;
340  ostream << "Unknown posix error " << error_result << ": " << strerror(error_result) << ".";
341  return StandardException(loc, UnknownError, ostream.str());
342  }
343  }
344 
345 }
346 
347 
348 }; // namespace time
349 } // namespace ecl
350 #endif
351 
352 #endif /* ECL_IS_POSIX */
353 #endif /* ECL_TIME_SLEEP_POS_HPP_ */
Embedded control libraries.
InterruptedError
UnknownError
Cross-platform header inclusions for the duration typedefs.
InvalidInputError
TimeStamp Duration
Convenience typedef to associate timestamps with the concept of durations.
Definition: duration.hpp:41
#define ecl_time_PUBLIC
Definition: macros.hpp:37
MemoryError


ecl_time
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:29