]> git.tdb.fi Git - ext/openal.git/blob - core/dbus_wrap.cpp
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / core / dbus_wrap.cpp
1
2 #include "config.h"
3
4 #include "dbus_wrap.h"
5
6 #ifdef HAVE_DYNLOAD
7
8 #include <mutex>
9 #include <type_traits>
10
11 #include "logging.h"
12
13
14 void *dbus_handle{nullptr};
15 #define DECL_FUNC(x) decltype(p##x) p##x{};
16 DBUS_FUNCTIONS(DECL_FUNC)
17 #undef DECL_FUNC
18
19 void PrepareDBus()
20 {
21     static constexpr char libname[] = "libdbus-1.so.3";
22
23     auto load_func = [](auto &f, const char *name) -> void
24     { f = reinterpret_cast<std::remove_reference_t<decltype(f)>>(GetSymbol(dbus_handle, name)); };
25 #define LOAD_FUNC(x) do {                         \
26     load_func(p##x, #x);                          \
27     if(!p##x)                                     \
28     {                                             \
29         WARN("Failed to load function %s\n", #x); \
30         CloseLib(dbus_handle);                    \
31         dbus_handle = nullptr;                    \
32         return;                                   \
33     }                                             \
34 } while(0);
35
36     dbus_handle = LoadLib(libname);
37     if(!dbus_handle)
38     {
39         WARN("Failed to load %s\n", libname);
40         return;
41     }
42
43 DBUS_FUNCTIONS(LOAD_FUNC)
44 #undef LOAD_FUNC
45 }
46 #endif