}
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_);
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);
void FdBroker::OnResultReceived(GObject* source_object,
GAsyncResult* res,
gpointer user_data) {
- FdBroker* broker = static_cast<FdBroker*>(user_data);
- IEventWatcher* watcher = broker->watcher_;
GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(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<FdBroker*>(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;
}
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);
}