Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #include "../../include/ecl/time_lite/functions_rt.hpp"
00013 #include <errno.h>
00014
00015
00016
00017
00018
00019 #if defined(ECL_HAS_RT_TIMERS)
00020
00021
00022
00023
00024
00025 namespace ecl {
00026
00027 TimeError epoch_time(TimeStructure &time) {
00028
00029
00030
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); }
00039 case(EINVAL) : { return TimeError(ArgNotSupportedError); }
00040 case(EPERM) : { return TimeError(PermissionsError); }
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); }
00050 case(EINVAL) : { return TimeError(ArgNotSupportedError); }
00051 case(EPERM) : { return TimeError(PermissionsError); }
00052 default : { return TimeError(UnknownError); }
00053 }
00054 }
00055
00056 TimeError sleep_until(const TimeStructure &time) {
00057
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); }
00066 case(EINTR) : { return TimeError(InterruptedError); }
00067 case(EINVAL) : { return TimeError(OutOfRangeError); }
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); }
00076 case(EINTR) : { return TimeError(InterruptedError); }
00077 case(EINVAL) : { return TimeError(OutOfRangeError); }
00078 default : { return TimeError(UnknownError); }
00079 }
00080 }
00081
00082 }
00083
00084 #endif