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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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()).
75 * Indicates the status of incoming data on a #DBusConnection. This determines whether
76 * dbus_connection_dispatch() needs to be called.
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. */
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().
90 typedef dbus_bool_t (* DBusAddWatchFunction) (DBusWatch *watch,
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().
96 typedef void (* DBusWatchToggledFunction) (DBusWatch *watch,
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().
102 typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch,
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().
109 typedef dbus_bool_t (* DBusAddTimeoutFunction) (DBusTimeout *timeout,
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().
116 typedef void (* DBusTimeoutToggledFunction) (DBusTimeout *timeout,
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().
122 typedef void (* DBusRemoveTimeoutFunction) (DBusTimeout *timeout,
124 /** Called when the return value of dbus_connection_get_dispatch_status()
125 * may have changed. Set with dbus_connection_set_dispatch_status_function().
127 typedef void (* DBusDispatchStatusFunction) (DBusConnection *connection,
128 DBusDispatchStatus new_status,
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().
134 typedef void (* DBusWakeupMainFunction) (void *data);
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().
142 typedef dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection,
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().
152 typedef dbus_bool_t (* DBusAllowWindowsUserFunction) (DBusConnection *connection,
153 const char *user_sid,
158 * Called when a pending call now has a reply available. Set with
159 * dbus_pending_call_set_notify().
161 typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
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().
168 typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection *connection,
169 DBusMessage *message,
172 DBusConnection* dbus_connection_open (const char *address,
174 DBusConnection* dbus_connection_open_private (const char *address,
176 DBusConnection* dbus_connection_ref (DBusConnection *connection);
177 void dbus_connection_unref (DBusConnection *connection);
178 void dbus_connection_close (DBusConnection *connection);
179 dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection);
180 dbus_bool_t dbus_connection_get_is_authenticated (DBusConnection *connection);
181 dbus_bool_t dbus_connection_get_is_anonymous (DBusConnection *connection);
182 char* dbus_connection_get_server_id (DBusConnection *connection);
183 dbus_bool_t dbus_connection_can_send_type (DBusConnection *connection,
185 void dbus_connection_set_exit_on_disconnect (DBusConnection *connection,
186 dbus_bool_t exit_on_disconnect);
187 void dbus_connection_flush (DBusConnection *connection);
188 dbus_bool_t dbus_connection_read_write_dispatch (DBusConnection *connection,
189 int timeout_milliseconds);
190 dbus_bool_t dbus_connection_read_write (DBusConnection *connection,
191 int timeout_milliseconds);
192 DBusMessage* dbus_connection_borrow_message (DBusConnection *connection);
193 void dbus_connection_return_message (DBusConnection *connection,
194 DBusMessage *message);
195 void dbus_connection_steal_borrowed_message (DBusConnection *connection,
196 DBusMessage *message);
197 DBusMessage* dbus_connection_pop_message (DBusConnection *connection);
198 DBusDispatchStatus dbus_connection_get_dispatch_status (DBusConnection *connection);
199 DBusDispatchStatus dbus_connection_dispatch (DBusConnection *connection);
200 dbus_bool_t dbus_connection_has_messages_to_send (DBusConnection *connection);
201 dbus_bool_t dbus_connection_send (DBusConnection *connection,
202 DBusMessage *message,
203 dbus_uint32_t *client_serial);
204 dbus_bool_t dbus_connection_send_with_reply (DBusConnection *connection,
205 DBusMessage *message,
206 DBusPendingCall **pending_return,
207 int timeout_milliseconds);
208 DBusMessage * dbus_connection_send_with_reply_and_block (DBusConnection *connection,
209 DBusMessage *message,
210 int timeout_milliseconds,
212 dbus_bool_t dbus_connection_set_watch_functions (DBusConnection *connection,
213 DBusAddWatchFunction add_function,
214 DBusRemoveWatchFunction remove_function,
215 DBusWatchToggledFunction toggled_function,
217 DBusFreeFunction free_data_function);
218 dbus_bool_t dbus_connection_set_timeout_functions (DBusConnection *connection,
219 DBusAddTimeoutFunction add_function,
220 DBusRemoveTimeoutFunction remove_function,
221 DBusTimeoutToggledFunction toggled_function,
223 DBusFreeFunction free_data_function);
224 void dbus_connection_set_wakeup_main_function (DBusConnection *connection,
225 DBusWakeupMainFunction wakeup_main_function,
227 DBusFreeFunction free_data_function);
228 void dbus_connection_set_dispatch_status_function (DBusConnection *connection,
229 DBusDispatchStatusFunction function,
231 DBusFreeFunction free_data_function);
232 dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection,
234 dbus_bool_t dbus_connection_get_unix_process_id (DBusConnection *connection,
236 dbus_bool_t dbus_connection_get_adt_audit_session_data (DBusConnection *connection,
238 dbus_int32_t *data_size);
239 void dbus_connection_set_unix_user_function (DBusConnection *connection,
240 DBusAllowUnixUserFunction function,
242 DBusFreeFunction free_data_function);
243 dbus_bool_t dbus_connection_get_windows_user (DBusConnection *connection,
244 char **windows_sid_p);
245 void dbus_connection_set_windows_user_function (DBusConnection *connection,
246 DBusAllowWindowsUserFunction function,
248 DBusFreeFunction free_data_function);
249 void dbus_connection_set_allow_anonymous (DBusConnection *connection,
251 void dbus_connection_set_route_peer_messages (DBusConnection *connection,
257 dbus_bool_t dbus_connection_add_filter (DBusConnection *connection,
258 DBusHandleMessageFunction function,
260 DBusFreeFunction free_data_function);
261 void dbus_connection_remove_filter (DBusConnection *connection,
262 DBusHandleMessageFunction function,
267 dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t *slot_p);
268 void dbus_connection_free_data_slot (dbus_int32_t *slot_p);
269 dbus_bool_t dbus_connection_set_data (DBusConnection *connection,
272 DBusFreeFunction free_data_func);
273 void* dbus_connection_get_data (DBusConnection *connection,
276 void dbus_connection_set_change_sigpipe (dbus_bool_t will_modify_sigpipe);
278 void dbus_connection_set_max_message_size (DBusConnection *connection,
280 long dbus_connection_get_max_message_size (DBusConnection *connection);
281 void dbus_connection_set_max_received_size (DBusConnection *connection,
283 long dbus_connection_get_max_received_size (DBusConnection *connection);
285 void dbus_connection_set_max_message_unix_fds (DBusConnection *connection,
287 long dbus_connection_get_max_message_unix_fds (DBusConnection *connection);
288 void dbus_connection_set_max_received_unix_fds(DBusConnection *connection,
290 long dbus_connection_get_max_received_unix_fds(DBusConnection *connection);
292 long dbus_connection_get_outgoing_size (DBusConnection *connection);
293 long dbus_connection_get_outgoing_unix_fds (DBusConnection *connection);
295 DBusPreallocatedSend* dbus_connection_preallocate_send (DBusConnection *connection);
296 void dbus_connection_free_preallocated_send (DBusConnection *connection,
297 DBusPreallocatedSend *preallocated);
298 void dbus_connection_send_preallocated (DBusConnection *connection,
299 DBusPreallocatedSend *preallocated,
300 DBusMessage *message,
301 dbus_uint32_t *client_serial);
304 /* Object tree functionality */
307 * Called when a #DBusObjectPathVTable is unregistered (or its connection is freed).
308 * Found in #DBusObjectPathVTable.
310 typedef void (* DBusObjectPathUnregisterFunction) (DBusConnection *connection,
313 * Called when a message is sent to a registered object path. Found in
314 * #DBusObjectPathVTable which is registered with dbus_connection_register_object_path()
315 * or dbus_connection_register_fallback().
317 typedef DBusHandlerResult (* DBusObjectPathMessageFunction) (DBusConnection *connection,
318 DBusMessage *message,
322 * Virtual table that must be implemented to handle a portion of the
323 * object path hierarchy. Attach the vtable to a particular path using
324 * dbus_connection_register_object_path() or
325 * dbus_connection_register_fallback().
327 struct DBusObjectPathVTable
329 DBusObjectPathUnregisterFunction unregister_function; /**< Function to unregister this handler */
330 DBusObjectPathMessageFunction message_function; /**< Function to handle messages */
332 void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */
333 void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */
334 void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */
335 void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */
338 dbus_bool_t dbus_connection_try_register_object_path (DBusConnection *connection,
340 const DBusObjectPathVTable *vtable,
344 dbus_bool_t dbus_connection_register_object_path (DBusConnection *connection,
346 const DBusObjectPathVTable *vtable,
349 dbus_bool_t dbus_connection_try_register_fallback (DBusConnection *connection,
351 const DBusObjectPathVTable *vtable,
355 dbus_bool_t dbus_connection_register_fallback (DBusConnection *connection,
357 const DBusObjectPathVTable *vtable,
359 dbus_bool_t dbus_connection_unregister_object_path (DBusConnection *connection,
362 dbus_bool_t dbus_connection_get_object_path_data (DBusConnection *connection,
366 dbus_bool_t dbus_connection_list_registered (DBusConnection *connection,
367 const char *parent_path,
368 char ***child_entries);
370 dbus_bool_t dbus_connection_get_unix_fd (DBusConnection *connection,
372 dbus_bool_t dbus_connection_get_socket (DBusConnection *connection,
379 * @addtogroup DBusWatch
383 #ifndef DBUS_DISABLE_DEPRECATED
384 DBUS_DEPRECATED int dbus_watch_get_fd (DBusWatch *watch);
387 int dbus_watch_get_unix_fd (DBusWatch *watch);
388 int dbus_watch_get_socket (DBusWatch *watch);
389 unsigned int dbus_watch_get_flags (DBusWatch *watch);
390 void* dbus_watch_get_data (DBusWatch *watch);
391 void dbus_watch_set_data (DBusWatch *watch,
393 DBusFreeFunction free_data_function);
394 dbus_bool_t dbus_watch_handle (DBusWatch *watch,
396 dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch);
401 * @addtogroup DBusTimeout
405 int dbus_timeout_get_interval (DBusTimeout *timeout);
406 void* dbus_timeout_get_data (DBusTimeout *timeout);
407 void dbus_timeout_set_data (DBusTimeout *timeout,
409 DBusFreeFunction free_data_function);
410 dbus_bool_t dbus_timeout_handle (DBusTimeout *timeout);
411 dbus_bool_t dbus_timeout_get_enabled (DBusTimeout *timeout);
417 #endif /* DBUS_CONNECTION_H */