From 79d8d1d557a26419414fca4779de2a72149b498e Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 10 Jan 2023 15:53:00 +0100 Subject: [PATCH] sculpt_manager: Deploy::use_as_deploy_template This patch simplifies the 'Deploy::update_managed_deploy_config' interface by keeping an internal copy of the currently used deploy template inside the 'Deploy' class. The template is updated whenever the config/deploy file is modified. This change weakens the coupling between the '_manual_deploy_rom' and the '_deploy' subsystem, easing the upcoming implementation of the switching between presets. --- repos/gems/src/app/sculpt_manager/deploy.h | 22 +++++++++++++++++++++- repos/gems/src/app/sculpt_manager/main.cc | 11 ++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/repos/gems/src/app/sculpt_manager/deploy.h b/repos/gems/src/app/sculpt_manager/deploy.h index 296ff54834..26aa60fbed 100644 --- a/repos/gems/src/app/sculpt_manager/deploy.h +++ b/repos/gems/src/app/sculpt_manager/deploy.h @@ -78,7 +78,27 @@ struct Sculpt::Deploy /* config obtained from '/config/managed/deploy' */ Attached_rom_dataspace _managed_deploy_rom { _env, "config -> managed/deploy" }; - void update_managed_deploy_config(Xml_node deploy) + Constructible _template { }; + + void use_as_deploy_template(Xml_node const &deploy) + { + _template.construct(_alloc, deploy); + } + + void update_managed_deploy_config() + { + if (!_template.constructed()) + return; + + Xml_node const deploy = _template->xml(); + + if (deploy.type() == "empty") + return; + + _update_managed_deploy_config(deploy); + } + + void _update_managed_deploy_config(Xml_node deploy) { /* * Ignore intermediate states that may occur when manually updating diff --git a/repos/gems/src/app/sculpt_manager/main.cc b/repos/gems/src/app/sculpt_manager/main.cc index 03dce96546..172631b683 100644 --- a/repos/gems/src/app/sculpt_manager/main.cc +++ b/repos/gems/src/app/sculpt_manager/main.cc @@ -397,7 +397,8 @@ struct Sculpt::Main : Input_event_handler, { _runtime_state.reset_abandoned_and_launched_children(); _manual_deploy_rom.update(); - _deploy.update_managed_deploy_config(_manual_deploy_rom.xml()); + _deploy.use_as_deploy_template(_manual_deploy_rom.xml()); + _deploy.update_managed_deploy_config(); } Signal_handler
_manual_deploy_handler { @@ -794,7 +795,7 @@ struct Sculpt::Main : Input_event_handler, _runtime_state.abandon(name); /* update config/managed/deploy with the component 'name' removed */ - _deploy.update_managed_deploy_config(_manual_deploy_rom.xml()); + _deploy.update_managed_deploy_config(); } /* @@ -822,7 +823,7 @@ struct Sculpt::Main : Input_event_handler, _runtime_state.restart(name); /* update config/managed/deploy with the component 'name' removed */ - _deploy.update_managed_deploy_config(_manual_deploy_rom.xml()); + _deploy.update_managed_deploy_config(); } } @@ -1078,7 +1079,7 @@ struct Sculpt::Main : Input_event_handler, _close_popup_dialog(); /* trigger change of the deployment */ - _deploy.update_managed_deploy_config(_manual_deploy_rom.xml()); + _deploy.update_managed_deploy_config(); } Start_name new_construction(Component::Path const &pkg, @@ -1101,7 +1102,7 @@ struct Sculpt::Main : Input_event_handler, _close_popup_dialog(); /* trigger change of the deployment */ - _deploy.update_managed_deploy_config(_manual_deploy_rom.xml()); + _deploy.update_managed_deploy_config(); } void trigger_download(Path const &path) override