#pragma once #include "util/helpers/Singleton.h" #include #include enum class Events : int32_t { ControllerChanged, }; using ControllerChangedFunc = void(void); class EventService : public Singleton { friend class Singleton; EventService() = default; public: template boost::signals2::connection connect(TFunc function, TClass thisptr) { using namespace boost::placeholders; if constexpr (event == Events::ControllerChanged) return m_controller_changed_signal.connect(boost::bind(function, thisptr)); else { cemu_assert_suspicious(); } } template void disconnect(const boost::signals2::connection& slot) { using namespace boost::placeholders; if constexpr (event == Events::ControllerChanged) m_controller_changed_signal.disconnect(slot); else { cemu_assert_suspicious(); } } template void signal(TArgs&&... args) { try { if constexpr (event == Events::ControllerChanged) m_controller_changed_signal(std::forward(args)...); else { cemu_assert_suspicious(); } } catch (const std::exception& ex) { cemuLog_force("error when signaling {}: {}", event, ex.what()); } } private: boost::signals2::signal m_controller_changed_signal; };