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