You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

563 lines
32 KiB

  1. /* GDBus - GLib D-Bus Library
  2. *
  3. * Copyright (C) 2008-2010 Red Hat, Inc.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General
  16. * Public License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  18. * Boston, MA 02111-1307, USA.
  19. *
  20. * Author: David Zeuthen <davidz@redhat.com>
  21. */
  22. #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
  23. #error "Only <gio/gio.h> can be included directly."
  24. #endif
  25. #ifndef __G_DBUS_CONNECTION_H__
  26. #define __G_DBUS_CONNECTION_H__
  27. #include <gio/giotypes.h>
  28. G_BEGIN_DECLS
  29. #define G_TYPE_DBUS_CONNECTION (g_dbus_connection_get_type ())
  30. #define G_DBUS_CONNECTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_DBUS_CONNECTION, GDBusConnection))
  31. #define G_IS_DBUS_CONNECTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_DBUS_CONNECTION))
  32. GType g_dbus_connection_get_type (void) G_GNUC_CONST;
  33. /* ---------------------------------------------------------------------------------------------------- */
  34. void g_bus_get (GBusType bus_type,
  35. GCancellable *cancellable,
  36. GAsyncReadyCallback callback,
  37. gpointer user_data);
  38. GDBusConnection *g_bus_get_finish (GAsyncResult *res,
  39. GError **error);
  40. GDBusConnection *g_bus_get_sync (GBusType bus_type,
  41. GCancellable *cancellable,
  42. GError **error);
  43. /* ---------------------------------------------------------------------------------------------------- */
  44. void g_dbus_connection_new (GIOStream *stream,
  45. const gchar *guid,
  46. GDBusConnectionFlags flags,
  47. GDBusAuthObserver *observer,
  48. GCancellable *cancellable,
  49. GAsyncReadyCallback callback,
  50. gpointer user_data);
  51. GDBusConnection *g_dbus_connection_new_finish (GAsyncResult *res,
  52. GError **error);
  53. GDBusConnection *g_dbus_connection_new_sync (GIOStream *stream,
  54. const gchar *guid,
  55. GDBusConnectionFlags flags,
  56. GDBusAuthObserver *observer,
  57. GCancellable *cancellable,
  58. GError **error);
  59. void g_dbus_connection_new_for_address (const gchar *address,
  60. GDBusConnectionFlags flags,
  61. GDBusAuthObserver *observer,
  62. GCancellable *cancellable,
  63. GAsyncReadyCallback callback,
  64. gpointer user_data);
  65. GDBusConnection *g_dbus_connection_new_for_address_finish (GAsyncResult *res,
  66. GError **error);
  67. GDBusConnection *g_dbus_connection_new_for_address_sync (const gchar *address,
  68. GDBusConnectionFlags flags,
  69. GDBusAuthObserver *observer,
  70. GCancellable *cancellable,
  71. GError **error);
  72. /* ---------------------------------------------------------------------------------------------------- */
  73. void g_dbus_connection_start_message_processing (GDBusConnection *connection);
  74. gboolean g_dbus_connection_is_closed (GDBusConnection *connection);
  75. GIOStream *g_dbus_connection_get_stream (GDBusConnection *connection);
  76. const gchar *g_dbus_connection_get_guid (GDBusConnection *connection);
  77. const gchar *g_dbus_connection_get_unique_name (GDBusConnection *connection);
  78. GCredentials *g_dbus_connection_get_peer_credentials (GDBusConnection *connection);
  79. gboolean g_dbus_connection_get_exit_on_close (GDBusConnection *connection);
  80. void g_dbus_connection_set_exit_on_close (GDBusConnection *connection,
  81. gboolean exit_on_close);
  82. GDBusCapabilityFlags g_dbus_connection_get_capabilities (GDBusConnection *connection);
  83. /* ---------------------------------------------------------------------------------------------------- */
  84. void g_dbus_connection_close (GDBusConnection *connection,
  85. GCancellable *cancellable,
  86. GAsyncReadyCallback callback,
  87. gpointer user_data);
  88. gboolean g_dbus_connection_close_finish (GDBusConnection *connection,
  89. GAsyncResult *res,
  90. GError **error);
  91. gboolean g_dbus_connection_close_sync (GDBusConnection *connection,
  92. GCancellable *cancellable,
  93. GError **error);
  94. /* ---------------------------------------------------------------------------------------------------- */
  95. void g_dbus_connection_flush (GDBusConnection *connection,
  96. GCancellable *cancellable,
  97. GAsyncReadyCallback callback,
  98. gpointer user_data);
  99. gboolean g_dbus_connection_flush_finish (GDBusConnection *connection,
  100. GAsyncResult *res,
  101. GError **error);
  102. gboolean g_dbus_connection_flush_sync (GDBusConnection *connection,
  103. GCancellable *cancellable,
  104. GError **error);
  105. /* ---------------------------------------------------------------------------------------------------- */
  106. gboolean g_dbus_connection_send_message (GDBusConnection *connection,
  107. GDBusMessage *message,
  108. GDBusSendMessageFlags flags,
  109. volatile guint32 *out_serial,
  110. GError **error);
  111. void g_dbus_connection_send_message_with_reply (GDBusConnection *connection,
  112. GDBusMessage *message,
  113. GDBusSendMessageFlags flags,
  114. gint timeout_msec,
  115. volatile guint32 *out_serial,
  116. GCancellable *cancellable,
  117. GAsyncReadyCallback callback,
  118. gpointer user_data);
  119. GDBusMessage *g_dbus_connection_send_message_with_reply_finish (GDBusConnection *connection,
  120. GAsyncResult *res,
  121. GError **error);
  122. GDBusMessage *g_dbus_connection_send_message_with_reply_sync (GDBusConnection *connection,
  123. GDBusMessage *message,
  124. GDBusSendMessageFlags flags,
  125. gint timeout_msec,
  126. volatile guint32 *out_serial,
  127. GCancellable *cancellable,
  128. GError **error);
  129. /* ---------------------------------------------------------------------------------------------------- */
  130. gboolean g_dbus_connection_emit_signal (GDBusConnection *connection,
  131. const gchar *destination_bus_name,
  132. const gchar *object_path,
  133. const gchar *interface_name,
  134. const gchar *signal_name,
  135. GVariant *parameters,
  136. GError **error);
  137. void g_dbus_connection_call (GDBusConnection *connection,
  138. const gchar *bus_name,
  139. const gchar *object_path,
  140. const gchar *interface_name,
  141. const gchar *method_name,
  142. GVariant *parameters,
  143. const GVariantType *reply_type,
  144. GDBusCallFlags flags,
  145. gint timeout_msec,
  146. GCancellable *cancellable,
  147. GAsyncReadyCallback callback,
  148. gpointer user_data);
  149. GVariant *g_dbus_connection_call_finish (GDBusConnection *connection,
  150. GAsyncResult *res,
  151. GError **error);
  152. GVariant *g_dbus_connection_call_sync (GDBusConnection *connection,
  153. const gchar *bus_name,
  154. const gchar *object_path,
  155. const gchar *interface_name,
  156. const gchar *method_name,
  157. GVariant *parameters,
  158. const GVariantType *reply_type,
  159. GDBusCallFlags flags,
  160. gint timeout_msec,
  161. GCancellable *cancellable,
  162. GError **error);
  163. /* ---------------------------------------------------------------------------------------------------- */
  164. /**
  165. * GDBusInterfaceMethodCallFunc:
  166. * @connection: A #GDBusConnection.
  167. * @sender: The unique bus name of the remote caller.
  168. * @object_path: The object path that the method was invoked on.
  169. * @interface_name: The D-Bus interface name the method was invoked on.
  170. * @method_name: The name of the method that was invoked.
  171. * @parameters: A #GVariant tuple with parameters.
  172. * @invocation: A #GDBusMethodInvocation object that can be used to return a value or error.
  173. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
  174. *
  175. * The type of the @method_call function in #GDBusInterfaceVTable.
  176. *
  177. * Since: 2.26
  178. */
  179. typedef void (*GDBusInterfaceMethodCallFunc) (GDBusConnection *connection,
  180. const gchar *sender,
  181. const gchar *object_path,
  182. const gchar *interface_name,
  183. const gchar *method_name,
  184. GVariant *parameters,
  185. GDBusMethodInvocation *invocation,
  186. gpointer user_data);
  187. /**
  188. * GDBusInterfaceGetPropertyFunc:
  189. * @connection: A #GDBusConnection.
  190. * @sender: The unique bus name of the remote caller.
  191. * @object_path: The object path that the method was invoked on.
  192. * @interface_name: The D-Bus interface name for the property.
  193. * @property_name: The name of the property to get the value of.
  194. * @error: Return location for error.
  195. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
  196. *
  197. * The type of the @get_property function in #GDBusInterfaceVTable.
  198. *
  199. * Returns: A #GVariant with the value for @property_name or %NULL if
  200. * @error is set. If the returned #GVariant is floating, it is
  201. * consumed - otherwise its reference count is decreased by one.
  202. *
  203. * Since: 2.26
  204. */
  205. typedef GVariant *(*GDBusInterfaceGetPropertyFunc) (GDBusConnection *connection,
  206. const gchar *sender,
  207. const gchar *object_path,
  208. const gchar *interface_name,
  209. const gchar *property_name,
  210. GError **error,
  211. gpointer user_data);
  212. /**
  213. * GDBusInterfaceSetPropertyFunc:
  214. * @connection: A #GDBusConnection.
  215. * @sender: The unique bus name of the remote caller.
  216. * @object_path: The object path that the method was invoked on.
  217. * @interface_name: The D-Bus interface name for the property.
  218. * @property_name: The name of the property to get the value of.
  219. * @value: The value to set the property to.
  220. * @error: Return location for error.
  221. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
  222. *
  223. * The type of the @set_property function in #GDBusInterfaceVTable.
  224. *
  225. * Returns: %TRUE if the property was set to @value, %FALSE if @error is set.
  226. *
  227. * Since: 2.26
  228. */
  229. typedef gboolean (*GDBusInterfaceSetPropertyFunc) (GDBusConnection *connection,
  230. const gchar *sender,
  231. const gchar *object_path,
  232. const gchar *interface_name,
  233. const gchar *property_name,
  234. GVariant *value,
  235. GError **error,
  236. gpointer user_data);
  237. /**
  238. * GDBusInterfaceVTable:
  239. * @method_call: Function for handling incoming method calls.
  240. * @get_property: Function for getting a property.
  241. * @set_property: Function for setting a property.
  242. *
  243. * Virtual table for handling properties and method calls for a D-Bus
  244. * interface.
  245. *
  246. * If you want to handle getting/setting D-Bus properties asynchronously, simply
  247. * register an object with the <literal>org.freedesktop.DBus.Properties</literal>
  248. * D-Bus interface using g_dbus_connection_register_object().
  249. *
  250. * Since: 2.26
  251. */
  252. struct _GDBusInterfaceVTable
  253. {
  254. GDBusInterfaceMethodCallFunc method_call;
  255. GDBusInterfaceGetPropertyFunc get_property;
  256. GDBusInterfaceSetPropertyFunc set_property;
  257. /*< private >*/
  258. /* Padding for future expansion - also remember to update
  259. * gdbusconnection.c:_g_dbus_interface_vtable_copy() when
  260. * changing this.
  261. */
  262. gpointer padding[8];
  263. };
  264. guint g_dbus_connection_register_object (GDBusConnection *connection,
  265. const gchar *object_path,
  266. GDBusInterfaceInfo *interface_info,
  267. const GDBusInterfaceVTable *vtable,
  268. gpointer user_data,
  269. GDestroyNotify user_data_free_func,
  270. GError **error);
  271. gboolean g_dbus_connection_unregister_object (GDBusConnection *connection,
  272. guint registration_id);
  273. /* ---------------------------------------------------------------------------------------------------- */
  274. /**
  275. * GDBusSubtreeEnumerateFunc:
  276. * @connection: A #GDBusConnection.
  277. * @sender: The unique bus name of the remote caller.
  278. * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
  279. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
  280. *
  281. * The type of the @enumerate function in #GDBusSubtreeVTable.
  282. *
  283. * This function is called when generating introspection data and also
  284. * when preparing to dispatch incoming messages in the event that the
  285. * %G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES flag is not
  286. * specified (ie: to verify that the object path is valid).
  287. *
  288. * Hierarchies are not supported; the items that you return should not
  289. * contain the '/' character.
  290. *
  291. * The return value will be freed with g_strfreev().
  292. *
  293. * Returns: A newly allocated array of strings for node names that are children of @object_path.
  294. *
  295. * Since: 2.26
  296. */
  297. typedef gchar** (*GDBusSubtreeEnumerateFunc) (GDBusConnection *connection,
  298. const gchar *sender,
  299. const gchar *object_path,
  300. gpointer user_data);
  301. /**
  302. * GDBusSubtreeIntrospectFunc:
  303. * @connection: A #GDBusConnection.
  304. * @sender: The unique bus name of the remote caller.
  305. * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
  306. * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
  307. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
  308. *
  309. * The type of the @introspect function in #GDBusSubtreeVTable.
  310. *
  311. * Subtrees are flat. @node, if non-%NULL, is always exactly one
  312. * segment of the object path (ie: it never contains a slash).
  313. *
  314. * This function should return %NULL to indicate that there is no object
  315. * at this node.
  316. *
  317. * If this function returns non-%NULL, the return value is expected to
  318. * be a %NULL-terminated array of pointers to #GDBusInterfaceInfo
  319. * structures describing the interfaces implemented by @node. This
  320. * array will have g_dbus_interface_info_unref() called on each item
  321. * before being freed with g_free().
  322. *
  323. * The difference between returning %NULL and an array containing zero
  324. * items is that the standard DBus interfaces will returned to the
  325. * remote introspector in the empty array case, but not in the %NULL
  326. * case.
  327. *
  328. * Returns: A %NULL-terminated array of pointers to #GDBusInterfaceInfo, or %NULL.
  329. *
  330. * Since: 2.26
  331. */
  332. typedef GDBusInterfaceInfo ** (*GDBusSubtreeIntrospectFunc) (GDBusConnection *connection,
  333. const gchar *sender,
  334. const gchar *object_path,
  335. const gchar *node,
  336. gpointer user_data);
  337. /**
  338. * GDBusSubtreeDispatchFunc:
  339. * @connection: A #GDBusConnection.
  340. * @sender: The unique bus name of the remote caller.
  341. * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
  342. * @interface_name: The D-Bus interface name that the method call or property access is for.
  343. * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
  344. * @out_user_data: Return location for user data to pass to functions in the returned #GDBusInterfaceVTable (never %NULL).
  345. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
  346. *
  347. * The type of the @dispatch function in #GDBusSubtreeVTable.
  348. *
  349. * Subtrees are flat. @node, if non-%NULL, is always exactly one
  350. * segment of the object path (ie: it never contains a slash).
  351. *
  352. * Returns: A #GDBusInterfaceVTable or %NULL if you don't want to handle the methods.
  353. *
  354. * Since: 2.26
  355. */
  356. typedef const GDBusInterfaceVTable * (*GDBusSubtreeDispatchFunc) (GDBusConnection *connection,
  357. const gchar *sender,
  358. const gchar *object_path,
  359. const gchar *interface_name,
  360. const gchar *node,
  361. gpointer *out_user_data,
  362. gpointer user_data);
  363. /**
  364. * GDBusSubtreeVTable:
  365. * @enumerate: Function for enumerating child nodes.
  366. * @introspect: Function for introspecting a child node.
  367. * @dispatch: Function for dispatching a remote call on a child node.
  368. *
  369. * Virtual table for handling subtrees registered with g_dbus_connection_register_subtree().
  370. *
  371. * Since: 2.26
  372. */
  373. struct _GDBusSubtreeVTable
  374. {
  375. GDBusSubtreeEnumerateFunc enumerate;
  376. GDBusSubtreeIntrospectFunc introspect;
  377. GDBusSubtreeDispatchFunc dispatch;
  378. /*< private >*/
  379. /* Padding for future expansion - also remember to update
  380. * gdbusconnection.c:_g_dbus_subtree_vtable_copy() when
  381. * changing this.
  382. */
  383. gpointer padding[8];
  384. };
  385. guint g_dbus_connection_register_subtree (GDBusConnection *connection,
  386. const gchar *object_path,
  387. const GDBusSubtreeVTable *vtable,
  388. GDBusSubtreeFlags flags,
  389. gpointer user_data,
  390. GDestroyNotify user_data_free_func,
  391. GError **error);
  392. gboolean g_dbus_connection_unregister_subtree (GDBusConnection *connection,
  393. guint registration_id);
  394. /* ---------------------------------------------------------------------------------------------------- */
  395. /**
  396. * GDBusSignalCallback:
  397. * @connection: A #GDBusConnection.
  398. * @sender_name: The unique bus name of the sender of the signal.
  399. * @object_path: The object path that the signal was emitted on.
  400. * @interface_name: The name of the interface.
  401. * @signal_name: The name of the signal.
  402. * @parameters: A #GVariant tuple with parameters for the signal.
  403. * @user_data: User data passed when subscribing to the signal.
  404. *
  405. * Signature for callback function used in g_dbus_connection_signal_subscribe().
  406. *
  407. * Since: 2.26
  408. */
  409. typedef void (*GDBusSignalCallback) (GDBusConnection *connection,
  410. const gchar *sender_name,
  411. const gchar *object_path,
  412. const gchar *interface_name,
  413. const gchar *signal_name,
  414. GVariant *parameters,
  415. gpointer user_data);
  416. guint g_dbus_connection_signal_subscribe (GDBusConnection *connection,
  417. const gchar *sender,
  418. const gchar *interface_name,
  419. const gchar *member,
  420. const gchar *object_path,
  421. const gchar *arg0,
  422. GDBusSignalFlags flags,
  423. GDBusSignalCallback callback,
  424. gpointer user_data,
  425. GDestroyNotify user_data_free_func);
  426. void g_dbus_connection_signal_unsubscribe (GDBusConnection *connection,
  427. guint subscription_id);
  428. /* ---------------------------------------------------------------------------------------------------- */
  429. /**
  430. * GDBusMessageFilterFunction:
  431. * @connection: (transfer none): A #GDBusConnection.
  432. * @message: (transfer full): A locked #GDBusMessage that the filter function takes ownership of.
  433. * @incoming: %TRUE if it is a message received from the other peer, %FALSE if it is
  434. * a message to be sent to the other peer.
  435. * @user_data: User data passed when adding the filter.
  436. *
  437. * Signature for function used in g_dbus_connection_add_filter().
  438. *
  439. * A filter function is passed a #GDBusMessage and expected to return
  440. * a #GDBusMessage too. Passive filter functions that don't modify the
  441. * message can simply return the @message object:
  442. * |[
  443. * static GDBusMessage *
  444. * passive_filter (GDBusConnection *connection
  445. * GDBusMessage *message,
  446. * gboolean incoming,
  447. * gpointer user_data)
  448. * {
  449. * /<!-- -->* inspect @message *<!-- -->/
  450. * return message;
  451. * }
  452. * ]|
  453. * Filter functions that wants to drop a message can simply return %NULL:
  454. * |[
  455. * static GDBusMessage *
  456. * drop_filter (GDBusConnection *connection
  457. * GDBusMessage *message,
  458. * gboolean incoming,
  459. * gpointer user_data)
  460. * {
  461. * if (should_drop_message)
  462. * {
  463. * g_object_unref (message);
  464. * message = NULL;
  465. * }
  466. * return message;
  467. * }
  468. * ]|
  469. * Finally, a filter function may modify a message by copying it:
  470. * |[
  471. * static GDBusMessage *
  472. * modifying_filter (GDBusConnection *connection
  473. * GDBusMessage *message,
  474. * gboolean incoming,
  475. * gpointer user_data)
  476. * {
  477. * GDBusMessage *copy;
  478. * GError *error;
  479. *
  480. * error = NULL;
  481. * copy = g_dbus_message_copy (message, &error);
  482. * /<!-- -->* handle @error being is set *<!-- -->/
  483. * g_object_unref (message);
  484. *
  485. * /<!-- -->* modify @copy *<!-- -->/
  486. *
  487. * return copy;
  488. * }
  489. * ]|
  490. * If the returned #GDBusMessage is different from @message and cannot
  491. * be sent on @connection (it could use features, such as file
  492. * descriptors, not compatible with @connection), then a warning is
  493. * logged to <emphasis>standard error</emphasis>. Applications can
  494. * check this ahead of time using g_dbus_message_to_blob() passing a
  495. * #GDBusCapabilityFlags value obtained from @connection.
  496. *
  497. * Returns: (transfer full) (allow-none): A #GDBusMessage that will be freed with
  498. * g_object_unref() or %NULL to drop the message. Passive filter
  499. * functions can simply return the passed @message object.
  500. *
  501. * Since: 2.26
  502. */
  503. typedef GDBusMessage *(*GDBusMessageFilterFunction) (GDBusConnection *connection,
  504. GDBusMessage *message,
  505. gboolean incoming,
  506. gpointer user_data);
  507. guint g_dbus_connection_add_filter (GDBusConnection *connection,
  508. GDBusMessageFilterFunction filter_function,
  509. gpointer user_data,
  510. GDestroyNotify user_data_free_func);
  511. void g_dbus_connection_remove_filter (GDBusConnection *connection,
  512. guint filter_id);
  513. /* ---------------------------------------------------------------------------------------------------- */
  514. G_END_DECLS
  515. #endif /* __G_DBUS_CONNECTION_H__ */