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>
30 #include <ecl/exceptions/macros.hpp>
31 #include <ecl/exceptions/standard_exception.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()() ecl_assert_throw_decl(StandardException);
100  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
101 
111  void operator()(const unsigned long &seconds) ecl_assert_throw_decl(StandardException);
121  void operator()(const Duration &duration) ecl_assert_throw_decl(StandardException);
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()() ecl_assert_throw_decl(StandardException);
172  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
173 
183  void operator()(const unsigned long &milliseconds) ecl_assert_throw_decl(StandardException);
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()() ecl_assert_throw_decl(StandardException);
234  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
244  void operator()(const unsigned long &micro_seconds) ecl_assert_throw_decl(StandardException);
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()() ecl_assert_throw_decl(StandardException);
295  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
305  void operator()(const unsigned long &nanoseconds) ecl_assert_throw_decl(StandardException);
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_ */
InterruptedError
#define ecl_time_PUBLIC
UnknownError
InvalidInputError
Standard exception type, provides code location and error string.
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
TimeStamp Duration
MemoryError


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:38