From: Hwankyu Jhun Date: Thu, 11 Jan 2018 07:45:15 +0000 (+0900) Subject: Add new APIs for RPC-Port X-Git-Tag: accepted/tizen/unified/20180205.060409~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F28%2F166628%2F12;p=platform%2Fcore%2Fappfw%2Faul-1.git Add new APIs for RPC-Port Adds new APIs: - aul_rpc_port_prepare_stub - aul_rpc_port_create_socket_pair - aul_rpc_port_notify_rpc_finished Change-Id: I1284c2bda813f9b722d07724661a75e0539e7aaa Signed-off-by: Hwankyu Jhun --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d0c9a9a..8e5ec1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_screen_connector.h DESTINA INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_window.h DESTINATION include/aul) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_widget.h DESTINATION include/aul) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_job_scheduler.h DESTINATION include/aul) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_rpc_port.h DESTINATION include/aul) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec_list.txt DESTINATION ${SHARE_INSTALL_PREFIX}/aul ) INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/miregex DESTINATION ${SHARE_INSTALL_PREFIX}/aul ) diff --git a/include/aul_cmd.h b/include/aul_cmd.h index c6ff097..82849bc 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -128,6 +128,10 @@ enum app_cmd { WIDGET_RUNNING_INFO = 97, JOB_STATUS_UPDATE = 98, WIDGET_CHANGE_STATUS = 99, + RPC_PORT_PREPARE_STUB = 100, + + RPC_PORT_CREATE_SOCKET_PAIR = 101, + RPC_PORT_NOTIFY_RPC_FINISHED = 102, APP_CMD_MAX }; diff --git a/include/aul_rpc_port.h b/include/aul_rpc_port.h new file mode 100644 index 0000000..cbfcb95 --- /dev/null +++ b/include/aul_rpc_port.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018 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 __AUL_RPC_PORT_H__ +#define __AUL_RPC_PORT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define AUL_K_RPC_PORT "__AUL_RPC_PORT__" + +int aul_rpc_port_prepare_stub(const char *appid, const char *port_name); + +int aul_rpc_port_create_socket_pair(int (*fds)[2]); + +int aul_rpc_port_notify_rpc_finished(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __AUL_RPC_PORT_H__ */ diff --git a/src/aul_rpc_port.c b/src/aul_rpc_port.c new file mode 100644 index 0000000..0fefe02 --- /dev/null +++ b/src/aul_rpc_port.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2018 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. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include + +#include "aul_api.h" +#include "aul_util.h" +#include "aul_sock.h" +#include "aul_rpc_port.h" +#include "aul.h" + +API int aul_rpc_port_prepare_stub(const char *appid, const char *port_name) +{ + bundle *b; + int r; + + if (!appid || !port_name) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + b = bundle_create(); + if (!b) { + _E("Out of memory"); + return AUL_R_ERROR; + } + + r = bundle_add(b, AUL_K_APPID, appid); + if (r != BUNDLE_ERROR_NONE) { + _E("Failed to add appid(%s)", appid); + bundle_free(b); + return AUL_R_ERROR; + } + + r = bundle_add(b, AUL_K_RPC_PORT, port_name); + if (r != BUNDLE_ERROR_NONE) { + _E("Failed to add port_name(%s)", port_name); + bundle_free(b); + return AUL_R_ERROR; + } + + r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), + RPC_PORT_PREPARE_STUB, b, AUL_SOCK_NOREPLY); + if (r != 0) { + _E("Failed to send request(%d:%s)", + RPC_PORT_PREPARE_STUB, appid); + bundle_free(b); + return r; + } + bundle_free(b); + + return AUL_R_OK; +} + +API int aul_rpc_port_create_socket_pair(int (*fds)[2]) +{ + int fd; + int r; + + if (!fds) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + fd = aul_sock_send_raw(AUL_UTIL_PID, getuid(), + RPC_PORT_CREATE_SOCKET_PAIR, NULL, + 0, AUL_SOCK_ASYNC); + if (fd <= 0 || fd > sysconf(_SC_OPEN_MAX)) { + _E("Failed to send socket pair creation request. err = %d", fd); + return fd; + } + + r = aul_sock_recv_reply_sock_fd(fd, fds, 2); + if (r != 0) { + _E("Failed to receive socket fds. err = %d", r); + return r; + } + + return AUL_R_OK; +} + +API int aul_rpc_port_notify_rpc_finished(void) +{ + char buf[12]; + bundle *b; + int r; + + b = bundle_create(); + if (!b) { + _E("Out of memory"); + return AUL_R_ERROR; + } + + snprintf(buf, sizeof(buf), "%d", getpid()); + r = bundle_add(b, AUL_K_PID, buf); + if (r != BUNDLE_ERROR_NONE) { + _E("Failed to add pid(%d). err = %d", getpid(), r); + bundle_free(b); + return AUL_R_ERROR; + } + + r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), + RPC_PORT_NOTIFY_RPC_FINISHED, b, AUL_SOCK_NOREPLY); + if (r != 0) { + _E("Failed to notify rpc finished(%d). err = %d", getpid(), r); + bundle_free(b); + return r; + } + bundle_free(b); + + return AUL_R_OK; +} +