From: Hwankyu Jhun Date: Mon, 21 Dec 2020 23:59:46 +0000 (+0900) Subject: Add Component Port API X-Git-Tag: accepted/tizen/unified/20210101.123059~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d295c13f64a607835274eebd64f3a70dc6fb9488;p=platform%2Fcore%2Fappfw%2Faul-1.git Add Component Port API 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 84f3d9e..83a1cbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ AUX_SOURCE_DIRECTORY(aul AUL_SRCS) 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 @@ -67,6 +68,7 @@ ADD_LIBRARY(${TARGET_AUL} SHARED ${AUL_API_SRCS} ${AUL_APP_MANAGER_SRCS} ${AUL_COMMON_SRCS} + ${AUL_COMPONENT_SRCS} ${AUL_SOCKET_SRCS} ) @@ -78,6 +80,7 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL} PUBLIC ${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 ) diff --git a/aul/api/aul_component_port.cc b/aul/api/aul_component_port.cc new file mode 100644 index 0000000..db8e149 --- /dev/null +++ b/aul/api/aul_component_port.cc @@ -0,0 +1,78 @@ +/* + * 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 + +#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; +} diff --git a/aul/api/aul_component_port.h b/aul/api/aul_component_port.h new file mode 100644 index 0000000..b68905b --- /dev/null +++ b/aul/api/aul_component_port.h @@ -0,0 +1,38 @@ +/* + * 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 + +#include + +#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_ diff --git a/aul/component/component_port.cc b/aul/component/component_port.cc new file mode 100644 index 0000000..6b7fa5c --- /dev/null +++ b/aul/component/component_port.cc @@ -0,0 +1,116 @@ +/* + * 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 +#include + +#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 diff --git a/aul/component/component_port.hh b/aul/component/component_port.hh new file mode 100644 index 0000000..44903f2 --- /dev/null +++ b/aul/component/component_port.hh @@ -0,0 +1,42 @@ +/* + * 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 + +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_ diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 44d6b7c..5e07d86 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -190,6 +190,9 @@ enum app_cmd { APP_GROUP_REMOVE = 150, APP_GET_APPID_LIST = 151, + COMP_PORT_EXIST = 152, + COMP_PORT_CREATE = 153, + COMP_PORT_DESTROY = 154, APP_CMD_MAX }; diff --git a/include/aul_key.h b/include/aul_key.h index f1d237f..c441ef9 100644 --- a/include/aul_key.h +++ b/include/aul_key.h @@ -789,3 +789,15 @@ * @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__" diff --git a/src/aul_cmd.c b/src/aul_cmd.c index 4913eaa..7cca83f 100755 --- a/src/aul_cmd.c +++ b/src/aul_cmd.c @@ -192,6 +192,9 @@ API const char *aul_cmd_convert_to_string(int cmd) "APP_GROUP_REMOVE", "APP_GET_APPID_LIST", + "COMP_PORT_EXIST", + "COMP_PORT_CREATE", + "COMP_PORT_DESTROY", "CUSTOM_COMMAND" };