mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-02-14 01:00:27 -05:00
InputCommon: Make ControllerInterface RegisterDevicesChangedCallback use Common::HookableEvent.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user