sleep_win.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_TIME_SLEEP_WIN_HPP_
13 #define ECL_TIME_SLEEP_WIN_HPP_
14 
15 /*****************************************************************************
16 ** Platform Check
17 *****************************************************************************/
18 
19 #include <ecl/config.hpp>
20 #if defined(ECL_IS_WIN32)
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 <ecl/time_lite.hpp>
33 #include "duration.hpp"
34 #include "macros.hpp"
35 
36 /*****************************************************************************
37 ** Namespaces
38 *****************************************************************************/
39 
40 namespace ecl {
41 
42 /*****************************************************************************
43 ** Interface [Sleep]
44 *****************************************************************************/
62 class ecl_time_PUBLIC Sleep {
63 public:
73  Sleep(const Duration &duration);
83  Sleep(const unsigned long &seconds = 0);
84  virtual ~Sleep() {}
85 
93  void operator()() ecl_assert_throw_decl(StandardException);
101  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
102 
112  void operator()(const unsigned long &seconds) ecl_assert_throw_decl(StandardException);
122  void operator()(const Duration &duration) ecl_assert_throw_decl(StandardException);
123 
124 private:
125  TimeStructure required, remaining;
126 };
127 
143 class ecl_time_PUBLIC MilliSleep {
144 public:
154  MilliSleep(const unsigned long &milliseconds = 0);
155 
156  virtual ~MilliSleep() {}
157 
165  void operator()() ecl_assert_throw_decl(StandardException);
173  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
174 
184  void operator()(const unsigned long &milliseconds) ecl_assert_throw_decl(StandardException);
185 private:
186  TimeStructure required, remaining;
187 };
188 
204 class ecl_time_PUBLIC MicroSleep {
205 public:
215  MicroSleep(const unsigned long &microseconds = 0);
216 
217  virtual ~MicroSleep() {}
218 
219 
227  void operator()() ecl_assert_throw_decl(StandardException);
235  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
245  void operator()(const unsigned long &micro_seconds) ecl_assert_throw_decl(StandardException);
246 private:
247  TimeStructure required, remaining;
248 };
249 
265 class ecl_time_PUBLIC NanoSleep {
266 public:
276  NanoSleep(const unsigned long &nanoseconds = 0);
277 
278  virtual ~NanoSleep() {}
279 
280 
288  void operator()() ecl_assert_throw_decl(StandardException);
296  Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
306  void operator()(const unsigned long &nanoseconds) ecl_assert_throw_decl(StandardException);
307 private:
308  TimeStructure required, remaining;
309 };
310 
311 
312 } // namespace ecl
313 
314 /*****************************************************************************
315 ** Interface [Exceptions][Sleeper Classes]
316 *****************************************************************************/
317 
318 #if defined(ECL_HAS_EXCEPTIONS)
319 namespace ecl {
320 namespace time {
321 
322 
323 /*****************************************************************************
324 ** Interface [Sleep Exceptions]
325 *****************************************************************************/
332 inline ecl::StandardException throwSleepException(const char* loc ) {
333  int error_result = errno;
334  switch (error_result) {
335  case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, "Interrupted the sleep.");
336  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");
337  case ( EFAULT ) : return StandardException(loc, ecl::MemoryError, "Memory error.");
338  default :
339  {
340  std::ostringstream ostream;
341  ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
342  return StandardException(loc, UnknownError, ostream.str());
343  }
344  }
345 
346 }
347 
348 
349 }; // namespace time
350 } // namespace ecl
351 #endif
352 
353 #endif /* ECL_IS_WIN32 */
354 #endif /* ECL_TIME_SLEEP_WIN_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