diff options
author | Conor Curran <conor.curran@canonical.com> | 2012-02-08 16:37:31 +0000 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2012-02-08 16:37:31 +0000 |
commit | d4162d24e4bdee56df9bf6815207cf0ecf15fed3 (patch) | |
tree | 9f3d9be2bfde1afa93c2f5a4438302f60f4a11b7 /src | |
parent | 3c560ddcaeb71953c7dfecf2acfa11aa77b0e3d9 (diff) | |
download | ayatana-indicator-session-d4162d24e4bdee56df9bf6815207cf0ecf15fed3.tar.gz ayatana-indicator-session-d4162d24e4bdee56df9bf6815207cf0ecf15fed3.tar.bz2 ayatana-indicator-session-d4162d24e4bdee56df9bf6815207cf0ecf15fed3.zip |
get rid of the transaction as we don't need to worry about updates installing state
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/apt-transaction.c | 263 | ||||
-rw-r--r-- | src/apt-transaction.h | 49 | ||||
-rw-r--r-- | src/apt-watcher.c | 9 |
4 files changed, 5 insertions, 320 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index afee66c..67a1cb6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -114,9 +114,7 @@ indicator_session_service_SOURCES = \ if BUILD_APT indicator_session_service_SOURCES += \ apt-watcher.h \ - apt-watcher.c \ - apt-transaction.h \ - apt-transaction.c + apt-watcher.c endif indicator_session_service_CFLAGS = \ diff --git a/src/apt-transaction.c b/src/apt-transaction.c deleted file mode 100644 index 2b3f5a4..0000000 --- a/src/apt-transaction.c +++ /dev/null @@ -1,263 +0,0 @@ -/* -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" -#include "dbus-shared-names.h" - -static void apt_transaction_investigate (AptTransaction* self); -static void apt_transaction_simulate_transaction_cb (GObject * obj, - GAsyncResult * res, - gpointer user_data); -static void apt_transaction_receive_signal (GDBusProxy * proxy, - gchar * sender_name, - 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; - GCancellable * proxy_cancel; - gchar* id; - TransactionType type; -}; - -enum { - UPDATE, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT); - -static void -apt_transaction_init (AptTransaction *self) -{ - self->proxy = NULL; - self->id = NULL; - self->proxy_cancel = g_cancellable_new(); -} - -static void -apt_transaction_finalize (GObject *object) -{ - AptTransaction* self = APT_TRANSACTION(object); - g_signal_handlers_disconnect_by_func (G_OBJECT (self->proxy), - G_CALLBACK (apt_transaction_receive_signal), - self); - 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); - object_class->finalize = apt_transaction_finalize; - - signals[UPDATE] = g_signal_new("state-update", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__INT, - 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) -{ - 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", - G_CALLBACK (apt_transaction_receive_signal), - self); - - if (self->type == SIMULATION){ - 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_receive_signal (GDBusProxy * proxy, - gchar * sender_name, - gchar * signal_name, - GVariant * parameters, - gpointer user_data) -{ - g_return_if_fail (APT_IS_TRANSACTION (user_data)); - AptTransaction* self = APT_TRANSACTION(user_data); - AptState current_state = DONT_KNOW; - - if (g_strcmp0(signal_name, "PropertyChanged") == 0) - { - gchar* prop_name= NULL; - GVariant* value = NULL; - g_variant_get (parameters, "(sv)", &prop_name, &value); - g_debug ("transaction prop update - prop = %s", prop_name); - - if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) == TRUE){ - gchar* key = NULL; - g_variant_get (value, "s", &key); - g_debug ("transaction prop update - value = %s", key); - } - - if (g_strcmp0 (prop_name, "Dependencies") == 0){ - - gchar** install = NULL; - gchar** reinstall = NULL; - gchar** remove = NULL; - gchar** purge = NULL; - gchar** upgrade = NULL; - gchar** downgrade = NULL; - gchar** keep = NULL; - g_variant_get (value, "(asasasasasasas)", &install, - &reinstall, &remove, &purge, &upgrade, &downgrade, - &keep); - /* - g_debug ("upgrade package length %i", g_strv_length(upgrade)); - g_debug ("install package length %i", g_strv_length(install)); - g_debug ("reinstall package length %i", g_strv_length(reinstall)); - g_debug ("remove package length %i", g_strv_length(remove)); - g_debug ("purge package length %i", g_strv_length(purge)); - */ - gboolean upgrade_needed = (g_strv_length(upgrade) > 1) || - (g_strv_length(install) > 1) || - (g_strv_length(reinstall) > 1) || - (g_strv_length(remove) > 1) || - (g_strv_length(purge) > 1); - if (upgrade_needed == TRUE){ - current_state = UPDATES_AVAILABLE; - } - else{ - current_state = UP_TO_DATE; - } - } - if (self->type == REAL) - { - GVariant* role = g_dbus_proxy_get_cached_property (self->proxy, - "Role"); - if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){ - gchar* current_role = NULL; - g_variant_get (role, "s", ¤t_role); - //g_debug ("Current transaction role = %s", current_role); - if (g_strcmp0 (current_role, "role-commit-packages") == 0 || - g_strcmp0 (current_role, "role-upgrade-system") == 0){ - g_debug ("UPGRADE IN PROGRESS"); - current_state = UPGRADE_IN_PROGRESS; - } - } - } - } - else if (g_strcmp0(signal_name, "Finished") == 0) - { - g_debug ("TRANSACTION Finished"); - current_state = FINISHED; - } - // Finally send out the state update - if (current_state != DONT_KNOW){ - g_signal_emit (self, - signals[UPDATE], - 0, - current_state); - } -} - -static void -apt_transaction_simulate_transaction_cb (GObject * obj, - GAsyncResult * res, - gpointer user_data) -{ - GError * error = NULL; - if (error != NULL) { - g_warning ("unable to complete the simulate call"); - g_error_free (error); - return; - } -} -TransactionType -apt_transaction_get_transaction_type (AptTransaction* self) -{ - return self->type; -} - -AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t) -{ - AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL); - tr->id = transaction_id; - tr->type = t; - g_debug ("Apt transaction new id = %s", tr->id); - apt_transaction_investigate (tr); - return tr; -} diff --git a/src/apt-transaction.h b/src/apt-transaction.h deleted file mode 100644 index 9e4370d..0000000 --- a/src/apt-transaction.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -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> -#include "dbus-shared-names.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, TransactionType t); -TransactionType apt_transaction_get_transaction_type (AptTransaction* self); -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 cdb3ce9..cab2d8b 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -30,9 +30,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>. static guint watcher_id; -// TODO -// Get it working and then remove the pkclient pointer in the priv -// it's not needed. struct _AptWatcher { GObject parent_instance; @@ -114,7 +111,6 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, AptWatcher* self = APT_WATCHER (user_data); g_variant_ref_sink (parameters); - GVariant *value = g_variant_get_child_value (parameters, 0); g_debug ("apt-watcher-signal cb signal name - %s", signal_name); if (g_strcmp0(signal_name, "UpdatesChanged") == 0){ g_debug ("updates changed signal received"); @@ -129,8 +125,11 @@ static void apt_watcher_signal_cb ( GDBusProxy* proxy, DBUSMENU_MENUITEM_PROP_DISPOSITION, DBUSMENU_MENUITEM_DISPOSITION_ALERT); } + else if (g_strcmp0(signal_name, "TransactionListChanged") == 0) { + GVariant *value = g_variant_get_child_value (parameters, 0); + g_variant_unref (value); - g_variant_unref (value); + } g_variant_unref (parameters); } |