dbus-connection.h 25 KB

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