aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/apt-transaction.c167
-rw-r--r--src/apt-transaction.h48
-rw-r--r--src/apt-watcher.c118
4 files changed, 250 insertions, 85 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 753b71d..83d12bb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -98,6 +98,8 @@ indicator_session_service_SOURCES = \
device-menu-mgr.c \
apt-watcher.h \
apt-watcher.c \
+ apt-transaction.h \
+ apt-transaction.c \
udev-mgr.h \
udev-mgr.c
indicator_session_service_CFLAGS = \
diff --git a/src/apt-transaction.c b/src/apt-transaction.c
new file mode 100644
index 0000000..68e1f6b
--- /dev/null
+++ b/src/apt-transaction.c
@@ -0,0 +1,167 @@
+/*
+Copyright 2011 Canonical Ltd.
+
+Authors:
+ Conor Curran <conor.curran@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <gio/gio.h>
+
+#include "apt-transaction.h"
+
+
+static void apt_transaction_on_properties_changed (GDBusProxy *proxy,
+ GVariant *changed_properties,
+ const gchar* const *invalidated_properties,
+ gpointer user_data);
+
+static void apt_transaction_investigate (AptTransaction* self);
+static void apt_transaction_simulate_transaction_cb (GObject * obj,
+ GAsyncResult * res,
+ gpointer user_data);
+
+struct _AptTransaction
+{
+ GObject parent_instance;
+ GDBusProxy * proxy;
+ gchar* id;
+};
+
+G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT);
+
+static void
+apt_transaction_init (AptTransaction *self)
+{
+ self->proxy = NULL;
+ self->id = NULL;
+}
+
+static void
+apt_transaction_finalize (GObject *object)
+{
+ /* TODO: Add deinitalization code here */
+ AptTransaction* self = APT_TRANSACTION(object);
+ if (self->proxy != NULL){
+ g_object_unref (self->proxy);
+ self->proxy = NULL;
+ }
+ g_free (self->id);
+ G_OBJECT_CLASS (apt_transaction_parent_class)->finalize (object);
+}
+
+static void
+apt_transaction_class_init (AptTransactionClass *klass)
+{
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+ //GObjectClass* parent_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = apt_transaction_finalize;
+}
+
+static void
+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_debug ("connecting to the properties changed signal on the transaction object");
+ g_signal_connect (self->proxy,
+ "g-properties-changed",
+ G_CALLBACK (apt_transaction_on_properties_changed),
+ self);
+
+ g_debug ("calling simulate on the transaction object");
+ g_dbus_proxy_call (self->proxy,
+ "Simulate",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ apt_transaction_simulate_transaction_cb,
+ self);
+}
+
+static void
+apt_transaction_on_properties_changed (GDBusProxy *proxy,
+ GVariant *changed_properties,
+ const gchar* const *invalidated_properties,
+ gpointer user_data)
+{
+ if (g_variant_n_children (changed_properties) > 0)
+ {
+ GVariantIter *iter;
+ const gchar *key;
+ GVariant *value;
+
+ g_print (" *** Apt Transaction Properties Changed:\n");
+ g_variant_get (changed_properties,
+ "a{sv}",
+ &iter);
+ while (g_variant_iter_loop (iter, "{&sv}", &key, &value))
+ {
+ gchar *value_str;
+ value_str = g_variant_print (value, TRUE);
+ g_print (" %s -> %s\n", key, value_str);
+ g_free (value_str);
+ }
+ g_variant_iter_free (iter);
+ }
+}
+
+static void
+apt_transaction_simulate_transaction_cb (GObject * obj,
+ GAsyncResult * res,
+ gpointer user_data)
+{
+ g_debug ("Simulate return");
+ g_return_if_fail (APT_IS_TRANSACTION (user_data));
+ AptTransaction* self = APT_TRANSACTION (user_data);
+
+ GError * error = NULL;
+ GVariant * result;
+
+ result = g_dbus_proxy_call_finish(self->proxy, res, &error);
+
+ if (error != NULL) {
+ g_warning ("unable to complete the simulate call");
+ g_error_free (error);
+ return;
+ }
+
+ g_debug ("simulate returned a %s",
+ g_variant_get_type_string (result));
+
+}
+
+
+AptTransaction* apt_transaction_new (gchar* transaction_id)
+{
+ AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL);
+ tr->id = transaction_id;
+ g_debug ("Apt transaction new");
+ apt_transaction_investigate (tr);
+ return tr;
+}
diff --git a/src/apt-transaction.h b/src/apt-transaction.h
new file mode 100644
index 0000000..dec62ef
--- /dev/null
+++ b/src/apt-transaction.h
@@ -0,0 +1,48 @@
+/*
+Copyright 2011 Canonical Ltd.
+
+Authors:
+ Conor Curran <conor.curran@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _APT_TRANSACTION_H_
+#define _APT_TRANSACTION_H_
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define APT_TYPE_TRANSACTION (apt_transaction_get_type ())
+#define APT_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APT_TYPE_TRANSACTION, AptTransaction))
+#define APT_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APT_TYPE_TRANSACTION, AptTransactionClass))
+#define APT_IS_TRANSACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APT_TYPE_TRANSACTION))
+#define APT_IS_TRANSACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APT_TYPE_TRANSACTION))
+#define APT_TRANSACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APT_TYPE_TRANSACTION, AptTransactionClass))
+
+typedef struct _AptTransactionClass AptTransactionClass;
+typedef struct _AptTransaction AptTransaction;
+
+struct _AptTransactionClass
+{
+ GObjectClass parent_class;
+};
+
+AptTransaction* apt_transaction_new (gchar* transaction_id);
+
+GType apt_transaction_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* _APT_TRANSACTION_H_ */
diff --git a/src/apt-watcher.c b/src/apt-watcher.c
index d02203b..7553f6e 100644
--- a/src/apt-watcher.c
+++ b/src/apt-watcher.c
@@ -21,6 +21,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <glib/gi18n.h>
#include "apt-watcher.h"
#include "dbus-shared-names.h"
+#include "apt-transaction.h"
static guint watcher_id;
@@ -29,10 +30,10 @@ struct _AptWatcher
GObject parent_instance;
GCancellable * proxy_cancel;
GDBusProxy * proxy;
- GDBusProxy * transaction_proxy;
SessionDbus* session_dbus_interface;
DbusmenuMenuitem* apt_item;
gint current_state;
+ AptTransaction* current_transaction;
};
static void
@@ -53,10 +54,6 @@ static void fetch_proxy_cb (GObject * object,
GAsyncResult * res,
gpointer user_data);
-static void apt_watcher_simulate_transaction_cb (GObject * obj,
- GAsyncResult * res,
- gpointer user_data);
-
static void apt_watcher_upgrade_system_cb (GObject * obj,
GAsyncResult * res,
gpointer user_data);
@@ -72,13 +69,9 @@ static void apt_watcher_signal_cb (GDBusProxy* proxy,
GVariant* parameters,
gpointer user_data);
-static void apt_watcher_determine_state (AptWatcher* self,
- GVariant* update);
+/*static void apt_watcher_determine_state (AptWatcher* self,
+ GVariant* update);*/
-static void transaction_on_properties_changed (GDBusProxy *proxy,
- GVariant *changed_properties,
- const gchar* const *invalidated_properties,
- gpointer user_data);
G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT);
@@ -88,7 +81,7 @@ apt_watcher_init (AptWatcher *self)
self->current_state = UP_TO_DATE;
self->proxy_cancel = g_cancellable_new();
self->proxy = NULL;
- self->transaction_proxy = NULL;
+ self->current_transaction = NULL;
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
@@ -104,6 +97,10 @@ static void
apt_watcher_finalize (GObject *object)
{
g_bus_unwatch_name (watcher_id);
+ AptWatcher* self = APT_WATCHER (object);
+
+ if (self->proxy != NULL)
+ g_object_unref (self->proxy);
G_OBJECT_CLASS (apt_watcher_parent_class)->finalize (object);
}
@@ -171,13 +168,15 @@ apt_watcher_on_name_appeared (GDBusConnection *connection,
g_dbus_proxy_call (watcher->proxy,
"UpgradeSystem",
- g_variant_new_boolean (TRUE),
+ g_variant_new("(b)", TRUE),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
apt_watcher_upgrade_system_cb,
user_data);
+ g_debug ("UpgradeSystem apt call made");
+
/*g_dbus_proxy_call (watcher->proxy,
"GetActiveTransactions",
NULL,
@@ -196,10 +195,6 @@ apt_watcher_on_name_vanished (GDBusConnection *connection,
g_debug ("Name %s does not exist or has just vanished",
name);
g_return_if_fail (APT_IS_WATCHER (user_data));
- AptWatcher* self = APT_WATCHER (user_data);
-
- if (self->proxy != NULL)
- g_object_unref (self->proxy);
}
/*static void
@@ -228,6 +223,8 @@ apt_watcher_upgrade_system_cb (GObject * obj,
GAsyncResult * res,
gpointer user_data)
{
+ g_debug ("UpgradeSystem apt callback");
+
g_return_if_fail (APT_IS_WATCHER (user_data));
AptWatcher* self = APT_WATCHER (user_data);
@@ -244,76 +241,21 @@ apt_watcher_upgrade_system_cb (GObject * obj,
gchar* transaction_id = NULL;
g_variant_get (result, "(s)", &transaction_id);
+
+ if (transaction_id == NULL){
+ g_debug ("apt_watcher_upgrade_system_cb - transaction id is null");
+ return;
+ }
- if (transaction_id != NULL){
- if (self->transaction_proxy != NULL){
- g_object_unref (self->transaction_proxy);
- self->transaction_proxy = NULL;
- }
- self->transaction_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL, /* GDBusInterfaceInfo */
- "org.debian.apt",
- transaction_id,
- "org.debian.apt",
- NULL, /* GCancellable */
- &error);
- if (error != NULL) {
- g_warning ("unable to fetch proxy for transaction object path");
- g_error_free (error);
- return;
- }
- g_signal_connect (self->transaction_proxy,
- "g-properties-changed",
- G_CALLBACK (transaction_on_properties_changed),
- self);
-
- g_dbus_proxy_call (self->transaction_proxy,
- "Simulate",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- apt_watcher_simulate_transaction_cb,
- self);
- }
-}
+ if (self->current_transaction == NULL){
+ self->current_transaction = apt_transaction_new (transaction_id);
+ }
-static void
-apt_watcher_simulate_transaction_cb (GObject * obj,
- GAsyncResult * res,
- gpointer user_data)
-{
}
-static void
-transaction_on_properties_changed (GDBusProxy *proxy,
- GVariant *changed_properties,
- const gchar* const *invalidated_properties,
- gpointer user_data)
-{
- if (g_variant_n_children (changed_properties) > 0)
- {
- GVariantIter *iter;
- const gchar *key;
- GVariant *value;
-
- g_print (" *** Properties Changed:\n");
- g_variant_get (changed_properties,
- "a{sv}",
- &iter);
- while (g_variant_iter_loop (iter, "{&sv}", &key, &value))
- {
- gchar *value_str;
- value_str = g_variant_print (value, TRUE);
- g_print (" %s -> %s\n", key, value_str);
- g_free (value_str);
- }
- g_variant_iter_free (iter);
- }
-}
-static void
+
+/*static void
apt_watcher_determine_state (AptWatcher* self,
GVariant* update)
{
@@ -346,7 +288,7 @@ apt_watcher_determine_state (AptWatcher* self,
_("Updates Installing..."));
}
}
-}
+}*/
static void
apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi,
@@ -355,7 +297,8 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi,
{
}
-// TODO signal is of type s not sas which is on d-feet !!!
+// TODO - Ask MVO about this.
+// Signal is of type s not sas which is on d-feet !!!
static void apt_watcher_signal_cb ( GDBusProxy* proxy,
gchar* sender_name,
gchar* signal_name,
@@ -370,7 +313,12 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy,
if (g_strcmp0(signal_name, "ActiveTransactionsChanged") == 0){
g_debug ("Active Transactions signal received");
- apt_watcher_determine_state (self, value);
+ gchar* input = NULL;
+ g_variant_get(value, "s", & input);
+ g_debug ("Active Transactions signal - input = %s", input);
+ if (self->current_transaction == NULL){
+ self->current_transaction = apt_transaction_new (input);
+ }
}
g_variant_unref (parameters);
}