Merge branch 'dbus-1.2'
[platform/upstream/dbus.git] / dbus / dbus-connection.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-connection.h DBusConnection object
3  *
4  * Copyright (C) 2002, 2003  Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23 #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 #error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
25 #endif
26
27 #ifndef DBUS_CONNECTION_H
28 #define DBUS_CONNECTION_H
29
30 #include <dbus/dbus-errors.h>
31 #include <dbus/dbus-memory.h>
32 #include <dbus/dbus-message.h>
33 #include <dbus/dbus-shared.h>
34
35 DBUS_BEGIN_DECLS
36
37 /**
38  * @addtogroup DBusConnection
39  * @{
40  */
41
42 /* documented in dbus-watch.c */
43 typedef struct DBusWatch DBusWatch;
44 /* documented in dbus-timeout.c */
45 typedef struct DBusTimeout DBusTimeout;
46 /** Opaque type representing preallocated resources so a message can be sent without further memory allocation. */
47 typedef struct DBusPreallocatedSend DBusPreallocatedSend;
48 /** Opaque type representing a method call that has not yet received a reply. */
49 typedef struct DBusPendingCall DBusPendingCall;
50 /** Opaque type representing a connection to a remote application and associated incoming/outgoing message queues. */
51 typedef struct DBusConnection DBusConnection;
52 /** Set of functions that must be implemented to handle messages sent to a particular object path. */
53 typedef struct DBusObjectPathVTable DBusObjectPathVTable;
54
55 /**
56  * Indicates the status of a #DBusWatch.
57  */
58 typedef enum
59 {
60   DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
61   DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
62   DBUS_WATCH_ERROR    = 1 << 2, /**< As in POLLERR (can't watch for
63                                  *   this, but can be present in
64                                  *   current state passed to
65                                  *   dbus_watch_handle()).
66                                  */
67   DBUS_WATCH_HANGUP   = 1 << 3  /**< As in POLLHUP (can't watch for
68                                  *   it, but can be present in current
69                                  *   state passed to
70                                  *   dbus_watch_handle()).
71                                  */
72 } DBusWatchFlags;
73
74 /**
75  * Indicates the status of incoming data on a #DBusConnection. This determines whether
76  * dbus_connection_dispatch() needs to be called.
77  */
78 typedef enum
79 {
80   DBUS_DISPATCH_DATA_REMAINS,  /**< There is more data to potentially convert to messages. */
81   DBUS_DISPATCH_COMPLETE,      /**< All currently available data has been processed. */
82   DBUS_DISPATCH_NEED_MEMORY    /**< More memory is needed to continue. */
83 } DBusDispatchStatus;
84
85 /** Called when libdbus needs a new watch to be monitored by the main
86  * loop. Returns #FALSE if it lacks enough memory to add the
87  * watch. Set by dbus_connection_set_watch_functions() or
88  * dbus_server_set_watch_functions().
89  */
90 typedef dbus_bool_t (* DBusAddWatchFunction)       (DBusWatch      *watch,
91                                                     void           *data);
92 /** Called when dbus_watch_get_enabled() may return a different value
93  *  than it did before.  Set by dbus_connection_set_watch_functions()
94  *  or dbus_server_set_watch_functions().
95  */
96 typedef void        (* DBusWatchToggledFunction)   (DBusWatch      *watch,
97                                                     void           *data);
98 /** Called when libdbus no longer needs a watch to be monitored by the
99  * main loop. Set by dbus_connection_set_watch_functions() or
100  * dbus_server_set_watch_functions().
101  */
102 typedef void        (* DBusRemoveWatchFunction)    (DBusWatch      *watch,
103                                                     void           *data);
104 /** Called when libdbus needs a new timeout to be monitored by the main
105  * loop. Returns #FALSE if it lacks enough memory to add the
106  * watch. Set by dbus_connection_set_timeout_functions() or
107  * dbus_server_set_timeout_functions().
108  */
109 typedef dbus_bool_t (* DBusAddTimeoutFunction)     (DBusTimeout    *timeout,
110                                                     void           *data);
111 /** Called when dbus_timeout_get_enabled() may return a different
112  * value than it did before.
113  * Set by dbus_connection_set_timeout_functions() or
114  * dbus_server_set_timeout_functions().
115  */
116 typedef void        (* DBusTimeoutToggledFunction) (DBusTimeout    *timeout,
117                                                     void           *data);
118 /** Called when libdbus no longer needs a timeout to be monitored by the
119  * main loop. Set by dbus_connection_set_timeout_functions() or
120  * dbus_server_set_timeout_functions().
121  */
122 typedef void        (* DBusRemoveTimeoutFunction)  (DBusTimeout    *timeout,
123                                                     void           *data);
124 /** Called when the return value of dbus_connection_get_dispatch_status()
125  * may have changed. Set with dbus_connection_set_dispatch_status_function().
126  */
127 typedef void        (* DBusDispatchStatusFunction) (DBusConnection *connection,
128                                                     DBusDispatchStatus new_status,
129                                                     void           *data);
130 /**
131  * Called when the main loop's thread should be notified that there's now work
132  * to do. Set with dbus_connection_set_wakeup_main_function().
133  */
134 typedef void        (* DBusWakeupMainFunction)     (void           *data);
135
136 /**
137  * Called during authentication to check whether the given UNIX user
138  * ID is allowed to connect, if the client tried to auth as a UNIX
139  * user ID. Normally on Windows this would never happen. Set with
140  * dbus_connection_set_unix_user_function().
141  */ 
142 typedef dbus_bool_t (* DBusAllowUnixUserFunction)  (DBusConnection *connection,
143                                                     unsigned long   uid,
144                                                     void           *data);
145
146 /**
147  * Called during authentication to check whether the given Windows user
148  * ID is allowed to connect, if the client tried to auth as a Windows
149  * user ID. Normally on UNIX this would never happen. Set with
150  * dbus_connection_set_windows_user_function().
151  */ 
152 typedef dbus_bool_t (* DBusAllowWindowsUserFunction)  (DBusConnection *connection,
153                                                        const char     *user_sid,
154                                                        void           *data);
155
156
157 /**
158  * Called when a pending call now has a reply available. Set with
159  * dbus_pending_call_set_notify().
160  */
161 typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
162                                                 void            *user_data);
163
164 /**
165  * Called when a message needs to be handled. The result indicates whether or
166  * not more handlers should be run. Set with dbus_connection_add_filter().
167  */
168 typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection     *connection,
169                                                          DBusMessage        *message,
170                                                          void               *user_data);
171 DBUS_EXPORT
172 DBusConnection*    dbus_connection_open                         (const char                 *address,
173                                                                  DBusError                  *error);
174 DBUS_EXPORT
175 DBusConnection*    dbus_connection_open_private                 (const char                 *address,
176                                                                  DBusError                  *error);
177 DBUS_EXPORT
178 DBusConnection*    dbus_connection_ref                          (DBusConnection             *connection);
179 DBUS_EXPORT
180 void               dbus_connection_unref                        (DBusConnection             *connection);
181 DBUS_EXPORT
182 void               dbus_connection_close                        (DBusConnection             *connection);
183 DBUS_EXPORT
184 dbus_bool_t        dbus_connection_get_is_connected             (DBusConnection             *connection);
185 DBUS_EXPORT
186 dbus_bool_t        dbus_connection_get_is_authenticated         (DBusConnection             *connection);
187 DBUS_EXPORT
188 dbus_bool_t        dbus_connection_get_is_anonymous             (DBusConnection             *connection);
189 DBUS_EXPORT
190 char*              dbus_connection_get_server_id                (DBusConnection             *connection);
191 DBUS_EXPORT
192 dbus_bool_t        dbus_connection_can_send_type                (DBusConnection             *connection,
193                                                                  int                         type);
194
195 DBUS_EXPORT
196 void               dbus_connection_set_exit_on_disconnect       (DBusConnection             *connection,
197                                                                  dbus_bool_t                 exit_on_disconnect);
198 DBUS_EXPORT
199 void               dbus_connection_flush                        (DBusConnection             *connection);
200 DBUS_EXPORT
201 dbus_bool_t        dbus_connection_read_write_dispatch          (DBusConnection             *connection,
202                                                                  int                         timeout_milliseconds);
203 DBUS_EXPORT
204 dbus_bool_t        dbus_connection_read_write                   (DBusConnection             *connection,
205                                                                  int                         timeout_milliseconds);
206 DBUS_EXPORT
207 DBusMessage*       dbus_connection_borrow_message               (DBusConnection             *connection);
208 DBUS_EXPORT
209 void               dbus_connection_return_message               (DBusConnection             *connection,
210                                                                  DBusMessage                *message);
211 DBUS_EXPORT
212 void               dbus_connection_steal_borrowed_message       (DBusConnection             *connection,
213                                                                  DBusMessage                *message);
214 DBUS_EXPORT
215 DBusMessage*       dbus_connection_pop_message                  (DBusConnection             *connection);
216 DBUS_EXPORT
217 DBusDispatchStatus dbus_connection_get_dispatch_status          (DBusConnection             *connection);
218 DBUS_EXPORT
219 DBusDispatchStatus dbus_connection_dispatch                     (DBusConnection             *connection);
220 DBUS_EXPORT
221 dbus_bool_t        dbus_connection_has_messages_to_send         (DBusConnection *connection);
222 DBUS_EXPORT
223 dbus_bool_t        dbus_connection_send                         (DBusConnection             *connection,
224                                                                  DBusMessage                *message,
225                                                                  dbus_uint32_t              *client_serial);
226 DBUS_EXPORT
227 dbus_bool_t        dbus_connection_send_with_reply              (DBusConnection             *connection,
228                                                                  DBusMessage                *message,
229                                                                  DBusPendingCall           **pending_return,
230                                                                  int                         timeout_milliseconds);
231 DBUS_EXPORT
232 DBusMessage *      dbus_connection_send_with_reply_and_block    (DBusConnection             *connection,
233                                                                  DBusMessage                *message,
234                                                                  int                         timeout_milliseconds,
235                                                                  DBusError                  *error);
236 DBUS_EXPORT
237 dbus_bool_t        dbus_connection_set_watch_functions          (DBusConnection             *connection,
238                                                                  DBusAddWatchFunction        add_function,
239                                                                  DBusRemoveWatchFunction     remove_function,
240                                                                  DBusWatchToggledFunction    toggled_function,
241                                                                  void                       *data,
242                                                                  DBusFreeFunction            free_data_function);
243 DBUS_EXPORT
244 dbus_bool_t        dbus_connection_set_timeout_functions        (DBusConnection             *connection,
245                                                                  DBusAddTimeoutFunction      add_function,
246                                                                  DBusRemoveTimeoutFunction   remove_function,
247                                                                  DBusTimeoutToggledFunction  toggled_function,
248                                                                  void                       *data,
249                                                                  DBusFreeFunction            free_data_function);
250 DBUS_EXPORT
251 void               dbus_connection_set_wakeup_main_function     (DBusConnection             *connection,
252                                                                  DBusWakeupMainFunction      wakeup_main_function,
253                                                                  void                       *data,
254                                                                  DBusFreeFunction            free_data_function);
255 DBUS_EXPORT
256 void               dbus_connection_set_dispatch_status_function (DBusConnection             *connection,
257                                                                  DBusDispatchStatusFunction  function,
258                                                                  void                       *data,
259                                                                  DBusFreeFunction            free_data_function);
260 DBUS_EXPORT
261 dbus_bool_t        dbus_connection_get_unix_user                (DBusConnection             *connection,
262                                                                  unsigned long              *uid);
263 DBUS_EXPORT
264 dbus_bool_t        dbus_connection_get_unix_process_id          (DBusConnection             *connection,
265                                                                  unsigned long              *pid);
266 DBUS_EXPORT
267 dbus_bool_t        dbus_connection_get_adt_audit_session_data   (DBusConnection             *connection,
268                                                                  void                      **data,
269                                                                  dbus_int32_t               *data_size);
270 DBUS_EXPORT
271 void               dbus_connection_set_unix_user_function       (DBusConnection             *connection,
272                                                                  DBusAllowUnixUserFunction   function,
273                                                                  void                       *data,
274                                                                  DBusFreeFunction            free_data_function);
275 DBUS_EXPORT
276 dbus_bool_t        dbus_connection_get_windows_user             (DBusConnection             *connection,
277                                                                  char                      **windows_sid_p); 
278 DBUS_EXPORT
279 void               dbus_connection_set_windows_user_function    (DBusConnection             *connection,
280                                                                  DBusAllowWindowsUserFunction function,
281                                                                  void                       *data,
282                                                                  DBusFreeFunction            free_data_function);
283 DBUS_EXPORT
284 void               dbus_connection_set_allow_anonymous          (DBusConnection             *connection,
285                                                                  dbus_bool_t                 value);
286 DBUS_EXPORT
287 void               dbus_connection_set_route_peer_messages      (DBusConnection             *connection,
288                                                                  dbus_bool_t                 value);
289
290
291 /* Filters */
292
293 DBUS_EXPORT
294 dbus_bool_t dbus_connection_add_filter    (DBusConnection            *connection,
295                                            DBusHandleMessageFunction  function,
296                                            void                      *user_data,
297                                            DBusFreeFunction           free_data_function);
298 DBUS_EXPORT
299 void        dbus_connection_remove_filter (DBusConnection            *connection,
300                                            DBusHandleMessageFunction  function,
301                                            void                      *user_data);
302
303
304 /* Other */
305 DBUS_EXPORT
306 dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t     *slot_p);
307 DBUS_EXPORT
308 void        dbus_connection_free_data_slot     (dbus_int32_t     *slot_p);
309 DBUS_EXPORT
310 dbus_bool_t dbus_connection_set_data           (DBusConnection   *connection,
311                                                 dbus_int32_t      slot,
312                                                 void             *data,
313                                                 DBusFreeFunction  free_data_func);
314 DBUS_EXPORT
315 void*       dbus_connection_get_data           (DBusConnection   *connection,
316                                                 dbus_int32_t      slot);
317
318 DBUS_EXPORT
319 void        dbus_connection_set_change_sigpipe (dbus_bool_t       will_modify_sigpipe); 
320
321 DBUS_EXPORT
322 void dbus_connection_set_max_message_size  (DBusConnection *connection,
323                                             long            size);
324 DBUS_EXPORT
325 long dbus_connection_get_max_message_size  (DBusConnection *connection);
326 DBUS_EXPORT
327 void dbus_connection_set_max_received_size (DBusConnection *connection,
328                                             long            size);
329 DBUS_EXPORT
330 long dbus_connection_get_max_received_size (DBusConnection *connection);
331
332 DBUS_EXPORT
333 void dbus_connection_set_max_message_unix_fds (DBusConnection *connection,
334                                                long            n);
335 DBUS_EXPORT
336 long dbus_connection_get_max_message_unix_fds (DBusConnection *connection);
337 DBUS_EXPORT
338 void dbus_connection_set_max_received_unix_fds(DBusConnection *connection,
339                                                long            n);
340 DBUS_EXPORT
341 long dbus_connection_get_max_received_unix_fds(DBusConnection *connection);
342
343 DBUS_EXPORT
344 long dbus_connection_get_outgoing_size     (DBusConnection *connection);
345 DBUS_EXPORT
346 long dbus_connection_get_outgoing_unix_fds (DBusConnection *connection);
347
348 DBUS_EXPORT
349 DBusPreallocatedSend* dbus_connection_preallocate_send       (DBusConnection       *connection);
350 DBUS_EXPORT
351 void                  dbus_connection_free_preallocated_send (DBusConnection       *connection,
352                                                               DBusPreallocatedSend *preallocated);
353 DBUS_EXPORT
354 void                  dbus_connection_send_preallocated      (DBusConnection       *connection,
355                                                               DBusPreallocatedSend *preallocated,
356                                                               DBusMessage          *message,
357                                                               dbus_uint32_t        *client_serial);
358
359
360 /* Object tree functionality */
361
362 /**
363  * Called when a #DBusObjectPathVTable is unregistered (or its connection is freed).
364  * Found in #DBusObjectPathVTable.
365  */
366 typedef void              (* DBusObjectPathUnregisterFunction) (DBusConnection  *connection,
367                                                                 void            *user_data);
368 /**
369  * Called when a message is sent to a registered object path. Found in
370  * #DBusObjectPathVTable which is registered with dbus_connection_register_object_path()
371  * or dbus_connection_register_fallback().
372  */
373 typedef DBusHandlerResult (* DBusObjectPathMessageFunction)    (DBusConnection  *connection,
374                                                                 DBusMessage     *message,
375                                                                 void            *user_data);
376
377 /**
378  * Virtual table that must be implemented to handle a portion of the
379  * object path hierarchy. Attach the vtable to a particular path using
380  * dbus_connection_register_object_path() or
381  * dbus_connection_register_fallback().
382  */
383 struct DBusObjectPathVTable
384 {
385   DBusObjectPathUnregisterFunction   unregister_function; /**< Function to unregister this handler */
386   DBusObjectPathMessageFunction      message_function; /**< Function to handle messages */
387   
388   void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */
389   void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */
390   void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */
391   void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */
392 };
393
394 DBUS_EXPORT
395 dbus_bool_t dbus_connection_try_register_object_path (DBusConnection              *connection,
396                                                       const char                  *path,
397                                                       const DBusObjectPathVTable  *vtable,
398                                                       void                        *user_data,
399                                                       DBusError                   *error);
400
401 DBUS_EXPORT
402 dbus_bool_t dbus_connection_register_object_path   (DBusConnection              *connection,
403                                                     const char                  *path,
404                                                     const DBusObjectPathVTable  *vtable,
405                                                     void                        *user_data);
406
407 DBUS_EXPORT
408 dbus_bool_t dbus_connection_try_register_fallback (DBusConnection              *connection,
409                                                    const char                  *path,
410                                                    const DBusObjectPathVTable  *vtable,
411                                                    void                        *user_data,
412                                                    DBusError                   *error);
413
414 DBUS_EXPORT
415 dbus_bool_t dbus_connection_register_fallback      (DBusConnection              *connection,
416                                                     const char                  *path,
417                                                     const DBusObjectPathVTable  *vtable,
418                                                     void                        *user_data);
419 DBUS_EXPORT
420 dbus_bool_t dbus_connection_unregister_object_path (DBusConnection              *connection,
421                                                     const char                  *path);
422
423 DBUS_EXPORT
424 dbus_bool_t dbus_connection_get_object_path_data   (DBusConnection              *connection,
425                                                     const char                  *path,
426                                                     void                       **data_p);
427
428 DBUS_EXPORT
429 dbus_bool_t dbus_connection_list_registered        (DBusConnection              *connection,
430                                                     const char                  *parent_path,
431                                                     char                      ***child_entries);
432
433 DBUS_EXPORT
434 dbus_bool_t dbus_connection_get_unix_fd            (DBusConnection              *connection,
435                                                     int                         *fd);
436 DBUS_EXPORT
437 dbus_bool_t dbus_connection_get_socket             (DBusConnection              *connection,
438                                                     int                         *fd);
439
440 /** @} */
441
442
443 /**
444  * @addtogroup DBusWatch
445  * @{
446  */
447
448 #ifndef DBUS_DISABLE_DEPRECATED
449 DBUS_EXPORT
450 DBUS_DEPRECATED int dbus_watch_get_fd      (DBusWatch        *watch);
451 #endif
452
453 DBUS_EXPORT
454 int          dbus_watch_get_unix_fd (DBusWatch        *watch);
455 DBUS_EXPORT
456 int          dbus_watch_get_socket  (DBusWatch        *watch);
457 DBUS_EXPORT
458 unsigned int dbus_watch_get_flags   (DBusWatch        *watch);
459 DBUS_EXPORT
460 void*        dbus_watch_get_data    (DBusWatch        *watch);
461 DBUS_EXPORT
462 void         dbus_watch_set_data    (DBusWatch        *watch,
463                                      void             *data,
464                                      DBusFreeFunction  free_data_function);
465 DBUS_EXPORT
466 dbus_bool_t  dbus_watch_handle      (DBusWatch        *watch,
467                                      unsigned int      flags);
468 DBUS_EXPORT
469 dbus_bool_t  dbus_watch_get_enabled (DBusWatch        *watch);
470
471 /** @} */
472
473 /**
474  * @addtogroup DBusTimeout
475  * @{
476  */
477
478 DBUS_EXPORT
479 int         dbus_timeout_get_interval (DBusTimeout      *timeout);
480 DBUS_EXPORT
481 void*       dbus_timeout_get_data     (DBusTimeout      *timeout);
482 DBUS_EXPORT
483 void        dbus_timeout_set_data     (DBusTimeout      *timeout,
484                                        void             *data,
485                                        DBusFreeFunction  free_data_function);
486 DBUS_EXPORT
487 dbus_bool_t dbus_timeout_handle       (DBusTimeout      *timeout);
488 DBUS_EXPORT
489 dbus_bool_t dbus_timeout_get_enabled  (DBusTimeout      *timeout);
490
491 /** @} */
492
493 DBUS_END_DECLS
494
495 #endif /* DBUS_CONNECTION_H */