[OpenSDK-cvs] openSDK/loader opensdkAPI.cc, 1.5, 1.6 opensdkAPI.h, 1.5, 1.6
Status: Beta
Brought to you by:
nuno-lopes
|
From: Nuno L. <nun...@us...> - 2007-07-16 15:21:45
|
Update of /cvsroot/opensdk/openSDK/loader In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv11855/loader Modified Files: opensdkAPI.cc opensdkAPI.h Log Message: move time/date handling functions to opensdkAPI Index: opensdkAPI.cc =================================================================== RCS file: /cvsroot/opensdk/openSDK/loader/opensdkAPI.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- opensdkAPI.cc 15 Jul 2007 15:06:14 -0000 1.5 +++ opensdkAPI.cc 16 Jul 2007 15:21:43 -0000 1.6 @@ -22,9 +22,11 @@ #include <opensdkAPI.h> #include <OVirtualRobotComm.h> #include <main.h> +#include <Platform.h> #include <pthread.h> #include <ctype.h> #include <glob.h> +#include <sys/time.h> static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -110,3 +112,49 @@ globfree(&globbuf); return tmp; } + + +// -------------------------- +// time/date handling +// -------------------------- + +static time_t diffToSystem = 0; // difference to the system clock +static sbyte myTimeDif = 0; // TZ offset (in hours) + + +sbyte GetTimeDifference(void) +{ + return myTimeDif; +} + + +OStatus SetTimeDifference(sbyte timeDifference) +{ + if (timeDifference >= -12 && timeDifference <= 12) { + myTimeDif = timeDifference; + return oSUCCESS; + } + + return oFAIL; +} + + +OStatus SetTime(const OTime& time) +{ + if (SetTimeDifference(time.GetTimeDif()) != oSUCCESS) { + return oFAIL; + } + + diffToSystem = time.GetClock() - (getSystemTime().seconds - diffToSystem); + + return oSUCCESS; +} + + +SystemTime getSystemTime(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + + return SystemTime(tv.tv_sec - TIME_DIFF_SYSTEM + diffToSystem, tv.tv_usec); +} Index: opensdkAPI.h =================================================================== RCS file: /cvsroot/opensdk/openSDK/loader/opensdkAPI.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- opensdkAPI.h 15 Jul 2007 15:06:14 -0000 1.5 +++ opensdkAPI.h 16 Jul 2007 15:21:43 -0000 1.6 @@ -28,6 +28,8 @@ #include <pthread.h> #include <OPENR/OPENR.h> #include <OPENR/ODataFormats.h> +#include <SystemTime.h> +#include <OPENR/OTime.h> extern pthread_key_t perThreadKey; extern bool __in_shutdown; @@ -40,5 +42,9 @@ OStatus GetJointValue(OPrimitiveID id, OJointValue* value); OStatus GetSensorValue(OPrimitiveID id, OSensorValue* value); char* resolve_case_insensitive_path(const char *path); +sbyte GetTimeDifference(void); +OStatus SetTimeDifference(sbyte timeDifference); +OStatus SetTime(const OTime& time); +SystemTime getSystemTime(void); #endif |