summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2018-01-11 16:45:15 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2018-01-29 15:10:01 +0900
commitcd16d73b0e9f0e5d1a407d411a5e4acf1913e737 (patch)
treedc5436d21dca329a35f91f15dcc2504bc869b71c
parentc924a6b98a813fd8078482f4f354002f9cdaf68f (diff)
downloadaul-1-cd16d73b0e9f0e5d1a407d411a5e4acf1913e737.tar.gz
aul-1-cd16d73b0e9f0e5d1a407d411a5e4acf1913e737.tar.bz2
aul-1-cd16d73b0e9f0e5d1a407d411a5e4acf1913e737.zip
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 <h.jhun@samsung.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--include/aul_cmd.h4
-rw-r--r--include/aul_rpc_port.h36
-rw-r--r--src/aul_rpc_port.c130
4 files changed, 171 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0c9a9a3..8e5ec1b6 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 c6ff0970..82849bc6 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 00000000..cbfcb95c
--- /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 00000000..0fefe024
--- /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 <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <bundle_internal.h>
+
+#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;
+}
+