-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+# Copyright (c) 2020 Samsung Electronics Co., Ltd 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.
+#
+# @file CMakeLists.txt
+#
+
+############################# Check minimum CMake version #####################
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)
SET(CAPI_UWB "capi-network-uwb")
+PROJECT(${CAPI_UWB})
-PROJECT(${CAPI_UWB} C CXX)
+############################# cmake packages ##################################
-MESSAGE(" - Defining...configuration variables")
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-
-SET(LIB ${LIB_PATH})
-SET(LIBDIR ${PREFIX}/${LIB_PATH})
-
-SET(INC_DIR include)
-INCLUDE_DIRECTORIES(${INC_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
-
-MESSAGE(" - Checking...packages dependency")
-SET(COMMON_DEPS dlog gio-2.0 glib-2.0 gio-unix-2.0 capi-system-info)
-SET(PC_DEPS "")
-
-MESSAGE(" - Making...build configuration")
INCLUDE(FindPkgConfig)
-pkg_check_modules(${CAPI_UWB} REQUIRED ${COMMON_DEPS})
-FOREACH(flag ${${CAPI_UWB}_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-SET(DEFAULT_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE -fPIC -Werror -g -fvisibility=hidden")
-IF(BUILD_GCOV)
- SET(GCOV_C_FLAGS "-fprofile-arcs -ftest-coverage")
-ENDIF(BUILD_GCOV)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEFAULT_CFLAGS} ${GCOV_C_FLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-IF("${ARCH}" STREQUAL "arm")
- ADD_DEFINITIONS("-DTARGET")
-ENDIF("${ARCH}" STREQUAL "arm")
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-ADD_DEFINITIONS("-DTIZEN_DEBUG")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie -Wl,--rpath=${LIBDIR}")
-
-MESSAGE(" - Generating...d-bus code")
-FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
-EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
- " \\
- --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/src/uwb_gdbus \\
- --interface-prefix org.tizen.uwb. \\
- ${CMAKE_CURRENT_SOURCE_DIR}/src/uwb-gdbuslib.xml \\
- ")
-
-MESSAGE(" - Building...shared library")
-SET(SOURCES src/uwb.c
- src/uwb_gdbus.c
- src/uwb_util.c)
-
-ADD_LIBRARY(${CAPI_UWB} SHARED ${SOURCES})
-TARGET_LINK_LIBRARIES(${CAPI_UWB} ${${CAPI_UWB}_LDFLAGS} pthread)
-
-SET_TARGET_PROPERTIES(${CAPI_UWB}
- PROPERTIES
- VERSION ${FULLVER}
- SOVERSION ${MAJORVER}
- CLEAN_DIRECT_OUTPUT 1
-)
-MESSAGE(" - Installing...the library and header files")
-INSTALL(TARGETS ${CAPI_UWB} DESTINATION ${LIB})
-INSTALL(
- DIRECTORY include/ DESTINATION include
- FILES_MATCHING
- PATTERN "include/*.h"
- )
+SET(COMMON_DEPS "dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-system-info")
+SET(PC_DEPS "capi-base-common")
+SET(TEST_DEPS "glib-2.0")
+SET(GTEST_DEPS "gmock")
-SET(PC_NAME ${CAPI_UWB})
-SET(PC_REQUIRED ${PC_DEPS})
-SET(PC_LDFLAGS -l${CAPI_UWB})
+SET(TARGET_UWB "capi-network-uwb")
+SET(TARGET_UWB_TEST "capi-network-uwb-test")
+SET(TARGET_UWB_GTEST "capi-network-uwb-gtest")
-CONFIGURE_FILE(
- ${CAPI_UWB}.pc.in
- ${CMAKE_CURRENT_SOURCE_DIR}/${CAPI_UWB}.pc
- @ONLY
-)
+ADD_DEFINITIONS("-DUSE_DLOG")
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${CAPI_UWB}.pc DESTINATION ${LIB}/pkgconfig)
+ADD_SUBDIRECTORY(include)
+ADD_SUBDIRECTORY(pkgconfig)
+ADD_SUBDIRECTORY(src)
+++ /dev/null
-
-# Package Information for pkg-config
-
-prefix=@PREFIX@
-exec_prefix=/usr
-libdir=@libdir@
-includedir=/usr/include/
-
-Name: @PC_NAME@
-Description: @PACKAGE_DESCRIPTION@
-Version: @VERSION@
-Requires: @PC_REQUIRED@
-Libs: -L${libdir} @PC_LDFLAGS@
-Cflags: -I${includedir}
-
--- /dev/null
+# Copyright (c) 2020 Samsung Electronics Co., Ltd 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.
+#
+# @file CMakeLists.txt
+#
+
+INSTALL(FILES
+ ${CMAKE_SOURCE_DIR}/include/uwb.h
+ DESTINATION ${INCLUDE_DIR}
+ )
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 __UWB_LOG_H__
-#define __UWB_LOG_H__
-
-#include <dlog.h>
-
-#define NOTUSED(var) (var = var)
-
-#define COLOR_BLACK "\033[0;30m"
-#define COLOR_RED "\033[0;31m"
-#define COLOR_GREEN "\033[0;32m"
-#define COLOR_BROWN "\033[0;33m"
-#define COLOR_BLUE "\033[0;34m"
-#define COLOR_PURPLE "\033[0;35m"
-#define COLOR_CYAN "\033[0;36m"
-#define COLOR_GRAY "\033[0;37m"
-#define COLOR_END "\033[0;m"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "UWB_CAPI"
-
-#define _ERR(fmt, ...) \
- do { \
- LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__); \
- } while (0)
-
-#define _INFO(fmt, ...) \
- do { \
- LOGI(COLOR_GREEN fmt COLOR_END, ##__VA_ARGS__); \
- } while (0)
-
-#define _WARN(fmt, ...) \
- do { \
- LOGI(COLOR_BROWN fmt COLOR_END, ##__VA_ARGS__); \
- } while (0)
-
-#define _DBG(fmt, ...) \
- do { \
- LOGD(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#define _BEGIN() \
- do { \
- LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END); \
- } while (0)
-
-#define _END() \
- do { \
- LOGD(COLOR_BLUE "END <<<<" COLOR_END); \
- } while (0)
-
-#define cond_expr_ret(expr, val) \
- do { \
- if (expr) { \
- _ERR("[precond fail] expr : %s, ret : %d\n", #expr, val); \
- return (val); \
- } \
- } while (0)
-
-#define cond_ret(val) \
- do { \
- if (val) { \
- _ERR("[precond fail] ret : %d\n", val); \
- return (val); \
- } \
- } while (0)
-
-#define uwb_check_null_ret_error(name, value, error) \
- do { \
- /* LCOV_EXCL_START */ \
- if (G_UNLIKELY(NULL == (value))) { \
- LOGE("%s is NULL", name); \
- return error; \
- } \
- /* LCOV_EXCL_STOP */ \
- } while (FALSE)
-
-#define uwb_check_null_ret(name, value) \
- do { \
- /* LCOV_EXCL_START */ \
- if (G_UNLIKELY(NULL == (value))) { \
- LOGE("%s is NULL", name); \
- return; \
- } \
- /* LCOV_EXCL_STOP */ \
- } while (FALSE)
-
-#define PRT(format, args...) printf("%s:%d() " format, __FUNCTION__, __LINE__, ##args)
-#define TC_PRT(format, args...) PRT(format "\n", ##args)
-
-#endif /* __UWB_LOG_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 __UWB_PRIVATE_H__
-#define __UWB_PRIVATE_H__
-
-#include <gio/gio.h>
-#include <glib.h>
-#include <uwb.h>
-#include <uwb_log.h>
-#include <uwb_gdbus.h>
-#include <system_info.h>
-
-#define UWB_FEATURE "http://tizen.org/feature/network.uwb"
-
-#define CHECK_INPUT_PARAMETER(arg) \
- if (arg == NULL) { \
- _WARN("INVALID_PARAMETER"); \
- return UWB_ERROR_INVALID_PARAMETER; \
- }
-
-#if 0
-#define CHECK_FEATURE_SUPPORTED(feature_name) \
- { \
- bool uwb_supported = FALSE; \
- if (!system_info_get_platform_bool(feature_name, &uwb_supported)) { \
- if (uwb_supported == FALSE) { \
- _WARN("UWB Manager feature is disabled"); \
- return UWB_ERROR_NOT_SUPPORTED; \
- } \
- } else { \
- _ERR("Error - Feature getting from System Info"); \
- return UWB_ERROR_NOT_SUPPORTED; \
- } \
- }
-#else
-#define CHECK_FEATURE_SUPPORTED(feature_name) \
- { \
- _WARN("[Feature] Should be check !"); \
- }
-#endif
-
-typedef struct {
- uint64_t node_id;
- uint16_t pan_id;
- bool is_remote;
- uint64_t distance;
- int x;
- int y;
- int z;
-} uwb_node_s;
-
-typedef struct {
- uint16_t pan_id;
- GSList *remote_node_list;
- int remote_node_count;
-} uwb_network_s;
-
-#endif /* __UWB_PRIVATE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 __UWB_UTIL_H__
-#define __UWB_UTIL_H__
-
-#include <uwb_private.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-uwb_node_s *uwb_get_node_from_variant(GVariant *va);
-void uwb_network_clean(uwb_network_s *network);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __UWB_UTIL_H__ */
Summary: UWB CAPI
Version: 0.1.1
Release: 0
-Group: Network & Connectivity/Other
+Group: Network & Connectivity/API
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
Source1: %{name}.manifest
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
+%if 0%{?gcov:1}
+BuildRequires: lcov
+BuildRequires: tar
+%endif
+BuildRequires: pkgconfig(gmock)
+
%description
UWB API library
-Group: Network & Connectivity/Other
-Requires: %{name} = %{version}-%{release}
%package devel
Summary: UWB API library (development library)
-Group: Network & Connectivity/Other
+Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
%description devel
This package contains the development files for %{name} API library.
+%package tests
+Summary: Test Application UWB
+Group: Network & Connectivity/Testing
+Requires: %{name} = %{version}-%{release}
+
+%description tests
+Test Application for UWB Framework
+
%if 0%{?gcov:1}
%package gcov
Summary: A UWB gcov Tool
%endif
%prep
-%setup #-q
-chmod g-w %_sourcedir/*
+%setup -q
+chmod 644 %{SOURCE0}
cp %{SOURCE1} ./%{name}.manifest
%build
-CFLAGS=$(echo $CFLAGS | sed 's/-O2/-O0/' | sed 's/-O1/-O0/' | sed 's/-Wp,-D_FORTIFY_SOURCE=2//')
-CXXFLAGS=$(echo $CXXFLAGS | sed 's/-O2/-O0/' | sed 's/-O1/-O0/' | sed 's/-Wp,-D_FORTIFY_SOURCE=2//')
+
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export FFLAGS+=" -fprofile-arcs -ftest-coverage"
export LDFLAGS+=" -lgcov"
%endif
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%define NETWORK_FW_DATADIR %{TZ_SYS_GLOBALUSER_DATA}/network
-%define DBDIR %{TZ_SYS_GLOBALUSER_DATA}/
+cmake . \
+ -DCMAKE_VERBOSE_MAKEFILE=ON \
+ -DLIB_DIR:PATH=%{_libdir} \
+ -DBIN_DIR:PATH=%{_bindir} \
+ -DINCLUDE_DIR:PATH=%{_includedir} \
+ -DFULLVER=%{version} \
+ -DMAJORVER=${MAJORVER}
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
- -DLIB_INSTALL_DIR=%{_libdir} \
- -DBIN_INSTALL_DIR=%{_bindir} \
- -DINCLUDE_INSTALL_DIR=%{_includedir} \
- -DLIB_PATH=%{_lib} \
- -DFULLVER=%{version} \
- -DMAJORVER=${MAJORVER} \
- -DNETWORK_FW_DATADIR=%{NETWORK_FW_DATADIR} \
- -DDBDIR=%{DBDIR} \
- -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0}
+make %{?_smp_mflags}
-make %{?jobs:-j%jobs}
+%install
+
+%make_install
%if 0%{?gcov:1}
-mkdir -p gcov-obj
-find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
+find .. -name '*.gcno' | tar cf %{name}-gcov.tar -T -
+install -d -m 755 %{buildroot}%{_datadir}/gcov/obj
+tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj
%endif
-%install
-rm -rf %{buildroot}/BUILD/%{name}
-%make_install
-
+%check
+#tests/%{name}-gtest
%if 0%{?gcov:1}
-mkdir -p %{buildroot}%{_datadir}/gcov/obj
-install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
+lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info
+genhtml %{name}.info -o out --legend --show-details
%endif
%post -p /sbin/ldconfig
%files
%manifest %{name}.manifest
-%defattr(-,root,root,-)
%license LICENSE.APLv2
+%defattr(-,root,root,-)
%attr(644,-,-) %{_libdir}/lib%{name}.so.*
%files devel
%{_libdir}/pkgconfig/%{name}.pc
%{_includedir}/*.h
+%files tests
+#%{_bindir}/%{name}-test
+#%{_bindir}/%{name}-gtest
+
%if 0%{?gcov:1}
%files gcov
%{_datadir}/gcov/obj/*
--- /dev/null
+# Copyright (c) 2020 Samsung Electronics Co., Ltd 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.
+#
+# @file CMakeLists.txt
+#
+
+SET(PC_NAME ${CAPI_UWB})
+SET(PC_DESCRIPTION ${PACKAGE_DESCRIPTION})
+SET(PC_VERSION ${FULLVER})
+SET(PC_REQUIRED ${PC_DEPS})
+SET(PC_LDFLAGS -l${CAPI_UWB})
+
+CONFIGURE_FILE(${PC_NAME}.pc.in ${PC_NAME}.pc @ONLY)
+
+INSTALL(FILES
+ ${CMAKE_BINARY_DIR}/pkgconfig/${PC_NAME}.pc
+ DESTINATION
+ ${LIB_DIR}/pkgconfig
+ )
--- /dev/null
+# Package Information for pkg-config
+
+libdir=@LIB_DIR@
+includedir=@INCLUDE_DIR@
+
+Name: @PC_NAME@
+Description: @PC_DESCRIPTION@
+Version: @PC_VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
\ No newline at end of file
--- /dev/null
+########################## search for packages ################################
+
+PKG_CHECK_MODULES(UWB_DEPS REQUIRED ${COMMON_DEPS})
+
+############################# compiler flags ##################################
+
+SET(EXTRA_FLAGS "-fPIC -Wall -Werror -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -pie")
+
+######################## directory configuration ############################
+
+INCLUDE_DIRECTORIES(${UWB_DEPS_INCLUDE_DIRS})
+LINK_DIRECTORIES(${UWB_DEPS_LIBRARY_DIRS})
+
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src)
+
+MESSAGE(" - Generating...d-bus code")
+FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
+EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
+ " \\
+ --generate-c-code ${CMAKE_SOURCE_DIR}/src/uwb-gdbus \\
+ --interface-prefix org.tizen.uwb. \\
+ ${CMAKE_SOURCE_DIR}/src/uwb-gdbuslib.xml \\
+ ")
+# Build
+SET(SRCS
+ uwb.c
+ uwb-util.c
+ uwb-gdbus.c
+)
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${UWB_DEPS_LIBRARIES})
+SET_TARGET_PROPERTIES(${PROJECT_NAME}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+)
+
+# Install
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_DIR})
+++ /dev/null
-gdbus-codegen --interface-prefix org.tizen.uwb \
- --generate-c-code uwb_gdbus \
- --c-generate-object-manager \
- uwb-gdbuslib.xml \
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 __UWB_LOG_H__
+#define __UWB_LOG_H__
+
+#include <dlog.h>
+
+#define NOTUSED(var) (var = var)
+
+#define COLOR_BLACK "\033[0;30m"
+#define COLOR_RED "\033[0;31m"
+#define COLOR_GREEN "\033[0;32m"
+#define COLOR_BROWN "\033[0;33m"
+#define COLOR_BLUE "\033[0;34m"
+#define COLOR_PURPLE "\033[0;35m"
+#define COLOR_CYAN "\033[0;36m"
+#define COLOR_GRAY "\033[0;37m"
+#define COLOR_END "\033[0;m"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "UWB_CAPI"
+
+#define _ERR(fmt, ...) \
+ do { \
+ LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__); \
+ } while (0)
+
+#define _INFO(fmt, ...) \
+ do { \
+ LOGI(COLOR_GREEN fmt COLOR_END, ##__VA_ARGS__); \
+ } while (0)
+
+#define _WARN(fmt, ...) \
+ do { \
+ LOGI(COLOR_BROWN fmt COLOR_END, ##__VA_ARGS__); \
+ } while (0)
+
+#define _DBG(fmt, ...) \
+ do { \
+ LOGD(fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define _BEGIN() \
+ do { \
+ LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END); \
+ } while (0)
+
+#define _END() \
+ do { \
+ LOGD(COLOR_BLUE "END <<<<" COLOR_END); \
+ } while (0)
+
+#define cond_expr_ret(expr, val) \
+ do { \
+ if (expr) { \
+ _ERR("[precond fail] expr : %s, ret : %d\n", #expr, val); \
+ return (val); \
+ } \
+ } while (0)
+
+#define cond_ret(val) \
+ do { \
+ if (val) { \
+ _ERR("[precond fail] ret : %d\n", val); \
+ return (val); \
+ } \
+ } while (0)
+
+#define uwb_check_null_ret_error(name, value, error) \
+ do { \
+ /* LCOV_EXCL_START */ \
+ if (G_UNLIKELY(NULL == (value))) { \
+ LOGE("%s is NULL", name); \
+ return error; \
+ } \
+ /* LCOV_EXCL_STOP */ \
+ } while (FALSE)
+
+#define uwb_check_null_ret(name, value) \
+ do { \
+ /* LCOV_EXCL_START */ \
+ if (G_UNLIKELY(NULL == (value))) { \
+ LOGE("%s is NULL", name); \
+ return; \
+ } \
+ /* LCOV_EXCL_STOP */ \
+ } while (FALSE)
+
+#define PRT(format, args...) printf("%s:%d() " format, __FUNCTION__, __LINE__, ##args)
+#define TC_PRT(format, args...) PRT(format "\n", ##args)
+
+#endif /* __UWB_LOG_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 __UWB_PRIVATE_H__
+#define __UWB_PRIVATE_H__
+
+#include <gio/gio.h>
+#include <glib.h>
+#include <uwb.h>
+#include <uwb-log.h>
+#include <system_info.h>
+
+#define UWB_FEATURE "http://tizen.org/feature/network.uwb"
+
+#define CHECK_INPUT_PARAMETER(arg) \
+ if (arg == NULL) { \
+ _WARN("INVALID_PARAMETER"); \
+ return UWB_ERROR_INVALID_PARAMETER; \
+ }
+
+#if 0
+#define CHECK_FEATURE_SUPPORTED(feature_name) \
+ { \
+ bool uwb_supported = FALSE; \
+ if (!system_info_get_platform_bool(feature_name, &uwb_supported)) { \
+ if (uwb_supported == FALSE) { \
+ _WARN("UWB Manager feature is disabled"); \
+ return UWB_ERROR_NOT_SUPPORTED; \
+ } \
+ } else { \
+ _ERR("Error - Feature getting from System Info"); \
+ return UWB_ERROR_NOT_SUPPORTED; \
+ } \
+ }
+#else
+#define CHECK_FEATURE_SUPPORTED(feature_name) \
+ { \
+ _WARN("[Feature] Should be check !"); \
+ }
+#endif
+
+typedef struct {
+ uint64_t node_id;
+ uint16_t pan_id;
+ bool is_remote;
+ uint64_t distance;
+ int x;
+ int y;
+ int z;
+} uwb_node_s;
+
+typedef struct {
+ uint16_t pan_id;
+ GSList *remote_node_list;
+ int remote_node_count;
+} uwb_network_s;
+
+#endif /* __UWB_PRIVATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 <glib.h>
+#include <uwb.h>
+#include <uwb-log.h>
+#include <uwb-private.h>
+#include <stdlib.h>
+
+void _node_free_func(gpointer data)
+{
+ uwb_node_s *node = (uwb_node_s *)data;
+
+ free(node);
+ node = NULL;
+}
+
+void uwb_network_clean(uwb_network_s *network)
+{
+ if (network == NULL)
+ return;
+
+ g_slist_free_full(network->remote_node_list, _node_free_func);
+
+ g_free(network);
+ network = NULL;
+}
+
+uwb_node_s *uwb_get_node_from_variant(GVariant *va)
+{
+ GVariantIter *iter = NULL;
+ const gchar *key;
+ GVariant *key_value = NULL;
+
+ uwb_node_s *node = calloc(1, sizeof(uwb_node_s));
+ if (NULL == node) {
+ _ERR("Memory allocation failed");
+ return NULL;
+ }
+
+ g_variant_get(va, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
+ if (g_strcmp0(key, "Distance") == 0)
+ node->distance = g_variant_get_uint64(key_value);
+ else if (g_strcmp0(key, "NodeID") == 0)
+ node->node_id = g_variant_get_uint64(key_value);
+ else if (g_strcmp0(key, "PanID") == 0)
+ node->pan_id = g_variant_get_uint16(key_value);
+ else if (g_strcmp0(key, "X") == 0)
+ node->x = g_variant_get_int32(key_value);
+ else if (g_strcmp0(key, "Y") == 0)
+ node->y = g_variant_get_int32(key_value);
+ else if (g_strcmp0(key, "Z") == 0)
+ node->z = g_variant_get_int32(key_value);
+ }
+
+ g_variant_iter_free(iter);
+
+ return node;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 __UWB_UTIL_H__
+#define __UWB_UTIL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+uwb_node_s *uwb_get_node_from_variant(GVariant *va);
+void uwb_network_clean(uwb_network_s *network);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UWB_UTIL_H__ */
#include <dlog.h>
#include <uwb.h>
-#include <uwb_log.h>
-#include <uwb_private.h>
-#include <uwb_gdbus.h>
-#include <uwb_util.h>
+#include <uwb-log.h>
+#include <uwb-private.h>
+#include <uwb-gdbus.h>
+#include <uwb-util.h>
#include <inttypes.h>
#define UWB_DBUS_SERVICE "org.tizen.uwb" /**< For uwb dbus */
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd. 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 <glib.h>
-#include <uwb.h>
-#include <uwb_log.h>
-#include <uwb_private.h>
-#include <stdlib.h>
-
-void _node_free_func(gpointer data)
-{
- uwb_node_s *node = (uwb_node_s *)data;
-
- free(node);
- node = NULL;
-}
-
-void uwb_network_clean(uwb_network_s *network)
-{
- if (network == NULL)
- return;
-
- g_slist_free_full(network->remote_node_list, _node_free_func);
-
- g_free(network);
- network = NULL;
-}
-
-uwb_node_s *uwb_get_node_from_variant(GVariant *va)
-{
- GVariantIter *iter = NULL;
- const gchar *key;
- GVariant *key_value = NULL;
-
- uwb_node_s *node = calloc(1, sizeof(uwb_node_s));
- if (NULL == node) {
- _ERR("Memory allocation failed");
- return NULL;
- }
-
- g_variant_get(va, "a{sv}", &iter);
- while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
- if (g_strcmp0(key, "Distance") == 0)
- node->distance = g_variant_get_uint64(key_value);
- else if (g_strcmp0(key, "NodeID") == 0)
- node->node_id = g_variant_get_uint64(key_value);
- else if (g_strcmp0(key, "PanID") == 0)
- node->pan_id = g_variant_get_uint16(key_value);
- else if (g_strcmp0(key, "X") == 0)
- node->x = g_variant_get_int32(key_value);
- else if (g_strcmp0(key, "Y") == 0)
- node->y = g_variant_get_int32(key_value);
- else if (g_strcmp0(key, "Z") == 0)
- node->z = g_variant_get_int32(key_value);
- }
-
- g_variant_iter_free(iter);
-
- return node;
-}