aboutsummaryrefslogtreecommitdiffstats
path: root/core/dbus_wrap.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-04-18 00:34:36 -0700
committerChris Robinson <[email protected]>2021-04-18 00:43:01 -0700
commit5165b29b1945e1cff5e8c042bd371a5b2da9b492 (patch)
tree686d5edf04f9b33ca65ec3cf16c2bf536c73400a /core/dbus_wrap.cpp
parent784dbd7d21f36b0dbf034e7ac5d46cdc5533b91b (diff)
Optionally use RTKit/D-Bus to set elevated priority
If pthread_setschedparam fails or is unavailable.
Diffstat (limited to 'core/dbus_wrap.cpp')
-rw-r--r--core/dbus_wrap.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/core/dbus_wrap.cpp b/core/dbus_wrap.cpp
new file mode 100644
index 00000000..506dd815
--- /dev/null
+++ b/core/dbus_wrap.cpp
@@ -0,0 +1,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(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