csdk: Relocate timerlib to c_common/octimer
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Mon, 20 Mar 2017 14:07:28 +0000 (15:07 +0100)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Wed, 5 Apr 2017 15:42:18 +0000 (15:42 +0000)
It never was an external library while it was located there,
the code is small enough to be part c_common utility library.

No functionnal changes were introduced, just reformated source.

Note, For Arduino, timer object is built using C++ compiler tricks,
that could be removed once support is dropped.

Bug: https://jira.iotivity.org/browse/IOT-1889
Change-Id: I776c5273315a7552495974f58a199a38073fb45e
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18009
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
20 files changed:
extlibs/timer/SConscript [deleted file]
resource/SConscript
resource/c_common/SConscript
resource/c_common/octimer/include/octimer.h [moved from extlibs/timer/timer.h with 74% similarity]
resource/c_common/octimer/src/octimer.c [moved from extlibs/timer/timer.c with 87% similarity, mode: 0644]
resource/csdk/connectivity/src/SConscript
resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c
resource/csdk/connectivity/test/SConscript
resource/csdk/security/provisioning/unittest/SConscript
resource/csdk/security/tool/SConscript
resource/csdk/security/unittest/SConscript
resource/csdk/stack/SConscript
resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript
resource/csdk/stack/samples/linux/SimpleClientServer/SConscript
resource/csdk/stack/src/oicgroup.c
resource/csdk/stack/test/SConscript
resource/unittests/SConscript
service/simulator/examples/client/SConscript
service/simulator/examples/server/SConscript
service/simulator/ramlparser/SConscript

diff --git a/extlibs/timer/SConscript b/extlibs/timer/SConscript
deleted file mode 100644 (file)
index 27182b2..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-# *****************************************************************
-#
-#  Copyright 2015 Samsung Electronics All Rights Reserved.
-#
-#
-#
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-#
-# *****************************************************************/
-
-Import('env')
-
-timer_env = env.Clone()
-
-target_os = timer_env.get('TARGET_OS')
-
-# Required for arduino builds to have access to Timer.h.
-if target_os == 'arduino':
-    timer_env.Replace(CC = env.get('CXX'))
-    timer_env.Replace(CFLAGS = env.get('CXXFLAGS'))
-elif target_os == 'windows':
-    timer_env.AppendUnique(CCFLAGS = ['/W4', '/WX'])
-
-libtimer = timer_env.StaticLibrary('timer', ['timer.c'], OBJPREFIX='libtimer_')
-timer_env.InstallTarget(libtimer, 'timer');
index 3a0d5ae..fc17494 100644 (file)
@@ -36,9 +36,6 @@ if target_os not in ['arduino', 'darwin', 'ios', 'android', 'msys_nt', 'windows'
 # Download (if not already present) & build libcoap
 SConscript('#extlibs/libcoap/SConscript')
 
-# Build timer library
-SConscript('#/extlibs/timer/SConscript')
-
 # Build csdk
 SConscript('csdk/SConscript')
 
index fa81420..c7d630a 100644 (file)
@@ -135,15 +135,16 @@ env.AppendUnique(CPPPATH = [os.path.join(src_dir, 'resource', 'c_common')])
 ######################################################################
 
 env.AppendUnique(CPPPATH = [
-            os.path.join(Dir('.').abspath, 'oic_malloc', 'include'),
-            os.path.join(Dir('.').abspath, 'oic_string', 'include'),
-            os.path.join(Dir('.').abspath, 'oic_time', 'include'),
-            os.path.join(Dir('.').abspath, 'ocatomic', 'include'),
-            os.path.join(Dir('.').abspath, 'ocrandom', 'include'),
-            os.path.join(Dir('.').abspath, 'octhread', 'include'),
-            os.path.join(Dir('.').abspath, 'oic_platform', 'include'),
-            '#/extlibs/mbedtls/mbedtls/include'
-        ])
+    os.path.join(Dir('.').abspath, 'oic_malloc', 'include'),
+    os.path.join(Dir('.').abspath, 'oic_string', 'include'),
+    os.path.join(Dir('.').abspath, 'oic_time', 'include'),
+    os.path.join(Dir('.').abspath, 'ocatomic', 'include'),
+    os.path.join(Dir('.').abspath, 'ocrandom', 'include'),
+    os.path.join(Dir('.').abspath, 'octhread', 'include'),
+    os.path.join(Dir('.').abspath, 'oic_platform', 'include'),
+    os.path.join(Dir('.').abspath, 'octimer', 'include'),
+   '#/extlibs/mbedtls/mbedtls/include'
+])
 
 if target_os not in ['tizen']:
     env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'c_common')])
@@ -176,7 +177,7 @@ common_src = [
     'oic_time/src/oic_time.c',
     'ocrandom/src/ocrandom.c',
     'oic_platform/src/oic_platform.c'
-    ]
+]
 
 if env['POSIX_SUPPORTED']:
     common_src.append('octhread/src/posix/octhread.c')
@@ -186,11 +187,21 @@ else:
     common_src.append('octhread/src/noop/octhread.c')
 
 if target_os in ['windows', 'msys_nt']:
-       common_src.append('ocatomic/src/windows/ocatomic.c')
+    common_src.append('ocatomic/src/windows/ocatomic.c')
 elif target_os in ['arduino']:
-       common_src.append('ocatomic/src/arduino/ocatomic.c')
+    common_src.append('ocatomic/src/arduino/ocatomic.c')
 else:
-       common_src.append('ocatomic/src/others/ocatomic.c')
+    common_src.append('ocatomic/src/others/ocatomic.c')
+
+# C++ Arduino's <Timer.h> is included so use C++ compiler/flags
+if target_os in ['arduino']:
+    octimer_env = common_env.Clone()
+    octimer_env.Replace(CC = env.get('CXX'))
+    octimer_env.Replace(CFLAGS = env.get('CXXFLAGS'))
+    octimer = octimer_env.Object('octimer/src/octimer.c')
+    common_src.append(octimer)
+else:
+    common_src.append('octimer/src/octimer.c')
 
 common_env.AppendUnique(LIBS = ['logger'])
 common_env.AppendUnique(CPPPATH = ['#resource/csdk/logger/include'])
similarity index 74%
rename from extlibs/timer/timer.h
rename to resource/c_common/octimer/include/octimer.h
index a5ac14e..446ea79 100644 (file)
@@ -18,8 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#ifndef TIMER_H_
-#define TIMER_H_
+#ifndef OCTIMER_H_
+#define OCTIMER_H_
 
 #include "iotivity_config.h"
 #ifdef HAVE_TIME_H
@@ -49,14 +49,26 @@ extern "C"
 
 typedef void(*TimerCallback)();
 
+/**
+ * This must be async-signal safe, so it cannot use difftime().
+ * @param[in] after time to be substracted
+ * @param[in] before reference time to be compared to
+ * @return number of seconds between before and after, (after - before).
+ */
 time_t timespec_diff(const time_t after, const time_t before);
-void timespec_add(time_t * to, const time_t seconds);
+
+/**
+ * Add positive seconds to a timespec, nothing if seconds is negative.
+ * @param[out] to time result to be added
+ * @param[in] seconds amount of sec to add
+ */
+void timespec_add(time_t *to, const time_t seconds);
 void checkTimeout();
 
 #ifndef WITH_ARDUINO
-long int getSeconds(struct tmtp);
-time_t getRelativeIntervalOfWeek(struct tmtp);
-time_t getSecondsFromAbsTime(struct tmtp);
+long int getSeconds(struct tm *tp);
+time_t getRelativeIntervalOfWeek(struct tm *tp);
+time_t getSecondsFromAbsTime(struct tm *tp);
 
 int initThread();
 void *loop(void *threadid);
@@ -75,5 +87,4 @@ void unregisterTimer(int id);
 #ifdef __cplusplus
 }
 #endif
-#endif /* TIMER_H_ */
-
+#endif /* OCTIMER_H_ */
old mode 100755 (executable)
new mode 100644 (file)
similarity index 87%
rename from extlibs/timer/timer.c
rename to resource/c_common/octimer/src/octimer.c
index acc784b..c4a9285
@@ -44,7 +44,7 @@
 
 #include <stdio.h>
 
-#include "timer.h"
+#include "octimer.h"
 
 #define SECOND (1)
 
@@ -65,19 +65,12 @@ struct timelist_t
     TimerCallback cb;
 } timeout_list[TIMEOUTS];
 
-/*
- * Return the number of seconds between before and after, (after - before).
- * This must be async-signal safe, so it cannot use difftime().
- */
 time_t timespec_diff(const time_t after, const time_t before)
 {
     return after - before;
 }
 
-/*
- * Add positive seconds to a timespec, nothing if seconds is negative.
- */
-void timespec_add(time_t * to, const time_t seconds)
+void timespec_add(time_t *to, const time_t seconds)
 {
     if (to && seconds > 0)
     {
@@ -87,7 +80,7 @@ void timespec_add(time_t * to, const time_t seconds)
 
 #ifndef WITH_ARDUINO
 
-long int getSeconds(struct tmtp)
+long int getSeconds(struct tm *tp)
 {
     long int nInterval = 0;
 
@@ -102,30 +95,30 @@ long int getSeconds(struct tm* tp)
 
 long int getRelativeSecondsOfDayofweek(int ia, int ib)
 {
-    if( ia > ib )
+    if (ia > ib)
         return (((long int)(7 - (ib - ia))) * SECS_PER_DAY);
 
     return (((long int)((ib - ia))) * SECS_PER_DAY);
 }
 
-time_t getRelativeIntervalOfWeek(struct tmtp)
+time_t getRelativeIntervalOfWeek(struct tm *tp)
 {
     time_t current_time;
-    struct tmcurrent, *midnight;
+    struct tm *current, *midnight;
     time_t delayed_time = 0;
 
     time(&current_time);
     current = localtime(&current_time);
 
-    if(current == NULL)
+    if (current == NULL)
     {
         printf("ERROR; Getting local time fails\n");
         return 0;
     }
 
-    midnight = (struct tm)malloc(sizeof(struct tm));
+    midnight = (struct tm *)malloc(sizeof(struct tm));
 
-    if(midnight == NULL)
+    if (midnight == NULL)
     {
         printf("ERROR; Memory allocation fails\n");
         return 0;
@@ -148,17 +141,17 @@ time_t getRelativeIntervalOfWeek(struct tm* tp)
     return delayed_time;
 }
 
-time_t getSecondsFromAbsTime(struct tmtp)
+time_t getSecondsFromAbsTime(struct tm *tp)
 {
-   time_t current_time;
-   time_t delayed_time = 0;
+    time_t current_time;
+    time_t delayed_time = 0;
 
-   time(&current_time);
-   localtime(&current_time);
+    time(&current_time);
+    localtime(&current_time);
 
-   delayed_time = mktime(tp) - current_time;
+    delayed_time = mktime(tp) - current_time;
 
-   return delayed_time;
+    return delayed_time;
 }
 
 time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
@@ -221,7 +214,7 @@ time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
 
 void unregisterTimer(int idx)
 {
-    if0 <= idx && idx < TIMEOUTS)
+    if (0 <= idx && idx < TIMEOUTS)
         timeout_list[idx].timeout_state = TIMEOUT_UNUSED;
 }
 
@@ -292,17 +285,17 @@ time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
     int i, idx;
 
     if (seconds <= 0)
-    return -1;
+        return -1;
 
     // get the current time
     t = now();
 
     for (idx = 0; idx < TIMEOUTS; ++idx)
-    if (!((timeout_list[idx].timeout_state & TIMEOUT_USED) & TIMEOUT_USED))
-    break;
+        if (!((timeout_list[idx].timeout_state & TIMEOUT_USED) & TIMEOUT_USED))
+            break;
 
     if (TIMEOUTS == idx)// reach to end of timer list
-    return -1;
+        return -1;
 
     // idx th timeout will be used.
     // Reset and set state of the timer
@@ -325,13 +318,13 @@ time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
     for (i = 0; i < TIMEOUTS; i++)
     {
         if ((timeout_list[i].timeout_state & (TIMEOUT_USED | TIMEOUT_UNUSED))
-                == TIMEOUT_USED)
+            == TIMEOUT_USED)
         {
             const time_t secs = timespec_diff(timeout_list[i].timeout_time,
-                    t);
+                                              t);
 
             if (secs >= 0 && secs < next)
-            next = secs;
+                next = secs;
         }
     }
 
@@ -342,7 +335,7 @@ time_t registerTimer(const time_t seconds, int *id, TimerCallback cb)
 
 void unregisterTimer(int idx)
 {
-    if0 <= idx && idx < TIMEOUTS)
+    if (0 <= idx && idx < TIMEOUTS)
         timeout_list[idx].timeout_state = TIMEOUT_UNUSED;
 }
 
@@ -357,10 +350,10 @@ void checkTimeout()
     for (i = 0; i < TIMEOUTS; i++)
     {
         if ((timeout_list[i].timeout_state & (TIMEOUT_USED | TIMEOUT_UNUSED))
-                == TIMEOUT_USED)
+            == TIMEOUT_USED)
         {
             const time_t seconds = timespec_diff(timeout_list[i].timeout_time,
-                    t);
+                                                 t);
 
             if (seconds <= 0)
             {
index 9cfaeb4..e929495 100644 (file)
@@ -67,7 +67,7 @@ else:
     connectivity_env.AppendUnique(CPPPATH = ['#' + tls_path + '/' + tls_headers_path])
 
 if connectivity_env.get('SECURED') == '1':
-       connectivity_env.AppendUnique(CPPPATH = ['#extlibs/timer'])
+       connectivity_env.AppendUnique(CPPPATH = ['#/resource/c_common/octimer/include'])
        connectivity_env.AppendUnique(CPPPATH = [src_dir + '/resource/csdk/security/include'])
        connectivity_env.AppendUnique(CPPPATH = [os.path.join(root_dir, 'external/inc')])
        if ca_os != 'tizen' or os.path.exists(root_dir + '/' + tls_path) == False:
@@ -160,7 +160,7 @@ if ca_os == 'android':
        connectivity_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,libconnectivity_abstraction.so'])
 
 if connectivity_env.get('SECURED') == '1':
-       connectivity_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto', 'timer'])
+       connectivity_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto'])
 
 if ca_os in ['android', 'tizen', 'linux', 'yocto']:
        connectivity_env.AppendUnique(LIBS = ['coap'])
index 5c7abcc..8d1b436 100644 (file)
@@ -33,7 +33,7 @@
 #include "ocrandom.h"
 #include "byte_array.h"
 #include "octhread.h"
-#include "timer.h"
+#include "octimer.h"
 
 // headers required for mbed TLS
 #include "mbedtls/platform.h"
index c876721..fa958f4 100644 (file)
@@ -41,7 +41,7 @@ else:
     catest_env.AppendUnique(CPPPATH = [ os.path.join('#', 'resource', 'csdk', 'connectivity', 'lib', 'libcoap-4.1.1', 'include')])
 
 catest_env.PrependUnique(CPPPATH = [
-                '#/extlibs/timer',
+                '#/resource/c_common/octimer/include',
                 '#/extlibs/mbedtls/mbedtls/include',
                 '#/resource/csdk/connectivity/api',
                 '#/resource/csdk/connectivity/inc',
@@ -72,7 +72,6 @@ if target_os not in ['msys_nt', 'windows']:
 else:
     catest_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
 
-catest_env.AppendUnique(LIBS = ['timer'])
 
 ######################################################################
 # Source files and Targets
index dc957e9..48e5e89 100644 (file)
@@ -85,7 +85,6 @@ else:
 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
        sptest_env.PrependUnique(LIBS = ['resource_directory'])
 
-sptest_env.AppendUnique(LIBS = ['timer'])
 
 ######################################################################
 # Source files and Targets
index a44202b..a4cd300 100644 (file)
@@ -63,7 +63,6 @@ else:
     tools_env.PrependUnique(LIBS = ['octbstack', 'ocsrm', 'm'])
 
 tools_env.PrependUnique(LIBS = ['cjson'])
-tools_env.AppendUnique(LIBS = ['timer'])
 
 ######################################################################
 # Source files and Targets
index 7b8071c..cb6b019 100644 (file)
@@ -82,7 +82,6 @@ else:
 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
        srmtest_env.PrependUnique(LIBS = ['resource_directory', 'oc'])
 
-srmtest_env.AppendUnique(LIBS = ['timer'])
 
 ######################################################################
 # Source files and Targets
index 7d19138..1fe098f 100644 (file)
@@ -56,7 +56,7 @@ else:
     liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/connectivity/lib/libcoap-4.1.1/include'])
 
 liboctbstack_env.PrependUnique(CPPPATH = [
-        '#/extlibs/timer/',
+        '#resource/c_common/octimer/include',
         '#resource/c_common/ocatomic/include',
         '#resource/csdk/logger/include',
         '#resource/csdk/include',
@@ -92,7 +92,7 @@ elif liboctbstack_env.get('ROUTING') == 'EP':
 if target_os not in ['windows']:
     liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
 
-liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap', 'timer'])
+liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap'])
 
 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
     liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
index d8d2781..a8d4390 100644 (file)
@@ -35,7 +35,7 @@ arduino_simplecs_env.PrependUnique(CPPPATH = [
 
 arduino_simplecs_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
-arduino_simplecs_env.PrependUnique(LIBS = ['octbstack', 'ocsrm', 'connectivity_abstraction','coap', 'timer'])
+arduino_simplecs_env.PrependUnique(LIBS = ['octbstack', 'ocsrm', 'connectivity_abstraction','coap'])
 
 arduino_simplecs = arduino_simplecs_env.Program('SimpleClientServer', 'ocserver.cpp')
 arduino_simplecs_env.CreateBin('SimpleClientServer')
index 4b9bfdf..f29a43b 100644 (file)
@@ -67,8 +67,6 @@ if target_os not in ['windows']:
 if samples_env.get('SECURED') == '1':
     samples_env.AppendUnique(LIBS=['mbedtls'])
 
-samples_env.AppendUnique(LIBS = ['timer'])
-
 samples_env.AppendUnique(CPPDEFINES=['TB_LOG'])
 
 src_dir = samples_env.get('SRC_DIR')
index 3f0a6ac..49dcab4 100755 (executable)
@@ -32,7 +32,7 @@
 #include "octhread.h"
 #include "occollection.h"
 #include "logger.h"
-#include "timer.h"
+#include "octimer.h"
 
 #define TAG "OIC_RI_GROUP"
 
index e0b80f3..27a07e9 100644 (file)
@@ -69,7 +69,6 @@ else:
 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
     stacktest_env.PrependUnique(LIBS = ['resource_directory'])
 
-stacktest_env.AppendUnique(LIBS = ['timer'])
 ######################################################################
 # Source files and Targets
 ######################################################################
index 06bef6f..76606da 100644 (file)
@@ -62,7 +62,6 @@ unittests_env.PrependUnique(LIBS = [
                'oc_logger',
                'connectivity_abstraction',
                'coap',
-               'timer',
                'mbedcrypto'])
 
 if unittests_env.get('SECURED') == '1':
index 553fe2a..fd4cf5f 100644 (file)
@@ -7,7 +7,6 @@ sim_env = lib_env.Clone()
 # Build flags
 ######################################################################
 sim_env.AppendUnique(CPPPATH = [
-    '#/extlibs/timer',
     '../../inc',
     '#/resource/csdk/include',
     '#/resource/csdk/stack/include',
index ff45cc9..805281c 100644 (file)
@@ -7,7 +7,7 @@ sim_env = lib_env.Clone()
 # Build flags
 ######################################################################
 sim_env.AppendUnique(CPPPATH = [
-    '#/extlibs/timer',
+    '#/resource/c_common/octimer/include',
     '../../inc',
     '#/resource/csdk/include',
     '#/resource/csdk/stack/include',
index cff7ab3..1cee926 100755 (executable)
@@ -29,7 +29,7 @@ SConscript('#/extlibs/yaml/SConscript')
 ######################################################################
 # Build flags
 ######################################################################
-raml_env.AppendUnique(CPPPATH = ['#/extlibs/timer',
+raml_env.AppendUnique(CPPPATH = ['#/resource/c_common/octimer/include',
                                  '#/extlibs/cjson',
                                  '#/extlibs/yaml/yaml/src' ,
                                  '#/extlibs/yaml/yaml/include',