GDBus: Rename `introspection_data' parameter to `interface_info'
[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_DBUS_CONNECTION_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_DBUS_CONNECTION, GDBusConnectionClass))
37 #define G_DBUS_CONNECTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_DBUS_CONNECTION, GDBusConnectionClass))
38 #define G_IS_DBUS_CONNECTION(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_DBUS_CONNECTION))
39 #define G_IS_DBUS_CONNECTION_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_DBUS_CONNECTION))
40
41 typedef struct _GDBusConnectionClass   GDBusConnectionClass;
42 typedef struct _GDBusConnectionPrivate GDBusConnectionPrivate;
43
44 /**
45  * GDBusConnection:
46  *
47  * The #GDBusConnection structure contains only private data and
48  * should only be accessed using the provided API.
49  *
50  * Since: 2.26
51  */
52 struct _GDBusConnection
53 {
54   /*< private >*/
55   GObject parent_instance;
56   GDBusConnectionPrivate *priv;
57 };
58
59 /**
60  * GDBusConnectionClass:
61  * @closed: Signal class handler for the #GDBusConnection::closed signal.
62  *
63  * Class structure for #GDBusConnection.
64  *
65  * Since: 2.26
66  */
67 struct _GDBusConnectionClass
68 {
69   /*< private >*/
70   GObjectClass parent_class;
71
72   /*< public >*/
73   /* Signals */
74   void (*closed) (GDBusConnection *connection,
75                   gboolean         remote_peer_vanished,
76                   GError          *error);
77
78   /*< private >*/
79   /* Padding for future expansion */
80   gpointer padding[64];
81 };
82
83 GType            g_dbus_connection_get_type                   (void) G_GNUC_CONST;
84
85 /* ---------------------------------------------------------------------------------------------------- */
86
87 void              g_bus_get                    (GBusType             bus_type,
88                                                 GCancellable        *cancellable,
89                                                 GAsyncReadyCallback  callback,
90                                                 gpointer             user_data);
91 GDBusConnection  *g_bus_get_finish             (GAsyncResult        *res,
92                                                 GError             **error);
93 GDBusConnection  *g_bus_get_sync               (GBusType            bus_type,
94                                                 GCancellable       *cancellable,
95                                                 GError            **error);
96
97 /* ---------------------------------------------------------------------------------------------------- */
98
99 void             g_dbus_connection_new                        (GIOStream              *stream,
100                                                                const gchar            *guid,
101                                                                GDBusConnectionFlags    flags,
102                                                                GDBusAuthObserver      *observer,
103                                                                GCancellable           *cancellable,
104                                                                GAsyncReadyCallback     callback,
105                                                                gpointer                user_data);
106 GDBusConnection *g_dbus_connection_new_finish                 (GAsyncResult           *res,
107                                                                GError                **error);
108 GDBusConnection *g_dbus_connection_new_sync                   (GIOStream              *stream,
109                                                                const gchar            *guid,
110                                                                GDBusConnectionFlags    flags,
111                                                                GDBusAuthObserver      *observer,
112                                                                GCancellable           *cancellable,
113                                                                GError                **error);
114
115 void             g_dbus_connection_new_for_address            (const gchar            *address,
116                                                                GDBusConnectionFlags    flags,
117                                                                GDBusAuthObserver      *observer,
118                                                                GCancellable           *cancellable,
119                                                                GAsyncReadyCallback     callback,
120                                                                gpointer                user_data);
121 GDBusConnection *g_dbus_connection_new_for_address_finish     (GAsyncResult           *res,
122                                                                GError                **error);
123 GDBusConnection *g_dbus_connection_new_for_address_sync       (const gchar            *address,
124                                                                GDBusConnectionFlags    flags,
125                                                                GDBusAuthObserver      *observer,
126                                                                GCancellable           *cancellable,
127                                                                GError                **error);
128
129 /* ---------------------------------------------------------------------------------------------------- */
130
131 void             g_dbus_connection_start_message_processing   (GDBusConnection    *connection);
132 gboolean         g_dbus_connection_is_closed                  (GDBusConnection    *connection);
133 void             g_dbus_connection_close                      (GDBusConnection    *connection);
134 GIOStream       *g_dbus_connection_get_stream                 (GDBusConnection    *connection);
135 const gchar     *g_dbus_connection_get_guid                   (GDBusConnection    *connection);
136 const gchar     *g_dbus_connection_get_unique_name            (GDBusConnection    *connection);
137 GCredentials    *g_dbus_connection_get_peer_credentials       (GDBusConnection    *connection);
138 gboolean         g_dbus_connection_get_exit_on_close          (GDBusConnection    *connection);
139 void             g_dbus_connection_set_exit_on_close          (GDBusConnection    *connection,
140                                                                gboolean            exit_on_close);
141 GDBusCapabilityFlags  g_dbus_connection_get_capabilities      (GDBusConnection    *connection);
142 /* ---------------------------------------------------------------------------------------------------- */
143
144 gboolean         g_dbus_connection_send_message                   (GDBusConnection     *connection,
145                                                                    GDBusMessage        *message,
146                                                                    volatile guint32    *out_serial,
147                                                                    GError             **error);
148 void             g_dbus_connection_send_message_with_reply        (GDBusConnection     *connection,
149                                                                    GDBusMessage        *message,
150                                                                    gint                 timeout_msec,
151                                                                    volatile guint32    *out_serial,
152                                                                    GCancellable        *cancellable,
153                                                                    GAsyncReadyCallback  callback,
154                                                                    gpointer             user_data);
155 GDBusMessage    *g_dbus_connection_send_message_with_reply_finish (GDBusConnection     *connection,
156                                                                    GAsyncResult        *res,
157                                                                    GError             **error);
158 GDBusMessage    *g_dbus_connection_send_message_with_reply_sync   (GDBusConnection     *connection,
159                                                                    GDBusMessage        *message,
160                                                                    gint                 timeout_msec,
161                                                                    volatile guint32    *out_serial,
162                                                                    GCancellable        *cancellable,
163                                                                    GError             **error);
164
165 /* ---------------------------------------------------------------------------------------------------- */
166
167 gboolean  g_dbus_connection_emit_signal                       (GDBusConnection    *connection,
168                                                                const gchar        *destination_bus_name,
169                                                                const gchar        *object_path,
170                                                                const gchar        *interface_name,
171                                                                const gchar        *signal_name,
172                                                                GVariant           *parameters,
173                                                                GError            **error);
174 void      g_dbus_connection_call                              (GDBusConnection    *connection,
175                                                                const gchar        *bus_name,
176                                                                const gchar        *object_path,
177                                                                const gchar        *interface_name,
178                                                                const gchar        *method_name,
179                                                                GVariant           *parameters,
180                                                                const GVariantType *reply_type,
181                                                                GDBusCallFlags      flags,
182                                                                gint                timeout_msec,
183                                                                GCancellable       *cancellable,
184                                                                GAsyncReadyCallback callback,
185                                                                gpointer            user_data);
186 GVariant *g_dbus_connection_call_finish                       (GDBusConnection    *connection,
187                                                                GAsyncResult       *res,
188                                                                GError            **error);
189 GVariant *g_dbus_connection_call_sync                         (GDBusConnection    *connection,
190                                                                const gchar        *bus_name,
191                                                                const gchar        *object_path,
192                                                                const gchar        *interface_name,
193                                                                const gchar        *method_name,
194                                                                GVariant           *parameters,
195                                                                const GVariantType *reply_type,
196                                                                GDBusCallFlags      flags,
197                                                                gint                timeout_msec,
198                                                                GCancellable       *cancellable,
199                                                                GError            **error);
200
201 /* ---------------------------------------------------------------------------------------------------- */
202
203
204 /**
205  * GDBusInterfaceMethodCallFunc:
206  * @connection: A #GDBusConnection.
207  * @sender: The unique bus name of the remote caller.
208  * @object_path: The object path that the method was invoked on.
209  * @interface_name: The D-Bus interface name the method was invoked on.
210  * @method_name: The name of the method that was invoked.
211  * @parameters: A #GVariant tuple with parameters.
212  * @invocation: A #GDBusMethodInvocation object that can be used to return a value or error.
213  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
214  *
215  * The type of the @method_call function in #GDBusInterfaceVTable.
216  *
217  * Since: 2.26
218  */
219 typedef void (*GDBusInterfaceMethodCallFunc) (GDBusConnection       *connection,
220                                               const gchar           *sender,
221                                               const gchar           *object_path,
222                                               const gchar           *interface_name,
223                                               const gchar           *method_name,
224                                               GVariant              *parameters,
225                                               GDBusMethodInvocation *invocation,
226                                               gpointer               user_data);
227
228 /**
229  * GDBusInterfaceGetPropertyFunc:
230  * @connection: A #GDBusConnection.
231  * @sender: The unique bus name of the remote caller.
232  * @object_path: The object path that the method was invoked on.
233  * @interface_name: The D-Bus interface name for the property.
234  * @property_name: The name of the property to get the value of.
235  * @error: Return location for error.
236  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
237  *
238  * The type of the @get_property function in #GDBusInterfaceVTable.
239  *
240  * Returns: A newly-allocated #GVariant with the value for @property_name or %NULL if @error is set.
241  *
242  * Since: 2.26
243  */
244 typedef GVariant *(*GDBusInterfaceGetPropertyFunc) (GDBusConnection       *connection,
245                                                     const gchar           *sender,
246                                                     const gchar           *object_path,
247                                                     const gchar           *interface_name,
248                                                     const gchar           *property_name,
249                                                     GError               **error,
250                                                     gpointer               user_data);
251
252 /**
253  * GDBusInterfaceSetPropertyFunc:
254  * @connection: A #GDBusConnection.
255  * @sender: The unique bus name of the remote caller.
256  * @object_path: The object path that the method was invoked on.
257  * @interface_name: The D-Bus interface name for the property.
258  * @property_name: The name of the property to get the value of.
259  * @value: The value to set the property to.
260  * @error: Return location for error.
261  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
262  *
263  * The type of the @set_property function in #GDBusInterfaceVTable.
264  *
265  * Returns: %TRUE if the property was set to @value, %FALSE if @error is set.
266  *
267  * Since: 2.26
268  */
269 typedef gboolean  (*GDBusInterfaceSetPropertyFunc) (GDBusConnection       *connection,
270                                                     const gchar           *sender,
271                                                     const gchar           *object_path,
272                                                     const gchar           *interface_name,
273                                                     const gchar           *property_name,
274                                                     GVariant              *value,
275                                                     GError               **error,
276                                                     gpointer               user_data);
277
278 /**
279  * GDBusInterfaceVTable:
280  * @method_call: Function for handling incoming method calls.
281  * @get_property: Function for getting a property.
282  * @set_property: Function for setting a property.
283  *
284  * Virtual table for handling properties and method calls for a D-Bus
285  * interface.
286  *
287  * If you want to handle getting/setting D-Bus properties asynchronously, simply
288  * register an object with the <literal>org.freedesktop.DBus.Properties</literal>
289  * D-Bus interface using g_dbus_connection_register_object().
290  *
291  * Since: 2.26
292  */
293 struct _GDBusInterfaceVTable
294 {
295   GDBusInterfaceMethodCallFunc  method_call;
296   GDBusInterfaceGetPropertyFunc get_property;
297   GDBusInterfaceSetPropertyFunc set_property;
298
299   /*< private >*/
300   /* Padding for future expansion */
301   gpointer padding[8];
302 };
303
304 guint            g_dbus_connection_register_object            (GDBusConnection            *connection,
305                                                                const gchar                *object_path,
306                                                                const GDBusInterfaceInfo   *interface_info,
307                                                                const GDBusInterfaceVTable *vtable,
308                                                                gpointer                    user_data,
309                                                                GDestroyNotify              user_data_free_func,
310                                                                GError                    **error);
311 gboolean         g_dbus_connection_unregister_object          (GDBusConnection            *connection,
312                                                                guint                       registration_id);
313
314 /* ---------------------------------------------------------------------------------------------------- */
315
316 /**
317  * GDBusSubtreeEnumerateFunc:
318  * @connection: A #GDBusConnection.
319  * @sender: The unique bus name of the remote caller.
320  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
321  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
322  *
323  * The type of the @enumerate function in #GDBusSubtreeVTable.
324  *
325  * Returns: A newly allocated array of strings for node names that are children of @object_path.
326  *
327  * Since: 2.26
328  */
329 typedef gchar** (*GDBusSubtreeEnumerateFunc) (GDBusConnection       *connection,
330                                               const gchar           *sender,
331                                               const gchar           *object_path,
332                                               gpointer               user_data);
333
334 /**
335  * GDBusSubtreeIntrospectFunc:
336  * @connection: A #GDBusConnection.
337  * @sender: The unique bus name of the remote caller.
338  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
339  * @node: A node that is a child of @object_path (relative to @object_path) or <quote>/</quote> for the root of the subtree.
340  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
341  *
342  * The type of the @introspect function in #GDBusSubtreeVTable.
343  *
344  * Returns: A newly-allocated #GPtrArray with pointers to #GDBusInterfaceInfo describing
345  * the interfaces implemented by @node.
346  *
347  * Since: 2.26
348  */
349 typedef GPtrArray *(*GDBusSubtreeIntrospectFunc) (GDBusConnection       *connection,
350                                                   const gchar           *sender,
351                                                   const gchar           *object_path,
352                                                   const gchar           *node,
353                                                   gpointer               user_data);
354
355 /**
356  * GDBusSubtreeDispatchFunc:
357  * @connection: A #GDBusConnection.
358  * @sender: The unique bus name of the remote caller.
359  * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
360  * @interface_name: The D-Bus interface name that the method call or property access is for.
361  * @node: A node that is a child of @object_path (relative to @object_path) or <quote>/</quote> for the root of the subtree.
362  * @out_user_data: Return location for user data to pass to functions in the returned #GDBusInterfaceVTable (never %NULL).
363  * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
364  *
365  * The type of the @dispatch function in #GDBusSubtreeVTable.
366  *
367  * Returns: A #GDBusInterfaceVTable or %NULL if you don't want to handle the methods.
368  *
369  * Since: 2.26
370  */
371 typedef const GDBusInterfaceVTable * (*GDBusSubtreeDispatchFunc) (GDBusConnection             *connection,
372                                                                   const gchar                 *sender,
373                                                                   const gchar                 *object_path,
374                                                                   const gchar                 *interface_name,
375                                                                   const gchar                 *node,
376                                                                   gpointer                    *out_user_data,
377                                                                   gpointer                     user_data);
378
379 /**
380  * GDBusSubtreeVTable:
381  * @enumerate: Function for enumerating child nodes.
382  * @introspect: Function for introspecting a child node.
383  * @dispatch: Function for dispatching a remote call on a child node.
384  *
385  * Virtual table for handling subtrees registered with g_dbus_connection_register_subtree().
386  *
387  * Since: 2.26
388  */
389 struct _GDBusSubtreeVTable
390 {
391   GDBusSubtreeEnumerateFunc  enumerate;
392   GDBusSubtreeIntrospectFunc introspect;
393   GDBusSubtreeDispatchFunc   dispatch;
394
395   /*< private >*/
396   /* Padding for future expansion */
397   void (*_g_reserved1) (void);
398   void (*_g_reserved2) (void);
399   void (*_g_reserved3) (void);
400   void (*_g_reserved4) (void);
401   void (*_g_reserved5) (void);
402   void (*_g_reserved6) (void);
403   void (*_g_reserved7) (void);
404   void (*_g_reserved8) (void);
405 };
406
407 guint            g_dbus_connection_register_subtree           (GDBusConnection            *connection,
408                                                                const gchar                *object_path,
409                                                                const GDBusSubtreeVTable   *vtable,
410                                                                GDBusSubtreeFlags           flags,
411                                                                gpointer                    user_data,
412                                                                GDestroyNotify              user_data_free_func,
413                                                                GError                    **error);
414 gboolean         g_dbus_connection_unregister_subtree         (GDBusConnection            *connection,
415                                                                guint                       registration_id);
416
417 /* ---------------------------------------------------------------------------------------------------- */
418
419 /**
420  * GDBusSignalCallback:
421  * @connection: A #GDBusConnection.
422  * @sender_name: The unique bus name of the sender of the signal.
423  * @object_path: The object path that the signal was emitted on.
424  * @interface_name: The name of the interface.
425  * @signal_name: The name of the signal.
426  * @parameters: A #GVariant tuple with parameters for the signal.
427  * @user_data: User data passed when subscribing to the signal.
428  *
429  * Signature for callback function used in g_dbus_connection_signal_subscribe().
430  *
431  * Since: 2.26
432  */
433 typedef void (*GDBusSignalCallback) (GDBusConnection  *connection,
434                                      const gchar      *sender_name,
435                                      const gchar      *object_path,
436                                      const gchar      *interface_name,
437                                      const gchar      *signal_name,
438                                      GVariant         *parameters,
439                                      gpointer          user_data);
440
441 guint            g_dbus_connection_signal_subscribe           (GDBusConnection     *connection,
442                                                                const gchar         *sender,
443                                                                const gchar         *interface_name,
444                                                                const gchar         *member,
445                                                                const gchar         *object_path,
446                                                                const gchar         *arg0,
447                                                                GDBusSignalCallback  callback,
448                                                                gpointer             user_data,
449                                                                GDestroyNotify       user_data_free_func);
450 void             g_dbus_connection_signal_unsubscribe         (GDBusConnection     *connection,
451                                                                guint                subscription_id);
452
453 /* ---------------------------------------------------------------------------------------------------- */
454
455 /**
456  * GDBusMessageFilterFunction:
457  * @connection: A #GDBusConnection.
458  * @message: A #GDBusMessage.
459  * @incoming: %TRUE if it is a message received from the other peer, %FALSE if it is
460  * a message to be sent to the other peer.
461  * @user_data: User data passed when adding the filter.
462  *
463  * Signature for function used in g_dbus_connection_add_filter().
464  *
465  * Returns: %TRUE if the filter handled @message, %FALSE to let other
466  * handlers run.
467  *
468  * Since: 2.26
469  */
470 typedef gboolean (*GDBusMessageFilterFunction) (GDBusConnection *connection,
471                                                 GDBusMessage    *message,
472                                                 gboolean         incoming,
473                                                 gpointer         user_data);
474
475 guint g_dbus_connection_add_filter (GDBusConnection            *connection,
476                                     GDBusMessageFilterFunction  filter_function,
477                                     gpointer                    user_data,
478                                     GDestroyNotify              user_data_free_func);
479
480 void  g_dbus_connection_remove_filter (GDBusConnection    *connection,
481                                        guint               filter_id);
482
483 /* ---------------------------------------------------------------------------------------------------- */
484
485
486 G_END_DECLS
487
488 #endif /* __G_DBUS_CONNECTION_H__ */