rom_filter: copy input node content to output node

Add suppport for copying the content of an 'input' node to the 'output'
node.

Issue #2558.
This commit is contained in:
Josef Söntgen 2017-11-09 11:48:32 +01:00 committed by Christian Helmuth
parent f9c2e0e21c
commit adb00d329f
3 changed files with 49 additions and 0 deletions

View File

@ -30,6 +30,10 @@ The '<output>' node can contain the following sub nodes:
sub node is evaluated. Each of those sub nodes can contain the same
nodes as the '<output>' node.
:'<input>':
Copies all sub nodes named by the 'sub_node' attribute of the input ROM
specified by the 'name' attribute to the output node.
Conditions
----------

View File

@ -54,6 +54,7 @@ class Rom_filter::Input_rom_registry
* Exception type
*/
class Nonexistent_input_value { };
class Nonexistent_input_node { };
private:
@ -191,6 +192,15 @@ class Rom_filter::Input_rom_registry
throw Nonexistent_input_value();
}
Xml_node node() const
{
try {
return Xml_node(_top_level);
} catch (...) { }
throw Nonexistent_input_node();
}
};
Genode::Allocator &_alloc;
@ -372,6 +382,21 @@ class Rom_filter::Input_rom_registry
return input_value;
}
/**
* Lookup content of input with specified name
*
* \throw Nonexistent_input_value
*/
Xml_node xml(Input_name const &input_name) const
{
Entry const *e = _lookup_entry_by_name(input_name);
if (!e)
throw Nonexistent_input_node();
return e->node();
}
};
#endif /* _INPUT_ROM_REGISTRY_H_ */

View File

@ -310,6 +310,26 @@ void Rom_filter::Main::_evaluate_node(Xml_node node, Xml_generator &xml)
for (; src_len > 0 && Genode::is_whitespace(src[src_len - 1]); src_len--);
xml.append(src, src_len);
} else
if (node.has_type("input")) {
typedef Genode::String<128> String;
Input_name const input_name =
node.attribute_value("name", Input_name());
String const sub_node =
node.attribute_value("sub_node", String());
if (!sub_node.valid())
return;
try {
Xml_node input_node = _input_rom_registry.xml(input_name);
input_node.for_each_sub_node(sub_node.string(),
[&] (Xml_node node) { xml.append(node.addr(), node.size()); });
} catch (...) { }
}
};