GDBus: Add GDBusSendMessageFlags
[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, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: David Zeuthen <davidz@redhat.com>
21  */
22
23 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
24 #error "Only <gio/gio.h> can be included directly."
25 #endif
26
27 #ifndef __G_DBUS_CONNECTION_H__
28 #define __G_DBUS_CONNECTION_H__
29
30 #include <gio/giotypes.h>
31
32 G_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
38 GType            g_dbus_connection_get_type                   (void) G_GNUC_CONST;
39
40 /* ---------------------------------------------------------------------------------------------------- */
41
42 void              g_bus_get                    (GBusType             bus_type,
43                                                 GCancellable        *cancellable,
44                                                 GAsyncReadyCallback  callback,
45                                                 gpointer             user_data);
46 GDBusConnection  *g_bus_get_finish             (GAsyncResult        *res,
47                                                 GError             **error);
48 GDBusConnection  *g_bus_get_sync               (GBusType            bus_type,
49                                                 GCancellable       *cancellable,
50                                                 GError            **error);
51
52 /* ---------------------------------------------------------------------------------------------------- */
53
54 void             g_dbus_connection_new                        (GIOStream              *stream,
55                                                                const gchar            *guid,
56                                                                GDBusConnectionFlags    flags,
57                                                                GDBusAuthObserver      *observer,
58                                                                GCancellable           *cancellable,
59                                                                GAsyncReadyCallback     callback,
60                                                                gpointer                user_data);
61 GDBusConnection *g_dbus_connection_new_finish                 (GAsyncResult           *res,
62                                                                GError                **error);
63 GDBusConnection *g_dbus_connection_new_sync                   (GIOStream              *stream,
64                                                                const gchar            *guid,
65                                                                GDBusConnectionFlags    flags,
66                                                                GDBusAuthObserver      *observer,
67                                                                GCancellable           *cancellable,
68                                                                GError                **error);
69
70 void             g_dbus_connection_new_for_address            (const gchar            *address,
71                                                                GDBusConnectionFlags    flags,
72                                                                GDBusAuthObserver      *observer,
73                                                                GCancellable           *cancellable,
74                                                                GAsyncReadyCallback     callback,
75                                                                gpointer                user_data);
76 GDBusConnection *g_dbus_connection_new_for_address_finish     (GAsyncResult           *res,
77                                                                GError                **error);
78 GDBusConnection *g_dbus_connection_new_for_address_sync       (const gchar            *address,
79                                                                GDBusConnectionFlags    flags,
80                                                                GDBusAuthObserver      *observer,
81                                                                GCancellable           *cancellable,
82                                                                GError                **error);
83
84 /* ---------------------------------------------------------------------------------------------------- */
85
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);
96
97 /* ---------------------------------------------------------------------------------------------------- */
98
99 void             g_dbus_connection_close                          (GDBusConnection     *connection,
100                                                                    GCancellable        *cancellable,
101                                                                    GAsyncReadyCallback  callback,
102                                                                    gpointer             user_data);
103 gboolean         g_dbus_connection_close_finish                   (GDBusConnection     *connection,
104                                                                    GAsyncResult        *res,
105                                                                    GError             **error);
106 gboolean         g_dbus_connection_close_sync                     (GDBusConnection     *connection,
107                                                                    GCancellable        *cancellable,
108                                                                    GError             **error);
109
110 /* ---------------------------------------------------------------------------------------------------- */
111
112 void             g_dbus_connection_flush                          (GDBusConnection     *connection,
113                                                                    GCancellable        *cancellable,
114                                                                    GAsyncReadyCallback  callback,
115                                                                    gpointer             user_data);
116 gboolean         g_dbus_connection_flush_finish                   (GDBusConnection     *connection,
117                                                                    GAsyncResult        *res,
118                                                                    GError             **error);
119 gboolean         g_dbus_connection_flush_sync                     (GDBusConnection     *connection,
120                                                                    GCancellable        *cancellable,
121                                                                    GError             **error);
122
123 /* ---------------------------------------------------------------------------------------------------- */
124
125 gboolean         g_dbus_connection_send_message                   (GDBusConnection     *connection,
126                                                                    GDBusMessage        *message,
127                                                                    GDBusSendMessageFlags flags,
128                                                                    volatile guint32    *out_serial,
129                                                                    GError             **error);
130 void             g_dbus_connection_send_message_with_reply        (GDBusConnection     *connection,
131                                                                    GDBusMessage        *message,
132                                                                    GDBusSendMessageFlags flags,
133                                                                    gint                 timeout_msec,
134                                                                    volatile guint32    *out_serial,
135                                                                    GCancellable        *cancellable,
136                                                                    GAsyncReadyCallback  callback,
137                                                                    gpointer             user_data);
138 GDBusMessage    *g_dbus_connection_send_message_with_reply_finish (GDBusConnection     *connection,
139                                                                    GAsyncResult        *res,
140                                                                    GError             **error);
141 GDBusMessage    *g_dbus_connection_send_message_with_reply_sync   (GDBusConnection     *connection,
142                                                                    GDBusMessage        *message,
143                                                                    GDBusSendMessageFlags flags,
144                                                                    gint                 timeout_msec,
145                                                                    volatile guint32    *out_serial,
146                                                                    GCancellable        *cancellable,
147                                                                    GError             **error);
148
149 /* ---------------------------------------------------------------------------------------------------- */
150
151 gboolean  g_dbus_connection_emit_signal                       (GDBusConnection    *connection,
152                                                                const gchar        *destination_bus_name,
153                                                                const gchar        *object_path,
154                                                                const gchar        *interface_name,
155                                                                const gchar        *signal_name,
156                                                                GVariant           *parameters,
157                                                                GError            **error);
158 void      g_dbus_connection_call                              (GDBusConnection    *connection,
159                                                                const gchar        *bus_name,
160                                                                const gchar        *object_path,
161                                                                const gchar        *interface_name,
162                                                                const gchar        *method_name,
163                                                                GVariant           *parameters,
164                                                                const GVariantType *reply_type,
165                                                                GDBusCallFlags      flags,
166                                                                gint                timeout_msec,
167                                                                GCancellable       *cancellable,
168                                                                GAsyncReadyCallback callback,
169                                                                gpointer            user_data);
170 GVariant *g_dbus_connection_call_finish                       (GDBusConnection    *connection,
171                                                                GAsyncResult       *res,
172                                                                GError            **error);
173 GVariant *g_dbus_connection_call_sync                         (GDBusConnection    *connection,
174                                                                const gchar        *bus_name,
175                                                                const gchar        *object_path,
176                                                                const gchar        *interface_name,
177                                                                const gchar        *method_name,
178                                                                GVariant           *parameters,
179                                                                const GVariantType *reply_type,
180                                                                GDBusCallFlags      flags,
181                                                                gint                timeout_msec,
182                                                                GCancellable       *cancellable,
183                                                                GError            **error);
184
185 /* ---------------------------------------------------------------------------------------------------- */
186
187
188 /**
189  * GDBusInterfaceMethodCallFunc:
190  * @connection: A #GDBusConnection.
191  * @sender: The unique bus name of the remote caller.
192  * @object_path: The object path that the method was invoked on.
193  * @interface_name: The D-Bus interface name the method was invoked on.
194  * @method_name: The name of the method that was invoked.
195  * @parameters: A #GVariant tuple with parameters.
196  * @invocation: A #GDBusMethodInvocation object that can be used to return a value or error.
197  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
198  *
199  * The type of the @method_call function in #GDBusInterfaceVTable.
200  *
201  * Since: 2.26
202  */
203 typedef void (*GDBusInterfaceMethodCallFunc) (GDBusConnection       *connection,
204                                               const gchar           *sender,
205                                               const gchar           *object_path,
206                                               const gchar           *interface_name,
207                                               const gchar           *method_name,
208                                               GVariant              *parameters,
209                                               GDBusMethodInvocation *invocation,
210                                               gpointer               user_data);
211
212 /**
213  * GDBusInterfaceGetPropertyFunc:
214  * @connection: A #GDBusConnection.
215  * @sender: The unique bus name of the remote caller.
216  * @object_path: The object path that the method was invoked on.
217  * @interface_name: The D-Bus interface name for the property.
218  * @property_name: The name of the property to get the value of.
219  * @error: Return location for error.
220  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
221  *
222  * The type of the @get_property function in #GDBusInterfaceVTable.
223  *
224  * Returns: A newly-allocated #GVariant with the value for @property_name or %NULL if @error is set.
225  *
226  * Since: 2.26
227  */
228 typedef GVariant *(*GDBusInterfaceGetPropertyFunc) (GDBusConnection       *connection,
229                                                     const gchar           *sender,
230                                                     const gchar           *object_path,
231                                                     const gchar           *interface_name,
232                                                     const gchar           *property_name,
233                                                     GError               **error,
234                                                     gpointer               user_data);
235
236 /**
237  * GDBusInterfaceSetPropertyFunc:
238  * @connection: A #GDBusConnection.
239  * @sender: The unique bus name of the remote caller.
240  * @object_path: The object path that the method was invoked on.
241  * @interface_name: The D-Bus interface name for the property.
242  * @property_name: The name of the property to get the value of.
243  * @value: The value to set the property to.
244  * @error: Return location for error.
245  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
246  *
247  * The type of the @set_property function in #GDBusInterfaceVTable.
248  *
249  * Returns: %TRUE if the property was set to @value, %FALSE if @error is set.
250  *
251  * Since: 2.26
252  */
253 typedef gboolean  (*GDBusInterfaceSetPropertyFunc) (GDBusConnection       *connection,
254                                                     const gchar           *sender,
255                                                     const gchar           *object_path,
256                                                     const gchar           *interface_name,
257                                                     const gchar           *property_name,
258                                                     GVariant              *value,
259                                                     GError               **error,
260                                                     gpointer               user_data);
261
262 /**
263  * GDBusInterfaceVTable:
264  * @method_call: Function for handling incoming method calls.
265  * @get_property: Function for getting a property.
266  * @set_property: Function for setting a property.
267  *
268  * Virtual table for handling properties and method calls for a D-Bus
269  * interface.
270  *
271  * If you want to handle getting/setting D-Bus properties asynchronously, simply
272  * register an object with the <literal>org.freedesktop.DBus.Properties</literal>
273  * D-Bus interface using g_dbus_connection_register_object().
274  *
275  * Since: 2.26
276  */
277 struct _GDBusInterfaceVTable
278 {
279   GDBusInterfaceMethodCallFunc  method_call;
280   GDBusInterfaceGetPropertyFunc get_property;
281   GDBusInterfaceSetPropertyFunc set_property;
282
283   /*< private >*/
284   /* Padding for future expansion - also remember to update
285    * gdbusconnection.c:_g_dbus_interface_vtable_copy() when
286    * changing this.
287    */
288   gpointer padding[8];
289 };
290
291 guint            g_dbus_connection_register_object            (GDBusConnection            *connection,
292                                                                const gchar                *object_path,
293                                                                GDBusInterfaceInfo         *interface_info,
294                                                                const GDBusInterfaceVTable *vtable,
295                                                                gpointer                    user_data,
296                                                                GDestroyNotify              user_data_free_func,
297                                                                GError                    **error);
298 gboolean         g_dbus_connection_unregister_object          (GDBusConnection            *connection,
299                                                                guint                       registration_id);
300
301 /* ---------------------------------------------------------------------------------------------------- */
302
303 /**
304  * GDBusSubtreeEnumerateFunc:
305  * @connection: A #GDBusConnection.
306  * @sender: The unique bus name of the remote caller.
307  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
308  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
309  *
310  * The type of the @enumerate function in #GDBusSubtreeVTable.
311  *
312  * This function is called when generating introspection data and also
313  * when preparing to dispatch incoming messages in the event that the
314  * %G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES flag is not
315  * specified (ie: to verify that the object path is valid).
316  *
317  * Hierarchies are not supported; the items that you return should not
318  * contain the '/' character.
319  *
320  * The return value will be freed with g_strfreev().
321  *
322  * Returns: A newly allocated array of strings for node names that are children of @object_path.
323  *
324  * Since: 2.26
325  */
326 typedef gchar** (*GDBusSubtreeEnumerateFunc) (GDBusConnection       *connection,
327                                               const gchar           *sender,
328                                               const gchar           *object_path,
329                                               gpointer               user_data);
330
331 /**
332  * GDBusSubtreeIntrospectFunc:
333  * @connection: A #GDBusConnection.
334  * @sender: The unique bus name of the remote caller.
335  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
336  * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
337  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
338  *
339  * The type of the @introspect function in #GDBusSubtreeVTable.
340  *
341  * Subtrees are flat.  @node, if non-%NULL, is always exactly one
342  * segment of the object path (ie: it never contains a slash).
343  *
344  * This function should return %NULL to indicate that there is no object
345  * at this node.
346  *
347  * If this function returns non-%NULL, the return value is expected to
348  * be a %NULL-terminated array of pointers to #GDBusInterfaceInfo
349  * structures describing the interfaces implemented by @node.  This
350  * array will have g_dbus_interface_info_unref() called on each item
351  * before being freed with g_free().
352  *
353  * The difference between returning %NULL and an array containing zero
354  * items is that the standard DBus interfaces will returned to the
355  * remote introspector in the empty array case, but not in the %NULL
356  * case.
357  *
358  * Returns: A %NULL-terminated array of pointers to #GDBusInterfaceInfo, or %NULL.
359  *
360  * Since: 2.26
361  */
362 typedef GDBusInterfaceInfo ** (*GDBusSubtreeIntrospectFunc) (GDBusConnection       *connection,
363                                                              const gchar           *sender,
364                                                              const gchar           *object_path,
365                                                              const gchar           *node,
366                                                              gpointer               user_data);
367
368 /**
369  * GDBusSubtreeDispatchFunc:
370  * @connection: A #GDBusConnection.
371  * @sender: The unique bus name of the remote caller.
372  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
373  * @interface_name: The D-Bus interface name that the method call or property access is for.
374  * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
375  * @out_user_data: Return location for user data to pass to functions in the returned #GDBusInterfaceVTable (never %NULL).
376  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
377  *
378  * The type of the @dispatch function in #GDBusSubtreeVTable.
379  *
380  * Subtrees are flat.  @node, if non-%NULL, is always exactly one
381  * segment of the object path (ie: it never contains a slash).
382  *
383  * Returns: A #GDBusInterfaceVTable or %NULL if you don't want to handle the methods.
384  *
385  * Since: 2.26
386  */
387 typedef const GDBusInterfaceVTable * (*GDBusSubtreeDispatchFunc) (GDBusConnection             *connection,
388                                                                   const gchar                 *sender,
389                                                                   const gchar                 *object_path,
390                                                                   const gchar                 *interface_name,
391                                                                   const gchar                 *node,
392                                                                   gpointer                    *out_user_data,
393                                                                   gpointer                     user_data);
394
395 /**
396  * GDBusSubtreeVTable:
397  * @enumerate: Function for enumerating child nodes.
398  * @introspect: Function for introspecting a child node.
399  * @dispatch: Function for dispatching a remote call on a child node.
400  *
401  * Virtual table for handling subtrees registered with g_dbus_connection_register_subtree().
402  *
403  * Since: 2.26
404  */
405 struct _GDBusSubtreeVTable
406 {
407   GDBusSubtreeEnumerateFunc  enumerate;
408   GDBusSubtreeIntrospectFunc introspect;
409   GDBusSubtreeDispatchFunc   dispatch;
410
411   /*< private >*/
412   /* Padding for future expansion - also remember to update
413    * gdbusconnection.c:_g_dbus_subtree_vtable_copy() when
414    * changing this.
415    */
416   gpointer padding[8];
417 };
418
419 guint            g_dbus_connection_register_subtree           (GDBusConnection            *connection,
420                                                                const gchar                *object_path,
421                                                                const GDBusSubtreeVTable   *vtable,
422                                                                GDBusSubtreeFlags           flags,
423                                                                gpointer                    user_data,
424                                                                GDestroyNotify              user_data_free_func,
425                                                                GError                    **error);
426 gboolean         g_dbus_connection_unregister_subtree         (GDBusConnection            *connection,
427                                                                guint                       registration_id);
428
429 /* ---------------------------------------------------------------------------------------------------- */
430
431 /**
432  * GDBusSignalCallback:
433  * @connection: A #GDBusConnection.
434  * @sender_name: The unique bus name of the sender of the signal.
435  * @object_path: The object path that the signal was emitted on.
436  * @interface_name: The name of the interface.
437  * @signal_name: The name of the signal.
438  * @parameters: A #GVariant tuple with parameters for the signal.
439  * @user_data: User data passed when subscribing to the signal.
440  *
441  * Signature for callback function used in g_dbus_connection_signal_subscribe().
442  *
443  * Since: 2.26
444  */
445 typedef void (*GDBusSignalCallback) (GDBusConnection  *connection,
446                                      const gchar      *sender_name,
447                                      const gchar      *object_path,
448                                      const gchar      *interface_name,
449                                      const gchar      *signal_name,
450                                      GVariant         *parameters,
451                                      gpointer          user_data);
452
453 guint            g_dbus_connection_signal_subscribe           (GDBusConnection     *connection,
454                                                                const gchar         *sender,
455                                                                const gchar         *interface_name,
456                                                                const gchar         *member,
457                                                                const gchar         *object_path,
458                                                                const gchar         *arg0,
459                                                                GDBusSignalFlags     flags,
460                                                                GDBusSignalCallback  callback,
461                                                                gpointer             user_data,
462                                                                GDestroyNotify       user_data_free_func);
463 void             g_dbus_connection_signal_unsubscribe         (GDBusConnection     *connection,
464                                                                guint                subscription_id);
465
466 /* ---------------------------------------------------------------------------------------------------- */
467
468 /**
469  * GDBusMessageFilterFunction:
470  * @connection: A #GDBusConnection.
471  * @message: A #GDBusMessage.
472  * @incoming: %TRUE if it is a message received from the other peer, %FALSE if it is
473  * a message to be sent to the other peer.
474  * @user_data: User data passed when adding the filter.
475  *
476  * Signature for function used in g_dbus_connection_add_filter().
477  *
478  * Returns: %TRUE if the filter handled @message, %FALSE to let other
479  * handlers run.
480  *
481  * Since: 2.26
482  */
483 typedef gboolean (*GDBusMessageFilterFunction) (GDBusConnection *connection,
484                                                 GDBusMessage    *message,
485                                                 gboolean         incoming,
486                                                 gpointer         user_data);
487
488 guint g_dbus_connection_add_filter (GDBusConnection            *connection,
489                                     GDBusMessageFilterFunction  filter_function,
490                                     gpointer                    user_data,
491                                     GDestroyNotify              user_data_free_func);
492
493 void  g_dbus_connection_remove_filter (GDBusConnection    *connection,
494                                        guint               filter_id);
495
496 /* ---------------------------------------------------------------------------------------------------- */
497
498
499 G_END_DECLS
500
501 #endif /* __G_DBUS_CONNECTION_H__ */