diff --git a/repos/os/src/server/vmm/config.cc b/repos/os/src/server/vmm/config.cc index 31b863099d..1e21fabf09 100644 --- a/repos/os/src/server/vmm/config.cc +++ b/repos/os/src/server/vmm/config.cc @@ -61,6 +61,25 @@ void Vmm::Config::update(Xml_node node) _cpu_count = 1; } - Virtio_device_update_policy policy(*this); - _model.update_from_xml(policy, node); + update_list_model_from_xml(_model, node, + + /* create */ + [&] (Xml_node const &node) -> Virtio_device & + { + Config::Name name = node.attribute_value("name", Config::Name()); + Virtio_device::Type t = Virtio_device::type_from_xml(node); + + if (t == Virtio_device::INVALID || !name.valid()) { + error("Invalid type or missing name in Virtio device node"); + throw Invalid_configuration(); + } + return *new (_heap) Virtio_device(name, t, *this); + }, + + /* destroy */ + [&] (Virtio_device &dev) { destroy(_heap, &dev); }, + + /* update */ + [&] (Virtio_device &, Xml_node const &) { } + ); } diff --git a/repos/os/src/server/vmm/config.h b/repos/os/src/server/vmm/config.h index ac1ef8c670..a59223f6c8 100644 --- a/repos/os/src/server/vmm/config.h +++ b/repos/os/src/server/vmm/config.h @@ -62,6 +62,30 @@ class Vmm::Config void * const mmio_start; size_t const mmio_size; unsigned const irq; + + static Type type_from_xml(Xml_node const &node) + { + Config::Name const type = node.attribute_value("type", Config::Name()); + + if (type == "console") return CONSOLE; + if (type == "net") return NET; + if (type == "block") return BLOCK; + if (type == "gpu") return GPU; + if (type == "input") return INPUT; + + return INVALID; + } + + bool matches(Xml_node const &node) const + { + return (name == node.attribute_value("name", Config::Name())) + && (type == type_from_xml(node)); + } + + static bool type_matches(Xml_node const &node) + { + return node.has_type("virtio_device"); + } }; private: @@ -94,52 +118,6 @@ class Vmm::Config List_model _model {}; - struct Virtio_device_update_policy - : List_model::Update_policy - { - Config & config; - - Virtio_device_update_policy(Config & config) - : config(config) {} - - static Virtio_device::Type type(Xml_node node) - { - Virtio_device::Type t = Virtio_device::INVALID; - Config::Name type = node.attribute_value("type", Config::Name()); - if (type == "console") t = Virtio_device::CONSOLE; - if (type == "net") t = Virtio_device::NET; - if (type == "block") t = Virtio_device::BLOCK; - if (type == "gpu") t = Virtio_device::GPU; - if (type == "input") t = Virtio_device::INPUT; - return t; - } - - void destroy_element(Element & dev) { destroy(config._heap, &dev); } - - Element & create_element(Genode::Xml_node node) - { - Config::Name name = node.attribute_value("name", Config::Name()); - Virtio_device::Type t = type(node); - if (t == Virtio_device::INVALID || !name.valid()) { - error("Invalid type or missing name in Virtio device node"); - throw Invalid_configuration(); - } - return *(new (config._heap) Element(name, t, config)); - } - - void update_element(Element &, Genode::Xml_node) {} - - static bool element_matches_xml_node(Element const & dev, Xml_node node) - { - Config::Name name = node.attribute_value("name", Config::Name()); - Virtio_device::Type t = type(node); - return name == dev.name && t == dev.type; - } - - static bool node_is_element(Xml_node node) { - return node.has_type("virtio_device"); } - }; - public: Config(Heap & heap) : _heap(heap) {