1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-connection.h DBusConnection object
4 * Copyright (C) 2002, 2003 Red Hat Inc.
6 * Licensed under the Academic Free License version 2.1
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.
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.
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
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."
27 #ifndef DBUS_CONNECTION_H
28 #define DBUS_CONNECTION_H
30 #include <dbus/dbus-errors.h>
31 #include <dbus/dbus-memory.h>
32 #include <dbus/dbus-message.h>
33 #include <dbus/dbus-shared.h>
38 * @addtogroup DBusConnection
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;
56 * Indicates the status of a #DBusWatch.
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()).
67 DBUS_WATCH_HANGUP = 1 << 3 /**< As in POLLHUP (can't watch for
68 * it, but can be present in current
70 * dbus_watch_handle()).
72 /* Internal to libdbus, there is also _DBUS_WATCH_NVAL in dbus-watch.h */
76 * Indicates the status of incoming data on a #DBusConnection. This determines whether
77 * dbus_connection_dispatch() needs to be called.
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. */
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().
91 typedef dbus_bool_t (* DBusAddWatchFunction) (DBusWatch *watch,
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().
97 typedef void (* DBusWatchToggledFunction) (DBusWatch *watch,
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().
103 typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch,
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().
110 typedef dbus_bool_t (* DBusAddTimeoutFunction) (DBusTimeout *timeout,
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().
117 typedef void (* DBusTimeoutToggledFunction) (DBusTimeout *timeout,
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().
123 typedef void (* DBusRemoveTimeoutFunction) (DBusTimeout *timeout,
125 /** Called when the return value of dbus_connection_get_dispatch_status()
126 * may have changed. Set with dbus_connection_set_dispatch_status_function().
128 typedef void (* DBusDispatchStatusFunction) (DBusConnection *connection,
129 DBusDispatchStatus new_status,
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().
135 typedef void (* DBusWakeupMainFunction) (void *data);
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().
143 typedef dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection,
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().
153 typedef dbus_bool_t (* DBusAllowWindowsUserFunction) (DBusConnection *connection,
154 const char *user_sid,
159 * Called when a pending call now has a reply available. Set with
160 * dbus_pending_call_set_notify().
162 typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
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().
169 typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection *connection,
170 DBusMessage *message,
174 DBusMessage * generate_local_error_message (dbus_uint32_t serial,
178 DBusConnection* dbus_connection_open (const char *address,
181 DBusConnection* dbus_connection_open_private (const char *address,
184 DBusConnection* dbus_connection_ref (DBusConnection *connection);
186 void dbus_connection_unref (DBusConnection *connection);
187 #ifdef ENABLE_KDBUS_TRANSPORT
189 void dbus_connection_unref_phantom (DBusConnection *connection);
192 void dbus_connection_close (DBusConnection *connection);
194 dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection);
196 dbus_bool_t dbus_connection_get_is_authenticated (DBusConnection *connection);
197 #ifdef ENABLE_KDBUS_TRANSPORT
199 dbus_bool_t dbus_connection_set_is_authenticated (DBusConnection *connection);
202 dbus_bool_t dbus_connection_get_is_anonymous (DBusConnection *connection);
204 char* dbus_connection_get_server_id (DBusConnection *connection);
206 dbus_bool_t dbus_connection_can_send_type (DBusConnection *connection,
210 void dbus_connection_set_exit_on_disconnect (DBusConnection *connection,
211 dbus_bool_t exit_on_disconnect);
213 void dbus_connection_flush (DBusConnection *connection);
215 dbus_bool_t dbus_connection_read_write_dispatch (DBusConnection *connection,
216 int timeout_milliseconds);
218 dbus_bool_t dbus_connection_read_write (DBusConnection *connection,
219 int timeout_milliseconds);
221 DBusMessage* dbus_connection_borrow_message (DBusConnection *connection);
223 void dbus_connection_return_message (DBusConnection *connection,
224 DBusMessage *message);
226 void dbus_connection_steal_borrowed_message (DBusConnection *connection,
227 DBusMessage *message);
229 DBusMessage* dbus_connection_pop_message (DBusConnection *connection);
231 DBusDispatchStatus dbus_connection_get_dispatch_status (DBusConnection *connection);
233 DBusDispatchStatus dbus_connection_dispatch (DBusConnection *connection);
235 dbus_bool_t dbus_connection_has_messages_to_send (DBusConnection *connection);
237 dbus_bool_t dbus_connection_send (DBusConnection *connection,
238 DBusMessage *message,
239 dbus_uint32_t *client_serial);
241 dbus_bool_t dbus_connection_send_with_reply (DBusConnection *connection,
242 DBusMessage *message,
243 DBusPendingCall **pending_return,
244 int timeout_milliseconds);
246 DBusMessage * dbus_connection_send_with_reply_and_block (DBusConnection *connection,
247 DBusMessage *message,
248 int timeout_milliseconds,
251 dbus_bool_t dbus_connection_set_watch_functions (DBusConnection *connection,
252 DBusAddWatchFunction add_function,
253 DBusRemoveWatchFunction remove_function,
254 DBusWatchToggledFunction toggled_function,
256 DBusFreeFunction free_data_function);
258 dbus_bool_t dbus_connection_set_timeout_functions (DBusConnection *connection,
259 DBusAddTimeoutFunction add_function,
260 DBusRemoveTimeoutFunction remove_function,
261 DBusTimeoutToggledFunction toggled_function,
263 DBusFreeFunction free_data_function);
265 void dbus_connection_set_wakeup_main_function (DBusConnection *connection,
266 DBusWakeupMainFunction wakeup_main_function,
268 DBusFreeFunction free_data_function);
270 void dbus_connection_set_dispatch_status_function (DBusConnection *connection,
271 DBusDispatchStatusFunction function,
273 DBusFreeFunction free_data_function);
275 dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection,
278 dbus_bool_t dbus_connection_get_unix_process_id (DBusConnection *connection,
280 #ifdef ENABLE_KDBUS_TRANSPORT
282 dbus_bool_t dbus_connection_get_unix_user_dbus (DBusConnection *connection,
285 dbus_bool_t dbus_connection_get_unix_process_id_dbus (DBusConnection *connection,
289 dbus_bool_t dbus_connection_get_adt_audit_session_data (DBusConnection *connection,
291 dbus_int32_t *data_size);
293 void dbus_connection_set_unix_user_function (DBusConnection *connection,
294 DBusAllowUnixUserFunction function,
296 DBusFreeFunction free_data_function);
298 dbus_bool_t dbus_connection_get_windows_user (DBusConnection *connection,
299 char **windows_sid_p);
301 void dbus_connection_set_windows_user_function (DBusConnection *connection,
302 DBusAllowWindowsUserFunction function,
304 DBusFreeFunction free_data_function);
306 void dbus_connection_set_allow_anonymous (DBusConnection *connection,
309 void dbus_connection_set_route_peer_messages (DBusConnection *connection,
316 dbus_bool_t dbus_connection_add_filter (DBusConnection *connection,
317 DBusHandleMessageFunction function,
319 DBusFreeFunction free_data_function);
321 void dbus_connection_remove_filter (DBusConnection *connection,
322 DBusHandleMessageFunction function,
328 dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t *slot_p);
330 void dbus_connection_free_data_slot (dbus_int32_t *slot_p);
332 dbus_bool_t dbus_connection_set_data (DBusConnection *connection,
335 DBusFreeFunction free_data_func);
337 void* dbus_connection_get_data (DBusConnection *connection,
341 void dbus_connection_set_change_sigpipe (dbus_bool_t will_modify_sigpipe);
344 void dbus_connection_set_max_message_size (DBusConnection *connection,
347 long dbus_connection_get_max_message_size (DBusConnection *connection);
349 void dbus_connection_set_max_received_size (DBusConnection *connection,
352 long dbus_connection_get_max_received_size (DBusConnection *connection);
355 void dbus_connection_set_max_message_unix_fds (DBusConnection *connection,
358 long dbus_connection_get_max_message_unix_fds (DBusConnection *connection);
360 void dbus_connection_set_max_received_unix_fds(DBusConnection *connection,
363 long dbus_connection_get_max_received_unix_fds(DBusConnection *connection);
366 long dbus_connection_get_outgoing_size (DBusConnection *connection);
368 long dbus_connection_get_outgoing_unix_fds (DBusConnection *connection);
371 DBusPreallocatedSend* dbus_connection_preallocate_send (DBusConnection *connection);
373 void dbus_connection_free_preallocated_send (DBusConnection *connection,
374 DBusPreallocatedSend *preallocated);
376 void dbus_connection_send_preallocated (DBusConnection *connection,
377 DBusPreallocatedSend *preallocated,
378 DBusMessage *message,
379 dbus_uint32_t *client_serial);
382 /* Object tree functionality */
385 * Called when a #DBusObjectPathVTable is unregistered (or its connection is freed).
386 * Found in #DBusObjectPathVTable.
388 typedef void (* DBusObjectPathUnregisterFunction) (DBusConnection *connection,
391 * Called when a message is sent to a registered object path. Found in
392 * #DBusObjectPathVTable which is registered with dbus_connection_register_object_path()
393 * or dbus_connection_register_fallback().
395 typedef DBusHandlerResult (* DBusObjectPathMessageFunction) (DBusConnection *connection,
396 DBusMessage *message,
400 * Virtual table that must be implemented to handle a portion of the
401 * object path hierarchy. Attach the vtable to a particular path using
402 * dbus_connection_register_object_path() or
403 * dbus_connection_register_fallback().
405 struct DBusObjectPathVTable
407 DBusObjectPathUnregisterFunction unregister_function; /**< Function to unregister this handler */
408 DBusObjectPathMessageFunction message_function; /**< Function to handle messages */
410 void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */
411 void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */
412 void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */
413 void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */
417 dbus_bool_t dbus_connection_try_register_object_path (DBusConnection *connection,
419 const DBusObjectPathVTable *vtable,
424 dbus_bool_t dbus_connection_register_object_path (DBusConnection *connection,
426 const DBusObjectPathVTable *vtable,
430 dbus_bool_t dbus_connection_try_register_fallback (DBusConnection *connection,
432 const DBusObjectPathVTable *vtable,
437 dbus_bool_t dbus_connection_register_fallback (DBusConnection *connection,
439 const DBusObjectPathVTable *vtable,
442 dbus_bool_t dbus_connection_unregister_object_path (DBusConnection *connection,
446 dbus_bool_t dbus_connection_get_object_path_data (DBusConnection *connection,
451 dbus_bool_t dbus_connection_list_registered (DBusConnection *connection,
452 const char *parent_path,
453 char ***child_entries);
456 dbus_bool_t dbus_connection_get_unix_fd (DBusConnection *connection,
459 dbus_bool_t dbus_connection_get_socket (DBusConnection *connection,
466 * @addtogroup DBusWatch
470 #ifndef DBUS_DISABLE_DEPRECATED
472 DBUS_DEPRECATED int dbus_watch_get_fd (DBusWatch *watch);
476 int dbus_watch_get_unix_fd (DBusWatch *watch);
478 int dbus_watch_get_socket (DBusWatch *watch);
480 unsigned int dbus_watch_get_flags (DBusWatch *watch);
482 void* dbus_watch_get_data (DBusWatch *watch);
484 void dbus_watch_set_data (DBusWatch *watch,
486 DBusFreeFunction free_data_function);
488 dbus_bool_t dbus_watch_handle (DBusWatch *watch,
491 dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch);
496 * @addtogroup DBusTimeout
501 int dbus_timeout_get_interval (DBusTimeout *timeout);
503 void* dbus_timeout_get_data (DBusTimeout *timeout);
505 void dbus_timeout_set_data (DBusTimeout *timeout,
507 DBusFreeFunction free_data_function);
509 dbus_bool_t dbus_timeout_handle (DBusTimeout *timeout);
511 dbus_bool_t dbus_timeout_get_enabled (DBusTimeout *timeout);
517 #endif /* DBUS_CONNECTION_H */