gdbusconnection.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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.1 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, see <http://www.gnu.org/licenses/>.
  17. *
  18. * Author: David Zeuthen <davidz@redhat.com>
  19. */
  20. #ifndef __G_DBUS_CONNECTION_H__
  21. #define __G_DBUS_CONNECTION_H__
  22. #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
  23. #error "Only <gio/gio.h> can be included directly."
  24. #endif
  25. #include <gio/giotypes.h>
  26. G_BEGIN_DECLS
  27. #define G_TYPE_DBUS_CONNECTION (g_dbus_connection_get_type ())
  28. #define G_DBUS_CONNECTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_DBUS_CONNECTION, GDBusConnection))
  29. #define G_IS_DBUS_CONNECTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_DBUS_CONNECTION))
  30. GLIB_AVAILABLE_IN_ALL
  31. GType g_dbus_connection_get_type (void) G_GNUC_CONST;
  32. /* ---------------------------------------------------------------------------------------------------- */
  33. GLIB_AVAILABLE_IN_ALL
  34. void g_bus_get (GBusType bus_type,
  35. GCancellable *cancellable,
  36. GAsyncReadyCallback callback,
  37. gpointer user_data);
  38. GLIB_AVAILABLE_IN_ALL
  39. GDBusConnection *g_bus_get_finish (GAsyncResult *res,
  40. GError **error);
  41. GLIB_AVAILABLE_IN_ALL
  42. GDBusConnection *g_bus_get_sync (GBusType bus_type,
  43. GCancellable *cancellable,
  44. GError **error);
  45. /* ---------------------------------------------------------------------------------------------------- */
  46. GLIB_AVAILABLE_IN_ALL
  47. void g_dbus_connection_new (GIOStream *stream,
  48. const gchar *guid,
  49. GDBusConnectionFlags flags,
  50. GDBusAuthObserver *observer,
  51. GCancellable *cancellable,
  52. GAsyncReadyCallback callback,
  53. gpointer user_data);
  54. GLIB_AVAILABLE_IN_ALL
  55. GDBusConnection *g_dbus_connection_new_finish (GAsyncResult *res,
  56. GError **error);
  57. GLIB_AVAILABLE_IN_ALL
  58. GDBusConnection *g_dbus_connection_new_sync (GIOStream *stream,
  59. const gchar *guid,
  60. GDBusConnectionFlags flags,
  61. GDBusAuthObserver *observer,
  62. GCancellable *cancellable,
  63. GError **error);
  64. GLIB_AVAILABLE_IN_ALL
  65. void g_dbus_connection_new_for_address (const gchar *address,
  66. GDBusConnectionFlags flags,
  67. GDBusAuthObserver *observer,
  68. GCancellable *cancellable,
  69. GAsyncReadyCallback callback,
  70. gpointer user_data);
  71. GLIB_AVAILABLE_IN_ALL
  72. GDBusConnection *g_dbus_connection_new_for_address_finish (GAsyncResult *res,
  73. GError **error);
  74. GLIB_AVAILABLE_IN_ALL
  75. GDBusConnection *g_dbus_connection_new_for_address_sync (const gchar *address,
  76. GDBusConnectionFlags flags,
  77. GDBusAuthObserver *observer,
  78. GCancellable *cancellable,
  79. GError **error);
  80. /* ---------------------------------------------------------------------------------------------------- */
  81. GLIB_AVAILABLE_IN_ALL
  82. void g_dbus_connection_start_message_processing (GDBusConnection *connection);
  83. GLIB_AVAILABLE_IN_ALL
  84. gboolean g_dbus_connection_is_closed (GDBusConnection *connection);
  85. GLIB_AVAILABLE_IN_ALL
  86. GIOStream *g_dbus_connection_get_stream (GDBusConnection *connection);
  87. GLIB_AVAILABLE_IN_ALL
  88. const gchar *g_dbus_connection_get_guid (GDBusConnection *connection);
  89. GLIB_AVAILABLE_IN_ALL
  90. const gchar *g_dbus_connection_get_unique_name (GDBusConnection *connection);
  91. GLIB_AVAILABLE_IN_ALL
  92. GCredentials *g_dbus_connection_get_peer_credentials (GDBusConnection *connection);
  93. GLIB_AVAILABLE_IN_2_34
  94. guint32 g_dbus_connection_get_last_serial (GDBusConnection *connection);
  95. GLIB_AVAILABLE_IN_ALL
  96. gboolean g_dbus_connection_get_exit_on_close (GDBusConnection *connection);
  97. GLIB_AVAILABLE_IN_ALL
  98. void g_dbus_connection_set_exit_on_close (GDBusConnection *connection,
  99. gboolean exit_on_close);
  100. GLIB_AVAILABLE_IN_ALL
  101. GDBusCapabilityFlags g_dbus_connection_get_capabilities (GDBusConnection *connection);
  102. GLIB_AVAILABLE_IN_2_60
  103. GDBusConnectionFlags g_dbus_connection_get_flags (GDBusConnection *connection);
  104. /* ---------------------------------------------------------------------------------------------------- */
  105. GLIB_AVAILABLE_IN_ALL
  106. void g_dbus_connection_close (GDBusConnection *connection,
  107. GCancellable *cancellable,
  108. GAsyncReadyCallback callback,
  109. gpointer user_data);
  110. GLIB_AVAILABLE_IN_ALL
  111. gboolean g_dbus_connection_close_finish (GDBusConnection *connection,
  112. GAsyncResult *res,
  113. GError **error);
  114. GLIB_AVAILABLE_IN_ALL
  115. gboolean g_dbus_connection_close_sync (GDBusConnection *connection,
  116. GCancellable *cancellable,
  117. GError **error);
  118. /* ---------------------------------------------------------------------------------------------------- */
  119. GLIB_AVAILABLE_IN_ALL
  120. void g_dbus_connection_flush (GDBusConnection *connection,
  121. GCancellable *cancellable,
  122. GAsyncReadyCallback callback,
  123. gpointer user_data);
  124. GLIB_AVAILABLE_IN_ALL
  125. gboolean g_dbus_connection_flush_finish (GDBusConnection *connection,
  126. GAsyncResult *res,
  127. GError **error);
  128. GLIB_AVAILABLE_IN_ALL
  129. gboolean g_dbus_connection_flush_sync (GDBusConnection *connection,
  130. GCancellable *cancellable,
  131. GError **error);
  132. /* ---------------------------------------------------------------------------------------------------- */
  133. GLIB_AVAILABLE_IN_ALL
  134. gboolean g_dbus_connection_send_message (GDBusConnection *connection,
  135. GDBusMessage *message,
  136. GDBusSendMessageFlags flags,
  137. volatile guint32 *out_serial,
  138. GError **error);
  139. GLIB_AVAILABLE_IN_ALL
  140. void g_dbus_connection_send_message_with_reply (GDBusConnection *connection,
  141. GDBusMessage *message,
  142. GDBusSendMessageFlags flags,
  143. gint timeout_msec,
  144. volatile guint32 *out_serial,
  145. GCancellable *cancellable,
  146. GAsyncReadyCallback callback,
  147. gpointer user_data);
  148. GLIB_AVAILABLE_IN_ALL
  149. GDBusMessage *g_dbus_connection_send_message_with_reply_finish (GDBusConnection *connection,
  150. GAsyncResult *res,
  151. GError **error);
  152. GLIB_AVAILABLE_IN_ALL
  153. GDBusMessage *g_dbus_connection_send_message_with_reply_sync (GDBusConnection *connection,
  154. GDBusMessage *message,
  155. GDBusSendMessageFlags flags,
  156. gint timeout_msec,
  157. volatile guint32 *out_serial,
  158. GCancellable *cancellable,
  159. GError **error);
  160. /* ---------------------------------------------------------------------------------------------------- */
  161. GLIB_AVAILABLE_IN_ALL
  162. gboolean g_dbus_connection_emit_signal (GDBusConnection *connection,
  163. const gchar *destination_bus_name,
  164. const gchar *object_path,
  165. const gchar *interface_name,
  166. const gchar *signal_name,
  167. GVariant *parameters,
  168. GError **error);
  169. GLIB_AVAILABLE_IN_ALL
  170. void g_dbus_connection_call (GDBusConnection *connection,
  171. const gchar *bus_name,
  172. const gchar *object_path,
  173. const gchar *interface_name,
  174. const gchar *method_name,
  175. GVariant *parameters,
  176. const GVariantType *reply_type,
  177. GDBusCallFlags flags,
  178. gint timeout_msec,
  179. GCancellable *cancellable,
  180. GAsyncReadyCallback callback,
  181. gpointer user_data);
  182. GLIB_AVAILABLE_IN_ALL
  183. GVariant *g_dbus_connection_call_finish (GDBusConnection *connection,
  184. GAsyncResult *res,
  185. GError **error);
  186. GLIB_AVAILABLE_IN_ALL
  187. GVariant *g_dbus_connection_call_sync (GDBusConnection *connection,
  188. const gchar *bus_name,
  189. const gchar *object_path,
  190. const gchar *interface_name,
  191. const gchar *method_name,
  192. GVariant *parameters,
  193. const GVariantType *reply_type,
  194. GDBusCallFlags flags,
  195. gint timeout_msec,
  196. GCancellable *cancellable,
  197. GError **error);
  198. GLIB_AVAILABLE_IN_2_30
  199. void g_dbus_connection_call_with_unix_fd_list (GDBusConnection *connection,
  200. const gchar *bus_name,
  201. const gchar *object_path,
  202. const gchar *interface_name,
  203. const gchar *method_name,
  204. GVariant *parameters,
  205. const GVariantType *reply_type,
  206. GDBusCallFlags flags,
  207. gint timeout_msec,
  208. GUnixFDList *fd_list,
  209. GCancellable *cancellable,
  210. GAsyncReadyCallback callback,
  211. gpointer user_data);
  212. GLIB_AVAILABLE_IN_2_30
  213. GVariant *g_dbus_connection_call_with_unix_fd_list_finish (GDBusConnection *connection,
  214. GUnixFDList **out_fd_list,
  215. GAsyncResult *res,
  216. GError **error);
  217. GLIB_AVAILABLE_IN_2_30
  218. GVariant *g_dbus_connection_call_with_unix_fd_list_sync (GDBusConnection *connection,
  219. const gchar *bus_name,
  220. const gchar *object_path,
  221. const gchar *interface_name,
  222. const gchar *method_name,
  223. GVariant *parameters,
  224. const GVariantType *reply_type,
  225. GDBusCallFlags flags,
  226. gint timeout_msec,
  227. GUnixFDList *fd_list,
  228. GUnixFDList **out_fd_list,
  229. GCancellable *cancellable,
  230. GError **error);
  231. /* ---------------------------------------------------------------------------------------------------- */
  232. /**
  233. * GDBusInterfaceMethodCallFunc:
  234. * @connection: A #GDBusConnection.
  235. * @sender: The unique bus name of the remote caller.
  236. * @object_path: The object path that the method was invoked on.
  237. * @interface_name: The D-Bus interface name the method was invoked on.
  238. * @method_name: The name of the method that was invoked.
  239. * @parameters: A #GVariant tuple with parameters.
  240. * @invocation: (transfer full): A #GDBusMethodInvocation object that must be used to return a value or error.
  241. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
  242. *
  243. * The type of the @method_call function in #GDBusInterfaceVTable.
  244. *
  245. * Since: 2.26
  246. */
  247. typedef void (*GDBusInterfaceMethodCallFunc) (GDBusConnection *connection,
  248. const gchar *sender,
  249. const gchar *object_path,
  250. const gchar *interface_name,
  251. const gchar *method_name,
  252. GVariant *parameters,
  253. GDBusMethodInvocation *invocation,
  254. gpointer user_data);
  255. /**
  256. * GDBusInterfaceGetPropertyFunc:
  257. * @connection: A #GDBusConnection.
  258. * @sender: The unique bus name of the remote caller.
  259. * @object_path: The object path that the method was invoked on.
  260. * @interface_name: The D-Bus interface name for the property.
  261. * @property_name: The name of the property to get the value of.
  262. * @error: Return location for error.
  263. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
  264. *
  265. * The type of the @get_property function in #GDBusInterfaceVTable.
  266. *
  267. * Returns: A #GVariant with the value for @property_name or %NULL if
  268. * @error is set. If the returned #GVariant is floating, it is
  269. * consumed - otherwise its reference count is decreased by one.
  270. *
  271. * Since: 2.26
  272. */
  273. typedef GVariant *(*GDBusInterfaceGetPropertyFunc) (GDBusConnection *connection,
  274. const gchar *sender,
  275. const gchar *object_path,
  276. const gchar *interface_name,
  277. const gchar *property_name,
  278. GError **error,
  279. gpointer user_data);
  280. /**
  281. * GDBusInterfaceSetPropertyFunc:
  282. * @connection: A #GDBusConnection.
  283. * @sender: The unique bus name of the remote caller.
  284. * @object_path: The object path that the method was invoked on.
  285. * @interface_name: The D-Bus interface name for the property.
  286. * @property_name: The name of the property to get the value of.
  287. * @value: The value to set the property to.
  288. * @error: Return location for error.
  289. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
  290. *
  291. * The type of the @set_property function in #GDBusInterfaceVTable.
  292. *
  293. * Returns: %TRUE if the property was set to @value, %FALSE if @error is set.
  294. *
  295. * Since: 2.26
  296. */
  297. typedef gboolean (*GDBusInterfaceSetPropertyFunc) (GDBusConnection *connection,
  298. const gchar *sender,
  299. const gchar *object_path,
  300. const gchar *interface_name,
  301. const gchar *property_name,
  302. GVariant *value,
  303. GError **error,
  304. gpointer user_data);
  305. /**
  306. * GDBusInterfaceVTable:
  307. * @method_call: Function for handling incoming method calls.
  308. * @get_property: Function for getting a property.
  309. * @set_property: Function for setting a property.
  310. *
  311. * Virtual table for handling properties and method calls for a D-Bus
  312. * interface.
  313. *
  314. * Since 2.38, if you want to handle getting/setting D-Bus properties
  315. * asynchronously, give %NULL as your get_property() or set_property()
  316. * function. The D-Bus call will be directed to your @method_call function,
  317. * with the provided @interface_name set to "org.freedesktop.DBus.Properties".
  318. *
  319. * Ownership of the #GDBusMethodInvocation object passed to the
  320. * method_call() function is transferred to your handler; you must
  321. * call one of the methods of #GDBusMethodInvocation to return a reply
  322. * (possibly empty), or an error. These functions also take ownership
  323. * of the passed-in invocation object, so unless the invocation
  324. * object has otherwise been referenced, it will be then be freed.
  325. * Calling one of these functions may be done within your
  326. * method_call() implementation but it also can be done at a later
  327. * point to handle the method asynchronously.
  328. *
  329. * The usual checks on the validity of the calls is performed. For
  330. * `Get` calls, an error is automatically returned if the property does
  331. * not exist or the permissions do not allow access. The same checks are
  332. * performed for `Set` calls, and the provided value is also checked for
  333. * being the correct type.
  334. *
  335. * For both `Get` and `Set` calls, the #GDBusMethodInvocation
  336. * passed to the @method_call handler can be queried with
  337. * g_dbus_method_invocation_get_property_info() to get a pointer
  338. * to the #GDBusPropertyInfo of the property.
  339. *
  340. * If you have readable properties specified in your interface info,
  341. * you must ensure that you either provide a non-%NULL @get_property()
  342. * function or provide implementations of both the `Get` and `GetAll`
  343. * methods on org.freedesktop.DBus.Properties interface in your @method_call
  344. * function. Note that the required return type of the `Get` call is
  345. * `(v)`, not the type of the property. `GetAll` expects a return value
  346. * of type `a{sv}`.
  347. *
  348. * If you have writable properties specified in your interface info,
  349. * you must ensure that you either provide a non-%NULL @set_property()
  350. * function or provide an implementation of the `Set` call. If implementing
  351. * the call, you must return the value of type %G_VARIANT_TYPE_UNIT.
  352. *
  353. * Since: 2.26
  354. */
  355. struct _GDBusInterfaceVTable
  356. {
  357. GDBusInterfaceMethodCallFunc method_call;
  358. GDBusInterfaceGetPropertyFunc get_property;
  359. GDBusInterfaceSetPropertyFunc set_property;
  360. /*< private >*/
  361. /* Padding for future expansion - also remember to update
  362. * gdbusconnection.c:_g_dbus_interface_vtable_copy() when
  363. * changing this.
  364. */
  365. gpointer padding[8];
  366. };
  367. GLIB_AVAILABLE_IN_ALL
  368. guint g_dbus_connection_register_object (GDBusConnection *connection,
  369. const gchar *object_path,
  370. GDBusInterfaceInfo *interface_info,
  371. const GDBusInterfaceVTable *vtable,
  372. gpointer user_data,
  373. GDestroyNotify user_data_free_func,
  374. GError **error);
  375. GLIB_AVAILABLE_IN_2_46
  376. guint g_dbus_connection_register_object_with_closures (GDBusConnection *connection,
  377. const gchar *object_path,
  378. GDBusInterfaceInfo *interface_info,
  379. GClosure *method_call_closure,
  380. GClosure *get_property_closure,
  381. GClosure *set_property_closure,
  382. GError **error);
  383. GLIB_AVAILABLE_IN_ALL
  384. gboolean g_dbus_connection_unregister_object (GDBusConnection *connection,
  385. guint registration_id);
  386. /* ---------------------------------------------------------------------------------------------------- */
  387. /**
  388. * GDBusSubtreeEnumerateFunc:
  389. * @connection: A #GDBusConnection.
  390. * @sender: The unique bus name of the remote caller.
  391. * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
  392. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
  393. *
  394. * The type of the @enumerate function in #GDBusSubtreeVTable.
  395. *
  396. * This function is called when generating introspection data and also
  397. * when preparing to dispatch incoming messages in the event that the
  398. * %G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES flag is not
  399. * specified (ie: to verify that the object path is valid).
  400. *
  401. * Hierarchies are not supported; the items that you return should not
  402. * contain the '/' character.
  403. *
  404. * The return value will be freed with g_strfreev().
  405. *
  406. * Returns: A newly allocated array of strings for node names that are children of @object_path.
  407. *
  408. * Since: 2.26
  409. */
  410. typedef gchar** (*GDBusSubtreeEnumerateFunc) (GDBusConnection *connection,
  411. const gchar *sender,
  412. const gchar *object_path,
  413. gpointer user_data);
  414. /**
  415. * GDBusSubtreeIntrospectFunc:
  416. * @connection: A #GDBusConnection.
  417. * @sender: The unique bus name of the remote caller.
  418. * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
  419. * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
  420. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
  421. *
  422. * The type of the @introspect function in #GDBusSubtreeVTable.
  423. *
  424. * Subtrees are flat. @node, if non-%NULL, is always exactly one
  425. * segment of the object path (ie: it never contains a slash).
  426. *
  427. * This function should return %NULL to indicate that there is no object
  428. * at this node.
  429. *
  430. * If this function returns non-%NULL, the return value is expected to
  431. * be a %NULL-terminated array of pointers to #GDBusInterfaceInfo
  432. * structures describing the interfaces implemented by @node. This
  433. * array will have g_dbus_interface_info_unref() called on each item
  434. * before being freed with g_free().
  435. *
  436. * The difference between returning %NULL and an array containing zero
  437. * items is that the standard DBus interfaces will returned to the
  438. * remote introspector in the empty array case, but not in the %NULL
  439. * case.
  440. *
  441. * Returns: A %NULL-terminated array of pointers to #GDBusInterfaceInfo, or %NULL.
  442. *
  443. * Since: 2.26
  444. */
  445. typedef GDBusInterfaceInfo ** (*GDBusSubtreeIntrospectFunc) (GDBusConnection *connection,
  446. const gchar *sender,
  447. const gchar *object_path,
  448. const gchar *node,
  449. gpointer user_data);
  450. /**
  451. * GDBusSubtreeDispatchFunc:
  452. * @connection: A #GDBusConnection.
  453. * @sender: The unique bus name of the remote caller.
  454. * @object_path: The object path that was registered with g_dbus_connection_register_subtree().
  455. * @interface_name: The D-Bus interface name that the method call or property access is for.
  456. * @node: A node that is a child of @object_path (relative to @object_path) or %NULL for the root of the subtree.
  457. * @out_user_data: (nullable) (not optional): Return location for user data to pass to functions in the returned #GDBusInterfaceVTable (never %NULL).
  458. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_subtree().
  459. *
  460. * The type of the @dispatch function in #GDBusSubtreeVTable.
  461. *
  462. * Subtrees are flat. @node, if non-%NULL, is always exactly one
  463. * segment of the object path (ie: it never contains a slash).
  464. *
  465. * Returns: A #GDBusInterfaceVTable or %NULL if you don't want to handle the methods.
  466. *
  467. * Since: 2.26
  468. */
  469. typedef const GDBusInterfaceVTable * (*GDBusSubtreeDispatchFunc) (GDBusConnection *connection,
  470. const gchar *sender,
  471. const gchar *object_path,
  472. const gchar *interface_name,
  473. const gchar *node,
  474. gpointer *out_user_data,
  475. gpointer user_data);
  476. /**
  477. * GDBusSubtreeVTable:
  478. * @enumerate: Function for enumerating child nodes.
  479. * @introspect: Function for introspecting a child node.
  480. * @dispatch: Function for dispatching a remote call on a child node.
  481. *
  482. * Virtual table for handling subtrees registered with g_dbus_connection_register_subtree().
  483. *
  484. * Since: 2.26
  485. */
  486. struct _GDBusSubtreeVTable
  487. {
  488. GDBusSubtreeEnumerateFunc enumerate;
  489. GDBusSubtreeIntrospectFunc introspect;
  490. GDBusSubtreeDispatchFunc dispatch;
  491. /*< private >*/
  492. /* Padding for future expansion - also remember to update
  493. * gdbusconnection.c:_g_dbus_subtree_vtable_copy() when
  494. * changing this.
  495. */
  496. gpointer padding[8];
  497. };
  498. GLIB_AVAILABLE_IN_ALL
  499. guint g_dbus_connection_register_subtree (GDBusConnection *connection,
  500. const gchar *object_path,
  501. const GDBusSubtreeVTable *vtable,
  502. GDBusSubtreeFlags flags,
  503. gpointer user_data,
  504. GDestroyNotify user_data_free_func,
  505. GError **error);
  506. GLIB_AVAILABLE_IN_ALL
  507. gboolean g_dbus_connection_unregister_subtree (GDBusConnection *connection,
  508. guint registration_id);
  509. /* ---------------------------------------------------------------------------------------------------- */
  510. /**
  511. * GDBusSignalCallback:
  512. * @connection: A #GDBusConnection.
  513. * @sender_name: The unique bus name of the sender of the signal.
  514. * @object_path: The object path that the signal was emitted on.
  515. * @interface_name: The name of the interface.
  516. * @signal_name: The name of the signal.
  517. * @parameters: A #GVariant tuple with parameters for the signal.
  518. * @user_data: User data passed when subscribing to the signal.
  519. *
  520. * Signature for callback function used in g_dbus_connection_signal_subscribe().
  521. *
  522. * Since: 2.26
  523. */
  524. typedef void (*GDBusSignalCallback) (GDBusConnection *connection,
  525. const gchar *sender_name,
  526. const gchar *object_path,
  527. const gchar *interface_name,
  528. const gchar *signal_name,
  529. GVariant *parameters,
  530. gpointer user_data);
  531. GLIB_AVAILABLE_IN_ALL
  532. guint g_dbus_connection_signal_subscribe (GDBusConnection *connection,
  533. const gchar *sender,
  534. const gchar *interface_name,
  535. const gchar *member,
  536. const gchar *object_path,
  537. const gchar *arg0,
  538. GDBusSignalFlags flags,
  539. GDBusSignalCallback callback,
  540. gpointer user_data,
  541. GDestroyNotify user_data_free_func);
  542. GLIB_AVAILABLE_IN_ALL
  543. void g_dbus_connection_signal_unsubscribe (GDBusConnection *connection,
  544. guint subscription_id);
  545. /* ---------------------------------------------------------------------------------------------------- */
  546. /**
  547. * GDBusMessageFilterFunction:
  548. * @connection: (transfer none): A #GDBusConnection.
  549. * @message: (transfer full): A locked #GDBusMessage that the filter function takes ownership of.
  550. * @incoming: %TRUE if it is a message received from the other peer, %FALSE if it is
  551. * a message to be sent to the other peer.
  552. * @user_data: User data passed when adding the filter.
  553. *
  554. * Signature for function used in g_dbus_connection_add_filter().
  555. *
  556. * A filter function is passed a #GDBusMessage and expected to return
  557. * a #GDBusMessage too. Passive filter functions that don't modify the
  558. * message can simply return the @message object:
  559. * |[
  560. * static GDBusMessage *
  561. * passive_filter (GDBusConnection *connection
  562. * GDBusMessage *message,
  563. * gboolean incoming,
  564. * gpointer user_data)
  565. * {
  566. * // inspect @message
  567. * return message;
  568. * }
  569. * ]|
  570. * Filter functions that wants to drop a message can simply return %NULL:
  571. * |[
  572. * static GDBusMessage *
  573. * drop_filter (GDBusConnection *connection
  574. * GDBusMessage *message,
  575. * gboolean incoming,
  576. * gpointer user_data)
  577. * {
  578. * if (should_drop_message)
  579. * {
  580. * g_object_unref (message);
  581. * message = NULL;
  582. * }
  583. * return message;
  584. * }
  585. * ]|
  586. * Finally, a filter function may modify a message by copying it:
  587. * |[
  588. * static GDBusMessage *
  589. * modifying_filter (GDBusConnection *connection
  590. * GDBusMessage *message,
  591. * gboolean incoming,
  592. * gpointer user_data)
  593. * {
  594. * GDBusMessage *copy;
  595. * GError *error;
  596. *
  597. * error = NULL;
  598. * copy = g_dbus_message_copy (message, &error);
  599. * // handle @error being set
  600. * g_object_unref (message);
  601. *
  602. * // modify @copy
  603. *
  604. * return copy;
  605. * }
  606. * ]|
  607. * If the returned #GDBusMessage is different from @message and cannot
  608. * be sent on @connection (it could use features, such as file
  609. * descriptors, not compatible with @connection), then a warning is
  610. * logged to standard error. Applications can
  611. * check this ahead of time using g_dbus_message_to_blob() passing a
  612. * #GDBusCapabilityFlags value obtained from @connection.
  613. *
  614. * Returns: (transfer full) (nullable): A #GDBusMessage that will be freed with
  615. * g_object_unref() or %NULL to drop the message. Passive filter
  616. * functions can simply return the passed @message object.
  617. *
  618. * Since: 2.26
  619. */
  620. typedef GDBusMessage *(*GDBusMessageFilterFunction) (GDBusConnection *connection,
  621. GDBusMessage *message,
  622. gboolean incoming,
  623. gpointer user_data);
  624. GLIB_AVAILABLE_IN_ALL
  625. guint g_dbus_connection_add_filter (GDBusConnection *connection,
  626. GDBusMessageFilterFunction filter_function,
  627. gpointer user_data,
  628. GDestroyNotify user_data_free_func);
  629. GLIB_AVAILABLE_IN_ALL
  630. void g_dbus_connection_remove_filter (GDBusConnection *connection,
  631. guint filter_id);
  632. /* ---------------------------------------------------------------------------------------------------- */
  633. G_END_DECLS
  634. #endif /* __G_DBUS_CONNECTION_H__ */