1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-gproxy.c Proxy for remote objects
4 * Copyright (C) 2003, 2004, 2005 Red Hat, Inc.
5 * Copyright (C) 2005 Nokia
7 * Licensed under the Academic Free License version 2.1
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program 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
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <dbus/dbus-glib.h>
25 #include <dbus/dbus-glib-lowlevel.h>
26 #include <dbus/dbus-signature.h>
27 #include "dbus-gutils.h"
28 #include "dbus-gsignature.h"
29 #include "dbus-gvalue.h"
30 #include "dbus-gvalue-utils.h"
31 #include "dbus-gobject.h"
33 #include <glib/gi18n.h>
34 #include <gobject/gvaluecollector.h>
36 #define DBUS_G_PROXY_CALL_TO_ID(x) (GPOINTER_TO_UINT(x))
37 #define DBUS_G_PROXY_ID_TO_CALL(x) (GUINT_TO_POINTER(x))
38 #define DBUS_G_PROXY_GET_PRIVATE(o) \
39 (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUS_TYPE_G_PROXY, DBusGProxyPrivate))
43 * @addtogroup DBusGLibInternals
49 * DBusGProxyManager typedef
52 typedef struct _DBusGProxyManager DBusGProxyManager;
54 typedef struct _DBusGProxyPrivate DBusGProxyPrivate;
57 * Internals of DBusGProxy
59 struct _DBusGProxyPrivate
61 DBusGProxyManager *manager; /**< Proxy manager */
62 char *name; /**< Name messages go to or NULL */
63 char *path; /**< Path messages go to or NULL */
64 char *interface; /**< Interface messages go to or NULL */
66 DBusGProxyCall *name_call; /**< Pending call id to retrieve name owner */
67 guint for_owner : 1; /**< Whether or not this proxy is for a name owner */
68 guint associated : 1; /**< Whether or not this proxy is associated (for name proxies) */
70 /* FIXME: make threadsafe? */
71 guint call_id_counter; /**< Integer counter for pending calls */
73 GData *signal_signatures; /**< D-BUS signatures for each signal */
75 GHashTable *pending_calls; /**< Calls made on this proxy which have not yet returned */
77 int default_timeout; /**< Default timeout to use, see dbus_g_proxy_set_default_timeout */
80 static void dbus_g_proxy_init (DBusGProxy *proxy);
81 static void dbus_g_proxy_class_init (DBusGProxyClass *klass);
82 static GObject *dbus_g_proxy_constructor (GType type,
83 guint n_construct_properties,
84 GObjectConstructParam *construct_properties);
85 static void dbus_g_proxy_set_property (GObject *object,
89 static void dbus_g_proxy_get_property (GObject *object,
94 static void dbus_g_proxy_finalize (GObject *object);
95 static void dbus_g_proxy_dispose (GObject *object);
96 static void dbus_g_proxy_destroy (DBusGProxy *proxy);
97 static void dbus_g_proxy_emit_remote_signal (DBusGProxy *proxy,
98 DBusMessage *message);
100 static DBusGProxyCall *manager_begin_bus_call (DBusGProxyManager *manager,
102 DBusGProxyCallNotify notify,
104 GDestroyNotify destroy,
105 GType first_arg_type,
107 static guint dbus_g_proxy_begin_call_internal (DBusGProxy *proxy,
109 DBusGProxyCallNotify notify,
111 GDestroyNotify destroy,
114 static gboolean dbus_g_proxy_end_call_internal (DBusGProxy *proxy,
117 GType first_arg_type,
121 * A list of proxies with a given name+path+interface, used to
122 * route incoming signals.
126 GSList *proxies; /**< The list of proxies */
128 char name[4]; /**< name (empty string for none), nul byte,
130 * interface, nul byte
136 * DBusGProxyManager's primary task is to route signals to the proxies
137 * those signals are emitted on. In order to do this it also has to
138 * track the owners of the names proxies are bound to.
140 struct _DBusGProxyManager
142 GStaticMutex lock; /**< Thread lock */
143 int refcount; /**< Reference count */
144 DBusConnection *connection; /**< Connection we're associated with. */
146 DBusGProxy *bus_proxy; /**< Special internal proxy used to talk to the bus */
148 GHashTable *proxy_lists; /**< Hash used to route incoming signals
149 * and iterate over proxies
151 GHashTable *owner_names; /**< Hash to keep track of mapping from
152 * base name -> [name,name,...] for proxies which
155 GSList *unassociated_proxies; /**< List of name proxies for which
156 * there was no result for
161 static DBusGProxyManager *dbus_g_proxy_manager_ref (DBusGProxyManager *manager);
162 static DBusHandlerResult dbus_g_proxy_manager_filter (DBusConnection *connection,
163 DBusMessage *message,
167 /** Lock the DBusGProxyManager */
168 #define LOCK_MANAGER(mgr) (g_static_mutex_lock (&(mgr)->lock))
169 /** Unlock the DBusGProxyManager */
170 #define UNLOCK_MANAGER(mgr) (g_static_mutex_unlock (&(mgr)->lock))
172 static int g_proxy_manager_slot = -1;
174 /* Lock controlling get/set manager as data on each connection */
175 static GStaticMutex connection_g_proxy_lock = G_STATIC_MUTEX_INIT;
177 static DBusGProxyManager*
178 dbus_g_proxy_manager_get (DBusConnection *connection)
180 DBusGProxyManager *manager;
182 dbus_connection_allocate_data_slot (&g_proxy_manager_slot);
183 if (g_proxy_manager_slot < 0)
184 g_error ("out of memory");
186 g_static_mutex_lock (&connection_g_proxy_lock);
188 manager = dbus_connection_get_data (connection, g_proxy_manager_slot);
191 dbus_connection_free_data_slot (&g_proxy_manager_slot);
192 dbus_g_proxy_manager_ref (manager);
193 g_static_mutex_unlock (&connection_g_proxy_lock);
197 manager = g_new0 (DBusGProxyManager, 1);
199 manager->refcount = 1;
200 manager->connection = connection;
202 g_static_mutex_init (&manager->lock);
204 /* Proxy managers keep the connection alive, which means that
205 * DBusGProxy indirectly does. To free a connection you have to free
206 * all the proxies referring to it.
208 dbus_connection_ref (manager->connection);
210 dbus_connection_set_data (connection, g_proxy_manager_slot,
213 dbus_connection_add_filter (connection, dbus_g_proxy_manager_filter,
216 g_static_mutex_unlock (&connection_g_proxy_lock);
221 static DBusGProxyManager *
222 dbus_g_proxy_manager_ref (DBusGProxyManager *manager)
224 g_assert (manager != NULL);
225 g_assert (manager->refcount > 0);
227 LOCK_MANAGER (manager);
229 manager->refcount += 1;
231 UNLOCK_MANAGER (manager);
237 dbus_g_proxy_manager_unref (DBusGProxyManager *manager)
239 g_assert (manager != NULL);
240 g_assert (manager->refcount > 0);
242 LOCK_MANAGER (manager);
243 manager->refcount -= 1;
244 if (manager->refcount == 0)
246 UNLOCK_MANAGER (manager);
248 if (manager->bus_proxy)
249 g_object_unref (manager->bus_proxy);
251 if (manager->proxy_lists)
253 /* can't have any proxies left since they hold
254 * a reference to the proxy manager.
256 g_assert (g_hash_table_size (manager->proxy_lists) == 0);
258 g_hash_table_destroy (manager->proxy_lists);
259 manager->proxy_lists = NULL;
263 if (manager->owner_names)
265 /* Since we destroyed all proxies, none can be tracking
268 g_assert (g_hash_table_size (manager->owner_names) == 0);
270 g_hash_table_destroy (manager->owner_names);
271 manager->owner_names = NULL;
274 g_assert (manager->unassociated_proxies == NULL);
276 g_static_mutex_free (&manager->lock);
278 g_static_mutex_lock (&connection_g_proxy_lock);
280 dbus_connection_remove_filter (manager->connection, dbus_g_proxy_manager_filter,
283 dbus_connection_set_data (manager->connection,
284 g_proxy_manager_slot,
287 g_static_mutex_unlock (&connection_g_proxy_lock);
289 dbus_connection_unref (manager->connection);
292 dbus_connection_free_data_slot (&g_proxy_manager_slot);
296 UNLOCK_MANAGER (manager);
301 tristring_hash (gconstpointer key)
308 for (p += 1; *p != '\0'; p++)
309 h = (h << 5) - h + *p;
312 /* skip nul and do the next substring */
313 for (p += 1; *p != '\0'; p++)
314 h = (h << 5) - h + *p;
316 /* skip nul again and another substring */
317 for (p += 1; *p != '\0'; p++)
318 h = (h << 5) - h + *p;
324 strequal_len (const char *a,
337 if (memcmp (a, b, a_len) != 0)
346 tristring_equal (gconstpointer a,
353 if (!strequal_len (ap, bp, &len))
359 if (!strequal_len (ap, bp, &len))
365 if (strcmp (ap, bp) != 0)
372 tristring_alloc_from_strings (size_t padding_before,
375 const char *interface)
377 size_t name_len, iface_len, path_len, len;
381 name_len = strlen (name);
385 path_len = strlen (path);
387 iface_len = strlen (interface);
389 tri = g_malloc (padding_before + name_len + path_len + iface_len + 3);
391 len = padding_before;
394 memcpy (&tri[len], name, name_len);
400 g_assert (len == (padding_before + name_len + 1));
402 memcpy (&tri[len], path, path_len);
407 g_assert (len == (padding_before + name_len + path_len + 2));
409 memcpy (&tri[len], interface, iface_len);
414 g_assert (len == (padding_before + name_len + path_len + iface_len + 3));
420 tristring_from_proxy (DBusGProxy *proxy)
422 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
424 return tristring_alloc_from_strings (0,
431 tristring_from_message (DBusMessage *message)
434 const char *interface;
436 path = dbus_message_get_path (message);
437 interface = dbus_message_get_interface (message);
440 g_assert (interface);
442 return tristring_alloc_from_strings (0,
443 dbus_message_get_sender (message),
447 static DBusGProxyList*
448 g_proxy_list_new (DBusGProxy *first_proxy)
450 DBusGProxyList *list;
451 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(first_proxy);
453 list = (void*) tristring_alloc_from_strings (G_STRUCT_OFFSET (DBusGProxyList, name),
457 list->proxies = NULL;
463 g_proxy_list_free (DBusGProxyList *list)
465 /* we don't hold a reference to the proxies in the list,
466 * as they ref the GProxyManager
468 g_slist_free (list->proxies);
474 g_proxy_get_signal_match_rule (DBusGProxy *proxy)
476 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
477 /* FIXME Escaping is required here */
480 return g_strdup_printf ("type='signal',sender='%s',path='%s',interface='%s'",
481 priv->name, priv->path, priv->interface);
483 return g_strdup_printf ("type='signal',path='%s',interface='%s'",
484 priv->path, priv->interface);
488 g_proxy_get_owner_match_rule (DBusGProxy *proxy)
490 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
493 return g_strdup_printf ("type='signal',sender='" DBUS_SERVICE_DBUS
494 "',path='" DBUS_PATH_DBUS
495 "',interface='" DBUS_INTERFACE_DBUS
496 "',member='NameOwnerChanged'"
497 ",arg0='%s'", priv->name);
506 } DBusGProxyNameOwnerInfo;
509 find_name_in_info (gconstpointer a, gconstpointer b)
511 const DBusGProxyNameOwnerInfo *info = a;
512 const char *name = b;
514 return strcmp (info->name, name);
521 DBusGProxyNameOwnerInfo *info;
522 } DBusGProxyNameOwnerForeachData;
525 name_owner_foreach (gpointer key, gpointer val, gpointer data)
528 DBusGProxyNameOwnerForeachData *foreach_data;
536 if (foreach_data->owner != NULL)
539 g_assert (foreach_data->info == NULL);
541 link = g_slist_find_custom (names, foreach_data->name, find_name_in_info);
544 foreach_data->owner = owner;
545 foreach_data->info = link->data;
550 dbus_g_proxy_manager_lookup_name_owner (DBusGProxyManager *manager,
552 DBusGProxyNameOwnerInfo **info,
555 DBusGProxyNameOwnerForeachData foreach_data;
557 foreach_data.name = name;
558 foreach_data.owner = NULL;
559 foreach_data.info = NULL;
561 g_hash_table_foreach (manager->owner_names, name_owner_foreach, &foreach_data);
563 *info = foreach_data.info;
564 *owner = foreach_data.owner;
565 return *info != NULL;
569 insert_nameinfo (DBusGProxyManager *manager,
571 DBusGProxyNameOwnerInfo *info)
576 names = g_hash_table_lookup (manager->owner_names, owner);
578 /* Only need to g_hash_table_insert the first time */
579 insert = (names == NULL);
581 names = g_slist_append (names, info);
584 g_hash_table_insert (manager->owner_names, g_strdup (owner), names);
588 dbus_g_proxy_manager_monitor_name_owner (DBusGProxyManager *manager,
594 DBusGProxyNameOwnerInfo *nameinfo;
596 names = g_hash_table_lookup (manager->owner_names, owner);
597 link = g_slist_find_custom (names, name, find_name_in_info);
601 nameinfo = g_new0 (DBusGProxyNameOwnerInfo, 1);
602 nameinfo->name = g_strdup (name);
603 nameinfo->refcount = 1;
605 insert_nameinfo (manager, owner, nameinfo);
609 nameinfo = link->data;
610 nameinfo->refcount++;
615 dbus_g_proxy_manager_unmonitor_name_owner (DBusGProxyManager *manager,
618 DBusGProxyNameOwnerInfo *info;
622 ret = dbus_g_proxy_manager_lookup_name_owner (manager, name, &info, &owner);
624 g_assert (info != NULL);
625 g_assert (owner != NULL);
628 if (info->refcount == 0)
633 names = g_hash_table_lookup (manager->owner_names, owner);
634 link = g_slist_find_custom (names, name, find_name_in_info);
635 names = g_slist_delete_link (names, link);
637 g_hash_table_insert (manager->owner_names, g_strdup (owner), names);
639 g_hash_table_remove (manager->owner_names, owner);
650 } DBusGProxyUnassociateData;
653 unassociate_proxies (gpointer key, gpointer val, gpointer user_data)
655 DBusGProxyList *list;
658 DBusGProxyUnassociateData *data;
664 for (tmp = list->proxies; tmp; tmp = tmp->next)
666 DBusGProxy *proxy = DBUS_G_PROXY (tmp->data);
667 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
668 DBusGProxyManager *manager;
670 manager = priv->manager;
672 if (!strcmp (priv->name, name))
674 if (!priv->for_owner)
676 /* If a service appeared and then vanished very quickly,
677 * it's conceivable we have an inflight request for
678 * GetNameOwner here. Cancel it.
679 * https://bugs.freedesktop.org/show_bug.cgi?id=18573
682 dbus_g_proxy_cancel_call (manager->bus_proxy, priv->name_call);
684 priv->name_call = NULL;
686 priv->associated = FALSE;
687 manager->unassociated_proxies = g_slist_prepend (manager->unassociated_proxies, proxy);
691 data->destroyed = g_slist_prepend (data->destroyed, proxy);
692 /* make contents of list into weak pointers in case the objects
693 * unref each other when disposing */
694 g_object_add_weak_pointer (G_OBJECT (proxy),
695 &(data->destroyed->data));
702 dbus_g_proxy_manager_replace_name_owner (DBusGProxyManager *manager,
704 const char *prev_owner,
705 const char *new_owner)
709 if (prev_owner[0] == '\0')
714 /* We have a new service, look at unassociated proxies */
718 for (tmp = manager->unassociated_proxies; tmp ; tmp = tmp->next)
720 DBusGProxy *proxy = tmp->data;
721 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
723 if (!strcmp (priv->name, name))
725 removed = g_slist_prepend (removed, tmp);
727 dbus_g_proxy_manager_monitor_name_owner (manager, new_owner, name);
728 priv->associated = TRUE;
732 for (tmp = removed; tmp; tmp = tmp->next)
733 manager->unassociated_proxies = g_slist_delete_link (manager->unassociated_proxies, tmp->data);
734 g_slist_free (removed);
738 DBusGProxyNameOwnerInfo *info;
741 /* Name owner changed or deleted */
743 names = g_hash_table_lookup (manager->owner_names, prev_owner);
748 link = g_slist_find_custom (names, name, find_name_in_info);
754 names = g_slist_delete_link (names, link);
758 g_hash_table_remove (manager->owner_names, prev_owner);
762 g_hash_table_insert (manager->owner_names,
763 g_strdup (prev_owner), names);
768 if (new_owner[0] == '\0')
770 DBusGProxyUnassociateData data;
774 data.destroyed = NULL;
776 /* A service went away, we need to unassociate proxies */
777 g_hash_table_foreach (manager->proxy_lists,
778 unassociate_proxies, &data);
780 UNLOCK_MANAGER (manager);
782 /* the destroyed list's data pointers are weak pointers, so that we
783 * don't end up calling destroy on proxies which have already been
784 * freed up as a result of other ones being destroyed */
785 for (tmp = data.destroyed; tmp; tmp = tmp->next)
786 if (tmp->data != NULL)
788 g_object_remove_weak_pointer (G_OBJECT (tmp->data),
790 dbus_g_proxy_destroy (tmp->data);
792 g_slist_free (data.destroyed);
794 LOCK_MANAGER (manager);
804 insert_nameinfo (manager, new_owner, info);
810 got_name_owner_cb (DBusGProxy *bus_proxy,
811 DBusGProxyCall *call,
814 DBusGProxy *proxy = user_data;
815 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
822 LOCK_MANAGER (priv->manager);
824 if (!dbus_g_proxy_end_call (bus_proxy, call, &error,
825 G_TYPE_STRING, &owner,
828 if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
830 priv->manager->unassociated_proxies = g_slist_prepend (priv->manager->unassociated_proxies, proxy);
832 else if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
833 g_warning ("Couldn't get name owner (%s): %s",
834 dbus_g_error_get_name (error),
837 g_warning ("Couldn't get name owner (code %d): %s",
838 error->code, error->message);
839 g_clear_error (&error);
844 dbus_g_proxy_manager_monitor_name_owner (priv->manager, owner, priv->name);
845 priv->associated = TRUE;
849 priv->name_call = NULL;
850 UNLOCK_MANAGER (priv->manager);
855 get_name_owner (DBusConnection *connection,
860 DBusMessage *request, *reply;
863 dbus_error_init (&derror);
868 request = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
873 g_error ("Out of memory");
875 if (!dbus_message_append_args (request,
876 DBUS_TYPE_STRING, &name,
878 g_error ("Out of memory");
881 dbus_connection_send_with_reply_and_block (connection,
887 if (dbus_set_error_from_message (&derror, reply))
890 if (!dbus_message_get_args (reply, &derror,
891 DBUS_TYPE_STRING, &base_name,
895 base_name = g_strdup (base_name);
899 g_assert (dbus_error_is_set (&derror));
900 dbus_set_g_error (error, &derror);
901 dbus_error_free (&derror);
905 dbus_message_unref (request);
907 dbus_message_unref (reply);
914 dbus_g_proxy_manager_register (DBusGProxyManager *manager,
917 DBusGProxyList *list;
918 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
920 LOCK_MANAGER (manager);
922 if (manager->proxy_lists == NULL)
924 g_assert (manager->owner_names == NULL);
927 manager->proxy_lists = g_hash_table_new_full (tristring_hash,
930 (GFreeFunc) g_proxy_list_free);
931 manager->owner_names = g_hash_table_new_full (g_str_hash,
940 tri = tristring_from_proxy (proxy);
942 list = g_hash_table_lookup (manager->proxy_lists, tri);
949 list = g_proxy_list_new (proxy);
951 g_hash_table_replace (manager->proxy_lists,
955 if (list->proxies == NULL && priv->name)
957 /* We have to add match rules to the server,
958 * but only if the server is a message bus,
959 * not if it's a peer.
963 rule = g_proxy_get_signal_match_rule (proxy);
964 /* We don't check for errors; it's not like anyone would handle them, and
965 * we don't want a round trip here.
967 dbus_bus_add_match (manager->connection,
971 rule = g_proxy_get_owner_match_rule (proxy);
973 dbus_bus_add_match (manager->connection,
978 g_assert (g_slist_find (list->proxies, proxy) == NULL);
980 list->proxies = g_slist_prepend (list->proxies, proxy);
982 if (!priv->for_owner)
985 DBusGProxyNameOwnerInfo *info;
987 if (!dbus_g_proxy_manager_lookup_name_owner (manager, priv->name, &info, &owner))
989 priv->name_call = manager_begin_bus_call (manager, "GetNameOwner",
996 priv->associated = FALSE;
1001 priv->associated = TRUE;
1005 UNLOCK_MANAGER (manager);
1009 dbus_g_proxy_manager_unregister (DBusGProxyManager *manager,
1012 DBusGProxyList *list;
1013 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
1016 LOCK_MANAGER (manager);
1018 #ifndef G_DISABLE_CHECKS
1019 if (manager->proxy_lists == NULL)
1021 g_warning ("Trying to unregister a proxy but there aren't any registered");
1026 tri = tristring_from_proxy (proxy);
1028 list = g_hash_table_lookup (manager->proxy_lists, tri);
1030 #ifndef G_DISABLE_CHECKS
1033 g_warning ("Trying to unregister a proxy but it isn't registered");
1038 g_assert (g_slist_find (list->proxies, proxy) != NULL);
1040 list->proxies = g_slist_remove (list->proxies, proxy);
1042 g_assert (g_slist_find (list->proxies, proxy) == NULL);
1044 if (!priv->for_owner)
1046 if (!priv->associated)
1050 if (priv->name_call != 0)
1052 dbus_g_proxy_cancel_call (manager->bus_proxy, priv->name_call);
1053 priv->name_call = 0;
1057 link = g_slist_find (manager->unassociated_proxies, proxy);
1058 g_assert (link != NULL);
1060 manager->unassociated_proxies = g_slist_delete_link (manager->unassociated_proxies, link);
1065 g_assert (priv->name_call == 0);
1067 dbus_g_proxy_manager_unmonitor_name_owner (manager, priv->name);
1071 if (list->proxies == NULL)
1074 g_hash_table_remove (manager->proxy_lists,
1078 rule = g_proxy_get_signal_match_rule (proxy);
1079 dbus_bus_remove_match (manager->connection,
1082 rule = g_proxy_get_owner_match_rule (proxy);
1084 dbus_bus_remove_match (manager->connection,
1089 if (g_hash_table_size (manager->proxy_lists) == 0)
1091 g_hash_table_destroy (manager->proxy_lists);
1092 manager->proxy_lists = NULL;
1097 UNLOCK_MANAGER (manager);
1101 list_proxies_foreach (gpointer key,
1105 DBusGProxyList *list;
1112 tmp = list->proxies;
1115 DBusGProxy *proxy = DBUS_G_PROXY (tmp->data);
1117 g_object_ref (proxy);
1118 *ret = g_slist_prepend (*ret, proxy);
1125 dbus_g_proxy_manager_list_all (DBusGProxyManager *manager)
1131 if (manager->proxy_lists)
1133 g_hash_table_foreach (manager->proxy_lists,
1134 list_proxies_foreach,
1141 static DBusHandlerResult
1142 dbus_g_proxy_manager_filter (DBusConnection *connection,
1143 DBusMessage *message,
1146 DBusGProxyManager *manager;
1148 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
1149 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1151 manager = user_data;
1153 dbus_g_proxy_manager_ref (manager);
1155 LOCK_MANAGER (manager);
1157 if (dbus_message_is_signal (message,
1158 DBUS_INTERFACE_LOCAL,
1161 /* Destroy all the proxies, quite possibly resulting in unreferencing
1162 * the proxy manager and the connection as well.
1167 all = dbus_g_proxy_manager_list_all (manager);
1174 proxy = DBUS_G_PROXY (tmp->data);
1176 UNLOCK_MANAGER (manager);
1177 dbus_g_proxy_destroy (proxy);
1178 g_object_unref (G_OBJECT (proxy));
1179 LOCK_MANAGER (manager);
1186 #ifndef G_DISABLE_CHECKS
1187 if (manager->proxy_lists != NULL)
1188 g_warning ("Disconnection emitted \"destroy\" on all DBusGProxy, but somehow new proxies were created in response to one of those destroy signals. This will cause a memory leak.");
1195 GSList *owned_names;
1199 /* First we handle NameOwnerChanged internally */
1200 if (dbus_message_is_signal (message,
1201 DBUS_INTERFACE_DBUS,
1202 "NameOwnerChanged"))
1205 const char *prev_owner;
1206 const char *new_owner;
1209 dbus_error_init (&derr);
1210 if (!dbus_message_get_args (message,
1220 /* Ignore this error */
1221 dbus_error_free (&derr);
1223 else if (manager->owner_names != NULL)
1225 dbus_g_proxy_manager_replace_name_owner (manager, name, prev_owner, new_owner);
1229 sender = dbus_message_get_sender (message);
1231 /* dbus spec requires these, libdbus validates */
1232 g_assert (dbus_message_get_path (message) != NULL);
1233 g_assert (dbus_message_get_interface (message) != NULL);
1234 g_assert (dbus_message_get_member (message) != NULL);
1236 tri = tristring_from_message (message);
1238 if (manager->proxy_lists)
1240 DBusGProxyList *owner_list;
1241 owner_list = g_hash_table_lookup (manager->proxy_lists, tri);
1243 full_list = g_slist_copy (owner_list->proxies);
1252 if (manager->owner_names && sender)
1254 owned_names = g_hash_table_lookup (manager->owner_names, sender);
1255 for (tmp = owned_names; tmp; tmp = tmp->next)
1257 DBusGProxyList *owner_list;
1258 DBusGProxyNameOwnerInfo *nameinfo;
1260 nameinfo = tmp->data;
1261 g_assert (nameinfo->refcount > 0);
1262 tri = tristring_alloc_from_strings (0, nameinfo->name,
1263 dbus_message_get_path (message),
1264 dbus_message_get_interface (message));
1266 owner_list = g_hash_table_lookup (manager->proxy_lists, tri);
1267 if (owner_list != NULL)
1271 /* Ignore duplicates when adding to full_list */
1272 for (elt = owner_list->proxies; elt; elt = g_slist_next (elt))
1274 if (!g_slist_find (full_list, elt->data))
1275 full_list = g_slist_append (full_list, elt->data);
1283 g_print ("proxy got %s,%s,%s = list %p\n",
1285 tri + strlen (tri) + 1,
1286 tri + strlen (tri) + 1 + strlen (tri + strlen (tri) + 1) + 1,
1290 /* Emit the signal */
1292 g_slist_foreach (full_list, (GFunc) g_object_ref, NULL);
1294 for (tmp = full_list; tmp; tmp = tmp->next)
1298 proxy = DBUS_G_PROXY (tmp->data);
1300 UNLOCK_MANAGER (manager);
1301 dbus_g_proxy_emit_remote_signal (proxy, message);
1302 g_object_unref (G_OBJECT (proxy));
1303 LOCK_MANAGER (manager);
1305 g_slist_free (full_list);
1308 UNLOCK_MANAGER (manager);
1309 dbus_g_proxy_manager_unref (manager);
1311 /* "Handling" signals doesn't make sense, they are for everyone
1314 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1319 /* ---------- DBusGProxy -------------- */
1320 #define DBUS_G_PROXY_DESTROYED(proxy) (DBUS_G_PROXY_GET_PRIVATE(proxy)->manager == NULL)
1323 marshal_dbus_message_to_g_marshaller (GClosure *closure,
1324 GValue *return_value,
1325 guint n_param_values,
1326 const GValue *param_values,
1327 gpointer invocation_hint,
1328 gpointer marshal_data);
1345 static void *parent_class;
1346 static guint signals[LAST_SIGNAL] = { 0 };
1349 dbus_g_proxy_init (DBusGProxy *proxy)
1351 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
1353 g_datalist_init (&priv->signal_signatures);
1354 priv->pending_calls = g_hash_table_new_full (NULL, NULL, NULL,
1355 (GDestroyNotify) dbus_pending_call_unref);
1356 priv->name_call = 0;
1357 priv->associated = FALSE;
1358 priv->default_timeout = -1;
1362 dbus_g_proxy_constructor (GType type,
1363 guint n_construct_properties,
1364 GObjectConstructParam *construct_properties)
1367 DBusGProxyClass *klass;
1368 GObjectClass *parent_class;
1369 DBusGProxyPrivate *priv;
1371 klass = DBUS_G_PROXY_CLASS (g_type_class_peek (DBUS_TYPE_G_PROXY));
1373 parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
1375 proxy = DBUS_G_PROXY (parent_class->constructor (type, n_construct_properties,
1376 construct_properties));
1378 priv = DBUS_G_PROXY_GET_PRIVATE (proxy);
1380 /* if these assertions fail, a deriving class has not set our required
1381 * parameters - our own public constructors do return_if_fail checks
1382 * on these parameters being provided. unfortunately we can't assert
1383 * for manager because it's allowed to be NULL when tha mangager is
1384 * setting up a bus proxy for its own calls */
1385 g_assert (priv->path != NULL);
1386 g_assert (priv->interface != NULL);
1388 if (priv->manager != NULL)
1390 dbus_g_proxy_manager_register (priv->manager, proxy);
1393 return G_OBJECT (proxy);
1397 dbus_g_proxy_class_init (DBusGProxyClass *klass)
1399 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1401 parent_class = g_type_class_peek_parent (klass);
1403 g_type_class_add_private (klass, sizeof (DBusGProxyPrivate));
1405 object_class->set_property = dbus_g_proxy_set_property;
1406 object_class->get_property = dbus_g_proxy_get_property;
1408 g_object_class_install_property (object_class,
1410 g_param_spec_string ("name",
1414 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
1416 g_object_class_install_property (object_class,
1418 g_param_spec_string ("path",
1422 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
1424 g_object_class_install_property (object_class,
1426 g_param_spec_string ("interface",
1430 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
1432 g_object_class_install_property (object_class,
1434 g_param_spec_boxed ("connection",
1437 DBUS_TYPE_G_CONNECTION,
1438 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
1440 object_class->finalize = dbus_g_proxy_finalize;
1441 object_class->dispose = dbus_g_proxy_dispose;
1442 object_class->constructor = dbus_g_proxy_constructor;
1445 g_signal_new ("destroy",
1446 G_OBJECT_CLASS_TYPE (object_class),
1447 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1450 g_cclosure_marshal_VOID__VOID,
1454 g_signal_new ("received",
1455 G_OBJECT_CLASS_TYPE (object_class),
1456 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
1459 marshal_dbus_message_to_g_marshaller,
1460 G_TYPE_NONE, 2, DBUS_TYPE_MESSAGE, G_TYPE_POINTER);
1464 cancel_pending_call (gpointer key, gpointer val, gpointer data)
1466 DBusPendingCall *pending = val;
1468 dbus_pending_call_cancel (pending);
1474 dbus_g_proxy_dispose (GObject *object)
1476 DBusGProxy *proxy = DBUS_G_PROXY (object);
1477 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
1479 if (priv->pending_calls == NULL)
1484 /* Cancel outgoing pending calls */
1485 g_hash_table_foreach_remove (priv->pending_calls, cancel_pending_call, NULL);
1486 g_hash_table_destroy (priv->pending_calls);
1487 priv->pending_calls = NULL;
1489 if (priv->manager && proxy != priv->manager->bus_proxy)
1491 dbus_g_proxy_manager_unregister (priv->manager, proxy);
1492 dbus_g_proxy_manager_unref (priv->manager);
1494 priv->manager = NULL;
1496 g_datalist_clear (&priv->signal_signatures);
1498 g_signal_emit (object, signals[DESTROY], 0);
1500 G_OBJECT_CLASS (parent_class)->dispose (object);
1504 dbus_g_proxy_finalize (GObject *object)
1506 DBusGProxy *proxy = DBUS_G_PROXY (object);
1507 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
1509 g_return_if_fail (DBUS_G_PROXY_DESTROYED (proxy));
1511 g_free (priv->name);
1512 g_free (priv->path);
1513 g_free (priv->interface);
1515 G_OBJECT_CLASS (parent_class)->finalize (object);
1519 dbus_g_proxy_destroy (DBusGProxy *proxy)
1521 /* FIXME do we need the GTK_IN_DESTRUCTION style flag
1524 g_object_run_dispose (G_OBJECT (proxy));
1528 dbus_g_proxy_set_property (GObject *object,
1530 const GValue *value,
1533 DBusGProxy *proxy = DBUS_G_PROXY (object);
1534 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
1535 DBusGConnection *connection;
1540 priv->name = g_strdup (g_value_get_string (value));
1542 priv->for_owner = (priv->name[0] == ':');
1544 priv->for_owner = TRUE;
1547 priv->path = g_strdup (g_value_get_string (value));
1549 case PROP_INTERFACE:
1550 priv->interface = g_strdup (g_value_get_string (value));
1552 case PROP_CONNECTION:
1553 connection = g_value_get_boxed (value);
1554 if (connection != NULL)
1556 priv->manager = dbus_g_proxy_manager_get (DBUS_CONNECTION_FROM_G_CONNECTION (connection));
1560 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1566 dbus_g_proxy_get_property (GObject *object,
1571 DBusGProxy *proxy = DBUS_G_PROXY (object);
1572 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
1577 g_value_set_string (value, priv->name);
1580 g_value_set_string (value, priv->path);
1582 case PROP_INTERFACE:
1583 g_value_set_string (value, priv->interface);
1585 case PROP_CONNECTION:
1586 g_value_set_boxed (value, DBUS_G_CONNECTION_FROM_CONNECTION(priv->manager->connection));
1589 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1594 /* this is to avoid people using g_signal_connect() directly,
1595 * to avoid confusion with local signal names, and because
1596 * of the horribly broken current setup (signals are added
1597 * globally to all proxies)
1600 create_signal_name (const char *interface,
1606 str = g_string_new (interface);
1608 g_string_append (str, "-");
1610 g_string_append (str, signal);
1612 /* GLib will silently barf on '.' in signal names */
1621 return g_string_free (str, FALSE);
1625 marshal_dbus_message_to_g_marshaller (GClosure *closure,
1626 GValue *return_value,
1627 guint n_param_values,
1628 const GValue *param_values,
1629 gpointer invocation_hint,
1630 gpointer marshal_data)
1632 /* Incoming here we have three params, the instance (Proxy), the
1633 * DBusMessage, the signature. We want to convert that to an
1634 * expanded GValue array, then call an appropriate normal GLib
1637 #define MAX_SIGNATURE_ARGS 20
1638 GValueArray *value_array;
1639 GSignalCMarshaller c_marshaller;
1641 DBusMessage *message;
1644 DBusGProxyPrivate *priv;
1646 g_assert (n_param_values == 3);
1648 proxy = g_value_get_object (¶m_values[0]);
1649 message = g_value_get_boxed (¶m_values[1]);
1650 gsignature = g_value_get_pointer (¶m_values[2]);
1652 g_return_if_fail (DBUS_IS_G_PROXY (proxy));
1653 g_return_if_fail (message != NULL);
1654 g_return_if_fail (gsignature != NULL);
1656 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
1658 c_marshaller = _dbus_gobject_lookup_marshaller (G_TYPE_NONE, gsignature->len,
1659 (GType*) gsignature->data);
1661 g_return_if_fail (c_marshaller != NULL);
1664 DBusGValueMarshalCtx context;
1665 context.recursion_depth = 0;
1666 context.gconnection = DBUS_G_CONNECTION_FROM_CONNECTION (priv->manager->connection);
1667 context.proxy = proxy;
1669 types = (const GType*) gsignature->data;
1670 value_array = _dbus_gvalue_demarshal_message (&context, message,
1671 gsignature->len, types, NULL);
1674 if (value_array == NULL)
1677 g_value_array_prepend (value_array, NULL);
1678 g_value_init (g_value_array_get_nth (value_array, 0), G_TYPE_FROM_INSTANCE (proxy));
1679 g_value_set_instance (g_value_array_get_nth (value_array, 0), proxy);
1681 (* c_marshaller) (closure, return_value, value_array->n_values,
1682 value_array->values, invocation_hint, marshal_data);
1684 g_value_array_free (value_array);
1688 dbus_g_proxy_emit_remote_signal (DBusGProxy *proxy,
1689 DBusMessage *message)
1691 const char *interface;
1695 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
1696 GArray *msg_gsignature = NULL;
1698 g_return_if_fail (!DBUS_G_PROXY_DESTROYED (proxy));
1700 interface = dbus_message_get_interface (message);
1701 signal = dbus_message_get_member (message);
1703 g_assert (interface != NULL);
1704 g_assert (signal != NULL);
1706 name = create_signal_name (interface, signal);
1708 /* If the quark isn't preexisting, there's no way there
1709 * are any handlers connected. We don't want to create
1710 * extra quarks for every possible signal.
1712 q = g_quark_try_string (name);
1719 gsignature = g_datalist_id_get_data (&priv->signal_signatures, q);
1720 if (gsignature == NULL)
1723 msg_gsignature = _dbus_gtypes_from_arg_signature (dbus_message_get_signature (message),
1725 for (i = 0; i < gsignature->len; i++)
1727 if (msg_gsignature->len == i
1728 || g_array_index (gsignature, GType, i) != g_array_index (msg_gsignature, GType, i))
1731 if (msg_gsignature->len != i)
1734 g_signal_emit (proxy,
1744 g_array_free (msg_gsignature, TRUE);
1748 /* Don't spew on remote errors */
1749 g_warning ("Unexpected message signature '%s' for signal '%s'\n",
1750 dbus_message_get_signature (message),
1760 DBusGProxyCallNotify func;
1762 GDestroyNotify free_data_func;
1763 } GPendingNotifyClosure;
1766 d_pending_call_notify (DBusPendingCall *dcall,
1769 GPendingNotifyClosure *closure = data;
1771 (* closure->func) (closure->proxy, DBUS_G_PROXY_ID_TO_CALL (closure->call_id), closure->data);
1775 d_pending_call_free (void *data)
1777 GPendingNotifyClosure *closure = data;
1779 if (closure->free_data_func)
1780 (* closure->free_data_func) (closure->data);
1785 #define DBUS_G_VALUE_ARRAY_COLLECT_ALL(VALARRAY, FIRST_ARG_TYPE, ARGS) \
1789 VALARRAY = g_value_array_new (6); \
1790 valtype = FIRST_ARG_TYPE; \
1791 while (valtype != G_TYPE_INVALID) \
1793 const char *collect_err; \
1795 g_value_array_append (VALARRAY, NULL); \
1796 val = g_value_array_get_nth (VALARRAY, i); \
1797 g_value_init (val, valtype); \
1798 collect_err = NULL; \
1799 G_VALUE_COLLECT (val, ARGS, G_VALUE_NOCOPY_CONTENTS, &collect_err); \
1800 valtype = va_arg (ARGS, GType); \
1806 manager_begin_bus_call (DBusGProxyManager *manager,
1808 DBusGProxyCallNotify notify,
1810 GDestroyNotify destroy,
1811 GType first_arg_type,
1814 DBusGProxyCall *call;
1815 DBusGProxyPrivate *priv;
1817 GValueArray *arg_values;
1819 va_start (args, first_arg_type);
1821 if (!manager->bus_proxy)
1823 manager->bus_proxy = g_object_new (DBUS_TYPE_G_PROXY,
1824 "name", DBUS_SERVICE_DBUS,
1825 "path", DBUS_PATH_DBUS,
1826 "interface", DBUS_INTERFACE_DBUS,
1828 priv = DBUS_G_PROXY_GET_PRIVATE(manager->bus_proxy);
1829 priv->manager = manager;
1832 DBUS_G_VALUE_ARRAY_COLLECT_ALL (arg_values, first_arg_type, args);
1834 call = DBUS_G_PROXY_ID_TO_CALL (dbus_g_proxy_begin_call_internal (manager->bus_proxy, method, notify, user_data, destroy, arg_values,-1));
1836 g_value_array_free (arg_values);
1843 /** @} End of DBusGLibInternals */
1845 /** @addtogroup DBusGLib
1850 * SECTION:dbus-gproxy
1851 * @short_description: DBus Proxy
1852 * @see_also: #DBusProxy
1853 * @stability: Stable
1855 * A #DBusGProxy is a boxed type abstracting a #DBusProxy.
1859 * dbus_g_proxy_get_type:
1860 * Standard GObject get_type() function for DBusGProxy.
1862 * Returns: type ID for DBusGProxy class
1865 dbus_g_proxy_get_type (void)
1867 static GType object_type = 0;
1871 static const GTypeInfo object_info =
1873 sizeof (DBusGProxyClass),
1874 (GBaseInitFunc) NULL,
1875 (GBaseFinalizeFunc) NULL,
1876 (GClassInitFunc) dbus_g_proxy_class_init,
1877 NULL, /* class_finalize */
1878 NULL, /* class_data */
1879 sizeof (DBusGProxy),
1880 0, /* n_preallocs */
1881 (GInstanceInitFunc) dbus_g_proxy_init,
1884 object_type = g_type_register_static (G_TYPE_OBJECT,
1893 dbus_g_proxy_new (DBusGConnection *connection,
1895 const char *path_name,
1896 const char *interface_name)
1900 g_assert (connection != NULL);
1902 proxy = g_object_new (DBUS_TYPE_G_PROXY,
1905 "interface", interface_name,
1906 "connection", connection, NULL);
1912 * dbus_g_proxy_new_for_name:
1913 * @connection: the connection to the remote bus
1914 * @name: any name on the message bus
1915 * @path_name: name of the object instance to call methods on
1916 * @interface_name: name of the interface to call methods on
1918 * Creates a new proxy for a remote interface exported by a connection
1919 * on a message bus. Method calls and signal connections over this
1920 * proxy will go to the name owner; the name's owner is expected to
1921 * support the given interface name. THE NAME OWNER MAY CHANGE OVER
1922 * TIME, for example between two different method calls, unless the
1923 * name is a unique name. If you need a fixed owner, you need to
1924 * request the current owner and bind a proxy to its unique name
1925 * rather than to the generic name; see
1926 * dbus_g_proxy_new_for_name_owner().
1928 * A name-associated proxy only makes sense with a message bus, not
1929 * for app-to-app direct dbus connections.
1931 * This proxy will only emit the "destroy" signal if the
1932 * #DBusConnection is disconnected, the proxy has no remaining
1933 * references, or the name is a unique name and its owner
1934 * disappears. If a well-known name changes owner, the proxy will
1937 * Returns: new proxy object
1940 dbus_g_proxy_new_for_name (DBusGConnection *connection,
1942 const char *path_name,
1943 const char *interface_name)
1945 g_return_val_if_fail (connection != NULL, NULL);
1946 g_return_val_if_fail (name != NULL, NULL);
1947 g_return_val_if_fail (path_name != NULL, NULL);
1948 g_return_val_if_fail (interface_name != NULL, NULL);
1950 return dbus_g_proxy_new (connection, name,
1951 path_name, interface_name);
1955 * dbus_g_proxy_new_for_name_owner:
1956 * @connection: the connection to the remote bus
1957 * @name: any name on the message bus
1958 * @path_name: name of the object inside the service to call methods on
1959 * @interface_name: name of the interface to call methods on
1960 * @error: return location for an error
1962 * Similar to dbus_g_proxy_new_for_name(), but makes a round-trip
1963 * request to the message bus to get the current name owner, then
1964 * binds the proxy to the unique name of the current owner, rather
1965 * than to the well-known name. As a result, the name owner will
1966 * not change over time, and the proxy will emit the "destroy" signal
1967 * when the owner disappears from the message bus.
1969 * An example of the difference between dbus_g_proxy_new_for_name()
1970 * and dbus_g_proxy_new_for_name_owner(): if you provide the well-known name
1971 * "org.freedesktop.Database" dbus_g_proxy_new_for_name() remains bound
1972 * to that name as it changes owner. dbus_g_proxy_new_for_name_owner()
1973 * will fail if the name has no owner. If the name has an owner,
1974 * dbus_g_proxy_new_for_name_owner() will bind to the unique name
1975 * of that owner rather than the generic name.
1977 * Returns: new proxy object, or #NULL on error
1980 dbus_g_proxy_new_for_name_owner (DBusGConnection *connection,
1982 const char *path_name,
1983 const char *interface_name,
1989 g_return_val_if_fail (connection != NULL, NULL);
1990 g_return_val_if_fail (name != NULL, NULL);
1991 g_return_val_if_fail (path_name != NULL, NULL);
1992 g_return_val_if_fail (interface_name != NULL, NULL);
1994 if (!(unique_name = get_name_owner (DBUS_CONNECTION_FROM_G_CONNECTION (connection), name, error)))
1997 proxy = dbus_g_proxy_new (connection, unique_name,
1998 path_name, interface_name);
1999 g_free (unique_name);
2004 * dbus_g_proxy_new_from_proxy:
2005 * @proxy: the proxy to use as a template
2006 * @path: of the object inside the peer to call methods on
2007 * @interface: name of the interface to call methods on
2009 * Creates a proxy using an existing proxy as a template, substituting
2010 * the specified interface and path. Either or both may be NULL.
2012 * Returns: new proxy object
2015 dbus_g_proxy_new_from_proxy (DBusGProxy *proxy,
2016 const char *interface,
2019 DBusGProxyPrivate *priv;
2021 g_return_val_if_fail (proxy != NULL, NULL);
2023 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2025 if (interface == NULL)
2026 interface = priv->interface;
2030 return dbus_g_proxy_new (DBUS_G_CONNECTION_FROM_CONNECTION (priv->manager->connection),
2036 * dbus_g_proxy_new_for_peer:
2037 * @connection: the connection to the peer
2038 * @path_name: name of the object inside the peer to call methods on
2039 * @interface_name: name of the interface to call methods on
2041 * Creates a proxy for an object in peer application (one
2042 * we're directly connected to). That is, this function is
2043 * intended for use when there's no message bus involved,
2044 * we're doing a simple 1-to-1 communication between two
2047 * Returns: new proxy object
2050 dbus_g_proxy_new_for_peer (DBusGConnection *connection,
2051 const char *path_name,
2052 const char *interface_name)
2056 g_return_val_if_fail (connection != NULL, NULL);
2057 g_return_val_if_fail (path_name != NULL, NULL);
2058 g_return_val_if_fail (interface_name != NULL, NULL);
2060 proxy = dbus_g_proxy_new (connection, NULL,
2061 path_name, interface_name);
2067 * dbus_g_proxy_get_bus_name:
2070 * Gets the bus name a proxy is bound to (may be #NULL in some cases).
2071 * If you created the proxy with dbus_g_proxy_new_for_name(), then
2072 * the name you passed to that will be returned.
2073 * If you created it with dbus_g_proxy_new_for_name_owner(), then the
2074 * unique connection name will be returned. If you created it
2075 * with dbus_g_proxy_new_for_peer() then #NULL will be returned.
2077 * Returns: the bus name the proxy sends messages to
2080 dbus_g_proxy_get_bus_name (DBusGProxy *proxy)
2082 DBusGProxyPrivate *priv;
2084 g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);
2085 g_return_val_if_fail (!DBUS_G_PROXY_DESTROYED (proxy), NULL);
2087 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2093 * dbus_g_proxy_get_interface:
2096 * Gets the object interface proxy is bound to (may be #NULL in some cases).
2098 * Returns: an object interface
2101 dbus_g_proxy_get_interface (DBusGProxy *proxy)
2103 DBusGProxyPrivate *priv;
2105 g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);
2106 g_return_val_if_fail (!DBUS_G_PROXY_DESTROYED (proxy), NULL);
2108 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2110 return priv->interface;
2114 * dbus_g_proxy_set_interface:
2116 * @interface_name: an object interface
2118 * Sets the object interface proxy is bound to
2121 dbus_g_proxy_set_interface (DBusGProxy *proxy,
2122 const char *interface_name)
2124 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2125 /* FIXME - need to unregister when we switch interface for now
2126 * later should support idea of unset interface
2128 dbus_g_proxy_manager_unregister (priv->manager, proxy);
2129 g_free (priv->interface);
2130 priv->interface = g_strdup (interface_name);
2131 dbus_g_proxy_manager_register (priv->manager, proxy);
2135 * dbus_g_proxy_get_path:
2136 * Gets the path this proxy is bound to
2139 * Returns: an object path
2142 dbus_g_proxy_get_path (DBusGProxy *proxy)
2144 DBusGProxyPrivate *priv;
2146 g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);
2147 g_return_val_if_fail (!DBUS_G_PROXY_DESTROYED (proxy), NULL);
2149 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2154 static DBusMessage *
2155 dbus_g_proxy_marshal_args_to_message (DBusGProxy *proxy,
2159 DBusMessage *message;
2160 DBusMessageIter msgiter;
2162 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2164 message = dbus_message_new_method_call (priv->name,
2168 if (message == NULL)
2171 dbus_message_iter_init_append (message, &msgiter);
2172 for (i = 0; i < args->n_values; i++)
2176 gvalue = g_value_array_get_nth (args, i);
2178 if (!_dbus_gvalue_marshal (&msgiter, gvalue))
2179 g_assert_not_reached ();
2187 dbus_g_proxy_begin_call_internal (DBusGProxy *proxy,
2189 DBusGProxyCallNotify notify,
2191 GDestroyNotify destroy,
2195 DBusMessage *message;
2196 DBusPendingCall *pending;
2197 GPendingNotifyClosure *closure;
2199 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2203 message = dbus_g_proxy_marshal_args_to_message (proxy, method, args);
2207 if (!dbus_connection_send_with_reply (priv->manager->connection,
2212 dbus_message_unref (message);
2214 /* If we got a NULL pending, that means the connection was disconnected,
2215 * and we need to abort this call.
2216 * https://bugs.freedesktop.org/show_bug.cgi?id=12675
2218 if (pending == NULL)
2221 call_id = ++priv->call_id_counter;
2225 closure = g_new (GPendingNotifyClosure, 1);
2226 closure->proxy = proxy; /* No need to ref as the lifecycle is tied to proxy */
2227 closure->call_id = call_id;
2228 closure->func = notify;
2229 closure->data = user_data;
2230 closure->free_data_func = destroy;
2231 dbus_pending_call_set_notify (pending, d_pending_call_notify,
2233 d_pending_call_free);
2236 g_hash_table_insert (priv->pending_calls, GUINT_TO_POINTER (call_id), pending);
2240 g_error ("Out of memory");
2245 dbus_g_proxy_end_call_internal (DBusGProxy *proxy,
2248 GType first_arg_type,
2252 DBusMessageIter msgiter;
2254 va_list args_unwind;
2256 int n_retvals_processed;
2259 DBusPendingCall *pending;
2260 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2264 n_retvals_processed = 0;
2267 /* Keep around a copy of output arguments so we can free on error. */
2268 G_VA_COPY(args_unwind, args);
2270 pending = g_hash_table_lookup (priv->pending_calls, GUINT_TO_POINTER (call_id));
2272 dbus_pending_call_block (pending);
2273 reply = dbus_pending_call_steal_reply (pending);
2275 g_assert (reply != NULL);
2277 dbus_error_init (&derror);
2279 switch (dbus_message_get_type (reply))
2281 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
2282 dbus_message_iter_init (reply, &msgiter);
2283 valtype = first_arg_type;
2284 while (valtype != G_TYPE_INVALID)
2287 gpointer return_storage;
2288 GValue gvalue = { 0, };
2289 DBusGValueMarshalCtx context;
2291 context.recursion_depth = 0;
2292 context.gconnection = DBUS_G_CONNECTION_FROM_CONNECTION (priv->manager->connection);
2293 context.proxy = proxy;
2295 arg_type = dbus_message_iter_get_arg_type (&msgiter);
2296 if (arg_type == DBUS_TYPE_INVALID)
2298 g_set_error (error, DBUS_GERROR,
2299 DBUS_GERROR_INVALID_ARGS,
2300 _("Too few arguments in reply"));
2304 return_storage = va_arg (args, gpointer);
2305 if (return_storage == NULL)
2308 /* We handle variants specially; the caller is expected
2309 * to have already allocated storage for them.
2311 if (arg_type == DBUS_TYPE_VARIANT
2312 && g_type_is_a (valtype, G_TYPE_VALUE))
2314 if (!_dbus_gvalue_demarshal_variant (&context, &msgiter, (GValue*) return_storage, NULL))
2318 DBUS_GERROR_INVALID_ARGS,
2319 _("Couldn't convert argument, expected \"%s\""),
2320 g_type_name (valtype));
2326 g_value_init (&gvalue, valtype);
2328 if (!_dbus_gvalue_demarshal (&context, &msgiter, &gvalue, error))
2331 /* Anything that can be demarshaled must be storable */
2332 if (!_dbus_gvalue_store (&gvalue, return_storage))
2333 g_assert_not_reached ();
2334 /* Ownership of the value passes to the client, don't unset */
2338 n_retvals_processed++;
2339 dbus_message_iter_next (&msgiter);
2340 valtype = va_arg (args, GType);
2343 while (dbus_message_iter_get_arg_type (&msgiter) != DBUS_TYPE_INVALID)
2346 dbus_message_iter_next (&msgiter);
2351 g_set_error (error, DBUS_GERROR,
2352 DBUS_GERROR_INVALID_ARGS,
2353 _("Too many arguments in reply; expected %d, got %d"),
2354 n_retvals_processed, over);
2358 case DBUS_MESSAGE_TYPE_ERROR:
2359 dbus_set_error_from_message (&derror, reply);
2360 dbus_set_g_error (error, &derror);
2361 dbus_error_free (&derror);
2365 dbus_set_error (&derror, DBUS_ERROR_FAILED,
2366 "Reply was neither a method return nor an exception");
2367 dbus_set_g_error (error, &derror);
2368 dbus_error_free (&derror);
2379 valtype = first_arg_type;
2380 for (i = 0; i < n_retvals_processed; i++)
2382 GValue value = {0,};
2385 g_value_init (&value, valtype);
2387 retval = va_arg (args_unwind, gpointer);
2394 _dbus_gvalue_take (&value, retval);
2395 g_value_unset (&value);
2397 valtype = va_arg (args_unwind, GType);
2400 va_end (args_unwind);
2403 g_hash_table_remove (priv->pending_calls, GUINT_TO_POINTER (call_id));
2406 dbus_message_unref (reply);
2411 * dbus_g_proxy_begin_call:
2412 * @proxy: a proxy for a remote interface
2413 * @method: the name of the method to invoke
2414 * @notify: callback to be invoked when method returns
2415 * @user_data: user data passed to callback
2416 * @destroy: function called to destroy user_data
2417 * @first_arg_type: type of the first argument
2419 * Asynchronously invokes a method on a remote interface. The method
2420 * call will not be sent over the wire until the application returns
2421 * to the main loop, or blocks in dbus_g_connection_flush() to write out
2422 * pending data. The call will be completed after a timeout, or when
2423 * a reply is received. When the call returns, the callback specified
2424 * will be invoked; you can then collect the results of the call
2425 * (which may be an error, or a reply), use dbus_g_proxy_end_call().
2427 * TODO this particular function shouldn't die on out of memory,
2428 * since you should be able to do a call with large arguments.
2430 * Returns: call identifier.
2433 dbus_g_proxy_begin_call (DBusGProxy *proxy,
2435 DBusGProxyCallNotify notify,
2437 GDestroyNotify destroy,
2438 GType first_arg_type,
2443 GValueArray *arg_values;
2444 DBusGProxyPrivate *priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2446 g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);
2447 g_return_val_if_fail (!DBUS_G_PROXY_DESTROYED (proxy), NULL);
2449 va_start (args, first_arg_type);
2451 DBUS_G_VALUE_ARRAY_COLLECT_ALL (arg_values, first_arg_type, args);
2453 call_id = dbus_g_proxy_begin_call_internal (proxy, method, notify, user_data, destroy, arg_values, priv->default_timeout);
2455 g_value_array_free (arg_values);
2459 return DBUS_G_PROXY_ID_TO_CALL (call_id);
2463 * dbus_g_proxy_begin_call_with_timeout:
2464 * @proxy: a proxy for a remote interface
2465 * @method: the name of the method to invoke
2466 * @notify: callback to be invoked when method returns
2467 * @user_data: user data passed to callback
2468 * @destroy: function called to destroy user_data
2469 * @timeout: specify the timeout in milliseconds
2470 * @first_arg_type: type of the first argument
2472 * Asynchronously invokes a method on a remote interface. The method
2473 * call will not be sent over the wire until the application returns
2474 * to the main loop, or blocks in dbus_g_connection_flush() to write out
2475 * pending data. The call will be completed after a timeout, or when
2476 * a reply is received. When the call returns, the callback specified
2477 * will be invoked; you can then collect the results of the call
2478 * (which may be an error, or a reply), use dbus_g_proxy_end_call().
2480 * TODO this particular function shouldn't die on out of memory,
2481 * since you should be able to do a call with large arguments.
2483 * Returns: call identifier.
2486 dbus_g_proxy_begin_call_with_timeout (DBusGProxy *proxy,
2488 DBusGProxyCallNotify notify,
2490 GDestroyNotify destroy,
2492 GType first_arg_type,
2497 GValueArray *arg_values;
2499 g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);
2500 g_return_val_if_fail (!DBUS_G_PROXY_DESTROYED (proxy), NULL);
2502 va_start (args, first_arg_type);
2504 DBUS_G_VALUE_ARRAY_COLLECT_ALL (arg_values, first_arg_type, args);
2506 call_id = dbus_g_proxy_begin_call_internal (proxy, method, notify, user_data, destroy, arg_values,timeout);
2508 g_value_array_free (arg_values);
2512 return DBUS_G_PROXY_ID_TO_CALL (call_id);
2516 * dbus_g_proxy_end_call:
2517 * @proxy: a proxy for a remote interface
2518 * @call: the pending call ID from dbus_g_proxy_begin_call()
2519 * @error: return location for an error
2520 * @first_arg_type: type of first "out" argument
2522 * Collects the results of a method call. The method call was normally
2523 * initiated with dbus_g_proxy_end_call(). You may use this function
2524 * outside of the callback given to dbus_g_proxy_begin_call; in that
2525 * case this function will block if the results haven't yet been
2528 * If the call results in an error, the error is set as normal for
2529 * GError and the function returns #FALSE.
2531 * Otherwise, the "out" parameters and return value of the
2532 * method are stored in the provided varargs list.
2533 * The list should be terminated with G_TYPE_INVALID.
2535 * Returns: #FALSE if an error is set.
2538 dbus_g_proxy_end_call (DBusGProxy *proxy,
2539 DBusGProxyCall *call,
2541 GType first_arg_type,
2547 va_start (args, first_arg_type);
2549 ret = dbus_g_proxy_end_call_internal (proxy, GPOINTER_TO_UINT (call), error, first_arg_type, args);
2557 * dbus_g_proxy_call:
2558 * @proxy: a proxy for a remote interface
2559 * @method: method to invoke
2560 * @error: return location for an error
2561 * @first_arg_type: type of first "in" argument
2563 * Function for synchronously invoking a method and receiving reply
2564 * values. This function is equivalent to dbus_g_proxy_begin_call
2565 * followed by dbus_g_proxy_end_call. All of the input arguments are
2566 * specified first, followed by G_TYPE_INVALID, followed by all of the
2567 * output values, followed by a second G_TYPE_INVALID. Note that
2568 * this means you must always specify G_TYPE_INVALID twice.
2570 * Returns: #FALSE if an error is set, #TRUE otherwise.
2573 dbus_g_proxy_call (DBusGProxy *proxy,
2576 GType first_arg_type,
2582 GValueArray *in_args;
2583 DBusGProxyPrivate *priv;
2585 g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), FALSE);
2586 g_return_val_if_fail (!DBUS_G_PROXY_DESTROYED (proxy), FALSE);
2588 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2590 va_start (args, first_arg_type);
2592 DBUS_G_VALUE_ARRAY_COLLECT_ALL (in_args, first_arg_type, args);
2594 call_id = dbus_g_proxy_begin_call_internal (proxy, method, NULL, NULL, NULL, in_args, priv->default_timeout);
2596 g_value_array_free (in_args);
2600 first_arg_type = va_arg (args, GType);
2601 ret = dbus_g_proxy_end_call_internal (proxy, call_id, error, first_arg_type, args);
2605 g_set_error (error, DBUS_GERROR,
2607 _("Disconnection or out-of-memory"));
2617 * dbus_g_proxy_call_with_timeout:
2618 * @proxy: a proxy for a remote interface
2619 * @method: method to invoke
2620 * @timeout: specify the timeout in milliseconds
2621 * @error: return location for an error
2622 * @first_arg_type: type of first "in" argument
2624 * Function for synchronously invoking a method and receiving reply
2625 * values. This function is equivalent to dbus_g_proxy_begin_call
2626 * followed by dbus_g_proxy_end_call. All of the input arguments are
2627 * specified first, followed by G_TYPE_INVALID, followed by all of the
2628 * output values, followed by a second G_TYPE_INVALID. Note that
2629 * this means you must always specify G_TYPE_INVALID twice.
2631 * Returns: #FALSE if an error is set, #TRUE otherwise.
2634 dbus_g_proxy_call_with_timeout (DBusGProxy *proxy,
2638 GType first_arg_type,
2644 GValueArray *in_args;
2646 g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), FALSE);
2647 g_return_val_if_fail (!DBUS_G_PROXY_DESTROYED (proxy), FALSE);
2649 va_start (args, first_arg_type);
2651 DBUS_G_VALUE_ARRAY_COLLECT_ALL (in_args, first_arg_type, args);
2653 call_id = dbus_g_proxy_begin_call_internal (proxy, method, NULL, NULL, NULL, in_args,timeout);
2655 g_value_array_free (in_args);
2657 first_arg_type = va_arg (args, GType);
2658 ret = dbus_g_proxy_end_call_internal (proxy, call_id, error, first_arg_type, args);
2666 * dbus_g_proxy_call_no_reply:
2667 * @proxy: a proxy for a remote interface
2668 * @method: the name of the method to invoke
2669 * @first_arg_type: type of the first argument
2671 * Sends a method call message as with dbus_g_proxy_begin_call(), but
2672 * does not ask for a reply or allow you to receive one.
2674 * TODO: this particular function shouldn't die on out of memory,
2675 * since you should be able to do a call with large arguments.
2678 dbus_g_proxy_call_no_reply (DBusGProxy *proxy,
2680 GType first_arg_type,
2683 DBusMessage *message;
2685 GValueArray *in_args;
2686 DBusGProxyPrivate *priv;
2688 g_return_if_fail (DBUS_IS_G_PROXY (proxy));
2689 g_return_if_fail (!DBUS_G_PROXY_DESTROYED (proxy));
2691 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2693 va_start (args, first_arg_type);
2694 DBUS_G_VALUE_ARRAY_COLLECT_ALL (in_args, first_arg_type, args);
2696 message = dbus_g_proxy_marshal_args_to_message (proxy, method, in_args);
2698 g_value_array_free (in_args);
2704 dbus_message_set_no_reply (message, TRUE);
2706 if (!dbus_connection_send (priv->manager->connection,
2710 dbus_message_unref (message);
2714 g_error ("Out of memory");
2718 * dbus_g_proxy_cancel_call
2719 * @proxy: a proxy for a remote interface
2720 * @call: the pending call ID from dbus_g_proxy_begin_call()
2722 * Cancels a pending method call. The method call was normally
2723 * initiated with dbus_g_proxy_begin_call(). This function
2724 * may not be used on pending calls that have already been
2725 * ended with dbus_g_proxy_end_call.
2728 dbus_g_proxy_cancel_call (DBusGProxy *proxy,
2729 DBusGProxyCall *call)
2732 DBusPendingCall *pending;
2733 DBusGProxyPrivate *priv;
2735 g_return_if_fail (DBUS_IS_G_PROXY (proxy));
2736 g_return_if_fail (!DBUS_G_PROXY_DESTROYED (proxy));
2738 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2740 call_id = DBUS_G_PROXY_CALL_TO_ID (call);
2742 pending = g_hash_table_lookup (priv->pending_calls, GUINT_TO_POINTER (call_id));
2743 g_hash_table_remove (priv->pending_calls, GUINT_TO_POINTER (call_id));
2744 g_return_if_fail (pending != NULL);
2746 dbus_pending_call_cancel (pending);
2750 * dbus_g_proxy_send:
2751 * @proxy: a proxy for a remote interface
2752 * @message: the message to address and send
2753 * @client_serial: return location for message's serial, or #NULL
2755 * Sends a message to the interface we're proxying for. Does not
2756 * block or wait for a reply. The message is only actually written out
2757 * when you return to the main loop or block in
2758 * dbus_g_connection_flush().
2760 * The message is modified to be addressed to the target interface.
2761 * That is, a destination name field or whatever is needed will be
2762 * added to the message. The basic point of this function is to add
2763 * the necessary header fields, otherwise it's equivalent to
2764 * dbus_connection_send().
2766 * This function adds a reference to the message, so the caller
2767 * still owns its original reference.
2770 dbus_g_proxy_send (DBusGProxy *proxy,
2771 DBusMessage *message,
2772 dbus_uint32_t *client_serial)
2774 DBusGProxyPrivate *priv;
2776 g_return_if_fail (DBUS_IS_G_PROXY (proxy));
2777 g_return_if_fail (!DBUS_G_PROXY_DESTROYED (proxy));
2779 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2783 if (!dbus_message_set_destination (message, priv->name))
2784 g_error ("Out of memory");
2788 if (!dbus_message_set_path (message, priv->path))
2789 g_error ("Out of memory");
2791 if (priv->interface)
2793 if (!dbus_message_set_interface (message, priv->interface))
2794 g_error ("Out of memory");
2797 if (!dbus_connection_send (priv->manager->connection, message, client_serial))
2798 g_error ("Out of memory\n");
2802 array_free_all (gpointer array)
2804 g_array_free (array, TRUE);
2808 * dbus_g_proxy_add_signal:
2809 * @proxy: the proxy for a remote interface
2810 * @signal_name: the name of the signal
2811 * @first_type: the first argument type, or G_TYPE_INVALID if none
2813 * Specifies the argument signature of a signal;.only necessary
2814 * if the remote object does not support introspection. The arguments
2815 * specified are the GLib types expected.
2818 dbus_g_proxy_add_signal (DBusGProxy *proxy,
2819 const char *signal_name,
2828 DBusGProxyPrivate *priv;
2830 g_return_if_fail (DBUS_IS_G_PROXY (proxy));
2831 g_return_if_fail (!DBUS_G_PROXY_DESTROYED (proxy));
2832 g_return_if_fail (signal_name != NULL);
2834 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2836 name = create_signal_name (priv->interface, signal_name);
2838 q = g_quark_from_string (name);
2840 g_return_if_fail (g_datalist_id_get_data (&priv->signal_signatures, q) == NULL);
2842 gtypesig = g_array_new (FALSE, TRUE, sizeof (GType));
2844 va_start (args, first_type);
2846 while (gtype != G_TYPE_INVALID)
2848 g_array_append_val (gtypesig, gtype);
2849 gtype = va_arg (args, GType);
2853 #ifndef G_DISABLE_CHECKS
2854 if (_dbus_gobject_lookup_marshaller (G_TYPE_NONE, gtypesig->len, (const GType*) gtypesig->data) == NULL)
2855 g_warning ("No marshaller for signature of signal '%s'", signal_name);
2859 g_datalist_id_set_data_full (&priv->signal_signatures,
2867 * dbus_g_proxy_connect_signal:
2868 * @proxy: a proxy for a remote interface
2869 * @signal_name: the DBus signal name to listen for
2870 * @handler: the handler to connect
2871 * @data: data to pass to handler
2872 * @free_data_func: callback function to destroy data
2874 * Connect a signal handler to a proxy for a remote interface. When
2875 * the remote interface emits the specified signal, the proxy will
2876 * emit a corresponding GLib signal.
2879 dbus_g_proxy_connect_signal (DBusGProxy *proxy,
2880 const char *signal_name,
2883 GClosureNotify free_data_func)
2888 DBusGProxyPrivate *priv;
2890 g_return_if_fail (DBUS_IS_G_PROXY (proxy));
2891 g_return_if_fail (!DBUS_G_PROXY_DESTROYED (proxy));
2892 g_return_if_fail (signal_name != NULL);
2893 g_return_if_fail (handler != NULL);
2895 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2896 name = create_signal_name (priv->interface, signal_name);
2898 q = g_quark_try_string (name);
2900 #ifndef G_DISABLE_CHECKS
2901 if (q == 0 || g_datalist_id_get_data (&priv->signal_signatures, q) == NULL)
2903 g_warning ("Must add the signal '%s' with dbus_g_proxy_add_signal() prior to connecting to it\n", name);
2909 closure = g_cclosure_new (G_CALLBACK (handler), data, free_data_func);
2911 g_signal_connect_closure_by_id (G_OBJECT (proxy),
2920 * dbus_g_proxy_disconnect_signal:
2921 * @proxy: a proxy for a remote interface
2922 * @signal_name: the DBus signal name to disconnect
2923 * @handler: the handler to disconnect
2924 * @data: the data that was registered with handler
2926 * Disconnect all signal handlers from a proxy that match the given
2930 dbus_g_proxy_disconnect_signal (DBusGProxy *proxy,
2931 const char *signal_name,
2937 DBusGProxyPrivate *priv;
2939 g_return_if_fail (DBUS_IS_G_PROXY (proxy));
2940 g_return_if_fail (!DBUS_G_PROXY_DESTROYED (proxy));
2941 g_return_if_fail (signal_name != NULL);
2942 g_return_if_fail (handler != NULL);
2944 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2945 name = create_signal_name (priv->interface, signal_name);
2947 q = g_quark_try_string (name);
2951 g_signal_handlers_disconnect_matched (G_OBJECT (proxy),
2952 G_SIGNAL_MATCH_DETAIL |
2953 G_SIGNAL_MATCH_FUNC |
2954 G_SIGNAL_MATCH_DATA,
2958 G_CALLBACK (handler), data);
2962 g_warning ("Attempt to disconnect from signal '%s' which is not registered\n",
2970 * dbus_g_proxy_set_default_timeout:
2971 * @proxy: a proxy for a remote interface
2972 * @timeout: specify the timeout in milliseconds
2974 * Sets the default timeout to use for a proxy. This timeout will be
2975 * used in calls where the timeout is not specified.
2977 * This is useful for long-running operations that takes longer than
2978 * the default timeout (which is a on the order of magnitude of tens
2979 * of seconds). For some applications, consider using a pattern where
2980 * the method returns once the operation is underway
2981 * (e.g. immediately) and emits a signal when the operation terminates
2982 * (though beware of leaking information with/in the signal return value).
2987 dbus_g_proxy_set_default_timeout (DBusGProxy *proxy,
2990 DBusGProxyPrivate *priv;
2992 g_return_if_fail (DBUS_IS_G_PROXY (proxy));
2993 g_return_if_fail (!DBUS_G_PROXY_DESTROYED (proxy));
2995 priv = DBUS_G_PROXY_GET_PRIVATE(proxy);
2996 priv->default_timeout = timeout;
3000 /** @} End of DBusGLib public */
3002 #ifdef DBUS_BUILD_TESTS
3005 * @ingroup DBusGLibInternals
3006 * Unit test for GLib proxy functions
3007 * Returns: #TRUE on success.
3010 _dbus_g_proxy_test (void)
3017 #endif /* DBUS_BUILD_TESTS */