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;
185 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
187 if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &address,
188 DBUS_TYPE_INVALID) && address [0])
193 dbus_error_init (&error);
194 bus = dbus_connection_open_private (address, &error);
199 dbus_connection_unref (app->bus);
202 atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default());
206 if (!strcmp (error.name, DBUS_ERROR_FILE_NOT_FOUND))
207 g_warning ("AT-SPI: Unable to open bus connection: %s", error.message);
208 dbus_error_free (&error);
212 dbus_message_unref (reply);
213 dbus_pending_call_unref (pending);
216 return; /* application has gone away / been disposed */
218 message = dbus_message_new_method_call (app->bus_name,
219 "/org/a11y/atspi/cache",
220 atspi_interface_cache, "GetItems");
222 result = dbus_connection_send_with_reply (app->bus, message, &new_pending, 2000);
223 dbus_message_unref (message);
224 if (!result || !new_pending)
226 dbus_pending_call_set_notify (new_pending, handle_get_items, app, NULL);
229 static AtspiApplication *
230 get_application (const char *bus_name)
232 AtspiApplication *app = NULL;
234 DBusMessage *message;
235 DBusPendingCall *pending = NULL;
240 app_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref);
241 if (!app_hash) return NULL;
243 app = g_hash_table_lookup (app_hash, bus_name);
245 bus_name_dup = g_strdup (bus_name);
246 if (!bus_name_dup) return NULL;
247 // TODO: change below to something that will send state-change:defunct notification if necessary */
248 app = _atspi_application_new (bus_name);
249 app->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
250 app->bus = dbus_connection_ref (_atspi_bus ());
251 gettimeofday (&app->time_added, NULL);
252 app->cache = ATSPI_CACHE_UNDEFINED;
253 g_hash_table_insert (app_hash, bus_name_dup, app);
254 message = dbus_message_new_method_call (bus_name, atspi_path_root,
255 atspi_interface_application, "GetApplicationBusAddress");
257 result = dbus_connection_send_with_reply (app->bus, message, &pending, 2000);
258 dbus_message_unref (message);
259 if (!result || !pending)
261 g_hash_table_remove (app_hash, bus_name_dup);
264 dbus_pending_call_set_notify (pending, handle_get_bus_address, app, NULL);
269 ref_accessible (const char *app_name, const char *path)
271 AtspiApplication *app;
274 if (!strcmp (path, ATSPI_DBUS_PATH_NULL))
277 app = get_application (app_name);
279 if (!strcmp (path, "/org/a11y/atspi/accessible/root"))
283 app->root = _atspi_accessible_new (app, atspi_path_root);
284 app->root->accessible_parent = atspi_get_desktop (0);
285 g_ptr_array_add (app->root->accessible_parent->children, g_object_ref (app->root));
287 return g_object_ref (app->root);
290 a = g_hash_table_lookup (app->hash, path);
293 return g_object_ref (a);
295 a = _atspi_accessible_new (app, path);
298 g_hash_table_insert (app->hash, g_strdup (a->parent.path), g_object_ref (a));
302 static AtspiHyperlink *
303 ref_hyperlink (const char *app_name, const char *path)
305 AtspiApplication *app = get_application (app_name);
306 AtspiHyperlink *hyperlink;
308 if (!strcmp (path, ATSPI_DBUS_PATH_NULL))
311 hyperlink = g_hash_table_lookup (app->hash, path);
314 return g_object_ref (hyperlink);
316 hyperlink = _atspi_hyperlink_new (app, path);
317 g_hash_table_insert (app->hash, g_strdup (hyperlink->parent.path), hyperlink);
318 /* TODO: This should be a weak ref */
319 g_object_ref (hyperlink); /* for the hash */
332 GArray *state_bitflags;
335 static DBusHandlerResult
336 handle_remove_accessible (DBusConnection *bus, DBusMessage *message, void *user_data)
338 const char *sender = dbus_message_get_sender (message);
339 AtspiApplication *app;
341 DBusMessageIter iter, iter_struct;
342 const char *signature = dbus_message_get_signature (message);
345 if (strcmp (signature, "(so)") != 0)
347 g_warning ("AT-SPI: Unknown signature %s for RemoveAccessible", signature);
348 return DBUS_HANDLER_RESULT_HANDLED;
351 dbus_message_iter_init (message, &iter);
352 dbus_message_iter_recurse (&iter, &iter_struct);
353 dbus_message_iter_get_basic (&iter_struct, &sender);
354 dbus_message_iter_next (&iter_struct);
355 dbus_message_iter_get_basic (&iter_struct, &path);
356 app = get_application (sender);
357 a = ref_accessible (sender, path);
359 return DBUS_HANDLER_RESULT_HANDLED;
360 g_object_run_dispose (G_OBJECT (a));
361 g_hash_table_remove (app->hash, a->parent.path);
362 g_object_unref (a); /* unref our own ref */
363 return DBUS_HANDLER_RESULT_HANDLED;
366 static DBusHandlerResult
367 handle_name_owner_changed (DBusConnection *bus, DBusMessage *message, void *user_data)
369 const char *name, *new, *old;
370 static gboolean registry_lost = FALSE;
372 if (!dbus_message_get_args (message, NULL,
373 DBUS_TYPE_STRING, &name,
374 DBUS_TYPE_STRING, &old,
375 DBUS_TYPE_STRING, &new,
378 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
381 if (!strcmp (name, "org.a11y.atspi.Registry"))
383 if (registry_lost && !old[0])
385 _atspi_reregister_event_listeners ();
386 _atspi_reregister_device_listeners ();
387 registry_lost = FALSE;
390 registry_lost = TRUE;
394 AtspiApplication *app = g_hash_table_lookup (app_hash, old);
395 if (app && app->bus_name && !strcmp(app->bus_name, name))
396 g_object_run_dispose (G_OBJECT (app));
398 return DBUS_HANDLER_RESULT_HANDLED;
402 add_app_to_desktop (AtspiAccessible *a, const char *bus_name)
404 AtspiAccessible *obj = ref_accessible (bus_name, atspi_path_root);
405 /* The app will be added to the desktop as a side-effect of calling
407 g_object_unref (obj);
408 return (obj != NULL);
412 get_reference_from_iter (DBusMessageIter *iter, const char **app_name, const char **path)
414 DBusMessageIter iter_struct;
416 dbus_message_iter_recurse (iter, &iter_struct);
417 dbus_message_iter_get_basic (&iter_struct, app_name);
418 dbus_message_iter_next (&iter_struct);
419 dbus_message_iter_get_basic (&iter_struct, path);
420 dbus_message_iter_next (iter);
424 add_accessible_from_iter (DBusMessageIter *iter)
426 DBusMessageIter iter_struct, iter_array;
427 const char *app_name, *path;
428 AtspiAccessible *accessible;
429 const char *name, *description;
431 gboolean children_cached = FALSE;
432 dbus_int32_t count, index;
434 dbus_message_iter_recurse (iter, &iter_struct);
437 get_reference_from_iter (&iter_struct, &app_name, &path);
438 accessible = ref_accessible (app_name, path);
442 /* Get application: TODO */
443 dbus_message_iter_next (&iter_struct);
446 get_reference_from_iter (&iter_struct, &app_name, &path);
447 if (accessible->accessible_parent)
448 g_object_unref (accessible->accessible_parent);
449 accessible->accessible_parent = ref_accessible (app_name, path);
451 if (dbus_message_iter_get_arg_type (&iter_struct) == 'i')
453 /* Get index in parent */
454 dbus_message_iter_get_basic (&iter_struct, &index);
455 if (index >= 0 && accessible->accessible_parent)
457 if (index >= accessible->accessible_parent->children->len)
458 g_ptr_array_set_size (accessible->accessible_parent->children, index + 1);
459 g_ptr_array_index (accessible->accessible_parent->children, index) = g_object_ref (accessible);
462 /* get child count */
463 dbus_message_iter_next (&iter_struct);
464 dbus_message_iter_get_basic (&iter_struct, &count);
467 g_ptr_array_set_size (accessible->children, count);
468 children_cached = TRUE;
471 else if (dbus_message_iter_get_arg_type (&iter_struct) == 'a')
473 /* It's the old API with a list of children */
474 /* TODO: Perhaps remove this code eventually */
475 dbus_message_iter_recurse (&iter_struct, &iter_array);
476 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
478 AtspiAccessible *child;
479 get_reference_from_iter (&iter_array, &app_name, &path);
480 child = ref_accessible (app_name, path);
481 g_ptr_array_remove (accessible->children, child);
482 g_ptr_array_add (accessible->children, child);
484 children_cached = TRUE;
488 dbus_message_iter_next (&iter_struct);
489 _atspi_dbus_set_interfaces (accessible, &iter_struct);
490 dbus_message_iter_next (&iter_struct);
493 if (accessible->name)
494 g_free (accessible->name);
495 dbus_message_iter_get_basic (&iter_struct, &name);
496 accessible->name = g_strdup (name);
497 dbus_message_iter_next (&iter_struct);
500 dbus_message_iter_get_basic (&iter_struct, &role);
501 accessible->role = role;
502 dbus_message_iter_next (&iter_struct);
505 if (accessible->description)
506 g_free (accessible->description);
507 dbus_message_iter_get_basic (&iter_struct, &description);
508 accessible->description = g_strdup (description);
509 dbus_message_iter_next (&iter_struct);
511 _atspi_dbus_set_state (accessible, &iter_struct);
512 dbus_message_iter_next (&iter_struct);
514 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_NAME | ATSPI_CACHE_ROLE |
515 ATSPI_CACHE_PARENT | ATSPI_CACHE_DESCRIPTION);
516 if (!atspi_state_set_contains (accessible->states,
517 ATSPI_STATE_MANAGES_DESCENDANTS) &&
519 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_CHILDREN);
521 /* This is a bit of a hack since the cache holds a ref, so we don't need
522 * the one provided for us anymore */
523 g_object_unref (accessible);
527 handle_get_items (DBusPendingCall *pending, void *user_data)
529 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
530 DBusMessageIter iter, iter_array;
532 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
534 const char *sender = dbus_message_get_sender (reply);
535 const char *error = NULL;
536 if (!strcmp (dbus_message_get_error_name (reply),
537 DBUS_ERROR_SERVICE_UNKNOWN))
542 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &error,
544 g_warning ("AT-SPI: Error in GetItems, sender=%s, error=%s", sender, error);
546 dbus_message_unref (reply);
547 dbus_pending_call_unref (pending);
551 dbus_message_iter_init (reply, &iter);
552 dbus_message_iter_recurse (&iter, &iter_array);
553 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
555 add_accessible_from_iter (&iter_array);
556 dbus_message_iter_next (&iter_array);
558 dbus_message_unref (reply);
559 dbus_pending_call_unref (pending);
562 /* TODO: Do we stil need this function? */
563 static AtspiAccessible *
564 ref_accessible_desktop (AtspiApplication *app)
567 DBusMessage *message, *reply;
568 DBusMessageIter iter, iter_array;
573 g_object_ref (desktop);
576 desktop = _atspi_accessible_new (app, atspi_path_root);
581 g_hash_table_insert (app->hash, g_strdup (desktop->parent.path),
582 g_object_ref (desktop));
583 app->root = g_object_ref (desktop);
584 desktop->name = g_strdup ("main");
585 message = dbus_message_new_method_call (atspi_bus_registry,
587 atspi_interface_accessible,
592 reply = _atspi_dbus_send_with_reply_and_block (message, &error);
593 if (!reply || strcmp (dbus_message_get_signature (reply), "a(so)") != 0)
597 g_warning ("Couldn't get application list: %s", error->message);
598 g_clear_error (&error);
601 dbus_message_unref (reply);
604 dbus_message_iter_init (reply, &iter);
605 dbus_message_iter_recurse (&iter, &iter_array);
606 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
608 const char *app_name, *path;
609 get_reference_from_iter (&iter_array, &app_name, &path);
610 add_app_to_desktop (desktop, app_name);
613 /* Record the alternate name as an alias for org.a11y.atspi.Registry */
614 bus_name_dup = g_strdup (dbus_message_get_sender (reply));
616 g_hash_table_insert (app_hash, bus_name_dup, app);
618 dbus_message_unref (reply);
620 return g_object_ref (desktop);
624 _atspi_ref_accessible (const char *app, const char *path)
626 AtspiApplication *a = get_application (app);
629 if ( APP_IS_REGISTRY(a))
632 g_object_unref (ref_accessible_desktop (a)); /* sets a->root */
633 return g_object_ref (a->root);
635 return ref_accessible (app, path);
639 _atspi_dbus_return_accessible_from_message (DBusMessage *message)
641 DBusMessageIter iter;
642 AtspiAccessible *retval = NULL;
643 const char *signature;
648 signature = dbus_message_get_signature (message);
649 if (!strcmp (signature, "(so)"))
651 dbus_message_iter_init (message, &iter);
652 retval = _atspi_dbus_return_accessible_from_iter (&iter);
656 g_warning ("AT-SPI: Called _atspi_dbus_return_accessible_from_message with strange signature %s", signature);
658 dbus_message_unref (message);
663 _atspi_dbus_return_accessible_from_iter (DBusMessageIter *iter)
665 const char *app_name, *path;
667 get_reference_from_iter (iter, &app_name, &path);
668 return ref_accessible (app_name, path);
672 _atspi_dbus_return_hyperlink_from_message (DBusMessage *message)
674 DBusMessageIter iter;
675 AtspiHyperlink *retval = NULL;
676 const char *signature;
681 signature = dbus_message_get_signature (message);
682 if (!strcmp (signature, "(so)"))
684 dbus_message_iter_init (message, &iter);
685 retval = _atspi_dbus_return_hyperlink_from_iter (&iter);
689 g_warning ("AT-SPI: Called _atspi_dbus_return_hyperlink_from_message with strange signature %s", signature);
691 dbus_message_unref (message);
696 _atspi_dbus_return_hyperlink_from_iter (DBusMessageIter *iter)
698 const char *app_name, *path;
700 get_reference_from_iter (iter, &app_name, &path);
701 return ref_hyperlink (app_name, path);
704 const char *cache_signal_type = "((so)(so)(so)iiassusau)";
705 const char *old_cache_signal_type = "((so)(so)(so)a(so)assusau)";
707 static DBusHandlerResult
708 handle_add_accessible (DBusConnection *bus, DBusMessage *message, void *user_data)
710 DBusMessageIter iter;
711 const char *signature = dbus_message_get_signature (message);
713 if (strcmp (signature, cache_signal_type) != 0 &&
714 strcmp (signature, old_cache_signal_type) != 0)
716 g_warning ("AT-SPI: AddAccessible with unknown signature %s\n", signature);
717 return DBUS_HANDLER_RESULT_HANDLED;
720 dbus_message_iter_init (message, &iter);
721 add_accessible_from_iter (&iter);
722 return DBUS_HANDLER_RESULT_HANDLED;
728 DBusMessage *message;
732 static GSource *process_deferred_messages_source = NULL;
735 process_deferred_message (BusDataClosure *closure)
737 int type = dbus_message_get_type (closure->message);
738 const char *interface = dbus_message_get_interface (closure->message);
740 if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
741 !strncmp (interface, "org.a11y.atspi.Event.", 21))
743 _atspi_dbus_handle_event (closure->bus, closure->message, closure->data);
745 if (dbus_message_is_method_call (closure->message, atspi_interface_device_event_listener, "NotifyEvent"))
747 _atspi_dbus_handle_DeviceEvent (closure->bus,
748 closure->message, closure->data);
750 if (dbus_message_is_signal (closure->message, atspi_interface_cache, "AddAccessible"))
752 handle_add_accessible (closure->bus, closure->message, closure->data);
754 if (dbus_message_is_signal (closure->message, atspi_interface_cache, "RemoveAccessible"))
756 handle_remove_accessible (closure->bus, closure->message, closure->data);
758 if (dbus_message_is_signal (closure->message, "org.freedesktop.DBus", "NameOwnerChanged"))
760 handle_name_owner_changed (closure->bus, closure->message, closure->data);
764 static GQueue *deferred_messages = NULL;
767 process_deferred_messages (void)
769 static int in_process_deferred_messages = 0;
770 BusDataClosure *closure;
772 if (in_process_deferred_messages)
774 in_process_deferred_messages = 1;
775 while ((closure = g_queue_pop_head (deferred_messages)))
777 process_deferred_message (closure);
778 dbus_message_unref (closure->message);
779 dbus_connection_unref (closure->bus);
782 in_process_deferred_messages = 0;
787 process_deferred_messages_callback (gpointer data)
789 if (process_deferred_messages ())
790 return G_SOURCE_CONTINUE;
792 process_deferred_messages_source = NULL;
793 return G_SOURCE_REMOVE;
796 static DBusHandlerResult
797 defer_message (DBusConnection *connection, DBusMessage *message, void *user_data)
799 BusDataClosure *closure = g_new (BusDataClosure, 1);
801 closure->bus = dbus_connection_ref (bus);
802 closure->message = dbus_message_ref (message);
803 closure->data = user_data;
805 g_queue_push_tail (deferred_messages, closure);
807 if (process_deferred_messages_source == NULL)
809 process_deferred_messages_source = g_idle_source_new ();
810 g_source_set_callback (process_deferred_messages_source,
811 process_deferred_messages_callback, NULL, NULL);
812 g_source_attach (process_deferred_messages_source, atspi_main_context);
813 g_source_unref (process_deferred_messages_source);
816 return DBUS_HANDLER_RESULT_HANDLED;
819 static DBusHandlerResult
820 atspi_dbus_filter (DBusConnection *bus, DBusMessage *message, void *data)
822 int type = dbus_message_get_type (message);
823 const char *interface = dbus_message_get_interface (message);
825 if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
826 !strncmp (interface, "org.a11y.atspi.Event.", 21))
828 return defer_message (bus, message, data);
830 if (dbus_message_is_method_call (message, atspi_interface_device_event_listener, "NotifyEvent"))
832 return defer_message (bus, message, data);
834 if (dbus_message_is_signal (message, atspi_interface_cache, "AddAccessible"))
836 return defer_message (bus, message, data);
838 if (dbus_message_is_signal (message, atspi_interface_cache, "RemoveAccessible"))
840 return defer_message (bus, message, data);
842 if (dbus_message_is_signal (message, "org.freedesktop.DBus", "NameOwnerChanged"))
844 defer_message (bus, message, data);
845 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
847 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
851 * Returns a 'canonicalized' value for DISPLAY,
852 * with the screen number stripped off if present.
854 * TODO: Avoid having duplicate functions for this here and in at-spi2-atk
857 spi_display_name (void)
859 char *canonical_display_name = NULL;
860 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
864 display_env = g_getenv ("DISPLAY");
865 if (!display_env || !display_env[0])
869 gchar *display_p, *screen_p;
870 canonical_display_name = g_strdup (display_env);
871 display_p = g_utf8_strrchr (canonical_display_name, -1, ':');
872 screen_p = g_utf8_strrchr (canonical_display_name, -1, '.');
873 if (screen_p && display_p && (screen_p > display_p))
881 canonical_display_name = g_strdup (display_env);
884 return canonical_display_name;
890 * Connects to the accessibility registry and initializes the SPI.
892 * Returns: 0 on success, 1 if already initialized, or an integer error code.
898 const gchar *no_cache;
907 _atspi_get_live_refs();
909 bus = atspi_get_a11y_bus ();
912 if (!dbus_bus_register (bus, NULL))
914 atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default());
915 dbus_connection_add_filter (bus, atspi_dbus_filter, NULL, NULL);
916 match = g_strdup_printf ("type='signal',interface='%s',member='AddAccessible'", atspi_interface_cache);
917 dbus_bus_add_match (bus, match, NULL);
919 match = g_strdup_printf ("type='signal',interface='%s',member='RemoveAccessible'", atspi_interface_cache);
920 dbus_bus_add_match (bus, match, NULL);
922 match = g_strdup_printf ("type='signal',interface='%s',member='ChildrenChanged'", atspi_interface_event_object);
923 dbus_bus_add_match (bus, match, NULL);
925 match = g_strdup_printf ("type='signal',interface='%s',member='PropertyChange'", atspi_interface_event_object);
926 dbus_bus_add_match (bus, match, NULL);
928 match = g_strdup_printf ("type='signal',interface='%s',member='StateChanged'", atspi_interface_event_object);
929 dbus_bus_add_match (bus, match, NULL);
932 dbus_bus_add_match (bus,
933 "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged'",
936 no_cache = g_getenv ("ATSPI_NO_CACHE");
937 if (no_cache && g_strcmp0 (no_cache, "0") != 0)
938 atspi_no_cache = TRUE;
940 deferred_messages = g_queue_new ();
946 * atspi_is_initialized:
948 * Indicates whether AT-SPI has been initialized.
950 * Returns: %True if initialized; %False otherwise.
953 atspi_is_initialized ()
961 * Starts/enters the main event loop for the AT-SPI services.
963 * NOTE: This method does not return control; it is exited via a call to
964 * #atspi_event_quit from within an event handler.
968 atspi_event_main (void)
970 atspi_main_loop = g_main_loop_new (NULL, FALSE);
971 g_main_loop_run (atspi_main_loop);
972 atspi_main_loop = NULL;
978 * Quits the last main event loop for the AT-SPI services,
979 * See: #atspi_event_main
982 atspi_event_quit (void)
984 g_main_loop_quit (atspi_main_loop);
990 * Disconnects from #AtspiRegistry instances and releases
991 * any floating resources. Call only once at exit.
993 * Returns: 0 if there were no leaks, otherwise other integer values.
1005 atspi_inited = FALSE;
1009 leaked = g_hash_table_size (live_refs);
1021 static GSList *hung_processes;
1024 remove_hung_process (DBusPendingCall *pending, void *data)
1026 hung_processes = g_slist_remove (hung_processes, data);
1028 dbus_pending_call_unref (pending);
1032 check_for_hang (DBusMessage *message, DBusError *error, DBusConnection *bus, const char *bus_name)
1034 if (!message && error->name &&
1035 !strcmp (error->name, "org.freedesktop.DBus.Error.NoReply"))
1038 DBusMessage *message;
1039 gchar *bus_name_dup;
1040 DBusPendingCall *pending = NULL;
1042 for (l = hung_processes; l; l = l->next)
1043 if (!strcmp (l->data, bus_name))
1045 message = dbus_message_new_method_call (bus_name, "/",
1046 "org.freedesktop.DBus.Peer",
1050 result = dbus_connection_send_with_reply (bus, message, &pending, -1);
1051 dbus_message_unref (message);
1052 if (!result || !pending)
1054 bus_name_dup = g_strdup (bus_name);
1055 hung_processes = g_slist_append (hung_processes, bus_name_dup);
1056 dbus_pending_call_set_notify (pending, remove_hung_process, bus_name_dup, NULL);
1061 connection_is_hung (const char *bus_name)
1065 for (l = hung_processes; l; l = l->next)
1066 if (!strcmp (l->data, bus_name))
1072 check_app (AtspiApplication *app, GError **error)
1074 if (!app || !app->bus)
1076 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_APPLICATION_GONE,
1077 _("The application no longer exists"));
1081 if (atspi_main_loop && connection_is_hung (app->bus_name))
1083 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC,
1084 "The process appears to be hung.");
1092 set_timeout (AtspiApplication *app)
1097 if (app && app_startup_time > 0)
1099 gettimeofday (&tv, NULL);
1100 diff = (tv.tv_sec - app->time_added.tv_sec) * 1000 + (tv.tv_usec - app->time_added.tv_usec) / 1000;
1101 dbind_set_timeout (MAX(method_call_timeout, app_startup_time - diff));
1104 dbind_set_timeout (method_call_timeout);
1108 _atspi_dbus_call (gpointer obj, const char *interface, const char *method, GError **error, const char *type, ...)
1113 AtspiObject *aobj = ATSPI_OBJECT (obj);
1115 if (!check_app (aobj->app, error))
1120 _atspi_set_error_no_sync (error);
1124 va_start (args, type);
1125 dbus_error_init (&err);
1126 set_timeout (aobj->app);
1127 retval = dbind_method_call_reentrant_va (aobj->app->bus, aobj->app->bus_name,
1128 aobj->path, interface, method, &err,
1131 check_for_hang (NULL, &err, aobj->app->bus, aobj->app->bus_name);
1132 process_deferred_messages ();
1133 if (dbus_error_is_set (&err))
1135 g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "%s", err.message);
1136 dbus_error_free (&err);
1142 _atspi_dbus_call_partial (gpointer obj,
1143 const char *interface,
1146 const char *type, ...)
1149 DBusMessage * result;
1150 va_start (args, type);
1151 result = _atspi_dbus_call_partial_va (obj, interface, method, error, type, args);
1158 _atspi_dbus_call_partial_va (gpointer obj,
1159 const char *interface,
1165 AtspiObject *aobj = ATSPI_OBJECT (obj);
1167 DBusMessage *msg = NULL, *reply = NULL;
1168 DBusMessageIter iter;
1171 dbus_error_init (&err);
1173 if (!check_app (aobj->app, error))
1176 msg = dbus_message_new_method_call (aobj->app->bus_name, aobj->path, interface, method);
1181 dbus_message_iter_init_append (msg, &iter);
1182 dbind_any_marshal_va (&iter, &p, args);
1184 set_timeout (aobj->app);
1185 reply = dbind_send_and_allow_reentry (aobj->app->bus, msg, &err);
1186 check_for_hang (reply, &err, aobj->app->bus, aobj->app->bus_name);
1190 dbus_message_unref (msg);
1191 process_deferred_messages ();
1192 if (dbus_error_is_set (&err))
1194 g_set_error_literal(error, ATSPI_ERROR, ATSPI_ERROR_IPC, err.message);
1195 dbus_error_free (&err);
1197 dbus_message_unref(reply);
1200 else if (reply && dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
1202 const char *err_str = NULL;
1203 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err_str, DBUS_TYPE_INVALID);
1205 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err_str);
1206 dbus_message_unref (reply);
1213 _atspi_dbus_get_property (gpointer obj, const char *interface, const char *name, GError **error, const char *type, void *data)
1215 DBusMessage *message, *reply;
1216 DBusMessageIter iter, iter_variant;
1218 dbus_bool_t retval = FALSE;
1219 AtspiObject *aobj = ATSPI_OBJECT (obj);
1220 char expected_type = (type [0] == '(' ? 'r' : type [0]);
1225 if (!check_app (aobj->app, error))
1230 _atspi_set_error_no_sync (error);
1234 message = dbus_message_new_method_call (aobj->app->bus_name,
1236 "org.freedesktop.DBus.Properties",
1240 // TODO: throw exception
1243 dbus_message_append_args (message, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
1244 dbus_error_init (&err);
1245 set_timeout (aobj->app);
1246 reply = dbind_send_and_allow_reentry (aobj->app->bus, message, &err);
1247 check_for_hang (reply, &err, aobj->app->bus, aobj->app->bus_name);
1248 dbus_message_unref (message);
1249 process_deferred_messages ();
1252 // TODO: throw exception
1256 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
1258 const char *err_str = NULL;
1259 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err_str, DBUS_TYPE_INVALID);
1261 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err_str);
1265 dbus_message_iter_init (reply, &iter);
1266 if (dbus_message_iter_get_arg_type (&iter) != 'v')
1268 g_warning ("atspi_dbus_get_property: expected a variant when fetching %s from interface %s; got %s\n", name, interface, dbus_message_get_signature (reply));
1271 dbus_message_iter_recurse (&iter, &iter_variant);
1272 if (dbus_message_iter_get_arg_type (&iter_variant) != expected_type)
1274 g_warning ("atspi_dbus_get_property: Wrong type: expected %s, got %c\n", type, dbus_message_iter_get_arg_type (&iter_variant));
1277 if (!strcmp (type, "(so)"))
1279 *((AtspiAccessible **)data) = _atspi_dbus_return_accessible_from_iter (&iter_variant);
1283 dbus_message_iter_get_basic (&iter_variant, data);
1284 if (type [0] == 's')
1285 *(char **)data = g_strdup (*(char **)data);
1289 dbus_error_free (&err);
1291 dbus_message_unref (reply);
1296 _atspi_dbus_send_with_reply_and_block (DBusMessage *message, GError **error)
1300 AtspiApplication *app;
1301 DBusConnection *bus;
1303 app = get_application (dbus_message_get_destination (message));
1305 if (app && !app->bus)
1306 return NULL; /* will fail anyway; app has been disposed */
1308 bus = (app ? app->bus : _atspi_bus());
1309 dbus_error_init (&err);
1311 reply = dbind_send_and_allow_reentry (bus, message, &err);
1312 process_deferred_messages ();
1313 dbus_message_unref (message);
1314 if (dbus_error_is_set (&err))
1317 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err.message);
1318 dbus_error_free (&err);
1324 _atspi_dbus_return_hash_from_message (DBusMessage *message)
1326 DBusMessageIter iter;
1332 _ATSPI_DBUS_CHECK_SIG (message, "a{ss}", NULL, NULL);
1334 dbus_message_iter_init (message, &iter);
1335 ret = _atspi_dbus_hash_from_iter (&iter);
1336 dbus_message_unref (message);
1341 _atspi_dbus_hash_from_iter (DBusMessageIter *iter)
1343 GHashTable *hash = g_hash_table_new_full (g_str_hash, g_str_equal,
1344 (GDestroyNotify) g_free,
1345 (GDestroyNotify) g_free);
1346 DBusMessageIter iter_array, iter_dict;
1348 dbus_message_iter_recurse (iter, &iter_array);
1349 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1351 const char *name, *value;
1352 dbus_message_iter_recurse (&iter_array, &iter_dict);
1353 dbus_message_iter_get_basic (&iter_dict, &name);
1354 dbus_message_iter_next (&iter_dict);
1355 dbus_message_iter_get_basic (&iter_dict, &value);
1356 g_hash_table_insert (hash, g_strdup (name), g_strdup (value));
1357 dbus_message_iter_next (&iter_array);
1363 _atspi_dbus_return_attribute_array_from_message (DBusMessage *message)
1365 DBusMessageIter iter;
1371 _ATSPI_DBUS_CHECK_SIG (message, "a{ss}", NULL, NULL);
1373 dbus_message_iter_init (message, &iter);
1375 ret = _atspi_dbus_attribute_array_from_iter (&iter);
1376 dbus_message_unref (message);
1381 _atspi_dbus_attribute_array_from_iter (DBusMessageIter *iter)
1383 DBusMessageIter iter_array, iter_dict;
1384 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
1386 dbus_message_iter_recurse (iter, &iter_array);
1387 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1389 const char *name, *value;
1391 dbus_message_iter_recurse (&iter_array, &iter_dict);
1392 dbus_message_iter_get_basic (&iter_dict, &name);
1393 dbus_message_iter_next (&iter_dict);
1394 dbus_message_iter_get_basic (&iter_dict, &value);
1395 str = g_strdup_printf ("%s:%s", name, value);
1396 array = g_array_append_val (array, str);
1397 dbus_message_iter_next (&iter_array);;
1403 _atspi_dbus_set_interfaces (AtspiAccessible *accessible, DBusMessageIter *iter)
1405 DBusMessageIter iter_array;
1406 char *iter_sig = dbus_message_iter_get_signature (iter);
1408 accessible->interfaces = 0;
1409 if (strcmp (iter_sig, "as") != 0)
1411 g_warning ("_atspi_dbus_set_interfaces: Passed iterator with invalid signature %s", dbus_message_iter_get_signature (iter));
1412 dbus_free (iter_sig);
1415 dbus_free (iter_sig);
1416 dbus_message_iter_recurse (iter, &iter_array);
1417 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1421 dbus_message_iter_get_basic (&iter_array, &iface);
1422 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable")) continue;
1423 n = _atspi_get_iface_num (iface);
1426 g_warning ("AT-SPI: Unknown interface %s", iface);
1429 accessible->interfaces |= (1 << n);
1430 dbus_message_iter_next (&iter_array);
1432 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
1436 _atspi_dbus_set_state (AtspiAccessible *accessible, DBusMessageIter *iter)
1438 DBusMessageIter iter_array;
1440 dbus_uint32_t *states;
1442 dbus_message_iter_recurse (iter, &iter_array);
1443 dbus_message_iter_get_fixed_array (&iter_array, &states, &count);
1446 g_warning ("AT-SPI: expected 2 values in states array; got %d\n", count);
1447 if (!accessible->states)
1448 accessible->states = _atspi_state_set_new_internal (accessible, 0);
1452 guint64 val = ((guint64)states [1]) << 32;
1454 if (!accessible->states)
1455 accessible->states = _atspi_state_set_new_internal (accessible, val);
1457 accessible->states->states = val;
1459 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_STATES);
1463 _atspi_error_quark (void)
1465 return g_quark_from_static_string ("atspi_error");
1469 * Gets the IOR from the XDisplay.
1473 get_accessibility_bus_address_x11 (void)
1477 Display *bridge_display = NULL;
1480 unsigned char *data_x11 = NULL;
1481 unsigned long nitems;
1482 unsigned long leftover;
1485 display_name = spi_display_name ();
1489 bridge_display = XOpenDisplay (display_name);
1490 g_free (display_name);
1492 if (!bridge_display)
1494 g_warning ("Could not open X display");
1498 AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
1499 XGetWindowProperty (bridge_display,
1500 XDefaultRootWindow (bridge_display),
1502 (long) BUFSIZ, False,
1503 (Atom) 31, &actual_type, &actual_format,
1504 &nitems, &leftover, &data_x11);
1505 XCloseDisplay (bridge_display);
1507 data = g_strdup ((gchar *)data_x11);
1514 get_accessibility_bus_address_dbus (void)
1516 DBusConnection *session_bus = NULL;
1517 DBusMessage *message;
1520 char *address = NULL;
1522 session_bus = dbus_bus_get (DBUS_BUS_SESSION, NULL);
1526 message = dbus_message_new_method_call ("org.a11y.Bus",
1531 dbus_error_init (&error);
1532 reply = dbus_connection_send_with_reply_and_block (session_bus,
1536 dbus_message_unref (message);
1540 g_warning ("AT-SPI: Error retrieving accessibility bus address: %s: %s",
1541 error.name, error.message);
1542 dbus_error_free (&error);
1547 const char *tmp_address;
1548 if (!dbus_message_get_args (reply,
1554 dbus_message_unref (reply);
1557 address = g_strdup (tmp_address);
1558 dbus_message_unref (reply);
1562 dbus_connection_unref (session_bus);
1566 static DBusConnection *a11y_bus;
1567 static dbus_int32_t a11y_dbus_slot = -1;
1570 a11y_bus_free (void *data)
1572 if (data == a11y_bus)
1575 dbus_connection_free_data_slot (&a11y_dbus_slot);
1580 * atspi_get_a11y_bus: (skip)
1583 atspi_get_a11y_bus (void)
1586 char *address = NULL;
1587 const char *address_env = NULL;
1589 if (a11y_bus && dbus_connection_get_is_connected (a11y_bus))
1592 if (a11y_dbus_slot == -1)
1593 if (!dbus_connection_allocate_data_slot (&a11y_dbus_slot))
1594 g_warning ("AT-SPI: Unable to allocate D-Bus slot");
1596 address_env = g_getenv ("AT_SPI_BUS_ADDRESS");
1597 if (address_env != NULL && *address_env != 0)
1598 address = g_strdup (address_env);
1601 address = get_accessibility_bus_address_x11 ();
1604 address = get_accessibility_bus_address_dbus ();
1608 dbus_error_init (&error);
1609 a11y_bus = dbus_connection_open_private (address, &error);
1614 if (!g_getenv("SSH_CONNECTION"))
1615 g_warning ("Couldn't connect to accessibility bus: %s", error.message);
1616 dbus_error_free (&error);
1621 if (!dbus_bus_register (a11y_bus, &error))
1623 g_warning ("Couldn't register with accessibility bus: %s", error.message);
1624 dbus_error_free (&error);
1625 dbus_connection_close (a11y_bus);
1626 dbus_connection_unref (a11y_bus);
1632 /* Simulate a weak ref on the bus */
1633 dbus_connection_set_data (a11y_bus, a11y_dbus_slot, a11y_bus, a11y_bus_free);
1639 * atspi_set_timeout:
1640 * @val: The timeout value, in milliseconds, or -1 to disable the timeout.
1641 * @startup_time: The amount of time, in milliseconds, to allow to pass
1642 * before enforcing timeouts on an application. Can be used to prevent
1643 * timeout exceptions if an application is likely to block for an extended
1644 * period of time on initialization. -1 can be passed to disable this
1647 * Set the timeout used for method calls. If this is not set explicitly,
1648 * a default of 0.8 ms is used.
1649 * Note that at-spi2-registryd currently uses a timeout of 3 seconds when
1650 * sending a keyboard event notification. This means that, if an AT makes
1651 * a call in response to the keyboard notification and the application
1652 * being called does not respond before the timeout is reached,
1653 * at-spi2-registryd will time out on the keyboard event notification and
1654 * pass the key onto the application (ie, reply to indicate that the key
1655 * was not consumed), so this may make it undesirable to set a timeout
1656 * larger than 3 seconds.
1658 * By default, the normal timeout is set to 800 ms, and the application startup
1659 * timeout is set to 15 seconds.
1662 atspi_set_timeout (gint val, gint startup_time)
1664 method_call_timeout = val;
1665 app_startup_time = startup_time;
1669 * atspi_set_main_context:
1670 * @cnx: The #GMainContext to use.
1672 * Sets the main loop context that AT-SPI should assume is in use when
1673 * setting an idle callback.
1674 * This function should be called by application-side implementors (ie,
1675 * at-spi2-atk) when it is desirable to re-enter the main loop.
1678 atspi_set_main_context (GMainContext *cnx)
1680 if (atspi_main_context == cnx)
1682 if (process_deferred_messages_source != NULL)
1684 g_source_destroy (process_deferred_messages_source);
1685 process_deferred_messages_source = g_idle_source_new ();
1686 g_source_set_callback (process_deferred_messages_source,
1687 process_deferred_messages_callback, NULL, NULL);
1688 g_source_attach (process_deferred_messages_source, cnx);
1689 g_source_unref (process_deferred_messages_source);
1691 atspi_main_context = cnx;
1692 atspi_dbus_connection_setup_with_g_main (atspi_get_a11y_bus (), cnx);
1697 for (i = desktop->children->len - 1; i >= 0; i--)
1699 AtspiAccessible *child = g_ptr_array_index (desktop->children, i);
1700 if (child->parent.app && child->parent.app->bus)
1701 atspi_dbus_connection_setup_with_g_main (child->parent.app->bus, cnx);
1706 #ifdef DEBUG_REF_COUNTS
1708 print_disposed (gpointer key, gpointer value, gpointer data)
1710 AtspiAccessible *accessible = key;
1711 if (accessible->parent.app)
1713 g_print ("disposed: %s %d\n", accessible->name, accessible->role);
1719 g_hash_table_foreach (live_refs, print_disposed, NULL);
1724 _atspi_name_compat (gchar *name)
1738 * atspi_role_get_name:
1739 * @role: an #AtspiRole object to query.
1741 * Gets a localizable string that indicates the name of an #AtspiRole.
1742 * <em>DEPRECATED.</em>
1744 * Returns: a localizable string name for an #AtspiRole enumerated type.
1747 atspi_role_get_name (AtspiRole role)
1749 gchar *retval = NULL;
1750 GTypeClass *type_class;
1753 type_class = g_type_class_ref (ATSPI_TYPE_ROLE);
1754 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1756 value = g_enum_get_value (G_ENUM_CLASS (type_class), role);
1760 retval = g_strdup (value->value_nick);
1763 g_type_class_unref (type_class);
1766 return _atspi_name_compat (retval);
1772 _atspi_dbus_update_cache_from_dict (AtspiAccessible *accessible, DBusMessageIter *iter)
1774 GHashTable *cache = _atspi_accessible_ref_cache (accessible);
1775 DBusMessageIter iter_dict, iter_dict_entry, iter_struct, iter_variant;
1777 dbus_message_iter_recurse (iter, &iter_dict);
1778 while (dbus_message_iter_get_arg_type (&iter_dict) != DBUS_TYPE_INVALID)
1782 dbus_message_iter_recurse (&iter_dict, &iter_dict_entry);
1783 dbus_message_iter_get_basic (&iter_dict_entry, &key);
1784 dbus_message_iter_next (&iter_dict_entry);
1785 dbus_message_iter_recurse (&iter_dict_entry, &iter_variant);
1786 if (!strcmp (key, "interfaces"))
1788 _atspi_dbus_set_interfaces (accessible, &iter_variant);
1790 else if (!strcmp (key, "Attributes"))
1792 char *iter_sig = dbus_message_iter_get_signature (&iter_variant);
1793 val = g_new0 (GValue, 1);;
1794 g_value_init (val, G_TYPE_HASH_TABLE);
1795 if (strcmp (iter_sig, "a{ss}") != 0)
1797 dbus_free (iter_sig);
1800 dbus_free (iter_sig);
1801 g_value_take_boxed (val, _atspi_dbus_hash_from_iter (&iter_variant));
1803 else if (!strcmp (key, "Component.ScreenExtents"))
1807 char *iter_sig = dbus_message_iter_get_signature (&iter_variant);
1808 val = g_new0 (GValue, 1);;
1809 g_value_init (val, ATSPI_TYPE_RECT);
1810 if (strcmp (iter_sig, "(iiii)") != 0)
1812 dbus_free (iter_sig);
1815 dbus_free (iter_sig);
1816 dbus_message_iter_recurse (&iter_variant, &iter_struct);
1817 dbus_message_iter_get_basic (&iter_struct, &d_int);
1819 dbus_message_iter_next (&iter_struct);
1820 dbus_message_iter_get_basic (&iter_struct, &d_int);
1822 dbus_message_iter_next (&iter_struct);
1823 dbus_message_iter_get_basic (&iter_struct, &d_int);
1824 extents.width = d_int;
1825 dbus_message_iter_next (&iter_struct);
1826 dbus_message_iter_get_basic (&iter_struct, &d_int);
1827 extents.height = d_int;
1828 g_value_set_boxed (val, &extents);
1831 g_hash_table_insert (cache, g_strdup (key), val);
1832 dbus_message_iter_next (&iter_dict);
1839 _atspi_get_allow_sync ()
1845 _atspi_set_allow_sync (gboolean val)
1847 gboolean ret = allow_sync;
1854 _atspi_set_error_no_sync (GError **error)
1856 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_SYNC_NOT_ALLOWED,
1857 _("Attempted synchronous call where prohibited"));