+++ /dev/null
-# *****************************************************************
-#
-# 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');
# Download (if not already present) & build libcoap
SConscript('#extlibs/libcoap/SConscript')
-# Build timer library
-SConscript('#/extlibs/timer/SConscript')
-
# Build csdk
SConscript('csdk/SConscript')
######################################################################
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')])
'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')
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'])
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#ifndef TIMER_H_
-#define TIMER_H_
+#ifndef OCTIMER_H_
+#define OCTIMER_H_
#include "iotivity_config.h"
#ifdef HAVE_TIME_H
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 tm* tp);
-time_t getRelativeIntervalOfWeek(struct tm* tp);
-time_t getSecondsFromAbsTime(struct tm* tp);
+long int getSeconds(struct tm *tp);
+time_t getRelativeIntervalOfWeek(struct tm *tp);
+time_t getSecondsFromAbsTime(struct tm *tp);
int initThread();
void *loop(void *threadid);
#ifdef __cplusplus
}
#endif
-#endif /* TIMER_H_ */
-
+#endif /* OCTIMER_H_ */
#include <stdio.h>
-#include "timer.h"
+#include "octimer.h"
#define SECOND (1)
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)
{
#ifndef WITH_ARDUINO
-long int getSeconds(struct tm* tp)
+long int getSeconds(struct tm *tp)
{
long int nInterval = 0;
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 tm* tp)
+time_t getRelativeIntervalOfWeek(struct tm *tp)
{
time_t current_time;
- struct tm* current, *midnight;
+ struct tm *current, *midnight;
time_t delayed_time = 0;
time(¤t_time);
current = localtime(¤t_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;
return delayed_time;
}
-time_t getSecondsFromAbsTime(struct tm* tp)
+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(¤t_time);
- localtime(¤t_time);
+ time(¤t_time);
+ localtime(¤t_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)
void unregisterTimer(int idx)
{
- if( 0 <= idx && idx < TIMEOUTS)
+ if (0 <= idx && idx < TIMEOUTS)
timeout_list[idx].timeout_state = TIMEOUT_UNUSED;
}
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
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;
}
}
void unregisterTimer(int idx)
{
- if( 0 <= idx && idx < TIMEOUTS)
+ if (0 <= idx && idx < TIMEOUTS)
timeout_list[idx].timeout_state = TIMEOUT_UNUSED;
}
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)
{
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:
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'])
#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"
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',
else:
catest_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
-catest_env.AppendUnique(LIBS = ['timer'])
######################################################################
# Source files and Targets
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
tools_env.PrependUnique(LIBS = ['octbstack', 'ocsrm', 'm'])
tools_env.PrependUnique(LIBS = ['cjson'])
-tools_env.AppendUnique(LIBS = ['timer'])
######################################################################
# Source files and Targets
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
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',
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'))
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')
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')
#include "octhread.h"
#include "occollection.h"
#include "logger.h"
-#include "timer.h"
+#include "octimer.h"
#define TAG "OIC_RI_GROUP"
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
######################################################################
'oc_logger',
'connectivity_abstraction',
'coap',
- 'timer',
'mbedcrypto'])
if unittests_env.get('SECURED') == '1':
# Build flags
######################################################################
sim_env.AppendUnique(CPPPATH = [
- '#/extlibs/timer',
'../../inc',
'#/resource/csdk/include',
'#/resource/csdk/stack/include',
# Build flags
######################################################################
sim_env.AppendUnique(CPPPATH = [
- '#/extlibs/timer',
+ '#/resource/c_common/octimer/include',
'../../inc',
'#/resource/csdk/include',
'#/resource/csdk/stack/include',
######################################################################
# 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',