aboutsummaryrefslogtreecommitdiffstats
path: root/core/dbus_wrap.cpp
blob: 08020c9bc2589c0bd775e0ef1076be1949b95cb2 (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

#include "config.h"

#include "dbus_wrap.h"

#ifdef HAVE_DYNLOAD

#include <mutex>
#include <type_traits>

#include "albit.h"
#include "logging.h"


void PrepareDBus()
{
    const char *libname{"libdbus-1.so.3"};

    auto load_func = [](auto &f, const char *name) -> void
    { f = al::bit_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