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