From: Hwankyu Jhun Date: Wed, 16 Jun 2021 05:09:05 +0000 (+0900) Subject: Refactor AUL RPC Port X-Git-Tag: submit/tizen/20210621.050815~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75b1053b0ca2751bcd9462ef2bc0ab1c172961c2;p=platform%2Fcore%2Fappfw%2Faul-1.git Refactor AUL RPC Port The implmentation is changed to c++. Change-Id: Ibbdbcf36e87ef6b9f7c1f5dc831512b1f87d5693 Signed-off-by: Hwankyu Jhun --- diff --git a/include/aul_rpc_port.h b/include/aul_rpc_port.h index 315300c..1fc68f2 100644 --- a/include/aul_rpc_port.h +++ b/include/aul_rpc_port.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2018 - 2021 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. @@ -30,8 +30,9 @@ int aul_rpc_port_create_socket_pair(const char *appid, const char *port_name, int aul_rpc_port_notify_rpc_finished(void); -int aul_rpc_port_set_private_sharing( - const char *appid, const char *paths[], unsigned int size); +int aul_rpc_port_set_private_sharing(const char *appid, const char *paths[], + unsigned int size); + int aul_rpc_port_unset_private_sharing(const char *appid); #ifdef __cplusplus diff --git a/src/aul_rpc_port.c b/src/aul_rpc_port.c deleted file mode 100644 index 23a49cf..0000000 --- a/src/aul_rpc_port.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * 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.h" -#include "aul_api.h" -#include "aul_error.h" -#include "aul_rpc_port.h" -#include "aul_sock.h" -#include "aul_util.h" -#include "aul_svc.h" - -static bundle *__create_bundle(const char *appid, const char *port_name) -{ - bundle *b; - int r; - - b = bundle_create(); - if (!b) { - _E("Out of memory"); - return NULL; - } - - r = bundle_add(b, AUL_K_APPID, appid); - if (r != BUNDLE_ERROR_NONE) { - _E("Failed to add appid(%s)", appid); - bundle_free(b); - return NULL; - } - - 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 NULL; - } - - return b; -} - -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 = __create_bundle(appid, port_name); - if (!b) - return AUL_R_ERROR; - - r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), - RPC_PORT_PREPARE_STUB, b, AUL_SOCK_QUEUE); - if (r < 0) { - _E("Failed to send request(%d:%s)", - RPC_PORT_PREPARE_STUB, appid); - bundle_free(b); - return aul_error_convert(r); - } - bundle_free(b); - - return AUL_R_OK; -} - -API int aul_rpc_port_create_socket_pair(const char *appid, - const char *port_name, int (*fds)[2]) -{ - bundle *b; - int fd; - int r; - - if (!appid || !port_name || !fds) { - _E("Invalid parameter"); - return AUL_R_EINVAL; - } - - b = __create_bundle(appid, port_name); - if (!b) - return AUL_R_ERROR; - - fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), - RPC_PORT_CREATE_SOCKET_PAIR, b, AUL_SOCK_ASYNC); - if (fd <= 0 || fd > sysconf(_SC_OPEN_MAX)) { - _E("Failed to send socket pair creation request. err = %d", fd); - bundle_free(b); - return aul_error_convert(fd); - } - bundle_free(b); - - r = aul_sock_recv_reply_sock_fd(fd, fds, 2); - if (r != 0) { - _E("Failed to receive socket fds. err = %d", r); - return aul_error_convert(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 aul_error_convert(r); - } - bundle_free(b); - - return AUL_R_OK; -} - -API int aul_rpc_port_set_private_sharing( - const char *appid, const char *paths[], unsigned int size) -{ - char buf[12]; - bundle *b; - int r; - - if (!appid || !paths) { - _E("Invalid parameter"); - return AUL_R_EINVAL; - } - - 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 = bundle_add(b, AUL_K_CALLEE_APPID, appid); - if (r != BUNDLE_ERROR_NONE) { - _E("Failed to add callee appid(%s). err = %d", appid, r); - bundle_free(b); - return AUL_R_ERROR; - } - - r = bundle_add_str_array(b, AUL_SVC_DATA_PATH, paths, size); - if (r != BUNDLE_ERROR_NONE) { - _E("Failed to add paths(%d). err = %d", size, r); - bundle_free(b); - return AUL_R_ERROR; - } - - r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), - SET_PRIVATE_SHARING, b, AUL_SOCK_NOREPLY); - if (r != 0) { - _E("Failed to set private sharing(%d). err = %d", getpid(), r); - bundle_free(b); - return aul_error_convert(r); - } - bundle_free(b); - - return AUL_R_OK; -} - -API int aul_rpc_port_unset_private_sharing(const char *appid) -{ - char buf[12]; - bundle *b; - int r; - - if (!appid) { - _E("Invalid parameter"); - return AUL_R_EINVAL; - } - - 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 = bundle_add(b, AUL_K_CALLEE_APPID, appid); - if (r != BUNDLE_ERROR_NONE) { - _E("Failed to add callee appid(%s). err = %d", appid, r); - bundle_free(b); - return AUL_R_ERROR; - } - - r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), - UNSET_PRIVATE_SHARING, b, AUL_SOCK_NOREPLY); - if (r != 0) { - _E("Failed to unset private sharing(%d). err = %d", getpid(), r); - bundle_free(b); - return aul_error_convert(r); - } - bundle_free(b); - - return AUL_R_OK; -} \ No newline at end of file diff --git a/src/aul_rpc_port.cc b/src/aul_rpc_port.cc new file mode 100644 index 0000000..38e3edf --- /dev/null +++ b/src/aul_rpc_port.cc @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2018 - 2021 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 +#include +#include +#include +#include + +#include "app_request.h" +#include "aul_api.h" +#include "aul_util.h" +#include "include/aul.h" +#include "include/aul_error.h" +#include "include/aul_rpc_port.h" +#include "include/aul_sock.h" +#include "include/aul_svc.h" + +using namespace aul::internal; + +extern "C" API int aul_rpc_port_prepare_stub(const char* app_id, + const char* port_name) { + if (app_id == nullptr || port_name == nullptr) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + tizen_base::Bundle b; + b.Add(AUL_K_RPC_PORT, port_name); + + int ret = AppRequest(RPC_PORT_PREPARE_STUB, getuid()) + .With(b) + .SetAppId(app_id) + .SendSimply(); + if (ret < 0) { + _E("Failed to send request. app_id(%s), port_name(%s)", app_id, port_name); + return ret; + } + + return AUL_R_OK; +} + +extern "C" API int aul_rpc_port_create_socket_pair(const char* app_id, + const char* port_name, int (*fds)[2]) { + if (app_id == nullptr || port_name == nullptr || fds == nullptr) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + tizen_base::Bundle b; + b.Add(AUL_K_RPC_PORT, port_name); + + int fd = AppRequest(RPC_PORT_CREATE_SOCKET_PAIR, getuid()) + .With(b) + .SetAppId(app_id) + .SendSimply(AUL_SOCK_ASYNC); + if (fd <= 0 || fd > sysconf(_SC_OPEN_MAX)) { + _E("Failed to send socket pair creation request. error(%d)", fd); + return fd; + } + + int ret = aul_sock_recv_reply_sock_fd(fd, fds, 2); + if (ret != 0) { + _E("Failed to receive socket fds. error(%d)", ret); + return aul_error_convert(ret); + } + + return AUL_R_OK; +} + +extern "C" API int aul_rpc_port_notify_rpc_finished(void) { + int ret = AppRequest(RPC_PORT_NOTIFY_RPC_FINISHED, getuid()) + .SetPid(getpid()) + .SendSimply(AUL_SOCK_NOREPLY); + if (ret != 0) { + _E("Failed to notify rpc finished. error(%d)", ret); + return ret; + } + + return AUL_R_OK; +} + +extern "C" API int aul_rpc_port_set_private_sharing(const char* app_id, + const char* paths[], unsigned int size) { + if (app_id == nullptr || paths == nullptr) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + tizen_base::Bundle b; + b.Add(AUL_K_CALLEE_APPID, app_id); + std::vector v; + for (unsigned int i = 0; i < size; ++i) + v.push_back(paths[i]); + b.Add(AUL_SVC_DATA_PATH, v); + + int ret = AppRequest(SET_PRIVATE_SHARING, getuid()) + .With(b) + .SetPid(getpid()) + .SendSimply(AUL_SOCK_NOREPLY); + if (ret != 0) { + _E("Failed to set private sharing. error(%d)", ret); + return ret; + } + + return AUL_R_OK; +} + +extern "C" API int aul_rpc_port_unset_private_sharing(const char* app_id) { + if (app_id == nullptr) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + tizen_base::Bundle b; + b.Add(AUL_K_CALLEE_APPID, app_id); + + int ret = AppRequest(UNSET_PRIVATE_SHARING, getuid()) + .With(b) + .SetPid(getpid()) + .SendSimply(AUL_SOCK_NOREPLY); + if (ret != 0) { + _E("Failed to unset private sharing. error(%d)", ret); + return ret; + } + + return AUL_R_OK; +}