2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * Basic SPI initialization and event loop function prototypes
30 #include "atspi-private.h"
35 static DBusConnection *bus = NULL;
36 static GHashTable *apps = NULL;
37 static GHashTable *live_refs = NULL;
38 static GQueue *exception_handlers = NULL;
39 static DBusError exception;
41 const char *atspi_path_dec = ATSPI_DBUS_PATH_DEC;
42 const char *atspi_path_registry = ATSPI_DBUS_PATH_REGISTRY;
43 const char *atspi_path_root = ATSPI_DBUS_PATH_ROOT;
44 const char *atspi_bus_registry = ATSPI_DBUS_NAME_REGISTRY;
45 const char *atspi_interface_accessible = ATSPI_DBUS_INTERFACE_ACCESSIBLE;
46 const char *atspi_interface_action = ATSPI_DBUS_INTERFACE_ACTION;
47 const char *atspi_interface_application = ATSPI_DBUS_INTERFACE_APPLICATION;
48 const char *atspi_interface_component = ATSPI_DBUS_INTERFACE_COMPONENT;
49 const char *atspi_interface_dec = ATSPI_DBUS_INTERFACE_DEC;
50 const char *atspi_interface_device_event_listener = ATSPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER;
51 const char *atspi_interface_document = ATSPI_DBUS_INTERFACE_DOCUMENT;
52 const char *atspi_interface_editable_text = ATSPI_DBUS_INTERFACE_EDITABLE_TEXT;
53 const char *atspi_interface_event_object = ATSPI_DBUS_INTERFACE_EVENT_OBJECT;
54 const char *atspi_interface_hyperlink = ATSPI_DBUS_INTERFACE_HYPERLINK;
55 const char *atspi_interface_hypertext = ATSPI_DBUS_INTERFACE_HYPERTEXT;
56 const char *atspi_interface_image = ATSPI_DBUS_INTERFACE_IMAGE;
57 const char *atspi_interface_registry = ATSPI_DBUS_INTERFACE_REGISTRY;
58 const char *atspi_interface_selection = ATSPI_DBUS_INTERFACE_SELECTION;
59 const char *atspi_interface_table = ATSPI_DBUS_INTERFACE_TABLE;
60 const char *atspi_interface_text = ATSPI_DBUS_INTERFACE_TEXT;
61 const char *atspi_interface_cache = ATSPI_DBUS_INTERFACE_CACHE;
62 const char *atspi_interface_value = ATSPI_DBUS_INTERFACE_VALUE;
64 static const char *interfaces[] =
66 ATSPI_DBUS_INTERFACE_ACCESSIBLE,
67 ATSPI_DBUS_INTERFACE_ACTION,
68 ATSPI_DBUS_INTERFACE_APPLICATION,
69 ATSPI_DBUS_INTERFACE_COLLECTION,
70 ATSPI_DBUS_INTERFACE_COMPONENT,
71 ATSPI_DBUS_INTERFACE_DOCUMENT,
72 ATSPI_DBUS_INTERFACE_EDITABLE_TEXT,
73 ATSPI_DBUS_INTERFACE_HYPERLINK,
74 ATSPI_DBUS_INTERFACE_HYPERTEXT,
75 ATSPI_DBUS_INTERFACE_IMAGE,
76 "org.a11y.atspi.LoginHelper",
77 ATSPI_DBUS_INTERFACE_SELECTION,
78 ATSPI_DBUS_INTERFACE_TABLE,
79 ATSPI_DBUS_INTERFACE_TEXT,
80 ATSPI_DBUS_INTERFACE_VALUE,
85 _atspi_get_iface_num (const char *iface)
87 /* TODO: Use a binary search or hash to improve performance */
90 for (i = 0; interfaces[i]; i++)
92 if (!strcmp(iface, interfaces[i])) return i;
102 live_refs = g_hash_table_new (g_direct_hash, g_direct_equal);
107 /* TODO: Add an application parameter */
116 #define APP_IS_REGISTRY(app) (!strcmp (app->bus_name, atspi_bus_registry))
127 g_hash_table_destroy (refs);
131 static gboolean atspi_inited = FALSE;
133 static GHashTable *app_hash = NULL;
135 static AtspiApplication *
136 get_application (const char *bus_name)
138 AtspiApplication *app = NULL;
143 app_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_hash_table_unref);
144 if (!app_hash) return NULL;
146 app = g_hash_table_lookup (app_hash, bus_name);
148 bus_name_dup = g_strdup (bus_name);
149 if (!bus_name_dup) return NULL;
150 // TODO: change below to something that will send state-change:defunct notification if necessary */
151 app = _atspi_application_new (bus_name);
152 if (!app) return NULL;
153 app->bus_name = bus_name_dup;
154 app->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
155 g_hash_table_insert (app_hash, bus_name_dup, app);
159 static AtspiAccessible *
160 ref_accessible (const char *app_name, const char *path)
162 AtspiApplication *app = get_application (app_name);
165 if (!strcmp (path, ATSPI_DBUS_PATH_NULL))
168 if (!strcmp (path, "/org/a11y/atspi/accessible/root"))
172 app->root = atspi_accessible_new (app, atspi_path_root);
173 app->root->accessible_parent = atspi_get_desktop (0);
175 return g_object_ref (app->root);
178 a = g_hash_table_lookup (app->hash, path);
181 return g_object_ref (a);
183 a = atspi_accessible_new (app, path);
186 g_hash_table_insert (app->hash, a->path, a);
187 g_object_ref (a); /* for the hash */
200 GArray *state_bitflags;
203 static DBusHandlerResult
204 handle_remove_accessible (DBusConnection *bus, DBusMessage *message, void *user_data)
206 const char *sender = dbus_message_get_sender (message);
207 AtspiApplication *app;
209 DBusMessageIter iter, iter_struct;
210 const char *signature = dbus_message_get_signature (message);
214 if (strcmp (signature, "(so)") != 0)
216 g_warning ("at-spi: Unknown signature %s for RemoveAccessible", signature);
217 return DBUS_HANDLER_RESULT_HANDLED;
220 dbus_message_iter_init (message, &iter);
221 dbus_message_iter_recurse (&iter, &iter_struct);
222 dbus_message_iter_get_basic (&iter_struct, &sender);
223 dbus_message_iter_get_basic (&iter_struct, &path);
224 app = get_application (sender);
225 a = ref_accessible (sender, path);
227 return DBUS_HANDLER_RESULT_HANDLED;
228 if (a->accessible_parent && g_list_find (a->accessible_parent->children, a))
230 a->accessible_parent->children = g_list_remove (a->accessible_parent->children, a);
233 g_hash_table_remove (app->hash, app->bus_name);
234 g_object_unref (a); /* unref our own ref */
235 return DBUS_HANDLER_RESULT_HANDLED;
239 add_app_to_desktop (AtspiAccessible *a, const char *bus_name)
244 dbus_error_init (&error);
245 AtspiAccessible *obj = ref_accessible (bus_name, atspi_path_root);
248 GList *new_list = g_list_append (a->children, obj);
251 a->children = new_list;
257 g_warning ("Error calling getRoot for %s: %s", bus_name, error.message);
263 send_children_changed (AtspiAccessible *parent, AtspiAccessible *child, gboolean add)
267 memset (&e, 0, sizeof (e));
268 e.type = (add? "object:children-changed:add": "object:children-changed:remove");
270 e.detail1 = g_list_index (parent->children, child);
272 _atspi_send_event (&e);
276 unref_object_and_descendants (AtspiAccessible *obj)
280 for (l = obj->children; l; l = l->next)
282 unref_object_and_descendants (l->data);
284 g_object_unref (obj);
288 remove_app_from_desktop (AtspiAccessible *a, const char *bus_name)
291 AtspiAccessible *child;
293 for (l = a->children; l; l = l->next)
296 if (!strcmp (bus_name, child->app->bus_name)) break;
300 g_warning ("Removing unregistered app %s; doing nothing\n", bus_name);
303 send_children_changed (a, child, FALSE);
304 a->children = g_list_remove (a->children, child);
305 unref_object_and_descendants (child);
309 static AtspiAccessible *desktop;
312 get_reference_from_iter (DBusMessageIter *iter, const char **app_name, const char **path)
314 DBusMessageIter iter_struct;
316 dbus_message_iter_recurse (iter, &iter_struct);
317 dbus_message_iter_get_basic (&iter_struct, app_name);
318 dbus_message_iter_next (&iter_struct);
319 dbus_message_iter_get_basic (&iter_struct, path);
320 dbus_message_iter_next (iter);
324 add_accessible_from_iter (DBusMessageIter *iter)
328 DBusMessageIter iter_struct, iter_array;
329 const char *app_name, *path;
330 AtspiApplication *app;
331 AtspiAccessible *accessible;
332 const char *name, *description;
334 dbus_uint32_t *states;
337 dbus_message_iter_recurse (iter, &iter_struct);
340 get_reference_from_iter (&iter_struct, &app_name, &path);
341 accessible = ref_accessible (app_name, path);
345 /* Get application: TODO */
346 dbus_message_iter_next (&iter_struct);
349 get_reference_from_iter (&iter_struct, &app_name, &path);
350 accessible->accessible_parent = ref_accessible (app_name, path);
353 dbus_message_iter_recurse (&iter_struct, &iter_array);
354 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
356 AtspiAccessible *child;
357 get_reference_from_iter (&iter_array, &app_name, &path);
358 child = ref_accessible (app_name, path);
359 new_list = g_list_append (accessible->children, child);
360 if (new_list) accessible->children = new_list;
364 accessible->interfaces = 0;
365 dbus_message_iter_next (&iter_struct);
366 dbus_message_iter_recurse (&iter_struct, &iter_array);
367 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
371 dbus_message_iter_get_basic (&iter_array, &iface);
372 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable")) continue;
373 n = _atspi_get_iface_num (iface);
376 g_warning ("Unknown interface %s", iface);
378 else accessible->interfaces |= (1 << n);
379 dbus_message_iter_next (&iter_array);
381 dbus_message_iter_next (&iter_struct);
384 dbus_message_iter_get_basic (&iter_struct, &name);
385 accessible->name = g_strdup (name);
386 dbus_message_iter_next (&iter_struct);
389 dbus_message_iter_get_basic (&iter_struct, &role);
390 accessible->role = role;
391 dbus_message_iter_next (&iter_struct);
394 dbus_message_iter_get_basic (&iter_struct, &description);
395 accessible->description = g_strdup (description);
396 dbus_message_iter_next (&iter_struct);
398 dbus_message_iter_recurse (&iter_struct, &iter_array);
399 dbus_message_iter_get_fixed_array (&iter_array, &states, &count);
402 g_warning ("at-spi: expected 2 values in states array; got %d\n", count);
403 accessible->states = atspi_state_set_new (accessible, 0);
407 guint64 val = ((guint64)states [1]) << 32;
409 accessible->states = atspi_state_set_new (accessible, val);
411 dbus_message_iter_next (&iter_struct);
413 /* This is a bit of a hack since the cache holds a ref, so we don't need
414 * the one provided for us anymore */
415 g_object_unref (accessible);
419 add_accessibles (const char *app_name)
422 DBusMessage *message, *reply;
423 DBusMessageIter iter, iter_array;
425 AtspiApplication *app = get_application (app_name);
426 /* TODO: Move this functionality into app initializer? */
427 dbus_error_init (&error);
428 message = dbus_message_new_method_call (app_name, "/org/a11y/atspi/cache", atspi_interface_cache, "GetItems");
429 reply = _atspi_dbus_send_with_reply_and_block (message);
430 if (!reply || strcmp (dbus_message_get_signature (reply), "a((so)(so)(so)a(so)assusau)") != 0)
432 g_warning ("at-spi: Error in GetItems");
435 dbus_message_unref (reply);
437 dbus_message_iter_init (reply, &iter);
438 dbus_message_iter_recurse (&iter, &iter_array);
439 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
441 add_accessible_from_iter (&iter_array);
442 dbus_message_iter_next (&iter_array);
444 dbus_message_unref (reply);
447 /* TODO: Do we stil need this function? */
448 static AtspiAccessible *
449 ref_accessible_desktop (AtspiApplication *app)
455 DBusMessage *message, *reply;
456 DBusMessageIter iter, iter_array;
460 g_object_ref (desktop);
463 desktop = atspi_accessible_new (app, atspi_path_root);
468 g_hash_table_insert (app->hash, desktop->path, desktop);
469 g_object_ref (desktop); /* for the hash */
470 desktop->name = g_strdup ("main");
471 dbus_error_init (&error);
472 message = dbus_message_new_method_call (atspi_bus_registry,
474 atspi_interface_accessible,
478 reply = _atspi_dbus_send_with_reply_and_block (message);
479 if (!reply || strcmp (dbus_message_get_signature (reply), "a(so)") != 0)
481 g_error ("Couldn't get application list: %s", error.message);
483 dbus_message_unref (reply);
486 dbus_message_iter_init (reply, &iter);
487 dbus_message_iter_recurse (&iter, &iter_array);
488 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
490 const char *app_name, *path;
491 get_reference_from_iter (&iter_array, &app_name, &path);
492 add_accessibles (app_name);
493 add_app_to_desktop (desktop, app_name);
495 dbus_message_unref (reply);
500 _atspi_ref_accessible (const char *app, const char *path)
502 AtspiApplication *a = get_application (app);
504 if ( APP_IS_REGISTRY(a))
506 return ref_accessible_desktop (a);
508 return ref_accessible (app, path);
512 _atspi_dbus_return_accessible_from_message (DBusMessage *message)
514 DBusMessageIter iter;
515 AtspiAccessible *retval = NULL;
516 const char *signature = dbus_message_get_signature (message);
518 if (!strcmp (signature, "(so)"))
520 dbus_message_iter_init (message, &iter);
521 retval = _atspi_dbus_return_accessible_from_iter (&iter);
525 g_warning ("Atspi: Called __atspi_dbus_return_accessible_from_message with strange signature %s", signature);
527 dbus_message_unref (message);
532 _atspi_dbus_return_accessible_from_iter (DBusMessageIter *iter)
534 const char *app_name, *path;
536 get_reference_from_iter (iter, &app_name, &path);
537 return ref_accessible (app_name, path);
540 /* TODO: Remove this function. We should not need it anymore.
541 * If we do, it's a bug.
544 _atspi_ref_related_accessible (AtspiAccessible *obj, const AtspiReference *ref)
546 const char *app = (ref->name && ref->name[0]? ref->name: obj->app->bus_name);
547 return ref_accessible (app, obj->path);
550 const char *cache_signal_type = "((so)(so)(so)a(so)assusau)";
552 static DBusHandlerResult
553 handle_add_accessible (DBusConnection *bus, DBusMessage *message, void *user_data)
555 DBusMessageIter iter;
556 const char *sender = dbus_message_get_sender (message);
557 AtspiApplication *app = get_application (sender);
558 const char *type = cache_signal_type;
560 if (strcmp (dbus_message_get_signature (message), cache_signal_type) != 0)
562 g_warning ("atspi: AddAccessible with unknown signature %s\n", dbus_message_get_signature (message));
566 dbus_message_iter_init (message, &iter);
567 add_accessible_from_iter (&iter);
570 static DBusHandlerResult
571 atspi_dbus_filter (DBusConnection *bus, DBusMessage *message, void *data)
573 int type = dbus_message_get_type (message);
574 const char *interface = dbus_message_get_interface (message);
575 const char *member = dbus_message_get_member (message);
579 if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
580 !strncmp (interface, "org.a11y.atspi.Event.", 21))
582 return atspi_dbus_handle_event (bus, message, data);
584 if (dbus_message_is_method_call (message, atspi_interface_device_event_listener, "notifyEvent"))
586 g_warning ("atspi: TODO: DeviceEvent");
587 //return handle_device_event (bus, message, data);
589 if (dbus_message_is_signal (message, atspi_interface_cache, "AddAccessible"))
591 return handle_add_accessible (bus, message, data);
593 if (dbus_message_is_signal (message, atspi_interface_cache, "RemoveAccessible"))
595 return handle_remove_accessible (bus, message, data);
597 /* TODO: Handle ChildrenChanged, StateChanged, PropertyChanged */
598 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
601 static const char *signal_interfaces[] =
603 "org.a11y.atspi.Event.Object",
604 "org.a11y.atspi.Event.Window",
605 "org.a11y.atspi.Event.Mouse",
606 "org.a11y.atspi.Event.Terminal",
607 "org.a11y.atspi.Event.Document",
608 "org.a11y.atspi.Event.Focus",
613 * Returns a 'canonicalized' value for DISPLAY,
614 * with the screen number stripped off if present.
616 * TODO: Avoid having duplicate functions for this here and in at-spi2-atk
619 spi_display_name (void)
621 static const char *canonical_display_name = NULL;
622 if (!canonical_display_name)
624 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
627 display_env = g_getenv ("DISPLAY");
628 if (!display_env || !display_env[0])
629 canonical_display_name = ":0";
632 gchar *display_p, *screen_p;
633 canonical_display_name = g_strdup (display_env);
634 display_p = g_utf8_strrchr (canonical_display_name, -1, ':');
635 screen_p = g_utf8_strrchr (canonical_display_name, -1, '.');
636 if (screen_p && display_p && (screen_p > display_p))
644 canonical_display_name = display_env;
647 return canonical_display_name;
650 /* TODO: Avoid having duplicate functions for this here and in at-spi2-atk */
651 static DBusConnection *
652 get_accessibility_bus ()
656 Display *bridge_display;
658 unsigned char *data = NULL;
659 unsigned long nitems;
660 unsigned long leftover;
662 DBusConnection *bus = NULL;
665 bridge_display = XOpenDisplay (spi_display_name ());
668 g_warning ("AT_SPI: Could not get the display\n");
672 AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
673 XGetWindowProperty (bridge_display,
674 XDefaultRootWindow (bridge_display),
676 (long) BUFSIZ, False,
677 (Atom) 31, &actual_type, &actual_format,
678 &nitems, &leftover, &data);
680 dbus_error_init (&error);
685 ("AT-SPI: Accessibility bus not found - Using session bus.\n");
686 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
689 g_warning ("AT-SPI: Couldn't connect to bus: %s\n", error.message);
695 bus = dbus_connection_open (data, &error);
698 g_warning ("AT-SPI: Couldn't connect to bus: %s\n", error.message);
703 if (!dbus_bus_register (bus, &error))
705 g_warning ("AT-SPI: Couldn't register with bus: %s\n", error.message);
717 * Connects to the accessibility registry and initializes the SPI.
719 * Returns: 0 on success, otherwise an integer error code.
739 dbus_error_init (&error);
740 bus = get_accessibility_bus ();
743 g_error ("Couldn't get session bus");
746 dbus_bus_register (bus, &error);
747 dbus_connection_setup_with_g_main(bus, g_main_context_default());
748 dbus_connection_add_filter (bus, atspi_dbus_filter, NULL, NULL);
749 match = g_strdup_printf ("type='signal',interface='%s',member='AddAccessible'", atspi_interface_cache);
750 dbus_error_init (&error);
751 dbus_bus_add_match (bus, match, &error);
753 match = g_strdup_printf ("type='signal',interface='%s',member='RemoveAccessible'", atspi_interface_cache);
754 dbus_bus_add_match (bus, match, &error);
756 match = g_strdup_printf ("type='signal',interface='%s',member='ChildrenChanged'", atspi_interface_event_object);
757 dbus_bus_add_match (bus, match, &error);
759 match = g_strdup_printf ("type='signal',interface='%s',member='PropertyChange'", atspi_interface_event_object);
760 dbus_bus_add_match (bus, match, &error);
762 match = g_strdup_printf ("type='signal',interface='%s',member='StateChanged'", atspi_interface_event_object);
763 dbus_bus_add_match (bus, match, &error);
768 static GMainLoop *mainloop;
773 * Starts/enters the main event loop for the AT-SPI services.
775 * (NOTE: This method does not return control, it is exited via a call to
776 * atspi_event_quit () from within an event handler).
780 atspi_event_main (void)
782 mainloop = g_main_loop_new (NULL, FALSE);
783 g_main_loop_run (mainloop);
789 * Quits the last main event loop for the SPI services,
790 * see atspi_event_main
793 atspi_event_quit (void)
795 g_main_loop_quit (mainloop);
801 * Disconnects from the Accessibility Registry and releases
802 * any floating resources. Call only once at exit.
804 * Returns: 0 if there were no leaks, otherwise non zero.
816 atspi_inited = FALSE;
820 leaked = g_hash_table_size (live_refs);
833 _atspi_dbus_call (gpointer obj, const char *interface, const char *method, GError **error, const char *type, ...)
838 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
840 dbus_error_init (&err);
841 va_start (args, type);
842 retval = dbind_method_call_reentrant_va (_atspi_bus(), accessible->app->bus_name, accessible->path, interface, method, &err, type, args);
844 if (dbus_error_is_set (&err))
846 /* TODO: Set gerror */
847 dbus_error_free (&err);
853 _atspi_dbus_call_partial (gpointer obj, const char *interface, const char *method, GError **error, const char *type, ...)
855 AtspiAccessible *accessible = ATSPI_ACCESSIBLE (obj);
859 DBusMessage *msg = NULL, *reply = NULL;
860 DBusMessageIter iter;
863 dbus_error_init (&err);
864 va_start (args, type);
866 msg = dbus_message_new_method_call (accessible->app->bus_name, accessible->path, interface, method);
871 dbus_message_iter_init_append (msg, &iter);
872 dbind_any_marshal_va (&iter, &p, &args);
874 reply = dbind_send_and_allow_reentry (_atspi_bus(), msg, &err);
877 if (dbus_error_is_set (&err))
879 /* TODO: Set gerror */
880 dbus_error_free (&err);
886 _atspi_dbus_get_property (AtspiAccessible *obj, const char *interface, const char *name, GError **error, const char *type, void *data)
888 DBusMessage *message, *reply;
889 DBusMessageIter iter, iter_variant;
891 dbus_bool_t retval = FALSE;
893 message = dbus_message_new_method_call (obj->app->bus_name, obj->path, "org.freedesktop.DBus.Properties", "Get");
896 // TODO: throw exception
899 dbus_message_append_args (message, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
900 dbus_error_init (&err);
901 reply = dbus_connection_send_with_reply_and_block (_atspi_bus(), message, 1000, &err);
902 dbus_message_unref (message);
905 // TODO: throw exception
908 dbus_message_iter_init (reply, &iter);
909 dbus_message_iter_recurse (&iter, &iter_variant);
910 if (dbus_message_iter_get_arg_type (&iter_variant) != type[0])
912 g_warning ("atspi_dbus_get_property: Wrong type: expected %s, got %c\n", type, dbus_message_iter_get_arg_type (&iter_variant));
915 dbus_message_iter_get_basic (&iter_variant, data);
916 dbus_message_unref (reply);
917 if (type[0] == 's') *(char **)data = g_strdup (*(char **)data);
924 _atspi_dbus_send_with_reply_and_block (DBusMessage *message)
929 dbus_error_init (&err);
930 /* TODO: Write this function; allow reentrancy */
931 reply = dbus_connection_send_with_reply_and_block (_atspi_bus(), message, 1000, &err);
932 dbus_message_unref (message);
934 g_warning ("Atspi: Got error: %s\n", err.message);
939 _atspi_dbus_hash_from_message (DBusMessage *message)
941 DBusMessageIter iter;
942 const char *signature;
944 signature = dbus_message_get_signature (message);
946 if (strcmp (signature, "a{ss}") != 0)
948 g_warning ("Trying to get hash from message of unexpected type %s\n", signature);
952 dbus_message_iter_init (message, &iter);
953 return _atspi_dbus_hash_from_iter (&iter);
957 _atspi_dbus_hash_from_iter (DBusMessageIter *iter)
959 GHashTable *hash = g_hash_table_new (g_str_hash, g_str_equal);
960 DBusMessageIter iter_array, iter_dict;
962 dbus_message_iter_recurse (iter, &iter_array);
963 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
965 const char *name, *value;
966 dbus_message_iter_recurse (&iter_array, &iter_dict);
967 dbus_message_iter_get_basic (&iter_dict, &name);
968 dbus_message_iter_get_basic (&iter_dict, &value);
969 g_hash_table_insert (hash, g_strdup (name), g_strdup (value));
970 dbus_message_iter_next (&iter_array);
976 _atspi_dbus_attribute_array_from_message (DBusMessage *message)
978 DBusMessageIter iter;
979 const char *signature;
981 signature = dbus_message_get_signature (message);
983 if (strcmp (signature, "a{ss}") != 0)
985 g_warning ("Trying to get hash from message of unexpected type %s\n", signature);
989 return _atspi_dbus_attribute_array_from_iter (&iter);
993 _atspi_dbus_attribute_array_from_iter (DBusMessageIter *iter)
995 DBusMessageIter iter_array, iter_dict;
996 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
999 dbus_message_iter_recurse (iter, &iter_array);
1000 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1002 const char *name, *value;
1005 dbus_message_iter_recurse (&iter_array, &iter_dict);
1006 dbus_message_iter_get_basic (&iter_dict, &name);
1007 dbus_message_iter_get_basic (&iter_dict, &value);
1008 str = g_strdup_printf ("%s:;%s", name, value);
1009 new_array = g_array_append_val (array, str);
1012 dbus_message_iter_next (iter);;