+++ /dev/null
-/*
- * 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 <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <bundle_internal.h>
-
-#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
--- /dev/null
+/*
+ * 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 <bundle_cpp.h>
+#include <bundle_internal.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#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<std::string> 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;
+}