sleep_pos.hpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Ifdefs
00010 *****************************************************************************/
00011 
00012 #ifndef ECL_TIME_SLEEP_POS_HPP_
00013 #define ECL_TIME_SLEEP_POS_HPP_
00014 
00015 /*****************************************************************************
00016 ** Platform Check
00017 *****************************************************************************/
00018 
00019 #include <ecl/config.hpp>
00020 #if defined(ECL_IS_POSIX)
00021 
00022 /*****************************************************************************
00023 ** Includes
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 "duration.hpp"
00033 #include "macros.hpp"
00034 
00035 /*****************************************************************************
00036 ** Namespaces
00037 *****************************************************************************/
00038 
00039 namespace ecl {
00040 
00041 /*****************************************************************************
00042 ** Interface [Sleep]
00043 *****************************************************************************/
00061 class ecl_time_PUBLIC Sleep {
00062 public:
00072         Sleep(const Duration &duration);
00082         Sleep(const unsigned long &seconds = 0);
00083         virtual ~Sleep() {}
00084 
00092         void operator()() ecl_assert_throw_decl(StandardException);
00100         Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
00101 
00111         void operator()(const unsigned long &seconds) ecl_assert_throw_decl(StandardException);
00121         void operator()(const Duration &duration) ecl_assert_throw_decl(StandardException);
00122 
00123 private:
00124     timespec required, remaining;
00125 };
00126 
00142 class ecl_time_PUBLIC MilliSleep {
00143 public:
00153         MilliSleep(const unsigned long &milliseconds = 0);
00154 
00155         virtual ~MilliSleep() {}
00156 
00164         void operator()() ecl_assert_throw_decl(StandardException);
00172         Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
00173 
00183         void operator()(const unsigned long &milliseconds) ecl_assert_throw_decl(StandardException);
00184 private:
00185     timespec required, remaining;
00186 };
00187 
00203 class ecl_time_PUBLIC MicroSleep {
00204 public:
00214         MicroSleep(const unsigned long &microseconds = 0);
00215 
00216         virtual ~MicroSleep() {}
00217 
00218 
00226         void operator()() ecl_assert_throw_decl(StandardException);
00234         Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
00244         void operator()(const unsigned long &micro_seconds) ecl_assert_throw_decl(StandardException);
00245 private:
00246     timespec required, remaining;
00247 };
00248 
00264 class ecl_time_PUBLIC NanoSleep {
00265 public:
00275         NanoSleep(const unsigned long &nanoseconds = 0);
00276 
00277         virtual ~NanoSleep() {}
00278 
00279 
00287         void operator()() ecl_assert_throw_decl(StandardException);
00295         Duration duration() { return Duration(required.tv_sec,required.tv_nsec); }
00305         void operator()(const unsigned long &nanoseconds) ecl_assert_throw_decl(StandardException);
00306 private:
00307     timespec required, remaining;
00308 };
00309 
00310 
00311 } // namespace ecl
00312 
00313 /*****************************************************************************
00314 ** Interface [Exceptions][Sleeper Classes]
00315 *****************************************************************************/
00316 
00317 #if defined(ECL_HAS_EXCEPTIONS)
00318 namespace ecl {
00319 namespace time {
00320 
00321 
00322 /*****************************************************************************
00323 ** Interface [Sleep Exceptions]
00324 *****************************************************************************/
00331 inline ecl::StandardException throwSleepException(const char* loc ) {
00332         int error_result = errno;
00333         switch (error_result) {
00334                 case ( EINTR  ) : return StandardException(loc, ecl::InterruptedError, "A posix signal interrupted the sleep.");
00335                 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");
00336                 case ( EFAULT ) : return StandardException(loc, ecl::MemoryError, "Internal posix issue copying information from user space.");
00337                 default         :
00338                 {
00339                         std::ostringstream ostream;
00340                         ostream << "Unknown posix error " << error_result << ": " << strerror(error_result) << ".";
00341                         return StandardException(loc, UnknownError, ostream.str());
00342                 }
00343         }
00344 
00345 }
00346 
00347 
00348 }; // namespace time
00349 } // namespace ecl
00350 #endif
00351 
00352 #endif /* ECL_IS_POSIX */
00353 #endif /* ECL_TIME_SLEEP_POS_HPP_ */


ecl_time
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:17