common/espp_service_common.c is added.
[Version] 0.1.1
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
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
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) \
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;
}
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) {
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;
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;
espp_service_client_deps = []
espp_service_client_sources = files([
+ '../common/espp_service_common.c',
'espp_service_client.c',
'espp_service_client_socket.c',
])
--- /dev/null
+/*
+ * 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
} \
} 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 */
#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;
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;
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;
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;
}
#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)
} 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)
espp_service_sources = [
+ '../common/espp_service_common.c',
'espp_service.c',
'espp_service_socket.c',
'espp_service_handler.c',