Add common/espp_service_common.h for being used commonly in client/daemon
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 18 Apr 2023 07:41:48 +0000 (16:41 +0900)
committer이상철/Tizen Platform Lab(SR)/삼성전자 <sc11.lee@samsung.com>
Wed, 19 Apr 2023 07:54:10 +0000 (16:54 +0900)
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
meson.build
meson_options.txt
packaging/espp-service.spec
src/common/espp_service_common.h [new file with mode: 0644]
src/daemon/espp_service_priv.h
src/daemon/espp_service_socket.c

index aa7481cdc924469510bac3dfbd1fe5083d499f7f..e896ffede66b19536e9c76885b77ced425e5a8e8 100644 (file)
@@ -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')
index 26668b37a16640e5321b5c8b1bfa7b76303e132b..bced3864e01a967626a9a8c47e2950f6b9ef9ab4 100644 (file)
@@ -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
index eca578fd1e7958541add3667cede6fdbd5ccef16..523de2c2bd73bcd189f8d3f155add818eebb1188 100644 (file)
@@ -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 (file)
index 0000000..f1cc934
--- /dev/null
@@ -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 <config.h>
+#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 <stdlib.h>
+#include <glib.h>
+#include <stdbool.h>
+#ifdef USE_DLOG
+#include <dlog.h>
+#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"<Enter>"FONT_COLOR_RESET); \
+} while (0)
+
+#define LOG_DEBUG_LEAVE() \
+do { \
+       LOGD(FONT_COLOR_PURPLE"<Leave>"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"<Enter>\n"FONT_COLOR_RESET);
+#define LOG_DEBUG_LEAVE() printf(FONT_COLOR_PURPLE"<Leave>\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__ */
index 0c855eec7653c0adea25a829ff384060da5720ba..21bded194eb049070da4418e68472a7056a7b22c 100644 (file)
 #ifndef __ESPP_SERVICE_PRIV_H__
 #define __ESPP_SERVICE_PRIV_H__
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#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 <stdlib.h>
-#include <glib.h>
-#include <stdbool.h>
-#ifdef USE_DLOG
-#include <dlog.h>
-#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"<Enter>"FONT_COLOR_RESET); \
-} while (0)
-
-#define LOG_DEBUG_LEAVE() \
-do { \
-       LOGD(FONT_COLOR_PURPLE"<Leave>"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"<Enter>\n"FONT_COLOR_RESET);
-#define LOG_DEBUG_LEAVE() printf(FONT_COLOR_PURPLE"<Leave>\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;
index 9090fdce2ecfe6bf85cea67c8c41be8bd6ad30a5..3c9c891959500162dbd38b2a68480835c0343d0a 100644 (file)
 #include <sys/un.h>
 #include <pthread.h>
 
-#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)
 {