Rearrange folder 22/242422/1
authorYu <jiung.yu@samsung.com>
Thu, 27 Aug 2020 00:08:43 +0000 (09:08 +0900)
committerYu <jiung.yu@samsung.com>
Thu, 27 Aug 2020 00:09:07 +0000 (09:09 +0900)
Change-Id: I34c301ae4dbff30d25e66e12c9b7ddec91be466d
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
17 files changed:
CMakeLists.txt
capi-network-uwb.pc.in [deleted file]
include/CMakeLists.txt [new file with mode: 0644]
include/uwb_log.h [deleted file]
include/uwb_private.h [deleted file]
include/uwb_util.h [deleted file]
packaging/capi-network-uwb.spec
pkgconfig/CMakeLists.txt [new file with mode: 0644]
pkgconfig/capi-network-uwb.pc.in [new file with mode: 0644]
src/CMakeLists.txt [new file with mode: 0644]
src/gen.sh [deleted file]
src/uwb-log.h [new file with mode: 0755]
src/uwb-private.h [new file with mode: 0755]
src/uwb-util.c [new file with mode: 0755]
src/uwb-util.h [new file with mode: 0755]
src/uwb.c
src/uwb_util.c [deleted file]

index 4425f6511a742ed46f1157192327b570c1bbf203..516c32fdde3fb7254081343c51e2b6af60899030 100644 (file)
@@ -1,84 +1,41 @@
-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)
diff --git a/capi-network-uwb.pc.in b/capi-network-uwb.pc.in
deleted file mode 100644 (file)
index c45e5b2..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-
-# 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}
-
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
new file mode 100644 (file)
index 0000000..55a2db4
--- /dev/null
@@ -0,0 +1,21 @@
+# 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}
+    )
diff --git a/include/uwb_log.h b/include/uwb_log.h
deleted file mode 100755 (executable)
index f20a398..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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__ */
diff --git a/include/uwb_private.h b/include/uwb_private.h
deleted file mode 100755 (executable)
index d0e8d2b..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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__ */
diff --git a/include/uwb_util.h b/include/uwb_util.h
deleted file mode 100755 (executable)
index de78287..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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__ */
index 55149ca58595d6b9a79d596fc219491835e76310..48b5eee3b24e8873405cd225836e1021dd6c97f3 100644 (file)
@@ -2,7 +2,7 @@ Name:       capi-network-uwb
 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
@@ -17,19 +17,31 @@ BuildRequires: pkgconfig(capi-system-info)
 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
@@ -40,48 +52,50 @@ UWB gcov objects
 %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
@@ -91,8 +105,8 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
 
 %files
 %manifest %{name}.manifest
-%defattr(-,root,root,-)
 %license LICENSE.APLv2
+%defattr(-,root,root,-)
 %attr(644,-,-) %{_libdir}/lib%{name}.so.*
 
 %files devel
@@ -101,6 +115,10 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
 %{_libdir}/pkgconfig/%{name}.pc
 %{_includedir}/*.h
 
+%files tests
+#%{_bindir}/%{name}-test
+#%{_bindir}/%{name}-gtest
+
 %if 0%{?gcov:1}
 %files gcov
 %{_datadir}/gcov/obj/*
diff --git a/pkgconfig/CMakeLists.txt b/pkgconfig/CMakeLists.txt
new file mode 100644 (file)
index 0000000..44ff5e3
--- /dev/null
@@ -0,0 +1,30 @@
+# 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
+    )
diff --git a/pkgconfig/capi-network-uwb.pc.in b/pkgconfig/capi-network-uwb.pc.in
new file mode 100644 (file)
index 0000000..72dcd2b
--- /dev/null
@@ -0,0 +1,11 @@
+# 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
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3c99212
--- /dev/null
@@ -0,0 +1,43 @@
+########################## 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})
diff --git a/src/gen.sh b/src/gen.sh
deleted file mode 100755 (executable)
index c41531f..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-gdbus-codegen --interface-prefix org.tizen.uwb \
-        --generate-c-code uwb_gdbus \
-        --c-generate-object-manager \
-        uwb-gdbuslib.xml \
diff --git a/src/uwb-log.h b/src/uwb-log.h
new file mode 100755 (executable)
index 0000000..f20a398
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * 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__ */
diff --git a/src/uwb-private.h b/src/uwb-private.h
new file mode 100755 (executable)
index 0000000..b317bb9
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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__ */
diff --git a/src/uwb-util.c b/src/uwb-util.c
new file mode 100755 (executable)
index 0000000..5a4a563
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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;
+}
diff --git a/src/uwb-util.h b/src/uwb-util.h
new file mode 100755 (executable)
index 0000000..c30859c
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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__ */
index 4c4689378f6ba75d47a5743400a4d30a86984e14..b5bac02c8252657b6b1fb8a51deb5112793fa71f 100755 (executable)
--- a/src/uwb.c
+++ b/src/uwb.c
 
 #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 */
diff --git a/src/uwb_util.c b/src/uwb_util.c
deleted file mode 100755 (executable)
index ecaae35..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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;
-}