|
@@ -51,8 +51,14 @@ UA_Boolean UA_String_equal(const UA_String *string1, const UA_String *string2) {
|
|
|
}
|
|
|
|
|
|
/* DateTime */
|
|
|
+
|
|
|
+/* Implement UA_DateTime_now and UA_DateTime_nowMonotonic outside of the
|
|
|
+ library. This becomes necessary on embedded targets when the POSIX/Windows
|
|
|
+ API is not available. */
|
|
|
+#ifndef UA_ENABLE_EMBEDDED_CLOCK
|
|
|
+
|
|
|
UA_DateTime UA_DateTime_now(void) {
|
|
|
-#ifdef _WIN32
|
|
|
+#if defined(_WIN32) && !defined(__MINGW32__)
|
|
|
/* Windows filetime has the same definition as UA_DateTime */
|
|
|
FILETIME ft;
|
|
|
SYSTEMTIME st;
|
|
@@ -70,31 +76,34 @@ UA_DateTime UA_DateTime_now(void) {
|
|
|
}
|
|
|
|
|
|
UA_DateTime UA_DateTime_nowMonotonic(void) {
|
|
|
-#ifdef _WIN32
|
|
|
+#if defined(_WIN32) && !defined(__MINGW32__)
|
|
|
LARGE_INTEGER freq, ticks;
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
QueryPerformanceCounter(&ticks);
|
|
|
UA_Double ticks2dt = UA_SEC_TO_DATETIME;
|
|
|
ticks2dt /= freq.QuadPart;
|
|
|
return (UA_DateTime)(ticks.QuadPart * ticks2dt);
|
|
|
-#elif defined(__APPLE__) || defined(__MACH__) // OS X does not have clock_gettime, use clock_get_time
|
|
|
+#elif defined(__APPLE__) || defined(__MACH__)
|
|
|
+ /* OS X does not have clock_gettime, use clock_get_time */
|
|
|
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_SEC_TO_DATETIME) + (mts.tv_nsec / 100);
|
|
|
-#else
|
|
|
+#elif defined(__CYGWIN__)
|
|
|
struct timespec ts;
|
|
|
-#ifdef __CYGWIN__
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
+ return (ts.tv_sec * UA_SEC_TO_DATETIME) + (ts.tv_nsec / 100);
|
|
|
#else
|
|
|
+ struct timespec ts;
|
|
|
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
|
|
-#endif
|
|
|
return (ts.tv_sec * UA_SEC_TO_DATETIME) + (ts.tv_nsec / 100);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
+#endif
|
|
|
+
|
|
|
UA_DateTimeStruct UA_DateTime_toStruct(UA_DateTime t) {
|
|
|
/* Calculating the the milli-, micro- and nanoseconds */
|
|
|
UA_DateTimeStruct dateTimeStruct;
|