diff options
Diffstat (limited to 'src/ipc_server.c')
-rw-r--r-- | src/ipc_server.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/ipc_server.c b/src/ipc_server.c new file mode 100644 index 0000000..a17deb8 --- /dev/null +++ b/src/ipc_server.c @@ -0,0 +1,119 @@ +/** + * @file interface.c + * @brief API interface server + + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * This software is the confidential and proprietary information + * of Samsung Electronics, Inc. ("Confidential Information"). You + * shall not disclose such Confidential Information and shall use + * it only in accordance with the terms of the license agreement + * you entered into with Samsung. + */ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <pthread.h> +#include "sa_common.h" +#include "sa_types.h" +#include "ipc.h" +#include "ipc_config.h" + +#define MAXLINE 1024 + +int IPC_StartServer(char *(*pFunc) (char *, int)) +{ + SOCKET_HANDLE handle; + int ret = 0; + char *buf = NULL; + int msgSize = 0; + char *ret_buf = NULL; + + _D("adaptor_api_server start"); + + ret = IPC_OpenServerConnection(SERVER, &handle); + + _D("IPC_OpenServerConnection ret=%d", ret); + + if (ret >= 0) { + while (1) { + if (IPC_ClientAccept(&handle) != -1) { + ret = IPC_GetMessage(&handle, &msgSize); + _D("<<Server>> msgSize = %d", msgSize); + + if (msgSize > 0) { + buf = (char *)malloc(msgSize + 1); + if (buf == NULL) { + _D("adaptor_api_server buff is null!!"); + IPC_SocketOpenClientClose(&handle); + IPC_OpenServerClose(&handle); + return -1; + } + memset(buf, 0x00, msgSize + 1); + + IPC_RecvMessage(&handle, buf, msgSize); + //_D("<<Server>> recvData = %s", buf); + /* Server mainloop */ + ret_buf = pFunc(buf, strlen(buf)); + + //_D("<<Server>> sendData = %s", ret_buf); + if (ret_buf != NULL) { + IPC_SendMessage(&handle, ret_buf, strlen(ret_buf)); + free(ret_buf); + } + + if (buf != NULL) + free(buf); + } + IPC_SocketOpenClientClose(&handle); + } + } + ret = IPC_OpenServerClose(&handle); + } else { + _E("<<Server>> server open error !!"); + return -1; + } + + _D("<<Server>> close"); + return 0; + +} + +static SOCKET_HANDLE __cbhndl; +static SOCKET_HANDLE *__pcbhndl = NULL; + +static int __open_callback_connection(void) +{ + int ret = 0; + + _D("[SERVER-CB] adaptor_server start (%s)", EVENT_SERVER); + + ret = IPC_OpenServerConnection(EVENT_SERVER, &__cbhndl); + + _D("[SERVER-CB] IPC_OpenServerConnection (ret=%d)", ret); + + if (ret >= 0) { + __pcbhndl = &__cbhndl; + + ret = IPC_ClientAccept(__pcbhndl); + _D("[SERVER-CB] IPC_ClientAccept (ret=%d)", ret); + if (0 != ret) + _E("[SERVER-CB] error (%d)", ret); + } else { + _E("[SERVER-CB] servercallback_init_connection open error !!"); + } + + return ret; + +} + +int callback_init_connection(void) +{ + int ret = 0; + _D("[SERVER-CB] callback_thread"); + + ret = __open_callback_connection(); + if (0 != ret) + _E("[SERVER-CB] __open_callback_connection Failed"); + + return ret; +} |