depot_download: use modern list-model interface

Issue #4317
This commit is contained in:
Norman Feske 2023-10-27 16:16:55 +02:00 committed by Christian Helmuth
parent b249d9f66d
commit 3e24a86b87
2 changed files with 17 additions and 25 deletions

View File

@ -36,31 +36,12 @@ struct Depot_download_manager::Job : List_model<Job>::Element
Job(Archive::Path const &path) : path(path) { }
struct Update_policy
bool matches(Xml_node const &node) const
{
typedef Job Element;
return node.attribute_value("path", Archive::Path()) == path;
}
Allocator &_alloc;
Update_policy(Allocator &alloc) : _alloc(alloc) { }
void destroy_element(Job &elem) { destroy(_alloc, &elem); }
Job &create_element(Xml_node elem_node)
{
return *new (_alloc)
Job(elem_node.attribute_value("path", Archive::Path()));
}
void update_element(Job &, Xml_node) { }
static bool element_matches_xml_node(Job const &job, Xml_node node)
{
return node.attribute_value("path", Archive::Path()) == job.path;
}
static bool node_is_element(Xml_node) { return true; }
};
static bool type_matches(Xml_node const &) { return true; }
};
#endif /* _JOB_H_ */

View File

@ -163,8 +163,19 @@ struct Depot_download_manager::Main
{
_installation.update();
Job::Update_policy policy(_heap);
_jobs.update_from_xml(policy, _installation.xml());
update_list_model_from_xml(_jobs, _installation.xml(),
/* create */
[&] (Xml_node const &node) -> Job & {
return *new (_heap)
Job(node.attribute_value("path", Archive::Path())); },
/* destroy */
[&] (Job &job) { destroy(_heap, &job); },
/* update */
[&] (Job &, Xml_node const &) { }
);
_depot_query_count.value++;