From: Hwankyu Jhun Date: Wed, 17 Jul 2019 04:36:04 +0000 (+0900) Subject: Cancel sending dbus message X-Git-Tag: submit/tizen/20190718.001331~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9801b6bee79eb0656e89a7e7e794879a6223365;p=platform%2Fcore%2Fappfw%2Frpc-port.git Cancel sending dbus message To prevent calling the callback function after the proxy object is destoyed, the GCancellable object is used. If Send() method is called twice, the previous request will be cancelled. Change-Id: Ibe3d692306864749ee37a0e78cbf7c82de651346 Signed-off-by: Hwankyu Jhun --- diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index a059c92..a8cf58a 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -197,6 +197,12 @@ GUnixFDList* FdBroker::FdList::GetRaw() { } FdBroker::~FdBroker() { + if (cancellable_) { + LOGW("Cancel the send request"); + g_cancellable_cancel(cancellable_); + g_object_unref(cancellable_); + } + if (watcher_id_ > 0) g_bus_unwatch_name(watcher_id_); @@ -273,11 +279,23 @@ int FdBroker::Send(const std::string& target_appid, return -1; } + if (cancellable_) { + g_cancellable_cancel(cancellable_); + g_object_unref(cancellable_); + } + + cancellable_ = g_cancellable_new(); + if (!cancellable_) { + LOGE("Failed to create GCancellable"); + g_object_unref(msg); + return -1; + } + g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw()); g_dbus_connection_send_message_with_reply( DBusConnectionManager::GetInst().GetConnection(), msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, - 5000, NULL, NULL, OnResultReceived, this); + 5000, NULL, cancellable_, OnResultReceived, this); g_object_unref(msg); (*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER); @@ -593,29 +611,23 @@ int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid, void FdBroker::OnResultReceived(GObject* source_object, GAsyncResult* res, gpointer user_data) { - FdBroker* broker = static_cast(user_data); - IEventWatcher* watcher = broker->watcher_; GDBusConnection* conn = reinterpret_cast(source_object); - GError *err = nullptr; + 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 (watcher) { - watcher->OnPortDisconnected(broker->watch_appid_, - broker->watch_port_name_); - } g_error_free(err); return; } + FdBroker* broker = static_cast(user_data); + IEventWatcher* watcher = broker->watcher_; + GVariant* reply_body = g_dbus_message_get_body(reply); if (reply_body == nullptr) { LOGE("g_dbus_message_get_body() is failed"); - if (watcher) { - watcher->OnPortDisconnected(broker->watch_appid_, - broker->watch_port_name_); - } + watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_); g_object_unref(reply); return; } @@ -625,13 +637,11 @@ void FdBroker::OnResultReceived(GObject* source_object, g_object_unref(reply); if (ret != 0) { LOGE("Access Denied[sender_appid : %s]", broker->watch_appid_.c_str()); - if (watcher) - watcher->OnPortRejected(broker->watch_appid_); + watcher->OnPortRejected(broker->watch_appid_); return; } - if (watcher) - watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_); + watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_); LOGD("[Reply : %d]", ret); } diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index cfd5bbd..aac7584 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -176,6 +176,7 @@ class FdBroker { guint watcher_id_ = 0; std::string watch_appid_; std::string watch_port_name_; + GCancellable* cancellable_ = nullptr; }; } // namespace internal