diff options
author | Ted Gould <ted@canonical.com> | 2009-01-15 15:33:00 -0600 |
---|---|---|
committer | Ted Gould <ted@canonical.com> | 2009-01-15 15:33:00 -0600 |
commit | 441032cd3c150032bae9c7ec1c94fcacceee7c90 (patch) | |
tree | 786fe11c156e191533e7d33664461a5032ab8a32 /libindicate | |
parent | ccac9b84bae42b0ad622d282dc12a65c3f7c7b11 (diff) | |
download | libayatana-indicator-441032cd3c150032bae9c7ec1c94fcacceee7c90.tar.gz libayatana-indicator-441032cd3c150032bae9c7ec1c94fcacceee7c90.tar.bz2 libayatana-indicator-441032cd3c150032bae9c7ec1c94fcacceee7c90.zip |
Starting to flesh out the listener a little bit, should get a list of names on teh bus at this point
Diffstat (limited to 'libindicate')
-rw-r--r-- | libindicate/listener.c | 138 | ||||
-rw-r--r-- | libindicate/listener.h | 12 |
2 files changed, 149 insertions, 1 deletions
diff --git a/libindicate/listener.c b/libindicate/listener.c index 3b082d7..a82f0f2 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -1,5 +1,6 @@ #include "listener.h" +#include <dbus/dbus-glib-bindings.h> /* Errors */ enum { @@ -18,10 +19,23 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; +typedef struct { + DBusGProxy * proxy; + gchar * name; +} proxy_t; + +typedef struct { + gchar * name; +} proxy_todo_t; + G_DEFINE_TYPE (IndicateListener, indicate_listener, G_TYPE_OBJECT); /* Prototypes */ static void indicate_listener_finalize (GObject * obj); +static void dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, IndicateListener * listener); +static void proxy_struct_destroy (gpointer data); +static void build_todo_list_cb (DBusGProxy * proxy, char ** names, GError * error, void * data); +static void todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListener * listener); /* Code */ static void @@ -61,9 +75,76 @@ indicate_listener_class_init (IndicateListenerClass * class) } static void -indicate_listener_init (IndicateListener * server) +indicate_listener_init (IndicateListener * listener) { g_debug("Listener Object Initialized"); + GError *error = NULL; + + /* Get the buses */ + listener->session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (error != NULL) { + g_error("Unable to get session bus: %s", error->message); + g_error_free(error); + return; + } + + listener->system_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (error != NULL) { + g_error("Unable to get system bus: %s", error->message); + g_error_free(error); + return; + } + + /* Set up the DBUS service proxies */ + listener->dbus_proxy_session = dbus_g_proxy_new_for_name_owner (listener->session_bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + &error); + if (error != NULL) { + g_error("Unable to get dbus proxy on session bus: %s", error->message); + g_error_free(error); + return; + } + + listener->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (listener->system_bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + &error); + if (error != NULL) { + g_error("Unable to get dbus proxy on system bus: %s", error->message); + g_error_free(error); + return; + } + + /* Set up name change signals */ + dbus_g_proxy_add_signal(listener->dbus_proxy_session, "NameOwnerChanged", + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(listener->dbus_proxy_session, "NameOwnerChanged", + G_CALLBACK(dbus_owner_change), listener, NULL); + dbus_g_proxy_add_signal(listener->dbus_proxy_system, "NameOwnerChanged", + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(listener->dbus_proxy_system, "NameOwnerChanged", + G_CALLBACK(dbus_owner_change), listener, NULL); + + /* Initialize Data structures */ + listener->proxies_system = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, proxy_struct_destroy); + listener->proxies_session = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, proxy_struct_destroy); + /* TODO: Look at some common scenarios and find out how to make this sized */ + listener->proxy_todo = g_array_new(FALSE, TRUE, sizeof(proxy_todo_t)); + + /* WARNING */ + /* Starting massive asynchronisity */ + /* */ + + /* Build todo list */ + org_freedesktop_DBus_list_names_async (listener->dbus_proxy_session, build_todo_list_cb, listener); + org_freedesktop_DBus_list_names_async (listener->dbus_proxy_system, build_todo_list_cb, listener); return; } @@ -76,3 +157,58 @@ indicate_listener_finalize (GObject * obj) return; } +static void +dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, IndicateListener * listener) +{ + DBusGConnection * bus; + gchar * bus_name; + if (proxy == listener->dbus_proxy_system) { + bus = listener->system_bus; + bus_name = "system"; + } else { + bus = listener->session_bus; + bus_name = "session"; + } + + g_debug("Name change on %s bus: '%s' from '%s' to '%s'", bus_name, name, prev, new); + + return; +} + +static void +proxy_struct_destroy (gpointer data) +{ + proxy_t * proxy_data = data; + + g_object_unref(proxy_data->proxy); + // name is the key also, so it'll get destroyed there + + return; +} + +static void +build_todo_list_cb (DBusGProxy * proxy, char ** names, GError * error, void * data) +{ + IndicateListener * listener = INDICATE_LISTENER(data); + + if (error != NULL) { + g_warning("Unable to get names: %s", error->message); + return; + } + + guint i = 0; + for (i = 0; names[i] != NULL; i++) { + todo_list_add(names[i], proxy, listener); + } + + return; +} + +static void +todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListener * listener) +{ + g_debug ("Adding %s"); + + return; +} + diff --git a/libindicate/listener.h b/libindicate/listener.h index 1f0c870..8fc210f 100644 --- a/libindicate/listener.h +++ b/libindicate/listener.h @@ -5,6 +5,8 @@ #include <glib.h> #include <glib-object.h> +#include <dbus/dbus-glib.h> + #include "indicator.h" #include "server.h" @@ -22,6 +24,16 @@ typedef struct _IndicateListener IndicateListener; struct _IndicateListener { GObject parent; + DBusGConnection * session_bus; + DBusGConnection * system_bus; + + DBusGProxy * dbus_proxy_session; + DBusGProxy * dbus_proxy_system; + + GHashTable * proxies_session; + GHashTable * proxies_system; + + GArray * proxy_todo; }; typedef struct _IndicateListenerClass IndicateListenerClass; |