[daemon-dev][daemon-fix] starting services by direct message (autostart) and some...
[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   /* Internal to libdbus, there is also _DBUS_WATCH_NVAL in dbus-watch.h */
73 } DBusWatchFlags;
74
75 /**
76  * Indicates the status of incoming data on a #DBusConnection. This determines whether
77  * dbus_connection_dispatch() needs to be called.
78  */
79 typedef enum
80 {
81   DBUS_DISPATCH_DATA_REMAINS,  /**< There is more data to potentially convert to messages. */
82   DBUS_DISPATCH_COMPLETE,      /**< All currently available data has been processed. */
83   DBUS_DISPATCH_NEED_MEMORY    /**< More memory is needed to continue. */
84 } DBusDispatchStatus;
85
86 /** Called when libdbus needs a new watch to be monitored by the main
87  * loop. Returns #FALSE if it lacks enough memory to add the
88  * watch. Set by dbus_connection_set_watch_functions() or
89  * dbus_server_set_watch_functions().
90  */
91 typedef dbus_bool_t (* DBusAddWatchFunction)       (DBusWatch      *watch,
92                                                     void           *data);
93 /** Called when dbus_watch_get_enabled() may return a different value
94  *  than it did before.  Set by dbus_connection_set_watch_functions()
95  *  or dbus_server_set_watch_functions().
96  */
97 typedef void        (* DBusWatchToggledFunction)   (DBusWatch      *watch,
98                                                     void           *data);
99 /** Called when libdbus no longer needs a watch to be monitored by the
100  * main loop. Set by dbus_connection_set_watch_functions() or
101  * dbus_server_set_watch_functions().
102  */
103 typedef void        (* DBusRemoveWatchFunction)    (DBusWatch      *watch,
104                                                     void           *data);
105 /** Called when libdbus needs a new timeout to be monitored by the main
106  * loop. Returns #FALSE if it lacks enough memory to add the
107  * watch. Set by dbus_connection_set_timeout_functions() or
108  * dbus_server_set_timeout_functions().
109  */
110 typedef dbus_bool_t (* DBusAddTimeoutFunction)     (DBusTimeout    *timeout,
111                                                     void           *data);
112 /** Called when dbus_timeout_get_enabled() may return a different
113  * value than it did before.
114  * Set by dbus_connection_set_timeout_functions() or
115  * dbus_server_set_timeout_functions().
116  */
117 typedef void        (* DBusTimeoutToggledFunction) (DBusTimeout    *timeout,
118                                                     void           *data);
119 /** Called when libdbus no longer needs a timeout to be monitored by the
120  * main loop. Set by dbus_connection_set_timeout_functions() or
121  * dbus_server_set_timeout_functions().
122  */
123 typedef void        (* DBusRemoveTimeoutFunction)  (DBusTimeout    *timeout,
124                                                     void           *data);
125 /** Called when the return value of dbus_connection_get_dispatch_status()
126  * may have changed. Set with dbus_connection_set_dispatch_status_function().
127  */
128 typedef void        (* DBusDispatchStatusFunction) (DBusConnection *connection,
129                                                     DBusDispatchStatus new_status,
130                                                     void           *data);
131 /**
132  * Called when the main loop's thread should be notified that there's now work
133  * to do. Set with dbus_connection_set_wakeup_main_function().
134  */
135 typedef void        (* DBusWakeupMainFunction)     (void           *data);
136
137 /**
138  * Called during authentication to check whether the given UNIX user
139  * ID is allowed to connect, if the client tried to auth as a UNIX
140  * user ID. Normally on Windows this would never happen. Set with
141  * dbus_connection_set_unix_user_function().
142  */ 
143 typedef dbus_bool_t (* DBusAllowUnixUserFunction)  (DBusConnection *connection,
144                                                     unsigned long   uid,
145                                                     void           *data);
146
147 /**
148  * Called during authentication to check whether the given Windows user
149  * ID is allowed to connect, if the client tried to auth as a Windows
150  * user ID. Normally on UNIX this would never happen. Set with
151  * dbus_connection_set_windows_user_function().
152  */ 
153 typedef dbus_bool_t (* DBusAllowWindowsUserFunction)  (DBusConnection *connection,
154                                                        const char     *user_sid,
155                                                        void           *data);
156
157
158 /**
159  * Called when a pending call now has a reply available. Set with
160  * dbus_pending_call_set_notify().
161  */
162 typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
163                                                 void            *user_data);
164
165 /**
166  * Called when a message needs to be handled. The result indicates whether or
167  * not more handlers should be run. Set with dbus_connection_add_filter().
168  */
169 typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection     *connection,
170                                                          DBusMessage        *message,
171                                                          void               *user_data);
172
173 DBUS_EXPORT
174 DBusMessage *      generate_local_error_message                                 (dbus_uint32_t serial,
175                                                                                                  char *error_name,
176                                                                                                  char *error_msg);
177 DBUS_EXPORT
178 DBusConnection*    dbus_connection_open                         (const char                 *address,
179                                                                  DBusError                  *error);
180 DBUS_EXPORT
181 DBusConnection*    dbus_connection_open_private                 (const char                 *address,
182                                                                  DBusError                  *error);
183 DBUS_EXPORT
184 DBusConnection*    dbus_connection_ref                          (DBusConnection             *connection);
185 DBUS_EXPORT
186 void               dbus_connection_unref                        (DBusConnection             *connection);
187 DBUS_EXPORT
188 void               dbus_connection_unref_phantom               (DBusConnection             *connection);
189 DBUS_EXPORT
190 void               dbus_connection_close                        (DBusConnection             *connection);
191 DBUS_EXPORT
192 dbus_bool_t        dbus_connection_get_is_connected             (DBusConnection             *connection);
193 DBUS_EXPORT
194 dbus_bool_t        dbus_connection_get_is_authenticated         (DBusConnection             *connection);
195 DBUS_EXPORT
196 dbus_bool_t        dbus_connection_set_is_authenticated         (DBusConnection             *connection);
197 DBUS_EXPORT
198 dbus_bool_t        dbus_connection_get_is_anonymous             (DBusConnection             *connection);
199 DBUS_EXPORT
200 char*              dbus_connection_get_server_id                (DBusConnection             *connection);
201 DBUS_EXPORT
202 dbus_bool_t        dbus_connection_can_send_type                (DBusConnection             *connection,
203                                                                  int                         type);
204
205 DBUS_EXPORT
206 void               dbus_connection_set_exit_on_disconnect       (DBusConnection             *connection,
207                                                                  dbus_bool_t                 exit_on_disconnect);
208 DBUS_EXPORT
209 void               dbus_connection_flush                        (DBusConnection             *connection);
210 DBUS_EXPORT
211 dbus_bool_t        dbus_connection_read_write_dispatch          (DBusConnection             *connection,
212                                                                  int                         timeout_milliseconds);
213 DBUS_EXPORT
214 dbus_bool_t        dbus_connection_read_write                   (DBusConnection             *connection,
215                                                                  int                         timeout_milliseconds);
216 DBUS_EXPORT
217 DBusMessage*       dbus_connection_borrow_message               (DBusConnection             *connection);
218 DBUS_EXPORT
219 void               dbus_connection_return_message               (DBusConnection             *connection,
220                                                                  DBusMessage                *message);
221 DBUS_EXPORT
222 void               dbus_connection_steal_borrowed_message       (DBusConnection             *connection,
223                                                                  DBusMessage                *message);
224 DBUS_EXPORT
225 DBusMessage*       dbus_connection_pop_message                  (DBusConnection             *connection);
226 DBUS_EXPORT
227 DBusDispatchStatus dbus_connection_get_dispatch_status          (DBusConnection             *connection);
228 DBUS_EXPORT
229 DBusDispatchStatus dbus_connection_dispatch                     (DBusConnection             *connection);
230 DBUS_EXPORT
231 dbus_bool_t        dbus_connection_has_messages_to_send         (DBusConnection *connection);
232 DBUS_EXPORT
233 dbus_bool_t        dbus_connection_send                         (DBusConnection             *connection,
234                                                                  DBusMessage                *message,
235                                                                  dbus_uint32_t              *client_serial);
236 DBUS_EXPORT
237 dbus_bool_t        dbus_connection_send_with_reply              (DBusConnection             *connection,
238                                                                  DBusMessage                *message,
239                                                                  DBusPendingCall           **pending_return,
240                                                                  int                         timeout_milliseconds);
241 DBUS_EXPORT
242 DBusMessage *      dbus_connection_send_with_reply_and_block    (DBusConnection             *connection,
243                                                                  DBusMessage                *message,
244                                                                  int                         timeout_milliseconds,
245                                                                  DBusError                  *error);
246 DBUS_EXPORT
247 dbus_bool_t        dbus_connection_set_watch_functions          (DBusConnection             *connection,
248                                                                  DBusAddWatchFunction        add_function,
249                                                                  DBusRemoveWatchFunction     remove_function,
250                                                                  DBusWatchToggledFunction    toggled_function,
251                                                                  void                       *data,
252                                                                  DBusFreeFunction            free_data_function);
253 DBUS_EXPORT
254 dbus_bool_t        dbus_connection_set_timeout_functions        (DBusConnection             *connection,
255                                                                  DBusAddTimeoutFunction      add_function,
256                                                                  DBusRemoveTimeoutFunction   remove_function,
257                                                                  DBusTimeoutToggledFunction  toggled_function,
258                                                                  void                       *data,
259                                                                  DBusFreeFunction            free_data_function);
260 DBUS_EXPORT
261 void               dbus_connection_set_wakeup_main_function     (DBusConnection             *connection,
262                                                                  DBusWakeupMainFunction      wakeup_main_function,
263                                                                  void                       *data,
264                                                                  DBusFreeFunction            free_data_function);
265 DBUS_EXPORT
266 void               dbus_connection_set_dispatch_status_function (DBusConnection             *connection,
267                                                                  DBusDispatchStatusFunction  function,
268                                                                  void                       *data,
269                                                                  DBusFreeFunction            free_data_function);
270 DBUS_EXPORT
271 dbus_bool_t        dbus_connection_get_unix_user                (DBusConnection             *connection,
272                                                                  unsigned long              *uid);
273 DBUS_EXPORT
274 dbus_bool_t        dbus_connection_get_unix_process_id          (DBusConnection             *connection,
275                                                                  unsigned long              *pid);
276 DBUS_EXPORT
277 dbus_bool_t        dbus_connection_get_adt_audit_session_data   (DBusConnection             *connection,
278                                                                  void                      **data,
279                                                                  dbus_int32_t               *data_size);
280 DBUS_EXPORT
281 void               dbus_connection_set_unix_user_function       (DBusConnection             *connection,
282                                                                  DBusAllowUnixUserFunction   function,
283                                                                  void                       *data,
284                                                                  DBusFreeFunction            free_data_function);
285 DBUS_EXPORT
286 dbus_bool_t        dbus_connection_get_windows_user             (DBusConnection             *connection,
287                                                                  char                      **windows_sid_p); 
288 DBUS_EXPORT
289 void               dbus_connection_set_windows_user_function    (DBusConnection             *connection,
290                                                                  DBusAllowWindowsUserFunction function,
291                                                                  void                       *data,
292                                                                  DBusFreeFunction            free_data_function);
293 DBUS_EXPORT
294 void               dbus_connection_set_allow_anonymous          (DBusConnection             *connection,
295                                                                  dbus_bool_t                 value);
296 DBUS_EXPORT
297 void               dbus_connection_set_route_peer_messages      (DBusConnection             *connection,
298                                                                  dbus_bool_t                 value);
299
300
301 /* Filters */
302
303 DBUS_EXPORT
304 dbus_bool_t dbus_connection_add_filter    (DBusConnection            *connection,
305                                            DBusHandleMessageFunction  function,
306                                            void                      *user_data,
307                                            DBusFreeFunction           free_data_function);
308 DBUS_EXPORT
309 void        dbus_connection_remove_filter (DBusConnection            *connection,
310                                            DBusHandleMessageFunction  function,
311                                            void                      *user_data);
312
313
314 /* Other */
315 DBUS_EXPORT
316 dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t     *slot_p);
317 DBUS_EXPORT
318 void        dbus_connection_free_data_slot     (dbus_int32_t     *slot_p);
319 DBUS_EXPORT
320 dbus_bool_t dbus_connection_set_data           (DBusConnection   *connection,
321                                                 dbus_int32_t      slot,
322                                                 void             *data,
323                                                 DBusFreeFunction  free_data_func);
324 DBUS_EXPORT
325 void*       dbus_connection_get_data           (DBusConnection   *connection,
326                                                 dbus_int32_t      slot);
327
328 DBUS_EXPORT
329 void        dbus_connection_set_change_sigpipe (dbus_bool_t       will_modify_sigpipe); 
330
331 DBUS_EXPORT
332 void dbus_connection_set_max_message_size  (DBusConnection *connection,
333                                             long            size);
334 DBUS_EXPORT
335 long dbus_connection_get_max_message_size  (DBusConnection *connection);
336 DBUS_EXPORT
337 void dbus_connection_set_max_received_size (DBusConnection *connection,
338                                             long            size);
339 DBUS_EXPORT
340 long dbus_connection_get_max_received_size (DBusConnection *connection);
341
342 DBUS_EXPORT
343 void dbus_connection_set_max_message_unix_fds (DBusConnection *connection,
344                                                long            n);
345 DBUS_EXPORT
346 long dbus_connection_get_max_message_unix_fds (DBusConnection *connection);
347 DBUS_EXPORT
348 void dbus_connection_set_max_received_unix_fds(DBusConnection *connection,
349                                                long            n);
350 DBUS_EXPORT
351 long dbus_connection_get_max_received_unix_fds(DBusConnection *connection);
352
353 DBUS_EXPORT
354 long dbus_connection_get_outgoing_size     (DBusConnection *connection);
355 DBUS_EXPORT
356 long dbus_connection_get_outgoing_unix_fds (DBusConnection *connection);
357
358 DBUS_EXPORT
359 DBusPreallocatedSend* dbus_connection_preallocate_send       (DBusConnection       *connection);
360 DBUS_EXPORT
361 void                  dbus_connection_free_preallocated_send (DBusConnection       *connection,
362                                                               DBusPreallocatedSend *preallocated);
363 DBUS_EXPORT
364 void                  dbus_connection_send_preallocated      (DBusConnection       *connection,
365                                                               DBusPreallocatedSend *preallocated,
366                                                               DBusMessage          *message,
367                                                               dbus_uint32_t        *client_serial);
368
369
370 /* Object tree functionality */
371
372 /**
373  * Called when a #DBusObjectPathVTable is unregistered (or its connection is freed).
374  * Found in #DBusObjectPathVTable.
375  */
376 typedef void              (* DBusObjectPathUnregisterFunction) (DBusConnection  *connection,
377                                                                 void            *user_data);
378 /**
379  * Called when a message is sent to a registered object path. Found in
380  * #DBusObjectPathVTable which is registered with dbus_connection_register_object_path()
381  * or dbus_connection_register_fallback().
382  */
383 typedef DBusHandlerResult (* DBusObjectPathMessageFunction)    (DBusConnection  *connection,
384                                                                 DBusMessage     *message,
385                                                                 void            *user_data);
386
387 /**
388  * Virtual table that must be implemented to handle a portion of the
389  * object path hierarchy. Attach the vtable to a particular path using
390  * dbus_connection_register_object_path() or
391  * dbus_connection_register_fallback().
392  */
393 struct DBusObjectPathVTable
394 {
395   DBusObjectPathUnregisterFunction   unregister_function; /**< Function to unregister this handler */
396   DBusObjectPathMessageFunction      message_function; /**< Function to handle messages */
397   
398   void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */
399   void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */
400   void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */
401   void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */
402 };
403
404 DBUS_EXPORT
405 dbus_bool_t dbus_connection_try_register_object_path (DBusConnection              *connection,
406                                                       const char                  *path,
407                                                       const DBusObjectPathVTable  *vtable,
408                                                       void                        *user_data,
409                                                       DBusError                   *error);
410
411 DBUS_EXPORT
412 dbus_bool_t dbus_connection_register_object_path   (DBusConnection              *connection,
413                                                     const char                  *path,
414                                                     const DBusObjectPathVTable  *vtable,
415                                                     void                        *user_data);
416
417 DBUS_EXPORT
418 dbus_bool_t dbus_connection_try_register_fallback (DBusConnection              *connection,
419                                                    const char                  *path,
420                                                    const DBusObjectPathVTable  *vtable,
421                                                    void                        *user_data,
422                                                    DBusError                   *error);
423
424 DBUS_EXPORT
425 dbus_bool_t dbus_connection_register_fallback      (DBusConnection              *connection,
426                                                     const char                  *path,
427                                                     const DBusObjectPathVTable  *vtable,
428                                                     void                        *user_data);
429 DBUS_EXPORT
430 dbus_bool_t dbus_connection_unregister_object_path (DBusConnection              *connection,
431                                                     const char                  *path);
432
433 DBUS_EXPORT
434 dbus_bool_t dbus_connection_get_object_path_data   (DBusConnection              *connection,
435                                                     const char                  *path,
436                                                     void                       **data_p);
437
438 DBUS_EXPORT
439 dbus_bool_t dbus_connection_list_registered        (DBusConnection              *connection,
440                                                     const char                  *parent_path,
441                                                     char                      ***child_entries);
442
443 DBUS_EXPORT
444 dbus_bool_t dbus_connection_get_unix_fd            (DBusConnection              *connection,
445                                                     int                         *fd);
446 DBUS_EXPORT
447 dbus_bool_t dbus_connection_get_socket             (DBusConnection              *connection,
448                                                     int                         *fd);
449
450 /** @} */
451
452
453 /**
454  * @addtogroup DBusWatch
455  * @{
456  */
457
458 #ifndef DBUS_DISABLE_DEPRECATED
459 DBUS_EXPORT
460 DBUS_DEPRECATED int dbus_watch_get_fd      (DBusWatch        *watch);
461 #endif
462
463 DBUS_EXPORT
464 int          dbus_watch_get_unix_fd (DBusWatch        *watch);
465 DBUS_EXPORT
466 int          dbus_watch_get_socket  (DBusWatch        *watch);
467 DBUS_EXPORT
468 unsigned int dbus_watch_get_flags   (DBusWatch        *watch);
469 DBUS_EXPORT
470 void*        dbus_watch_get_data    (DBusWatch        *watch);
471 DBUS_EXPORT
472 void         dbus_watch_set_data    (DBusWatch        *watch,
473                                      void             *data,
474                                      DBusFreeFunction  free_data_function);
475 DBUS_EXPORT
476 dbus_bool_t  dbus_watch_handle      (DBusWatch        *watch,
477                                      unsigned int      flags);
478 DBUS_EXPORT
479 dbus_bool_t  dbus_watch_get_enabled (DBusWatch        *watch);
480
481 /** @} */
482
483 /**
484  * @addtogroup DBusTimeout
485  * @{
486  */
487
488 DBUS_EXPORT
489 int         dbus_timeout_get_interval (DBusTimeout      *timeout);
490 DBUS_EXPORT
491 void*       dbus_timeout_get_data     (DBusTimeout      *timeout);
492 DBUS_EXPORT
493 void        dbus_timeout_set_data     (DBusTimeout      *timeout,
494                                        void             *data,
495                                        DBusFreeFunction  free_data_function);
496 DBUS_EXPORT
497 dbus_bool_t dbus_timeout_handle       (DBusTimeout      *timeout);
498 DBUS_EXPORT
499 dbus_bool_t dbus_timeout_get_enabled  (DBusTimeout      *timeout);
500
501 /** @} */
502
503 DBUS_END_DECLS
504
505 #endif /* DBUS_CONNECTION_H */