Commit 8e6f6b8f authored by Philippe Coval's avatar Philippe Coval Committed by Dan Mihai

csdk: Relocate timerlib to c_common/octimer

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: default avatarPhilippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18009Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarDan Mihai <Daniel.Mihai@microsoft.com>
parent def305e2
# *****************************************************************
#
# 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');
......@@ -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')
......
......@@ -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'])
......
......@@ -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 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);
......@@ -75,5 +87,4 @@ void unregisterTimer(int id);
#ifdef __cplusplus
}
#endif
#endif /* TIMER_H_ */
#endif /* OCTIMER_H_ */
......@@ -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 tm* tp)
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 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(&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 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(&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)
{
if( 0 <= 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)
{
if( 0 <= 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)
{
......
......@@ -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'])
......
......@@ -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"
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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'))
......
......@@ -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')
......
......@@ -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')
......
......@@ -32,7 +32,7 @@
#include "octhread.h"
#include "occollection.h"
#include "logger.h"
#include "timer.h"
#include "octimer.h"
#define TAG "OIC_RI_GROUP"
......
......@@ -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
######################################################################
......
......@@ -62,7 +62,6 @@ unittests_env.PrependUnique(LIBS = [
'oc_logger',
'connectivity_abstraction',
'coap',
'timer',
'mbedcrypto'])
if unittests_env.get('SECURED') == '1':
......
......@@ -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',
......
......@@ -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',
......
......@@ -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',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment