| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#pragma once |
| 8 |
|
| 9 |
#include <dbus/dbus.h> |
| 10 |
#include <functional> |
| 11 |
|
| 12 |
namespace flightgear::swift { |
| 13 |
|
| 14 |
template <typename T> |
| 15 |
class DBusAsyncCallbacks |
| 16 |
{ |
| 17 |
public: |
| 18 |
DBusAsyncCallbacks() = default; |
| 19 |
DBusAsyncCallbacks(const std::function<dbus_bool_t(T*)>& add, |
| 20 |
const std::function<void(T*)>& remove, |
| 21 |
const std::function<void(T*)>& toggled) |
| 22 |
: m_addHandler(add), m_removeHandler(remove), m_toggledHandler(toggled) |
| 23 |
{ |
| 24 |
} |
| 25 |
|
| 26 |
static dbus_bool_t add(T* watch, void* refcon) |
| 27 |
{ |
| 28 |
return static_cast<DBusAsyncCallbacks*>(refcon)->m_addHandler(watch); |
| 29 |
} |
| 30 |
|
| 31 |
static void remove(T* watch, void* refcon) |
| 32 |
{ |
| 33 |
return static_cast<DBusAsyncCallbacks*>(refcon)->m_removeHandler(watch); |
| 34 |
} |
| 35 |
|
| 36 |
static void toggled(T* watch, void* refcon) |
| 37 |
{ |
| 38 |
return static_cast<DBusAsyncCallbacks*>(refcon)->m_toggledHandler(watch); |
| 39 |
} |
| 40 |
|
| 41 |
private: |
| 42 |
std::function<dbus_bool_t(T*)> m_addHandler; |
| 43 |
std::function<void(T*)> m_removeHandler; |
| 44 |
std::function<void(T*)> m_toggledHandler; |
| 45 |
}; |
| 46 |
|
| 47 |
} |