8ffd094932129a30bbf1e0be5d4711e50e57c2c3
[platform/upstream/glib.git] / gio / gdbusconnection.h
1 /* GDBus - GLib D-Bus Library
2  *
3  * Copyright (C) 2008-2010 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17  *
18  * Author: David Zeuthen <davidz@redhat.com>
19  */
20
21 #ifndef __G_DBUS_CONNECTION_H__
22 #define __G_DBUS_CONNECTION_H__
23
24 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
25 #error "Only <gio/gio.h> can be included directly."
26 #endif
27
28 #include <gio/giotypes.h>
29
30 G_BEGIN_DECLS
31
32 #define G_TYPE_DBUS_CONNECTION         (g_dbus_connection_get_type ())
33 #define G_DBUS_CONNECTION(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_DBUS_CONNECTION, GDBusConnection))
34 #define G_IS_DBUS_CONNECTION(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_DBUS_CONNECTION))
35
36 GLIB_AVAILABLE_IN_ALL
37 GType            g_dbus_connection_get_type                   (void) G_GNUC_CONST;
38
39 /* ---------------------------------------------------------------------------------------------------- */
40
41 GLIB_AVAILABLE_IN_ALL
42 void              g_bus_get                    (GBusType             bus_type,
43                                                 GCancellable        *cancellable,
44                                                 GAsyncReadyCallback  callback,
45                                                 gpointer             user_data);
46 GLIB_AVAILABLE_IN_ALL
47 GDBusConnection  *g_bus_get_finish             (GAsyncResult        *res,
48                                                 GError             **error);
49 GLIB_AVAILABLE_IN_ALL
50 GDBusConnection  *g_bus_get_sync               (GBusType            bus_type,
51                                                 GCancellable       *cancellable,
52                                                 GError            **error);
53
54 /* ---------------------------------------------------------------------------------------------------- */
55
56 GLIB_AVAILABLE_IN_ALL
57 void             g_dbus_connection_new                        (GIOStream              *stream,
58                                                                const gchar            *guid,
59                                                                GDBusConnectionFlags    flags,
60                                                                GDBusAuthObserver      *observer,
61                                                                GCancellable           *cancellable,
62                                                                GAsyncReadyCallback     callback,
63                                                                gpointer                user_data);
64 GLIB_AVAILABLE_IN_ALL
65 GDBusConnection *g_dbus_connection_new_finish                 (GAsyncResult           *res,
66                                                                GError                **error);
67 GLIB_AVAILABLE_IN_ALL
68 GDBusConnection *g_dbus_connection_new_sync                   (GIOStream              *stream,
69                                                                const gchar            *guid,
70                                                                GDBusConnectionFlags    flags,
71                                                                GDBusAuthObserver      *observer,
72                                                                GCancellable           *cancellable,
73                                                                GError                **error);
74
75 GLIB_AVAILABLE_IN_ALL
76 void             g_dbus_connection_new_for_address            (const gchar            *address,
77                                                                GDBusConnectionFlags    flags,
78                                                                GDBusAuthObserver      *observer,
79                                                                GCancellable           *cancellable,
80                                                                GAsyncReadyCallback     callback,
81                                                                gpointer                user_data);
82 GLIB_AVAILABLE_IN_ALL
83 GDBusConnection *g_dbus_connection_new_for_address_finish     (GAsyncResult           *res,
84                                                                GError                **error);
85 GLIB_AVAILABLE_IN_ALL
86 GDBusConnection *g_dbus_connection_new_for_address_sync       (const gchar            *address,
87                                                                GDBusConnectionFlags    flags,
88                                                                GDBusAuthObserver      *observer,
89                                                                GCancellable           *cancellable,
90                                                                GError                **error);
91
92 /* ---------------------------------------------------------------------------------------------------- */
93
94 GLIB_AVAILABLE_IN_2_40
95 gchar     *g_dbus_get_bus_id                                  (GDBusConnection    *connection,
96                                                                gint                timeout_msec,
97                                                                GError            **error);
98 GLIB_AVAILABLE_IN_2_40
99 gchar    **g_dbus_get_list_names                              (GDBusConnection    *connection,
100                                                                gint                timeout_msec,
101                                                                GError            **error);
102 GLIB_AVAILABLE_IN_2_40
103 gchar    **g_dbus_get_list_activatable_names                  (GDBusConnection    *connection,
104                                                                gint                timeout_msec,
105                                                                GError            **error);
106 GLIB_AVAILABLE_IN_2_40
107 gchar    **g_dbus_get_list_queued_owners                      (GDBusConnection    *connection,
108                                                                const gchar        *name,
109                                                                gint                timeout_msec,
110                                                                GError            **error);
111 GLIB_AVAILABLE_IN_2_40
112 gchar     *g_dbus_get_name_owner                              (GDBusConnection    *connection,
113                                                                const gchar        *name,
114                                                                gint                timeout_msec,
115                                                                GError            **error);
116 GLIB_AVAILABLE_IN_2_40
117 gboolean   g_dbus_name_has_owner                              (GDBusConnection    *connection,
118                                                                const gchar        *name,
119                                                                gint                timeout_msec,
120                                                                GError            **error);
121 GLIB_AVAILABLE_IN_2_40
122 guint32    g_dbus_get_connection_pid                          (GDBusConnection    *connection,
123                                                                const gchar        *name,
124                                                                gint                timeout_msec,
125                                                                GError            **error);
126 GLIB_AVAILABLE_IN_2_40
127 guint32    g_dbus_get_connection_uid                          (GDBusConnection    *connection,
128                                                                const gchar        *name,
129                                                                gint                timeout_msec,
130                                                                GError            **error);
131
132 /* ---------------------------------------------------------------------------------------------------- */
133
134 GLIB_AVAILABLE_IN_ALL
135 void             g_dbus_connection_start_message_processing   (GDBusConnection    *connection);
136 GLIB_AVAILABLE_IN_ALL
137 gboolean         g_dbus_connection_is_closed                  (GDBusConnection    *connection);
138 GLIB_AVAILABLE_IN_ALL
139 GIOStream       *g_dbus_connection_get_stream                 (GDBusConnection    *connection);
140 GLIB_AVAILABLE_IN_ALL
141 const gchar     *g_dbus_connection_get_guid                   (GDBusConnection    *connection);
142 GLIB_AVAILABLE_IN_ALL
143 const gchar     *g_dbus_connection_get_unique_name            (GDBusConnection    *connection);
144 GLIB_AVAILABLE_IN_ALL
145 GCredentials    *g_dbus_connection_get_peer_credentials       (GDBusConnection    *connection);
146
147 GLIB_AVAILABLE_IN_2_34
148 guint32          g_dbus_connection_get_last_serial            (GDBusConnection    *connection);
149
150 GLIB_AVAILABLE_IN_ALL
151 gboolean         g_dbus_connection_get_exit_on_close          (GDBusConnection    *connection);
152 GLIB_AVAILABLE_IN_ALL
153 void             g_dbus_connection_set_exit_on_close          (GDBusConnection    *connection,
154                                                                gboolean            exit_on_close);
155 GLIB_AVAILABLE_IN_ALL
156 GDBusCapabilityFlags  g_dbus_connection_get_capabilities      (GDBusConnection    *connection);
157
158 /* ---------------------------------------------------------------------------------------------------- */
159
160 GLIB_AVAILABLE_IN_ALL
161 void             g_dbus_connection_close                          (GDBusConnection     *connection,
162                                                                    GCancellable        *cancellable,
163                                                                    GAsyncReadyCallback  callback,
164                                                                    gpointer             user_data);
165 GLIB_AVAILABLE_IN_ALL
166 gboolean         g_dbus_connection_close_finish                   (GDBusConnection     *connection,
167                                                                    GAsyncResult        *res,
168                                                                    GError             **error);
169 GLIB_AVAILABLE_IN_ALL
170 gboolean         g_dbus_connection_close_sync                     (GDBusConnection     *connection,
171                                                                    GCancellable        *cancellable,
172                                                                    GError             **error);
173
174 /* ---------------------------------------------------------------------------------------------------- */
175
176 GLIB_AVAILABLE_IN_ALL
177 void             g_dbus_connection_flush                          (GDBusConnection     *connection,
178                                                                    GCancellable        *cancellable,
179                                                                    GAsyncReadyCallback  callback,
180                                                                    gpointer             user_data);
181 GLIB_AVAILABLE_IN_ALL
182 gboolean         g_dbus_connection_flush_finish                   (GDBusConnection     *connection,
183                                                                    GAsyncResult        *res,
184                                                                    GError             **error);
185 GLIB_AVAILABLE_IN_ALL
186 gboolean         g_dbus_connection_flush_sync                     (GDBusConnection     *connection,
187                                                                    GCancellable        *cancellable,
188                                                                    GError             **error);
189
190 /* ---------------------------------------------------------------------------------------------------- */
191
192 GLIB_AVAILABLE_IN_ALL
193 gboolean         g_dbus_connection_send_message                   (GDBusConnection     *connection,
194                                                                    GDBusMessage        *message,
195                                                                    GDBusSendMessageFlags flags,
196                                                                    volatile guint32    *out_serial,
197                                                                    GError             **error);
198 GLIB_AVAILABLE_IN_ALL
199 void             g_dbus_connection_send_message_with_reply        (GDBusConnection     *connection,
200                                                                    GDBusMessage        *message,
201                                                                    GDBusSendMessageFlags flags,
202                                                                    gint                 timeout_msec,
203                                                                    volatile guint32    *out_serial,
204                                                                    GCancellable        *cancellable,
205                                                                    GAsyncReadyCallback  callback,
206                                                                    gpointer             user_data);
207 GLIB_AVAILABLE_IN_ALL
208 GDBusMessage    *g_dbus_connection_send_message_with_reply_finish (GDBusConnection     *connection,
209                                                                    GAsyncResult        *res,
210                                                                    GError             **error);
211 GLIB_AVAILABLE_IN_ALL
212 GDBusMessage    *g_dbus_connection_send_message_with_reply_sync   (GDBusConnection     *connection,
213                                                                    GDBusMessage        *message,
214                                                                    GDBusSendMessageFlags flags,
215                                                                    gint                 timeout_msec,
216                                                                    volatile guint32    *out_serial,
217                                                                    GCancellable        *cancellable,
218                                                                    GError             **error);
219
220 /* ---------------------------------------------------------------------------------------------------- */
221
222 GLIB_AVAILABLE_IN_ALL
223 gboolean  g_dbus_connection_emit_signal                       (GDBusConnection    *connection,
224                                                                const gchar        *destination_bus_name,
225                                                                const gchar        *object_path,
226                                                                const gchar        *interface_name,
227                                                                const gchar        *signal_name,
228                                                                GVariant           *parameters,
229                                                                GError            **error);
230 GLIB_AVAILABLE_IN_ALL
231 void      g_dbus_connection_call                              (GDBusConnection    *connection,
232                                                                const gchar        *bus_name,
233                                                                const gchar        *object_path,
234                                                                const gchar        *interface_name,
235                                                                const gchar        *method_name,
236                                                                GVariant           *parameters,
237                                                                const GVariantType *reply_type,
238                                                                GDBusCallFlags      flags,
239                                                                gint                timeout_msec,
240                                                                GCancellable       *cancellable,
241                                                                GAsyncReadyCallback callback,
242                                                                gpointer            user_data);
243 GLIB_AVAILABLE_IN_ALL
244 GVariant *g_dbus_connection_call_finish                       (GDBusConnection    *connection,
245                                                                GAsyncResult       *res,
246                                                                GError            **error);
247 GLIB_AVAILABLE_IN_ALL
248 GVariant *g_dbus_connection_call_sync                         (GDBusConnection    *connection,
249                                                                const gchar        *bus_name,
250                                                                const gchar        *object_path,
251                                                                const gchar        *interface_name,
252                                                                const gchar        *method_name,
253                                                                GVariant           *parameters,
254                                                                const GVariantType *reply_type,
255                                                                GDBusCallFlags      flags,
256                                                                gint                timeout_msec,
257                                                                GCancellable       *cancellable,
258                                                                GError            **error);
259 GLIB_AVAILABLE_IN_2_30
260 void      g_dbus_connection_call_with_unix_fd_list            (GDBusConnection    *connection,
261                                                                const gchar        *bus_name,
262                                                                const gchar        *object_path,
263                                                                const gchar        *interface_name,
264                                                                const gchar        *method_name,
265                                                                GVariant           *parameters,
266                                                                const GVariantType *reply_type,
267                                                                GDBusCallFlags      flags,
268                                                                gint                timeout_msec,
269                                                                GUnixFDList        *fd_list,
270                                                                GCancellable       *cancellable,
271                                                                GAsyncReadyCallback callback,
272                                                                gpointer            user_data);
273 GLIB_AVAILABLE_IN_2_30
274 GVariant *g_dbus_connection_call_with_unix_fd_list_finish     (GDBusConnection    *connection,
275                                                                GUnixFDList       **out_fd_list,
276                                                                GAsyncResult       *res,
277                                                                GError            **error);
278 GLIB_AVAILABLE_IN_2_30
279 GVariant *g_dbus_connection_call_with_unix_fd_list_sync       (GDBusConnection    *connection,
280                                                                const gchar        *bus_name,
281                                                                const gchar        *object_path,
282                                                                const gchar        *interface_name,
283                                                                const gchar        *method_name,
284                                                                GVariant           *parameters,
285                                                                const GVariantType *reply_type,
286                                                                GDBusCallFlags      flags,
287                                                                gint                timeout_msec,
288                                                                GUnixFDList        *fd_list,
289                                                                GUnixFDList       **out_fd_list,
290                                                                GCancellable       *cancellable,
291                                                                GError            **error);
292
293 /* ---------------------------------------------------------------------------------------------------- */
294
295
296 /**
297  * GDBusInterfaceMethodCallFunc:
298  * @connection: A #GDBusConnection.
299  * @sender: The unique bus name of the remote caller.
300  * @object_path: The object path that the method was invoked on.
301  * @interface_name: The D-Bus interface name the method was invoked on.
302  * @method_name: The name of the method that was invoked.
303  * @parameters: A #GVariant tuple with parameters.
304  * @invocation: (transfer full): A #GDBusMethodInvocation object that must be used to return a value or error.
305  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
306  *
307  * The type of the @method_call function in #GDBusInterfaceVTable.
308  *
309  * Since: 2.26
310  */
311 typedef void (*GDBusInterfaceMethodCallFunc) (GDBusConnection       *connection,
312                                               const gchar           *sender,
313                                               const gchar           *object_path,
314                                               const gchar           *interface_name,
315                                               const gchar           *method_name,
316                                               GVariant              *parameters,
317                                               GDBusMethodInvocation *invocation,
318                                               gpointer               user_data);
319
320 /**
321  * GDBusInterfaceGetPropertyFunc:
322  * @connection: A #GDBusConnection.
323  * @sender: The unique bus name of the remote caller.
324  * @object_path: The object path that the method was invoked on.
325  * @interface_name: The D-Bus interface name for the property.
326  * @property_name: The name of the property to get the value of.
327  * @error: Return location for error.
328  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
329  *
330  * The type of the @get_property function in #GDBusInterfaceVTable.
331  *
332  * Returns: A #GVariant with the value for @property_name or %NULL if
333  *     @error is set. If the returned #GVariant is floating, it is
334  *     consumed - otherwise its reference count is decreased by one.
335  *
336  * Since: 2.26
337  */
338 typedef GVariant *(*GDBusInterfaceGetPropertyFunc) (GDBusConnection       *connection,
339                                                     const gchar           *sender,
340                                                     const gchar           *object_path,
341                                                     const gchar           *interface_name,
342                                                     const gchar           *property_name,
343                                                     GError               **error,
344                                                     gpointer               user_data);
345
346 /**
347  * GDBusInterfaceSetPropertyFunc:
348  * @connection: A #GDBusConnection.
349  * @sender: The unique bus name of the remote caller.
350  * @object_path: The object path that the method was invoked on.
351  * @interface_name: The D-Bus interface name for the property.
352  * @property_name: The name of the property to get the value of.
353  * @value: The value to set the property to.
354  * @error: Return location for error.
355  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
356  *
357  * The type of the @set_property function in #GDBusInterfaceVTable.
358  *
359  * Returns: %TRUE if the property was set to @value, %FALSE if @error is set.
360  *
361  * Since: 2.26
362  */
363 typedef gboolean  (*GDBusInterfaceSetPropertyFunc) (GDBusConnection       *connection,
364                                                     const gchar           *sender,
365                                                     const gchar           *object_path,
366                                                     const gchar           *interface_name,
367                                                     const gchar           *property_name,
368                                                     GVariant              *value,
369                                                     GError               **error,
370                                                     gpointer               user_data);
371
372 /**
373  * GDBusInterfaceVTable:
374  * @method_call: Function for handling incoming method calls.
375  * @get_property: Function for getting a property.
376  * @set_property: Function for setting a property.
377  *
378  * Virtual table for handling properties and method calls for a D-Bus
379  * interface.
380  *
381  * Since 2.38, if you want to handle getting/setting D-Bus properties
382  * asynchronously, give %NULL as your get_property() or set_property()
383  * function. The D-Bus call will be directed to your @method_call function,
384  * with the provided @interface_name set to "org.freedesktop.DBus.Properties".
385  *
386  * Ownership of the #GDBusMethodInvocation object passed to the
387  * method_call() function is transferred to your handler; you must
388  * call one of the methods of #GDBusMethodInvocation to return a reply
389  * (possibly empty), or an error. These functions also take ownership
390  * of the passed-in invocation object, so unless the invocation
391  * object has otherwise been referenced, it will be then be freed.
392  * Calling one of these functions may be done within your
393  * method_call() implementation but it also can be done at a later
394  * point to handle the method asynchronously.
395  *
396  * The usual checks on the validity of the calls is performed. For
397  * `Get` calls, an error is automatically returned if the property does
398  * not exist or the permissions do not allow access. The same checks are
399  * performed for `Set` calls, and the provided value is also checked for
400  * being the correct type.
401  *
402  * For both `Get` and `Set` calls, the #GDBusMethodInvocation
403  * passed to the @method_call handler can be queried with
404  * g_dbus_method_invocation_get_property_info() to get a pointer
405  * to the #GDBusPropertyInfo of the property.
406  *
407  * If you have readable properties specified in your interface info,
408  * you must ensure that you either provide a non-%NULL @get_property()
409  * function or provide implementations of both the `Get` and `GetAll`
410  * methods on org.freedesktop.DBus.Properties interface in your @method_call
411  * function. Note that the required return type of the `Get` call is
412  * `(v)`, not the type of the property. `GetAll` expects a return value
413  * of type `a{sv}`.
414  *
415  * If you have writable properties specified in your interface info,
416  * you must ensure that you either provide a non-%NULL @set_property()
417  * function or provide an implementation of the `Set` call. If implementing
418  * the call, you must return the value of type %G_VARIANT_TYPE_UNIT.
419  *
420  * Since: 2.26
421  */
422 struct _GDBusInterfaceVTable
423 {
424   GDBusInterfaceMethodCallFunc  method_call;
425   GDBusInterfaceGetPropertyFunc get_property;
426   GDBusInterfaceSetPropertyFunc set_property;
427
428   /*< private >*/
429   /* Padding for future expansion - also remember to update
430    * gdbusconnection.c:_g_dbus_interface_vtable_copy() when
431    * changing this.
432    */
433   gpointer padding[8];
434 };
435
436 GLIB_AVAILABLE_IN_ALL
437 guint            g_dbus_connection_register_object            (GDBusConnection            *connection,
438                                                                const gchar                *object_path,
439                                                                GDBusInterfaceInfo         *interface_info,
440                                                                const GDBusInterfaceVTable *vtable,
441                                                                gpointer                    user_data,
442                                                                GDestroyNotify              user_data_free_func,
443                                                                GError                    **error);
444 GLIB_AVAILABLE_IN_ALL
445 gboolean         g_dbus_connection_unregister_object          (GDBusConnection            *connection,
446                                                                guint                       registration_id);
447
448 /* ---------------------------------------------------------------------------------------------------- */
449
450 /**
451  * GDBusSubtreeEnumerateFunc:
452  * @connection: A #GDBusConnection.
453  * @sender: The unique bus name of the remote caller.
454  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
455  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
456  *
457  * The type of the @enumerate function in #GDBusSubtreeVTable.
458  *
459  * This function is called when generating introspection data and also
460  * when preparing to dispatch incoming messages in the event that the
461  * %G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES flag is not
462  * specified (ie: to verify that the object path is valid).
463  *
464  * Hierarchies are not supported; the items that you return should not
465  * contain the '/' character.
466  *
467  * The return value will be freed with g_strfreev().
468  *
469  * Returns: A newly allocated array of strings for node names that are children of @object_path.
470  *
471  * Since: 2.26
472  */
473 typedef gchar** (*GDBusSubtreeEnumerateFunc) (GDBusConnection       *connection,
474                                               const gchar           *sender,
475                                               const gchar           *object_path,
476                                               gpointer               user_data);
477
478 /**
479  * GDBusSubtreeIntrospectFunc:
480  * @connection: A #GDBusConnection.
481  * @sender: The unique bus name of the remote caller.
482  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
483  * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
484  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
485  *
486  * The type of the @introspect function in #GDBusSubtreeVTable.
487  *
488  * Subtrees are flat.  @node, if non-%NULL, is always exactly one
489  * segment of the object path (ie: it never contains a slash).
490  *
491  * This function should return %NULL to indicate that there is no object
492  * at this node.
493  *
494  * If this function returns non-%NULL, the return value is expected to
495  * be a %NULL-terminated array of pointers to #GDBusInterfaceInfo
496  * structures describing the interfaces implemented by @node.  This
497  * array will have g_dbus_interface_info_unref() called on each item
498  * before being freed with g_free().
499  *
500  * The difference between returning %NULL and an array containing zero
501  * items is that the standard DBus interfaces will returned to the
502  * remote introspector in the empty array case, but not in the %NULL
503  * case.
504  *
505  * Returns: A %NULL-terminated array of pointers to #GDBusInterfaceInfo, or %NULL.
506  *
507  * Since: 2.26
508  */
509 typedef GDBusInterfaceInfo ** (*GDBusSubtreeIntrospectFunc) (GDBusConnection       *connection,
510                                                              const gchar           *sender,
511                                                              const gchar           *object_path,
512                                                              const gchar           *node,
513                                                              gpointer               user_data);
514
515 /**
516  * GDBusSubtreeDispatchFunc:
517  * @connection: A #GDBusConnection.
518  * @sender: The unique bus name of the remote caller.
519  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
520  * @interface_name: The D-Bus interface name that the method call or property access is for.
521  * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
522  * @out_user_data: Return location for user data to pass to functions in the returned #GDBusInterfaceVTable (never %NULL).
523  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
524  *
525  * The type of the @dispatch function in #GDBusSubtreeVTable.
526  *
527  * Subtrees are flat.  @node, if non-%NULL, is always exactly one
528  * segment of the object path (ie: it never contains a slash).
529  *
530  * Returns: A #GDBusInterfaceVTable or %NULL if you don't want to handle the methods.
531  *
532  * Since: 2.26
533  */
534 typedef const GDBusInterfaceVTable * (*GDBusSubtreeDispatchFunc) (GDBusConnection             *connection,
535                                                                   const gchar                 *sender,
536                                                                   const gchar                 *object_path,
537                                                                   const gchar                 *interface_name,
538                                                                   const gchar                 *node,
539                                                                   gpointer                    *out_user_data,
540                                                                   gpointer                     user_data);
541
542 /**
543  * GDBusSubtreeVTable:
544  * @enumerate: Function for enumerating child nodes.
545  * @introspect: Function for introspecting a child node.
546  * @dispatch: Function for dispatching a remote call on a child node.
547  *
548  * Virtual table for handling subtrees registered with g_dbus_connection_register_subtree().
549  *
550  * Since: 2.26
551  */
552 struct _GDBusSubtreeVTable
553 {
554   GDBusSubtreeEnumerateFunc  enumerate;
555   GDBusSubtreeIntrospectFunc introspect;
556   GDBusSubtreeDispatchFunc   dispatch;
557
558   /*< private >*/
559   /* Padding for future expansion - also remember to update
560    * gdbusconnection.c:_g_dbus_subtree_vtable_copy() when
561    * changing this.
562    */
563   gpointer padding[8];
564 };
565
566 GLIB_AVAILABLE_IN_ALL
567 guint            g_dbus_connection_register_subtree           (GDBusConnection            *connection,
568                                                                const gchar                *object_path,
569                                                                const GDBusSubtreeVTable   *vtable,
570                                                                GDBusSubtreeFlags           flags,
571                                                                gpointer                    user_data,
572                                                                GDestroyNotify              user_data_free_func,
573                                                                GError                    **error);
574 GLIB_AVAILABLE_IN_ALL
575 gboolean         g_dbus_connection_unregister_subtree         (GDBusConnection            *connection,
576                                                                guint                       registration_id);
577
578 /* ---------------------------------------------------------------------------------------------------- */
579
580 /**
581  * GDBusSignalCallback:
582  * @connection: A #GDBusConnection.
583  * @sender_name: The unique bus name of the sender of the signal.
584  * @object_path: The object path that the signal was emitted on.
585  * @interface_name: The name of the interface.
586  * @signal_name: The name of the signal.
587  * @parameters: A #GVariant tuple with parameters for the signal.
588  * @user_data: User data passed when subscribing to the signal.
589  *
590  * Signature for callback function used in g_dbus_connection_signal_subscribe().
591  *
592  * Since: 2.26
593  */
594 typedef void (*GDBusSignalCallback) (GDBusConnection  *connection,
595                                      const gchar      *sender_name,
596                                      const gchar      *object_path,
597                                      const gchar      *interface_name,
598                                      const gchar      *signal_name,
599                                      GVariant         *parameters,
600                                      gpointer          user_data);
601
602 GLIB_AVAILABLE_IN_ALL
603 guint            g_dbus_connection_signal_subscribe           (GDBusConnection     *connection,
604                                                                const gchar         *sender,
605                                                                const gchar         *interface_name,
606                                                                const gchar         *member,
607                                                                const gchar         *object_path,
608                                                                const gchar         *arg0,
609                                                                GDBusSignalFlags     flags,
610                                                                GDBusSignalCallback  callback,
611                                                                gpointer             user_data,
612                                                                GDestroyNotify       user_data_free_func);
613 GLIB_AVAILABLE_IN_ALL
614 void             g_dbus_connection_signal_unsubscribe         (GDBusConnection     *connection,
615                                                                guint                subscription_id);
616
617 /* ---------------------------------------------------------------------------------------------------- */
618
619 /**
620  * GDBusMessageFilterFunction:
621  * @connection: (transfer none): A #GDBusConnection.
622  * @message: (transfer full): A locked #GDBusMessage that the filter function takes ownership of.
623  * @incoming: %TRUE if it is a message received from the other peer, %FALSE if it is
624  * a message to be sent to the other peer.
625  * @user_data: User data passed when adding the filter.
626  *
627  * Signature for function used in g_dbus_connection_add_filter().
628  *
629  * A filter function is passed a #GDBusMessage and expected to return
630  * a #GDBusMessage too. Passive filter functions that don't modify the
631  * message can simply return the @message object:
632  * |[
633  * static GDBusMessage *
634  * passive_filter (GDBusConnection *connection
635  *                 GDBusMessage    *message,
636  *                 gboolean         incoming,
637  *                 gpointer         user_data)
638  * {
639  *   /<!-- -->* inspect @message *<!-- -->/
640  *   return message;
641  * }
642  * ]|
643  * Filter functions that wants to drop a message can simply return %NULL:
644  * |[
645  * static GDBusMessage *
646  * drop_filter (GDBusConnection *connection
647  *              GDBusMessage    *message,
648  *              gboolean         incoming,
649  *              gpointer         user_data)
650  * {
651  *   if (should_drop_message)
652  *     {
653  *       g_object_unref (message);
654  *       message = NULL;
655  *     }
656  *   return message;
657  * }
658  * ]|
659  * Finally, a filter function may modify a message by copying it:
660  * |[
661  * static GDBusMessage *
662  * modifying_filter (GDBusConnection *connection
663  *                   GDBusMessage    *message,
664  *                   gboolean         incoming,
665  *                   gpointer         user_data)
666  * {
667  *   GDBusMessage *copy;
668  *   GError *error;
669  *
670  *   error = NULL;
671  *   copy = g_dbus_message_copy (message, &error);
672  *   /<!-- -->* handle @error being is set *<!-- -->/
673  *   g_object_unref (message);
674  *
675  *   /<!-- -->* modify @copy *<!-- -->/
676  *
677  *   return copy;
678  * }
679  * ]|
680  * If the returned #GDBusMessage is different from @message and cannot
681  * be sent on @connection (it could use features, such as file
682  * descriptors, not compatible with @connection), then a warning is
683  * logged to <emphasis>standard error</emphasis>. Applications can
684  * check this ahead of time using g_dbus_message_to_blob() passing a
685  * #GDBusCapabilityFlags value obtained from @connection.
686  *
687  * Returns: (transfer full) (allow-none): A #GDBusMessage that will be freed with
688  * g_object_unref() or %NULL to drop the message. Passive filter
689  * functions can simply return the passed @message object.
690  *
691  * Since: 2.26
692  */
693 typedef GDBusMessage *(*GDBusMessageFilterFunction) (GDBusConnection *connection,
694                                                      GDBusMessage    *message,
695                                                      gboolean         incoming,
696                                                      gpointer         user_data);
697
698 GLIB_AVAILABLE_IN_ALL
699 guint g_dbus_connection_add_filter (GDBusConnection            *connection,
700                                     GDBusMessageFilterFunction  filter_function,
701                                     gpointer                    user_data,
702                                     GDestroyNotify              user_data_free_func);
703
704 GLIB_AVAILABLE_IN_ALL
705 void  g_dbus_connection_remove_filter (GDBusConnection    *connection,
706                                        guint               filter_id);
707
708 /* ---------------------------------------------------------------------------------------------------- */
709
710
711 G_END_DECLS
712
713 #endif /* __G_DBUS_CONNECTION_H__ */