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 Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 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 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, 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 if (child->parent.app)
163 g_object_run_dispose (G_OBJECT (child->parent.app));
164 g_object_run_dispose (G_OBJECT (child));
167 g_object_run_dispose (G_OBJECT (desktop->parent.app));
168 g_object_unref (desktop);
172 static gboolean atspi_inited = FALSE;
174 static GHashTable *app_hash = NULL;
177 handle_get_bus_address (DBusPendingCall *pending, void *user_data)
179 AtspiApplication *app = user_data;
180 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
181 DBusMessage *message;
183 DBusPendingCall *new_pending;
186 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
188 if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &address,
189 DBUS_TYPE_INVALID) && address [0])
194 dbus_error_init (&error);
195 bus = dbus_connection_open_private (address, &error);
200 dbus_connection_unref (app->bus);
203 atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default());
207 if (!strcmp (error.name, DBUS_ERROR_FILE_NOT_FOUND))
208 g_warning ("AT-SPI: Unable to open bus connection: %s", error.message);
209 dbus_error_free (&error);
213 dbus_message_unref (reply);
214 dbus_pending_call_unref (pending);
217 return; /* application has gone away / been disposed */
219 message = dbus_message_new_method_call (app->bus_name,
220 "/org/a11y/atspi/cache",
221 atspi_interface_cache, "GetItems");
223 result = dbus_connection_send_with_reply (app->bus, message, &new_pending, 2000);
224 dbus_message_unref (message);
225 if (!result || !new_pending)
227 dbus_pending_call_set_notify (new_pending, handle_get_items, app, NULL);
230 static AtspiApplication *
231 get_application (const char *bus_name)
233 AtspiApplication *app = NULL;
235 DBusMessage *message;
236 DBusPendingCall *pending = NULL;
241 app_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref);
242 if (!app_hash) return NULL;
244 app = g_hash_table_lookup (app_hash, bus_name);
246 bus_name_dup = g_strdup (bus_name);
247 if (!bus_name_dup) return NULL;
248 // TODO: change below to something that will send state-change:defunct notification if necessary */
249 app = _atspi_application_new (bus_name);
250 app->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
251 app->bus = dbus_connection_ref (_atspi_bus ());
252 gettimeofday (&app->time_added, NULL);
253 app->cache = ATSPI_CACHE_UNDEFINED;
254 g_hash_table_insert (app_hash, bus_name_dup, app);
255 message = dbus_message_new_method_call (bus_name, atspi_path_root,
256 atspi_interface_application, "GetApplicationBusAddress");
258 result = dbus_connection_send_with_reply (app->bus, message, &pending, 2000);
259 dbus_message_unref (message);
260 if (!result || !pending)
262 g_hash_table_remove (app_hash, bus_name_dup);
265 dbus_pending_call_set_notify (pending, handle_get_bus_address, app, NULL);
270 ref_accessible (const char *app_name, const char *path)
272 AtspiApplication *app;
275 if (!strcmp (path, ATSPI_DBUS_PATH_NULL))
278 app = get_application (app_name);
280 if (!strcmp (path, "/org/a11y/atspi/accessible/root"))
284 app->root = _atspi_accessible_new (app, atspi_path_root);
285 app->root->accessible_parent = atspi_get_desktop (0);
286 g_ptr_array_add (app->root->accessible_parent->children, g_object_ref (app->root));
288 return g_object_ref (app->root);
291 a = g_hash_table_lookup (app->hash, path);
294 return g_object_ref (a);
296 a = _atspi_accessible_new (app, path);
299 g_hash_table_insert (app->hash, g_strdup (a->parent.path), g_object_ref (a));
303 static AtspiHyperlink *
304 ref_hyperlink (const char *app_name, const char *path)
306 AtspiApplication *app = get_application (app_name);
307 AtspiHyperlink *hyperlink;
309 if (!strcmp (path, ATSPI_DBUS_PATH_NULL))
312 hyperlink = g_hash_table_lookup (app->hash, path);
315 return g_object_ref (hyperlink);
317 hyperlink = _atspi_hyperlink_new (app, path);
318 g_hash_table_insert (app->hash, g_strdup (hyperlink->parent.path), hyperlink);
319 /* TODO: This should be a weak ref */
320 g_object_ref (hyperlink); /* for the hash */
333 GArray *state_bitflags;
336 static DBusHandlerResult
337 handle_remove_accessible (DBusConnection *bus, DBusMessage *message, void *user_data)
339 const char *sender = dbus_message_get_sender (message);
340 AtspiApplication *app;
342 DBusMessageIter iter, iter_struct;
343 const char *signature = dbus_message_get_signature (message);
346 if (strcmp (signature, "(so)") != 0)
348 g_warning ("AT-SPI: Unknown signature %s for RemoveAccessible", signature);
349 return DBUS_HANDLER_RESULT_HANDLED;
352 dbus_message_iter_init (message, &iter);
353 dbus_message_iter_recurse (&iter, &iter_struct);
354 dbus_message_iter_get_basic (&iter_struct, &sender);
355 dbus_message_iter_next (&iter_struct);
356 dbus_message_iter_get_basic (&iter_struct, &path);
357 app = get_application (sender);
358 a = ref_accessible (sender, path);
360 return DBUS_HANDLER_RESULT_HANDLED;
361 g_object_run_dispose (G_OBJECT (a));
362 g_hash_table_remove (app->hash, a->parent.path);
363 g_object_unref (a); /* unref our own ref */
364 return DBUS_HANDLER_RESULT_HANDLED;
367 static DBusHandlerResult
368 handle_name_owner_changed (DBusConnection *bus, DBusMessage *message, void *user_data)
370 const char *name, *new, *old;
371 static gboolean registry_lost = FALSE;
373 if (!dbus_message_get_args (message, NULL,
374 DBUS_TYPE_STRING, &name,
375 DBUS_TYPE_STRING, &old,
376 DBUS_TYPE_STRING, &new,
379 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
382 if (!strcmp (name, "org.a11y.atspi.Registry"))
384 if (registry_lost && !old[0])
386 _atspi_reregister_event_listeners ();
387 _atspi_reregister_device_listeners ();
388 registry_lost = FALSE;
391 registry_lost = TRUE;
395 AtspiApplication *app = g_hash_table_lookup (app_hash, old);
396 if (app && app->bus_name && !strcmp(app->bus_name, name))
397 g_object_run_dispose (G_OBJECT (app));
399 return DBUS_HANDLER_RESULT_HANDLED;
403 add_app_to_desktop (AtspiAccessible *a, const char *bus_name)
405 AtspiAccessible *obj = ref_accessible (bus_name, atspi_path_root);
406 /* The app will be added to the desktop as a side-effect of calling
408 g_object_unref (obj);
409 return (obj != NULL);
413 get_reference_from_iter (DBusMessageIter *iter, const char **app_name, const char **path)
415 DBusMessageIter iter_struct;
417 dbus_message_iter_recurse (iter, &iter_struct);
418 dbus_message_iter_get_basic (&iter_struct, app_name);
419 dbus_message_iter_next (&iter_struct);
420 dbus_message_iter_get_basic (&iter_struct, path);
421 dbus_message_iter_next (iter);
425 add_accessible_from_iter (DBusMessageIter *iter)
427 DBusMessageIter iter_struct, iter_array;
428 const char *app_name, *path;
429 AtspiAccessible *accessible;
430 const char *name, *description;
432 gboolean children_cached = FALSE;
433 dbus_int32_t count, index;
435 dbus_message_iter_recurse (iter, &iter_struct);
438 get_reference_from_iter (&iter_struct, &app_name, &path);
439 accessible = ref_accessible (app_name, path);
443 /* Get application: TODO */
444 dbus_message_iter_next (&iter_struct);
447 get_reference_from_iter (&iter_struct, &app_name, &path);
448 if (accessible->accessible_parent)
449 g_object_unref (accessible->accessible_parent);
450 accessible->accessible_parent = ref_accessible (app_name, path);
452 if (dbus_message_iter_get_arg_type (&iter_struct) == 'i')
454 /* Get index in parent */
455 dbus_message_iter_get_basic (&iter_struct, &index);
456 if (index >= 0 && accessible->accessible_parent)
458 if (index >= accessible->accessible_parent->children->len)
459 g_ptr_array_set_size (accessible->accessible_parent->children, index + 1);
460 g_ptr_array_index (accessible->accessible_parent->children, index) = g_object_ref (accessible);
463 /* get child count */
464 dbus_message_iter_next (&iter_struct);
465 dbus_message_iter_get_basic (&iter_struct, &count);
468 g_ptr_array_set_size (accessible->children, count);
469 children_cached = TRUE;
472 else if (dbus_message_iter_get_arg_type (&iter_struct) == 'a')
474 /* It's the old API with a list of children */
475 /* TODO: Perhaps remove this code eventually */
476 dbus_message_iter_recurse (&iter_struct, &iter_array);
477 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
479 AtspiAccessible *child;
480 get_reference_from_iter (&iter_array, &app_name, &path);
481 child = ref_accessible (app_name, path);
482 g_ptr_array_remove (accessible->children, child);
483 g_ptr_array_add (accessible->children, child);
485 children_cached = TRUE;
489 dbus_message_iter_next (&iter_struct);
490 _atspi_dbus_set_interfaces (accessible, &iter_struct);
491 dbus_message_iter_next (&iter_struct);
494 if (accessible->name)
495 g_free (accessible->name);
496 dbus_message_iter_get_basic (&iter_struct, &name);
497 accessible->name = g_strdup (name);
498 dbus_message_iter_next (&iter_struct);
501 dbus_message_iter_get_basic (&iter_struct, &role);
502 accessible->role = role;
503 dbus_message_iter_next (&iter_struct);
506 if (accessible->description)
507 g_free (accessible->description);
508 dbus_message_iter_get_basic (&iter_struct, &description);
509 accessible->description = g_strdup (description);
510 dbus_message_iter_next (&iter_struct);
512 _atspi_dbus_set_state (accessible, &iter_struct);
513 dbus_message_iter_next (&iter_struct);
515 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_NAME | ATSPI_CACHE_ROLE |
516 ATSPI_CACHE_PARENT | ATSPI_CACHE_DESCRIPTION);
517 if (!atspi_state_set_contains (accessible->states,
518 ATSPI_STATE_MANAGES_DESCENDANTS) &&
520 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_CHILDREN);
522 /* This is a bit of a hack since the cache holds a ref, so we don't need
523 * the one provided for us anymore */
524 g_object_unref (accessible);
528 handle_get_items (DBusPendingCall *pending, void *user_data)
530 DBusMessage *reply = dbus_pending_call_steal_reply (pending);
531 DBusMessageIter iter, iter_array;
533 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
535 const char *sender = dbus_message_get_sender (reply);
536 const char *error = NULL;
537 const char *error_name = dbus_message_get_error_name (reply);
538 if (!strcmp (error_name, DBUS_ERROR_SERVICE_UNKNOWN)
539 || !strcmp (error_name, DBUS_ERROR_NO_REPLY))
544 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &error,
546 g_warning ("AT-SPI: Error in GetItems, sender=%s, error=%s", sender, error);
548 dbus_message_unref (reply);
549 dbus_pending_call_unref (pending);
553 dbus_message_iter_init (reply, &iter);
554 dbus_message_iter_recurse (&iter, &iter_array);
555 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
557 add_accessible_from_iter (&iter_array);
558 dbus_message_iter_next (&iter_array);
560 dbus_message_unref (reply);
561 dbus_pending_call_unref (pending);
564 /* TODO: Do we stil need this function? */
565 static AtspiAccessible *
566 ref_accessible_desktop (AtspiApplication *app)
569 DBusMessage *message, *reply;
570 DBusMessageIter iter, iter_array;
575 g_object_ref (desktop);
578 desktop = _atspi_accessible_new (app, atspi_path_root);
583 g_hash_table_insert (app->hash, g_strdup (desktop->parent.path),
584 g_object_ref (desktop));
585 app->root = g_object_ref (desktop);
586 desktop->name = g_strdup ("main");
587 message = dbus_message_new_method_call (atspi_bus_registry,
589 atspi_interface_accessible,
594 reply = _atspi_dbus_send_with_reply_and_block (message, &error);
595 if (!reply || strcmp (dbus_message_get_signature (reply), "a(so)") != 0)
599 g_warning ("Couldn't get application list: %s", error->message);
600 g_clear_error (&error);
603 dbus_message_unref (reply);
606 dbus_message_iter_init (reply, &iter);
607 dbus_message_iter_recurse (&iter, &iter_array);
608 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
610 const char *app_name, *path;
611 get_reference_from_iter (&iter_array, &app_name, &path);
612 add_app_to_desktop (desktop, app_name);
615 /* Record the alternate name as an alias for org.a11y.atspi.Registry */
616 bus_name_dup = g_strdup (dbus_message_get_sender (reply));
618 g_hash_table_insert (app_hash, bus_name_dup, app);
620 dbus_message_unref (reply);
622 return g_object_ref (desktop);
626 _atspi_ref_accessible (const char *app, const char *path)
628 AtspiApplication *a = get_application (app);
631 if ( APP_IS_REGISTRY(a))
634 g_object_unref (ref_accessible_desktop (a)); /* sets a->root */
635 return g_object_ref (a->root);
637 return ref_accessible (app, path);
641 _atspi_dbus_return_accessible_from_message (DBusMessage *message)
643 DBusMessageIter iter;
644 AtspiAccessible *retval = NULL;
645 const char *signature;
650 signature = dbus_message_get_signature (message);
651 if (!strcmp (signature, "(so)"))
653 dbus_message_iter_init (message, &iter);
654 retval = _atspi_dbus_return_accessible_from_iter (&iter);
658 g_warning ("AT-SPI: Called _atspi_dbus_return_accessible_from_message with strange signature %s", signature);
660 dbus_message_unref (message);
665 _atspi_dbus_return_accessible_from_iter (DBusMessageIter *iter)
667 const char *app_name, *path;
669 get_reference_from_iter (iter, &app_name, &path);
670 return ref_accessible (app_name, path);
674 _atspi_dbus_return_hyperlink_from_message (DBusMessage *message)
676 DBusMessageIter iter;
677 AtspiHyperlink *retval = NULL;
678 const char *signature;
683 signature = dbus_message_get_signature (message);
684 if (!strcmp (signature, "(so)"))
686 dbus_message_iter_init (message, &iter);
687 retval = _atspi_dbus_return_hyperlink_from_iter (&iter);
691 g_warning ("AT-SPI: Called _atspi_dbus_return_hyperlink_from_message with strange signature %s", signature);
693 dbus_message_unref (message);
698 _atspi_dbus_return_hyperlink_from_iter (DBusMessageIter *iter)
700 const char *app_name, *path;
702 get_reference_from_iter (iter, &app_name, &path);
703 return ref_hyperlink (app_name, path);
706 const char *cache_signal_type = "((so)(so)(so)iiassusau)";
707 const char *old_cache_signal_type = "((so)(so)(so)a(so)assusau)";
709 static DBusHandlerResult
710 handle_add_accessible (DBusConnection *bus, DBusMessage *message, void *user_data)
712 DBusMessageIter iter;
713 const char *signature = dbus_message_get_signature (message);
715 if (strcmp (signature, cache_signal_type) != 0 &&
716 strcmp (signature, old_cache_signal_type) != 0)
718 g_warning ("AT-SPI: AddAccessible with unknown signature %s\n", signature);
719 return DBUS_HANDLER_RESULT_HANDLED;
722 dbus_message_iter_init (message, &iter);
723 add_accessible_from_iter (&iter);
724 return DBUS_HANDLER_RESULT_HANDLED;
730 DBusMessage *message;
734 static GSource *process_deferred_messages_source = NULL;
737 process_deferred_message (BusDataClosure *closure)
739 int type = dbus_message_get_type (closure->message);
740 const char *interface = dbus_message_get_interface (closure->message);
742 if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
743 !strncmp (interface, "org.a11y.atspi.Event.", 21))
745 _atspi_dbus_handle_event (closure->bus, closure->message, closure->data);
747 if (dbus_message_is_method_call (closure->message, atspi_interface_device_event_listener, "NotifyEvent"))
749 _atspi_dbus_handle_DeviceEvent (closure->bus,
750 closure->message, closure->data);
752 if (dbus_message_is_signal (closure->message, atspi_interface_cache, "AddAccessible"))
754 handle_add_accessible (closure->bus, closure->message, closure->data);
756 if (dbus_message_is_signal (closure->message, atspi_interface_cache, "RemoveAccessible"))
758 handle_remove_accessible (closure->bus, closure->message, closure->data);
760 if (dbus_message_is_signal (closure->message, "org.freedesktop.DBus", "NameOwnerChanged"))
762 handle_name_owner_changed (closure->bus, closure->message, closure->data);
766 static GQueue *deferred_messages = NULL;
769 process_deferred_messages (void)
771 static int in_process_deferred_messages = 0;
772 BusDataClosure *closure;
774 if (in_process_deferred_messages)
776 in_process_deferred_messages = 1;
777 while ((closure = g_queue_pop_head (deferred_messages)))
779 process_deferred_message (closure);
780 dbus_message_unref (closure->message);
781 dbus_connection_unref (closure->bus);
784 in_process_deferred_messages = 0;
789 process_deferred_messages_callback (gpointer data)
791 if (process_deferred_messages ())
792 return G_SOURCE_CONTINUE;
794 process_deferred_messages_source = NULL;
795 return G_SOURCE_REMOVE;
798 static DBusHandlerResult
799 defer_message (DBusConnection *connection, DBusMessage *message, void *user_data)
801 BusDataClosure *closure = g_new (BusDataClosure, 1);
803 closure->bus = dbus_connection_ref (bus);
804 closure->message = dbus_message_ref (message);
805 closure->data = user_data;
807 g_queue_push_tail (deferred_messages, closure);
809 if (process_deferred_messages_source == NULL)
811 process_deferred_messages_source = g_idle_source_new ();
812 g_source_set_callback (process_deferred_messages_source,
813 process_deferred_messages_callback, NULL, NULL);
814 g_source_attach (process_deferred_messages_source, atspi_main_context);
815 g_source_unref (process_deferred_messages_source);
818 return DBUS_HANDLER_RESULT_HANDLED;
821 static DBusHandlerResult
822 atspi_dbus_filter (DBusConnection *bus, DBusMessage *message, void *data)
824 int type = dbus_message_get_type (message);
825 const char *interface = dbus_message_get_interface (message);
827 if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
828 !strncmp (interface, "org.a11y.atspi.Event.", 21))
830 return defer_message (bus, message, data);
832 if (dbus_message_is_method_call (message, atspi_interface_device_event_listener, "NotifyEvent"))
834 return defer_message (bus, message, data);
836 if (dbus_message_is_signal (message, atspi_interface_cache, "AddAccessible"))
838 return defer_message (bus, message, data);
840 if (dbus_message_is_signal (message, atspi_interface_cache, "RemoveAccessible"))
842 return defer_message (bus, message, data);
844 if (dbus_message_is_signal (message, "org.freedesktop.DBus", "NameOwnerChanged"))
846 defer_message (bus, message, data);
847 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
849 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
853 * Returns a 'canonicalized' value for DISPLAY,
854 * with the screen number stripped off if present.
856 * TODO: Avoid having duplicate functions for this here and in at-spi2-atk
859 spi_display_name (void)
861 char *canonical_display_name = NULL;
862 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
866 display_env = g_getenv ("DISPLAY");
867 if (!display_env || !display_env[0])
871 gchar *display_p, *screen_p;
872 canonical_display_name = g_strdup (display_env);
873 display_p = g_utf8_strrchr (canonical_display_name, -1, ':');
874 screen_p = g_utf8_strrchr (canonical_display_name, -1, '.');
875 if (screen_p && display_p && (screen_p > display_p))
883 canonical_display_name = g_strdup (display_env);
886 return canonical_display_name;
892 * Connects to the accessibility registry and initializes the SPI.
894 * Returns: 0 on success, 1 if already initialized, or an integer error code.
900 const gchar *no_cache;
909 _atspi_get_live_refs();
911 bus = atspi_get_a11y_bus ();
914 if (!dbus_bus_register (bus, NULL))
916 atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default());
917 dbus_connection_add_filter (bus, atspi_dbus_filter, NULL, NULL);
918 match = g_strdup_printf ("type='signal',interface='%s',member='AddAccessible'", atspi_interface_cache);
919 dbus_bus_add_match (bus, match, NULL);
921 match = g_strdup_printf ("type='signal',interface='%s',member='RemoveAccessible'", atspi_interface_cache);
922 dbus_bus_add_match (bus, match, NULL);
924 match = g_strdup_printf ("type='signal',interface='%s',member='ChildrenChanged'", atspi_interface_event_object);
925 dbus_bus_add_match (bus, match, NULL);
927 match = g_strdup_printf ("type='signal',interface='%s',member='PropertyChange'", atspi_interface_event_object);
928 dbus_bus_add_match (bus, match, NULL);
930 match = g_strdup_printf ("type='signal',interface='%s',member='StateChanged'", atspi_interface_event_object);
931 dbus_bus_add_match (bus, match, NULL);
934 dbus_bus_add_match (bus,
935 "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged'",
938 no_cache = g_getenv ("ATSPI_NO_CACHE");
939 if (no_cache && g_strcmp0 (no_cache, "0") != 0)
940 atspi_no_cache = TRUE;
942 deferred_messages = g_queue_new ();
948 * atspi_is_initialized:
950 * Indicates whether AT-SPI has been initialized.
952 * Returns: %True if initialized; %False otherwise.
955 atspi_is_initialized ()
963 * Starts/enters the main event loop for the AT-SPI services.
965 * NOTE: This method does not return control; it is exited via a call to
966 * #atspi_event_quit from within an event handler.
970 atspi_event_main (void)
972 atspi_main_loop = g_main_loop_new (NULL, FALSE);
973 g_main_loop_run (atspi_main_loop);
974 atspi_main_loop = NULL;
980 * Quits the last main event loop for the AT-SPI services,
981 * See: #atspi_event_main
984 atspi_event_quit (void)
986 g_main_loop_quit (atspi_main_loop);
992 * Disconnects from #AtspiRegistry instances and releases
993 * any floating resources. Call only once at exit.
995 * Returns: 0 if there were no leaks, otherwise other integer values.
1007 atspi_inited = FALSE;
1011 leaked = g_hash_table_size (live_refs);
1023 static GSList *hung_processes;
1026 remove_hung_process (DBusPendingCall *pending, void *data)
1028 hung_processes = g_slist_remove (hung_processes, data);
1030 dbus_pending_call_unref (pending);
1034 check_for_hang (DBusMessage *message, DBusError *error, DBusConnection *bus, const char *bus_name)
1036 if (!message && error->name &&
1037 !strcmp (error->name, "org.freedesktop.DBus.Error.NoReply"))
1040 DBusMessage *message;
1041 gchar *bus_name_dup;
1042 DBusPendingCall *pending = NULL;
1044 for (l = hung_processes; l; l = l->next)
1045 if (!strcmp (l->data, bus_name))
1047 message = dbus_message_new_method_call (bus_name, "/",
1048 "org.freedesktop.DBus.Peer",
1052 result = dbus_connection_send_with_reply (bus, message, &pending, -1);
1053 dbus_message_unref (message);
1054 if (!result || !pending)
1056 bus_name_dup = g_strdup (bus_name);
1057 hung_processes = g_slist_append (hung_processes, bus_name_dup);
1058 dbus_pending_call_set_notify (pending, remove_hung_process, bus_name_dup, NULL);
1063 connection_is_hung (const char *bus_name)
1067 for (l = hung_processes; l; l = l->next)
1068 if (!strcmp (l->data, bus_name))
1074 check_app (AtspiApplication *app, GError **error)
1076 if (!app || !app->bus)
1078 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_APPLICATION_GONE,
1079 _("The application no longer exists"));
1083 if (atspi_main_loop && connection_is_hung (app->bus_name))
1085 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC,
1086 "The process appears to be hung.");
1094 set_timeout (AtspiApplication *app)
1099 if (app && app_startup_time > 0)
1101 gettimeofday (&tv, NULL);
1102 diff = (tv.tv_sec - app->time_added.tv_sec) * 1000 + (tv.tv_usec - app->time_added.tv_usec) / 1000;
1103 dbind_set_timeout (MAX(method_call_timeout, app_startup_time - diff));
1106 dbind_set_timeout (method_call_timeout);
1110 _atspi_dbus_call (gpointer obj, const char *interface, const char *method, GError **error, const char *type, ...)
1115 AtspiObject *aobj = ATSPI_OBJECT (obj);
1117 if (!check_app (aobj->app, error))
1122 _atspi_set_error_no_sync (error);
1126 va_start (args, type);
1127 dbus_error_init (&err);
1128 set_timeout (aobj->app);
1129 retval = dbind_method_call_reentrant_va (aobj->app->bus, aobj->app->bus_name,
1130 aobj->path, interface, method, &err,
1133 check_for_hang (NULL, &err, aobj->app->bus, aobj->app->bus_name);
1134 process_deferred_messages ();
1135 if (dbus_error_is_set (&err))
1137 g_set_error(error, ATSPI_ERROR, ATSPI_ERROR_IPC, "%s", err.message);
1138 dbus_error_free (&err);
1144 _atspi_dbus_call_partial (gpointer obj,
1145 const char *interface,
1148 const char *type, ...)
1151 DBusMessage * result;
1152 va_start (args, type);
1153 result = _atspi_dbus_call_partial_va (obj, interface, method, error, type, args);
1160 _atspi_dbus_call_partial_va (gpointer obj,
1161 const char *interface,
1167 AtspiObject *aobj = ATSPI_OBJECT (obj);
1169 DBusMessage *msg = NULL, *reply = NULL;
1170 DBusMessageIter iter;
1173 dbus_error_init (&err);
1175 if (!check_app (aobj->app, error))
1178 msg = dbus_message_new_method_call (aobj->app->bus_name, aobj->path, interface, method);
1183 dbus_message_iter_init_append (msg, &iter);
1184 dbind_any_marshal_va (&iter, &p, args);
1186 set_timeout (aobj->app);
1187 reply = dbind_send_and_allow_reentry (aobj->app->bus, msg, &err);
1188 check_for_hang (reply, &err, aobj->app->bus, aobj->app->bus_name);
1192 dbus_message_unref (msg);
1193 process_deferred_messages ();
1194 if (dbus_error_is_set (&err))
1196 g_set_error_literal(error, ATSPI_ERROR, ATSPI_ERROR_IPC, err.message);
1197 dbus_error_free (&err);
1199 dbus_message_unref(reply);
1202 else if (reply && dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
1204 const char *err_str = NULL;
1205 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err_str, DBUS_TYPE_INVALID);
1207 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err_str);
1208 dbus_message_unref (reply);
1215 _atspi_dbus_get_property (gpointer obj, const char *interface, const char *name, GError **error, const char *type, void *data)
1217 DBusMessage *message, *reply;
1218 DBusMessageIter iter, iter_variant;
1220 dbus_bool_t retval = FALSE;
1221 AtspiObject *aobj = ATSPI_OBJECT (obj);
1222 char expected_type = (type [0] == '(' ? 'r' : type [0]);
1227 if (!check_app (aobj->app, error))
1232 _atspi_set_error_no_sync (error);
1236 message = dbus_message_new_method_call (aobj->app->bus_name,
1238 "org.freedesktop.DBus.Properties",
1242 // TODO: throw exception
1245 dbus_message_append_args (message, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
1246 dbus_error_init (&err);
1247 set_timeout (aobj->app);
1248 reply = dbind_send_and_allow_reentry (aobj->app->bus, message, &err);
1249 check_for_hang (reply, &err, aobj->app->bus, aobj->app->bus_name);
1250 dbus_message_unref (message);
1251 process_deferred_messages ();
1254 // TODO: throw exception
1258 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
1260 const char *err_str = NULL;
1261 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err_str, DBUS_TYPE_INVALID);
1263 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err_str);
1267 dbus_message_iter_init (reply, &iter);
1268 if (dbus_message_iter_get_arg_type (&iter) != 'v')
1270 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));
1273 dbus_message_iter_recurse (&iter, &iter_variant);
1274 if (dbus_message_iter_get_arg_type (&iter_variant) != expected_type)
1276 g_warning ("atspi_dbus_get_property: Wrong type: expected %s, got %c\n", type, dbus_message_iter_get_arg_type (&iter_variant));
1279 if (!strcmp (type, "(so)"))
1281 *((AtspiAccessible **)data) = _atspi_dbus_return_accessible_from_iter (&iter_variant);
1285 dbus_message_iter_get_basic (&iter_variant, data);
1286 if (type [0] == 's')
1287 *(char **)data = g_strdup (*(char **)data);
1291 dbus_error_free (&err);
1293 dbus_message_unref (reply);
1298 _atspi_dbus_send_with_reply_and_block (DBusMessage *message, GError **error)
1302 AtspiApplication *app;
1303 DBusConnection *bus;
1305 app = get_application (dbus_message_get_destination (message));
1307 if (app && !app->bus)
1308 return NULL; /* will fail anyway; app has been disposed */
1310 bus = (app ? app->bus : _atspi_bus());
1311 dbus_error_init (&err);
1313 reply = dbind_send_and_allow_reentry (bus, message, &err);
1314 process_deferred_messages ();
1315 dbus_message_unref (message);
1316 if (dbus_error_is_set (&err))
1319 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_IPC, err.message);
1320 dbus_error_free (&err);
1326 _atspi_dbus_return_hash_from_message (DBusMessage *message)
1328 DBusMessageIter iter;
1334 _ATSPI_DBUS_CHECK_SIG (message, "a{ss}", NULL, NULL);
1336 dbus_message_iter_init (message, &iter);
1337 ret = _atspi_dbus_hash_from_iter (&iter);
1338 dbus_message_unref (message);
1343 _atspi_dbus_hash_from_iter (DBusMessageIter *iter)
1345 GHashTable *hash = g_hash_table_new_full (g_str_hash, g_str_equal,
1346 (GDestroyNotify) g_free,
1347 (GDestroyNotify) g_free);
1348 DBusMessageIter iter_array, iter_dict;
1350 dbus_message_iter_recurse (iter, &iter_array);
1351 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1353 const char *name, *value;
1354 dbus_message_iter_recurse (&iter_array, &iter_dict);
1355 dbus_message_iter_get_basic (&iter_dict, &name);
1356 dbus_message_iter_next (&iter_dict);
1357 dbus_message_iter_get_basic (&iter_dict, &value);
1358 g_hash_table_insert (hash, g_strdup (name), g_strdup (value));
1359 dbus_message_iter_next (&iter_array);
1365 _atspi_dbus_return_attribute_array_from_message (DBusMessage *message)
1367 DBusMessageIter iter;
1373 _ATSPI_DBUS_CHECK_SIG (message, "a{ss}", NULL, NULL);
1375 dbus_message_iter_init (message, &iter);
1377 ret = _atspi_dbus_attribute_array_from_iter (&iter);
1378 dbus_message_unref (message);
1383 _atspi_dbus_attribute_array_from_iter (DBusMessageIter *iter)
1385 DBusMessageIter iter_array, iter_dict;
1386 GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
1388 dbus_message_iter_recurse (iter, &iter_array);
1389 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1391 const char *name, *value;
1393 dbus_message_iter_recurse (&iter_array, &iter_dict);
1394 dbus_message_iter_get_basic (&iter_dict, &name);
1395 dbus_message_iter_next (&iter_dict);
1396 dbus_message_iter_get_basic (&iter_dict, &value);
1397 str = g_strdup_printf ("%s:%s", name, value);
1398 array = g_array_append_val (array, str);
1399 dbus_message_iter_next (&iter_array);;
1405 _atspi_dbus_set_interfaces (AtspiAccessible *accessible, DBusMessageIter *iter)
1407 DBusMessageIter iter_array;
1408 char *iter_sig = dbus_message_iter_get_signature (iter);
1410 accessible->interfaces = 0;
1411 if (strcmp (iter_sig, "as") != 0)
1413 g_warning ("_atspi_dbus_set_interfaces: Passed iterator with invalid signature %s", dbus_message_iter_get_signature (iter));
1414 dbus_free (iter_sig);
1417 dbus_free (iter_sig);
1418 dbus_message_iter_recurse (iter, &iter_array);
1419 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
1423 dbus_message_iter_get_basic (&iter_array, &iface);
1424 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable")) continue;
1425 n = _atspi_get_iface_num (iface);
1428 g_warning ("AT-SPI: Unknown interface %s", iface);
1431 accessible->interfaces |= (1 << n);
1432 dbus_message_iter_next (&iter_array);
1434 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_INTERFACES);
1438 _atspi_dbus_set_state (AtspiAccessible *accessible, DBusMessageIter *iter)
1440 DBusMessageIter iter_array;
1442 dbus_uint32_t *states;
1444 dbus_message_iter_recurse (iter, &iter_array);
1445 dbus_message_iter_get_fixed_array (&iter_array, &states, &count);
1448 g_warning ("AT-SPI: expected 2 values in states array; got %d\n", count);
1449 if (!accessible->states)
1450 accessible->states = _atspi_state_set_new_internal (accessible, 0);
1454 guint64 val = ((guint64)states [1]) << 32;
1456 if (!accessible->states)
1457 accessible->states = _atspi_state_set_new_internal (accessible, val);
1459 accessible->states->states = val;
1461 _atspi_accessible_add_cache (accessible, ATSPI_CACHE_STATES);
1465 _atspi_error_quark (void)
1467 return g_quark_from_static_string ("atspi_error");
1471 * Gets the IOR from the XDisplay.
1475 get_accessibility_bus_address_x11 (void)
1479 Display *bridge_display = NULL;
1482 unsigned char *data_x11 = NULL;
1483 unsigned long nitems;
1484 unsigned long leftover;
1487 display_name = spi_display_name ();
1491 bridge_display = XOpenDisplay (display_name);
1492 g_free (display_name);
1494 if (!bridge_display)
1496 g_warning ("Could not open X display");
1500 AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
1501 XGetWindowProperty (bridge_display,
1502 XDefaultRootWindow (bridge_display),
1504 (long) BUFSIZ, False,
1505 (Atom) 31, &actual_type, &actual_format,
1506 &nitems, &leftover, &data_x11);
1507 XCloseDisplay (bridge_display);
1509 data = g_strdup ((gchar *)data_x11);
1516 get_accessibility_bus_address_dbus (void)
1518 DBusConnection *session_bus = NULL;
1519 DBusMessage *message;
1522 char *address = NULL;
1524 session_bus = dbus_bus_get (DBUS_BUS_SESSION, NULL);
1528 message = dbus_message_new_method_call ("org.a11y.Bus",
1533 dbus_error_init (&error);
1534 reply = dbus_connection_send_with_reply_and_block (session_bus,
1538 dbus_message_unref (message);
1542 g_warning ("AT-SPI: Error retrieving accessibility bus address: %s: %s",
1543 error.name, error.message);
1544 dbus_error_free (&error);
1549 const char *tmp_address;
1550 if (!dbus_message_get_args (reply,
1556 dbus_message_unref (reply);
1559 address = g_strdup (tmp_address);
1560 dbus_message_unref (reply);
1564 dbus_connection_unref (session_bus);
1568 static DBusConnection *a11y_bus;
1569 static dbus_int32_t a11y_dbus_slot = -1;
1572 a11y_bus_free (void *data)
1574 if (data == a11y_bus)
1577 dbus_connection_free_data_slot (&a11y_dbus_slot);
1582 * atspi_get_a11y_bus: (skip)
1585 atspi_get_a11y_bus (void)
1588 char *address = NULL;
1589 const char *address_env = NULL;
1591 if (a11y_bus && dbus_connection_get_is_connected (a11y_bus))
1594 if (a11y_dbus_slot == -1)
1595 if (!dbus_connection_allocate_data_slot (&a11y_dbus_slot))
1596 g_warning ("AT-SPI: Unable to allocate D-Bus slot");
1598 address_env = g_getenv ("AT_SPI_BUS_ADDRESS");
1599 if (address_env != NULL && *address_env != 0)
1600 address = g_strdup (address_env);
1602 if (!address && g_getenv ("DISPLAY") != NULL &&
1603 g_getenv ("WAYLAND_DISPLAY") == NULL)
1604 address = get_accessibility_bus_address_x11 ();
1607 address = get_accessibility_bus_address_dbus ();
1611 dbus_error_init (&error);
1612 a11y_bus = dbus_connection_open_private (address, &error);
1617 if (!g_getenv("SSH_CONNECTION"))
1618 g_warning ("Couldn't connect to accessibility bus: %s", error.message);
1619 dbus_error_free (&error);
1624 if (!dbus_bus_register (a11y_bus, &error))
1626 g_warning ("Couldn't register with accessibility bus: %s", error.message);
1627 dbus_error_free (&error);
1628 dbus_connection_close (a11y_bus);
1629 dbus_connection_unref (a11y_bus);
1635 /* Simulate a weak ref on the bus */
1636 dbus_connection_set_data (a11y_bus, a11y_dbus_slot, a11y_bus, a11y_bus_free);
1642 * atspi_set_timeout:
1643 * @val: The timeout value, in milliseconds, or -1 to disable the timeout.
1644 * @startup_time: The amount of time, in milliseconds, to allow to pass
1645 * before enforcing timeouts on an application. Can be used to prevent
1646 * timeout exceptions if an application is likely to block for an extended
1647 * period of time on initialization. -1 can be passed to disable this
1650 * Set the timeout used for method calls. If this is not set explicitly,
1651 * a default of 0.8 ms is used.
1652 * Note that at-spi2-registryd currently uses a timeout of 3 seconds when
1653 * sending a keyboard event notification. This means that, if an AT makes
1654 * a call in response to the keyboard notification and the application
1655 * being called does not respond before the timeout is reached,
1656 * at-spi2-registryd will time out on the keyboard event notification and
1657 * pass the key onto the application (ie, reply to indicate that the key
1658 * was not consumed), so this may make it undesirable to set a timeout
1659 * larger than 3 seconds.
1661 * By default, the normal timeout is set to 800 ms, and the application startup
1662 * timeout is set to 15 seconds.
1665 atspi_set_timeout (gint val, gint startup_time)
1667 method_call_timeout = val;
1668 app_startup_time = startup_time;
1672 * atspi_set_main_context:
1673 * @cnx: The #GMainContext to use.
1675 * Sets the main loop context that AT-SPI should assume is in use when
1676 * setting an idle callback.
1677 * This function should be called by application-side implementors (ie,
1678 * at-spi2-atk) when it is desirable to re-enter the main loop.
1681 atspi_set_main_context (GMainContext *cnx)
1683 if (atspi_main_context == cnx)
1685 if (process_deferred_messages_source != NULL)
1687 g_source_destroy (process_deferred_messages_source);
1688 process_deferred_messages_source = g_idle_source_new ();
1689 g_source_set_callback (process_deferred_messages_source,
1690 process_deferred_messages_callback, NULL, NULL);
1691 g_source_attach (process_deferred_messages_source, cnx);
1692 g_source_unref (process_deferred_messages_source);
1694 atspi_main_context = cnx;
1695 atspi_dbus_connection_setup_with_g_main (atspi_get_a11y_bus (), cnx);
1700 for (i = desktop->children->len - 1; i >= 0; i--)
1702 AtspiAccessible *child = g_ptr_array_index (desktop->children, i);
1703 if (child->parent.app && child->parent.app->bus)
1704 atspi_dbus_connection_setup_with_g_main (child->parent.app->bus, cnx);
1709 #ifdef DEBUG_REF_COUNTS
1711 print_disposed (gpointer key, gpointer value, gpointer data)
1713 AtspiAccessible *accessible = key;
1714 if (accessible->parent.app)
1716 g_print ("disposed: %s %d\n", accessible->name, accessible->role);
1722 g_hash_table_foreach (live_refs, print_disposed, NULL);
1727 _atspi_name_compat (gchar *name)
1741 * atspi_role_get_name:
1742 * @role: an #AtspiRole object to query.
1744 * Gets a localizable string that indicates the name of an #AtspiRole.
1745 * <em>DEPRECATED.</em>
1747 * Returns: a localizable string name for an #AtspiRole enumerated type.
1750 atspi_role_get_name (AtspiRole role)
1752 gchar *retval = NULL;
1753 GTypeClass *type_class;
1756 type_class = g_type_class_ref (ATSPI_TYPE_ROLE);
1757 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1759 value = g_enum_get_value (G_ENUM_CLASS (type_class), role);
1763 retval = g_strdup (value->value_nick);
1766 g_type_class_unref (type_class);
1769 return _atspi_name_compat (retval);
1775 _atspi_dbus_update_cache_from_dict (AtspiAccessible *accessible, DBusMessageIter *iter)
1777 GHashTable *cache = _atspi_accessible_ref_cache (accessible);
1778 DBusMessageIter iter_dict, iter_dict_entry, iter_struct, iter_variant;
1780 dbus_message_iter_recurse (iter, &iter_dict);
1781 while (dbus_message_iter_get_arg_type (&iter_dict) != DBUS_TYPE_INVALID)
1785 dbus_message_iter_recurse (&iter_dict, &iter_dict_entry);
1786 dbus_message_iter_get_basic (&iter_dict_entry, &key);
1787 dbus_message_iter_next (&iter_dict_entry);
1788 dbus_message_iter_recurse (&iter_dict_entry, &iter_variant);
1789 if (!strcmp (key, "interfaces"))
1791 _atspi_dbus_set_interfaces (accessible, &iter_variant);
1793 else if (!strcmp (key, "Attributes"))
1795 char *iter_sig = dbus_message_iter_get_signature (&iter_variant);
1796 val = g_new0 (GValue, 1);;
1797 g_value_init (val, G_TYPE_HASH_TABLE);
1798 if (strcmp (iter_sig, "a{ss}") != 0)
1800 dbus_free (iter_sig);
1803 dbus_free (iter_sig);
1804 g_value_take_boxed (val, _atspi_dbus_hash_from_iter (&iter_variant));
1806 else if (!strcmp (key, "Component.ScreenExtents"))
1810 char *iter_sig = dbus_message_iter_get_signature (&iter_variant);
1811 val = g_new0 (GValue, 1);;
1812 g_value_init (val, ATSPI_TYPE_RECT);
1813 if (strcmp (iter_sig, "(iiii)") != 0)
1815 dbus_free (iter_sig);
1818 dbus_free (iter_sig);
1819 dbus_message_iter_recurse (&iter_variant, &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);
1825 dbus_message_iter_next (&iter_struct);
1826 dbus_message_iter_get_basic (&iter_struct, &d_int);
1827 extents.width = d_int;
1828 dbus_message_iter_next (&iter_struct);
1829 dbus_message_iter_get_basic (&iter_struct, &d_int);
1830 extents.height = d_int;
1831 g_value_set_boxed (val, &extents);
1834 g_hash_table_insert (cache, g_strdup (key), val);
1835 dbus_message_iter_next (&iter_dict);
1842 _atspi_get_allow_sync ()
1848 _atspi_set_allow_sync (gboolean val)
1850 gboolean ret = allow_sync;
1857 _atspi_set_error_no_sync (GError **error)
1859 g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_SYNC_NOT_ALLOWED,
1860 _("Attempted synchronous call where prohibited"));
1863 static const char *sr_introspection = "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
1864 "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
1865 "<node name=\"/org/a11y/atspi/screenreader\">\n"
1866 " <interface name=\"org.a11y.Atspi.ScreenReader\">\n"
1867 " <signal name=\"ReadingPosition\">\n"
1868 " <arg type=\"i\"/>\n"
1869 " <arg type=\"i\"/>\n"
1874 static DBusHandlerResult
1875 screen_reader_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
1877 if (dbus_message_is_method_call (message, DBUS_INTERFACE_INTROSPECTABLE,
1880 DBusMessage *reply = dbus_message_new_method_return (message);
1881 dbus_message_append_args (reply, DBUS_TYPE_STRING, &sr_introspection,
1883 dbus_connection_send (bus, reply, NULL);
1884 dbus_message_unref (reply);
1885 return DBUS_HANDLER_RESULT_HANDLED;
1887 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1891 _atspi_prepare_screen_reader_interface ()
1893 static gint initialized = 0;
1894 DBusConnection *a11y_bus = _atspi_bus ();
1897 return (initialized > 0);
1899 if (dbus_bus_request_name (a11y_bus, "org.a11y.Atspi.ScreenReader", 0, NULL) < 0)
1906 dbus_connection_add_filter (a11y_bus, screen_reader_filter, NULL, NULL);