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 realtime_epoch_time(TimeStructure &time) {
00046         int result = clock_gettime(CLOCK_REALTIME,&time);
00047         switch (result) {
00048                 case(0) : { return TimeError(NoError); }
00049                 case(EFAULT) : { return TimeError(MemoryError); }          // time was not in addressable memory space
00050                 case(EINVAL) : { return TimeError(ArgNotSupportedError); } // clock id is not supported (actually impossible if cmake detects)
00051                 case(EPERM) : { return TimeError(PermissionsError); }      // user does not have permissions to use the clock.
00052                 default : { return TimeError(UnknownError); }
00053         }
00054 }
00055 
00056 TimeError sleep_until(const TimeStructure &time) {
00057     // Last arg is to catch remaining time if interrupted by a signal, not necessary here.
00058 #ifdef ECL_HAS_CLOCK_MONOTONIC
00059         int result = clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME,&time,NULL);
00060 #else
00061         int result =  clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&time,NULL);
00062 #endif
00063         switch (result) {
00064                 case(0) : { return TimeError(NoError); }
00065                 case(EFAULT) : { return TimeError(MemoryError); }     // time was not in addressable memory space
00066                 case(EINTR) : { return TimeError(InterruptedError); } // interrupted by a signal
00067                 case(EINVAL) : { return TimeError(OutOfRangeError); } // sec/nsec pair specified was out of range
00068                 default : { return TimeError(UnknownError); }
00069         }
00070 }
00071 TimeError sleep(const TimeStructure &time) {
00072         int result = nanosleep(&time, NULL);
00073         switch (result) {
00074                 case(0) : { return TimeError(NoError); }
00075                 case(EFAULT) : { return TimeError(MemoryError); }     // some memory error copying information around
00076                 case(EINTR) : { return TimeError(InterruptedError); } // interrupted by a signal
00077                 case(EINVAL) : { return TimeError(OutOfRangeError); } // sec/nsec pair specified was out of range
00078                 default : { return TimeError(UnknownError); }
00079         }
00080 }
00081 
00082 } // namespace ecl
00083 
00084 #endif


ecl_time_lite
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 18:53:26