diff options
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index b8651c608d..19ac7d3690 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -413,27 +413,16 @@ bool ControllerInterface::IsMouseCenteringRequested() const // Register a callback to be called when a device is added or removed (as from the input backends' // hotplug thread), or when devices are refreshed // Returns a handle for later removing the callback. -ControllerInterface::HotplugCallbackHandle -ControllerInterface::RegisterDevicesChangedCallback(std::function<void()> callback) -{ - std::lock_guard lk(m_callbacks_mutex); - m_devices_changed_callbacks.emplace_back(std::move(callback)); - return std::prev(m_devices_changed_callbacks.end()); -} -// Unregister a device callback. -void ControllerInterface::UnregisterDevicesChangedCallback(const HotplugCallbackHandle& handle) +Common::EventHook +ControllerInterface::RegisterDevicesChangedCallback(std::string_view name, + Common::HookableEvent<>::CallbackType callback) { - std::lock_guard lk(m_callbacks_mutex); - m_devices_changed_callbacks.erase(handle); + return m_devices_changed_event.Register(std::move(callback), name); } // Invoke all callbacks that were registered -void ControllerInterface::InvokeDevicesChangedCallbacks() const +void ControllerInterface::InvokeDevicesChangedCallbacks() { - m_callbacks_mutex.lock(); - const auto devices_changed_callbacks = m_devices_changed_callbacks; - m_callbacks_mutex.unlock(); - for (const auto& callback : devices_changed_callbacks) - callback(); + m_devices_changed_event.Trigger(); } |
