From 92aff7e886491bb0ae59dfa31471fda397697ee2 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 28 Oct 2019 19:46:16 +0900 Subject: [PATCH 01/16] Add timer for connection - Dbus name for stub app should be appeared within 10s Change-Id: I11bd7b54afc9df013171c4083d8f2e1555ea7606 Signed-off-by: Junghoon Park --- src/proxy-internal.cc | 23 +++++++++++++++++++++++ src/proxy-internal.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 04deef8..3546273 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -40,6 +40,10 @@ Proxy::Proxy(bool mock) Proxy::~Proxy() { LOGD("Proxy::~Proxy"); + if (conn_timer_) { + g_source_remove(conn_timer_); + conn_timer_ = 0; + } } gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, @@ -96,6 +100,10 @@ void Proxy::OnPortRejected(const std::string& appid) { void Proxy::OnPortAppeared(const std::string& appid, const std::string& port_name) { LOGD("endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str()); + if (conn_timer_) { + g_source_remove(conn_timer_); + conn_timer_ = 0; + } if (listener_ == nullptr) return; @@ -164,9 +172,24 @@ int Proxy::Connect(std::string appid, std::string port_name, return RPC_PORT_ERROR_IO_ERROR; } + if (conn_timer_) + g_source_remove(conn_timer_); + conn_timer_ = g_timeout_add(10 * 1000, DbusNameTimeout, this); + return RPC_PORT_ERROR_NONE; } +gboolean Proxy::DbusNameTimeout(gpointer user_data) { + Proxy* obj = static_cast(user_data); + + LOGW("[__DbusNameTimeout__] endpoint(%s)", obj->target_appid_.c_str()); + if (obj->listener_) + obj->listener_->OnRejected(obj->target_appid_); + + obj->conn_timer_ = 0; + return G_SOURCE_REMOVE; +} + Proxy::ProxyPort::ProxyPort(Proxy* parent, int fd, const std::string& id, bool receive) : Port(fd, id), parent_(parent) { Watch(receive); diff --git a/src/proxy-internal.h b/src/proxy-internal.h index 642be5b..dce40a0 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -80,6 +80,7 @@ class Proxy : public FdBroker::IEventWatcher { gpointer data); static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond, gpointer data); + static gboolean DbusNameTimeout(gpointer user_data); void OnPortAppeared(const std::string& appid, const std::string& port_name) override; void OnPortVanished(const std::string& appid, @@ -98,6 +99,7 @@ class Proxy : public FdBroker::IEventWatcher { FdBroker fd_broker_; std::string target_appid_; int fds_[2]; + guint conn_timer_ = 0; }; } // namespace internal -- 2.7.4 From 270d5d6ff9f613427e5e404ab267104fac43dd58 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 4 Nov 2019 09:46:55 +0900 Subject: [PATCH 02/16] Release version 1.3.21 Changes: - Update doxygen - Add timer for connection Change-Id: I25da31bc4ec8e86f4dede54202c96c72730128d9 Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index df7c9c6..ede53ee 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.20 +Version: 1.3.21 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 29d529edf3bff2d8c6f6122e71a6409ddf7ebe89 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 6 Nov 2019 09:57:01 +0900 Subject: [PATCH 03/16] Implement rpc_port_proxy_connect_sync() Change-Id: I655bc3d13124c8623359578842eed431ba81a661 Signed-off-by: Hwankyu Jhun --- include/rpc-port-internal.h | 4 ++ src/fdbroker-internal.cc | 168 ++++++++++++++++++++++++++++++++++++++++---- src/fdbroker-internal.h | 3 + src/proxy-internal.cc | 41 +++++++++++ src/proxy-internal.h | 1 + src/rpc-port.cc | 11 +++ 6 files changed, 216 insertions(+), 12 deletions(-) diff --git a/include/rpc-port-internal.h b/include/rpc-port-internal.h index 5a9af2a..3af29e4 100644 --- a/include/rpc-port-internal.h +++ b/include/rpc-port-internal.h @@ -24,8 +24,12 @@ extern "C" { #endif int rpc_port_proxy_create_mockup(rpc_port_proxy_h *h); + int rpc_port_stub_create_mockup(rpc_port_stub_h *h, const char *port_name); +int rpc_port_proxy_connect_sync(rpc_port_proxy_h h, const char *appid, + const char *port_name); + #ifdef __cplusplus } #endif diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index a8cf58a..c77f2d5 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -304,6 +304,142 @@ int FdBroker::Send(const std::string& target_appid, return (*fds)[0]; } +int FdBroker::SendSync(const std::string& target_appid, + const std::string& port_name, + int (*fds)[2]) { + char sender_appid[255] = { 0, }; + int ret; + if (!mock_) { + ret = aul_app_get_appid_bypid(getpid(), sender_appid, sizeof(sender_appid)); + if (ret != AUL_R_OK) { + LOGE("Failed to get application ID. ret(%d)", ret); + return -1; + } + } + + SocketPair main_sock_pair(mock_); + ret = main_sock_pair.Request(target_appid, port_name); + if (ret != 0) + return -1; + + SocketPair delegate_sock_pair(mock_); + ret = delegate_sock_pair.Request(target_appid, port_name); + if (ret != 0) + return -1; + + if (mock_) { + int send_fds[2]; + send_fds[0] = main_sock_pair.Detach(SocketPair::RECEIVER); + send_fds[1] = delegate_sock_pair.Detach(SocketPair::RECEIVER); + + ret = DBusMock::GetInst().Send("TestApp", port_name, send_fds); + if (ret < 0) + return ret; + + (*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER); + (*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER); + return (*fds)[0]; + } + + FdList fd_list; + ret = fd_list.Add(main_sock_pair.Detach(SocketPair::RECEIVER)); + if (ret != 0) + return -1; + + ret = fd_list.Add(delegate_sock_pair.Detach(SocketPair::RECEIVER)); + if (ret != 0) + return -1; + + std::string interface_name = GetInterfaceName(target_appid, port_name); + +#define MAX_CNT 100 +#define MAX_SLEEP 100 +#define MIN_SLEEP 50 +#define BASE_SLEEP (1000 * 1000) + GDBusMessage* reply; + GError* err = nullptr; + struct timespec try_sleep_time = { 0, MIN_SLEEP * BASE_SLEEP }; + struct timespec start_time = { 0, }; + struct timespec end_time = { 0, }; + int max_timeout = MAX_CNT * MAX_SLEEP; + + do { + clock_gettime(CLOCK_MONOTONIC, &start_time); + GDBusMessage* msg = g_dbus_message_new_method_call(interface_name.c_str(), + RPC_PORT_OBJECT_PATH, interface_name.c_str(), "send_message"); + if (msg == nullptr) { + LOGE("g_dbus_message_new_method_call() is failed"); + return -1; + } + + g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw()); + + reply = g_dbus_connection_send_message_with_reply_sync( + DBusConnectionManager::GetInst().GetConnection(), + msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 500, nullptr, nullptr, &err); + clock_gettime(CLOCK_MONOTONIC, &end_time); + g_object_unref(msg); + + if (reply && !g_dbus_message_to_gerror(reply, &err)) + break; + + if (reply == nullptr) { + LOGE("g_dbus_connection_send_message_with_reply_sync() is failed"); + if (err) { + LOGE("error(%s)", err->message); + g_error_free(err); + } + } else if (g_dbus_message_to_gerror(reply, &err)) { + LOGE("error(%s) was set", err->message); + g_error_free(err); + g_object_unref(reply); + } + err = nullptr; + + max_timeout -= (((end_time.tv_sec - start_time.tv_sec) * 1000) + + ((end_time.tv_nsec - start_time.tv_nsec) / BASE_SLEEP)); + if (max_timeout <= 0) + break; + + nanosleep(&try_sleep_time, 0); + max_timeout -= (try_sleep_time.tv_nsec / BASE_SLEEP); + if (max_timeout <= 0) + break; + + try_sleep_time.tv_nsec *= 2; + if (try_sleep_time.tv_nsec > (MAX_SLEEP * BASE_SLEEP)) + try_sleep_time.tv_nsec = MAX_SLEEP * BASE_SLEEP; + + LOGD("Retry"); + } while (max_timeout > 0); + + if (max_timeout <= 0) { + LOGE("Timed out"); + return -1; + } + + GVariant* reply_body = g_dbus_message_get_body(reply); + if (reply_body == nullptr) { + LOGE("g_dbus_message_get_body() is failed"); + g_object_unref(reply); + return -1; + } + + g_variant_get(reply_body, "(i)", &ret); + if (ret != 0) { + LOGE("Access Denied[sender_appid: %s, result: %d]", sender_appid, ret); + g_object_unref(reply); + return -EILLEGALACCESS; + } + + LOGD("[Reply: %d]", ret); + + (*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER); + (*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER); + + return (*fds)[0]; +} + void FdBroker::ReceiveMessage(const char* sender_appid, GDBusMethodInvocation* invocation) { GDBusMessage* msg; @@ -557,27 +693,20 @@ void FdBroker::OnNameVanished(GDBusConnection *connection, int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid, const std::string& port_name) { - int r; - if (ev == nullptr) return -1; - if (!mock_) { - r = aul_rpc_port_prepare_stub(target_appid.c_str(), port_name.c_str()); - if (r != AUL_R_OK) { - LOGE("Failed to prepare stub %s:%s [ret : %d]", - target_appid.c_str(), port_name.c_str(), r); - return r; - } - } + int ret = Prepare(target_appid, port_name); + if (ret < 0) + return ret; watcher_ = ev; watch_appid_ = target_appid; watch_port_name_ = port_name; if (mock_) { - r = DBusMock::GetInst().Watch(ev, target_appid, port_name); - if (r < 0) + ret = DBusMock::GetInst().Watch(ev, target_appid, port_name); + if (ret < 0) return -1; return 0; @@ -608,6 +737,21 @@ int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid, return 0; } +int FdBroker::Prepare(const std::string& target_appid, + const std::string& port_name) { + if (!mock_) { + int ret = aul_rpc_port_prepare_stub(target_appid.c_str(), + port_name.c_str()); + if (ret != AUL_R_OK) { + LOGE("Failed to prepare stub %s:%s [ret : %d]", + target_appid.c_str(), port_name.c_str(), ret); + return ret; + } + } + + return 0; +} + void FdBroker::OnResultReceived(GObject* source_object, GAsyncResult* res, gpointer user_data) { diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index aac7584..ca489ab 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -65,6 +65,9 @@ class FdBroker { AccessController& GetAccessController(); int Watch(IEventWatcher* ev, const std::string& target_appid, const std::string& port_name); + int Prepare(const std::string& target_appid, const std::string& port_name); + int SendSync(const std::string& target_appid, const std::string& port_name, + int (*fds)[2]); private: class DBusConnectionManager { diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 3546273..f09a493 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -179,6 +179,47 @@ int Proxy::Connect(std::string appid, std::string port_name, return RPC_PORT_ERROR_NONE; } +int Proxy::ConnectSync(std::string appid, std::string port_name, + IEventListener* ev) { + if (ev == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + if (listener_ != nullptr) { + LOGW("Already connected"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + listener_ = ev; + target_appid_ = std::move(appid); + port_name_ = std::move(port_name); + + int ret = fd_broker_.Prepare(target_appid_, port_name_); + if (ret < 0) { + listener_ = nullptr; + if (ret == -EILLEGALACCESS) + return RPC_PORT_ERROR_PERMISSION_DENIED; + + return RPC_PORT_ERROR_IO_ERROR; + } + + fds_[0] = 0; + fds_[1] = 0; + ret = fd_broker_.SendSync(target_appid_, port_name_, &fds_); + if (ret <= 0) { + listener_ = nullptr; + if (ret == -EILLEGALACCESS) + return RPC_PORT_ERROR_PERMISSION_DENIED; + + return RPC_PORT_ERROR_IO_ERROR; + } + + main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false)); + delegate_port_.reset(new ProxyPort(this, fds_[1], target_appid_)); + listener_->OnConnected(target_appid_, main_port_.get()); + + return RPC_PORT_ERROR_NONE; +} + gboolean Proxy::DbusNameTimeout(gpointer user_data) { Proxy* obj = static_cast(user_data); diff --git a/src/proxy-internal.h b/src/proxy-internal.h index dce40a0..75b30e2 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -44,6 +44,7 @@ class Proxy : public FdBroker::IEventWatcher { }; int Connect(std::string appid, std::string port_name, IEventListener* ev); + int ConnectSync(std::string appid, std::string port_name, IEventListener* ev); std::shared_ptr GetPort() const { return main_port_; diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 48d7518..88046bb 100644 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -232,6 +232,17 @@ RPC_API int rpc_port_proxy_connect(rpc_port_proxy_h h, const char* appid, return p->Connect(appid, port, p); } +RPC_API int rpc_port_proxy_connect_sync(rpc_port_proxy_h h, const char* appid, + const char* port) { + if (h == nullptr || appid == nullptr || port == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + auto p = static_cast<::ProxyExt*>(h); + std::lock_guard lock(p->GetMutex()); + + return p->ConnectSync(appid, port, p); +} + RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_connected_event_cb cb, void *user_data) { if (h == nullptr || cb == nullptr) -- 2.7.4 From ec77162303165e7e1f4f9592a6b91b184dc35781 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 11 Nov 2019 10:49:18 +0900 Subject: [PATCH 04/16] Release version 1.3.22 Changes: - Implement rpc_port_proxy_connect_sync() Change-Id: I8dc0ef343f518bb444d16b05ef0a9a5c68e38c9e Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index ede53ee..2dd4af6 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.21 +Version: 1.3.22 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 1d896e69b4de9faad0bb8ff9576c9b52c2afaa90 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 13 Nov 2019 08:44:13 +0900 Subject: [PATCH 05/16] Add internal APIs for parcel - int rpc_port_parcel_reset_reader(rpc_port_parcel_h h); - int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array, unsigned int *size); - int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array, unsigned int size); Change-Id: I62b659cb2c8b79e9f566303352dbb619ffd47300 Signed-off-by: Junghoon Park --- src/parcel-internal.cc | 14 ++++++++++++++ src/parcel-internal.h | 3 +++ src/rpc-port-parcel.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index 3fce740..54f2d99 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -151,4 +151,18 @@ void Parcel::Read(unsigned char* buf, unsigned int size) { reader_ += size; } +void Parcel::ResetReader() { + reader_ = 0; +} + +void Parcel::Clear() { + data_.clear(); + reader_ = 0; +} + +void Parcel::Reset(const unsigned char* buf, unsigned int size) { + Clear(); + Write(buf, size); +} + } // namespace rpc_port diff --git a/src/parcel-internal.h b/src/parcel-internal.h index ac2290a..991fe17 100644 --- a/src/parcel-internal.h +++ b/src/parcel-internal.h @@ -54,6 +54,9 @@ class Parcel { bundle* ReadBundle(); int ReadArrayCount(); const std::vector& GetRaw(); + void ResetReader(); + void Clear(); + void Reset(const unsigned char* buf, unsigned int size); private: template diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 55c10b2..8ce15d3 100644 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -376,3 +376,45 @@ RPC_API int rpc_port_parcel_burst_write(rpc_port_parcel_h h, return RPC_PORT_ERROR_NONE; } + +RPC_API int rpc_port_parcel_reset_reader(rpc_port_parcel_h h) { + if (h == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + Parcel* p = static_cast(h); + + p->ResetReader(); + + return RPC_PORT_ERROR_NONE; +} + +RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array, + unsigned int *size) { + if (h == nullptr || !array || !size) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + Parcel* p = static_cast(h); + + const auto& ptr = p->GetRaw(); + void* array_ptr = malloc(ptr.size()); + if (!array_ptr) + return RPC_PORT_ERROR_OUT_OF_MEMORY; + + memcpy(array_ptr, ptr.data(), ptr.size()); + *array = array_ptr; + *size = ptr.size(); + + return RPC_PORT_ERROR_NONE; +} + +RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array, + unsigned int size) { + if (h == nullptr || !array || size == 0) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + Parcel* p = static_cast(h); + + p->Reset(reinterpret_cast(array), size); + + return RPC_PORT_ERROR_NONE; +} \ No newline at end of file -- 2.7.4 From b9314682979ce01e26df8da5264e3131e6a26671 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 13 Nov 2019 10:57:56 +0900 Subject: [PATCH 06/16] Release version 1.3.23 Changes: - Add internal APIs for parcel Change-Id: I7d5eabbc0cc2082d123cade32924faaeeeedce12 Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 2dd4af6..bf7dccb 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.22 +Version: 1.3.23 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 874466642c2045e8383464a605e3fff978127d7c Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 13 Nov 2019 13:16:27 +0900 Subject: [PATCH 07/16] Add missing header Change-Id: Ib4a492cf8400f5ba0085f656f4e4822a13ca4029 Signed-off-by: Junghoon Park --- include/rpc-port-parcel-internal.h | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/rpc-port-parcel-internal.h diff --git a/include/rpc-port-parcel-internal.h b/include/rpc-port-parcel-internal.h new file mode 100644 index 0000000..a4f8323 --- /dev/null +++ b/include/rpc-port-parcel-internal.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 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 __TIZEN_APPFW_RPC_PORT_PARCEL_INTERNAL_INCLUDE_H__ +#define __TIZEN_APPFW_RPC_PORT_PARCEL_INTERNAL_INCLUDE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int rpc_port_parcel_reset_reader(rpc_port_parcel_h h); + +int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array, + unsigned int *size); + +int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array, + unsigned int size); + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_APPFW_RPC_PORT_PARCEL_INTERNAL_INCLUDE_H__ */ + + + -- 2.7.4 From 5174c943f6a07a1f9b6b597122a208d3e850cafd Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 13 Nov 2019 13:21:39 +0900 Subject: [PATCH 08/16] Release version 1.3.24 Changes: - Add missing header Change-Id: Iacb6378ab645e0679e64700eff688737497cd2fd Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index bf7dccb..817cb12 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.23 +Version: 1.3.24 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 9dd66a35bac82729dc5a2e230afaa5f74bcf271b Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Fri, 22 Nov 2019 09:46:50 +0900 Subject: [PATCH 09/16] Call the 'disconnected callback' if the reply sent to the stub is null The proxy should be checked if the port has been disconnected. So, if the reply sent to the stub is null, should call the 'disconnected callback' except 'G_IO_ERROR_CANCELLED' Change-Id: Icdd80baad7cae62b5ba7886ff790435380fd4e65 Signed-off-by: Inkyun Kil Signed-off-by: Junghoon Park --- src/fdbroker-internal.cc | 13 +++++++++++-- src/fdbroker-internal.h | 3 ++- src/proxy-internal.cc | 7 ++++++- src/proxy-internal.h | 3 ++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index c77f2d5..5d8db42 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -761,13 +761,22 @@ void FdBroker::OnResultReceived(GObject* source_object, res, &err); if (reply == nullptr) { LOGE("No reply. err(%s)", err ? err->message : "Unknown"); - g_error_free(err); - return; + if (err && err->code == G_IO_ERROR_CANCELLED) { + g_error_free(err); + return; + } } FdBroker* broker = static_cast(user_data); IEventWatcher* watcher = broker->watcher_; + if (err) { + watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_, + true); + g_error_free(err); + return; + } + GVariant* reply_body = g_dbus_message_get_body(reply); if (reply_body == nullptr) { LOGE("g_dbus_message_get_body() is failed"); diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index ca489ab..be23530 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -49,7 +49,8 @@ class FdBroker { virtual void OnPortConnected(const std::string& appid, const std::string& port_name) = 0; virtual void OnPortDisconnected(const std::string& appid, - const std::string& port_name) = 0; + const std::string& port_name, + bool cancel = false) = 0; }; explicit FdBroker(bool mock = false) : mock_(mock) {} diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index f09a493..b54f305 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -141,10 +141,15 @@ void Proxy::OnPortConnected(const std::string& appid, } void Proxy::OnPortDisconnected(const std::string& appid, - const std::string& port_name) { + const std::string& port_name, bool cancel) { LOGW("[__OnPortDisconnected__] endporint(%s), port_name(%s)", appid.c_str(), port_name.c_str()); + if (cancel) { + close(fds_[0]); + close(fds_[1]); + } + IEventListener* listener = listener_; listener_ = nullptr; listener->OnDisconnected(appid); diff --git a/src/proxy-internal.h b/src/proxy-internal.h index 75b30e2..a5046b0 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -90,7 +90,8 @@ class Proxy : public FdBroker::IEventWatcher { void OnPortConnected(const std::string& appid, const std::string& port_name) override; void OnPortDisconnected(const std::string& appid, - const std::string& port_name) override; + const std::string& port_name, + bool cancel = false) override; private: std::string port_name_; -- 2.7.4 From 28e458a8b0914fca505973663b4561ad1cc0f5cc Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 25 Nov 2019 10:29:11 +0900 Subject: [PATCH 10/16] Release version 1.3.25 Changes: - Call the 'disconnected callback' if the reply sent to the stub is null Change-Id: I66d505d39db8749ab1e0fa297fc6c51fa6621688 Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 817cb12..6c32a8c 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.24 +Version: 1.3.25 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 8a0b9d135d5fcd666962636df2e40a0c708dfbb8 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Tue, 26 Nov 2019 15:36:48 +0900 Subject: [PATCH 11/16] Clear listener after being rejected Change-Id: I781cae8c66809c18649dd0fe63a85d5bf887ef6c Signed-off-by: Junghoon Park --- src/proxy-internal.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index b54f305..1b183fb 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -229,10 +229,13 @@ gboolean Proxy::DbusNameTimeout(gpointer user_data) { Proxy* obj = static_cast(user_data); LOGW("[__DbusNameTimeout__] endpoint(%s)", obj->target_appid_.c_str()); - if (obj->listener_) - obj->listener_->OnRejected(obj->target_appid_); - obj->conn_timer_ = 0; + if (obj->listener_) { + IEventListener* listener = obj->listener_; + obj->listener_ = nullptr; + listener->OnRejected(obj->target_appid_); + } + return G_SOURCE_REMOVE; } -- 2.7.4 From e1661da3ac64449953b846b51d67461332521222 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 28 Nov 2019 09:36:49 +0900 Subject: [PATCH 12/16] Release version 1.3.26 Changes: - Clear listener after being rejected Change-Id: I793068f3f3b5e4b4f229a8dc7165379d10a1fc7d Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 6c32a8c..5cf0d2b 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.25 +Version: 1.3.26 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From f06603dc57b2c92f0132ce9511a577995aaced31 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 5 Dec 2019 11:09:45 +0900 Subject: [PATCH 13/16] Cancel the request when timeout happen Change-Id: Idcb9612efce312537454b007e33fa486fa442271 Signed-off-by: Junghoon Park --- src/fdbroker-internal.cc | 6 ++++++ src/proxy-internal.cc | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 5d8db42..376c2c7 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -774,6 +774,12 @@ void FdBroker::OnResultReceived(GObject* source_object, watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_, true); g_error_free(err); + if (broker && broker->cancellable_) { + LOGW("Cancel the send request"); + g_cancellable_cancel(broker->cancellable_); + g_object_unref(broker->cancellable_); + broker->cancellable_ = nullptr; + } return; } diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 1b183fb..7d78f8d 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -82,7 +82,8 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond, return FALSE; } - proxy->listener_->OnReceived(proxy->target_appid_); + if (proxy->listener_) + proxy->listener_->OnReceived(proxy->target_appid_); } return TRUE; @@ -134,6 +135,10 @@ void Proxy::OnPortConnected(const std::string& appid, const std::string& port_name) { LOGW("[__OnPortConnected__] endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str()); + if (!listener_) { + LOGW("listener is null"); + return; + } main_port_.reset(new ProxyPort(this, fds_[0], appid, false)); delegate_port_.reset(new ProxyPort(this, fds_[1], appid)); @@ -150,6 +155,11 @@ void Proxy::OnPortDisconnected(const std::string& appid, close(fds_[1]); } + if (!listener_) { + LOGW("listener is null"); + return; + } + IEventListener* listener = listener_; listener_ = nullptr; listener->OnDisconnected(appid); -- 2.7.4 From 89db7ba27e87c6853775d47fabd17eb94946b532 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 5 Dec 2019 11:28:10 +0900 Subject: [PATCH 14/16] Release version 1.3.27 Changes: - Cancel the request when timeout happen Change-Id: I8adbaa5ae4c861e91c34966021613fdf6c02decb Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 5cf0d2b..d5cdd47 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.26 +Version: 1.3.27 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From f0c71d85ea9c733c8809fe02fe03469fcaea59e3 Mon Sep 17 00:00:00 2001 From: hyunho Date: Mon, 16 Dec 2019 12:59:10 +0900 Subject: [PATCH 15/16] Fix reference null bug Change-Id: Ifaaa0edadf582b86321ebf8dee79c27d28c2b82e Signed-off-by: hyunho --- src/fdbroker-internal.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 376c2c7..6dd0c62 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -759,22 +759,25 @@ void FdBroker::OnResultReceived(GObject* source_object, GError* err = nullptr; GDBusMessage* reply = g_dbus_connection_send_message_with_reply_finish(conn, res, &err); - if (reply == nullptr) { - LOGE("No reply. err(%s)", err ? err->message : "Unknown"); - if (err && err->code == G_IO_ERROR_CANCELLED) { - g_error_free(err); - return; - } + + if (err && err->code == G_IO_ERROR_CANCELLED) { + g_error_free(err); + LOGE("IO error cancelled"); + return; } FdBroker* broker = static_cast(user_data); + if (broker == nullptr) { + LOGW("Null broker"); + return; + } IEventWatcher* watcher = broker->watcher_; if (err) { watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_, true); g_error_free(err); - if (broker && broker->cancellable_) { + if (broker->cancellable_) { LOGW("Cancel the send request"); g_cancellable_cancel(broker->cancellable_); g_object_unref(broker->cancellable_); @@ -783,6 +786,11 @@ void FdBroker::OnResultReceived(GObject* source_object, return; } + if (reply == nullptr) { + LOGW("Null reply"); + return; + } + GVariant* reply_body = g_dbus_message_get_body(reply); if (reply_body == nullptr) { LOGE("g_dbus_message_get_body() is failed"); -- 2.7.4 From a7db1f88d758f55940dab5a31b306090c5811862 Mon Sep 17 00:00:00 2001 From: hyunho Date: Mon, 16 Dec 2019 13:32:35 +0900 Subject: [PATCH 16/16] Release version 1.3.28 Changes: - Fix reference null bug Change-Id: I28db1116153fd8b8e62c1820aa329fe07113bae9 Signed-off-by: hyunho --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index d5cdd47..36437b6 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.3.27 +Version: 1.3.28 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4