Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Commit

Permalink
Merge branch '1.4-rel' (455c136)
Browse files Browse the repository at this point in the history
Relate-to:
      I923216cf283e97eada4b600d5ebf8f5360c9e317
      I3de75a1485c47fd54ea46da2f3079a6e5fae8084
      I6e9296de9b22858f831ee503587fda51323ac902
      Iead0efa96b95f026b6a5b20731c8069f688c9483
      Ib4f04677cdc6951a0a9505efbd6ab47a7a79288b
      Ic88f9bae3137c439518901084d77285ace964d99
      I6b6320e8a6444a43c6400527f2f982a39a3d9128
      Ibaf2c7d0b9daad7248b2f226da164a7a301dc526
      I4b820e50158e34a94d84195e4979ada6fefff190
      I91c44d9e3e8af731175337bc80afa13a44222d6c
      I5c10141d76c1d2a1ce3efc656990a628dfd6a246

Change-Id: Ie30199897cd6fe64e2fd7a66126a3c87d25d9c1d
Bug: https://jira.iotivity.org/browse/IOT-2453
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
  • Loading branch information
rzr committed Sep 13, 2018
2 parents b567c21 + 455c136 commit 38cb6d4
Show file tree
Hide file tree
Showing 26 changed files with 604 additions and 124 deletions.
2 changes: 2 additions & 0 deletions auto_build.py
Expand Up @@ -508,6 +508,8 @@ def build_tizen(flag, scons_options):
build_options['ES_TARGET_ENROLLEE'] = 'tizen'
build_extra_options = "-f service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/build/tizen/SConscript " + scons_options
call_scons(build_options, build_extra_options)
build_options['MULTIPLE_OWNER'] = 1
call_scons(build_options, build_extra_options)


def build_tizen_secured(flag, scons_options):
Expand Down
2 changes: 1 addition & 1 deletion bridging/plugins/hue_plugin/SConscript
Expand Up @@ -69,7 +69,7 @@ if target_os not in ['windows']:
if target_os in ['darwin', 'ios']:
hue_env.AppendUnique(CPPDEFINES=['_DARWIN_C_SOURCE'])

hue_env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-Werror'])
hue_env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra'])

if hue_env.get('LOGGING'):
hue_env.AppendUnique(CPPDEFINES=['TB_LOG'])
Expand Down
2 changes: 1 addition & 1 deletion bridging/plugins/lifx_plugin/SConscript
Expand Up @@ -63,7 +63,7 @@ lifx_env.AppendUnique(CPPPATH=[

if 'g++' in lifx_env.get('CXX'):
lifx_env.AppendUnique(
CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-Werror'])
CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra'])

libmpm = lifx_env.get('BUILD_DIR') + 'libmpmcommon.a'
lifx_env['LINKFLAGS'] = maskFlags(env['LINKFLAGS'])
Expand Down
2 changes: 1 addition & 1 deletion bridging/plugins/lyric_plugin/SConscript
Expand Up @@ -65,7 +65,7 @@ lyric_env.AppendUnique(CPPPATH=[

if 'g++' in lyric_env.get('CXX'):
lyric_env.AppendUnique(
CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-Werror'])
CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra'])

libmpm = lyric_env.get('BUILD_DIR') + 'libmpmcommon.a'
lyric_env['LINKFLAGS'] = maskFlags(env['LINKFLAGS'])
Expand Down
2 changes: 1 addition & 1 deletion bridging/plugins/nest_plugin/SConscript
Expand Up @@ -70,7 +70,7 @@ if target_os in ['darwin', 'ios']:

if 'g++' in nest_env.get('CXX'):
nest_env.AppendUnique(
CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-Werror'])
CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra'])

if nest_env.get('LOGGING'):
nest_env.AppendUnique(CPPDEFINES=['TB_LOG'])
Expand Down
2 changes: 1 addition & 1 deletion plugins/src/SConscript
Expand Up @@ -59,7 +59,7 @@ if target_os not in ['windows']:
if target_os in ['darwin', 'ios']:
env.AppendUnique(CPPDEFINES=['_DARWIN_C_SOURCE'])

env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-Werror'])
env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra'])

env.PrependUnique(LIBS=['zigbee_wrapper'])

Expand Down
2 changes: 1 addition & 1 deletion plugins/zigbee_wrapper/src/SConscript
Expand Up @@ -53,7 +53,7 @@ if target_os not in ['windows']:
if target_os in ['darwin', 'ios']:
env.AppendUnique(CPPDEFINES=['_DARWIN_C_SOURCE'])

env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-Werror'])
env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra'])
env.PrependUnique(LIBS=['telegesis_wrapper'])

#####################################################################
Expand Down
4 changes: 3 additions & 1 deletion resource/c_common/SConscript
Expand Up @@ -149,6 +149,7 @@ env.AppendUnique(CPPPATH=[
os.path.join(Dir('.').abspath, 'ocevent', 'include'),
os.path.join(Dir('.').abspath, 'oic_platform', 'include'),
os.path.join(Dir('.').abspath, 'octimer', 'include'),
os.path.join(Dir('.').abspath, 'oc_refcounter', 'include'),
'#/extlibs/mbedtls/mbedtls/include'
])

Expand Down Expand Up @@ -176,7 +177,8 @@ common_src = [
'oic_malloc/src/oic_malloc.c',
'oic_time/src/oic_time.c',
'ocrandom/src/ocrandom.c',
'oic_platform/src/oic_platform.c'
'oic_platform/src/oic_platform.c',
'oc_refcounter/src/oc_refcounter.c'
]

if env['POSIX_SUPPORTED']:
Expand Down
90 changes: 90 additions & 0 deletions resource/c_common/oc_refcounter/include/oc_refcounter.h
@@ -0,0 +1,90 @@
/******************************************************************
*
* Copyright 2018 Kistler Group 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.
*
******************************************************************/
#ifndef OC_REFCOUNTER_H_
#define OC_REFCOUNTER_H_

#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

typedef struct oc_refcounter_t *oc_refcounter;

/**
* Desctructor of a data of a refcounter and it is called when a counter of thet refcounter reach 0.
*/
typedef void (*oc_refcounter_dtor_data_func)(void* data);

/**
* Creates a new refcounter of a data. Ownership of the data is transferred to the refcounter.
* For deallocates the data use oc_refcounter_dec, otherwise it can cause crash of the application.
*
* @param data - Data which will be owned by refcounter
* @param dtor - Destructor of a data
*
* @return Poiner to newly created refcounter, NULL on allocation failure.
*/
oc_refcounter oc_refcounter_create(void* data, oc_refcounter_dtor_data_func dtor);

/**
* Increments atommically reference count of a refcounter
*
* @param ref - A pointer to the refcounter
*
* @return returns the ref
*/
oc_refcounter oc_refcounter_inc(oc_refcounter ref);

/**
* Decrements atommically a reference count of a refcounter. If the count of the refcounter
* reach 0, it's call destructor of a data and the refcounter.
*
* @param ref - A pointer to the refcounter
*
* @return
* on count == 0, a null pointer is returned
* otherwise returns the refcounter
*/
oc_refcounter oc_refcounter_dec(oc_refcounter ref);

/**
* Gets a current reference count of the refcount
*
* @param ref - A pointer to the refcounter
*
* @return returns a current reference count of the block
*/
int32_t oc_refcounter_get_count(oc_refcounter ref);

/**
* Gets a data of the refcount
*
* @param ref - A pointer to the refcounter
*
* @return returns a data of the refcounter
*/
void* oc_refcounter_get_data(oc_refcounter ref);

#ifdef __cplusplus
}
#endif // __cplusplus
#endif // OC_REFCOUNTER_H_
116 changes: 116 additions & 0 deletions resource/c_common/oc_refcounter/src/oc_refcounter.c
@@ -0,0 +1,116 @@
/******************************************************************
*
* Copyright 2018 Kistler Group 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.
*
******************************************************************/
#include "oc_refcounter.h"

#include "oic_malloc.h"
#include "ocatomic.h"
#include "iotivity_debug.h"

// Enable extra debug logging for malloc. Comment out to disable
#ifdef ENABLE_REFCOUNTER_DEBUG
#include "experimental/logger.h"
#define TAG "OC_REFCOUNT"
#endif

typedef struct oc_refcounter_t
{
/* count of the references*/
int32_t count;
/* data owned by refcount */
void* data;
/* data destructor*/
oc_refcounter_dtor_data_func dtor;
} oc_refcounter_t;

oc_refcounter oc_refcounter_create(void* data, oc_refcounter_dtor_data_func dtor)
{
oc_refcounter ref = (oc_refcounter)OICMalloc(sizeof(*ref));
if (ref == NULL)
{
return ref;
}
ref->count = 1;
#ifdef ENABLE_REFCOUNTER_DEBUG
OIC_LOG_V(INFO, TAG, "oc_refcounter_create: ref=%p count=%d", ref, 1);
#endif
ref->data = data;
ref->dtor = dtor;

return ref;
}

oc_refcounter oc_refcounter_inc(oc_refcounter ref)
{
if (ref == NULL)
{
return NULL;
}
OC_VERIFY(ref->count > 0);
int32_t count = oc_atomic_increment(&ref->count);
#ifdef ENABLE_REFCOUNTER_DEBUG
OIC_LOG_V(INFO, TAG, "oc_refcounter_inc: ref=%p count=%d", ref, count);
#else
(void) count;
#endif
return ref;
}

oc_refcounter oc_refcounter_dec(oc_refcounter ref)
{
if (ref == NULL)
{
return NULL;
}
OC_VERIFY(ref->count > 0);
int32_t count = oc_atomic_decrement(&ref->count);
#ifdef ENABLE_REFCOUNTER_DEBUG
OIC_LOG_V(INFO, TAG, "oc_refcounter_dec: ref=%p count=%d", ref, count);
#endif
if (count == 0)
{
if (ref->dtor)
{
ref->dtor(ref->data);
}
OICFree(ref);
return NULL;
}
return ref;
}

int32_t oc_refcounter_get_count(oc_refcounter ref)
{
if (ref == NULL)
{
return -1;
}
OC_VERIFY(ref->count > 0);
return ref->count;
}

void* oc_refcounter_get_data(oc_refcounter ref)
{
if (ref == NULL)
{
return NULL;
}
OC_VERIFY(ref->count > 0);
return ref->data;
}
56 changes: 56 additions & 0 deletions resource/c_common/oc_refcounter/test/SConscript
@@ -0,0 +1,56 @@
#******************************************************************
#
# Copyright 2018 Kistler Group 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 os
import os.path
from tools.scons.RunTest import run_test

Import('test_env')

# SConscript file for Local PKI google tests
refcountertest_env = test_env.Clone()
target_os = refcountertest_env.get('TARGET_OS')

######################################################################
# Build flags
######################################################################
refcountertest_env.PrependUnique(CPPPATH=['../include'])

refcountertest_env.AppendUnique(LIBPATH=[
os.path.join(refcountertest_env.get('BUILD_DIR'), 'resource', 'c_common')
])
refcountertest_env.PrependUnique(LIBS=['c_common'])

if refcountertest_env.get('LOGGING'):
refcountertest_env.AppendUnique(CPPDEFINES=['TB_LOG'])
#
######################################################################
# Source files and Targets
######################################################################
refcountertests = refcountertest_env.Program('refcountertests',
['linux/oc_refcounter_tests.cpp'])

Alias("test", [refcountertests])

refcountertest_env.AppendTarget('test')
if refcountertest_env.get('TEST') == '1':
if target_os in ['linux', 'windows']:
run_test(refcountertest_env, 'resource_ccommon_refcounter_test.memcheck',
'resource/c_common/oc_refcounter/test/refcountertests')

0 comments on commit 38cb6d4

Please sign in to comment.