aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2011-07-19 19:53:15 +0100
committerConor Curran <conor.curran@canonical.com>2011-07-19 19:53:15 +0100
commit34a5a7289ede2d662d6c64457afcd1c22354d21b (patch)
tree6a3f5e3a09dbe503bef4b44bf7327a61a2d5bb01
parent123c9776b0a67b8dd8a58b8295c3356b1f8be606 (diff)
downloadayatana-indicator-session-34a5a7289ede2d662d6c64457afcd1c22354d21b.tar.gz
ayatana-indicator-session-34a5a7289ede2d662d6c64457afcd1c22354d21b.tar.bz2
ayatana-indicator-session-34a5a7289ede2d662d6c64457afcd1c22354d21b.zip
apt watcher coming along nicely
-rw-r--r--src/Makefile.am6
-rw-r--r--src/apt-watcher.c177
-rw-r--r--src/apt-watcher.h46
-rw-r--r--src/device-menu-mgr.c4
-rw-r--r--src/udev-mgr.c1
5 files changed, 232 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2230910..753b71d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -95,7 +95,11 @@ indicator_session_service_SOURCES = \
user-menu-mgr.h \
user-menu-mgr.c \
device-menu-mgr.h \
- device-menu-mgr.c
+ device-menu-mgr.c \
+ apt-watcher.h \
+ apt-watcher.c \
+ udev-mgr.h \
+ udev-mgr.c
indicator_session_service_CFLAGS = \
$(SESSIONSERVICE_CFLAGS) \
$(GCONF_CFLAGS) \
diff --git a/src/apt-watcher.c b/src/apt-watcher.c
new file mode 100644
index 0000000..daab2ee
--- /dev/null
+++ b/src/apt-watcher.c
@@ -0,0 +1,177 @@
+/*
+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 "apt-watcher.h"
+#include <gio/gio.h>
+
+static guint watcher_id;
+
+struct _AptWatcher
+{
+ GObject parent_instance;
+ GCancellable * proxy_cancel;
+ GDBusProxy * proxy;
+};
+
+static void
+apt_watcher_on_name_appeared (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data);
+static void
+apt_watcher_on_name_vanished (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data);
+static void
+apt_watcher_get_active_transactions_cb (GObject * obj,
+ GAsyncResult * res,
+ gpointer user_data);
+static void
+fetch_proxy_cb (GObject * object,
+ GAsyncResult * res,
+ gpointer user_data);
+
+G_DEFINE_TYPE (AptWatcher, apt_watcher, G_TYPE_OBJECT);
+
+static void
+apt_watcher_init (AptWatcher *self)
+{
+ self->proxy_cancel = g_cancellable_new();
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.debian.apt",
+ "/org/debian/apt",
+ "org.debian.apt",
+ self->proxy_cancel,
+ fetch_proxy_cb,
+ self);
+}
+
+static void
+apt_watcher_finalize (GObject *object)
+{
+ g_bus_unwatch_name (watcher_id);
+
+ G_OBJECT_CLASS (apt_watcher_parent_class)->finalize (object);
+}
+
+static void
+apt_watcher_class_init (AptWatcherClass *klass)
+{
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = apt_watcher_finalize;
+}
+
+static void
+fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
+{
+ GError * error = NULL;
+
+ AptWatcher* self = APT_WATCHER(user_data);
+ g_return_if_fail(self != 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;
+ // Set up the watch.
+ watcher_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
+ "org.debian.apt",
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ apt_watcher_on_name_appeared,
+ apt_watcher_on_name_vanished,
+ self,
+ NULL);
+
+ //We'll need to connect to the state changed signal
+ //g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self);
+}
+
+
+static void
+apt_watcher_on_name_appeared (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
+{
+ g_return_if_fail (APT_IS_WATCHER (user_data));
+ AptWatcher* watcher = APT_WATCHER (user_data);
+
+ g_print ("Name %s on %s is owned by %s\n",
+ name,
+ "the system bus",
+ name_owner);
+
+
+ g_dbus_proxy_call (watcher->proxy,
+ "GetActiveTransactions",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ apt_watcher_get_active_transactions_cb,
+ user_data);
+}
+
+static void
+apt_watcher_get_active_transactions_cb (GObject * obj,
+ GAsyncResult * res,
+ gpointer user_data)
+{
+ g_return_if_fail (APT_IS_WATCHER (user_data));
+ AptWatcher* self = APT_WATCHER (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 fetching of active transactions");
+ g_error_free (error);
+ return;
+ }
+
+ g_debug ("WE GOT SOME ACTIVE TRANSACTIONS TO EXAMINE, type is %s",
+ g_variant_get_type_string (result));
+ //gchar ** transactions = g_variant_get_strv (result);
+
+}
+
+static void
+apt_watcher_on_name_vanished (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_print ("Name %s does not exist on %s\n",
+ name,
+ "the system bus");
+}
diff --git a/src/apt-watcher.h b/src/apt-watcher.h
new file mode 100644
index 0000000..148072f
--- /dev/null
+++ b/src/apt-watcher.h
@@ -0,0 +1,46 @@
+/*
+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_WATCHER_H_
+#define _APT_WATCHER_H_
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define APT_TYPE_WATCHER (apt_watcher_get_type ())
+#define APT_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APT_TYPE_WATCHER, AptWatcher))
+#define APT_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APT_TYPE_WATCHER, AptWatcherClass))
+#define APT_IS_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APT_TYPE_WATCHER))
+#define APT_IS_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APT_TYPE_WATCHER))
+#define APT_WATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APT_TYPE_WATCHER, AptWatcherClass))
+
+typedef struct _AptWatcherClass AptWatcherClass;
+typedef struct _AptWatcher AptWatcher;
+
+struct _AptWatcherClass
+{
+ GObjectClass parent_class;
+};
+
+GType apt_watcher_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* _APT_WATCHER_H_ */
diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c
index ccb4523..a3cea61 100644
--- a/src/device-menu-mgr.c
+++ b/src/device-menu-mgr.c
@@ -25,6 +25,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "dbusmenu-shared.h"
#include "lock-helper.h"
#include "upower-client.h"
+#include "apt-watcher.h"
#define UP_ADDRESS "org.freedesktop.UPower"
@@ -87,6 +88,7 @@ static void
machine_sleep_from_hibernate (DbusmenuMenuitem * mi,
guint timestamp,
gpointer userdata);
+static AptWatcher* watcher = NULL;
/*static void
machine_sleep_from_suspend (DbusmenuMenuitem * mi,
guint timestamp,
@@ -101,6 +103,7 @@ device_menu_mgr_init (DeviceMenuMgr *self)
setup_restart_watch(self);
setup_up(self);
g_idle_add(lock_screen_setup, NULL);
+
}
static void
@@ -117,6 +120,7 @@ device_menu_mgr_class_init (DeviceMenuMgrClass *klass)
GObjectClass* object_class = G_OBJECT_CLASS (klass);
//GObjectClass* parent_class = G_OBJECT_CLASS (klass);
object_class->finalize = device_menu_mgr_finalize;
+ watcher = g_object_new (APT_TYPE_WATCHER, NULL);
}
// TODO
diff --git a/src/udev-mgr.c b/src/udev-mgr.c
index 75f760d..6575ca5 100644
--- a/src/udev-mgr.c
+++ b/src/udev-mgr.c
@@ -40,7 +40,6 @@ static void
udev_mgr_class_init (UdevMgrClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
- GObjectClass* parent_class = G_OBJECT_CLASS (klass);
object_class->finalize = udev_mgr_finalize;
}