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.
27 #include <dbus/dbus-glib-lowlevel.h>
31 #include "introspection.h"
33 typedef struct event_data event_data;
41 children_added_listener (DBusConnection * bus,
47 children_removed_listener (DBusConnection * bus,
52 /*---------------------------------------------------------------------------*/
54 typedef struct _SpiReference
61 spi_reference_new (const gchar *name, const gchar *path)
65 ref = g_new0 (SpiReference, 1);
66 ref->name = g_strdup (name);
67 ref->path = g_strdup (path);
73 spi_reference_free (SpiReference *ref)
80 /*---------------------------------------------------------------------------*/
82 G_DEFINE_TYPE(SpiRegistry, spi_registry, G_TYPE_OBJECT)
85 spi_registry_class_init (SpiRegistryClass *klass)
87 GObjectClass * object_class = (GObjectClass *) klass;
89 spi_registry_parent_class = g_type_class_ref (G_TYPE_OBJECT);
93 spi_registry_init (SpiRegistry *registry)
95 registry->apps = g_ptr_array_new_with_free_func ((GDestroyNotify) spi_reference_free);
98 /*---------------------------------------------------------------------------*/
101 return_v_string (DBusMessageIter * iter, const gchar * str)
103 DBusMessageIter variant;
105 if (!dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s",
108 dbus_message_iter_append_basic (&variant, DBUS_TYPE_STRING, &str);
109 dbus_message_iter_close_container (iter, &variant);
114 append_reference (DBusMessageIter * iter, const char * name, const char * path)
116 DBusMessageIter iter_struct;
118 if (!dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL,
121 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
122 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
123 dbus_message_iter_close_container (iter, &iter_struct);
127 /*---------------------------------------------------------------------------*/
130 compare_reference (SpiReference *one, SpiReference *two)
132 if (g_strcmp0 (one->name, two->name) == 0 &&
133 g_strcmp0 (one->path, two->path) == 0)
140 find_index_of_reference (GPtrArray *arr, const gchar *name, const gchar * path, guint *index)
143 gboolean found = FALSE;
146 ref = spi_reference_new (name, path);
148 for (i = 0; i < arr->len && found == FALSE; i++)
150 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 /*TODO spi_remove_device_listeners (registry->de_controller, old);*/
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)
232 gboolean mouse_found = FALSE;
234 remove_data = g_strsplit (event, ":", 3);
240 for (list = registry->events; list;)
242 event_data *evdata = list->data;
243 if (!g_strcmp0 (evdata->bus_name, bus_name) &&
244 event_is_subtype (evdata->data, remove_data))
247 g_strfreev (evdata->data);
248 g_free (evdata->bus_name);
250 registry->events = g_list_remove (registry->events, evdata);
254 if (needs_mouse_poll (evdata->data))
261 spi_device_event_controller_stop_poll_mouse ();
263 g_strfreev (remove_data);
267 handle_disconnection (DBusConnection *bus, DBusMessage *message, void *user_data)
269 char *name, *old, *new;
270 SpiRegistry *reg = SPI_REGISTRY (user_data);
272 if (dbus_message_get_args (message, NULL,
273 DBUS_TYPE_STRING, &name,
274 DBUS_TYPE_STRING, &old,
275 DBUS_TYPE_STRING, &new,
278 if (*old != '\0' && *new == '\0')
280 /* Remove all children with the application name the same as the disconnected application. */
282 for (i = 0; i < reg->apps->len; i++)
284 SpiReference *ref = g_ptr_array_index (reg->apps, i);
285 while (!g_strcmp0 (old, ref->name))
287 children_removed_listener (bus, i, old, ref->path);
288 g_ptr_array_remove_index (reg->apps, i);
292 remove_events (reg, old, "");
298 * Converts names of th eform "active-descendant-changed" to
299 *"ActiveDesendantChanged"
302 ensure_proper_format (const char *name)
304 gchar *ret = (gchar *) g_malloc (strlen (name) * 2 + 2);
306 gboolean need_upper = TRUE;
314 *p++ = toupper (*name);
317 else if (*name == '-')
319 else if (*name == ':')
331 static DBusHandlerResult
332 signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
334 SpiRegistry *registry = SPI_REGISTRY (user_data);
335 guint res = DBUS_HANDLER_RESULT_HANDLED;
336 const gint type = dbus_message_get_type (message);
337 const char *iface = dbus_message_get_interface (message);
338 const char *member = dbus_message_get_member (message);
340 if (type != DBUS_MESSAGE_TYPE_SIGNAL)
343 if (!g_strcmp0(iface, DBUS_INTERFACE_DBUS) &&
344 !g_strcmp0(member, "NameOwnerChanged"))
345 handle_disconnection (bus, message, user_data);
347 res = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
352 /* org.at_spi.Socket interface */
353 /*---------------------------------------------------------------------------*/
356 impl_Embed (DBusConnection *bus, DBusMessage *message, void *user_data)
358 SpiRegistry *reg = SPI_REGISTRY (user_data);
359 DBusMessageIter iter, iter_struct;
360 gchar *app_name, *obj_path;
362 DBusMessage *reply = NULL;
363 DBusMessageIter reply_iter;
365 dbus_message_iter_init (message, &iter);
366 dbus_message_iter_recurse (&iter, &iter_struct);
367 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_STRING))
369 dbus_message_iter_get_basic (&iter_struct, &app_name);
370 if (!dbus_message_iter_next (&iter_struct))
372 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_OBJECT_PATH))
374 dbus_message_iter_get_basic (&iter_struct, &obj_path);
376 add_application(reg, bus, app_name, obj_path);
378 set_id (reg, bus, app_name, obj_path);
380 reply = dbus_message_new_method_return (message);
381 dbus_message_iter_init_append (reply, &reply_iter);
382 append_reference (&reply_iter,
383 dbus_bus_get_unique_name (bus),
388 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
392 impl_Unembed (DBusConnection *bus, DBusMessage *message, void *user_data)
394 SpiRegistry *reg = SPI_REGISTRY (user_data);
395 DBusMessageIter iter, iter_struct;
396 gchar *app_name, *obj_path;
399 dbus_message_iter_init (message, &iter);
400 dbus_message_iter_recurse (&iter, &iter_struct);
401 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_STRING))
403 dbus_message_iter_get_basic (&iter_struct, &app_name);
404 if (!dbus_message_iter_next (&iter_struct))
406 if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_OBJECT_PATH))
408 dbus_message_iter_get_basic (&iter_struct, &obj_path);
410 if (find_index_of_reference (reg->apps, app_name, obj_path, &index))
411 remove_application(reg, bus, index);
415 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
418 /* org.at_spi.Component interface */
419 /*---------------------------------------------------------------------------*/
422 impl_Contains (DBusConnection * bus, DBusMessage * message, void *user_data)
424 dbus_bool_t retval = FALSE;
427 reply = dbus_message_new_method_return (message);
428 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
434 impl_GetAccessibleAtPoint (DBusConnection * bus, DBusMessage * message,
437 DBusMessage *reply = NULL;
438 DBusMessageIter iter;
440 reply = dbus_message_new_method_return (message);
441 dbus_message_iter_init_append (reply, &iter);
442 append_reference (&iter,
443 dbus_bus_get_unique_name (bus),
450 impl_GetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
452 dbus_uint32_t coord_type;
453 dbus_int32_t x = 0, y = 0, width = 1024, height = 768;
455 DBusMessageIter iter, iter_struct;
457 reply = dbus_message_new_method_return (message);
458 dbus_message_iter_init_append (reply, &iter);
459 dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL,
461 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &x);
462 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &y);
463 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &width);
464 dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &height);
465 dbus_message_iter_close_container (&iter, &iter_struct);
470 impl_GetPosition (DBusConnection * bus, DBusMessage * message,
474 dbus_int32_t x = 0, y = 0;
476 reply = dbus_message_new_method_return (message);
477 dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
478 &y, DBUS_TYPE_INVALID);
483 impl_GetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
485 /* TODO - Get the screen size */
487 dbus_int32_t width = 1024, height = 768;
489 reply = dbus_message_new_method_return (message);
490 dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
491 DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
495 #define LAYER_WIDGET 3;
498 impl_GetLayer (DBusConnection * bus, DBusMessage * message, void *user_data)
501 dbus_uint32_t rv = LAYER_WIDGET;
503 reply = dbus_message_new_method_return (message);
504 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
510 impl_GetMDIZOrder (DBusConnection * bus, DBusMessage * message,
516 reply = dbus_message_new_method_return (message);
517 dbus_message_append_args (reply, DBUS_TYPE_INT16, &rv,
523 impl_GrabFocus (DBusConnection * bus, DBusMessage * message, void *user_data)
526 dbus_bool_t retval = FALSE;
528 reply = dbus_message_new_method_return (message);
529 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
535 impl_GetAlpha (DBusConnection * bus, DBusMessage * message, void *user_data)
540 reply = dbus_message_new_method_return (message);
541 dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
546 /* org.at_spi.Accessible interface */
547 /*---------------------------------------------------------------------------*/
550 impl_get_Name (DBusMessageIter * iter, void *user_data)
552 const gchar *name = "main";
553 return return_v_string (iter, name);
557 impl_get_Description (DBusMessageIter * iter, void *user_data)
559 const gchar *description = "";
560 return return_v_string (iter, description);
564 impl_get_Parent (DBusMessageIter * iter, void *user_data)
566 const gchar *name = "";
567 DBusMessageIter iter_variant;
569 dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(so)",
571 append_reference (&iter_variant,
574 dbus_message_iter_close_container (iter, &iter_variant);
579 impl_get_ChildCount (DBusMessageIter * iter, void *user_data)
581 SpiRegistry *reg = SPI_REGISTRY (user_data);
582 dbus_int32_t rv = reg->apps->len;
584 return dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &rv);
588 impl_GetChildAtIndex (DBusConnection * bus,
589 DBusMessage * message, void *user_data)
591 SpiRegistry *reg = SPI_REGISTRY (user_data);
593 DBusMessageIter iter;
598 dbus_error_init (&error);
599 if (!dbus_message_get_args
600 (message, &error, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID))
602 return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
605 reply = dbus_message_new_method_return (message);
606 dbus_message_iter_init_append (reply, &iter);
608 if (i < 0 || i >= reg->apps->len)
609 append_reference (&iter, SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_NULL);
612 ref = g_ptr_array_index (reg->apps, i);
613 append_reference (&iter, ref->name, ref->path);
620 impl_GetChildren (DBusConnection * bus,
621 DBusMessage * message, void *user_data)
623 DBusMessage *reply = NULL;
624 DBusMessageIter iter, iter_array;
625 SpiRegistry *reg = SPI_REGISTRY (user_data);
628 reply = dbus_message_new_method_return (message);
630 dbus_message_iter_init_append (reply, &iter);
631 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(so)", &iter_array);
632 for (i=0; i < reg->apps->len; i++)
634 SpiReference *current = g_ptr_array_index (reg->apps, i);
635 append_reference (&iter_array, current->name, current->path);
637 dbus_message_iter_close_container(&iter, &iter_array);
642 impl_GetIndexInParent (DBusConnection * bus,
643 DBusMessage * message, void *user_data)
646 dbus_uint32_t rv = 0;
648 reply = dbus_message_new_method_return (message);
649 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv, DBUS_TYPE_INVALID);
654 impl_GetRelationSet (DBusConnection * bus,
655 DBusMessage * message, void *user_data)
658 DBusMessageIter iter, iter_array;
660 reply = dbus_message_new_method_return (message);
661 dbus_message_iter_init_append (reply, &iter);
662 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ua(so))", &iter_array);
663 dbus_message_iter_close_container (&iter, &iter_array);
669 impl_GetRole (DBusConnection * bus, DBusMessage * message, void * user_data)
672 dbus_uint32_t rv = 0;
674 reply = dbus_message_new_method_return (message);
675 dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv, DBUS_TYPE_INVALID);
680 impl_GetRoleName (DBusConnection * bus,
681 DBusMessage * message, void *user_data)
684 const char *role_name = "unknown";
686 reply = dbus_message_new_method_return (message);
687 dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
693 impl_GetLocalizedRoleName (DBusConnection * bus,
694 DBusMessage * message, void *user_data)
696 /* TODO - Localize this */
698 const char *role_name = "unknown";
700 reply = dbus_message_new_method_return (message);
701 dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
707 impl_GetState (DBusConnection * bus, DBusMessage * message, void *user_data)
709 DBusMessage *reply = NULL;
710 DBusMessageIter iter, iter_array;
712 dbus_uint32_t states[2] = {0, 0};
715 reply = dbus_message_new_method_return (message);
716 dbus_message_iter_init_append (reply, &iter);
718 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "u", &iter_array);
719 for (count = 0; count < 2; count++)
721 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_UINT32,
724 dbus_message_iter_close_container (&iter, &iter_array);
729 impl_GetAttributes (DBusConnection * bus,
730 DBusMessage * message, void *user_data)
732 DBusMessage *reply = NULL;
733 DBusMessageIter iter, array;
735 reply = dbus_message_new_method_return (message);
736 dbus_message_iter_init_append (reply, &iter);
737 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{ss}", &array);
738 dbus_message_iter_close_container (&iter, &array);
744 impl_GetApplication (DBusConnection * bus,
745 DBusMessage * message, void *user_data)
747 DBusMessage *reply = NULL;
748 DBusMessageIter iter;
750 reply = dbus_message_new_method_return (message);
751 dbus_message_iter_init_append (reply, &iter);
752 append_reference (&iter,
753 dbus_bus_get_unique_name (bus),
760 impl_GetInterfaces (DBusConnection * bus,
761 DBusMessage * message, void *user_data)
764 DBusMessageIter iter, iter_array;
766 const char *acc = SPI_DBUS_INTERFACE_ACCESSIBLE;
767 const char *com = SPI_DBUS_INTERFACE_COMPONENT;
769 reply = dbus_message_new_method_return (message);
771 dbus_message_iter_init_append (reply, &iter);
772 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s",
774 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &acc);
775 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &com);
776 dbus_message_iter_close_container (&iter, &iter_array);
781 /* I would rather these two be signals, but I'm not sure that dbus-python
782 * supports emitting signals except for a service, so implementing as both
783 * a method call and signal for now.
786 impl_register_event_listener (DBusConnection *bus, DBusMessage *message, void *user_data)
788 SpiRegistry *registry = SPI_REGISTRY (user_data);
789 const char *orig_name;
795 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &orig_name,
799 name = ensure_proper_format (orig_name);
801 evdata = (event_data *) g_malloc (sizeof (*evdata));
804 data = g_strsplit (name, ":", 3);
810 evdata->bus_name = g_strdup (dbus_message_get_sender (message));
812 new_list = g_list_append (registry->events, evdata);
814 registry->events = new_list;
816 if (needs_mouse_poll (evdata->data))
818 spi_device_event_controller_start_poll_mouse (registry);
822 /* TODO: Send a signal */
823 return dbus_message_new_method_return (message);
827 impl_deregister_event_listener (DBusConnection *bus, DBusMessage *message, void *user_data)
829 SpiRegistry *registry = SPI_REGISTRY (user_data);
830 const char *orig_name;
833 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &orig_name,
836 name = ensure_proper_format (orig_name);
838 remove_events (registry, dbus_message_get_sender (message), name);
840 /* TODO: Send a signal */
842 return dbus_message_new_method_return (message);
845 /*---------------------------------------------------------------------------*/
848 emit_Available (DBusConnection * bus)
851 DBusMessageIter iter;
853 sig = dbus_message_new_signal(SPI_DBUS_PATH_ROOT, SPI_DBUS_INTERFACE_SOCKET, "Available");
855 dbus_message_iter_init_append(sig, &iter);
856 append_reference (&iter, SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_ROOT);
858 dbus_connection_send(bus, sig, NULL);
859 dbus_message_unref(sig);
862 /*---------------------------------------------------------------------------*/
864 static const char *introspection_header =
865 "<?xml version=\"1.0\"?>\n";
867 static const char *introspection_node_element =
868 "<node name=\"%s\">\n";
870 static const char *introspection_footer =
874 impl_Introspect (DBusConnection * bus,
875 DBusMessage * message, void *user_data)
881 const gchar *pathstr = SPI_DBUS_PATH_ROOT;
885 output = g_string_new(introspection_header);
887 g_string_append_printf(output, introspection_node_element, pathstr);
889 g_string_append (output, spi_org_a11y_atspi_Accessible);
890 g_string_append (output, spi_org_a11y_atspi_Component);
892 g_string_append(output, introspection_footer);
893 final = g_string_free(output, FALSE);
895 reply = dbus_message_new_method_return (message);
896 dbus_message_append_args(reply, DBUS_TYPE_STRING, &final, DBUS_TYPE_INVALID);
902 /*---------------------------------------------------------------------------*/
905 * Emits an AT-SPI event.
906 * AT-SPI events names are split into three parts:
908 * This is mapped onto D-Bus events as:
909 * D-Bus Interface:Signal Name:Detail argument
911 * Marshals a basic type into the 'any_data' attribute of
915 emit_event (DBusConnection *bus,
919 dbus_int32_t detail1,
920 dbus_int32_t detail2,
925 DBusMessageIter iter, iter_variant;
927 sig = dbus_message_new_signal(SPI_DBUS_PATH_ROOT, klass, major);
929 dbus_message_iter_init_append(sig, &iter);
931 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor);
932 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
933 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
935 dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(so)",
937 append_reference (&iter_variant, name, path);
938 dbus_message_iter_close_container (&iter, &iter_variant);
940 append_reference (&iter,
941 dbus_bus_get_unique_name (bus),
944 dbus_connection_send(bus, sig, NULL);
945 dbus_message_unref(sig);
948 /*---------------------------------------------------------------------------*/
951 * Children changed signal converter and forwarder.
953 * Klass (Interface) org.a11y.atspi.Event.Object
954 * Major is the signal name.
955 * Minor is 'add' or 'remove'
956 * detail1 is the index.
958 * any_data is the child reference.
962 children_added_listener (DBusConnection * bus,
967 emit_event (bus, SPI_DBUS_INTERFACE_EVENT_OBJECT, "ChildrenChanged", "add", index, 0,
972 children_removed_listener (DBusConnection * bus,
977 emit_event (bus, SPI_DBUS_INTERFACE_EVENT_OBJECT, "ChildrenChanged", "remove", index, 0,
981 /*---------------------------------------------------------------------------*/
983 static DBusHandlerResult
984 handle_method (DBusConnection *bus, DBusMessage *message, void *user_data)
986 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
988 const gchar *iface = dbus_message_get_interface (message);
989 const gchar *member = dbus_message_get_member (message);
990 const gint type = dbus_message_get_type (message);
992 DBusMessage *reply = NULL;
994 /* Check for basic reasons not to handle */
995 if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
998 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1000 if (!strcmp (iface, "org.freedesktop.DBus.Properties"))
1002 if (!strcmp (member, "Get"))
1004 const gchar *prop_iface;
1005 const gchar *prop_member;
1008 dbus_error_init (&error);
1009 if (dbus_message_get_args (message,
1017 DBusMessageIter iter;
1019 reply = dbus_message_new_method_return (message);
1020 dbus_message_iter_init_append (reply, &iter);
1023 if (!strcmp (prop_iface, SPI_DBUS_INTERFACE_ACCESSIBLE))
1025 if (!strcmp (prop_member, "Name"))
1026 impl_get_Name (&iter, user_data);
1027 else if (!strcmp (prop_member, "Description"))
1028 impl_get_Description (&iter, user_data);
1029 else if (!strcmp (prop_member, "Parent"))
1030 impl_get_Parent (&iter, user_data);
1031 else if (!strcmp (prop_member, "ChildCount"))
1032 impl_get_ChildCount (&iter, user_data);
1035 dbus_message_unref (reply);
1036 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
1042 reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, error.message);
1044 result = DBUS_HANDLER_RESULT_HANDLED;
1046 else if (!strcmp (member, "GetAll"))
1048 result = DBUS_HANDLER_RESULT_HANDLED;
1052 if (!strcmp (iface, SPI_DBUS_INTERFACE_ACCESSIBLE))
1054 result = DBUS_HANDLER_RESULT_HANDLED;
1055 if (!strcmp (member, "GetChildAtIndex"))
1056 reply = impl_GetChildAtIndex (bus, message, user_data);
1057 else if (!strcmp (member, "GetChildren"))
1058 reply = impl_GetChildren (bus, message, user_data);
1059 else if (!strcmp (member, "GetIndexInParent"))
1060 reply = impl_GetIndexInParent (bus, message, user_data);
1061 else if (!strcmp (member, "GetRelationSet"))
1062 reply = impl_GetRelationSet (bus, message, user_data);
1063 else if (!strcmp (member, "GetRole"))
1064 reply = impl_GetRole (bus, message, user_data);
1065 else if (!strcmp (member, "GetRoleName"))
1066 reply = impl_GetRoleName (bus, message, user_data);
1067 else if (!strcmp (member, "GetLocalizedRoleName"))
1068 reply = impl_GetLocalizedRoleName (bus, message, user_data);
1069 else if (!strcmp (member, "GetState"))
1070 reply = impl_GetState (bus, message, user_data);
1071 else if (!strcmp (member, "GetAttributes"))
1072 reply = impl_GetAttributes (bus, message, user_data);
1073 else if (!strcmp (member, "GetApplication"))
1074 reply = impl_GetApplication (bus, message, user_data);
1075 else if (!strcmp (member, "GetInterfaces"))
1076 reply = impl_GetInterfaces (bus, message, user_data);
1078 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1081 if (!strcmp (iface, SPI_DBUS_INTERFACE_COMPONENT))
1083 result = DBUS_HANDLER_RESULT_HANDLED;
1084 if (!strcmp (member, "Contains"))
1085 reply = impl_Contains (bus, message, user_data);
1086 else if (!strcmp (member, "GetAccessibleAtPoint"))
1087 reply = impl_GetAccessibleAtPoint (bus, message, user_data);
1088 else if (!strcmp (member, "GetExtents"))
1089 reply = impl_GetExtents (bus, message, user_data);
1090 else if (!strcmp (member, "GetPosition"))
1091 reply = impl_GetPosition (bus, message, user_data);
1092 else if (!strcmp (member, "GetSize"))
1093 reply = impl_GetSize (bus, message, user_data);
1094 else if (!strcmp (member, "GetLayer"))
1095 reply = impl_GetLayer (bus, message, user_data);
1096 else if (!strcmp (member, "GetMDIZOrder"))
1097 reply = impl_GetMDIZOrder (bus, message, user_data);
1098 else if (!strcmp (member, "GrabFocus"))
1099 reply = impl_GrabFocus (bus, message, user_data);
1100 else if (!strcmp (member, "GetAlpha"))
1101 reply = impl_GetAlpha (bus, message, user_data);
1103 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1106 if (!strcmp (iface, SPI_DBUS_INTERFACE_SOCKET))
1108 result = DBUS_HANDLER_RESULT_HANDLED;
1109 if (!strcmp (member, "Embed"))
1110 reply = impl_Embed (bus, message, user_data);
1111 else if (!strcmp (member, "Unembed"))
1112 reply = impl_Unembed (bus, message, user_data);
1114 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1117 if (!strcmp (iface, SPI_DBUS_INTERFACE_APPLICATION))
1119 result = DBUS_HANDLER_RESULT_HANDLED;
1120 if (!strcmp(member, "RegisterEventListener"))
1121 reply = impl_register_event_listener (bus, message, user_data);
1122 else if (!strcmp(member, "DeregisterEventListener"))
1123 reply = impl_deregister_event_listener (bus, message, user_data);
1125 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1127 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
1129 result = DBUS_HANDLER_RESULT_HANDLED;
1130 if (!strcmp (member, "Introspect"))
1131 reply = impl_Introspect (bus, message, user_data);
1133 result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1136 if (result == DBUS_HANDLER_RESULT_HANDLED)
1140 reply = dbus_message_new_method_return (message);
1143 dbus_connection_send (bus, reply, NULL);
1144 dbus_message_unref (reply);
1149 g_print ("Registry | Unhandled message : %s|%s\n", iface, member);
1156 /*---------------------------------------------------------------------------*/
1158 static DBusObjectPathVTable registry_vtable =
1162 NULL, NULL, NULL, NULL
1165 static gchar *app_sig_match_name_owner =
1166 "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged'";
1169 spi_registry_new (DBusConnection *bus)
1171 SpiRegistry *reg = g_object_new (SPI_REGISTRY_TYPE, NULL);
1175 dbus_bus_add_match (bus, app_sig_match_name_owner, NULL);
1176 dbus_connection_add_filter (bus, signal_filter, reg, NULL);
1178 dbus_connection_register_object_path (bus, SPI_DBUS_PATH_ROOT, ®istry_vtable, reg);
1180 emit_Available (bus);
1187 /*END------------------------------------------------------------------------*/