To support component-based port API, the functions are added.
When calling aul_component_port_create(), AMD creates a socket.
AMD passes a file descriptor to the caller component.
And then, the component waits for events using the received file descriptor.
Adds:
- aul_component_port_exist()
- aul_component_port_create()
- aul_component_port_destroy()
Requires:
- https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/250187/
- https://review.tizen.org/gerrit/#/c/platform/core/appfw/launchpad/+/250199/
Change-Id: I3f00461c8487854e0d8c84fa93b50c49f359e80c
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
AUX_SOURCE_DIRECTORY(aul/api AUL_API_SRCS)
AUX_SOURCE_DIRECTORY(aul/app_manager AUL_APP_MANAGER_SRCS)
AUX_SOURCE_DIRECTORY(aul/common AUL_COMMON_SRCS)
+AUX_SOURCE_DIRECTORY(aul/component AUL_COMPONENT_SRCS)
AUX_SOURCE_DIRECTORY(aul/socket AUL_SOCKET_SRCS)
ADD_LIBRARY(${TARGET_AUL} SHARED
${AUL_API_SRCS}
${AUL_APP_MANAGER_SRCS}
${AUL_COMMON_SRCS}
+ ${AUL_COMPONENT_SRCS}
${AUL_SOCKET_SRCS}
)
${CMAKE_CURRENT_SOURCE_DIR}/aul/api
${CMAKE_CURRENT_SOURCE_DIR}/aul/app_manager
${CMAKE_CURRENT_SOURCE_DIR}/aul/common
+ ${CMAKE_CURRENT_SOURCE_DIR}/aul/component
${CMAKE_CURRENT_SOURCE_DIR}/aul/socket
)
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <tizen.h>
+
+#include "aul/api/aul_component_port.h"
+#include "aul/common/api.hh"
+#include "aul/common/log_private.hh"
+#include "aul/component/component_port.hh"
+
+using namespace aul;
+
+extern "C" API int aul_component_port_exist(const char* port_name,
+ bool* exist) {
+ if (port_name == nullptr || exist == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ ComponentPort port(port_name);
+ bool res = port.Exist();
+ int ret = get_last_result();
+ if (ret != AUL_R_OK)
+ return ret;
+
+ *exist = res;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_component_port_create(const char* port_name, int* fd) {
+ if (port_name == nullptr || fd == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ ComponentPort port(port_name);
+ int ret = port.Create();
+ if (ret < 0) {
+ _E("Failed to create a port. port_name(%s), error(%d)",
+ port_name, ret);
+ return ret;
+ }
+
+ *fd = ret;
+ _D("Port(%s) is created. fd(%d)", port_name, *fd);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_component_port_destroy(const char* port_name) {
+ if (port_name == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ ComponentPort port(port_name);
+ int ret = port.Destroy();
+ if (ret != AUL_R_OK) {
+ _E("Failed to destroy a port. port_name(%s), error(%d)",
+ port_name, ret);
+ return ret;
+ }
+
+ _D("Port(%s) is destroyed", port_name);
+ return AUL_R_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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_API_AUL_COMPONENT_PORT_H_
+#define AUL_API_AUL_COMPONENT_PORT_H_
+
+#include <stdbool.h>
+
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int aul_component_port_exist(const char *port_name, bool *exist);
+
+int aul_component_port_create(const char *port_name, int *fd);
+
+int aul_component_port_destroy(const char *port_name);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AUL_API_AUL_COMPONENT_PORT_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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 <tizen.h>
+
+#include "aul/common/log_private.hh"
+#include "aul/common/exception.hh"
+#include "aul/component/component_port.hh"
+#include "aul/socket/client.hh"
+#include "include/aul.h"
+#include "include/aul_cmd.h"
+#include "include/aul_error.h"
+#include "include/aul_sock.h"
+
+namespace aul {
+
+ComponentPort::ComponentPort(std::string name)
+ : name_(std::move(name)) {
+}
+
+ComponentPort::~ComponentPort() = default;
+
+bool ComponentPort::Exist() {
+ int ret = SendRequest(COMP_PORT_EXIST, AUL_SOCK_NONE);
+ if (ret < 0) {
+ _E("Failed to send a request. error(%d)", ret);
+ set_last_result(ret);
+ return false;
+ }
+
+ return ret == 1 ? true : false;
+}
+
+int ComponentPort::Create() {
+ tizen_base::Bundle b;
+ b.Add(AUL_K_COMPONENT_PORT, name_);
+ Packet pkt(COMP_PORT_CREATE, AUL_SOCK_ASYNC | AUL_SOCK_BUNDLE, b);
+ int fds[2] = { -1, };
+ try {
+ Client client(PATH_AMD_SOCK);
+ int ret = client.Send(pkt);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ ret = aul_sock_recv_reply_sock_fd(client.GetFd(), &fds, 1);
+ if (ret != 0)
+ return aul_error_convert(ret);
+ } catch (Exception& e) {
+ _E("Failed to create client. error(%d)", e.GetErrorCode());
+ return aul_error_convert(e.GetErrorCode());
+ }
+
+ return fds[0];
+}
+
+int ComponentPort::Destroy() {
+ int ret = SendRequest(COMP_PORT_DESTROY, AUL_SOCK_NOREPLY);
+ if (ret < 0) {
+ _E("Failed to send a request. error(%d)", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+int ComponentPort::SendRequest(int cmd, int opt) {
+ tizen_base::Bundle b;
+ b.Add(AUL_K_COMPONENT_PORT, name_);
+ Packet pkt(cmd, opt | AUL_SOCK_BUNDLE, b);
+ Packet recv_pkt;
+ try {
+ Client client(PATH_AMD_SOCK);
+ int ret = client.Send(pkt);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ if (opt & AUL_SOCK_NOREPLY)
+ return ret;
+
+ ret = client.Recv(recv_pkt);
+ if (ret < 0)
+ return aul_error_convert(ret);
+ } catch (Exception& e) {
+ _E("Failed to create client. error(%d)", e.GetErrorCode());
+ return aul_error_convert(e.GetErrorCode());
+ }
+
+ if (recv_pkt.GetCmd() != cmd) {
+ _E("Invalid protocol");
+ return AUL_R_ECOMM;
+ }
+
+ b = recv_pkt.DataToBundle();
+ auto str = b.GetString(AUL_K_RESULT);
+ int ret = std::stoi(str);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ return ret;
+}
+
+} // namespace aul
--- /dev/null
+/*
+ * Copyright (c) 2020 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_COMPONENT_COMPONENT_PORT_HH_
+#define AUL_COMPONENT_COMPONENT_PORT_HH_
+
+#include <string>
+
+namespace aul {
+
+class ComponentPort {
+ public:
+ ComponentPort(std::string name);
+ virtual ~ComponentPort();
+
+ bool Exist();
+ int Create();
+ int Destroy();
+
+ private:
+ int SendRequest(int cmd, int opt);
+
+ private:
+ std::string name_;
+};
+
+} // namespace aul
+
+#endif // AUL_COMPONENT_COMPONENT_PORT_HH_
APP_GROUP_REMOVE = 150,
APP_GET_APPID_LIST = 151,
+ COMP_PORT_EXIST = 152,
+ COMP_PORT_CREATE = 153,
+ COMP_PORT_DESTROY = 154,
APP_CMD_MAX
};
* @since_tizen 6.0
*/
#define AUL_K_APPID_LIST "__AUL_K_APPID_LIST__"
+
+/**
+ * @brief Definition for AUL: The name of the component port.
+ * @since_tizen 6.5
+ */
+#define AUL_K_COMPONENT_PORT "__AUL_COMPONENT_PORT__"
+
+/**
+ * @brief Definition for AUL: The result.
+ * @since_tizen 6.5
+ */
+#define AUL_K_RESULT "__AUL_RESULT__"
"APP_GROUP_REMOVE",
"APP_GET_APPID_LIST",
+ "COMP_PORT_EXIST",
+ "COMP_PORT_CREATE",
+ "COMP_PORT_DESTROY",
"CUSTOM_COMMAND"
};