1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2010 Red Hat, Inc.
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.
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.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
23 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
24 #error "Only <gio/gio.h> can be included directly."
27 #ifndef __G_DBUS_CONNECTION_H__
28 #define __G_DBUS_CONNECTION_H__
30 #include <gio/giotypes.h>
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))
38 GType g_dbus_connection_get_type (void) G_GNUC_CONST;
40 /* ---------------------------------------------------------------------------------------------------- */
42 void g_bus_get (GBusType bus_type,
43 GCancellable *cancellable,
44 GAsyncReadyCallback callback,
46 GDBusConnection *g_bus_get_finish (GAsyncResult *res,
48 GDBusConnection *g_bus_get_sync (GBusType bus_type,
49 GCancellable *cancellable,
52 /* ---------------------------------------------------------------------------------------------------- */
54 void g_dbus_connection_new (GIOStream *stream,
56 GDBusConnectionFlags flags,
57 GDBusAuthObserver *observer,
58 GCancellable *cancellable,
59 GAsyncReadyCallback callback,
61 GDBusConnection *g_dbus_connection_new_finish (GAsyncResult *res,
63 GDBusConnection *g_dbus_connection_new_sync (GIOStream *stream,
65 GDBusConnectionFlags flags,
66 GDBusAuthObserver *observer,
67 GCancellable *cancellable,
70 void g_dbus_connection_new_for_address (const gchar *address,
71 GDBusConnectionFlags flags,
72 GDBusAuthObserver *observer,
73 GCancellable *cancellable,
74 GAsyncReadyCallback callback,
76 GDBusConnection *g_dbus_connection_new_for_address_finish (GAsyncResult *res,
78 GDBusConnection *g_dbus_connection_new_for_address_sync (const gchar *address,
79 GDBusConnectionFlags flags,
80 GDBusAuthObserver *observer,
81 GCancellable *cancellable,
84 /* ---------------------------------------------------------------------------------------------------- */
86 void g_dbus_connection_start_message_processing (GDBusConnection *connection);
87 gboolean g_dbus_connection_is_closed (GDBusConnection *connection);
88 GIOStream *g_dbus_connection_get_stream (GDBusConnection *connection);
89 const gchar *g_dbus_connection_get_guid (GDBusConnection *connection);
90 const gchar *g_dbus_connection_get_unique_name (GDBusConnection *connection);
91 GCredentials *g_dbus_connection_get_peer_credentials (GDBusConnection *connection);
92 gboolean g_dbus_connection_get_exit_on_close (GDBusConnection *connection);
93 void g_dbus_connection_set_exit_on_close (GDBusConnection *connection,
94 gboolean exit_on_close);
95 GDBusCapabilityFlags g_dbus_connection_get_capabilities (GDBusConnection *connection);
97 /* ---------------------------------------------------------------------------------------------------- */
99 void g_dbus_connection_close (GDBusConnection *connection,
100 GCancellable *cancellable,
101 GAsyncReadyCallback callback,
103 gboolean g_dbus_connection_close_finish (GDBusConnection *connection,
106 gboolean g_dbus_connection_close_sync (GDBusConnection *connection,
107 GCancellable *cancellable,
110 /* ---------------------------------------------------------------------------------------------------- */
112 void g_dbus_connection_flush (GDBusConnection *connection,
113 GCancellable *cancellable,
114 GAsyncReadyCallback callback,
116 gboolean g_dbus_connection_flush_finish (GDBusConnection *connection,
119 gboolean g_dbus_connection_flush_sync (GDBusConnection *connection,
120 GCancellable *cancellable,
123 /* ---------------------------------------------------------------------------------------------------- */
125 gboolean g_dbus_connection_send_message (GDBusConnection *connection,
126 GDBusMessage *message,
127 volatile guint32 *out_serial,
129 void g_dbus_connection_send_message_with_reply (GDBusConnection *connection,
130 GDBusMessage *message,
132 volatile guint32 *out_serial,
133 GCancellable *cancellable,
134 GAsyncReadyCallback callback,
136 GDBusMessage *g_dbus_connection_send_message_with_reply_finish (GDBusConnection *connection,
139 GDBusMessage *g_dbus_connection_send_message_with_reply_sync (GDBusConnection *connection,
140 GDBusMessage *message,
142 volatile guint32 *out_serial,
143 GCancellable *cancellable,
146 /* ---------------------------------------------------------------------------------------------------- */
148 gboolean g_dbus_connection_emit_signal (GDBusConnection *connection,
149 const gchar *destination_bus_name,
150 const gchar *object_path,
151 const gchar *interface_name,
152 const gchar *signal_name,
153 GVariant *parameters,
155 void g_dbus_connection_call (GDBusConnection *connection,
156 const gchar *bus_name,
157 const gchar *object_path,
158 const gchar *interface_name,
159 const gchar *method_name,
160 GVariant *parameters,
161 const GVariantType *reply_type,
162 GDBusCallFlags flags,
164 GCancellable *cancellable,
165 GAsyncReadyCallback callback,
167 GVariant *g_dbus_connection_call_finish (GDBusConnection *connection,
170 GVariant *g_dbus_connection_call_sync (GDBusConnection *connection,
171 const gchar *bus_name,
172 const gchar *object_path,
173 const gchar *interface_name,
174 const gchar *method_name,
175 GVariant *parameters,
176 const GVariantType *reply_type,
177 GDBusCallFlags flags,
179 GCancellable *cancellable,
182 /* ---------------------------------------------------------------------------------------------------- */
186 * GDBusInterfaceMethodCallFunc:
187 * @connection: A #GDBusConnection.
188 * @sender: The unique bus name of the remote caller.
189 * @object_path: The object path that the method was invoked on.
190 * @interface_name: The D-Bus interface name the method was invoked on.
191 * @method_name: The name of the method that was invoked.
192 * @parameters: A #GVariant tuple with parameters.
193 * @invocation: A #GDBusMethodInvocation object that can be used to return a value or error.
194 * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
196 * The type of the @method_call function in #GDBusInterfaceVTable.
200 typedef void (*GDBusInterfaceMethodCallFunc) (GDBusConnection *connection,
202 const gchar *object_path,
203 const gchar *interface_name,
204 const gchar *method_name,
205 GVariant *parameters,
206 GDBusMethodInvocation *invocation,
210 * GDBusInterfaceGetPropertyFunc:
211 * @connection: A #GDBusConnection.
212 * @sender: The unique bus name of the remote caller.
213 * @object_path: The object path that the method was invoked on.
214 * @interface_name: The D-Bus interface name for the property.
215 * @property_name: The name of the property to get the value of.
216 * @error: Return location for error.
217 * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
219 * The type of the @get_property function in #GDBusInterfaceVTable.
221 * Returns: A newly-allocated #GVariant with the value for @property_name or %NULL if @error is set.
225 typedef GVariant *(*GDBusInterfaceGetPropertyFunc) (GDBusConnection *connection,
227 const gchar *object_path,
228 const gchar *interface_name,
229 const gchar *property_name,
234 * GDBusInterfaceSetPropertyFunc:
235 * @connection: A #GDBusConnection.
236 * @sender: The unique bus name of the remote caller.
237 * @object_path: The object path that the method was invoked on.
238 * @interface_name: The D-Bus interface name for the property.
239 * @property_name: The name of the property to get the value of.
240 * @value: The value to set the property to.
241 * @error: Return location for error.
242 * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
244 * The type of the @set_property function in #GDBusInterfaceVTable.
246 * Returns: %TRUE if the property was set to @value, %FALSE if @error is set.
250 typedef gboolean (*GDBusInterfaceSetPropertyFunc) (GDBusConnection *connection,
252 const gchar *object_path,
253 const gchar *interface_name,
254 const gchar *property_name,
260 * GDBusInterfaceVTable:
261 * @method_call: Function for handling incoming method calls.
262 * @get_property: Function for getting a property.
263 * @set_property: Function for setting a property.
265 * Virtual table for handling properties and method calls for a D-Bus
268 * If you want to handle getting/setting D-Bus properties asynchronously, simply
269 * register an object with the <literal>org.freedesktop.DBus.Properties</literal>
270 * D-Bus interface using g_dbus_connection_register_object().
274 struct _GDBusInterfaceVTable
276 GDBusInterfaceMethodCallFunc method_call;
277 GDBusInterfaceGetPropertyFunc get_property;
278 GDBusInterfaceSetPropertyFunc set_property;
281 /* Padding for future expansion - also remember to update
282 * gdbusconnection.c:_g_dbus_interface_vtable_copy() when
288 guint g_dbus_connection_register_object (GDBusConnection *connection,
289 const gchar *object_path,
290 const GDBusInterfaceInfo *interface_info,
291 const GDBusInterfaceVTable *vtable,
293 GDestroyNotify user_data_free_func,
295 gboolean g_dbus_connection_unregister_object (GDBusConnection *connection,
296 guint registration_id);
298 /* ---------------------------------------------------------------------------------------------------- */
301 * GDBusSubtreeEnumerateFunc:
302 * @connection: A #GDBusConnection.
303 * @sender: The unique bus name of the remote caller.
304 * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
305 * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
307 * The type of the @enumerate function in #GDBusSubtreeVTable.
309 * This function is called when generating introspection data and also
310 * when preparing to dispatch incoming messages in the event that the
311 * %G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES flag is not
312 * specified (ie: to verify that the object path is valid).
314 * Hierarchies are not supported; the items that you return should not
315 * contain the '/' character.
317 * The return value will be freed with g_strfreev().
319 * Returns: A newly allocated array of strings for node names that are children of @object_path.
323 typedef gchar** (*GDBusSubtreeEnumerateFunc) (GDBusConnection *connection,
325 const gchar *object_path,
329 * GDBusSubtreeIntrospectFunc:
330 * @connection: A #GDBusConnection.
331 * @sender: The unique bus name of the remote caller.
332 * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
333 * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
334 * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
336 * The type of the @introspect function in #GDBusSubtreeVTable.
338 * Subtrees are flat. @node, if non-%NULL, is always exactly one
339 * segment of the object path (ie: it never contains a slash).
341 * This function should return %NULL to indicate that there is no object
344 * If this function returns non-%NULL, the return value is expected to
345 * be a %NULL-terminated array of pointers to #GDBusInterfaceInfo
346 * structures describing the interfaces implemented by @node. This
347 * array will have g_dbus_interface_info_unref() called on each item
348 * before being freed with g_free().
350 * The difference between returning %NULL and an array containing zero
351 * items is that the standard DBus interfaces will returned to the
352 * remote introspector in the empty array case, but not in the %NULL
355 * Returns: A %NULL-terminated array of pointers to #GDBusInterfaceInfo, or %NULL.
359 typedef GDBusInterfaceInfo ** (*GDBusSubtreeIntrospectFunc) (GDBusConnection *connection,
361 const gchar *object_path,
366 * GDBusSubtreeDispatchFunc:
367 * @connection: A #GDBusConnection.
368 * @sender: The unique bus name of the remote caller.
369 * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
370 * @interface_name: The D-Bus interface name that the method call or property access is for.
371 * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
372 * @out_user_data: Return location for user data to pass to functions in the returned #GDBusInterfaceVTable (never %NULL).
373 * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
375 * The type of the @dispatch function in #GDBusSubtreeVTable.
377 * Subtrees are flat. @node, if non-%NULL, is always exactly one
378 * segment of the object path (ie: it never contains a slash).
380 * Returns: A #GDBusInterfaceVTable or %NULL if you don't want to handle the methods.
384 typedef const GDBusInterfaceVTable * (*GDBusSubtreeDispatchFunc) (GDBusConnection *connection,
386 const gchar *object_path,
387 const gchar *interface_name,
389 gpointer *out_user_data,
393 * GDBusSubtreeVTable:
394 * @enumerate: Function for enumerating child nodes.
395 * @introspect: Function for introspecting a child node.
396 * @dispatch: Function for dispatching a remote call on a child node.
398 * Virtual table for handling subtrees registered with g_dbus_connection_register_subtree().
402 struct _GDBusSubtreeVTable
404 GDBusSubtreeEnumerateFunc enumerate;
405 GDBusSubtreeIntrospectFunc introspect;
406 GDBusSubtreeDispatchFunc dispatch;
409 /* Padding for future expansion - also remember to update
410 * gdbusconnection.c:_g_dbus_subtree_vtable_copy() when
416 guint g_dbus_connection_register_subtree (GDBusConnection *connection,
417 const gchar *object_path,
418 const GDBusSubtreeVTable *vtable,
419 GDBusSubtreeFlags flags,
421 GDestroyNotify user_data_free_func,
423 gboolean g_dbus_connection_unregister_subtree (GDBusConnection *connection,
424 guint registration_id);
426 /* ---------------------------------------------------------------------------------------------------- */
429 * GDBusSignalCallback:
430 * @connection: A #GDBusConnection.
431 * @sender_name: The unique bus name of the sender of the signal.
432 * @object_path: The object path that the signal was emitted on.
433 * @interface_name: The name of the interface.
434 * @signal_name: The name of the signal.
435 * @parameters: A #GVariant tuple with parameters for the signal.
436 * @user_data: User data passed when subscribing to the signal.
438 * Signature for callback function used in g_dbus_connection_signal_subscribe().
442 typedef void (*GDBusSignalCallback) (GDBusConnection *connection,
443 const gchar *sender_name,
444 const gchar *object_path,
445 const gchar *interface_name,
446 const gchar *signal_name,
447 GVariant *parameters,
450 guint g_dbus_connection_signal_subscribe (GDBusConnection *connection,
452 const gchar *interface_name,
454 const gchar *object_path,
456 GDBusSignalCallback callback,
458 GDestroyNotify user_data_free_func);
459 void g_dbus_connection_signal_unsubscribe (GDBusConnection *connection,
460 guint subscription_id);
462 /* ---------------------------------------------------------------------------------------------------- */
465 * GDBusMessageFilterFunction:
466 * @connection: A #GDBusConnection.
467 * @message: A #GDBusMessage.
468 * @incoming: %TRUE if it is a message received from the other peer, %FALSE if it is
469 * a message to be sent to the other peer.
470 * @user_data: User data passed when adding the filter.
472 * Signature for function used in g_dbus_connection_add_filter().
474 * Returns: %TRUE if the filter handled @message, %FALSE to let other
479 typedef gboolean (*GDBusMessageFilterFunction) (GDBusConnection *connection,
480 GDBusMessage *message,
484 guint g_dbus_connection_add_filter (GDBusConnection *connection,
485 GDBusMessageFilterFunction filter_function,
487 GDestroyNotify user_data_free_func);
489 void g_dbus_connection_remove_filter (GDBusConnection *connection,
492 /* ---------------------------------------------------------------------------------------------------- */
497 #endif /* __G_DBUS_CONNECTION_H__ */