Use oic_time inside provisioning
authorDavid Antler <david.a.antler@intel.com>
Tue, 21 Jun 2016 22:23:06 +0000 (15:23 -0700)
committerDavid Antler <david.a.antler@intel.com>
Mon, 27 Jun 2016 22:37:28 +0000 (22:37 +0000)
Change-Id: I8f91e99f3a84898e5da71de94f19f9b9c7e82635
Signed-off-by: David Antler <david.a.antler@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8823
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/provisioning/SConscript
resource/csdk/security/provisioning/src/pmutility.c

index 21686b5..3588f1a 100644 (file)
@@ -68,16 +68,6 @@ if target_os not in ['windows', 'msys_nt']:
        if target_os != 'android':
                provisioning_env.AppendUnique(LIBS = ['-lpthread', '-ldl'])
 
-provisioning_conf = Configure(provisioning_env)
-if provisioning_conf.CheckFunc('clock_gettime'):
-       provisioning_conf.env.AppendUnique(CPPDEFINES = ['HAVE_CLOCK_GETTIME'])
-if provisioning_conf.CheckFunc('GetSystemTimeAsFileTime') or target_os == 'windows':
-       # TODO: Remove target_os check.
-       # We currently check for 'windows' as well, because the environment can
-       # sometimes get so polluted that CheckFunc ceases to work!
-       provisioning_conf.env.AppendUnique(CPPDEFINES = ['HAVE_GETSYSTEMTIMEASFILETIME'])
-provisioning_env = provisioning_conf.Finish()
-
 provisioning_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 provisioning_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap'])
 
index 2d5343f..6a7f165 100644 (file)
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-#endif
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
-#ifdef HAVE_TIME_H
-#include <time.h>
-#endif
-#ifdef HAVE_SYS_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"
@@ -353,66 +345,15 @@ exit:
 OCStackResult PMTimeout(unsigned short waittime, bool waitForStackResponse)
 {
     OCStackResult res = OC_STACK_OK;
-#if defined(HAVE_GETSYSTEMTIMEASFILETIME)
-    FILETIME startTime = {0};
-    FILETIME currTime = {0};
-
-    GetSystemTimeAsFileTime(&startTime);
-#elif defined(HAVE_CLOCK_GETTIME)
-    struct timespec startTime = {.tv_sec=0, .tv_nsec=0};
-    struct timespec currTime  = {.tv_sec=0, .tv_nsec=0};
-
-# if defined(_POSIX_MONOTONIC_CLOCK)
-    int clock_res = clock_gettime(CLOCK_MONOTONIC, &startTime);
-# else
-    int clock_res = clock_gettime(CLOCK_REALTIME, &startTime);
-# endif // defined(_POSIX_MONOTONIC_CLOCK)
-    if (0 != clock_res)
-    {
-        return OC_STACK_ERROR;
-    }
-
-#else
-    ERROR Need PMTimeout implementation
-    return OC_STACK_ERROR;
-#endif
+    uint64_t startTime;
+    uint64_t currTime;
 
+    startTime = OICGetCurrentTime(TIME_IN_MS);
     while (OC_STACK_OK == res)
     {
-#if defined(HAVE_GETSYSTEMTIMEASFILETIME)
-        GetSystemTimeAsFileTime(&currTime);
-#elif defined(HAVE_CLOCK_GETTIME)
+        currTime = OICGetCurrentTime(TIME_IN_MS);
 
-# if defined(_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;
-        }
-#else
-        ERROR Need PMTimeout implementation
-#endif
-
-#if defined(HAVE_GETSYSTEMTIMEASFILETIME)
-#define HNS_TO_S(VAL)  ((VAL)/(10*1000*1000))
-        ULARGE_INTEGER currTimeInt;
-        ULARGE_INTEGER startTimeInt;
-
-        currTimeInt.LowPart  = currTime.dwLowDateTime;
-        currTimeInt.HighPart = currTime.dwHighDateTime;
-
-        startTimeInt.LowPart  = startTime.dwLowDateTime;
-        startTimeInt.HighPart = startTime.dwHighDateTime;
-
-        long elapsed = (long)HNS_TO_S(currTimeInt.QuadPart - startTimeInt.QuadPart);
-#elif defined(HAVE_CLOCK_GETTIME)
-        long elapsed = (currTime.tv_sec - startTime.tv_sec);
-#else
-        ERROR Need PMTimeout implementation
-#endif
+        long elapsed = (long)((currTime - startTime) / MS_PER_SEC);
         if (elapsed > waittime)
         {
             return OC_STACK_OK;