+static void
+add_event (const char *bus_name, const char *event)
+{
+ event_data *evdata;
+ gchar **data;
+ GList *new_list;
+
+ evdata = (event_data *) g_malloc (sizeof (*evdata));
+ if (!evdata)
+ return;
+ data = g_strsplit (event, ":", 3);
+ if (!data)
+ {
+ g_free (evdata);
+ return;
+ }
+ evdata->bus_name = g_strdup (bus_name);
+ evdata->data = data;
+ new_list = g_list_append (spi_global_app_data->events, evdata);
+ if (new_list)
+ spi_global_app_data->events = new_list;
+}
+
+static void
+get_registered_event_listeners (SpiBridge *app)
+{
+ DBusMessage *message, *reply;
+ DBusMessageIter iter, iter_array, iter_struct;
+
+ message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
+ SPI_DBUS_PATH_REGISTRY,
+ SPI_DBUS_INTERFACE_REGISTRY,
+ "GetRegisteredEvents");
+ spi_global_app_data->events_initialized = TRUE;
+ if (!message)
+ return;
+
+ reply = dbus_connection_send_with_reply_and_block (app->bus, message, 5000, NULL);
+ dbus_message_unref (message);
+ if (!reply)
+ return;
+ if (strcmp (dbus_message_get_signature (reply), "a(ss)") != 0)
+ {
+ /* TODO: Add a warning when it's okay to add strings */
+ dbus_message_unref (reply);
+ return;
+ }
+ dbus_message_iter_init (reply, &iter);
+ dbus_message_iter_recurse (&iter, &iter_array);
+ /* TODO: This is bad. Need to determine that the array is non-empty,
+ so that we don't initially read a value rom it in that case, but using
+ a deprecated function. */
+ if (dbus_message_iter_get_array_len (&iter_array) > 0) do
+ {
+ char *bus_name, *event;
+ dbus_message_iter_recurse (&iter_array, &iter_struct);
+ dbus_message_iter_get_basic (&iter_struct, &bus_name);
+ dbus_message_iter_next (&iter_struct);
+ dbus_message_iter_get_basic (&iter_struct, &event);
+ add_event (bus_name, event);
+ }
+ while (dbus_message_iter_next (&iter_array));
+ dbus_message_unref (reply);
+}
+
+static void
+register_reply (DBusPendingCall *pending, void *user_data)
+{
+ DBusMessage *reply;
+ SpiBridge *app = user_data;
+ DBusMessage *message;
+
+ reply = dbus_pending_call_steal_reply (pending);
+ if (reply)
+ {
+ gchar *app_name, *obj_path;
+
+ if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
+ {
+ g_warning ("AT-SPI: Could not obtain desktop path or name\n");
+printf("sig: %s\n", dbus_message_get_signature(reply));
+ }
+ else
+ {
+ DBusMessageIter iter, iter_struct;
+ dbus_message_iter_init (reply, &iter);
+ dbus_message_iter_recurse (&iter, &iter_struct);
+ dbus_message_iter_get_basic (&iter_struct, &app_name);
+ dbus_message_iter_next (&iter_struct);
+ dbus_message_iter_get_basic (&iter_struct, &obj_path);
+
+ app->desktop_name = g_strdup (app_name);
+ app->desktop_path = g_strdup (obj_path);
+ }
+ }
+ else
+ {
+ g_warning ("AT-SPI: Could not embed inside desktop");
+ return;
+ }
+ dbus_message_unref (reply);
+
+ get_registered_event_listeners (spi_global_app_data);
+}
+