1 #ifndef CORE_DBUS_WRAP_H
2 #define CORE_DBUS_WRAP_H
14 #define DBUS_FUNCTIONS(MAGIC) \
15 MAGIC(dbus_error_init) \
16 MAGIC(dbus_error_free) \
18 MAGIC(dbus_connection_set_exit_on_disconnect) \
19 MAGIC(dbus_connection_unref) \
20 MAGIC(dbus_connection_send_with_reply_and_block) \
21 MAGIC(dbus_message_unref) \
22 MAGIC(dbus_message_new_method_call) \
23 MAGIC(dbus_message_append_args) \
24 MAGIC(dbus_message_iter_init) \
25 MAGIC(dbus_message_iter_next) \
26 MAGIC(dbus_message_iter_recurse) \
27 MAGIC(dbus_message_iter_get_arg_type) \
28 MAGIC(dbus_message_iter_get_basic) \
29 MAGIC(dbus_set_error_from_message)
31 extern void *dbus_handle
;
32 #define DECL_FUNC(x) extern decltype(x) *p##x;
33 DBUS_FUNCTIONS(DECL_FUNC
)
37 #define dbus_error_init (*pdbus_error_init)
38 #define dbus_error_free (*pdbus_error_free)
39 #define dbus_bus_get (*pdbus_bus_get)
40 #define dbus_connection_set_exit_on_disconnect (*pdbus_connection_set_exit_on_disconnect)
41 #define dbus_connection_unref (*pdbus_connection_unref)
42 #define dbus_connection_send_with_reply_and_block (*pdbus_connection_send_with_reply_and_block)
43 #define dbus_message_unref (*pdbus_message_unref)
44 #define dbus_message_new_method_call (*pdbus_message_new_method_call)
45 #define dbus_message_append_args (*pdbus_message_append_args)
46 #define dbus_message_iter_init (*pdbus_message_iter_init)
47 #define dbus_message_iter_next (*pdbus_message_iter_next)
48 #define dbus_message_iter_recurse (*pdbus_message_iter_recurse)
49 #define dbus_message_iter_get_arg_type (*pdbus_message_iter_get_arg_type)
50 #define dbus_message_iter_get_basic (*pdbus_message_iter_get_basic)
51 #define dbus_set_error_from_message (*pdbus_set_error_from_message)
58 static std::once_flag init_dbus
{};
59 std::call_once(init_dbus
, []{ PrepareDBus(); });
65 constexpr bool HasDBus() noexcept
{ return true; }
66 #endif /* HAVE_DYNLOAD */
72 Error() { dbus_error_init(&mError
); }
73 ~Error() { dbus_error_free(&mError
); }
74 DBusError
* operator->() { return &mError
; }
75 DBusError
&get() { return mError
; }
80 struct ConnectionDeleter
{
81 void operator()(DBusConnection
*c
) { dbus_connection_unref(c
); }
83 using ConnectionPtr
= std::unique_ptr
<DBusConnection
,ConnectionDeleter
>;
87 #endif /* CORE_DBUS_WRAP_H */