From: Sangchul Lee Date: Tue, 18 Apr 2023 07:41:48 +0000 (+0900) Subject: Add common/espp_service_common.h for being used commonly in client/daemon X-Git-Tag: accepted/tizen/unified/20231025.120143~79 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a145e2340e314b076302aefa8734c97e16c31f3f;p=platform%2Fcore%2Fmultimedia%2Fespp-service.git Add common/espp_service_common.h for being used commonly in client/daemon Signed-off-by: Sangchul Lee --- diff --git a/meson.build b/meson.build index aa7481c..e896ffe 100644 --- a/meson.build +++ b/meson.build @@ -25,6 +25,7 @@ message('libdir_path[' + libdir_path + ']') message('================ common options ================') conf_data.set('ESPP_SERVICE_VERSION', get_option('version')) +conf_data.set('ESPP_SERVICE_SOCK_PATH', get_option('sock-path')) if get_option('dlog') message('dlog option is enabled, set USE_DLOG') diff --git a/meson_options.txt b/meson_options.txt index 26668b3..bced386 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ option('version', type: 'string', value: '0.0.0', description: 'ESPP service version') +option('sock-path', type: 'string', value: '/tmp/espp_service.socket', description: 'ESPP service socket path') option('dlog', type: 'boolean', value: true, description: 'Use dlog') \ No newline at end of file diff --git a/packaging/espp-service.spec b/packaging/espp-service.spec index eca578f..523de2c 100644 --- a/packaging/espp-service.spec +++ b/packaging/espp-service.spec @@ -45,6 +45,7 @@ meson setup --auto-features=disabled \ --libdir=%{_lib_dir} \ --datadir=%{_datadir} \ -Dversion=%{version} \ + -Dsock-path=/run/espp_service.sock \ build ninja -C build diff --git a/src/common/espp_service_common.h b/src/common/espp_service_common.h new file mode 100644 index 0000000..f1cc934 --- /dev/null +++ b/src/common/espp_service_common.h @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2023 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 __ESPP_SERVICE_COMMON_H__ +#define __ESPP_SERVICE_COMMON_H__ + +#ifdef HAVE_CONFIG_H +#include +#define GET_STRING(x) #x +#define TO_STRING(x) GET_STRING(x) +#define ESPP_SVC_VERSION TO_STRING(ESPP_SERVICE_VERSION) +#define ESPP_SVC_SOCK_PATH TO_STRING(ESPP_SERVICE_SOCK_PATH) +#else +#define ESPP_SVC_VERSION "unknown" +#define ESPP_SVC_SOCK_PATH "/tmp/espp_service.socket" +#endif +#include +#include +#include +#ifdef USE_DLOG +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define FONT_COLOR_RESET "\033[0m" +#define FONT_COLOR_RED "\033[31m" +#define FONT_COLOR_GREEN "\033[32m" +#define FONT_COLOR_YELLOW "\033[33m" +#define FONT_COLOR_BLUE "\033[34m" +#define FONT_COLOR_PURPLE "\033[35m" +#define FONT_COLOR_CYAN "\033[36m" +#define FONT_COLOR_GRAY "\033[37m" + +#ifdef USE_DLOG +#define LOG_DEBUG(fmt, arg...) \ +do { \ + LOGD(FONT_COLOR_RESET""fmt""FONT_COLOR_RESET, ##arg); \ +} while (0) + +#define LOG_INFO(fmt, arg...) \ +do { \ + LOGI(FONT_COLOR_GREEN""fmt""FONT_COLOR_RESET, ##arg); \ +} while (0) + +#define LOG_WARNING(fmt, arg...) \ +do { \ + LOGW(FONT_COLOR_YELLOW""fmt""FONT_COLOR_RESET, ##arg); \ +} while (0) + +#define LOG_ERROR(fmt, arg...) \ +do { \ + LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \ +} while (0) + +#define LOG_DEBUG_ENTER() \ +do { \ + LOGD(FONT_COLOR_PURPLE""FONT_COLOR_RESET); \ +} while (0) + +#define LOG_DEBUG_LEAVE() \ +do { \ + LOGD(FONT_COLOR_PURPLE""FONT_COLOR_RESET); \ +} while (0) + +#else +#define LOG_DEBUG(fmt, arg...) printf(FONT_COLOR_RESET""fmt"\n"FONT_COLOR_RESET, ##arg); +#define LOG_INFO(fmt, arg...) printf(FONT_COLOR_GREEN""fmt"\n"FONT_COLOR_RESET, ##arg); +#define LOG_WARNING(fmt, arg...) printf(FONT_COLOR_YELLOW""fmt"\n"FONT_COLOR_RESET, ##arg); +#define LOG_ERROR(fmt, arg...) printf(FONT_COLOR_RED""fmt"\n"FONT_COLOR_RESET, ##arg); +#define LOG_DEBUG_ENTER() printf(FONT_COLOR_PURPLE"\n"FONT_COLOR_RESET); +#define LOG_DEBUG_LEAVE() printf(FONT_COLOR_PURPLE"\n"FONT_COLOR_RESET); +#endif + +#define RET_IF(expr, fmt, arg...) \ +do { \ + if ((expr)) { \ + LOG_ERROR(""fmt"", ##arg); \ + return; \ + } \ +} while (0) + +#define RET_VAL_IF(expr, val, fmt, arg...) \ +do { \ + if ((expr)) { \ + LOG_ERROR(""fmt"", ##arg); \ + return (val);\ + } \ +} while (0) + +#define UNLIKELY(x) (__builtin_expect(!!(x),0)) +#define ASSERT(expr) \ +do {\ + if (UNLIKELY(!(expr))) { \ + LOG_ERROR("Assertion '%s' failed. Aborting.", #expr); \ + abort(); \ + } \ +} while (0) + +#define ESPP_SERVICE_SOCK ESPP_SVC_SOCK_PATH +#define MAX_FUNC_LEN 32 + +typedef struct { + char func[MAX_FUNC_LEN]; +} espp_service_data_from_client_s; + +typedef struct { + int ret; +} espp_service_data_from_server_s; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __ESPP_SERVICE_COMMON_H__ */ diff --git a/src/daemon/espp_service_priv.h b/src/daemon/espp_service_priv.h index 0c855ee..21bded1 100644 --- a/src/daemon/espp_service_priv.h +++ b/src/daemon/espp_service_priv.h @@ -17,104 +17,16 @@ #ifndef __ESPP_SERVICE_PRIV_H__ #define __ESPP_SERVICE_PRIV_H__ -#ifdef HAVE_CONFIG_H -#include -#define GET_STRING(x) #x -#define TO_STRING(x) GET_STRING(x) -#define ESPP_SVC_VERSION TO_STRING(ESPP_SERVICE_VERSION) -#else -#define ESPP_SVC_VERSION "unknown" -#endif -#include -#include -#include -#ifdef USE_DLOG -#include -#endif +#include "../common/espp_service_common.h" #ifdef __cplusplus extern "C" { #endif -#ifdef LOG_TAG -#undef LOG_TAG -#endif - -#define FONT_COLOR_RESET "\033[0m" -#define FONT_COLOR_RED "\033[31m" -#define FONT_COLOR_GREEN "\033[32m" -#define FONT_COLOR_YELLOW "\033[33m" -#define FONT_COLOR_BLUE "\033[34m" -#define FONT_COLOR_PURPLE "\033[35m" -#define FONT_COLOR_CYAN "\033[36m" -#define FONT_COLOR_GRAY "\033[37m" - #ifdef USE_DLOG #define LOG_TAG "ESPP_SERVICE" -#define LOG_DEBUG(fmt, arg...) \ -do { \ - LOGD(FONT_COLOR_RESET""fmt""FONT_COLOR_RESET, ##arg); \ -} while (0) - -#define LOG_INFO(fmt, arg...) \ -do { \ - LOGI(FONT_COLOR_GREEN""fmt""FONT_COLOR_RESET, ##arg); \ -} while (0) - -#define LOG_WARNING(fmt, arg...) \ -do { \ - LOGW(FONT_COLOR_YELLOW""fmt""FONT_COLOR_RESET, ##arg); \ -} while (0) - -#define LOG_ERROR(fmt, arg...) \ -do { \ - LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \ -} while (0) - -#define LOG_DEBUG_ENTER() \ -do { \ - LOGD(FONT_COLOR_PURPLE""FONT_COLOR_RESET); \ -} while (0) - -#define LOG_DEBUG_LEAVE() \ -do { \ - LOGD(FONT_COLOR_PURPLE""FONT_COLOR_RESET); \ -} while (0) - -#else -#define LOG_DEBUG(fmt, arg...) printf(FONT_COLOR_RESET""fmt"\n"FONT_COLOR_RESET, ##arg); -#define LOG_INFO(fmt, arg...) printf(FONT_COLOR_GREEN""fmt"\n"FONT_COLOR_RESET, ##arg); -#define LOG_WARNING(fmt, arg...) printf(FONT_COLOR_YELLOW""fmt"\n"FONT_COLOR_RESET, ##arg); -#define LOG_ERROR(fmt, arg...) printf(FONT_COLOR_RED""fmt"\n"FONT_COLOR_RESET, ##arg); -#define LOG_DEBUG_ENTER() printf(FONT_COLOR_PURPLE"\n"FONT_COLOR_RESET); -#define LOG_DEBUG_LEAVE() printf(FONT_COLOR_PURPLE"\n"FONT_COLOR_RESET); #endif -#define RET_IF(expr, fmt, arg...) \ -do { \ - if ((expr)) { \ - LOG_ERROR(""fmt"", ##arg); \ - return; \ - } \ -} while (0) - -#define RET_VAL_IF(expr, val, fmt, arg...) \ -do { \ - if ((expr)) { \ - LOG_ERROR(""fmt"", ##arg); \ - return (val);\ - } \ -} while (0) - -#define UNLIKELY(x) (__builtin_expect(!!(x),0)) -#define ASSERT(expr) \ -do {\ - if (UNLIKELY(!(expr))) { \ - LOG_ERROR("Assertion '%s' failed. Aborting.", #expr); \ - abort(); \ - } \ -} while (0) - typedef struct { bool start_service; GMainLoop *mainloop; diff --git a/src/daemon/espp_service_socket.c b/src/daemon/espp_service_socket.c index 9090fdc..3c9c891 100644 --- a/src/daemon/espp_service_socket.c +++ b/src/daemon/espp_service_socket.c @@ -21,17 +21,7 @@ #include #include -#define ESPP_SERVICE_SOCK "/run/espp_service.socket" #define MAX_ERROR_LEN 64 -#define MAX_FUNC_LEN 32 - -typedef struct { - char func[MAX_FUNC_LEN]; -} espp_service_data_from_client_s; - -typedef struct { - int ret; -} espp_service_data_from_server_s; static void *__work_thread_func(void *data) {