functions_rt.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 
00012 #include "../../include/ecl/time_lite/functions_rt.hpp"
00013 #include <errno.h>
00014 
00015 /*****************************************************************************
00016 ** Macros
00017 *****************************************************************************/
00018 
00019 #if defined(ECL_HAS_RT_TIMERS)
00020 
00021 /*****************************************************************************
00022 ** Namespaces
00023 *****************************************************************************/
00024 
00025 namespace ecl {
00026 
00027 TimeError epoch_time(TimeStructure &time) {
00028         // _POSIX_CLOCK_MONOTONIC should have gotten us this far,
00029         // just check if we have CLOCK_MONOTONIC and if not, fallback to
00030         // CLOCK_REALTIME.
00031 #ifdef ECL_HAS_CLOCK_MONOTONIC
00032         int result = clock_gettime(CLOCK_MONOTONIC,&time);
00033 #else
00034         int result = clock_gettime(CLOCK_REALTIME,&time);
00035 #endif
00036         switch (result) {
00037                 case(0) : { return TimeError(NoError); }
00038                 case(EFAULT) : { return TimeError(MemoryError); }          // time was not in addressable memory space
00039                 case(EINVAL) : { return TimeError(ArgNotSupportedError); } // clock id is not supported (actually impossible if cmake detects)
00040                 case(EPERM) : { return TimeError(PermissionsError); }      // user does not have permissions to use the clock.
00041                 default : { return TimeError(UnknownError); }
00042         }
00043 }
00044 
00045 TimeError sleep_until(const TimeStructure &time) {
00046     // Last arg is to catch remaining time if interrupted by a signal, not necessary here.
00047 #ifdef ECL_HAS_CLOCK_MONOTONIC
00048         int result = clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME,&time,NULL);
00049 #else
00050         int result =  clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&time,NULL);
00051 #endif
00052         switch (result) {
00053                 case(0) : { return TimeError(NoError); }
00054                 case(EFAULT) : { return TimeError(MemoryError); }     // time was not in addressable memory space
00055                 case(EINTR) : { return TimeError(InterruptedError); } // interrupted by a signal
00056                 case(EINVAL) : { return TimeError(OutOfRangeError); } // sec/nsec pair specified was out of range
00057                 default : { return TimeError(UnknownError); }
00058         }
00059 }
00060 TimeError sleep(const TimeStructure &time) {
00061         int result = nanosleep(&time, NULL);
00062         switch (result) {
00063                 case(0) : { return TimeError(NoError); }
00064                 case(EFAULT) : { return TimeError(MemoryError); }     // some memory error copying information around
00065                 case(EINTR) : { return TimeError(InterruptedError); } // interrupted by a signal
00066                 case(EINVAL) : { return TimeError(OutOfRangeError); } // sec/nsec pair specified was out of range
00067                 default : { return TimeError(UnknownError); }
00068         }
00069 }
00070 
00071 } // namespace ecl
00072 
00073 #endif


ecl_time_lite
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:35:28