swift
dbuscallbacks.h
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_SIM_XSWIFTBUS_DBUSASYNCCALLBACKS_H
5 #define SWIFT_SIM_XSWIFTBUS_DBUSASYNCCALLBACKS_H
6 
7 #include <dbus/dbus.h>
8 
9 #include <functional>
10 
11 namespace XSwiftBus
12 {
14  template <typename T>
15  class DBusAsyncCallbacks
16  {
17  public:
18  DBusAsyncCallbacks() = default;
19  DBusAsyncCallbacks(const std::function<dbus_bool_t(T *)> &add, const std::function<void(T *)> &remove,
20  const std::function<void(T *)> &toggled)
21  : m_addHandler(add), m_removeHandler(remove), m_toggledHandler(toggled)
22  {}
23 
24  static dbus_bool_t add(T *watch, void *refcon)
25  {
26  return static_cast<DBusAsyncCallbacks *>(refcon)->m_addHandler(watch);
27  }
28 
29  static void remove(T *watch, void *refcon)
30  {
31  return static_cast<DBusAsyncCallbacks *>(refcon)->m_removeHandler(watch);
32  }
33 
34  static void toggled(T *watch, void *refcon)
35  {
36  return static_cast<DBusAsyncCallbacks *>(refcon)->m_toggledHandler(watch);
37  }
38 
39  private:
40  std::function<dbus_bool_t(T *)> m_addHandler;
41  std::function<void(T *)> m_removeHandler;
42  std::function<void(T *)> m_toggledHandler;
43  };
45 
46 } // namespace XSwiftBus
47 
48 #endif // SWIFT_SIM_XSWIFTBUS_DBUSASYNCCALLBACKS_H
Plugin loaded by X-Plane which publishes a DBus service.
Definition: command.h:14