Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #ifndef ECL_TIME_SLEEP_WIN_HPP_
00013 #define ECL_TIME_SLEEP_WIN_HPP_
00014
00015
00016
00017
00018
00019 #include <ecl/config.hpp>
00020 #if defined(ECL_IS_WIN32)
00021
00022
00023
00024
00025
00026 #include <sstream>
00027 #include <time.h>
00028 #include <errno.h>
00029 #include <ecl/config/macros.hpp>
00030 #include <ecl/exceptions/macros.hpp>
00031 #include <ecl/exceptions/standard_exception.hpp>
00032 #include <ecl/time_lite.hpp>
00033 #include "duration.hpp"
00034 #include "macros.hpp"
00035
00036
00037
00038
00039
00040 namespace ecl {
00041
00042
00043
00044
00062 class ecl_time_PUBLIC Sleep {
00063 public:
00073 Sleep(const Duration &duration);
00083 Sleep(const unsigned long &seconds = 0);
00084 virtual ~Sleep() {}
00085
00093 void operator()() ecl_assert_throw_decl(StandardException);
00101 Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
00102
00112 void operator()(const unsigned long &seconds) ecl_assert_throw_decl(StandardException);
00122 void operator()(const Duration &duration) ecl_assert_throw_decl(StandardException);
00123
00124 private:
00125 TimeStructure required, remaining;
00126 };
00127
00143 class ecl_time_PUBLIC MilliSleep {
00144 public:
00154 MilliSleep(const unsigned long &milliseconds = 0);
00155
00156 virtual ~MilliSleep() {}
00157
00165 void operator()() ecl_assert_throw_decl(StandardException);
00173 Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
00174
00184 void operator()(const unsigned long &milliseconds) ecl_assert_throw_decl(StandardException);
00185 private:
00186 TimeStructure required, remaining;
00187 };
00188
00204 class ecl_time_PUBLIC MicroSleep {
00205 public:
00215 MicroSleep(const unsigned long µseconds = 0);
00216
00217 virtual ~MicroSleep() {}
00218
00219
00227 void operator()() ecl_assert_throw_decl(StandardException);
00235 Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
00245 void operator()(const unsigned long µ_seconds) ecl_assert_throw_decl(StandardException);
00246 private:
00247 TimeStructure required, remaining;
00248 };
00249
00265 class ecl_time_PUBLIC NanoSleep {
00266 public:
00276 NanoSleep(const unsigned long &nanoseconds = 0);
00277
00278 virtual ~NanoSleep() {}
00279
00280
00288 void operator()() ecl_assert_throw_decl(StandardException);
00296 Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
00306 void operator()(const unsigned long &nanoseconds) ecl_assert_throw_decl(StandardException);
00307 private:
00308 TimeStructure required, remaining;
00309 };
00310
00311
00312 }
00313
00314
00315
00316
00317
00318 #if defined(ECL_HAS_EXCEPTIONS)
00319 namespace ecl {
00320 namespace time {
00321
00322
00323
00324
00325
00332 inline ecl::StandardException throwSleepException(const char* loc ) {
00333 int error_result = errno;
00334 switch (error_result) {
00335 case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, "Interrupted the sleep.");
00336 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");
00337 case ( EFAULT ) : return StandardException(loc, ecl::MemoryError, "Memory error.");
00338 default :
00339 {
00340 std::ostringstream ostream;
00341 ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
00342 return StandardException(loc, UnknownError, ostream.str());
00343 }
00344 }
00345
00346 }
00347
00348
00349 };
00350 }
00351 #endif
00352
00353 #endif
00354 #endif