🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

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