ControllerInterface: Allow hotplug callbacks to be unregistered and don't reload the entire config from the ini file on hotplug, just update the control references. This should fix a crash on shutdown on Android.

This commit is contained in:
Jordan Woyak 2019-01-10 09:02:38 -06:00
parent c2afcb0f6b
commit b425f86121
10 changed files with 62 additions and 16 deletions

View file

@ -249,10 +249,20 @@ void ControllerInterface::UpdateInput()
// 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
void ControllerInterface::RegisterDevicesChangedCallback(std::function<void()> callback)
// Returns a handle for later removing the callback.
ControllerInterface::HotplugCallbackHandle
ControllerInterface::RegisterDevicesChangedCallback(std::function<void()> callback)
{
std::lock_guard<std::mutex> 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)
{
std::lock_guard<std::mutex> lk(m_callbacks_mutex);
m_devices_changed_callbacks.erase(handle);
}
// Invoke all callbacks that were registered