gdbusconnection.h 37 KB

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