+static gchar *
+introspect_children_cb (const char *path, void *data)
+{
+ if (!strcmp (path, "/org/a11y/atspi/accessible"))
+ {
+ return g_strdup ("<node name=\"root\"/>\n");
+ /* TODO: Should we place the whole hierarchy here? */
+ }
+ return NULL;
+}
+
+static void
+handle_event_listener_registered (DBusConnection *bus, DBusMessage *message,
+ void *user_data)
+{
+ const char *name;
+ char *sender;
+
+ if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
+ DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
+ return;
+
+ add_event (sender, name);
+}
+
+static void
+remove_events (const char *bus_name, const char *event)
+{
+ event_data *evdata;
+ gchar **remove_data;
+ GList *list;
+
+ remove_data = g_strsplit (event, ":", 3);
+ if (!remove_data)
+ {
+ return;
+ }
+
+ for (list = spi_global_app_data->events; list;)
+ {
+ event_data *evdata = list->data;
+ if (!g_strcmp0 (evdata->bus_name, bus_name) &&
+ spi_event_is_subtype (evdata->data, remove_data))
+ {
+ GList *events = spi_global_app_data->events;
+ list = list->next;
+ g_strfreev (evdata->data);
+ g_free (evdata->bus_name);
+ g_free (evdata);
+ spi_global_app_data->events = g_list_remove (events, evdata);
+ }
+ else
+ {
+ list = list->next;
+ }
+ }
+}
+
+static void
+handle_event_listener_deregistered (DBusConnection *bus, DBusMessage *message,
+ void *user_data)
+{
+ const char *orig_name;
+ gchar *name;
+ char *sender;
+
+ if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
+ DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
+ return;
+
+ remove_events (sender, name);
+}
+
+static DBusHandlerResult
+signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ const char *interface = dbus_message_get_interface (message);
+ const char *member = dbus_message_get_member (message);
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (!strcmp (interface, SPI_DBUS_INTERFACE_REGISTRY))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "EventListenerRegistered"))
+ handle_event_listener_registered (bus, message, user_data);
+ else if (!strcmp (member, "EventListenerDeregistered"))
+ handle_event_listener_deregistered (bus, message, user_data);
+ else
+ result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ return result;
+}
+