1 // dbuscallbacks.h 2 // 3 // Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/) 4 // Adapted to Flightgear by Lars Toenning <dev@ltoenning.de> 5 // 6 // This program is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU General Public License as 8 // published by the Free Software Foundation; either version 2 of the 9 // License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, but 12 // WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 // General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 20 #ifndef BLACKSIM_FGSWIFTBUS_DBUSASYNCCALLBACKS_H 21 #define BLACKSIM_FGSWIFTBUS_DBUSASYNCCALLBACKS_H 22 23 #include <dbus/dbus.h> 24 #include <functional> 25 26 namespace FGSwiftBus 27 { 28 //! \cond PRIVATE 29 template <typename T> 30 class DBusAsyncCallbacks 31 { 32 public: 33 DBusAsyncCallbacks() = default; DBusAsyncCallbacks(const std::function<dbus_bool_t (T *)> & add,const std::function<void (T *)> & remove,const std::function<void (T *)> & toggled)34 DBusAsyncCallbacks(const std::function<dbus_bool_t(T *)> &add, 35 const std::function<void(T *)> &remove, 36 const std::function<void(T *)> &toggled) 37 : m_addHandler(add), m_removeHandler(remove), m_toggledHandler(toggled) 38 { } 39 add(T * watch,void * refcon)40 static dbus_bool_t add(T *watch, void *refcon) 41 { 42 return static_cast<DBusAsyncCallbacks *>(refcon)->m_addHandler(watch); 43 } 44 remove(T * watch,void * refcon)45 static void remove(T *watch, void *refcon) 46 { 47 return static_cast<DBusAsyncCallbacks *>(refcon)->m_removeHandler(watch); 48 } 49 toggled(T * watch,void * refcon)50 static void toggled(T *watch, void *refcon) 51 { 52 return static_cast<DBusAsyncCallbacks *>(refcon)->m_toggledHandler(watch); 53 } 54 55 private: 56 std::function<dbus_bool_t(T *)> m_addHandler; 57 std::function<void(T *)> m_removeHandler; 58 std::function<void(T *)> m_toggledHandler; 59 }; 60 //! \endcond 61 62 } 63 64 #endif // guard 65