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.
7 * Copyright 2010, 2011 Novell, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
27 * Basic SPI initialization and event loop function prototypes
31 #include "atspi-private.h"
35 #include "atspi-gmain.h"
39 static void handle_get_items (DBusPendingCall *pending, void *user_data);
41 static DBusConnection *bus = NULL;
42 static GHashTable *live_refs = NULL;
43 static gint method_call_timeout = 800;
44 static gint app_startup_time = 15000;
45 static gboolean allow_sync = TRUE;
47 GMainLoop *atspi_main_loop;
48 GMainContext *atspi_main_context;
49 gboolean atspi_no_cache;
51 const char *atspi_path_dec = ATSPI_DBUS_PATH_DEC;
52 const char *atspi_path_registry = ATSPI_DBUS_PATH_REGISTRY;
53 const char *atspi_path_root = ATSPI_DBUS_PATH_ROOT;
54 const char *atspi_bus_registry = ATSPI_DBUS_NAME_REGISTRY;
55 const char *atspi_interface_accessible = ATSPI_DBUS_INTERFACE_ACCESSIBLE;
56 const char *atspi_interface_action = ATSPI_DBUS_INTERFACE_ACTION;
57 const char *atspi_interface_application = ATSPI_DBUS_INTERFACE_APPLICATION;
58 const char *atspi_interface_collection = ATSPI_DBUS_INTERFACE_COLLECTION;
59 const char *atspi_interface_component = ATSPI_DBUS_INTERFACE_COMPONENT;
60 const char *atspi_interface_dec = ATSPI_DBUS_INTERFACE_DEC;
61 const char *atspi_interface_device_event_listener = ATSPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER;
62 const char *atspi_interface_document = ATSPI_DBUS_INTERFACE_DOCUMENT;
63 const char *atspi_interface_editable_text = ATSPI_DBUS_INTERFACE_EDITABLE_TEXT;
64 const char *atspi_interface_event_object = ATSPI_DBUS_INTERFACE_EVENT_OBJECT;
65 const char *atspi_interface_hyperlink = ATSPI_DBUS_INTERFACE_HYPERLINK;
66 const char *atspi_interface_hypertext = ATSPI_DBUS_INTERFACE_HYPERTEXT;
67 const char *atspi_interface_image = ATSPI_DBUS_INTERFACE_IMAGE;
68 const char *atspi_interface_registry = ATSPI_DBUS_INTERFACE_REGISTRY;
69 const char *atspi_interface_selection = ATSPI_DBUS_INTERFACE_SELECTION;
70 const char *atspi_interface_table = ATSPI_DBUS_INTERFACE_TABLE;
71 const char *atspi_interface_table_cell = ATSPI_DBUS_INTERFACE_TABLE_CELL;
72 const char *atspi_interface_text = ATSPI_DBUS_INTERFACE_TEXT;
73 const char *atspi_interface_cache = ATSPI_DBUS_INTERFACE_CACHE;
74 const char *atspi_interface_value = ATSPI_DBUS_INTERFACE_VALUE;
76 static const char *interfaces[] =
78 ATSPI_DBUS_INTERFACE_ACCESSIBLE,
79 ATSPI_DBUS_INTERFACE_ACTION,
80 ATSPI_DBUS_INTERFACE_APPLICATION,
81 ATSPI_DBUS_INTERFACE_COLLECTION,
82 ATSPI_DBUS_INTERFACE_COMPONENT,
83 ATSPI_DBUS_INTERFACE_DOCUMENT,
84 ATSPI_DBUS_INTERFACE_EDITABLE_TEXT,
85 ATSPI_DBUS_INTERFACE_HYPERLINK,
86 ATSPI_DBUS_INTERFACE_HYPERTEXT,
87 ATSPI_DBUS_INTERFACE_IMAGE,
88 "org.a11y.atspi.LoginHelper",
89 ATSPI_DBUS_INTERFACE_SELECTION,
90 ATSPI_DBUS_INTERFACE_TABLE,
91 ATSPI_DBUS_INTERFACE_TABLE_CELL,
92 ATSPI_DBUS_INTERFACE_TEXT,
93 ATSPI_DBUS_INTERFACE_VALUE,
98 _atspi_get_iface_num (const char *iface)
100 /* TODO: Use a binary search or hash to improve performance */
103 for (i = 0; interfaces[i]; i++)
105 if (!strcmp(iface, interfaces[i])) return i;
111 _atspi_get_live_refs (void)
115 live_refs = g_hash_table_new (g_direct_hash, g_direct_equal);
120 /* TODO: Add an application parameter */
127 g_error ("AT-SPI: Couldn't connect to accessibility bus. Is at-spi-bus-launcher running?");
131 #define APP_IS_REGISTRY(app) (!strcmp (app->bus_name, atspi_bus_registry))
133 static AtspiAccessible *desktop;
145 g_hash_table_destroy (refs);
150 dbus_connection_close (bus);
151 dbus_connection_unref (bus);
158 /* TODO: Do we need this code, or should we just dispose the desktop? */
159 for (i = desktop->children->len - 1; i >= 0; i--)
161 AtspiAccessible *child = g_ptr_array_index (desktop->children, i);
162 g_object_run_dispose (G_OBJECT (child->parent.app));
163 g_object_run_dispose (G_OBJECT (child));
166 g_object_run_dispose (G_OBJECT (desktop->parent.app));
167 g_object_unref (desktop);
171 static gboolean atspi_inited = FALSE;
173 static GHashTable *app_hash = NULL;
176 handle_get_bus_address (DBusPendingCall *pending, void *user_data)
178 AtspiApplication *app = user_data;
179 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
180 DBusMessage *message;
182 DBusPendingCall *new_pending;
184 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
186 if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &address,
187 DBUS_TYPE_INVALID) && address [0])
192 dbus_error_init (&error);
193 bus = dbus_connection_open_private (address, &error);
198 dbus_connection_unref (app->bus);
201 atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default());
205 if (!strcmp (error.name, DBUS_ERROR_FILE_NOT_FOUND))
206 g_warning ("Unable to open bus connection: %s", error.message);
207 dbus_error_free (&error);
211 dbus_message_unref (reply);
212 dbus_pending_call_unref (pending);
215 return; /* application has gone away / been disposed */
217 message = dbus_message_new_method_call (app->bus_name,
218 "/org/a11y/atspi/cache",
219 atspi_interface_cache, "GetItems");
221 dbus_connection_send_with_reply (app->bus, message, &new_pending, 2000);
222 dbus_message_unref (message);
225 dbus_pending_call_set_notify (new_pending, handle_get_items, app, NULL);
228 static AtspiApplication *
229 get_application (const char *bus_name)
231 AtspiApplication *app = NULL;
233 DBusMessage *message;
234 DBusPendingCall *pending = NULL;
238 app_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref);
239 if (!app_hash) return NULL;
241 app = g_hash_table_lookup (app_hash, bus_name);
243 bus_name_dup = g_strdup (bus_name);
244 if (!bus_name_dup) return NULL;
245 // TODO: change below to something that will send state-change:defunct notification if necessary */
246 app = _atspi_application_new (bus_name);
247 app->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
248 app->bus = dbus_connection_ref (_atspi_bus ());
249 gettimeofday (&app->time_added, NULL);
250 app->cache = ATSPI_CACHE_UNDEFINED;
251 g_hash_table_insert (app_hash, bus_name_dup, app);
252 message = dbus_message_new_method_call (bus_name, atspi_path_root,
253 atspi_interface_application, "GetApplicationBusAddress");
255 dbus_connection_send_with_reply (app->bus, message, &pending, 2000);
256 dbus_message_unref (message);
259 g_hash_table_remove (app_hash, bus_name_dup);
262 dbus_pending_call_set_notify (pending, handle_get_bus_address, app, NULL);
266 static AtspiAccessible *
267 ref_accessible (const char *app_name, const char *path)
269 AtspiApplication *app;
272 if (!strcmp (path, ATSPI_DBUS_PATH_NULL))
275 app = get_application (app_name);
277 if (!strcmp (path, "/org/a11y/atspi/accessible/root"))
281 app->root = _atspi_accessible_new (app, atspi_path_root);
282 app->root->accessible_parent = atspi_get_desktop (0);
283 g_ptr_array_add (app->root->accessible_parent->children, g_object_ref (app->root));
285 return g_object_ref (app->root);
288 a = g_hash_table_lookup (app->hash, path);
291 return g_object_ref (a);
293 a = _atspi_accessible_new (app, path);
296 g_hash_table_insert (app->hash, g_strdup (a->parent.path), g_object_ref (a));
300 static AtspiHyperlink *
301 ref_hyperlink (const char *app_name, const char *path)
303 AtspiApplication *app = get_application (app_name);
304 AtspiHyperlink *hyperlink;
306 if (!strcmp (path, ATSPI_DBUS_PATH_NULL))
309 hyperlink = g_hash_table_lookup (app->hash, path);
312 return g_object_ref (hyperlink);
314 hyperlink = _atspi_hyperlink_new (app, path);
315 g_hash_table_insert (app->hash, g_strdup (hyperlink->parent.path), hyperlink);
316 /* TODO: This should be a weak ref */
317 g_object_ref (hyperlink); /* for the hash */
330 GArray *state_bitflags;
333 static DBusHandlerResult
334 handle_remove_accessible (DBusConnection *bus, DBusMessage *message, void *user_data)
336 const char *sender = dbus_message_get_sender (message);
337 AtspiApplication *app;
339 DBusMessageIter iter, iter_struct;
340 const char *signature = dbus_message_get_signature (message);
343 if (strcmp (signature, "(so)") != 0)
345 g_warning ("AT-SPI: Unknown signature %s for RemoveAccessible", signature);
346 return DBUS_HANDLER_RESULT_HANDLED;
349 dbus_message_iter_init (message, &iter);
350 dbus_message_iter_recurse (&iter, &iter_struct);
351 dbus_message_iter_get_basic (&iter_struct, &sender);
352 dbus_message_iter_next (&iter_struct);
353 dbus_message_iter_get_basic (&iter_struct, &path);
354 app = get_application (sender);
355 a = ref_accessible (sender, path);
357 return DBUS_HANDLER_RESULT_HANDLED;
358 g_object_run_dispose (G_OBJECT (a));
359 g_hash_table_remove (app->hash, a->parent.path);
360 g_object_unref (a); /* unref our own ref */
361 return DBUS_HANDLER_RESULT_HANDLED;
364 static DBusHandlerResult
365 handle_name_owner_changed (DBusConnection *bus, DBusMessage *message, void *user_data)
367 const char *name, *new, *old;
368 static gboolean registry_lost = FALSE;
370 if (!dbus_message_get_args (message, NULL,
371 DBUS_TYPE_STRING, &name,
372 DBUS_TYPE_STRING, &old,
373 DBUS_TYPE_STRING, &new,
376 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
379 if (!strcmp (name, "org.a11y.atspi.Registry"))
381 if (registry_lost && !old[0])
383 _atspi_reregister_event_listeners ();
384 _atspi_reregister_device_listeners ();
385 registry_lost = FALSE;
388 registry_lost = TRUE;
392 AtspiApplication *app = g_hash_table_lookup (app_hash, old);
393 if (app && !strcmp (app->bus_name, old))
394 g_object_run_dispose (G_OBJECT (app));
396 return DBUS_HANDLER_RESULT_HANDLED;
400 add_app_to_desktop (AtspiAccessible *a, const char *bus_name)
402 AtspiAccessible *obj = ref_accessible (bus_name, atspi_path_root);
403 /* The app will be added to the desktop as a side-effect of calling
405 g_object_unref (obj);
406 return (obj != NULL);
410 get_reference_from_iter (DBusMessageIter *iter, const char **app_name, const char **path)
412 DBusMessageIter iter_struct;
414 dbus_message_iter_recurse (iter, &iter_struct);
415 dbus_message_iter_get_basic (&iter_struct, app_name);
416 dbus_message_iter_next (&iter_struct);
417 dbus_message_iter_get_basic (&iter_struct, path);
418 dbus_message_iter_next (iter);
422 add_accessible_from_iter (DBusMessageIter *iter)
424 DBusMessageIter iter_struct, iter_array;
425 const char *app_name, *path;
426 AtspiAccessible *accessible;
427 const char *name, *description;
429 gboolean children_cached = FALSE;
430 dbus_int32_t count, index;
432 dbus_message_iter_recurse (iter, &iter_struct);
435 get_reference_from_iter (&iter_struct, &app_name, &path);
436 accessible = ref_accessible (app_name, path);
440 /* Get application: TODO */
441 dbus_message_iter_next (&iter_struct);
444 get_reference_from_iter (&iter_struct, &app_name, &path);
445 if (accessible->accessible_parent)
446 g_object_unref (accessible->accessible_parent);
447 accessible->accessible_parent = ref_accessible (app_name, path);
449 if (dbus_message_iter_get_arg_type (&iter_struct) == 'i')
451 /* Get index in parent */
452 dbus_message_iter_get_basic (&iter_struct, &index);
453 if (index >= 0 && accessible->accessible_parent)
455 if (index >= accessible->accessible_parent->children->len)
456 g_ptr_array_set_size (accessible->accessible_parent->children, index + 1);
457 g_ptr_array_index (accessible->accessible_parent->children, index) = g_object_ref (accessible);
460 /* get child count */
461 dbus_message_iter_next (&iter_struct);
462 dbus_message_iter_get_basic (&iter_struct, &count);
465 g_ptr_array_set_size (accessible->children, count);
466 children_cached = TRUE;
469 else if (dbus_message_iter_get_arg_type (&iter_struct) == 'a')
471 /* It's the old API with a list of children */
472 /* TODO: Perhaps remove this code eventually */
473 dbus_message_iter_recurse (&iter_struct, &iter_array);
474 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
476 AtspiAccessible *child;
477 get_reference_from_iter (&iter_array, &app_name, &path);
478 child = ref_accessible (app_name, path);
479 g_ptr_array_remove (accessible->children, child);
480 g_ptr_array_add (accessible->children, child);
482 children_cached = TRUE;
486 dbus_message_iter_next (&iter_struct);
487 _atspi_dbus_set_interfaces (accessible, &iter_struct);
488 dbus_message_iter_next (&iter_struct);
491 if (accessible->name)
492 g_free (accessible->name);
493 dbus_message_iter_get_basic (&iter_struct, &name);
494 accessible->name = g_strdup (name);
495 dbus_message_iter_next (&iter_struct);
498 dbus_message_iter_get_basic (&iter_struct, &role);
499 accessible->role = role;
500 dbus_message_iter_next (&iter_struct);
503 if (accessible->description)
504 g_free (accessible->description);
505 dbus_message_iter_get_basic (&iter_struct, &description);
506 accessible->description = g_strdup (description);
507 dbus_message_iter_next (&iter_struct);
509 _atspi_dbus_set_state (accessible, &iter_struct);
510 dbus_message_iter_next (&iter_struct);
512 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_NAME | ATSPI_CACHE_ROLE |
513 ATSPI_CACHE_PARENT | ATSPI_CACHE_DESCRIPTION);
514 if (!atspi_state_set_contains (accessible->states,
515 ATSPI_STATE_MANAGES_DESCENDANTS) &&
517 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_CHILDREN);
519 /* This is a bit of a hack since the cache holds a ref, so we don't need
520 * the one provided for us anymore */
521 g_object_unref (accessible);
525 handle_get_items (DBusPendingCall *pending, void *user_data)
527 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
528 DBusMessageIter iter, iter_array;
530 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
532 const char *sender = dbus_message_get_sender (reply);
533 const char *error = NULL;
534 if (!strcmp (dbus_message_get_error_name (reply),
535 DBUS_ERROR_SERVICE_UNKNOWN))
540 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &error,
542 g_warning ("AT-SPI: Error in GetItems, sender=%s, error=%s", sender, error);
544 dbus_message_unref (reply);
545 dbus_pending_call_unref (pending);
549 dbus_message_iter_init (reply, &iter);
550 dbus_message_iter_recurse (&iter, &iter_array);
551 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
553 add_accessible_from_iter (&iter_array);
554 dbus_message_iter_next (&iter_array);
556 dbus_message_unref (reply);
557 dbus_pending_call_unref (pending);
560 /* TODO: Do we stil need this function? */
561 static AtspiAccessible *
562 ref_accessible_desktop (AtspiApplication *app)
565 DBusMessage *message, *reply;
566 DBusMessageIter iter, iter_array;
571 g_object_ref (desktop);
574 desktop = _atspi_accessible_new (app, atspi_path_root);
579 g_hash_table_insert (app->hash, g_strdup (desktop->parent.path),
580 g_object_ref (desktop));
581 app->root = g_object_ref (desktop);
582 desktop->name = g_strdup ("main");
583 message = dbus_message_new_method_call (atspi_bus_registry,
585 atspi_interface_accessible,
590 reply = _atspi_dbus_send_with_reply_and_block (message, &error);
591 if (!reply || strcmp (dbus_message_get_signature (reply), "a(so)") != 0)
595 g_warning ("Couldn't get application list: %s", error->message);
596 g_clear_error (&error);
599 dbus_message_unref (reply);
602 dbus_message_iter_init (reply, &iter);
603 dbus_message_iter_recurse (&iter, &iter_array);
604 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
606 const char *app_name, *path;
607 get_reference_from_iter (&iter_array, &app_name, &path);
608 add_app_to_desktop (desktop, app_name);
611 /* Record the alternate name as an alias for org.a11y.atspi.Registry */
612 bus_name_dup = g_strdup (dbus_message_get_sender (reply));
614 g_hash_table_insert (app_hash, bus_name_dup, app);
616 dbus_message_unref (reply);
618 return g_object_ref (desktop);
622 _atspi_ref_accessible (const char *app, const char *path)
624 AtspiApplication *a = get_application (app);
627 if ( APP_IS_REGISTRY(a))
630 g_object_unref (ref_accessible_desktop (a)); /* sets a->root */
631 return g_object_ref (a->root);
633 return ref_accessible (app, path);
637 _atspi_dbus_return_accessible_from_message (DBusMessage *message)
639 DBusMessageIter iter;
640 AtspiAccessible *retval = NULL;
641 const char *signature;
646 signature = dbus_message_get_signature (message);
647 if (!strcmp (signature, "(so)"))
649 dbus_message_iter_init (message, &iter);
650 retval = _atspi_dbus_return_accessible_from_iter (&iter);
654 g_warning ("AT-SPI: Called _atspi_dbus_return_accessible_from_message with strange signature %s", signature);
656 dbus_message_unref (message);
661 _atspi_dbus_return_accessible_from_iter (DBusMessageIter *iter)
663 const char *app_name, *path;
665 get_reference_from_iter (iter, &app_name, &path);
666 return ref_accessible (app_name, path);
670 _atspi_dbus_return_hyperlink_from_message (DBusMessage *message)
672 DBusMessageIter iter;
673 AtspiHyperlink *retval = NULL;
674 const char *signature;
679 signature = dbus_message_get_signature (message);
680 if (!strcmp (signature, "(so)"))
682 dbus_message_iter_init (message, &iter);
683 retval = _atspi_dbus_return_hyperlink_from_iter (&iter);
687 g_warning ("AT-SPI: Called _atspi_dbus_return_hyperlink_from_message with strange signature %s", signature);
689 dbus_message_unref (message);
694 _atspi_dbus_return_hyperlink_from_iter (DBusMessageIter *iter)
696 const char *app_name, *path;
698 get_reference_from_iter (iter, &app_name, &path);
699 return ref_hyperlink (app_name, path);
702 const char *cache_signal_type = "((so)(so)(so)iiassusau)";
703 const char *old_cache_signal_type = "((so)(so)(so)a(so)assusau)";
705 static DBusHandlerResult
706 handle_add_accessible (DBusConnection *bus, DBusMessage *message, void *user_data)
708 DBusMessageIter iter;
709 const char *signature = dbus_message_get_signature (message);
711 if (strcmp (signature, cache_signal_type) != 0 &&
712 strcmp (signature, old_cache_signal_type) != 0)
714 g_warning ("AT-SPI: AddAccessible with unknown signature %s\n", signature);
715 return DBUS_HANDLER_RESULT_HANDLED;
718 dbus_message_iter_init (message, &iter);
719 add_accessible_from_iter (&iter);
720 return DBUS_HANDLER_RESULT_HANDLED;
726 DBusMessage *message;
730 static GSource *process_deferred_messages_source = NULL;
733 process_deferred_message (BusDataClosure *closure)
735 int type = dbus_message_get_type (closure->message);
736 const char *interface = dbus_message_get_interface (closure->message);
738 if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
739 !strncmp (interface, "org.a11y.atspi.Event.", 21))
741 _atspi_dbus_handle_event (closure->bus, closure->message, closure->data);
743 if (dbus_message_is_method_call (closure->message, atspi_interface_device_event_listener, "NotifyEvent"))
745 _atspi_dbus_handle_DeviceEvent (closure->bus,
746 closure->message, closure->data);
748 if (dbus_message_is_signal (closure->message, atspi_interface_cache, "AddAccessible"))
750 handle_add_accessible (closure->bus, closure->message, closure->data);
752 if (dbus_message_is_signal (closure->message, atspi_interface_cache, "RemoveAccessible"))
754 handle_remove_accessible (closure->bus, closure->message, closure->data);
756 if (dbus_message_is_signal (closure->message, "org.freedesktop.DBus", "NameOwnerChanged"))
758 handle_name_owner_changed (closure->bus, closure->message, closure->data);
762 static GQueue *deferred_messages = NULL;
765 process_deferred_messages (void)
767 static int in_process_deferred_messages = 0;
768 BusDataClosure *closure;
770 if (in_process_deferred_messages)
772 in_process_deferred_messages = 1;
773 while ((closure = g_queue_pop_head (deferred_messages)))
775 process_deferred_message (closure);
776 dbus_message_unref (closure->message);
777 dbus_connection_unref (closure->bus);
780 in_process_deferred_messages = 0;
785 process_deferred_messages_callback (gpointer data)
787 if (process_deferred_messages ())
788 return G_SOURCE_CONTINUE;
790 process_deferred_messages_source = NULL;
791 return G_SOURCE_REMOVE;
794 static DBusHandlerResult
795 defer_message (DBusConnection *connection, DBusMessage *message, void *user_data)
797 BusDataClosure *closure = g_new (BusDataClosure, 1);
799 closure->bus = dbus_connection_ref (bus);
800 closure->message = dbus_message_ref (message);
801 closure->data = user_data;
803 g_queue_push_tail (deferred_messages, closure);
805 if (process_deferred_messages_source == NULL)
807 process_deferred_messages_source = g_idle_source_new ();
808 g_source_set_callback (process_deferred_messages_source,
809 process_deferred_messages_callback, NULL, NULL);
810 g_source_attach (process_deferred_messages_source, atspi_main_context);
811 g_source_unref (process_deferred_messages_source);
814 return DBUS_HANDLER_RESULT_HANDLED;
817 static DBusHandlerResult
818 atspi_dbus_filter (DBusConnection *bus, DBusMessage *message, void *data)
820 int type = dbus_message_get_type (message);
821 const char *interface = dbus_message_get_interface (message);
823 if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
824 !strncmp (interface, "org.a11y.atspi.Event.", 21))
826 return defer_message (bus, message, data);
828 if (dbus_message_is_method_call (message, atspi_interface_device_event_listener, "NotifyEvent"))
830 return defer_message (bus, message, data);
832 if (dbus_message_is_signal (message, atspi_interface_cache, "AddAccessible"))
834 return defer_message (bus, message, data);
836 if (dbus_message_is_signal (message, atspi_interface_cache, "RemoveAccessible"))
838 return defer_message (bus, message, data);
840 if (dbus_message_is_signal (message, "org.freedesktop.DBus", "NameOwnerChanged"))
842 defer_message (bus, message, data);
843 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
845 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
849 * Returns a 'canonicalized' value for DISPLAY,
850 * with the screen number stripped off if present.
852 * TODO: Avoid having duplicate functions for this here and in at-spi2-atk
855 spi_display_name (void)
857 char *canonical_display_name = NULL;
858 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
862 display_env = g_getenv ("DISPLAY");
863 if (!display_env || !display_env[0])
867 gchar *display_p, *screen_p;
868 canonical_display_name = g_strdup (display_env);
869 display_p = g_utf8_strrchr (canonical_display_name, -1, ':');
870 screen_p = g_utf8_strrchr (canonical_display_name, -1, '.');
871 if (screen_p && display_p && (screen_p > display_p))
879 canonical_display_name = g_strdup (display_env);
882 return canonical_display_name;
888 * Connects to the accessibility registry and initializes the SPI.
890 * Returns: 0 on success, 1 if already initialized, or an integer error code.
896 const gchar *no_cache;
905 _atspi_get_live_refs();
907 bus = atspi_get_a11y_bus ();
910 dbus_bus_register (bus, NULL);
911 atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default());
912 dbus_connection_add_filter (bus, atspi_dbus_filter, NULL, NULL);
913 match = g_strdup_printf ("type='signal',interface='%s',member='AddAccessible'", atspi_interface_cache);
914 dbus_bus_add_match (bus, match, NULL);
916 match = g_strdup_printf ("type='signal',interface='%s',member='RemoveAccessible'", atspi_interface_cache);
917 dbus_bus_add_match (bus, match, NULL);
919 match = g_strdup_printf ("type='signal',interface='%s',member='ChildrenChanged'", atspi_interface_event_object);
920 dbus_bus_add_match (bus, match, NULL);
922 match = g_strdup_printf ("type='signal',interface='%s',member='PropertyChange'", atspi_interface_event_object);
923 dbus_bus_add_match (bus, match, NULL);
925 match = g_strdup_printf ("type='signal',interface='%s',member='StateChanged'", atspi_interface_event_object);
926 dbus_bus_add_match (bus, match, NULL);
929 dbus_bus_add_match (bus,
930 "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged'",
933 no_cache = g_getenv ("ATSPI_NO_CACHE");
934 if (no_cache && g_strcmp0 (no_cache, "0") != 0)
935 atspi_no_cache = TRUE;
937 deferred_messages = g_queue_new ();
943 * atspi_is_initialized:
945 * Indicates whether AT-SPI has been initialized.
947 * Returns: %True if initialized; %False otherwise.
950 atspi_is_initialized ()
958 * Starts/enters the main event loop for the AT-SPI services.
960 * NOTE: This method does not return control; it is exited via a call to
961 * #atspi_event_quit from within an event handler.
965 atspi_event_main (void)
967 atspi_main_loop = g_main_loop_new (NULL, FALSE);
968 g_main_loop_run (atspi_main_loop);
969 atspi_main_loop = NULL;
975 * Quits the last main event loop for the AT-SPI services,
976 * See: #atspi_event_main
979 atspi_event_quit (void)
981 g_main_loop_quit (atspi_main_loop);
987 * Disconnects from #AtspiRegistry instances and releases
988 * any floating resources. Call only once at exit.
990 * Returns: 0 if there were no leaks, otherwise other integer values.
1002 atspi_inited = FALSE;
1006 leaked = g_hash_table_size (live_refs);
1018 static GSList *hung_processes;
1021 remove_hung_process (DBusPendingCall *pending, void *data)
1023 hung_processes = g_slist_remove (hung_processes, data);
1025 dbus_pending_call_unref (pending);
1029 check_for_hang (DBusMessage *message, DBusError *error, DBusConnection *bus, const char *bus_name)
1031 if (!message && error->name &&
1032 !strcmp (error->name, "org.freedesktop.DBus.Error.NoReply"))
1035 DBusMessage *message;
1036 gchar *bus_name_dup;
1037 DBusPendingCall *pending = NULL;
1038 for (l = hung_processes; l; l = l->next)
1039 if (!strcmp (l->data, bus_name))
1041 message = dbus_message_new_method_call (bus_name, "/",
1042 "org.freedesktop.DBus.Peer",
1046 dbus_connection_send_with_reply (bus, message, &pending, -1);
1047 dbus_message_unref (message);
1050 bus_name_dup = g_strdup (bus_name);
1051 hung_processes = g_slist_append (hung_processes, bus_name_dup);
1052 dbus_pending_call_set_notify (pending, remove_hung_process, bus_name_dup, NULL);
1057 connection_is_hung (const char *bus_name)
1061 for (l = hung_processes; l; l = l->next)
1062 if (!strcmp (l->data, bus_name))
1068 check_app (AtspiApplication *app, GError **error)
1070 if (!app || !app->bus)
1072 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_APPLICATION_GONE,
1073 _("The application no longer exists"));
1077 if (atspi_main_loop && connection_is_hung (app->bus_name))
1079 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC,
1080 "The process appears to be hung.");
1088 set_timeout (AtspiApplication *app)
1093 if (app && app_startup_time > 0)
1095 gettimeofday (&tv, NULL);
1096 diff = (tv.tv_sec - app->time_added.tv_sec) * 1000 + (tv.tv_usec - app->time_added.tv_usec) / 1000;
1097 dbind_set_timeout (MAX(method_call_timeout, app_startup_time - diff));
1100 dbind_set_timeout (method_call_timeout);
1104 _atspi_dbus_call (gpointer obj, const char *interface, const char *method, GError **error, const char *type, ...)
1109 AtspiObject *aobj = ATSPI_OBJECT (obj);
1111 if (!check_app (aobj->app, error))
1116 _atspi_set_error_no_sync (error);
1120 va_start (args, type);
1121 dbus_error_init (&err);
1122 set_timeout (aobj->app);
1123 retval = dbind_method_call_reentrant_va (aobj->app->bus, aobj->app->bus_name,
1124 aobj->path, interface, method, &err,
1127 check_for_hang (NULL, &err, aobj->app->bus, aobj->app->bus_name);
1128 process_deferred_messages ();
1129 if (dbus_error_is_set (&err))
1131 g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "%s", err.message);
1132 dbus_error_free (&err);
1138 _atspi_dbus_call_partial (gpointer obj,
1139 const char *interface,
1142 const char *type, ...)
1146 va_start (args, type);
1147 return _atspi_dbus_call_partial_va (obj, interface, method, error, type, args);
1152 _atspi_dbus_call_partial_va (gpointer obj,
1153 const char *interface,
1159 AtspiObject *aobj = ATSPI_OBJECT (obj);
1161 DBusMessage *msg = NULL, *reply = NULL;
1162 DBusMessageIter iter;
1165 dbus_error_init (&err);
1167 if (!check_app (aobj->app, error))
1170 msg = dbus_message_new_method_call (aobj->app->bus_name, aobj->path, interface, method);
1175 dbus_message_iter_init_append (msg, &iter);
1176 dbind_any_marshal_va (&iter, &p, args);
1178 set_timeout (aobj->app);
1179 reply = dbind_send_and_allow_reentry (aobj->app->bus, msg, &err);
1180 check_for_hang (reply, &err, aobj->app->bus, aobj->app->bus_name);
1184 dbus_message_unref (msg);
1185 process_deferred_messages ();
1186 if (dbus_error_is_set (&err))
1188 /* TODO: Set gerror */
1189 dbus_error_free (&err);
1192 if (reply && dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
1194 const char *err_str = NULL;
1195 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err_str, DBUS_TYPE_INVALID);
1197 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err_str);
1198 dbus_message_unref (reply);
1206 _atspi_dbus_get_property (gpointer obj, const char *interface, const char *name, GError **error, const char *type, void *data)
1208 DBusMessage *message, *reply;
1209 DBusMessageIter iter, iter_variant;
1211 dbus_bool_t retval = FALSE;
1212 AtspiObject *aobj = ATSPI_OBJECT (obj);
1213 char expected_type = (type [0] == '(' ? 'r' : type [0]);
1218 if (!check_app (aobj->app, error))
1223 _atspi_set_error_no_sync (error);
1227 message = dbus_message_new_method_call (aobj->app->bus_name,
1229 "org.freedesktop.DBus.Properties",
1233 // TODO: throw exception
1236 dbus_message_append_args (message, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
1237 dbus_error_init (&err);
1238 set_timeout (aobj->app);
1239 reply = dbind_send_and_allow_reentry (aobj->app->bus, message, &err);
1240 check_for_hang (reply, &err, aobj->app->bus, aobj->app->bus_name);
1241 dbus_message_unref (message);
1242 process_deferred_messages ();
1245 // TODO: throw exception
1249 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
1251 const char *err_str = NULL;
1252 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err_str, DBUS_TYPE_INVALID);
1254 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err_str);
1258 dbus_message_iter_init (reply, &iter);
1259 if (dbus_message_iter_get_arg_type (&iter) != 'v')
1261 g_warning ("AT-SPI: expected a variant when fetching %s from interface %s; got %s\n", name, interface, dbus_message_get_signature (reply));
1264 dbus_message_iter_recurse (&iter, &iter_variant);
1265 if (dbus_message_iter_get_arg_type (&iter_variant) != expected_type)
1267 g_warning ("atspi_dbus_get_property: Wrong type: expected %s, got %c\n", type, dbus_message_iter_get_arg_type (&iter_variant));
1270 if (!strcmp (type, "(so)"))
1272 *((AtspiAccessible **)data) = _atspi_dbus_return_accessible_from_iter (&iter_variant);
1276 dbus_message_iter_get_basic (&iter_variant, data);
1277 if (type [0] == 's')
1278 *(char **)data = g_strdup (*(char **)data);
1282 dbus_error_free (&err);
1284 dbus_message_unref (reply);
1289 _atspi_dbus_send_with_reply_and_block (DBusMessage *message, GError **error)
1293 AtspiApplication *app;
1294 DBusConnection *bus;
1296 app = get_application (dbus_message_get_destination (message));
1298 if (app && !app->bus)
1299 return NULL; /* will fail anyway; app has been disposed */
1301 bus = (app ? app->bus : _atspi_bus());
1302 dbus_error_init (&err);
1304 reply = dbind_send_and_allow_reentry (bus, message, &err);
1305 process_deferred_messages ();
1306 dbus_message_unref (message);
1307 if (dbus_error_is_set (&err))
1310 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err.message);
1311 dbus_error_free (&err);
1317 _atspi_dbus_return_hash_from_message (DBusMessage *message)
1319 DBusMessageIter iter;
1325 _ATSPI_DBUS_CHECK_SIG (message, "a{ss}", NULL, NULL);
1327 dbus_message_iter_init (message, &iter);
1328 ret = _atspi_dbus_hash_from_iter (&iter);
1329 dbus_message_unref (message);
1334 _atspi_dbus_hash_from_iter (DBusMessageIter *iter)
1336 GHashTable *hash = g_hash_table_new_full (g_str_hash, g_str_equal,
1337 (GDestroyNotify) g_free,
1338 (GDestroyNotify) g_free);
1339 DBusMessageIter iter_array, iter_dict;
1341 dbus_message_iter_recurse (iter, &iter_array);
1342 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1344 const char *name, *value;
1345 dbus_message_iter_recurse (&iter_array, &iter_dict);
1346 dbus_message_iter_get_basic (&iter_dict, &name);
1347 dbus_message_iter_next (&iter_dict);
1348 dbus_message_iter_get_basic (&iter_dict, &value);
1349 g_hash_table_insert (hash, g_strdup (name), g_strdup (value));
1350 dbus_message_iter_next (&iter_array);
1356 _atspi_dbus_return_attribute_array_from_message (DBusMessage *message)
1358 DBusMessageIter iter;
1364 _ATSPI_DBUS_CHECK_SIG (message, "a{ss}", NULL, NULL);
1366 dbus_message_iter_init (message, &iter);
1368 ret = _atspi_dbus_attribute_array_from_iter (&iter);
1369 dbus_message_unref (message);
1374 _atspi_dbus_attribute_array_from_iter (DBusMessageIter *iter)
1376 DBusMessageIter iter_array, iter_dict;
1377 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
1379 dbus_message_iter_recurse (iter, &iter_array);
1380 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1382 const char *name, *value;
1384 dbus_message_iter_recurse (&iter_array, &iter_dict);
1385 dbus_message_iter_get_basic (&iter_dict, &name);
1386 dbus_message_iter_next (&iter_dict);
1387 dbus_message_iter_get_basic (&iter_dict, &value);
1388 str = g_strdup_printf ("%s:%s", name, value);
1389 array = g_array_append_val (array, str);
1390 dbus_message_iter_next (&iter_array);;
1396 _atspi_dbus_set_interfaces (AtspiAccessible *accessible, DBusMessageIter *iter)
1398 DBusMessageIter iter_array;
1399 char *iter_sig = dbus_message_iter_get_signature (iter);
1401 accessible->interfaces = 0;
1402 if (strcmp (iter_sig, "as") != 0)
1404 g_warning ("_atspi_dbus_set_interfaces: Passed iterator with invalid signature %s", dbus_message_iter_get_signature (iter));
1405 dbus_free (iter_sig);
1408 dbus_free (iter_sig);
1409 dbus_message_iter_recurse (iter, &iter_array);
1410 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1414 dbus_message_iter_get_basic (&iter_array, &iface);
1415 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable")) continue;
1416 n = _atspi_get_iface_num (iface);
1419 g_warning ("AT-SPI: Unknown interface %s", iface);
1422 accessible->interfaces |= (1 << n);
1423 dbus_message_iter_next (&iter_array);
1425 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
1429 _atspi_dbus_set_state (AtspiAccessible *accessible, DBusMessageIter *iter)
1431 DBusMessageIter iter_array;
1433 dbus_uint32_t *states;
1435 dbus_message_iter_recurse (iter, &iter_array);
1436 dbus_message_iter_get_fixed_array (&iter_array, &states, &count);
1439 g_warning ("AT-SPI: expected 2 values in states array; got %d\n", count);
1440 if (!accessible->states)
1441 accessible->states = _atspi_state_set_new_internal (accessible, 0);
1445 guint64 val = ((guint64)states [1]) << 32;
1447 if (!accessible->states)
1448 accessible->states = _atspi_state_set_new_internal (accessible, val);
1450 accessible->states->states = val;
1452 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_STATES);
1456 _atspi_error_quark (void)
1458 return g_quark_from_static_string ("atspi_error");
1462 * Gets the IOR from the XDisplay.
1466 get_accessibility_bus_address_x11 (void)
1470 Display *bridge_display = NULL;
1473 unsigned char *data_x11 = NULL;
1474 unsigned long nitems;
1475 unsigned long leftover;
1478 display_name = spi_display_name ();
1482 bridge_display = XOpenDisplay (display_name);
1483 g_free (display_name);
1485 if (!bridge_display)
1487 g_warning ("Could not open X display");
1491 AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
1492 XGetWindowProperty (bridge_display,
1493 XDefaultRootWindow (bridge_display),
1495 (long) BUFSIZ, False,
1496 (Atom) 31, &actual_type, &actual_format,
1497 &nitems, &leftover, &data_x11);
1498 XCloseDisplay (bridge_display);
1500 data = g_strdup ((gchar *)data_x11);
1507 get_accessibility_bus_address_dbus (void)
1509 DBusConnection *session_bus = NULL;
1510 DBusMessage *message;
1513 char *address = NULL;
1515 session_bus = dbus_bus_get (DBUS_BUS_SESSION, NULL);
1519 message = dbus_message_new_method_call ("org.a11y.Bus",
1524 dbus_error_init (&error);
1525 reply = dbus_connection_send_with_reply_and_block (session_bus,
1529 dbus_message_unref (message);
1533 g_warning ("Error retrieving accessibility bus address: %s: %s",
1534 error.name, error.message);
1535 dbus_error_free (&error);
1540 const char *tmp_address;
1541 if (!dbus_message_get_args (reply,
1547 dbus_message_unref (reply);
1550 address = g_strdup (tmp_address);
1551 dbus_message_unref (reply);
1555 dbus_connection_unref (session_bus);
1559 static DBusConnection *a11y_bus;
1560 static dbus_int32_t a11y_dbus_slot = -1;
1563 a11y_bus_free (void *data)
1565 if (data == a11y_bus)
1568 dbus_connection_free_data_slot (&a11y_dbus_slot);
1573 * atspi_get_a11y_bus: (skip)
1576 atspi_get_a11y_bus (void)
1579 char *address = NULL;
1581 if (a11y_bus && dbus_connection_get_is_connected (a11y_bus))
1584 if (a11y_dbus_slot == -1)
1585 if (!dbus_connection_allocate_data_slot (&a11y_dbus_slot))
1586 g_warning ("at-spi: Unable to allocate D-Bus slot");
1589 address = get_accessibility_bus_address_x11 ();
1592 address = get_accessibility_bus_address_dbus ();
1596 dbus_error_init (&error);
1597 a11y_bus = dbus_connection_open_private (address, &error);
1602 if (!g_getenv("SSH_CONNECTION"))
1603 g_warning ("Couldn't connect to accessibility bus: %s", error.message);
1604 dbus_error_free (&error);
1609 if (!dbus_bus_register (a11y_bus, &error))
1611 g_warning ("Couldn't register with accessibility bus: %s", error.message);
1612 dbus_error_free (&error);
1613 dbus_connection_close (a11y_bus);
1614 dbus_connection_unref (a11y_bus);
1620 /* Simulate a weak ref on the bus */
1621 dbus_connection_set_data (a11y_bus, a11y_dbus_slot, a11y_bus, a11y_bus_free);
1627 * atspi_set_timeout:
1628 * @val: The timeout value, in milliseconds, or -1 to disable the timeout.
1629 * @startup_time: The amount of time, in milliseconds, to allow to pass
1630 * before enforcing timeouts on an application. Can be used to prevent
1631 * timeout exceptions if an application is likely to block for an extended
1632 * period of time on initialization. -1 can be passed to disable this
1635 * Set the timeout used for method calls. If this is not set explicitly,
1636 * a default of 0.8 ms is used.
1637 * Note that at-spi2-registryd currently uses a timeout of 3 seconds when
1638 * sending a keyboard event notification. This means that, if an AT makes
1639 * a call in response to the keyboard notification and the application
1640 * being called does not respond before the timeout is reached,
1641 * at-spi2-registryd will time out on the keyboard event notification and
1642 * pass the key onto the application (ie, reply to indicate that the key
1643 * was not consumed), so this may make it undesirable to set a timeout
1644 * larger than 3 seconds.
1646 * By default, the normal timeout is set to 800 ms, and the application startup
1647 * timeout is set to 15 seconds.
1650 atspi_set_timeout (gint val, gint startup_time)
1652 method_call_timeout = val;
1653 app_startup_time = startup_time;
1657 * atspi_set_main_context:
1658 * @cnx: The #GMainContext to use.
1660 * Sets the main loop context that AT-SPI should assume is in use when
1661 * setting an idle callback.
1662 * This function should be called by application-side implementors (ie,
1663 * at-spi2-atk) when it is desirable to re-enter the main loop.
1666 atspi_set_main_context (GMainContext *cnx)
1668 if (atspi_main_context == cnx)
1670 if (process_deferred_messages_source != NULL)
1672 g_source_destroy (process_deferred_messages_source);
1673 process_deferred_messages_source = g_idle_source_new ();
1674 g_source_set_callback (process_deferred_messages_source,
1675 process_deferred_messages_callback, NULL, NULL);
1676 g_source_attach (process_deferred_messages_source, cnx);
1677 g_source_unref (process_deferred_messages_source);
1679 atspi_main_context = cnx;
1680 atspi_dbus_connection_setup_with_g_main (atspi_get_a11y_bus (), cnx);
1685 for (i = desktop->children->len - 1; i >= 0; i--)
1687 AtspiAccessible *child = g_ptr_array_index (desktop->children, i);
1688 if (child->parent.app && child->parent.app->bus)
1689 atspi_dbus_connection_setup_with_g_main (child->parent.app->bus, cnx);
1694 #ifdef DEBUG_REF_COUNTS
1696 print_disposed (gpointer key, gpointer value, gpointer data)
1698 AtspiAccessible *accessible = key;
1699 if (accessible->parent.app)
1701 g_print ("disposed: %s %d\n", accessible->name, accessible->role);
1707 g_hash_table_foreach (live_refs, print_disposed, NULL);
1712 _atspi_name_compat (gchar *name)
1726 * atspi_role_get_name:
1727 * @role: an #AtspiRole object to query.
1729 * Gets a localizable string that indicates the name of an #AtspiRole.
1730 * <em>DEPRECATED.</em>
1732 * Returns: a localizable string name for an #AtspiRole enumerated type.
1735 atspi_role_get_name (AtspiRole role)
1737 gchar *retval = NULL;
1738 GTypeClass *type_class;
1741 type_class = g_type_class_ref (ATSPI_TYPE_ROLE);
1742 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1744 value = g_enum_get_value (G_ENUM_CLASS (type_class), role);
1748 retval = g_strdup (value->value_nick);
1751 g_type_class_unref (type_class);
1754 return _atspi_name_compat (retval);
1760 _atspi_dbus_update_cache_from_dict (AtspiAccessible *accessible, DBusMessageIter *iter)
1762 GHashTable *cache = _atspi_accessible_ref_cache (accessible);
1763 DBusMessageIter iter_dict, iter_dict_entry, iter_struct, iter_variant;
1765 dbus_message_iter_recurse (iter, &iter_dict);
1766 while (dbus_message_iter_get_arg_type (&iter_dict) != DBUS_TYPE_INVALID)
1770 dbus_message_iter_recurse (&iter_dict, &iter_dict_entry);
1771 dbus_message_iter_get_basic (&iter_dict_entry, &key);
1772 dbus_message_iter_next (&iter_dict_entry);
1773 dbus_message_iter_recurse (&iter_dict_entry, &iter_variant);
1774 if (!strcmp (key, "interfaces"))
1776 _atspi_dbus_set_interfaces (accessible, &iter_variant);
1778 else if (!strcmp (key, "Attributes"))
1780 char *iter_sig = dbus_message_iter_get_signature (&iter_variant);
1781 val = g_new0 (GValue, 1);;
1782 g_value_init (val, G_TYPE_HASH_TABLE);
1783 if (strcmp (iter_sig, "a{ss}") != 0)
1785 dbus_free (iter_sig);
1788 dbus_free (iter_sig);
1789 g_value_take_boxed (val, _atspi_dbus_hash_from_iter (&iter_variant));
1791 else if (!strcmp (key, "Component.ScreenExtents"))
1795 char *iter_sig = dbus_message_iter_get_signature (&iter_variant);
1796 val = g_new0 (GValue, 1);;
1797 g_value_init (val, ATSPI_TYPE_RECT);
1798 if (strcmp (iter_sig, "(iiii)") != 0)
1800 dbus_free (iter_sig);
1803 dbus_free (iter_sig);
1804 dbus_message_iter_recurse (&iter_variant, &iter_struct);
1805 dbus_message_iter_get_basic (&iter_struct, &d_int);
1807 dbus_message_iter_next (&iter_struct);
1808 dbus_message_iter_get_basic (&iter_struct, &d_int);
1810 dbus_message_iter_next (&iter_struct);
1811 dbus_message_iter_get_basic (&iter_struct, &d_int);
1812 extents.width = d_int;
1813 dbus_message_iter_next (&iter_struct);
1814 dbus_message_iter_get_basic (&iter_struct, &d_int);
1815 extents.height = d_int;
1816 g_value_set_boxed (val, &extents);
1819 g_hash_table_insert (cache, g_strdup (key), val);
1820 dbus_message_iter_next (&iter_dict);
1827 _atspi_get_allow_sync ()
1833 _atspi_set_allow_sync (gboolean val)
1835 gboolean ret = allow_sync;
1842 _atspi_set_error_no_sync (GError **error)
1844 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_SYNC_NOT_ALLOWED,
1845 _("Attempted synchronous call where prohibited"));