From 48277fb0df0d455db8f1e953a591200fd650c202 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 10:39:32 -0600 Subject: Cut-and-paste error --- libindicate/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicate/server.h b/libindicate/server.h index fe3ec28..bc4522d 100644 --- a/libindicate/server.h +++ b/libindicate/server.h @@ -92,5 +92,5 @@ gboolean indicate_server_show_indicator_to_user (IndicateServer * server, guint G_END_DECLS -#endif /* INDICATE_INDICATOR_H_INCLUDED__ */ +#endif /* INDICATE_SERVER_H_INCLUDED__ */ -- cgit v1.2.3 From ccac9b84bae42b0ad622d282dc12a65c3f7c7b11 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 10:39:51 -0600 Subject: Adding in the base object for the listener. --- libindicate/Makefile.am | 2 ++ libindicate/listener.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ libindicate/listener.h | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 libindicate/listener.c create mode 100644 libindicate/listener.h diff --git a/libindicate/Makefile.am b/libindicate/Makefile.am index 3dd211d..2d75dbd 100644 --- a/libindicate/Makefile.am +++ b/libindicate/Makefile.am @@ -17,6 +17,7 @@ libindicateincludedir=$(includedir)/libindicate-1.0/libindicate indicate_headers = \ indicator.h \ + listener.h \ server.h libindicateinclude_HEADERS = \ @@ -26,6 +27,7 @@ libindicate_la_SOURCES = \ $(indicate_headers) \ dbus-indicate-server.h \ server.c \ + listener.c \ indicator.c libindicate_la_LDFLAGS = \ diff --git a/libindicate/listener.c b/libindicate/listener.c new file mode 100644 index 0000000..3b082d7 --- /dev/null +++ b/libindicate/listener.c @@ -0,0 +1,78 @@ + +#include "listener.h" + +/* Errors */ +enum { + LAST_ERROR +}; + +/* Signals */ +enum { + INDICATOR_ADDED, + INDICATOR_REMOVED, + INDICATOR_MODIFIED, + SERVER_ADDED, + SERVER_REMOVED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +G_DEFINE_TYPE (IndicateListener, indicate_listener, G_TYPE_OBJECT); + +/* Prototypes */ +static void indicate_listener_finalize (GObject * obj); + +/* Code */ +static void +indicate_listener_class_init (IndicateListenerClass * class) +{ + g_debug("Listener Class Initialized"); + GObjectClass * gobj; + gobj = G_OBJECT_CLASS(class); + + gobj->finalize = indicate_listener_finalize; + +/* TODO, I need new marshallers here, bah humbug + signals[INDICATOR_ADDED] = g_signal_new("indicator-added", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IndicateListenerClass, indicator_added), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER_POINTER_POINTER, + G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_OBJECT, G_TYPE_STRING); + signals[INDICATOR_REMOVED] = g_signal_new("indicator-removed", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IndicateServerClass, indicator_removed), + NULL, NULL, + g_cclosure_marshal_VOID__UINT_POINTER, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); + signals[INDICATOR_MODIFIED] = g_signal_new("indicator-modified", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IndicateServerClass, indicator_modified), + NULL, NULL, + g_cclosure_marshal_VOID__UINT_POINTER, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); +*/ + + return; +} + +static void +indicate_listener_init (IndicateListener * server) +{ + g_debug("Listener Object Initialized"); + + return; +} + +static void +indicate_listener_finalize (GObject * obj) +{ + IndicateListener * listener = INDICATE_LISTENER(obj); + + return; +} + diff --git a/libindicate/listener.h b/libindicate/listener.h new file mode 100644 index 0000000..1f0c870 --- /dev/null +++ b/libindicate/listener.h @@ -0,0 +1,53 @@ + +#ifndef INDICATE_LISTENER_H_INCLUDED__ +#define INDICATE_LISTENER_H_INCLUDED__ 1 + +#include +#include + +#include "indicator.h" +#include "server.h" + +G_BEGIN_DECLS + +/* Boilerplate */ +#define INDICATE_TYPE_LISTENER (indicate_server_get_type ()) +#define INDICATE_LISTENER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), INDICATE_TYPE_LISTENER, IndicateListener)) +#define INDICATE_IS_LISTENER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), INDICATE_TYPE_LISTENER)) +#define INDICATE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), INDICATE_TYPE_LISTENER, IndicateListenerClass)) +#define INDICATE_IS_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), INDICATE_TYPE_LISTENER)) +#define INDICATE_LISTENER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), INDICATE_TYPE_LISTENER, IndicateListenerClass)) + +typedef struct _IndicateListener IndicateListener; +struct _IndicateListener { + GObject parent; + +}; + +typedef struct _IndicateListenerClass IndicateListenerClass; +struct _IndicateListenerClass { + GObjectClass parent; + + /* Signals */ + void (* indicator_added) (IndicateServer * server, IndicateIndicator * indicator, gchar * type); + void (* indicator_removed) (IndicateServer * server, IndicateIndicator * indicator, gchar * type); + void (* indicator_modified) (IndicateServer * server, IndicateIndicator * indicator, gchar * property); + + void (* server_added) (IndicateServer * server); + void (* server_removed) (IndicateServer * server); + +}; + +GType indicate_listener_get_type (void) G_GNUC_CONST; + +/* Create a new server */ +IndicateListener * indicate_listener_new (void); + + + + + +G_END_DECLS + +#endif /* INDICATE_LISTENER_H_INCLUDED__ */ + -- cgit v1.2.3 From 441032cd3c150032bae9c7ec1c94fcacceee7c90 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 15:33:00 -0600 Subject: Starting to flesh out the listener a little bit, should get a list of names on teh bus at this point --- libindicate/listener.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++- libindicate/listener.h | 12 +++++ 2 files changed, 149 insertions(+), 1 deletion(-) 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 /* 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 #include +#include + #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; -- cgit v1.2.3 From 6ba40259a36abf1b1380921478b68e6dd4e2e8d9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 15:42:16 -0600 Subject: Adding a new function --- libindicate/listener.c | 10 +++++++++- libindicate/listener.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libindicate/listener.c b/libindicate/listener.c index a82f0f2..5f48ecf 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -157,6 +157,14 @@ indicate_listener_finalize (GObject * obj) return; } +IndicateListener * +indicate_listener_new (void) +{ + IndicateListener * listener; + listener = g_object_new(INDICATE_TYPE_LISTENER, NULL); + return listener; +} + static void dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, const gchar * new, IndicateListener * listener) { @@ -207,7 +215,7 @@ build_todo_list_cb (DBusGProxy * proxy, char ** names, GError * error, void * da static void todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListener * listener) { - g_debug ("Adding %s"); + g_debug ("Adding %s", name); return; } diff --git a/libindicate/listener.h b/libindicate/listener.h index 8fc210f..f596494 100644 --- a/libindicate/listener.h +++ b/libindicate/listener.h @@ -52,7 +52,7 @@ struct _IndicateListenerClass { GType indicate_listener_get_type (void) G_GNUC_CONST; -/* Create a new server */ +/* Create a new listener */ IndicateListener * indicate_listener_new (void); -- cgit v1.2.3 From da2657ed395994ec4018633f4f88a32adeed808c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 15:48:38 -0600 Subject: Adding in a basic listening test --- libindicate/tests/Makefile.am | 14 +++++++++++++- libindicate/tests/listen-and-print.c | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 libindicate/tests/listen-and-print.c diff --git a/libindicate/tests/Makefile.am b/libindicate/tests/Makefile.am index 814a50b..208da5b 100644 --- a/libindicate/tests/Makefile.am +++ b/libindicate/tests/Makefile.am @@ -1,7 +1,8 @@ noinst_PROGRAMS = \ indicate-and-crash \ - indicate-alot + indicate-alot \ + listen-and-print indicate_and_crash_SOURCES = \ indicate-and-crash.c @@ -24,3 +25,14 @@ indicate_alot_CFLAGS = \ indicate_alot_LDADD = \ ../libindicate.la \ $(LIBINDICATE_LIBS) + +listen_and_print_SOURCES = \ + listen-and-print.c + +listen_and_print_CFLAGS = \ + -I $(srcdir)/../.. \ + $(LIBINDICATE_CFLAGS) + +listen_and_print_LDADD = \ + ../libindicate.la \ + $(LIBINDICATE_LIBS) diff --git a/libindicate/tests/listen-and-print.c b/libindicate/tests/listen-and-print.c new file mode 100644 index 0000000..772e4f1 --- /dev/null +++ b/libindicate/tests/listen-and-print.c @@ -0,0 +1,16 @@ + +#include +#include "libindicate/listener.h" + + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicateListener * listener = indicate_listener_new(); + + g_main_loop_run(g_main_loop_new(NULL, FALSE)); + + return 0; +} -- cgit v1.2.3 From 4c623e47c0854f9acc2119045fa3f1ae76a82386 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 15:52:40 -0600 Subject: Amazing how a little string can make such a huge difference. --- libindicate/listener.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicate/listener.h b/libindicate/listener.h index f596494..7977711 100644 --- a/libindicate/listener.h +++ b/libindicate/listener.h @@ -13,7 +13,7 @@ G_BEGIN_DECLS /* Boilerplate */ -#define INDICATE_TYPE_LISTENER (indicate_server_get_type ()) +#define INDICATE_TYPE_LISTENER (indicate_listener_get_type ()) #define INDICATE_LISTENER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), INDICATE_TYPE_LISTENER, IndicateListener)) #define INDICATE_IS_LISTENER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), INDICATE_TYPE_LISTENER)) #define INDICATE_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), INDICATE_TYPE_LISTENER, IndicateListenerClass)) -- cgit v1.2.3 From 421cea272535812a6fcc4d64811d6bf6a5362647 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 17:10:14 -0600 Subject: Changing to the dbus interface and changing to build teh client and server interfaces --- libindicate/Makefile.am | 17 ++++++++--- libindicate/indicate-interface.xml | 60 ++++++++++++++++++++++++++++++++++++++ libindicate/indicate-server.xml | 60 -------------------------------------- 3 files changed, 73 insertions(+), 64 deletions(-) create mode 100644 libindicate/indicate-interface.xml delete mode 100644 libindicate/indicate-server.xml diff --git a/libindicate/Makefile.am b/libindicate/Makefile.am index 2d75dbd..b3c173a 100644 --- a/libindicate/Makefile.am +++ b/libindicate/Makefile.am @@ -5,10 +5,11 @@ INCLUDES= \ -DG_LOG_DOMAIN=\"libindicate\" EXTRA_DIST = \ - indicate-server.xml + indicate-interface.xml BUILT_SOURCES = \ - dbus-indicate-server.h + dbus-indicate-server.h \ + dbus-indicate-client.h lib_LTLIBRARIES = \ libindicate.la @@ -26,6 +27,7 @@ libindicateinclude_HEADERS = \ libindicate_la_SOURCES = \ $(indicate_headers) \ dbus-indicate-server.h \ + dbus-indicate-client.h \ server.c \ listener.c \ indicator.c @@ -41,12 +43,19 @@ libindicate_la_CFLAGS = \ libindicate_la_LIBADD = \ $(LIBINDICATE_LIBS) -dbus-indicate-server.h: indicate-server.xml +dbus-indicate-server.h: indicate-interface.xml libtool --mode=execute dbus-binding-tool \ --prefix=indicate_server \ --mode=glib-server \ --output=dbus-indicate-server.h \ - $(srcdir)/indicate-server.xml + $(srcdir)/indicate-interface.xml + +dbus-indicate-client.h: indicate-interface.xml + libtool --mode=execute dbus-binding-tool \ + --prefix=indicate_client \ + --mode=glib-client \ + --output=dbus-indicate-client.h \ + $(srcdir)/indicate-interface.xml pkgconfig_DATA = indicate.pc pkgconfigdir = $(libdir)/pkgconfig diff --git a/libindicate/indicate-interface.xml b/libindicate/indicate-interface.xml new file mode 100644 index 0000000..d1fed7e --- /dev/null +++ b/libindicate/indicate-interface.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libindicate/indicate-server.xml b/libindicate/indicate-server.xml deleted file mode 100644 index d1fed7e..0000000 --- a/libindicate/indicate-server.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3 From d1c2ed2c5ccdfefc8c63e591a1742d8d61f310c4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 17:10:36 -0600 Subject: Now doing some DBus listening and getting some of the initial configuration built up. --- libindicate/listener.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++- libindicate/listener.h | 1 + 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/libindicate/listener.c b/libindicate/listener.c index 5f48ecf..e60ad0f 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -1,6 +1,7 @@ #include "listener.h" #include +#include "dbus-indicate-client.h" /* Errors */ enum { @@ -22,9 +23,11 @@ static guint signals[LAST_SIGNAL] = { 0 }; typedef struct { DBusGProxy * proxy; gchar * name; + IndicateListener * listener; } proxy_t; typedef struct { + DBusGConnection * bus; gchar * name; } proxy_todo_t; @@ -36,6 +39,8 @@ static void dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gch 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); +static gboolean todo_idle (gpointer data); +static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt); /* Code */ static void @@ -137,6 +142,7 @@ indicate_listener_init (IndicateListener * listener) 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)); + listener->todo_idle = 0; /* WARNING */ /* Starting massive asynchronisity */ @@ -180,6 +186,10 @@ dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, c g_debug("Name change on %s bus: '%s' from '%s' to '%s'", bus_name, name, prev, new); + if (prev != NULL && prev[0] == '\0') { + todo_list_add(name, proxy, listener); + } + return; } @@ -215,8 +225,74 @@ build_todo_list_cb (DBusGProxy * proxy, char ** names, GError * error, void * da static void todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListener * listener) { - g_debug ("Adding %s", name); + 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 ("Adding on %s bus: %s", bus_name, name); + + proxy_todo_t todo; + todo.name = g_strdup(name); + todo.bus = bus; + + g_array_append_val(listener->proxy_todo, todo); + + if (listener->todo_idle == 0) { + listener->todo_idle = g_idle_add(todo_idle, listener); + } return; } +gboolean +todo_idle (gpointer data) +{ + IndicateListener * listener = INDICATE_LISTENER(data); + if (listener == NULL) { + g_error("Listener got lost in todo_idle"); + return FALSE; + } + + if (listener->proxy_todo->len == 0) { + /* Basically if we have no todo, we need to stop running. This + * is done this way to make the function error handling simpler + * and results in an extra run */ + return FALSE; + } + + proxy_todo_t * todo = &g_array_index(listener->proxy_todo, proxy_todo_t, listener->proxy_todo->len - 1); + + proxy_t * proxyt = g_new(proxy_t, 1); + proxyt->name = todo->name; + proxyt->proxy = dbus_g_proxy_new_for_name(todo->bus, + proxyt->name, + "/org/freedesktop/indicate", + "org.freedesktop.indicator"); + proxyt->listener = listener; + + listener->proxy_todo = g_array_remove_index(listener->proxy_todo, listener->proxy_todo->len - 1); + + if (proxyt->proxy == NULL) { + g_warning("Unable to create proxy for %s", proxyt->name); + return TRUE; + } + + dbus_g_proxy_add_signal(proxyt->proxy, "IndicatorAdded", + G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(proxyt->proxy, "IndicatorAdded", + G_CALLBACK(proxy_indicator_added), proxyt, NULL); + + return TRUE; +} + +static void +proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt) +{ + g_debug("Interface %s has an indicator %d", proxyt->name, id); + return; +} diff --git a/libindicate/listener.h b/libindicate/listener.h index 7977711..b86c8a3 100644 --- a/libindicate/listener.h +++ b/libindicate/listener.h @@ -34,6 +34,7 @@ struct _IndicateListener { GHashTable * proxies_system; GArray * proxy_todo; + guint todo_idle; }; typedef struct _IndicateListenerClass IndicateListenerClass; -- cgit v1.2.3 From e50f228a7e4116c902a992a12ce9332c4481bf4c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 19:49:23 -0600 Subject: Adding in a marshaller for the DBus signals that we need --- libindicate/Makefile.am | 16 +++++++++++++++- libindicate/listener-marshal.list | 2 ++ libindicate/listener.c | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 libindicate/listener-marshal.list diff --git a/libindicate/Makefile.am b/libindicate/Makefile.am index b3c173a..53917b7 100644 --- a/libindicate/Makefile.am +++ b/libindicate/Makefile.am @@ -9,7 +9,9 @@ EXTRA_DIST = \ BUILT_SOURCES = \ dbus-indicate-server.h \ - dbus-indicate-client.h + dbus-indicate-client.h \ + listener-marshal.c \ + listener-marshal.h lib_LTLIBRARIES = \ libindicate.la @@ -30,6 +32,8 @@ libindicate_la_SOURCES = \ dbus-indicate-client.h \ server.c \ listener.c \ + listener-marshal.c \ + listener-marshal.h \ indicator.c libindicate_la_LDFLAGS = \ @@ -57,5 +61,15 @@ dbus-indicate-client.h: indicate-interface.xml --output=dbus-indicate-client.h \ $(srcdir)/indicate-interface.xml +listener-marshal.h: listener-marshal.list + libtool --mode=execute glib-genmarshal --header \ + --prefix=indicate_listener_marshal $(srcdir)/listener-marshal.list \ + > listener-marshal.h + +listener-marshal.c: listener-marshal.list + libtool --mode=execute glib-genmarshal --body \ + --prefix=indicate_listener_marshal $(srcdir)/listener-marshal.list \ + > listener-marshal.c + pkgconfig_DATA = indicate.pc pkgconfigdir = $(libdir)/pkgconfig diff --git a/libindicate/listener-marshal.list b/libindicate/listener-marshal.list new file mode 100644 index 0000000..c02c70f --- /dev/null +++ b/libindicate/listener-marshal.list @@ -0,0 +1,2 @@ +# IndicatorAdded, IndicatorRemoved, IndicatorModified +VOID:UINT,STRING diff --git a/libindicate/listener.c b/libindicate/listener.c index e60ad0f..a26ddcc 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -1,5 +1,6 @@ #include "listener.h" +#include "listener-marshal.h" #include #include "dbus-indicate-client.h" @@ -76,6 +77,12 @@ indicate_listener_class_init (IndicateListenerClass * class) G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); */ + dbus_g_object_register_marshaller(indicate_listener_marshal_VOID__UINT_STRING, + G_TYPE_NONE, + G_TYPE_UINT, + G_TYPE_STRING, + G_TYPE_INVALID); + return; } @@ -255,6 +262,7 @@ todo_idle (gpointer data) IndicateListener * listener = INDICATE_LISTENER(data); if (listener == NULL) { g_error("Listener got lost in todo_idle"); + listener->todo_idle = 0; return FALSE; } @@ -262,6 +270,7 @@ todo_idle (gpointer data) /* Basically if we have no todo, we need to stop running. This * is done this way to make the function error handling simpler * and results in an extra run */ + listener->todo_idle = 0; return FALSE; } -- cgit v1.2.3 From fb5b3301a2b7dcb9239c1c19a6134e2999e04007 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 20:10:38 -0600 Subject: Now correctly calling the get indicators function to get the indicators on already created objects. --- libindicate/listener.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libindicate/listener.c b/libindicate/listener.c index a26ddcc..1087945 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -42,6 +42,7 @@ static void build_todo_list_cb (DBusGProxy * proxy, char ** names, GError * erro static void todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListener * listener); static gboolean todo_idle (gpointer data); static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt); +static void proxy_get_indicator_list (DBusGProxy * proxy, GArray * indicators, GError * error, gpointer data); /* Code */ static void @@ -296,9 +297,27 @@ todo_idle (gpointer data) dbus_g_proxy_connect_signal(proxyt->proxy, "IndicatorAdded", G_CALLBACK(proxy_indicator_added), proxyt, NULL); + org_freedesktop_indicator_get_indicator_list_async(proxyt->proxy, proxy_get_indicator_list, proxyt); return TRUE; } +static void +proxy_get_indicator_list (DBusGProxy * proxy, GArray * indicators, GError * error, gpointer data) +{ + if (error != NULL) { + return; + } + + proxy_t * proxyt = (proxy_t *)data; + + int i; + for (i = 0; i < indicators->len; i++) { + g_debug("Interface %s has an indicator %d", proxyt->name, g_array_index(indicators, guint, i)); + } + + return; +} + static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt) { -- cgit v1.2.3 From 0ff11650f31a7d76e2ad8cd6c951e3e2321089f8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 20:34:39 -0600 Subject: Get the type of the list of indicators that we got, and then set the up to register --- libindicate/listener.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/libindicate/listener.c b/libindicate/listener.c index 1087945..9ca8512 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -43,6 +43,7 @@ static void todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListe static gboolean todo_idle (gpointer data); static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt); static void proxy_get_indicator_list (DBusGProxy * proxy, GArray * indicators, GError * error, gpointer data); +static void proxy_get_indicator_type (DBusGProxy * proxy, gchar * type, GError * error, gpointer data); /* Code */ static void @@ -301,6 +302,11 @@ todo_idle (gpointer data) return TRUE; } +typedef struct { + guint id; + proxy_t * proxyt; +} indicator_type_t; + static void proxy_get_indicator_list (DBusGProxy * proxy, GArray * indicators, GError * error, gpointer data) { @@ -312,15 +318,36 @@ proxy_get_indicator_list (DBusGProxy * proxy, GArray * indicators, GError * erro int i; for (i = 0; i < indicators->len; i++) { - g_debug("Interface %s has an indicator %d", proxyt->name, g_array_index(indicators, guint, i)); + indicator_type_t * itt = g_new(indicator_type_t, 1); + itt->id = g_array_index(indicators, guint, i); + itt->proxyt = proxyt; + + org_freedesktop_indicator_get_indicator_property_async(proxyt->proxy, itt->id, "type", proxy_get_indicator_type, itt); } return; } +static void +proxy_get_indicator_type (DBusGProxy * proxy, gchar * type, GError * error, gpointer data) +{ + if (error != NULL) { + g_warning("Get Indicator Type returned error: %s", error->message); + return; + } + + indicator_type_t * itt = (indicator_type_t *)data; + guint id = itt->id; + proxy_t * proxyt = itt->proxyt; + + g_free(itt); + + return proxy_indicator_added(proxy, id, type, proxyt); +} + static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt) { - g_debug("Interface %s has an indicator %d", proxyt->name, id); + g_debug("Interface %s has an indicator %d of type %s", proxyt->name, id, type); return; } -- cgit v1.2.3 From 2722037935bb34848b71128776b997c6c158ff8e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 21:49:28 -0600 Subject: Okay, adding the other signals in and keeping track of the indicators that are hanging around. Now, to connect to things external. --- libindicate/listener.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++--- libindicate/listener.h | 4 +- 2 files changed, 112 insertions(+), 7 deletions(-) diff --git a/libindicate/listener.c b/libindicate/listener.c index 9ca8512..70ba8f4 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -25,6 +25,7 @@ typedef struct { DBusGProxy * proxy; gchar * name; IndicateListener * listener; + GHashTable * indicators; } proxy_t; typedef struct { @@ -42,8 +43,11 @@ static void build_todo_list_cb (DBusGProxy * proxy, char ** names, GError * erro static void todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListener * listener); static gboolean todo_idle (gpointer data); static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt); +static void proxy_indicator_removed (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt); +static void proxy_indicator_modified (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt); static void proxy_get_indicator_list (DBusGProxy * proxy, GArray * indicators, GError * error, gpointer data); static void proxy_get_indicator_type (DBusGProxy * proxy, gchar * type, GError * error, gpointer data); +static void proxy_indicators_free (gpointer data); /* Code */ static void @@ -145,10 +149,9 @@ indicate_listener_init (IndicateListener * listener) 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); + listener->proxies_working = g_hash_table_new(g_str_hash, g_str_equal); + listener->proxies_possible = g_hash_table_new(g_str_hash, g_str_equal); + /* 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)); listener->todo_idle = 0; @@ -208,7 +211,10 @@ 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 + g_free(proxy_data->name); + + /* TODO: Clear the indicators by signaling */ + /* TODO: Remove from the appropriate listener hash */ return; } @@ -285,6 +291,7 @@ todo_idle (gpointer data) "/org/freedesktop/indicate", "org.freedesktop.indicator"); proxyt->listener = listener; + proxyt->indicators = NULL; listener->proxy_todo = g_array_remove_index(listener->proxy_todo, listener->proxy_todo->len - 1); @@ -299,6 +306,9 @@ todo_idle (gpointer data) G_CALLBACK(proxy_indicator_added), proxyt, NULL); org_freedesktop_indicator_get_indicator_list_async(proxyt->proxy, proxy_get_indicator_list, proxyt); + + g_hash_table_insert(listener->proxies_possible, proxyt->name, proxyt); + return TRUE; } @@ -349,5 +359,100 @@ static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt) { g_debug("Interface %s has an indicator %d of type %s", proxyt->name, id, type); + + if (proxyt->indicators == NULL) { + proxyt->indicators = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, proxy_indicators_free); + /* Elevate to working */ + g_hash_table_remove(proxyt->listener->proxies_possible, proxyt->name); + g_hash_table_insert(proxyt->listener->proxies_working, proxyt->name, proxyt); + + dbus_g_proxy_add_signal(proxyt->proxy, "IndicatorRemoved", + G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(proxyt->proxy, "IndicatorRemoved", + G_CALLBACK(proxy_indicator_removed), proxyt, NULL); + dbus_g_proxy_add_signal(proxyt->proxy, "IndicatorModified", + G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(proxyt->proxy, "IndicatorModified", + G_CALLBACK(proxy_indicator_modified), proxyt, NULL); + + /* TODO: Send signal */ + } + + GHashTable * indicators = g_hash_table_lookup(proxyt->indicators, type); + + if (indicators == NULL) { + indicators = g_hash_table_new(g_direct_hash, g_direct_equal); + g_hash_table_insert(proxyt->indicators, g_strdup(type), indicators); + } + + if (g_hash_table_lookup(indicators, (gpointer)id)) { + g_hash_table_insert(indicators, (gpointer)id, TRUE); + /* TODO: Send signal */ + } + + return; +} + +static void +proxy_indicator_removed (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt) +{ + if (proxyt->indicators == NULL) { + g_warning("Oddly we had an indicator removed from an interface that we didn't think had indicators."); + return; + } + + GHashTable * indicators = g_hash_table_lookup(proxyt->indicators, type); + if (indicators == NULL) { + g_warning("Can not remove indicator %d of type '%s' as there are no indicators of that type on %s.", id, type, proxyt->name); + return; + } + + if (!g_hash_table_lookup(indicators, (gpointer)id)) { + g_warning("No indicator %d of type '%s' on '%s'.", id, type, proxyt->name); + return; + } + + g_hash_table_remove(indicators, (gpointer)id); + + /* TODO: Signal here */ + + return; +} + +static void +proxy_indicator_modified (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt) +{ + if (proxyt->indicators == NULL) { + g_warning("Oddly we had an indicator modified from an interface that we didn't think had indicators."); + return; + } + + GHashTable * indicators = g_hash_table_lookup(proxyt->indicators, type); + if (indicators == NULL) { + g_warning("Can not modify indicator %d of type '%s' as there are no indicators of that type on %s.", id, type, proxyt->name); + return; + } + + if (!g_hash_table_lookup(indicators, (gpointer)id)) { + g_warning("No indicator %d of type '%s' on '%s'.", id, type, proxyt->name); + return; + } + + /* TODO: Signal here */ + + return; +} + +static void +proxy_indicators_free (gpointer data) +{ + GHashTable * table = (GHashTable *)data; + + if (g_hash_table_size(table) != 0) { + g_warning("Clearning a set of indicators that wasn't signaled!"); + } + + g_hash_table_unref(table); return; } diff --git a/libindicate/listener.h b/libindicate/listener.h index b86c8a3..5c482ba 100644 --- a/libindicate/listener.h +++ b/libindicate/listener.h @@ -30,8 +30,8 @@ struct _IndicateListener { DBusGProxy * dbus_proxy_session; DBusGProxy * dbus_proxy_system; - GHashTable * proxies_session; - GHashTable * proxies_system; + GHashTable * proxies_working; + GHashTable * proxies_possible; GArray * proxy_todo; guint todo_idle; -- cgit v1.2.3 From 0d1e01e34d94b47b8785cac9138f529c1fcc55b9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 23:01:16 -0600 Subject: Getting the signals in shape --- libindicate/listener-marshal.list | 4 ++++ libindicate/listener.c | 44 +++++++++++++++++++++++++-------------- libindicate/listener.h | 14 +++++++------ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/libindicate/listener-marshal.list b/libindicate/listener-marshal.list index c02c70f..562d06f 100644 --- a/libindicate/listener-marshal.list +++ b/libindicate/listener-marshal.list @@ -1,2 +1,6 @@ # IndicatorAdded, IndicatorRemoved, IndicatorModified VOID:UINT,STRING +# Local indicator_added, indicator_removed +VOID:POINTER,POINTER,STRING +# Local indicator_modified +VOID:POINTER,POINTER,STRING,STRING diff --git a/libindicate/listener.c b/libindicate/listener.c index 70ba8f4..75c7649 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -59,29 +59,41 @@ indicate_listener_class_init (IndicateListenerClass * class) gobj->finalize = indicate_listener_finalize; -/* TODO, I need new marshallers here, bah humbug signals[INDICATOR_ADDED] = g_signal_new("indicator-added", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (IndicateListenerClass, indicator_added), NULL, NULL, - g_cclosure_marshal_VOID__POINTER_POINTER_POINTER, - G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_OBJECT, G_TYPE_STRING); + indicate_listener_marshal_VOID__POINTER_POINTER_STRING, + G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING); signals[INDICATOR_REMOVED] = g_signal_new("indicator-removed", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IndicateServerClass, indicator_removed), + G_STRUCT_OFFSET (IndicateListenerClass, indicator_removed), NULL, NULL, - g_cclosure_marshal_VOID__UINT_POINTER, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); + indicate_listener_marshal_VOID__POINTER_POINTER_STRING, + G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING); signals[INDICATOR_MODIFIED] = g_signal_new("indicator-modified", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (IndicateServerClass, indicator_modified), + G_STRUCT_OFFSET (IndicateListenerClass, indicator_modified), NULL, NULL, - g_cclosure_marshal_VOID__UINT_POINTER, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); -*/ + indicate_listener_marshal_VOID__POINTER_POINTER_STRING_STRING, + G_TYPE_NONE, 4, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING); + signals[SERVER_ADDED] = g_signal_new("server-added", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IndicateListenerClass, server_added), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); + signals[SERVER_REMOVED] = g_signal_new("server-removed", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IndicateListenerClass, server_removed), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); dbus_g_object_register_marshaller(indicate_listener_marshal_VOID__UINT_STRING, G_TYPE_NONE, @@ -376,7 +388,7 @@ proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t dbus_g_proxy_connect_signal(proxyt->proxy, "IndicatorModified", G_CALLBACK(proxy_indicator_modified), proxyt, NULL); - /* TODO: Send signal */ + g_signal_emit(proxyt->listener, signals[SERVER_ADDED], 0, proxyt->name, TRUE); } GHashTable * indicators = g_hash_table_lookup(proxyt->indicators, type); @@ -387,8 +399,8 @@ proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t } if (g_hash_table_lookup(indicators, (gpointer)id)) { - g_hash_table_insert(indicators, (gpointer)id, TRUE); - /* TODO: Send signal */ + g_hash_table_insert(indicators, (gpointer)id, (gpointer)TRUE); + g_signal_emit(proxyt->listener, signals[INDICATOR_ADDED], 0, proxyt->name, id, type, TRUE); } return; @@ -414,8 +426,7 @@ proxy_indicator_removed (DBusGProxy * proxy, guint id, const gchar * type, proxy } g_hash_table_remove(indicators, (gpointer)id); - - /* TODO: Signal here */ + g_signal_emit(proxyt->listener, signals[INDICATOR_REMOVED], 0, proxyt->name, id, type, TRUE); return; } @@ -428,6 +439,7 @@ proxy_indicator_modified (DBusGProxy * proxy, guint id, const gchar * type, prox return; } + // TODO: Search for the ID to discover the type GHashTable * indicators = g_hash_table_lookup(proxyt->indicators, type); if (indicators == NULL) { g_warning("Can not modify indicator %d of type '%s' as there are no indicators of that type on %s.", id, type, proxyt->name); @@ -439,7 +451,7 @@ proxy_indicator_modified (DBusGProxy * proxy, guint id, const gchar * type, prox return; } - /* TODO: Signal here */ + g_signal_emit(proxyt->listener, signals[INDICATOR_MODIFIED], 0, proxyt->name, id, type, type, TRUE); return; } diff --git a/libindicate/listener.h b/libindicate/listener.h index 5c482ba..c40bc07 100644 --- a/libindicate/listener.h +++ b/libindicate/listener.h @@ -20,6 +20,9 @@ G_BEGIN_DECLS #define INDICATE_IS_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), INDICATE_TYPE_LISTENER)) #define INDICATE_LISTENER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), INDICATE_TYPE_LISTENER, IndicateListenerClass)) +typedef gchar IndicateListenerServer; +typedef guint IndicateListenerIndicator; + typedef struct _IndicateListener IndicateListener; struct _IndicateListener { GObject parent; @@ -42,13 +45,12 @@ struct _IndicateListenerClass { GObjectClass parent; /* Signals */ - void (* indicator_added) (IndicateServer * server, IndicateIndicator * indicator, gchar * type); - void (* indicator_removed) (IndicateServer * server, IndicateIndicator * indicator, gchar * type); - void (* indicator_modified) (IndicateServer * server, IndicateIndicator * indicator, gchar * property); - - void (* server_added) (IndicateServer * server); - void (* server_removed) (IndicateServer * server); + void (* indicator_added) (IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type); + void (* indicator_removed) (IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type); + void (* indicator_modified) (IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property); + void (* server_added) (IndicateListenerServer * server); + void (* server_removed) (IndicateListenerServer * server); }; GType indicate_listener_get_type (void) G_GNUC_CONST; -- cgit v1.2.3 From fe3addbe95bcd54af249b315ee8d10be71005be8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 23:11:56 -0600 Subject: Changing the test to do the printing by itself instead of using the debug messages in the class itself --- libindicate/listener.c | 10 +++++----- libindicate/tests/listen-and-print.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/libindicate/listener.c b/libindicate/listener.c index 75c7649..2c1f3b3 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -53,7 +53,7 @@ static void proxy_indicators_free (gpointer data); static void indicate_listener_class_init (IndicateListenerClass * class) { - g_debug("Listener Class Initialized"); + /* g_debug("Listener Class Initialized"); */ GObjectClass * gobj; gobj = G_OBJECT_CLASS(class); @@ -107,7 +107,7 @@ indicate_listener_class_init (IndicateListenerClass * class) static void indicate_listener_init (IndicateListener * listener) { - g_debug("Listener Object Initialized"); + /* g_debug("Listener Object Initialized"); */ GError *error = NULL; /* Get the buses */ @@ -208,7 +208,7 @@ dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, c bus_name = "session"; } - g_debug("Name change on %s bus: '%s' from '%s' to '%s'", bus_name, name, prev, new); + /* g_debug("Name change on %s bus: '%s' from '%s' to '%s'", bus_name, name, prev, new); */ if (prev != NULL && prev[0] == '\0') { todo_list_add(name, proxy, listener); @@ -261,7 +261,7 @@ todo_list_add (const gchar * name, DBusGProxy * proxy, IndicateListener * listen bus = listener->session_bus; bus_name = "session"; } - g_debug ("Adding on %s bus: %s", bus_name, name); + /* g_debug ("Adding on %s bus: %s", bus_name, name); */ proxy_todo_t todo; todo.name = g_strdup(name); @@ -370,7 +370,7 @@ proxy_get_indicator_type (DBusGProxy * proxy, gchar * type, GError * error, gpoi static void proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t * proxyt) { - g_debug("Interface %s has an indicator %d of type %s", proxyt->name, id, type); + /* g_debug("Interface %s has an indicator %d of type %s", proxyt->name, id, type); */ if (proxyt->indicators == NULL) { proxyt->indicators = g_hash_table_new_full(g_str_hash, g_str_equal, diff --git a/libindicate/tests/listen-and-print.c b/libindicate/tests/listen-and-print.c index 772e4f1..381fdf2 100644 --- a/libindicate/tests/listen-and-print.c +++ b/libindicate/tests/listen-and-print.c @@ -2,6 +2,35 @@ #include #include "libindicate/listener.h" +static void +indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + g_debug("Indicator Added: %s %d %s", (gchar *)server, (guint)*indicator, type); +} + +static void +indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + g_debug("Indicator Removed: %s %d %s", (gchar *)server, (guint)*indicator, type); +} + +static void +indicator_modified (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property, gpointer data) +{ + g_debug("Indicator Modified: %s %d %s %s", (gchar *)server, (guint)*indicator, type, property); +} + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gpointer data) +{ + g_debug("Indicator Server Added: %s", (gchar *)server); +} + +static void +server_removed (IndicateListener * listener, IndicateListenerServer * server, gpointer data) +{ + g_debug("Indicator Server Removed: %s", (gchar *)server); +} int main (int argc, char ** argv) @@ -10,6 +39,12 @@ main (int argc, char ** argv) IndicateListener * listener = indicate_listener_new(); + g_signal_connect(listener, "indicator-added", G_CALLBACK(indicator_added), NULL); + g_signal_connect(listener, "indicator-removed", G_CALLBACK(indicator_removed), NULL); + g_signal_connect(listener, "indicator-modified", G_CALLBACK(indicator_modified), NULL); + g_signal_connect(listener, "server-added", G_CALLBACK(server_added), NULL); + g_signal_connect(listener, "server-removed", G_CALLBACK(server_removed), NULL); + g_main_loop_run(g_main_loop_new(NULL, FALSE)); return 0; -- cgit v1.2.3 From ad1cc2dcd28d83bd83ac7ad8f5d97f70546ea900 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Jan 2009 23:19:21 -0600 Subject: Fixing the printing and the saving of indicators. --- libindicate/listener.c | 2 +- libindicate/tests/listen-and-print.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libindicate/listener.c b/libindicate/listener.c index 2c1f3b3..5baa36f 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -398,7 +398,7 @@ proxy_indicator_added (DBusGProxy * proxy, guint id, const gchar * type, proxy_t g_hash_table_insert(proxyt->indicators, g_strdup(type), indicators); } - if (g_hash_table_lookup(indicators, (gpointer)id)) { + if (!g_hash_table_lookup(indicators, (gpointer)id)) { g_hash_table_insert(indicators, (gpointer)id, (gpointer)TRUE); g_signal_emit(proxyt->listener, signals[INDICATOR_ADDED], 0, proxyt->name, id, type, TRUE); } diff --git a/libindicate/tests/listen-and-print.c b/libindicate/tests/listen-and-print.c index 381fdf2..9ad2cc8 100644 --- a/libindicate/tests/listen-and-print.c +++ b/libindicate/tests/listen-and-print.c @@ -5,19 +5,19 @@ static void indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) { - g_debug("Indicator Added: %s %d %s", (gchar *)server, (guint)*indicator, type); + g_debug("Indicator Added: %s %d %s", (gchar *)server, (guint)indicator, type); } static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) { - g_debug("Indicator Removed: %s %d %s", (gchar *)server, (guint)*indicator, type); + g_debug("Indicator Removed: %s %d %s", (gchar *)server, (guint)indicator, type); } static void indicator_modified (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property, gpointer data) { - g_debug("Indicator Modified: %s %d %s %s", (gchar *)server, (guint)*indicator, type, property); + g_debug("Indicator Modified: %s %d %s %s", (gchar *)server, (guint)indicator, type, property); } static void -- cgit v1.2.3 From df1713a31e272324244419c0b7b6fbf9b3179069 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 16 Jan 2009 00:01:50 -0600 Subject: Handling the case that we're destroying an entry because the bus told us to. Properly signalling all of the removals --- libindicate/listener.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/libindicate/listener.c b/libindicate/listener.c index 5baa36f..bf613d6 100644 --- a/libindicate/listener.c +++ b/libindicate/listener.c @@ -213,20 +213,60 @@ dbus_owner_change (DBusGProxy * proxy, const gchar * name, const gchar * prev, c if (prev != NULL && prev[0] == '\0') { todo_list_add(name, proxy, listener); } + if (new != NULL && new[0] == '\0') { + proxy_t * proxyt; + proxyt = g_hash_table_lookup(listener->proxies_working, name); + if (proxyt != NULL) { + g_hash_table_remove(listener->proxies_working, name); + proxy_struct_destroy(proxyt); + } + proxyt = g_hash_table_lookup(listener->proxies_possible, name); + if (proxyt != NULL) { + g_hash_table_remove(listener->proxies_possible, name); + proxy_struct_destroy(proxyt); + } + } return; } static void -proxy_struct_destroy (gpointer data) +proxy_struct_destroy_indicators (gpointer key, gpointer value, gpointer data) { + gchar * type = (gchar *)key; + GHashTable * indicators = (GHashTable *)value; proxy_t * proxy_data = data; - g_object_unref(proxy_data->proxy); - g_free(proxy_data->name); + GList * keys = g_hash_table_get_keys(indicators); + GList * indicator; + for (indicator = keys; indicator != NULL; indicator = indicator->next) { + guint id = (guint)indicator->data; + g_signal_emit(proxy_data->listener, signals[INDICATOR_REMOVED], 0, proxy_data->name, id, type, TRUE); + } + g_list_free(keys); + + g_hash_table_remove_all(indicators); + return; +} + +static void +proxy_struct_destroy (gpointer data) +{ + proxy_t * proxy_data = data; /* TODO: Clear the indicators by signaling */ - /* TODO: Remove from the appropriate listener hash */ + if (proxy_data->indicators != NULL) { + g_hash_table_foreach(proxy_data->indicators, + proxy_struct_destroy_indicators, + proxy_data); + g_hash_table_remove_all(proxy_data->indicators); + + g_signal_emit(proxy_data->listener, signals[SERVER_REMOVED], 0, proxy_data->name, TRUE); + proxy_data->indicators = NULL; + } + + g_free(proxy_data->name); + g_free(proxy_data); return; } -- cgit v1.2.3