Log the buffer format when queueing mismatched buffers
[openal-soft.git] / core / dbus_wrap.h
blob09eaacf93bac128cf831e33b219c9cfa56fd03d1
1 #ifndef CORE_DBUS_WRAP_H
2 #define CORE_DBUS_WRAP_H
4 #include <memory>
6 #include <dbus/dbus.h>
8 #include "dynload.h"
10 #ifdef HAVE_DYNLOAD
12 #include <mutex>
14 #define DBUS_FUNCTIONS(MAGIC) \
15 MAGIC(dbus_error_init) \
16 MAGIC(dbus_error_free) \
17 MAGIC(dbus_bus_get) \
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)
34 #undef DECL_FUNC
36 #ifndef IN_IDE_PARSER
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)
52 #endif
54 void PrepareDBus();
56 inline auto HasDBus()
58 static std::once_flag init_dbus{};
59 std::call_once(init_dbus, []{ PrepareDBus(); });
60 return dbus_handle;
63 #else
65 constexpr bool HasDBus() noexcept { return true; }
66 #endif /* HAVE_DYNLOAD */
69 namespace dbus {
71 struct Error {
72 Error() { dbus_error_init(&mError); }
73 ~Error() { dbus_error_free(&mError); }
74 DBusError* operator->() { return &mError; }
75 DBusError &get() { return mError; }
76 private:
77 DBusError mError{};
80 struct ConnectionDeleter {
81 void operator()(DBusConnection *c) { dbus_connection_unref(c); }
83 using ConnectionPtr = std::unique_ptr<DBusConnection,ConnectionDeleter>;
85 } // namespace dbus
87 #endif /* CORE_DBUS_WRAP_H */