diff options
Diffstat (limited to 'src/apt-transaction.c')
-rw-r--r-- | src/apt-transaction.c | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/src/apt-transaction.c b/src/apt-transaction.c index 61868a3..78a0ff2 100644 --- a/src/apt-transaction.c +++ b/src/apt-transaction.c @@ -31,12 +31,16 @@ static void apt_transaction_receive_signal (GDBusProxy * proxy, gchar * signal_name, GVariant * parameters, gpointer user_data); +static void apt_transaction_finish_proxy_setup (GObject *source_object, + GAsyncResult *res, + gpointer user_data); struct _AptTransaction { - GObject parent_instance; - GDBusProxy * proxy; - gchar* id; + GObject parent_instance; + GDBusProxy * proxy; + GCancellable * proxy_cancel; + gchar* id; TransactionType type; }; @@ -54,6 +58,7 @@ apt_transaction_init (AptTransaction *self) { self->proxy = NULL; self->id = NULL; + self->proxy_cancel = g_cancellable_new(); } static void @@ -86,24 +91,46 @@ apt_transaction_class_init (AptTransactionClass *klass) G_TYPE_NONE, 1, G_TYPE_INT); } +// TODO: you don't need this additional helper +// Just GObject properties properly static void -apt_transaction_investigate(AptTransaction* self) +apt_transaction_investigate (AptTransaction* self) { - GError * error = NULL; - - self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, /* GDBusInterfaceInfo */ - "org.debian.apt", - self->id, - "org.debian.apt.transaction", - NULL, /* GCancellable */ - &error); - if (error != NULL) { - g_warning ("unable to fetch proxy for transaction object path %s", self->id); - g_error_free (error); - return; - } + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.debian.apt", + self->id, + "org.debian.apt.transaction", + self->proxy_cancel, + apt_transaction_finish_proxy_setup, + self); +} + +static void +apt_transaction_finish_proxy_setup (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + g_return_if_fail (APT_IS_TRANSACTION (user_data)); + AptTransaction* self = APT_TRANSACTION(user_data); + GError * error = NULL; + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (self->proxy_cancel != NULL) { + g_object_unref(self->proxy_cancel); + self->proxy_cancel = NULL; + } + + if (error != NULL) { + g_warning("Could not grab DBus proxy for %s: %s", + "org.debian.apt", error->message); + g_error_free(error); + return; + } + + self->proxy = proxy; g_signal_connect (G_OBJECT(self->proxy), "g-signal", @@ -131,7 +158,7 @@ apt_transaction_receive_signal (GDBusProxy * proxy, { g_return_if_fail (APT_IS_TRANSACTION (user_data)); AptTransaction* self = APT_TRANSACTION(user_data); - AptState current_state = UP_TO_DATE; + AptState current_state = DONT_KNOW; if (g_strcmp0(signal_name, "PropertyChanged") == 0 && self->type == SIMULATION) { @@ -195,10 +222,13 @@ apt_transaction_receive_signal (GDBusProxy * proxy, current_state = FINISHED; } // Finally send out the state update - g_signal_emit (self, - signals[UPDATE], - 0, - current_state); + if (current_state != DONT_KNOW){ + g_signal_emit (self, + signals[UPDATE], + 0, + current_state); + } + g_variant_unref (parameters); } static void |