Merge branch 'windows-port'
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / src / pmutility.c
index 56bf9b2..b72c28c 100644 (file)
 #define _POSIX_C_SOURCE 200112L
 #endif
 
+#if HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+#ifdef HAVE_STRING_H
 #include <string.h>
-#include <time.h>
-#include <sys/time.h>
+#endif
 
 #include "ocstack.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
+#include "oic_time.h"
 #include "logger.h"
 #include "cJSON.h"
 #include "utlist.h"
@@ -341,31 +344,14 @@ exit:
  */
 OCStackResult PMTimeout(unsigned short waittime, bool waitForStackResponse)
 {
-    struct timespec startTime = {.tv_sec=0, .tv_nsec=0};
-    struct timespec currTime  = {.tv_sec=0, .tv_nsec=0};
-
     OCStackResult res = OC_STACK_OK;
-#ifdef _POSIX_MONOTONIC_CLOCK
-    int clock_res = clock_gettime(CLOCK_MONOTONIC, &startTime);
-#else
-    int clock_res = clock_gettime(CLOCK_REALTIME, &startTime);
-#endif
-    if (0 != clock_res)
-    {
-        return OC_STACK_ERROR;
-    }
+
+    uint64_t startTime = OICGetCurrentTime(TIME_IN_MS);
     while (OC_STACK_OK == res)
     {
-#ifdef _POSIX_MONOTONIC_CLOCK
-        clock_res = clock_gettime(CLOCK_MONOTONIC, &currTime);
-#else
-        clock_res = clock_gettime(CLOCK_REALTIME, &currTime);
-#endif
-        if (0 != clock_res)
-        {
-            return OC_STACK_TIMEOUT;
-        }
-        long elapsed = (currTime.tv_sec - startTime.tv_sec);
+        uint64_t currTime = OICGetCurrentTime(TIME_IN_MS);
+
+        long elapsed = (long)((currTime - startTime) / MS_PER_SEC);
         if (elapsed > waittime)
         {
             return OC_STACK_OK;
@@ -428,8 +414,8 @@ uint16_t GetSecurePortFromJSON(char* jsonStr)
 }
 
 bool PMGenerateQuery(bool isSecure,
-                     const char* address, const uint16_t port,
-                     const OCConnectivityType connType,
+                     const char* address, uint16_t port,
+                     OCConnectivityType connType,
                      char* buffer, size_t bufferSize, const char* uri)
 {
     if(!address || !buffer || !uri)