| 702 | } // namespace |
| 703 | |
| 704 | std::unique_ptr<platf::deinit_t> init(const std::filesystem::path &persistence_filepath, const config::video_t &video_config) { |
| 705 | std::lock_guard lock {DD_DATA.mutex}; |
| 706 | // We can support re-init without any issues, however we should make sure to clean up first! |
| 707 | if (video_config.dd.configuration_option == config::video_t::dd_t::config_option_e::disabled) { |
| 708 | if (!persistence_filepath.empty() && std::filesystem::exists(persistence_filepath)) { |
| 709 | std::filesystem::remove(persistence_filepath); |
| 710 | } |
| 711 | } else { |
| 712 | revert_configuration_unlocked(revert_option_e::try_once); |
| 713 | } |
| 714 | DD_DATA.config_revert_delay = video_config.dd.config_revert_delay; |
| 715 | DD_DATA.sm_instance = nullptr; |
| 716 | |
| 717 | // If we fail to create settings manager, this means platform is not supported, and |
| 718 | // we will need to provided error-free pass-trough in other methods |
| 719 | if (auto settings_manager {make_settings_manager(persistence_filepath, video_config)}) { |
| 720 | DD_DATA.sm_instance = std::make_unique<RetryScheduler<SettingsManagerInterface>>(std::move(settings_manager)); |
| 721 | |
| 722 | const auto available_devices {DD_DATA.sm_instance->execute([](auto &settings_iface) { |
| 723 | return settings_iface.enumAvailableDevices(); |
| 724 | })}; |
| 725 | BOOST_LOG(info) << "Currently available display devices:\n" |
| 726 | << toJson(available_devices); |
| 727 | |
| 728 | // In case we have failed to revert configuration before shutting down, we should |
| 729 | // do it now. |
| 730 | revert_configuration_unlocked(revert_option_e::try_indefinitely); |
| 731 | } |
| 732 | |
| 733 | class deinit_t: public platf::deinit_t { |
| 734 | public: |
| 735 | ~deinit_t() override { |
| 736 | std::lock_guard lock {DD_DATA.mutex}; |
| 737 | try { |
| 738 | // This may throw if used incorrectly. At the moment this will not happen, however |
| 739 | // in case some unforeseen changes are made that could raise an exception, |
| 740 | // we definitely don't want this to happen in destructor. Especially in the |
| 741 | // deinit_t where the outcome does not really matter. |
| 742 | revert_configuration_unlocked(revert_option_e::try_once); |
| 743 | } catch (std::exception &err) { |
| 744 | BOOST_LOG(fatal) << err.what(); |
| 745 | } |
| 746 | |
| 747 | DD_DATA.sm_instance = nullptr; |
| 748 | } |
| 749 | }; |
| 750 | |
| 751 | return std::make_unique<deinit_t>(); |
| 752 | } |
| 753 | |
| 754 | std::string map_output_name(const std::string &output_name) { |
| 755 | std::lock_guard lock {DD_DATA.mutex}; |
nothing calls this directly
no test coverage detected