feat(display): retry reverting configuration only if device was added or removed (#3539)
This commit is contained in:
parent
7f0351d125
commit
fb557df270
2 changed files with 37 additions and 4 deletions
|
|
@ -674,11 +674,44 @@ namespace display_device {
|
||||||
scheduler_option.m_execution = SchedulerOptions::Execution::ScheduledOnly;
|
scheduler_option.m_execution = SchedulerOptions::Execution::ScheduledOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
DD_DATA.sm_instance->schedule([try_once = (option == revert_option_e::try_once)](auto &settings_iface, auto &stop_token) {
|
DD_DATA.sm_instance->schedule([try_once = (option == revert_option_e::try_once), tried_out_devices = std::set<std::string> {}](auto &settings_iface, auto &stop_token) mutable {
|
||||||
// Here we want to keep retrying indefinitely until we succeed.
|
if (try_once) {
|
||||||
if (settings_iface.revertSettings() || try_once) {
|
std::ignore = settings_iface.revertSettings();
|
||||||
stop_token.requestStop();
|
stop_token.requestStop();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto available_devices { [&settings_iface]() {
|
||||||
|
const auto devices { settings_iface.enumAvailableDevices() };
|
||||||
|
std::set<std::string> parsed_devices;
|
||||||
|
|
||||||
|
std::transform(
|
||||||
|
std::begin(devices), std::end(devices),
|
||||||
|
std::inserter(parsed_devices, std::end(parsed_devices)),
|
||||||
|
[](const auto &device) { return device.m_device_id + " - " + device.m_friendly_name; });
|
||||||
|
|
||||||
|
return parsed_devices;
|
||||||
|
}() };
|
||||||
|
if (available_devices == tried_out_devices) {
|
||||||
|
BOOST_LOG(debug) << "Skipping reverting configuration, because no newly added/removed devices were detected since last check. Currently available devices:\n"
|
||||||
|
<< toJson(available_devices);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using enum SettingsManagerInterface::RevertResult;
|
||||||
|
if (const auto result { settings_iface.revertSettings() }; result == Ok) {
|
||||||
|
stop_token.requestStop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (result == ApiTemporarilyUnavailable) {
|
||||||
|
// Do nothing and retry next time
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have failed to revert settings then we will try to do it next time only if a device was added/removed
|
||||||
|
BOOST_LOG(warning) << "Failed to revert display device configuration (will retry once devices are added or removed). Enabling all of the available devices:\n"
|
||||||
|
<< toJson(available_devices);
|
||||||
|
tried_out_devices.swap(available_devices);
|
||||||
},
|
},
|
||||||
scheduler_option);
|
scheduler_option);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
third-party/libdisplaydevice
vendored
2
third-party/libdisplaydevice
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2c431bce2981ebb4b6c116c7e11372a045596b70
|
Subproject commit 63599b07659a5d1dd554a24bd0c8e96b21e21112
|
||||||
Loading…
Add table
Add a link
Reference in a new issue