Revise member variables in espp_service_data_from_client_s and apply it
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 21 Apr 2023 02:10:26 +0000 (11:10 +0900)
committer이상철/Tizen Platform Lab(SR)/삼성전자 <sc11.lee@samsung.com>
Mon, 24 Apr 2023 05:07:39 +0000 (14:07 +0900)
common/espp_service_common.c is added.

[Version] 0.1.1

Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/espp-service.spec
src/client/espp_service_client_socket.c
src/client/meson.build
src/common/espp_service_common.c [new file with mode: 0644]
src/common/espp_service_common.h
src/daemon/espp_service_handler.c
src/daemon/espp_service_socket.c
src/daemon/meson.build

index 7a9e35e1ece66a98e27ea11fc9fcb9b8b0c5daf4..bb2f79e1c55ec89589a875aee402f654a177581a 100644 (file)
@@ -1,6 +1,6 @@
 Name:       espp-service
 Summary:    ESPP service package which contains client lib. and daemon binary
-Version:    0.1.0
+Version:    0.1.1
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 3944d269f689f76ae89cd38f0ff0e46128872dd2..6295640be1d1d786a4107026e57b6553c36dac4c 100644 (file)
@@ -31,10 +31,16 @@ do { \
        x_dst[x_size - 1] = '\0';\
 } while (0) \
 
-#define FILL_SOCKET_MSG_FUNC(x_msg, x_func) \
+#define FILL_SOCKET_MSG_PARAMS(x_msg, x_params) \
 do { \
-       memset(&x_msg.func, 0x00, MAX_FUNC_LEN); \
-       STRNCPY(x_msg.func, x_func, MAX_FUNC_LEN); \
+       memset(&x_msg.params, 0x00, MAX_PARAMS_LEN); \
+       STRNCPY(x_msg.params, x_params, MAX_PARAMS_LEN); \
+} while (0) \
+
+
+#define FILL_SOCKET_MSG_REQUEST(x_msg, x_request) \
+do { \
+       x_msg.request = x_request; \
 } while (0) \
 
 #define RET_VAL_IF_SERVER_RESULT_ERROR(x_result, x_val) \
@@ -119,7 +125,7 @@ static int send_data(int fd, espp_service_data_from_client_s *data, espp_service
                return -1;
        }
 
-       LOG_DEBUG("fd[%d] func[%s], ret[%d]", fd, data->func, result->ret);
+       LOG_DEBUG("fd[%d] request[%d], ret[%d]", fd, data->request, result->ret);
 
        return 0;
 }
@@ -138,7 +144,7 @@ int espp_service_client_socket_request_create(espp_s *espp)
        if (connect_socket(fd) != 0)
                goto error;
 
-       FILL_SOCKET_MSG_FUNC(data, ESPP_FUNC_CREATE);
+       FILL_SOCKET_MSG_REQUEST(data, ESPP_SERVICE_REQUEST_CREATE);
        if (send_data(fd, &data, &result) != 0)
                goto error;
        if (result.ret != 0) {
@@ -166,7 +172,7 @@ int espp_service_client_socket_request_destroy(espp_s *espp)
        ASSERT(espp);
        RET_VAL_IF(espp->fd == -1, -1, "fd is -1");
 
-       FILL_SOCKET_MSG_FUNC(data, ESPP_FUNC_DESTROY);
+       FILL_SOCKET_MSG_REQUEST(data, ESPP_SERVICE_REQUEST_DESTROY);
        if (send_data(espp->fd, &data, &result) != 0)
                return -1;
 
@@ -188,7 +194,7 @@ int espp_service_client_socket_request_start(espp_s *espp)
        ASSERT(espp);
        RET_VAL_IF(espp->fd == -1, -1, "fd is -1");
 
-       FILL_SOCKET_MSG_FUNC(data, ESPP_FUNC_START);
+       FILL_SOCKET_MSG_REQUEST(data, ESPP_SERVICE_REQUEST_START);
        if (send_data(espp->fd, &data, &result) != 0)
                return -1;
 
index 57edd4b8491fc37c2fe26460d60142e295e64277..61c2ce0c6d5dad14ab36686a8d78e8a4a63fbe64 100644 (file)
@@ -7,6 +7,7 @@ install_headers(espp_service_client_headers)
 espp_service_client_deps = []
 
 espp_service_client_sources = files([
+  '../common/espp_service_common.c',
   'espp_service_client.c',
   'espp_service_client_socket.c',
 ])
diff --git a/src/common/espp_service_common.c b/src/common/espp_service_common.c
new file mode 100644 (file)
index 0000000..6b3a63e
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+#include "espp_service_common.h"
+
+espp_service_request_s requests[] = { /* str, num_of_params */
+       [ESPP_SERVICE_REQUEST_CREATE] = { "Create", 0 },
+       [ESPP_SERVICE_REQUEST_DESTROY] = {"Destroy", 0 },
+       [ESPP_SERVICE_REQUEST_START] = { "Start", 0 },
+};
\ No newline at end of file
index 363127e90991f33d6f7491fa62f4d1d90f8d3d58..a7e3122f534604e798db28d4eef20ab7ed0e9bd9 100644 (file)
@@ -116,22 +116,32 @@ do {\
        } \
 } while (0)
 
-#define ESPP_FUNC_CREATE         "Create"
-#define ESPP_FUNC_DESTROY        "Destroy"
-#define ESPP_FUNC_START          "Start"
-
 #define ESPP_SERVICE_SOCK ESPP_SVC_SOCK_PATH
-#define MAX_FUNC_LEN 32
+#define MAX_PARAMS_LEN 128
 #define MAX_ERROR_LEN 64
 
+typedef enum {
+       ESPP_SERVICE_REQUEST_CREATE,
+       ESPP_SERVICE_REQUEST_DESTROY,
+       ESPP_SERVICE_REQUEST_START,
+} espp_service_request_e;
+
 typedef struct {
-       char func[MAX_FUNC_LEN];
+       espp_service_request_e request;
+       char params[MAX_PARAMS_LEN];
 } espp_service_data_from_client_s;
 
 typedef struct {
        int ret;
 } espp_service_data_from_server_s;
 
+typedef struct {
+       const char *str;
+       int num_of_params;
+} espp_service_request_s;
+
+extern espp_service_request_s requests[];
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 540fcdcdbd6e2126db117f4b18ca063f4eacc6ec..2311c83fa476854fa1d6021a87323130cffc4174 100644 (file)
 #include "espp_service_priv.h"
 #include <esplusplayer_capi.h>
 
-typedef void (*func_handler) (espp_service_s *svc, int fd, espp_service_data_from_client_s *param, espp_service_data_from_server_s *result);
+typedef void (*func_handler) (espp_service_s *svc, int fd, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result);
 
-enum {
-       ESPP_SERVICE_MSG_CREATE,
-       ESPP_SERVICE_MSG_DESTROY,
-       ESPP_SERVICE_MSG_START,
-};
-
-typedef struct {
-       const char *api;
-       func_handler handler;
-} espp_service_msg_handler_intf_s;
-
-static void __handle_create(espp_service_s *svc, int fd, espp_service_data_from_client_s *param, espp_service_data_from_server_s *result)
+static void __handle_create(espp_service_s *svc, int fd, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)
 {
        esplusplayer_handle espp;
 
        ASSERT(svc);
        ASSERT(fd >= 0);
-       ASSERT(param);
+       ASSERT(data);
        ASSERT(result);
 
        result->ret = -1;
@@ -56,13 +45,13 @@ static void __handle_create(espp_service_s *svc, int fd, espp_service_data_from_
        result->ret = 0;
 }
 
-static void __handle_destroy(espp_service_s *svc, int fd, espp_service_data_from_client_s *param, espp_service_data_from_server_s *result)
+static void __handle_destroy(espp_service_s *svc, int fd, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)
 {
        esplusplayer_handle espp;
 
        ASSERT(svc);
        ASSERT(fd >= 0);
-       ASSERT(param);
+       ASSERT(data);
        ASSERT(result);
 
        result->ret = -1;
@@ -77,14 +66,14 @@ static void __handle_destroy(espp_service_s *svc, int fd, espp_service_data_from
        result->ret = 0;
 }
 
-static void __handle_start(espp_service_s *svc, int fd, espp_service_data_from_client_s *param, espp_service_data_from_server_s *result)
+static void __handle_start(espp_service_s *svc, int fd, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)
 {
        int ret;
        esplusplayer_handle espp;
 
        ASSERT(svc);
        ASSERT(fd >= 0);
-       ASSERT(param);
+       ASSERT(data);
        ASSERT(result);
 
        result->ret = -1;
@@ -99,53 +88,22 @@ static void __handle_start(espp_service_s *svc, int fd, espp_service_data_from_c
        result->ret = 0;
 }
 
-static espp_service_msg_handler_intf_s handlers[] = {
-       [ESPP_SERVICE_MSG_CREATE] = {
-               .api = ESPP_FUNC_CREATE,
-               .handler = __handle_create
-       },
-       [ESPP_SERVICE_MSG_DESTROY] = {
-               .api = ESPP_FUNC_DESTROY,
-               .handler = __handle_destroy
-       },
-       [ESPP_SERVICE_MSG_START] = {
-               .api = ESPP_FUNC_START,
-               .handler = __handle_start
-       },
+static func_handler handlers[] = {
+       [ESPP_SERVICE_REQUEST_CREATE] = __handle_create,
+       [ESPP_SERVICE_REQUEST_DESTROY] = __handle_destroy,
+       [ESPP_SERVICE_REQUEST_START] = __handle_start,
 };
 
-static int get_msg_type(const char *func)
-{
-       RET_VAL_IF(!func, -1, "func is NULL");
-
-       if (g_strcmp0(func, ESPP_FUNC_CREATE) == 0)
-               return ESPP_SERVICE_MSG_CREATE;
-       if (g_strcmp0(func, ESPP_FUNC_DESTROY) == 0)
-               return ESPP_SERVICE_MSG_DESTROY;
-       if (g_strcmp0(func, ESPP_FUNC_START) == 0)
-               return ESPP_SERVICE_MSG_START;
-
-       LOG_ERROR("not supported func[%s]", func);
-       return -1;
-}
-
-int espp_service_func_handler(espp_service_s *svc, int fd, espp_service_data_from_client_s *request, espp_service_data_from_server_s *result)
+int espp_service_func_handler(espp_service_s *svc, int fd, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)
 {
-       int ret;
-
        ASSERT(svc);
        ASSERT(fd >= 0);
-       ASSERT(request);
+       ASSERT(data);
        ASSERT(result);
 
-       LOG_WARNING("fd[%d] request[%p, func:%s]", fd, request, request->func);
-
-       if ((ret = get_msg_type(request->func)) == -1) {
-               result->ret = -1;
-               return ret;
-       }
+       LOG_WARNING("fd[%d] data[%p, request:%s]", fd, data, requests[data->request].str);
 
-       handlers[ret].handler(svc, fd, request, result);
+       handlers[data->request](svc, fd, data, result);
 
        return 0;
 }
index ffae560b2bd02daf4b2048a6ce8dd44f5b2f2967..d84f72f3f0d4632cf79fb156ade7672497549ddf 100644 (file)
@@ -23,7 +23,7 @@
 
 #define EXIT_IF_NEEDED(x_rx_data) \
 do { \
-       if (g_strcmp0(x_rx_data.func, ESPP_FUNC_DESTROY) == 0) \
+       if (x_rx_data.request == ESPP_SERVICE_REQUEST_DESTROY) \
                goto exit; \
 } while (0)
 
@@ -58,7 +58,7 @@ static void *__work_thread_func(void *data)
 
                } else if (ret == sizeof(espp_service_data_from_client_s)) {
 
-                       LOG_DEBUG("<<<<< from fd[%d]: func[%s]", fd, rx_data.func);
+                       LOG_DEBUG("<<<<< from fd[%d]: request[%s]", fd, requests[rx_data.request].str);
 
                        memset(&tx_data, 0x00, sizeof(espp_service_data_from_server_s));
                        if (espp_service_func_handler(svc, fd, &rx_data, &tx_data) != 0)
index ad5287efbeb9cd1d7e17bcf66401a439d0e7f3f3..3a4d3dc66cfe02a17cd516a411fb2d091a98b456 100644 (file)
@@ -1,4 +1,5 @@
 espp_service_sources = [
+  '../common/espp_service_common.c',
   'espp_service.c',
   'espp_service_socket.c',
   'espp_service_handler.c',