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.
28 #include <dbus/dbus-glib-lowlevel.h>
32 #include "introspection.h"
34 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 GObjectClass * object_class = (GObjectClass *) klass;
90 spi_registry_parent_class = g_type_class_ref (G_TYPE_OBJECT);
94 spi_registry_init (SpiRegistry *registry)
96 registry->apps = g_ptr_array_new_with_free_func ((GDestroyNotify) spi_reference_free);
99 /*---------------------------------------------------------------------------*/
102 return_v_string (DBusMessageIter * iter, const gchar * str)
104 DBusMessageIter variant;
106 if (!dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s",
109 dbus_message_iter_append_basic (&variant, DBUS_TYPE_STRING, &str);
110 dbus_message_iter_close_container (iter, &variant);
115 append_reference (DBusMessageIter * iter, const char * name, const char * path)
117 DBusMessageIter iter_struct;
119 if (!dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL,
122 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
123 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
124 dbus_message_iter_close_container (iter, &iter_struct);
128 /*---------------------------------------------------------------------------*/
131 compare_reference (SpiReference *one, SpiReference *two)
133 if (g_strcmp0 (one->name, two->name) == 0 &&
134 g_strcmp0 (one->path, two->path) == 0)
141 find_index_of_reference (GPtrArray *arr, const gchar *name, const gchar * path, guint *index)
144 gboolean found = FALSE;
147 ref = spi_reference_new (name, path);
149 for (i = 0; i < arr->len && found == FALSE; i++)
151 if (compare_reference (ref, g_ptr_array_index (arr, i)));
157 spi_reference_free (ref);
164 add_application (SpiRegistry *reg, DBusConnection *bus, const gchar *name, const gchar *path)
166 g_ptr_array_add (reg->apps, spi_reference_new (name, path));
167 children_added_listener (bus, reg->apps->len - 1, name, path);
171 set_id (SpiRegistry *reg, DBusConnection *bus, const gchar *name, const gchar *path)
173 DBusMessage *message;
174 DBusMessageIter iter, iter_variant;
175 const char *iface_application = "org.a11y.atspi.Application";
176 const char *id = "Id";
178 message = dbus_message_new_method_call (name, path,
179 DBUS_INTERFACE_PROPERTIES, "Set");
182 dbus_message_iter_init_append (message, &iter);
183 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface_application);
184 dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &id);
185 dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "i", &iter_variant);
186 dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_INT32, ®->id);
187 /* TODO: This will cause problems if we cycle through 2^31 ids */
189 dbus_message_iter_close_container (&iter, &iter_variant);
190 dbus_connection_send (bus, message, NULL);
191 dbus_message_unref (message);
195 remove_application (SpiRegistry *reg, DBusConnection *bus, guint index)
197 SpiReference *ref = g_ptr_array_index (reg->apps, index);
199 /*TODO spi_remove_device_listeners (registry->de_controller, old);*/
200 children_removed_listener (bus, index, ref->name, ref->path);
201 g_ptr_array_remove_index (reg->apps, index);
205 event_is_subtype (gchar **needle, gchar **haystack)
207 while (*haystack && **haystack)
209 if (g_strcmp0 (*needle, *haystack))
218 needs_mouse_poll (char **event)
220 if (g_strcmp0 (event [0], "Mouse") != 0)
222 if (!event [1] || !event [1][0])
224 return (g_strcmp0 (event [1], "Abs") == 0);
228 remove_events (SpiRegistry *registry, const char *bus_name, const char *event)
233 gboolean mouse_found = FALSE;
236 remove_data = g_strsplit (event, ":", 3);
242 for (list = registry->events; list;)
244 event_data *evdata = list->data;
245 if (!g_strcmp0 (evdata->bus_name, bus_name) &&
246 event_is_subtype (evdata->data, remove_data))
249 g_strfreev (evdata->data);
250 g_free (evdata->bus_name);
252 registry->events = g_list_remove (registry->events, evdata);
256 if (needs_mouse_poll (evdata->data))
263 spi_device_event_controller_stop_poll_mouse ();
265 g_strfreev (remove_data);
267 signal = dbus_message_new_signal (SPI_DBUS_PATH_REGISTRY,
268 SPI_DBUS_INTERFACE_REGISTRY,
269 "EventListenerDeregistered");
270 dbus_message_append_args (signal, DBUS_TYPE_STRING, &bus_name,
271 DBUS_TYPE_STRING, &event, DBUS_TYPE_INVALID);
272 dbus_connection_send (registry->bus, signal, NULL);
273 dbus_message_unref (signal);
277 handle_disconnection (DBusConnection *bus, DBusMessage *message, void *user_data)
279 char *name, *old, *new;
280 SpiRegistry *reg = SPI_REGISTRY (user_data);
282 if (dbus_message_get_args (message, NULL,
283 DBUS_TYPE_STRING, &name,
284 DBUS_TYPE_STRING, &old,
285 DBUS_TYPE_STRING, &new,
288 if (*old != '\0' && *new == '\0')
290 /* Remove all children with the application name the same as the disconnected application. */
292 for (i = 0; i < reg->apps->len; i++)
294 SpiReference *ref = g_ptr_array_index (reg->apps, i);
295 while (!g_strcmp0 (old, ref->name))
297 children_removed_listener (bus, i, old, ref->path);
298 g_ptr_array_remove_index (reg->apps, i);
302 remove_events (reg, old, "");
308 * Converts names of the form "active-descendant-changed" to
309 *" ActiveDescendantChanged"
312 ensure_proper_format (const char *name)
314 gchar *ret = (gchar *) g_malloc (strlen (name) * 2 + 2);
316 gboolean need_upper = TRUE;
324 *p++ = toupper (*name);
327 else if (*name == '-')
329 else if (*name == ':')
342 static DBusHandlerResult
343 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
345 SpiRegistry *registry = SPI_REGISTRY (user_data);
346 guint res = DBUS_HANDLER_RESULT_HANDLED;
347 const gint type = dbus_message_get_type (message);
348 const char *iface = dbus_message_get_interface (message);
349 const char *member = dbus_message_get_member (message);
351 if (type != DBUS_MESSAGE_TYPE_SIGNAL)
354 if (!g_strcmp0(iface, DBUS_INTERFACE_DBUS) &&
355 !g_strcmp0(member, "NameOwnerChanged"))
356 handle_disconnection (bus, message, user_data);
358 res = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
363 /* org.at_spi.Socket interface */
364 /*---------------------------------------------------------------------------*/
367 impl_Embed (DBusConnection *bus, DBusMessage *message, void *user_data)
369 SpiRegistry *reg = SPI_REGISTRY (user_data);
370 DBusMessageIter iter, iter_struct;
371 gchar *app_name, *obj_path;
373 DBusMessage *reply = NULL;
374 DBusMessageIter reply_iter;
376 dbus_message_iter_init (message, &iter);
377 dbus_message_iter_recurse (&iter, &iter_struct);
378 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_STRING))
380 dbus_message_iter_get_basic (&iter_struct, &app_name);
381 if (!dbus_message_iter_next (&iter_struct))
383 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_OBJECT_PATH))
385 dbus_message_iter_get_basic (&iter_struct, &obj_path);
387 add_application(reg, bus, app_name, obj_path);
389 set_id (reg, bus, app_name, obj_path);
391 reply = dbus_message_new_method_return (message);
392 dbus_message_iter_init_append (reply, &reply_iter);
393 append_reference (&reply_iter,
394 dbus_bus_get_unique_name (bus),
399 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
403 impl_Unembed (DBusConnection *bus, DBusMessage *message, void *user_data)
405 SpiRegistry *reg = SPI_REGISTRY (user_data);
406 DBusMessageIter iter, iter_struct;
407 gchar *app_name, *obj_path;
410 dbus_message_iter_init (message, &iter);
411 dbus_message_iter_recurse (&iter, &iter_struct);
412 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_STRING))
414 dbus_message_iter_get_basic (&iter_struct, &app_name);
415 if (!dbus_message_iter_next (&iter_struct))
417 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_OBJECT_PATH))
419 dbus_message_iter_get_basic (&iter_struct, &obj_path);
421 if (find_index_of_reference (reg->apps, app_name, obj_path, &index))
422 remove_application(reg, bus, index);
426 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
429 /* org.at_spi.Component interface */
430 /*---------------------------------------------------------------------------*/
433 impl_Contains (DBusConnection * bus, DBusMessage * message, void *user_data)
435 dbus_bool_t retval = FALSE;
438 reply = dbus_message_new_method_return (message);
439 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
445 impl_GetAccessibleAtPoint (DBusConnection * bus, DBusMessage * message,
448 DBusMessage *reply = NULL;
449 DBusMessageIter iter;
451 reply = dbus_message_new_method_return (message);
452 dbus_message_iter_init_append (reply, &iter);
453 append_reference (&iter,
454 dbus_bus_get_unique_name (bus),
461 impl_GetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
463 dbus_uint32_t coord_type;
464 dbus_int32_t x = 0, y = 0, width = 1024, height = 768;
466 DBusMessageIter iter, iter_struct;
468 reply = dbus_message_new_method_return (message);
469 dbus_message_iter_init_append (reply, &iter);
470 dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL,
472 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &x);
473 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &y);
474 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &width);
475 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &height);
476 dbus_message_iter_close_container (&iter, &iter_struct);
481 impl_GetPosition (DBusConnection * bus, DBusMessage * message,
485 dbus_int32_t x = 0, y = 0;
487 reply = dbus_message_new_method_return (message);
488 dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
489 &y, DBUS_TYPE_INVALID);
494 impl_GetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
496 /* TODO - Get the screen size */
498 dbus_int32_t width = 1024, height = 768;
500 reply = dbus_message_new_method_return (message);
501 dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
502 DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
506 #define LAYER_WIDGET 3;
509 impl_GetLayer (DBusConnection * bus, DBusMessage * message, void *user_data)
512 dbus_uint32_t rv = LAYER_WIDGET;
514 reply = dbus_message_new_method_return (message);
515 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
521 impl_GetMDIZOrder (DBusConnection * bus, DBusMessage * message,
527 reply = dbus_message_new_method_return (message);
528 dbus_message_append_args (reply, DBUS_TYPE_INT16, &rv,
534 impl_GrabFocus (DBusConnection * bus, DBusMessage * message, void *user_data)
537 dbus_bool_t retval = FALSE;
539 reply = dbus_message_new_method_return (message);
540 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
546 impl_GetAlpha (DBusConnection * bus, DBusMessage * message, void *user_data)
551 reply = dbus_message_new_method_return (message);
552 dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
557 /* org.at_spi.Accessible interface */
558 /*---------------------------------------------------------------------------*/
561 impl_get_Name (DBusMessageIter * iter, void *user_data)
563 const gchar *name = "main";
564 return return_v_string (iter, name);
568 impl_get_Description (DBusMessageIter * iter, void *user_data)
570 const gchar *description = "";
571 return return_v_string (iter, description);
575 impl_get_Parent (DBusMessageIter * iter, void *user_data)
577 const gchar *name = "";
578 DBusMessageIter iter_variant;
580 dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(so)",
582 append_reference (&iter_variant,
585 dbus_message_iter_close_container (iter, &iter_variant);
590 impl_get_ChildCount (DBusMessageIter * iter, void *user_data)
592 SpiRegistry *reg = SPI_REGISTRY (user_data);
593 dbus_int32_t rv = reg->apps->len;
595 DBusMessageIter iter_variant;
597 if (!dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "i",
600 result = dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_INT32, &rv);
601 dbus_message_iter_close_container (iter, &iter_variant);
606 impl_get_ToolkitName (DBusMessageIter * iter, void *user_data)
608 return return_v_string (iter, "at-spi-registry");
611 impl_get_ToolkitVersion (DBusMessageIter * iter, void *user_data)
613 return return_v_string (iter, "2.0");
617 impl_GetChildAtIndex (DBusConnection * bus,
618 DBusMessage * message, void *user_data)
620 SpiRegistry *reg = SPI_REGISTRY (user_data);
622 DBusMessageIter iter;
627 dbus_error_init (&error);
628 if (!dbus_message_get_args
629 (message, &error, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID))
631 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
634 reply = dbus_message_new_method_return (message);
635 dbus_message_iter_init_append (reply, &iter);
637 if (i < 0 || i >= reg->apps->len)
638 append_reference (&iter, SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_NULL);
641 ref = g_ptr_array_index (reg->apps, i);
642 append_reference (&iter, ref->name, ref->path);
649 impl_GetChildren (DBusConnection * bus,
650 DBusMessage * message, void *user_data)
652 DBusMessage *reply = NULL;
653 DBusMessageIter iter, iter_array;
654 SpiRegistry *reg = SPI_REGISTRY (user_data);
657 reply = dbus_message_new_method_return (message);
659 dbus_message_iter_init_append (reply, &iter);
660 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(so)", &iter_array);
661 for (i=0; i < reg->apps->len; i++)
663 SpiReference *current = g_ptr_array_index (reg->apps, i);
664 append_reference (&iter_array, current->name, current->path);
666 dbus_message_iter_close_container(&iter, &iter_array);
671 impl_GetIndexInParent (DBusConnection * bus,
672 DBusMessage * message, void *user_data)
675 dbus_uint32_t rv = 0;
677 reply = dbus_message_new_method_return (message);
678 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv, DBUS_TYPE_INVALID);
683 impl_GetRelationSet (DBusConnection * bus,
684 DBusMessage * message, void *user_data)
687 DBusMessageIter iter, iter_array;
689 reply = dbus_message_new_method_return (message);
690 dbus_message_iter_init_append (reply, &iter);
691 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ua(so))", &iter_array);
692 dbus_message_iter_close_container (&iter, &iter_array);
698 impl_GetRole (DBusConnection * bus, DBusMessage * message, void * user_data)
701 dbus_uint32_t rv = 14; /* TODO: Get DESKTOP_FRAME from somewhere */
703 reply = dbus_message_new_method_return (message);
704 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv, DBUS_TYPE_INVALID);
709 impl_GetRoleName (DBusConnection * bus,
710 DBusMessage * message, void *user_data)
713 const char *role_name = "desktop frame";
715 reply = dbus_message_new_method_return (message);
716 dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
722 impl_GetLocalizedRoleName (DBusConnection * bus,
723 DBusMessage * message, void *user_data)
725 /* TODO - Localize this */
727 const char *role_name = "desktop frame";
729 reply = dbus_message_new_method_return (message);
730 dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
736 impl_GetState (DBusConnection * bus, DBusMessage * message, void *user_data)
738 DBusMessage *reply = NULL;
739 DBusMessageIter iter, iter_array;
741 dbus_uint32_t states[2] = {0, 0};
744 reply = dbus_message_new_method_return (message);
745 dbus_message_iter_init_append (reply, &iter);
747 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "u", &iter_array);
748 for (count = 0; count < 2; count++)
750 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_UINT32,
753 dbus_message_iter_close_container (&iter, &iter_array);
758 impl_GetAttributes (DBusConnection * bus,
759 DBusMessage * message, void *user_data)
761 DBusMessage *reply = NULL;
762 DBusMessageIter iter, array;
764 reply = dbus_message_new_method_return (message);
765 dbus_message_iter_init_append (reply, &iter);
766 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{ss}", &array);
767 dbus_message_iter_close_container (&iter, &array);
773 impl_GetApplication (DBusConnection * bus,
774 DBusMessage * message, void *user_data)
776 DBusMessage *reply = NULL;
777 DBusMessageIter iter;
779 reply = dbus_message_new_method_return (message);
780 dbus_message_iter_init_append (reply, &iter);
781 append_reference (&iter,
782 dbus_bus_get_unique_name (bus),
789 impl_GetInterfaces (DBusConnection * bus,
790 DBusMessage * message, void *user_data)
793 DBusMessageIter iter, iter_array;
795 const char *acc = SPI_DBUS_INTERFACE_ACCESSIBLE;
796 const char *com = SPI_DBUS_INTERFACE_COMPONENT;
798 reply = dbus_message_new_method_return (message);
800 dbus_message_iter_init_append (reply, &iter);
801 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s",
803 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &acc);
804 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &com);
805 dbus_message_iter_close_container (&iter, &iter_array);
811 impl_GetItems (DBusConnection * bus, DBusMessage * message, void *user_data)
814 DBusMessageIter iter, iter_array;
816 reply = dbus_message_new_method_return (message);
818 dbus_message_iter_init_append (reply, &iter);
819 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
820 "((so)(so)(so)a(so)assusau)", &iter_array);
821 dbus_message_iter_close_container (&iter, &iter_array);
825 /* I would rather these two be signals, but I'm not sure that dbus-python
826 * supports emitting signals except for a service, so implementing as both
827 * a method call and signal for now.
830 impl_register_event (DBusConnection *bus, DBusMessage *message, void *user_data)
832 SpiRegistry *registry = SPI_REGISTRY (user_data);
833 const char *orig_name;
839 const char *sender = dbus_message_get_sender (message);
841 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &orig_name,
845 name = ensure_proper_format (orig_name);
847 evdata = (event_data *) g_malloc (sizeof (*evdata));
850 data = g_strsplit (name, ":", 3);
860 evdata->bus_name = g_strdup (sender);
862 new_list = g_list_append (registry->events, evdata);
864 registry->events = new_list;
866 if (needs_mouse_poll (evdata->data))
868 spi_device_event_controller_start_poll_mouse (registry);
871 signal = dbus_message_new_signal (SPI_DBUS_PATH_REGISTRY,
872 SPI_DBUS_INTERFACE_REGISTRY,
873 "EventListenerRegistered");
874 dbus_message_append_args (signal, DBUS_TYPE_STRING, &sender,
875 DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
876 dbus_connection_send (bus, signal, NULL);
877 dbus_message_unref (signal);
880 return dbus_message_new_method_return (message);
884 impl_deregister_event (DBusConnection *bus, DBusMessage *message, void *user_data)
886 SpiRegistry *registry = SPI_REGISTRY (user_data);
887 const char *orig_name;
889 const char *sender = dbus_message_get_sender (message);
891 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &orig_name,
894 name = ensure_proper_format (orig_name);
896 remove_events (registry, sender, name);
899 return dbus_message_new_method_return (message);
903 impl_get_registered_events (DBusConnection *bus, DBusMessage *message, void *user_data)
905 SpiRegistry *registry = SPI_REGISTRY (user_data);
908 DBusMessageIter iter, iter_struct, iter_array;
911 reply = dbus_message_new_method_return (message);
915 dbus_message_iter_init_append (reply, &iter);
916 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ss)", &iter_array);
917 for (list = registry->events; list; list = list->next)
921 str = g_strconcat (evdata->data [0],
922 ":", (evdata->data [1]? evdata->data [1]: ""),
923 ":", (evdata->data [2]? evdata->data [2]: ""), NULL);
924 dbus_message_iter_open_container (&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
925 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &evdata->bus_name);
926 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &str);
927 dbus_message_iter_close_container (&iter_array, &iter_struct);
930 dbus_message_iter_close_container (&iter, &iter_array);
934 /*---------------------------------------------------------------------------*/
937 emit_Available (DBusConnection * bus)
940 DBusMessageIter iter;
942 sig = dbus_message_new_signal(SPI_DBUS_PATH_ROOT, SPI_DBUS_INTERFACE_SOCKET, "Available");
944 dbus_message_iter_init_append(sig, &iter);
945 append_reference (&iter, SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_ROOT);
947 dbus_connection_send(bus, sig, NULL);
948 dbus_message_unref(sig);
951 /*---------------------------------------------------------------------------*/
953 static const char *introspection_header =
954 "<?xml version=\"1.0\"?>\n";
956 static const char *introspection_node_element =
957 "<node name=\"%s\">\n";
959 static const char *introspection_footer =
963 impl_Introspect_root (DBusConnection * bus,
964 DBusMessage * message, void *user_data)
970 const gchar *pathstr = SPI_DBUS_PATH_ROOT;
974 output = g_string_new(introspection_header);
976 g_string_append_printf(output, introspection_node_element, pathstr);
978 g_string_append (output, spi_org_a11y_atspi_Accessible);
979 g_string_append (output, spi_org_a11y_atspi_Component);
981 g_string_append(output, introspection_footer);
982 final = g_string_free(output, FALSE);
984 reply = dbus_message_new_method_return (message);
985 dbus_message_append_args(reply, DBUS_TYPE_STRING, &final, DBUS_TYPE_INVALID);
992 impl_Introspect_registry (DBusConnection * bus,
993 DBusMessage * message, void *user_data)
999 const gchar *pathstr = SPI_DBUS_PATH_REGISTRY;
1003 output = g_string_new(introspection_header);
1005 g_string_append_printf(output, introspection_node_element, pathstr);
1007 g_string_append (output, spi_org_a11y_atspi_Registry);
1009 g_string_append(output, introspection_footer);
1010 final = g_string_free(output, FALSE);
1012 reply = dbus_message_new_method_return (message);
1013 dbus_message_append_args(reply, DBUS_TYPE_STRING, &final, DBUS_TYPE_INVALID);
1019 /*---------------------------------------------------------------------------*/
1022 * Emits an AT-SPI event.
1023 * AT-SPI events names are split into three parts:
1025 * This is mapped onto D-Bus events as:
1026 * D-Bus Interface:Signal Name:Detail argument
1028 * Marshals a basic type into the 'any_data' attribute of
1032 emit_event (DBusConnection *bus,
1036 dbus_int32_t detail1,
1037 dbus_int32_t detail2,
1042 DBusMessageIter iter, iter_variant;
1044 sig = dbus_message_new_signal(SPI_DBUS_PATH_ROOT, klass, major);
1046 dbus_message_iter_init_append(sig, &iter);
1048 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor);
1049 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
1050 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
1052 dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(so)",
1054 append_reference (&iter_variant, name, path);
1055 dbus_message_iter_close_container (&iter, &iter_variant);
1057 append_reference (&iter,
1058 dbus_bus_get_unique_name (bus),
1059 SPI_DBUS_PATH_ROOT);
1061 dbus_connection_send(bus, sig, NULL);
1062 dbus_message_unref(sig);
1065 /*---------------------------------------------------------------------------*/
1068 * Children changed signal converter and forwarder.
1070 * Klass (Interface) org.a11y.atspi.Event.Object
1071 * Major is the signal name.
1072 * Minor is 'add' or 'remove'
1073 * detail1 is the index.
1075 * any_data is the child reference.
1079 children_added_listener (DBusConnection * bus,
1084 emit_event (bus, SPI_DBUS_INTERFACE_EVENT_OBJECT, "ChildrenChanged", "add", index, 0,
1089 children_removed_listener (DBusConnection * bus,
1094 emit_event (bus, SPI_DBUS_INTERFACE_EVENT_OBJECT, "ChildrenChanged", "remove", index, 0,
1098 /*---------------------------------------------------------------------------*/
1100 static DBusHandlerResult
1101 handle_method_root (DBusConnection *bus, DBusMessage *message, void *user_data)
1103 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1105 const gchar *iface = dbus_message_get_interface (message);
1106 const gchar *member = dbus_message_get_member (message);
1107 const gint type = dbus_message_get_type (message);
1109 DBusMessage *reply = NULL;
1111 /* Check for basic reasons not to handle */
1112 if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
1115 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1117 if (!strcmp (iface, "org.freedesktop.DBus.Properties"))
1119 if (!strcmp (member, "Get"))
1121 const gchar *prop_iface;
1122 const gchar *prop_member;
1125 dbus_error_init (&error);
1126 if (dbus_message_get_args (message,
1134 DBusMessageIter iter;
1136 reply = dbus_message_new_method_return (message);
1137 dbus_message_iter_init_append (reply, &iter);
1140 if (!strcmp (prop_iface, SPI_DBUS_INTERFACE_ACCESSIBLE))
1142 if (!strcmp (prop_member, "Name"))
1143 impl_get_Name (&iter, user_data);
1144 else if (!strcmp (prop_member, "Description"))
1145 impl_get_Description (&iter, user_data);
1146 else if (!strcmp (prop_member, "Parent"))
1147 impl_get_Parent (&iter, user_data);
1148 else if (!strcmp (prop_member, "ChildCount"))
1149 impl_get_ChildCount (&iter, user_data);
1152 dbus_message_unref (reply);
1153 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
1156 else if (!strcmp (prop_iface, SPI_DBUS_INTERFACE_APPLICATION))
1158 if (!strcmp (prop_member, "ToolkitName"))
1159 impl_get_ToolkitName (&iter, user_data);
1160 else if (!strcmp (prop_member, "ToolkitVersion"))
1161 impl_get_ToolkitVersion (&iter, user_data);
1164 dbus_message_unref (reply);
1165 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
1170 dbus_message_unref (reply);
1171 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
1176 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, error.message);
1178 result = DBUS_HANDLER_RESULT_HANDLED;
1180 else if (!strcmp (member, "GetAll"))
1182 result = DBUS_HANDLER_RESULT_HANDLED;
1186 if (!strcmp (iface, SPI_DBUS_INTERFACE_ACCESSIBLE))
1188 result = DBUS_HANDLER_RESULT_HANDLED;
1189 if (!strcmp (member, "GetChildAtIndex"))
1190 reply = impl_GetChildAtIndex (bus, message, user_data);
1191 else if (!strcmp (member, "GetChildren"))
1192 reply = impl_GetChildren (bus, message, user_data);
1193 else if (!strcmp (member, "GetIndexInParent"))
1194 reply = impl_GetIndexInParent (bus, message, user_data);
1195 else if (!strcmp (member, "GetRelationSet"))
1196 reply = impl_GetRelationSet (bus, message, user_data);
1197 else if (!strcmp (member, "GetRole"))
1198 reply = impl_GetRole (bus, message, user_data);
1199 else if (!strcmp (member, "GetRoleName"))
1200 reply = impl_GetRoleName (bus, message, user_data);
1201 else if (!strcmp (member, "GetLocalizedRoleName"))
1202 reply = impl_GetLocalizedRoleName (bus, message, user_data);
1203 else if (!strcmp (member, "GetState"))
1204 reply = impl_GetState (bus, message, user_data);
1205 else if (!strcmp (member, "GetAttributes"))
1206 reply = impl_GetAttributes (bus, message, user_data);
1207 else if (!strcmp (member, "GetApplication"))
1208 reply = impl_GetApplication (bus, message, user_data);
1209 else if (!strcmp (member, "GetInterfaces"))
1210 reply = impl_GetInterfaces (bus, message, user_data);
1212 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1215 if (!strcmp (iface, SPI_DBUS_INTERFACE_COMPONENT))
1217 result = DBUS_HANDLER_RESULT_HANDLED;
1218 if (!strcmp (member, "Contains"))
1219 reply = impl_Contains (bus, message, user_data);
1220 else if (!strcmp (member, "GetAccessibleAtPoint"))
1221 reply = impl_GetAccessibleAtPoint (bus, message, user_data);
1222 else if (!strcmp (member, "GetExtents"))
1223 reply = impl_GetExtents (bus, message, user_data);
1224 else if (!strcmp (member, "GetPosition"))
1225 reply = impl_GetPosition (bus, message, user_data);
1226 else if (!strcmp (member, "GetSize"))
1227 reply = impl_GetSize (bus, message, user_data);
1228 else if (!strcmp (member, "GetLayer"))
1229 reply = impl_GetLayer (bus, message, user_data);
1230 else if (!strcmp (member, "GetMDIZOrder"))
1231 reply = impl_GetMDIZOrder (bus, message, user_data);
1232 else if (!strcmp (member, "GrabFocus"))
1233 reply = impl_GrabFocus (bus, message, user_data);
1234 else if (!strcmp (member, "GetAlpha"))
1235 reply = impl_GetAlpha (bus, message, user_data);
1237 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1240 if (!strcmp (iface, SPI_DBUS_INTERFACE_SOCKET))
1242 result = DBUS_HANDLER_RESULT_HANDLED;
1243 if (!strcmp (member, "Embed"))
1244 reply = impl_Embed (bus, message, user_data);
1245 else if (!strcmp (member, "Unembed"))
1246 reply = impl_Unembed (bus, message, user_data);
1248 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1251 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
1253 result = DBUS_HANDLER_RESULT_HANDLED;
1254 if (!strcmp (member, "Introspect"))
1255 reply = impl_Introspect_root (bus, message, user_data);
1257 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1260 if (result == DBUS_HANDLER_RESULT_HANDLED)
1264 reply = dbus_message_new_method_return (message);
1267 dbus_connection_send (bus, reply, NULL);
1268 dbus_message_unref (reply);
1273 g_print ("Registry | Unhandled message : %s|%s\n", iface, member);
1280 static DBusHandlerResult
1281 handle_method_cache (DBusConnection *bus, DBusMessage *message, void *user_data)
1283 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1285 const gchar *iface = dbus_message_get_interface (message);
1286 const gchar *member = dbus_message_get_member (message);
1287 const gint type = dbus_message_get_type (message);
1289 DBusMessage *reply = NULL;
1291 /* Check for basic reasons not to handle */
1292 if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
1295 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1297 if (!strcmp (iface, SPI_DBUS_INTERFACE_CACHE))
1299 result = DBUS_HANDLER_RESULT_HANDLED;
1300 if (!strcmp (member, "GetItems"))
1301 reply = impl_GetItems (bus, message, user_data);
1303 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1306 if (result == DBUS_HANDLER_RESULT_HANDLED)
1310 reply = dbus_message_new_method_return (message);
1313 dbus_connection_send (bus, reply, NULL);
1314 dbus_message_unref (reply);
1318 static DBusHandlerResult
1319 handle_method_registry (DBusConnection *bus, DBusMessage *message, void *user_data)
1321 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1323 const gchar *iface = dbus_message_get_interface (message);
1324 const gchar *member = dbus_message_get_member (message);
1325 const gint type = dbus_message_get_type (message);
1327 DBusMessage *reply = NULL;
1329 /* Check for basic reasons not to handle */
1330 if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
1333 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1335 if (!strcmp (iface, SPI_DBUS_INTERFACE_REGISTRY))
1337 result = DBUS_HANDLER_RESULT_HANDLED;
1338 if (!strcmp(member, "RegisterEvent"))
1339 reply = impl_register_event (bus, message, user_data);
1340 else if (!strcmp(member, "DeregisterEvent"))
1341 reply = impl_deregister_event (bus, message, user_data);
1342 else if (!strcmp(member, "GetRegisteredEvents"))
1343 reply = impl_get_registered_events (bus, message, user_data);
1345 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1348 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
1350 result = DBUS_HANDLER_RESULT_HANDLED;
1351 if (!strcmp (member, "Introspect"))
1352 reply = impl_Introspect_registry (bus, message, user_data);
1354 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1357 if (result == DBUS_HANDLER_RESULT_HANDLED)
1361 reply = dbus_message_new_method_return (message);
1364 dbus_connection_send (bus, reply, NULL);
1365 dbus_message_unref (reply);
1370 g_print ("Registry | Unhandled message : %s|%s\n", iface, member);
1377 /*---------------------------------------------------------------------------*/
1379 static DBusObjectPathVTable root_vtable =
1382 &handle_method_root,
1383 NULL, NULL, NULL, NULL
1386 static DBusObjectPathVTable registry_vtable =
1389 &handle_method_registry,
1390 NULL, NULL, NULL, NULL
1393 static DBusObjectPathVTable cache_vtable =
1396 &handle_method_cache,
1397 NULL, NULL, NULL, NULL
1400 static gchar *app_sig_match_name_owner =
1401 "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged'";
1404 spi_registry_new (DBusConnection *bus)
1406 SpiRegistry *reg = g_object_new (SPI_REGISTRY_TYPE, NULL);
1410 dbus_bus_add_match (bus, app_sig_match_name_owner, NULL);
1411 dbus_connection_add_filter (bus, signal_filter, reg, NULL);
1413 dbus_connection_register_object_path (bus, SPI_DBUS_PATH_ROOT, &root_vtable, reg);
1415 dbus_connection_register_object_path (bus, SPI_DBUS_PATH_CACHE, &cache_vtable, reg);
1417 dbus_connection_register_object_path (bus, SPI_DBUS_PATH_REGISTRY, ®istry_vtable, reg);
1419 emit_Available (bus);
1426 /*END------------------------------------------------------------------------*/