2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * Basic SPI initialization and event loop function prototypes
33 #include <cspi/spi-private.h>
38 static DBusConnection *bus = NULL;
39 static GHashTable *apps = NULL;
40 static GHashTable *live_refs = NULL;
41 static GQueue *exception_handlers = NULL;
42 static DBusError exception;
45 cspi_object_release (gpointer value)
50 cspi_exception_throw (DBusError *error, const char *desc_prefix)
52 SPIExceptionHandler *handler = NULL;
54 if (exception_handlers) handler = g_queue_peek_head (exception_handlers);
56 ex.type = SPI_EXCEPTION_SOURCE_UNSPECIFIED;
58 ex.code = SPI_EXCEPTION_UNSPECIFIED;
60 // TODO: Fill in description
63 return (*handler) (&ex, FALSE);
65 return FALSE; /* means exception was not handled */
68 const char *spi_path_dec = SPI_DBUS_PATH_DEC;
69 const char *spi_path_registry = SPI_DBUS_PATH_REGISTRY;
70 const char *spi_bus_registry = SPI_DBUS_NAME_REGISTRY;
71 const char *spi_path_desktop = SPI_DBUS_PATH_DESKTOP;
72 const char *spi_interface_accessible = SPI_DBUS_INTERFACE_ACCESSIBLE;
73 const char *spi_interface_action = SPI_DBUS_INTERFACE_ACTION;
74 const char *spi_interface_application = SPI_DBUS_INTERFACE_APPLICATION;
75 const char *spi_interface_component = SPI_DBUS_INTERFACE_COMPONENT;
76 const char *spi_interface_dec = SPI_DBUS_INTERFACE_DEC;
77 const char *spi_interface_desktop = SPI_DBUS_INTERFACE_DESKTOP;
78 const char *spi_interface_device_event_listener = SPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER;
79 const char *spi_interface_document = SPI_DBUS_INTERFACE_DOCUMENT;
80 const char *spi_interface_editable_text = SPI_DBUS_INTERFACE_EDITABLE_TEXT;
81 const char *spi_interface_hyperlink = SPI_DBUS_INTERFACE_HYPERLINK;
82 const char *spi_interface_hypertext = SPI_DBUS_INTERFACE_HYPERTEXT;
83 const char *spi_interface_image = SPI_DBUS_INTERFACE_IMAGE;
84 const char *spi_interface_registry = SPI_DBUS_INTERFACE_REGISTRY;
85 const char *spi_interface_selection = SPI_DBUS_INTERFACE_SELECTION;
86 const char *spi_interface_table = SPI_DBUS_INTERFACE_TABLE;
87 const char *spi_interface_text = SPI_DBUS_INTERFACE_TEXT;
88 const char *spi_interface_tree = SPI_DBUS_INTERFACE_TREE;
89 const char *spi_interface_value = SPI_DBUS_INTERFACE_VALUE;
91 static const char *interfaces[] =
93 SPI_DBUS_INTERFACE_ACCESSIBLE,
94 SPI_DBUS_INTERFACE_ACTION,
95 SPI_DBUS_INTERFACE_APPLICATION,
96 SPI_DBUS_INTERFACE_COMPONENT,
97 SPI_DBUS_INTERFACE_DOCUMENT,
98 SPI_DBUS_INTERFACE_EDITABLE_TEXT,
99 SPI_DBUS_INTERFACE_HYPERLINK,
100 SPI_DBUS_INTERFACE_HYPERTEXT,
101 SPI_DBUS_INTERFACE_IMAGE,
102 "org.freedesktop.atspi.LoginHelper",
103 SPI_DBUS_INTERFACE_SELECTION,
104 "org.freedesktop.atspi.Selector",
105 SPI_DBUS_INTERFACE_TABLE,
106 SPI_DBUS_INTERFACE_TEXT,
107 SPI_DBUS_INTERFACE_VALUE,
111 static gint get_iface_num (const char *iface)
113 // TODO: Use a binary search or hash to improve performance
116 for (i = 0; interfaces[i]; i++)
118 if (!strcmp(iface, interfaces[i])) return i;
124 cspi_accessible_is_a (Accessible *accessible,
125 const char *interface_name)
129 if (accessible == NULL)
134 n = get_iface_num (interface_name);
135 if (n == -1) return FALSE;
136 return (SPIBoolean)((accessible->interfaces & (1 << n))? TRUE: FALSE);
140 cspi_get_live_refs (void)
144 live_refs = g_hash_table_new (g_direct_hash, g_direct_equal);
156 cspi_exception (void)
158 if (dbus_error_is_set (&exception))
160 dbus_error_free (&exception);
167 cspi_check_ev (const char *error_string)
169 if (dbus_error_is_set (&exception))
171 cspi_exception_throw (&exception, error_string);
178 cspi_object_add (Accessible *accessible)
180 if (accessible) cspi_object_ref (accessible);
185 cspi_object_ref (Accessible *accessible)
187 g_return_if_fail (accessible != NULL);
189 accessible->ref_count++;
190 g_hash_table_insert (live_refs, accessible, accessible);
193 #define APP_IS_REGISTRY(app) (!strcmp (app->bus_name, spi_bus_registry))
196 cspi_object_unref_internal (Accessible *accessible, gboolean defunct)
200 if (accessible == NULL)
205 if (--accessible->ref_count == 0 || (accessible->ref_count == 1 && !defunct) && g_hash_table_lookup (live_refs, accessible))
208 memset (&e, 0, sizeof(e));
209 e.type = "object:state-change:defunct";
210 e.source = accessible;
212 cspi_dispatch_event (&e);
213 g_hash_table_remove (live_refs, accessible);
215 if (accessible->ref_count == 0)
217 if (APP_IS_REGISTRY (accessible->app))
219 g_free (accessible->v.path);
226 cspi_object_unref (Accessible *accessible)
228 cspi_object_unref_internal (accessible, FALSE);
236 cspi_streams_close_all ();
242 g_hash_table_destroy (refs);
246 static gboolean SPI_inited = FALSE;
248 static GHashTable *app_hash = NULL;
251 ref_accessible (CSpiApplication *app, const char *path)
256 if (sscanf (path, "/org/freedesktop/atspi/accessible/%d", &id) != 1)
260 Accessible *a = g_hash_table_lookup (app->hash, &id);
266 id_val = g_new (guint, 1);
267 if (!id_val) return NULL;
269 a = g_new0 (Accessible, 1);
275 g_hash_table_insert (app->hash, id_val, a);
278 a->ref_count = 2; /* one for the caller, one for the hash */
282 static CSpiApplication *
283 cspi_get_application (const char *bus_name)
285 CSpiApplication *app = NULL;
290 app_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_hash_table_unref);
291 if (!app_hash) return;
293 app = g_hash_table_lookup (app_hash, bus_name);
295 bus_name_dup = g_strdup (bus_name);
296 if (!bus_name_dup) return NULL;
297 // TODO: change below to something that will send state-change:defunct notification if necessary */
298 app = g_new (CSpiApplication, 1);
299 if (!app) return NULL;
300 app->bus_name = bus_name_dup;
301 if (APP_IS_REGISTRY (app))
303 app->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, cspi_object_unref);
307 app->hash = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, cspi_object_unref);
309 g_hash_table_insert (app_hash, bus_name_dup, app);
324 /* Update the cache with added/modified objects and free the array */
326 handle_additions (CSpiApplication*app, GArray *additions)
335 for (i = 0; i < additions->len; i++)
337 CACHE_ADDITION *ca = &g_array_index (additions, CACHE_ADDITION, i);
338 Accessible *a = ref_accessible (app, ca->path);
339 /* Note: children don't hold refs for their parents or vice versa */
340 a->parent = ref_accessible (app, ca->parent);
341 if (a->parent) cspi_object_unref (a->parent);
344 g_list_free (a->children);
347 for (j = 0; j < ca->children->len; j++)
349 const char *child_path = g_array_index (ca->children, const char *, j);
350 Accessible *child = ref_accessible (app, child_path);
351 new_list = g_list_append (a->children, child);
352 if (new_list) a->children = new_list;
353 cspi_object_unref (child);
356 for (j = 0; j < ca->interfaces->len; j++)
358 const char *iface = g_array_index (ca->interfaces, const char *, j);
359 if (!strcmp (iface, "org.freedesktop.DBus.Introspectable")) continue;
360 gint n = get_iface_num (iface);
363 g_warning ("Unknown interface %s", iface);
365 else a->interfaces |= (1 << n);
368 if (a->name) g_free (a->name);
371 if (a->description) g_free (a->description);
372 a->description = ca->description;
373 g_array_free (ca->interfaces, TRUE);
374 g_array_free (ca->children, TRUE);
375 /* This is a bit of a hack since ref_accessible sets ref_count to 2
376 * for a new object, one of the refs being for the cache */
377 cspi_object_unref (a);
379 g_array_free (additions, TRUE);
383 handle_removals (CSpiApplication *app, GArray *removals)
387 if (!removals) return;
388 for (j = 0; j < removals->len; j++)
390 const char *path = g_array_index (removals, const char *, j);
391 Accessible *a = ref_accessible (app, path);
392 if (a->parent && g_list_find (a->parent->children, a))
394 a->parent->children = g_list_remove (a->parent->children, a);
395 /* Note: children don't hold refs for their parents or vice versa */
397 g_hash_table_remove (app->hash, &a->v.id);
398 cspi_object_unref_internal (a, TRUE); /* unref our own ref */
400 g_array_free (removals, TRUE);
404 add_app_to_desktop (Accessible *a, const char *bus_name)
409 dbus_error_init (&error);
410 if (dbind_connection_method_call (bus, bus_name, "/org/freedesktop/atspi/tree", spi_interface_tree, "getRoot", &error, "=>o", &root_path))
412 Accessible *obj = cspi_ref_accessible (bus_name, root_path);
415 GList *new_list = g_list_append (a->children, obj);
418 a->children = new_list;
426 g_warning ("Error calling getRoot for %s: %s", bus_name, error.message);
432 send_children_changed (Accessible *parent, Accessible *child, gboolean add)
436 memset (&e, 0, sizeof(e));
437 e.type = (add? "object:children-changed:add": "object:children-changed:remove");
439 e.detail1 = g_list_index (parent->children, child);
440 cspi_dispatch_event (&e);
444 unref_object_and_children (Accessible *obj)
448 for (l = obj->children; l; l = l->next)
450 unref_object_and_children (l->data);
452 cspi_object_unref_internal (obj, TRUE);
456 remove_app_from_desktop (Accessible *a, const char *bus_name)
461 for (l = a->children; l; l = l->next)
464 if (!strcmp (bus_name, child->app->bus_name)) break;
468 g_warning ("Removing unregistered app %s; doing nothing\n", bus_name);
471 send_children_changed (a, child, FALSE);
472 a->children = g_list_remove (a->children, child);
473 unref_object_and_children (child);
478 ref_accessible_desktop (CSpiApplication *app, const char *path)
486 Accessible *a = g_hash_table_lookup (app->hash, path);
492 path_dup = g_strdup (path);
493 if (!path_dup) return NULL;
494 a = g_new0 (Accessible, 1);
500 g_hash_table_insert (app->hash, path_dup, a);
502 a->v.path = path_dup;
503 a->ref_count = 2; /* one for the caller, one for the hash */
504 cspi_dbus_get_property (a, SPI_DBUS_INTERFACE_ACCESSIBLE, "name", NULL, "s", &a->name);
505 dbus_error_init (&error);
506 if (!dbind_connection_method_call (bus, spi_bus_registry, a->v.path, spi_interface_desktop, "getChildren", &error, "=>as", &apps))
508 g_error ("Couldn't get desktop children: %s", error.message);
510 for (i = 0; i < apps->len; i++)
512 const char *app_name = g_array_index (apps, char *, i);
513 if (app_name[0] == '\0')
515 g_warning ("Got empty app name");
518 CSpiApplication *app = cspi_get_application (app_name);
520 dbus_error_init (&error);
521 dbind_connection_method_call (bus, app_name, "/org/freedesktop/atspi/tree", spi_interface_tree, "getTree", &error, "=>a(ooaoassus)", &additions);
524 g_warning ("getTree (%s): %s", app_name, error.message);
526 handle_additions (app, additions);
527 add_app_to_desktop (a, app_name);
529 g_array_free (apps, TRUE);
534 cspi_ref_accessible (const char *app, const char *path)
536 CSpiApplication *a = cspi_get_application (app);
538 if ( APP_IS_REGISTRY(a))
540 return ref_accessible_desktop (a, path);
542 return ref_accessible (a, path);
546 cspi_ref_related_accessible (Accessible *obj, const char *path)
548 return ref_accessible (obj->app, path);
557 static const char *cacheSignalType = "a(ooaoassus)ao";
559 static DBusHandlerResult
560 cspi_dbus_handle_update_tree (DBusConnection *bus, DBusMessage *message, void *user_data)
562 DBusMessageIter iter;
565 const char *sender = dbus_message_get_sender (message);
566 CSpiApplication *app = cspi_get_application (sender);
567 const char *type = cacheSignalType;
571 g_warning ("UpdateTree from unknown app. Should we add it?", sender);
574 dbus_message_iter_init (message, &iter);
575 // TODO: Check signature
576 dbind_any_demarshal (&iter, &type, &p); /* additions */
577 dbind_any_demarshal (&iter, &type, &p); /* removals */
578 handle_additions (app, cd.additions);
579 handle_removals (app, cd.removals);
582 static DBusHandlerResult
583 cspi_dbus_handle_add_application (DBusConnection *bus, DBusMessage *message, void *user_data)
590 dbus_error_init (&error);
591 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &v, DBUS_TYPE_STRING, &bus_name, DBUS_TYPE_INVALID))
593 g_warning ("Error processing %s: %s\n", dbus_message_get_member(message), error.message);
594 dbus_error_free (&error);
595 return DBUS_HANDLER_RESULT_HANDLED;
597 a = cspi_ref_accessible (spi_bus_registry, dbus_message_get_path(message));
598 if (add_app_to_desktop (a, bus_name))
600 send_children_changed (a, g_list_last (a->children)->data, TRUE);
602 cspi_object_unref (a);
603 return DBUS_HANDLER_RESULT_HANDLED;
606 static DBusHandlerResult
607 cspi_dbus_handle_remove_application (DBusConnection *bus, DBusMessage *message, void *user_data)
614 dbus_error_init (&error);
615 if (!dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &v, DBUS_TYPE_STRING, &bus_name, DBUS_TYPE_INVALID))
617 g_warning ("Error processing %s: %s\n", dbus_message_get_member(message), error.message);
618 dbus_error_free (&error);
619 return DBUS_HANDLER_RESULT_HANDLED;
621 a = cspi_ref_accessible (spi_bus_registry, dbus_message_get_path(message));
622 remove_app_from_desktop (a, bus_name);
623 cspi_object_unref (a);
624 return DBUS_HANDLER_RESULT_HANDLED;
628 static DBusHandlerResult
629 cspi_dbus_filter (DBusConnection *bus, DBusMessage *message, void *data)
631 int type = dbus_message_get_type (message);
632 const char *interface = dbus_message_get_interface (message);
633 const char *member = dbus_message_get_member (message);
637 if (type == DBUS_MESSAGE_TYPE_SIGNAL &&
638 !strcmp (interface, SPI_DBUS_INTERFACE_ACCESSIBLE))
640 return cspi_dbus_handle_event (bus, message, data);
642 if (dbus_message_is_method_call (message, spi_interface_device_event_listener, "notifyEvent"))
644 return cspi_dbus_handle_deviceEvent (bus, message, data);
646 if (dbus_message_is_signal (message, spi_interface_tree, "updateTree"))
648 return cspi_dbus_handle_update_tree (bus, message, data);
650 if (dbus_message_is_signal (message, spi_interface_registry, "applicationAdd"))
652 return cspi_dbus_handle_add_application (bus, message, data);
654 if (dbus_message_is_signal (message, spi_interface_registry, "applicationRemove"))
656 return cspi_dbus_handle_remove_application (bus, message, data);
658 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
664 * Connects to the accessibility registry and initializes the SPI.
666 * Returns: 0 on success, otherwise an integer error code.
683 cspi_get_live_refs();
684 g_atexit (cspi_cleanup);
686 dbus_error_init (&error);
687 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
690 g_error ("Couldn't get session bus");
693 dbus_bus_register (bus, &error);
694 dbus_connection_setup_with_g_main(bus, g_main_context_default());
695 dbus_connection_add_filter (bus, cspi_dbus_filter, NULL, NULL);
696 match = g_strdup_printf ("type='signal',interface='%s',member='updateTree'", spi_interface_tree);
697 dbus_error_init (&error);
698 dbus_bus_add_match (bus, match, &error);
700 match = g_strdup_printf ("type='signal',sender='%s'", spi_bus_registry);
701 dbus_bus_add_match (bus, match, &error);
706 static GMainLoop *mainloop;
711 * Starts/enters the main event loop for the SPI services.
713 * (NOTE: This method does not return control, it is exited via a call to
714 * SPI_event_quit () from within an event handler).
718 SPI_event_main (void)
721 mainloop = g_main_loop_new (NULL, FALSE);
722 g_main_loop_run (mainloop);
728 * Quits the last main event loop for the SPI services,
732 SPI_event_quit (void)
734 g_main_loop_quit (mainloop);
740 * Checks to see if an SPI event is waiting in the event queue.
741 * Used by clients that don't wish to use SPI_event_main().
743 * Not Yet Implemented.
745 * Returns: #TRUE if an event is waiting, otherwise #FALSE.
749 SPI_eventIsReady (void)
756 * @waitForEvent: a #SPIBoolean indicating whether to block or not.
758 * Gets the next event in the SPI event queue; blocks if no event
759 * is pending and @waitForEvent is #TRUE.
760 * Used by clients that don't wish to use SPI_event_main().
762 * Not Yet Implemented.
764 * Returns: the next #AccessibleEvent in the SPI event queue.
767 SPI_nextEvent (SPIBoolean waitForEvent)
774 report_leaked_ref (gpointer key, gpointer val, gpointer user_data)
777 Accessible *a = (Accessible *) val;
779 name = Accessible_getName (a);
780 if (cspi_exception ())
785 role = Accessible_getRoleName (a);
786 if (cspi_exception ())
791 fprintf (stderr, "leaked %d references to object %s, role %s %p\n",
792 a->ref_count, name ? name : "<?>", role ? role : "<?>", a);
794 SPI_freeString (name);
801 * Disconnects from the Accessibility Registry and releases
802 * any floating resources. Call only once at exit.
804 * Returns: 0 if there were no leaks, otherwise non zero.
820 leaked = g_hash_table_size (live_refs);
822 fprintf (stderr, "Leaked %d SPI handles\n", leaked);
826 g_hash_table_foreach (live_refs, report_leaked_ref, NULL);
843 * @s: a character string returned from another at-spi call.
845 * Free a character string returned from an at-spi call. Clients of
846 * at-spi should use this function instead of free () or g_free().
847 * A NULL string @s will be silently ignored.
848 * This API should not be used to free strings
849 * from other libraries or allocated by the client.
852 SPI_freeString (char *s)
862 * @r: a pointer to an SPIRect returned from another at-spi call.
864 * Free a SPIRect structure returned from an at-spi call. Clients of
865 * at-spi should use this function instead of free () or g_free().
866 * A NULL rect @r will be silently ignored.
867 * This API should not be used to free data
868 * from other libraries or allocated by the client.
873 SPI_freeRect (SPIRect *r)
877 /* err, okay, in this case the client _could_
878 have called g_free, but we don't want to guarantee it */
885 * @s: a UTF-8 string to be duplicated
889 * Returns: a duplicate of the string passed as a parameter, which should
890 * be freed via SPI_freeString after use.
893 SPI_dupString (char *s)
904 * SPI_exceptionHandlerPush:
905 * @handler: an #SPIExceptionHandler to install as the first code to deal with exceptions.
907 * Install a client-side handler for #SPIException instances, which can see and handle any
908 * exceptions before chaining them to the next exception handler in the stack.
912 * Returns %TRUE if the result succeeded, %FALSE if @hander could not be registered.
914 SPIBoolean SPI_exceptionHandlerPush (SPIExceptionHandler *handler)
916 if (!exception_handlers)
917 exception_handlers = g_queue_new ();
918 g_queue_push_head (exception_handlers, handler);
923 * SPI_exceptionHandlerPop:
925 * Remove/pop an #SPIExceptionHandler off the error handler stack and return the new handler.
929 * Returns the #SPIExceptionHandler which is now at the top of the error handler stack after the call.
931 SPIExceptionHandler* SPI_exceptionHandlerPop (void)
933 return (SPIExceptionHandler *) g_queue_pop_head (exception_handlers);
937 * SPIException_getSourceType:
938 * @err: the exception being queried
940 * Get the #SPIExceptionType of an exception which has been thrown.
944 * Returns: the #SPIExceptionType corresponding to exception @err.
946 SPIExceptionType SPIException_getSourceType (SPIException *err)
951 return SPI_EXCEPTION_SOURCE_UNSPECIFIED;
955 * SPIException_getExceptionCode:
956 * @err: the #SPIException being queried.
958 * Get the #SPIExceptionCode telling what type of exception condition has occurred.
962 * Returns: the #SPIExceptionCode corresponding to exception @err.
964 SPIExceptionCode SPIException_getExceptionCode (SPIException *err)
970 * SPIAccessibleException_getSource:
971 * @err: the #SPIException being queried.
973 * Get the identity of the object which threw an exception.
977 * Returns: a pointer to the #Accessible object which threw the exception.
979 Accessible* SPIAccessibleException_getSource (SPIException *err)
981 if (err->type == SPI_EXCEPTION_SOURCE_ACCESSIBLE)
982 cspi_object_ref (err->source);
988 * SPIException_getDescription:
989 * @err: the #SPIException being queried.
991 * Get a text description of the exception that has been thrown.
992 * Unfortunately these descriptions tend to be terse and limited in
993 * the detail which they can provide.
995 * Returns: a brief character string describing the exception.
997 char* SPIException_getDescription (SPIException *err)
999 /* TODO: friendlier error messages? */
1001 return err->error->message;
1006 get_path (Accessible *obj)
1008 if (APP_IS_REGISTRY (obj->app))
1010 return g_strdup_printf (SPI_DBUS_PATH_DESKTOP);
1012 return g_strdup_printf ("/org/freedesktop/atspi/accessible/%d", obj->v.id);
1016 cspi_dbus_call (Accessible *obj, const char *interface, const char *method, DBusError *error, const char *type, ...)
1019 char *path = get_path (obj);
1023 if (!error) error = &err;
1024 dbus_error_init (error);
1025 va_start (args, type);
1026 retval = dbind_connection_method_call_va (SPI_bus(), obj->app->bus_name, path, interface, method, error, type, args);
1029 if (dbus_error_is_set (error))
1031 if (!dbus_error_is_set (&exception))
1033 // TODO: Should we call cspi_exception_throw?
1034 dbus_move_error (error, &exception);
1036 else if (error == &err) dbus_error_free (error);
1042 cspi_dbus_get_property (Accessible *obj, const char *interface, const char *name, DBusError *error, const char *type, void *data)
1044 DBusMessage *message, *reply;
1045 char *path = get_path (obj);
1046 DBusMessageIter iter, iter_variant;
1048 dbus_bool_t retval = FALSE;
1050 message = dbus_message_new_method_call (obj->app->bus_name, path, "org.freedesktop.DBus.Properties", "Get");
1053 // TODO: throw exception
1056 dbus_message_append_args (message, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
1057 if (!error) error = &err;
1058 dbus_error_init (error);
1059 reply = dbus_connection_send_with_reply_and_block (SPI_bus(), message, 1000, error);
1060 dbus_message_unref (message);
1063 // TODO: throw exception
1066 dbus_message_iter_init (reply, &iter);
1067 dbus_message_iter_recurse (&iter, &iter_variant);
1068 if (dbus_message_iter_get_arg_type (&iter_variant) != type[0])
1070 g_warning ("cspi_dbus_get_property: Wrong type: expected %s, got %c\n", type, dbus_message_iter_get_arg_type (&iter_variant));
1073 dbus_message_iter_get_basic (&iter_variant, data);
1074 dbus_message_unref (reply);
1075 if (type[0] == 's') *(char **)data = g_strdup (*(char **)data);