12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #ifdef UA_ARCHITECTURE_POSIX
- #include <open62541/types.h>
- #include <time.h>
- #include <sys/time.h>
- #if defined(__APPLE__) || defined(__MACH__)
- # include <mach/clock.h>
- # include <mach/mach.h>
- #endif
- UA_DateTime UA_DateTime_now(void) {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (tv.tv_sec * UA_DATETIME_SEC) + (tv.tv_usec * UA_DATETIME_USEC) + UA_DATETIME_UNIX_EPOCH;
- }
- UA_Int64 UA_DateTime_localTimeUtcOffset(void) {
- time_t gmt, rawtime = time(NULL);
- struct tm *ptm;
- struct tm gbuf;
- ptm = gmtime_r(&rawtime, &gbuf);
-
- ptm->tm_isdst = -1;
- gmt = mktime(ptm);
- return (UA_Int64) (difftime(rawtime, gmt) * UA_DATETIME_SEC);
- }
- UA_DateTime UA_DateTime_nowMonotonic(void) {
- #if defined(__APPLE__) || defined(__MACH__)
-
- clock_serv_t cclock;
- mach_timespec_t mts;
- host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
- clock_get_time(cclock, &mts);
- mach_port_deallocate(mach_task_self(), cclock);
- return (mts.tv_sec * UA_DATETIME_SEC) + (mts.tv_nsec / 100);
- #elif !defined(CLOCK_MONOTONIC_RAW)
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- return (ts.tv_sec * UA_DATETIME_SEC) + (ts.tv_nsec / 100);
- #else
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
- return (ts.tv_sec * UA_DATETIME_SEC) + (ts.tv_nsec / 100);
- #endif
- }
- #endif
|