From a57dd46affcd0e2aa71159081920c7a77e59bf27 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 22 Jan 2018 13:55:27 +0100 Subject: [PATCH] depot_query: obtain query from separate ROM This patch adds the config attribute 'query'. If set to the value "rom", the query information is obtained from a ROM session labeled "query". Otherwise, the query information is expected to be part of the config. This enables us to use the component in two different scenarios. In one scenario, 'depot_query' is embedded in a managed dynamic init. Here, taking the query from the config is easy. In the other scenario, 'depot_query' is running as a daemon with a once-configured VFS but varying queries. The queries originate from a component that does not control the 'depot_query' config. --- repos/gems/src/app/depot_query/main.cc | 49 ++++++++++++++++++-------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/repos/gems/src/app/depot_query/main.cc b/repos/gems/src/app/depot_query/main.cc index e6dc77f232..5b1fb0cb2d 100644 --- a/repos/gems/src/app/depot_query/main.cc +++ b/repos/gems/src/app/depot_query/main.cc @@ -152,6 +152,8 @@ struct Depot_query::Main Attached_rom_dataspace _config { _env, "config" }; + Constructible _query_rom { }; + Root_directory _root { _env, _heap, _config.xml().sub_node("vfs") }; Directory _depot_dir { _root, "depot" }; @@ -191,23 +193,44 @@ struct Depot_query::Main { _config.update(); - Xml_node config = _config.xml(); + Xml_node const config = _config.xml(); - _directory_reporter .enabled(config.has_sub_node("scan")); - _blueprint_reporter .enabled(config.has_sub_node("blueprint")); - _dependencies_reporter.enabled(config.has_sub_node("dependencies")); - _user_reporter .enabled(config.has_sub_node("user")); + /* + * Depending of the 'query' config attribute, we obtain the query + * information from a separate ROM session (attribute value "rom") + * or from the depot_querty ''. + */ + bool const query_from_rom = + (config.attribute_value("query", String<5>()) == "rom"); + + if (query_from_rom && !_query_rom.constructed()) { + _query_rom.construct(_env, "query"); + _query_rom->sigh(_config_handler); + } + + if (!query_from_rom && _query_rom.constructed()) + _query_rom.destruct(); + + if (query_from_rom) + _query_rom->update(); + + Xml_node const query = (query_from_rom ? _query_rom->xml() : config); + + _directory_reporter .enabled(query.has_sub_node("scan")); + _blueprint_reporter .enabled(query.has_sub_node("blueprint")); + _dependencies_reporter.enabled(query.has_sub_node("dependencies")); + _user_reporter .enabled(query.has_sub_node("user")); _root.apply_config(config.sub_node("vfs")); - if (!config.has_attribute("arch")) - warning("config lacks 'arch' attribute"); + if (!query.has_attribute("arch")) + warning("query lacks 'arch' attribute"); - _architecture = config.attribute_value("arch", Architecture()); + _architecture = query.attribute_value("arch", Architecture()); if (_directory_reporter.enabled()) { Reporter::Xml_generator xml(_directory_reporter, [&] () { - config.for_each_sub_node("scan", [&] (Xml_node node) { + query.for_each_sub_node("scan", [&] (Xml_node node) { Archive::User const user = node.attribute_value("user", Archive::User()); Directory::Path path("depot/", user, "/pkg"); Directory pkg_dir(_root, path); @@ -218,7 +241,7 @@ struct Depot_query::Main if (_blueprint_reporter.enabled()) { Reporter::Xml_generator xml(_blueprint_reporter, [&] () { - config.for_each_sub_node("blueprint", [&] (Xml_node node) { + query.for_each_sub_node("blueprint", [&] (Xml_node node) { Archive::Path pkg = node.attribute_value("pkg", Archive::Path()); try { _query_blueprint(pkg, xml); } catch (...) { @@ -230,10 +253,8 @@ struct Depot_query::Main if (_dependencies_reporter.enabled()) { Reporter::Xml_generator xml(_dependencies_reporter, [&] () { - Dependencies dependencies(_heap, _depot_dir); - - config.for_each_sub_node("dependencies", [&] (Xml_node node) { + query.for_each_sub_node("dependencies", [&] (Xml_node node) { Archive::Path const path = node.attribute_value("path", Archive::Path()); @@ -249,7 +270,7 @@ struct Depot_query::Main if (_user_reporter.enabled()) { Reporter::Xml_generator xml(_user_reporter, [&] () { - config.for_each_sub_node("user", [&] (Xml_node node) { + query.for_each_sub_node("user", [&] (Xml_node node) { _query_user(node.attribute_value("name", Archive::User()), xml); }); }); }