2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008, 2010 Codethink Ltd.
6 * Copyright 2001, 2002 Sun Microsystems Inc.,
7 * Copyright 2001, 2002 Ximian, 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.
31 #include "introspection.h"
33 typedef struct event_data event_data;
42 children_added_listener (DBusConnection * bus,
48 children_removed_listener (DBusConnection * bus,
53 /*---------------------------------------------------------------------------*/
55 typedef struct _SpiReference
62 spi_reference_new (const gchar *name, const gchar *path)
66 ref = g_new0 (SpiReference, 1);
67 ref->name = g_strdup (name);
68 ref->path = g_strdup (path);
74 spi_reference_free (SpiReference *ref)
81 /*---------------------------------------------------------------------------*/
83 G_DEFINE_TYPE(SpiRegistry, spi_registry, G_TYPE_OBJECT)
86 spi_registry_class_init (SpiRegistryClass *klass)
88 spi_registry_parent_class = g_type_class_ref (G_TYPE_OBJECT);
92 spi_registry_init (SpiRegistry *registry)
94 registry->apps = g_ptr_array_new_with_free_func ((GDestroyNotify) spi_reference_free);
97 /*---------------------------------------------------------------------------*/
100 return_v_string (DBusMessageIter * iter, const gchar * str)
102 DBusMessageIter variant;
104 if (!dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s",
107 dbus_message_iter_append_basic (&variant, DBUS_TYPE_STRING, &str);
108 dbus_message_iter_close_container (iter, &variant);
113 append_reference (DBusMessageIter * iter, const char * name, const char * path)
115 DBusMessageIter iter_struct;
117 if (!dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL,
120 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
121 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
122 dbus_message_iter_close_container (iter, &iter_struct);
126 /*---------------------------------------------------------------------------*/
129 compare_reference (SpiReference *one, SpiReference *two)
131 if (g_strcmp0 (one->name, two->name) == 0 &&
132 g_strcmp0 (one->path, two->path) == 0)
139 find_index_of_reference (GPtrArray *arr, const gchar *name, const gchar * path, guint *index)
142 gboolean found = FALSE;
145 ref = spi_reference_new (name, path);
147 for (i = 0; i < arr->len; i++)
149 if (compare_reference (ref, g_ptr_array_index (arr, i)))
156 spi_reference_free (ref);
163 add_application (SpiRegistry *reg, DBusConnection *bus, const gchar *name, const gchar *path)
165 g_ptr_array_add (reg->apps, spi_reference_new (name, path));
166 children_added_listener (bus, reg->apps->len - 1, name, path);
170 set_id (SpiRegistry *reg, DBusConnection *bus, const gchar *name, const gchar *path)
172 DBusMessage *message;
173 DBusMessageIter iter, iter_variant;
174 const char *iface_application = "org.a11y.atspi.Application";
175 const char *id = "Id";
177 message = dbus_message_new_method_call (name, path,
178 DBUS_INTERFACE_PROPERTIES, "Set");
181 dbus_message_iter_init_append (message, &iter);
182 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface_application);
183 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &id);
184 dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "i", &iter_variant);
185 dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_INT32, ®->id);
186 /* TODO: This will cause problems if we cycle through 2^31 ids */
188 dbus_message_iter_close_container (&iter, &iter_variant);
189 dbus_connection_send (bus, message, NULL);
190 dbus_message_unref (message);
194 remove_application (SpiRegistry *reg, DBusConnection *bus, guint index)
196 SpiReference *ref = g_ptr_array_index (reg->apps, index);
198 spi_remove_device_listeners (reg->dec, ref->name);
199 children_removed_listener (bus, index, ref->name, ref->path);
200 g_ptr_array_remove_index (reg->apps, index);
204 event_is_subtype (gchar **needle, gchar **haystack)
206 while (*haystack && **haystack)
208 if (g_strcmp0 (*needle, *haystack))
217 needs_mouse_poll (char **event)
219 if (g_strcmp0 (event [0], "Mouse") != 0)
221 if (!event [1] || !event [1][0])
223 return (g_strcmp0 (event [1], "Abs") == 0);
227 remove_events (SpiRegistry *registry, const char *bus_name, const char *event)
231 gboolean mouse_found = FALSE;
234 remove_data = g_strsplit (event, ":", 3);
240 for (list = registry->events; list;)
242 event_data *evdata = list->data;
244 if (!g_strcmp0 (evdata->bus_name, bus_name) &&
245 event_is_subtype (evdata->data, remove_data))
247 g_strfreev (evdata->data);
248 g_free (evdata->bus_name);
249 g_slist_free_full (evdata->properties, g_free);
251 registry->events = g_list_remove (registry->events, evdata);
255 if (needs_mouse_poll (evdata->data))
261 spi_device_event_controller_stop_poll_mouse ();
263 g_strfreev (remove_data);
265 signal = dbus_message_new_signal (SPI_DBUS_PATH_REGISTRY,
266 SPI_DBUS_INTERFACE_REGISTRY,
267 "EventListenerDeregistered");
268 dbus_message_append_args (signal, DBUS_TYPE_STRING, &bus_name,
269 DBUS_TYPE_STRING, &event, DBUS_TYPE_INVALID);
270 dbus_connection_send (registry->bus, signal, NULL);
271 dbus_message_unref (signal);
275 handle_disconnection (DBusConnection *bus, DBusMessage *message, void *user_data)
277 char *name, *old, *new;
278 SpiRegistry *reg = SPI_REGISTRY (user_data);
280 if (dbus_message_get_args (message, NULL,
281 DBUS_TYPE_STRING, &name,
282 DBUS_TYPE_STRING, &old,
283 DBUS_TYPE_STRING, &new,
286 if (*old != '\0' && *new == '\0')
288 /* Remove all children with the application name the same as the disconnected application. */
290 for (i = 0; i < reg->apps->len; i++)
292 SpiReference *ref = g_ptr_array_index (reg->apps, i);
293 if (!g_strcmp0 (old, ref->name))
295 remove_application (reg, bus, i);
300 remove_events (reg, old, "");
306 * Converts names of the form "active-descendant-changed" to
307 *" ActiveDescendantChanged"
310 ensure_proper_format (const char *name)
312 gchar *ret = (gchar *) g_malloc (strlen (name) * 2 + 2);
314 gboolean need_upper = TRUE;
322 *p++ = toupper (*name);
325 else if (*name == '-')
327 else if (*name == ':')
340 static DBusHandlerResult
341 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
343 guint res = DBUS_HANDLER_RESULT_HANDLED;
344 const gint type = dbus_message_get_type (message);
345 const char *iface = dbus_message_get_interface (message);
346 const char *member = dbus_message_get_member (message);
348 if (type != DBUS_MESSAGE_TYPE_SIGNAL)
349 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
351 if (!g_strcmp0(iface, DBUS_INTERFACE_DBUS) &&
352 !g_strcmp0(member, "NameOwnerChanged"))
353 handle_disconnection (bus, message, user_data);
355 res = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
360 /* org.at_spi.Socket interface */
361 /*---------------------------------------------------------------------------*/
364 impl_Embed (DBusConnection *bus, DBusMessage *message, void *user_data)
366 SpiRegistry *reg = SPI_REGISTRY (user_data);
367 DBusMessageIter iter, iter_struct;
368 const gchar *app_name, *obj_path;
370 DBusMessage *reply = NULL;
371 DBusMessageIter reply_iter;
373 dbus_message_iter_init (message, &iter);
374 dbus_message_iter_recurse (&iter, &iter_struct);
375 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_STRING))
377 dbus_message_iter_get_basic (&iter_struct, &app_name);
379 app_name = dbus_message_get_sender (message);
380 if (!dbus_message_iter_next (&iter_struct))
382 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_OBJECT_PATH))
384 dbus_message_iter_get_basic (&iter_struct, &obj_path);
386 add_application(reg, bus, app_name, obj_path);
388 set_id (reg, bus, app_name, obj_path);
390 reply = dbus_message_new_method_return (message);
391 dbus_message_iter_init_append (reply, &reply_iter);
392 append_reference (&reply_iter,
393 dbus_bus_get_unique_name (bus),
398 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
402 impl_Unembed (DBusConnection *bus, DBusMessage *message, void *user_data)
404 SpiRegistry *reg = SPI_REGISTRY (user_data);
405 DBusMessageIter iter, iter_struct;
406 gchar *app_name, *obj_path;
409 dbus_message_iter_init (message, &iter);
410 dbus_message_iter_recurse (&iter, &iter_struct);
411 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_STRING))
413 dbus_message_iter_get_basic (&iter_struct, &app_name);
414 if (!dbus_message_iter_next (&iter_struct))
416 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_OBJECT_PATH))
418 dbus_message_iter_get_basic (&iter_struct, &obj_path);
420 if (find_index_of_reference (reg->apps, app_name, obj_path, &index))
421 remove_application(reg, bus, index);
425 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
428 /* org.at_spi.Component interface */
429 /*---------------------------------------------------------------------------*/
432 impl_Contains (DBusConnection * bus, DBusMessage * message, void *user_data)
434 dbus_bool_t retval = FALSE;
437 reply = dbus_message_new_method_return (message);
438 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
444 impl_GetAccessibleAtPoint (DBusConnection * bus, DBusMessage * message,
447 DBusMessage *reply = NULL;
448 DBusMessageIter iter;
450 reply = dbus_message_new_method_return (message);
451 dbus_message_iter_init_append (reply, &iter);
452 append_reference (&iter,
453 dbus_bus_get_unique_name (bus),
460 impl_GetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
462 dbus_int32_t x = 0, y = 0, width = 1024, height = 768;
464 DBusMessageIter iter, iter_struct;
466 reply = dbus_message_new_method_return (message);
467 dbus_message_iter_init_append (reply, &iter);
468 dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL,
470 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &x);
471 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &y);
472 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &width);
473 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &height);
474 dbus_message_iter_close_container (&iter, &iter_struct);
479 impl_GetPosition (DBusConnection * bus, DBusMessage * message,
483 dbus_int32_t x = 0, y = 0;
485 reply = dbus_message_new_method_return (message);
486 dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
487 &y, DBUS_TYPE_INVALID);
492 impl_GetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
494 /* TODO - Get the screen size */
496 dbus_int32_t width = 1024, height = 768;
498 reply = dbus_message_new_method_return (message);
499 dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
500 DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
504 #define LAYER_WIDGET 3;
507 impl_GetLayer (DBusConnection * bus, DBusMessage * message, void *user_data)
510 dbus_uint32_t rv = LAYER_WIDGET;
512 reply = dbus_message_new_method_return (message);
513 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
519 impl_GetMDIZOrder (DBusConnection * bus, DBusMessage * message,
525 reply = dbus_message_new_method_return (message);
526 dbus_message_append_args (reply, DBUS_TYPE_INT16, &rv,
532 impl_GrabFocus (DBusConnection * bus, DBusMessage * message, void *user_data)
535 dbus_bool_t retval = FALSE;
537 reply = dbus_message_new_method_return (message);
538 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
544 impl_GetAlpha (DBusConnection * bus, DBusMessage * message, void *user_data)
549 reply = dbus_message_new_method_return (message);
550 dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
555 /* org.at_spi.Accessible interface */
556 /*---------------------------------------------------------------------------*/
559 impl_get_Name (DBusMessageIter * iter, void *user_data)
561 const gchar *name = "main";
562 return return_v_string (iter, name);
566 impl_get_Description (DBusMessageIter * iter, void *user_data)
568 const gchar *description = "";
569 return return_v_string (iter, description);
573 impl_get_Parent (DBusMessageIter * iter, void *user_data)
575 const gchar *name = "";
576 DBusMessageIter iter_variant;
578 dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(so)",
580 append_reference (&iter_variant,
583 dbus_message_iter_close_container (iter, &iter_variant);
588 impl_get_ChildCount (DBusMessageIter * iter, void *user_data)
590 SpiRegistry *reg = SPI_REGISTRY (user_data);
591 dbus_int32_t rv = reg->apps->len;
593 DBusMessageIter iter_variant;
595 if (!dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "i",
598 result = dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_INT32, &rv);
599 dbus_message_iter_close_container (iter, &iter_variant);
604 impl_get_ToolkitName (DBusMessageIter * iter, void *user_data)
606 return return_v_string (iter, "at-spi-registry");
610 impl_get_ToolkitVersion (DBusMessageIter * iter, void *user_data)
612 return return_v_string (iter, "2.0");
616 impl_GetChildAtIndex (DBusConnection * bus,
617 DBusMessage * message, void *user_data)
619 SpiRegistry *reg = SPI_REGISTRY (user_data);
621 DBusMessageIter iter;
626 dbus_error_init (&error);
627 if (!dbus_message_get_args
628 (message, &error, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID))
630 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
633 reply = dbus_message_new_method_return (message);
634 dbus_message_iter_init_append (reply, &iter);
636 if (i < 0 || i >= reg->apps->len)
637 append_reference (&iter, SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_NULL);
640 ref = g_ptr_array_index (reg->apps, i);
641 append_reference (&iter, ref->name, ref->path);
648 impl_GetChildren (DBusConnection * bus,
649 DBusMessage * message, void *user_data)
651 DBusMessage *reply = NULL;
652 DBusMessageIter iter, iter_array;
653 SpiRegistry *reg = SPI_REGISTRY (user_data);
656 reply = dbus_message_new_method_return (message);
658 dbus_message_iter_init_append (reply, &iter);
659 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(so)", &iter_array);
660 for (i=0; i < reg->apps->len; i++)
662 SpiReference *current = g_ptr_array_index (reg->apps, i);
663 append_reference (&iter_array, current->name, current->path);
665 dbus_message_iter_close_container(&iter, &iter_array);
670 impl_GetIndexInParent (DBusConnection * bus,
671 DBusMessage * message, void *user_data)
674 dbus_uint32_t rv = 0;
676 reply = dbus_message_new_method_return (message);
677 dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv, DBUS_TYPE_INVALID);
682 impl_GetRelationSet (DBusConnection * bus,
683 DBusMessage * message, void *user_data)
686 DBusMessageIter iter, iter_array;
688 reply = dbus_message_new_method_return (message);
689 dbus_message_iter_init_append (reply, &iter);
690 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ua(so))", &iter_array);
691 dbus_message_iter_close_container (&iter, &iter_array);
697 impl_GetRole (DBusConnection * bus, DBusMessage * message, void * user_data)
700 dbus_uint32_t rv = 14; /* TODO: Get DESKTOP_FRAME from somewhere */
702 reply = dbus_message_new_method_return (message);
703 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv, DBUS_TYPE_INVALID);
708 impl_GetRoleName (DBusConnection * bus,
709 DBusMessage * message, void *user_data)
712 const char *role_name = "desktop frame";
714 reply = dbus_message_new_method_return (message);
715 dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
721 impl_GetLocalizedRoleName (DBusConnection * bus,
722 DBusMessage * message, void *user_data)
724 /* TODO - Localize this */
726 const char *role_name = "desktop frame";
728 reply = dbus_message_new_method_return (message);
729 dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
735 impl_GetState (DBusConnection * bus, DBusMessage * message, void *user_data)
737 DBusMessage *reply = NULL;
738 DBusMessageIter iter, iter_array;
740 dbus_uint32_t states[2] = {0, 0};
743 reply = dbus_message_new_method_return (message);
744 dbus_message_iter_init_append (reply, &iter);
746 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "u", &iter_array);
747 for (count = 0; count < 2; count++)
749 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_UINT32,
752 dbus_message_iter_close_container (&iter, &iter_array);
757 impl_GetAttributes (DBusConnection * bus,
758 DBusMessage * message, void *user_data)
760 DBusMessage *reply = NULL;
761 DBusMessageIter iter, array;
763 reply = dbus_message_new_method_return (message);
764 dbus_message_iter_init_append (reply, &iter);
765 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{ss}", &array);
766 dbus_message_iter_close_container (&iter, &array);
772 impl_GetApplication (DBusConnection * bus,
773 DBusMessage * message, void *user_data)
775 DBusMessage *reply = NULL;
776 DBusMessageIter iter;
778 reply = dbus_message_new_method_return (message);
779 dbus_message_iter_init_append (reply, &iter);
780 append_reference (&iter,
781 dbus_bus_get_unique_name (bus),
788 impl_GetInterfaces (DBusConnection * bus,
789 DBusMessage * message, void *user_data)
792 DBusMessageIter iter, iter_array;
794 const char *acc = SPI_DBUS_INTERFACE_ACCESSIBLE;
795 const char *com = SPI_DBUS_INTERFACE_COMPONENT;
797 reply = dbus_message_new_method_return (message);
799 dbus_message_iter_init_append (reply, &iter);
800 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s",
802 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &acc);
803 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &com);
804 dbus_message_iter_close_container (&iter, &iter_array);
810 impl_GetItems (DBusConnection * bus, DBusMessage * message, void *user_data)
813 DBusMessageIter iter, iter_array;
815 reply = dbus_message_new_method_return (message);
817 dbus_message_iter_init_append (reply, &iter);
818 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
819 "((so)(so)(so)a(so)assusau)", &iter_array);
820 dbus_message_iter_close_container (&iter, &iter_array);
824 /* I would rather these two be signals, but I'm not sure that dbus-python
825 * supports emitting signals except for a service, so implementing as both
826 * a method call and signal for now.
829 impl_register_event (DBusConnection *bus, DBusMessage *message, void *user_data)
831 SpiRegistry *registry = SPI_REGISTRY (user_data);
832 const char *orig_name;
837 const char *sender = dbus_message_get_sender (message);
838 DBusMessageIter iter, iter_array;
839 const char *signature = dbus_message_get_signature (message);
841 if (strcmp (signature, "sas") != 0 &&
842 strcmp (signature, "s") != 0)
844 g_warning ("got RegisterEvent with invalid signature '%s'", signature);
848 dbus_message_iter_init (message, &iter);
849 dbus_message_iter_get_basic (&iter, &orig_name);
850 dbus_message_iter_next (&iter);
851 name = ensure_proper_format (orig_name);
853 evdata = g_new0 (event_data, 1);
854 data = g_strsplit (name, ":", 3);
855 evdata->bus_name = g_strdup (sender);
858 if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY)
860 dbus_message_iter_recurse (&iter, &iter_array);
861 while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
863 const char *property;
864 dbus_message_iter_get_basic (&iter_array, &property);
865 evdata->properties = g_slist_append (evdata->properties,
866 g_strdup (property));
867 dbus_message_iter_next (&iter_array);
870 registry->events = g_list_append (registry->events, evdata);
872 if (needs_mouse_poll (evdata->data))
874 spi_device_event_controller_start_poll_mouse (registry);
877 signal = dbus_message_new_signal (SPI_DBUS_PATH_REGISTRY,
878 SPI_DBUS_INTERFACE_REGISTRY,
879 "EventListenerRegistered");
882 GSList *ls = evdata->properties;
883 dbus_message_iter_init_append (signal, &iter);
884 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &sender);
885 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
886 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &iter_array);
889 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &ls->data);
890 ls = g_slist_next (ls);
892 dbus_message_iter_close_container (&iter, &iter_array);
893 dbus_connection_send (bus, signal, NULL);
894 dbus_message_unref (signal);
898 return dbus_message_new_method_return (message);
902 impl_deregister_event (DBusConnection *bus, DBusMessage *message, void *user_data)
904 SpiRegistry *registry = SPI_REGISTRY (user_data);
905 const char *orig_name;
907 const char *sender = dbus_message_get_sender (message);
909 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &orig_name,
912 name = ensure_proper_format (orig_name);
914 remove_events (registry, sender, name);
917 return dbus_message_new_method_return (message);
921 impl_get_registered_events (DBusConnection *bus, DBusMessage *message, void *user_data)
923 SpiRegistry *registry = SPI_REGISTRY (user_data);
926 DBusMessageIter iter, iter_struct, iter_array;
929 reply = dbus_message_new_method_return (message);
933 dbus_message_iter_init_append (reply, &iter);
934 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ss)", &iter_array);
935 for (list = registry->events; list; list = list->next)
939 str = g_strconcat (evdata->data [0],
940 ":", (evdata->data [1]? evdata->data [1]: ""),
941 ":", (evdata->data [1] && evdata->data [2]? evdata->data [2]: ""), NULL);
942 dbus_message_iter_open_container (&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
943 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &evdata->bus_name);
944 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &str);
945 dbus_message_iter_close_container (&iter_array, &iter_struct);
948 dbus_message_iter_close_container (&iter, &iter_array);
952 /*---------------------------------------------------------------------------*/
955 emit_Available (DBusConnection * bus)
958 DBusMessageIter iter;
960 sig = dbus_message_new_signal(SPI_DBUS_PATH_ROOT, SPI_DBUS_INTERFACE_SOCKET, "Available");
962 dbus_message_iter_init_append(sig, &iter);
963 append_reference (&iter, SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_ROOT);
965 dbus_connection_send(bus, sig, NULL);
966 dbus_message_unref(sig);
969 /*---------------------------------------------------------------------------*/
971 static const char *introspection_header =
972 "<?xml version=\"1.0\"?>\n";
974 static const char *introspection_node_element =
975 "<node name=\"%s\">\n";
977 static const char *introspection_footer =
981 impl_Introspect_root (DBusConnection * bus,
982 DBusMessage * message, void *user_data)
987 const gchar *pathstr = SPI_DBUS_PATH_ROOT;
991 output = g_string_new(introspection_header);
993 g_string_append_printf(output, introspection_node_element, pathstr);
995 g_string_append (output, spi_org_a11y_atspi_Accessible);
996 g_string_append (output, spi_org_a11y_atspi_Component);
998 g_string_append(output, introspection_footer);
999 final = g_string_free(output, FALSE);
1001 reply = dbus_message_new_method_return (message);
1002 dbus_message_append_args(reply, DBUS_TYPE_STRING, &final, DBUS_TYPE_INVALID);
1008 static DBusMessage *
1009 impl_Introspect_registry (DBusConnection * bus,
1010 DBusMessage * message, void *user_data)
1015 const gchar *pathstr = SPI_DBUS_PATH_REGISTRY;
1019 output = g_string_new(introspection_header);
1021 g_string_append_printf(output, introspection_node_element, pathstr);
1023 g_string_append (output, spi_org_a11y_atspi_Registry);
1025 g_string_append(output, introspection_footer);
1026 final = g_string_free(output, FALSE);
1028 reply = dbus_message_new_method_return (message);
1029 dbus_message_append_args(reply, DBUS_TYPE_STRING, &final, DBUS_TYPE_INVALID);
1035 /*---------------------------------------------------------------------------*/
1038 * Emits an AT-SPI event.
1039 * AT-SPI events names are split into three parts:
1041 * This is mapped onto D-Bus events as:
1042 * D-Bus Interface:Signal Name:Detail argument
1044 * Marshals a basic type into the 'any_data' attribute of
1048 emit_event (DBusConnection *bus,
1052 dbus_int32_t detail1,
1053 dbus_int32_t detail2,
1058 DBusMessageIter iter, iter_variant;
1060 sig = dbus_message_new_signal(SPI_DBUS_PATH_ROOT, klass, major);
1062 dbus_message_iter_init_append(sig, &iter);
1064 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor);
1065 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
1066 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
1068 dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(so)",
1070 append_reference (&iter_variant, name, path);
1071 dbus_message_iter_close_container (&iter, &iter_variant);
1073 append_reference (&iter,
1074 dbus_bus_get_unique_name (bus),
1075 SPI_DBUS_PATH_ROOT);
1077 dbus_connection_send(bus, sig, NULL);
1078 dbus_message_unref(sig);
1081 /*---------------------------------------------------------------------------*/
1084 * Children changed signal converter and forwarder.
1086 * Klass (Interface) org.a11y.atspi.Event.Object
1087 * Major is the signal name.
1088 * Minor is 'add' or 'remove'
1089 * detail1 is the index.
1091 * any_data is the child reference.
1095 children_added_listener (DBusConnection * bus,
1100 emit_event (bus, SPI_DBUS_INTERFACE_EVENT_OBJECT, "ChildrenChanged", "add", index, 0,
1105 children_removed_listener (DBusConnection * bus,
1110 emit_event (bus, SPI_DBUS_INTERFACE_EVENT_OBJECT, "ChildrenChanged", "remove", index, 0,
1114 /*---------------------------------------------------------------------------*/
1116 static DBusHandlerResult
1117 handle_method_root (DBusConnection *bus, DBusMessage *message, void *user_data)
1119 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1121 const gchar *iface = dbus_message_get_interface (message);
1122 const gchar *member = dbus_message_get_member (message);
1123 const gint type = dbus_message_get_type (message);
1125 DBusMessage *reply = NULL;
1127 /* Check for basic reasons not to handle */
1128 if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
1131 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1133 if (!strcmp (iface, "org.freedesktop.DBus.Properties"))
1135 if (!strcmp (member, "Get"))
1137 const gchar *prop_iface;
1138 const gchar *prop_member;
1141 dbus_error_init (&error);
1142 if (dbus_message_get_args (message,
1150 DBusMessageIter iter;
1152 reply = dbus_message_new_method_return (message);
1153 dbus_message_iter_init_append (reply, &iter);
1156 if (!strcmp (prop_iface, SPI_DBUS_INTERFACE_ACCESSIBLE))
1158 if (!strcmp (prop_member, "Name"))
1159 impl_get_Name (&iter, user_data);
1160 else if (!strcmp (prop_member, "Description"))
1161 impl_get_Description (&iter, user_data);
1162 else if (!strcmp (prop_member, "Parent"))
1163 impl_get_Parent (&iter, user_data);
1164 else if (!strcmp (prop_member, "ChildCount"))
1165 impl_get_ChildCount (&iter, user_data);
1168 dbus_message_unref (reply);
1169 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
1172 else if (!strcmp (prop_iface, SPI_DBUS_INTERFACE_APPLICATION))
1174 if (!strcmp (prop_member, "ToolkitName"))
1175 impl_get_ToolkitName (&iter, user_data);
1176 else if (!strcmp (prop_member, "ToolkitVersion"))
1177 impl_get_ToolkitVersion (&iter, user_data);
1180 dbus_message_unref (reply);
1181 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
1186 dbus_message_unref (reply);
1187 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
1192 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, error.message);
1194 result = DBUS_HANDLER_RESULT_HANDLED;
1196 else if (!strcmp (member, "GetAll"))
1198 result = DBUS_HANDLER_RESULT_HANDLED;
1202 if (!strcmp (iface, SPI_DBUS_INTERFACE_ACCESSIBLE))
1204 result = DBUS_HANDLER_RESULT_HANDLED;
1205 if (!strcmp (member, "GetChildAtIndex"))
1206 reply = impl_GetChildAtIndex (bus, message, user_data);
1207 else if (!strcmp (member, "GetChildren"))
1208 reply = impl_GetChildren (bus, message, user_data);
1209 else if (!strcmp (member, "GetIndexInParent"))
1210 reply = impl_GetIndexInParent (bus, message, user_data);
1211 else if (!strcmp (member, "GetRelationSet"))
1212 reply = impl_GetRelationSet (bus, message, user_data);
1213 else if (!strcmp (member, "GetRole"))
1214 reply = impl_GetRole (bus, message, user_data);
1215 else if (!strcmp (member, "GetRoleName"))
1216 reply = impl_GetRoleName (bus, message, user_data);
1217 else if (!strcmp (member, "GetLocalizedRoleName"))
1218 reply = impl_GetLocalizedRoleName (bus, message, user_data);
1219 else if (!strcmp (member, "GetState"))
1220 reply = impl_GetState (bus, message, user_data);
1221 else if (!strcmp (member, "GetAttributes"))
1222 reply = impl_GetAttributes (bus, message, user_data);
1223 else if (!strcmp (member, "GetApplication"))
1224 reply = impl_GetApplication (bus, message, user_data);
1225 else if (!strcmp (member, "GetInterfaces"))
1226 reply = impl_GetInterfaces (bus, message, user_data);
1228 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1231 if (!strcmp (iface, SPI_DBUS_INTERFACE_COMPONENT))
1233 result = DBUS_HANDLER_RESULT_HANDLED;
1234 if (!strcmp (member, "Contains"))
1235 reply = impl_Contains (bus, message, user_data);
1236 else if (!strcmp (member, "GetAccessibleAtPoint"))
1237 reply = impl_GetAccessibleAtPoint (bus, message, user_data);
1238 else if (!strcmp (member, "GetExtents"))
1239 reply = impl_GetExtents (bus, message, user_data);
1240 else if (!strcmp (member, "GetPosition"))
1241 reply = impl_GetPosition (bus, message, user_data);
1242 else if (!strcmp (member, "GetSize"))
1243 reply = impl_GetSize (bus, message, user_data);
1244 else if (!strcmp (member, "GetLayer"))
1245 reply = impl_GetLayer (bus, message, user_data);
1246 else if (!strcmp (member, "GetMDIZOrder"))
1247 reply = impl_GetMDIZOrder (bus, message, user_data);
1248 else if (!strcmp (member, "GrabFocus"))
1249 reply = impl_GrabFocus (bus, message, user_data);
1250 else if (!strcmp (member, "GetAlpha"))
1251 reply = impl_GetAlpha (bus, message, user_data);
1253 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1256 if (!strcmp (iface, SPI_DBUS_INTERFACE_SOCKET))
1258 result = DBUS_HANDLER_RESULT_HANDLED;
1259 if (!strcmp (member, "Embed"))
1260 reply = impl_Embed (bus, message, user_data);
1261 else if (!strcmp (member, "Unembed"))
1262 reply = impl_Unembed (bus, message, user_data);
1264 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1267 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
1269 result = DBUS_HANDLER_RESULT_HANDLED;
1270 if (!strcmp (member, "Introspect"))
1271 reply = impl_Introspect_root (bus, message, user_data);
1273 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1276 if (result == DBUS_HANDLER_RESULT_HANDLED)
1280 reply = dbus_message_new_method_return (message);
1283 dbus_connection_send (bus, reply, NULL);
1284 dbus_message_unref (reply);
1289 g_print ("Registry | Unhandled message : %s|%s\n", iface, member);
1296 static DBusHandlerResult
1297 handle_method_cache (DBusConnection *bus, DBusMessage *message, void *user_data)
1299 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1301 const gchar *iface = dbus_message_get_interface (message);
1302 const gchar *member = dbus_message_get_member (message);
1303 const gint type = dbus_message_get_type (message);
1305 DBusMessage *reply = NULL;
1307 /* Check for basic reasons not to handle */
1308 if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
1311 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1313 if (!strcmp (iface, SPI_DBUS_INTERFACE_CACHE))
1315 result = DBUS_HANDLER_RESULT_HANDLED;
1316 if (!strcmp (member, "GetItems"))
1317 reply = impl_GetItems (bus, message, user_data);
1319 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1322 if (result == DBUS_HANDLER_RESULT_HANDLED)
1326 reply = dbus_message_new_method_return (message);
1329 dbus_connection_send (bus, reply, NULL);
1330 dbus_message_unref (reply);
1335 static DBusHandlerResult
1336 handle_method_registry (DBusConnection *bus, DBusMessage *message, void *user_data)
1338 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1340 const gchar *iface = dbus_message_get_interface (message);
1341 const gchar *member = dbus_message_get_member (message);
1342 const gint type = dbus_message_get_type (message);
1344 DBusMessage *reply = NULL;
1346 /* Check for basic reasons not to handle */
1347 if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
1350 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1352 if (!strcmp (iface, SPI_DBUS_INTERFACE_REGISTRY))
1354 result = DBUS_HANDLER_RESULT_HANDLED;
1355 if (!strcmp(member, "RegisterEvent"))
1356 reply = impl_register_event (bus, message, user_data);
1357 else if (!strcmp(member, "DeregisterEvent"))
1358 reply = impl_deregister_event (bus, message, user_data);
1359 else if (!strcmp(member, "GetRegisteredEvents"))
1360 reply = impl_get_registered_events (bus, message, user_data);
1362 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1365 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
1367 result = DBUS_HANDLER_RESULT_HANDLED;
1368 if (!strcmp (member, "Introspect"))
1369 reply = impl_Introspect_registry (bus, message, user_data);
1371 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1374 if (result == DBUS_HANDLER_RESULT_HANDLED)
1378 reply = dbus_message_new_method_return (message);
1381 dbus_connection_send (bus, reply, NULL);
1382 dbus_message_unref (reply);
1387 g_print ("Registry | Unhandled message : %s|%s\n", iface, member);
1394 /*---------------------------------------------------------------------------*/
1396 static DBusObjectPathVTable root_vtable =
1399 &handle_method_root,
1400 NULL, NULL, NULL, NULL
1403 static DBusObjectPathVTable registry_vtable =
1406 &handle_method_registry,
1407 NULL, NULL, NULL, NULL
1410 static DBusObjectPathVTable cache_vtable =
1413 &handle_method_cache,
1414 NULL, NULL, NULL, NULL
1417 static gchar *app_sig_match_name_owner =
1418 "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged'";
1421 spi_registry_new (DBusConnection *bus)
1423 SpiRegistry *reg = g_object_new (SPI_REGISTRY_TYPE, NULL);
1427 dbus_bus_add_match (bus, app_sig_match_name_owner, NULL);
1428 dbus_connection_add_filter (bus, signal_filter, reg, NULL);
1430 dbus_connection_register_object_path (bus, SPI_DBUS_PATH_ROOT, &root_vtable, reg);
1432 dbus_connection_register_object_path (bus, SPI_DBUS_PATH_CACHE, &cache_vtable, reg);
1434 dbus_connection_register_object_path (bus, SPI_DBUS_PATH_REGISTRY, ®istry_vtable, reg);
1436 emit_Available (bus);
1443 /*END------------------------------------------------------------------------*/