summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2018-03-20 15:06:00 -0500
committerYifan Hong2018-03-22 16:54:15 -0500
commit7e9e04d10d74377a13d36d3f945b1cbc1aaf1a50 (patch)
treeebd240c54df6a79a9460d7ebea539dae2e93392c /parse_xml.cpp
parent85103c60a46945fbd318d3c1e2d9a0bb5768c948 (diff)
downloadplatform-system-libvintf-7e9e04d10d74377a13d36d3f945b1cbc1aaf1a50.tar.gz
platform-system-libvintf-7e9e04d10d74377a13d36d3f945b1cbc1aaf1a50.tar.xz
platform-system-libvintf-7e9e04d10d74377a13d36d3f945b1cbc1aaf1a50.zip
regex-instance: HalInterface: add regex API and hide public fields
<regex-instance> is added under an <interface> tag, which is represented by an HalInterface object. Add API for looping over all <regex-instance>s / <instance>s under it. With this API, HalInterface can hide its public fields. Bug: 73738616 Test: libvintf_test Test: vintf_object_test Test: vts_treble_vintf_test Change-Id: Ia072dd7e946c28789797db8a46fd968bc7872dca
Diffstat (limited to 'parse_xml.cpp')
-rw-r--r--parse_xml.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/parse_xml.cpp b/parse_xml.cpp
index 38a09b4..3d67e1c 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -473,22 +473,24 @@ KernelConfigConverter kernelConfigConverter{};
473struct HalInterfaceConverter : public XmlNodeConverter<HalInterface> { 473struct HalInterfaceConverter : public XmlNodeConverter<HalInterface> {
474 std::string elementName() const override { return "interface"; } 474 std::string elementName() const override { return "interface"; }
475 void mutateNode(const HalInterface &intf, NodeType *root, DocType *d) const override { 475 void mutateNode(const HalInterface &intf, NodeType *root, DocType *d) const override {
476 appendTextElement(root, "name", intf.name, d); 476 appendTextElement(root, "name", intf.name(), d);
477 appendTextElements(root, "instance", intf.instances, d); 477 appendTextElements(root, "instance", intf.mInstances, d);
478 } 478 }
479 bool buildObject(HalInterface* intf, NodeType* root, std::string* error) const override { 479 bool buildObject(HalInterface* intf, NodeType* root, std::string* error) const override {
480 std::vector<std::string> instances; 480 std::vector<std::string> instances;
481 if (!parseTextElement(root, "name", &intf->name, error) || 481 if (!parseTextElement(root, "name", &intf->mName, error) ||
482 !parseTextElements(root, "instance", &instances, error)) { 482 !parseTextElements(root, "instance", &instances, error)) {
483 return false; 483 return false;
484 } 484 }
485 intf->instances.clear(); 485 bool success = true;
486 intf->instances.insert(instances.begin(), instances.end()); 486 for (const auto& e : instances) {
487 if (intf->instances.size() != instances.size()) { 487 if (!intf->insertInstance(e, false /* isRegex */)) {
488 *error = "Duplicated instances in " + intf->name; 488 if (!error->empty()) *error += "\n";
489 return false; 489 *error += "Duplicated instance '" + e + "' in " + intf->name();
490 success = false;
491 }
490 } 492 }
491 return true; 493 return success;
492 } 494 }
493}; 495};
494 496
@@ -514,7 +516,7 @@ struct MatrixHalConverter : public XmlNodeConverter<MatrixHal> {
514 return false; 516 return false;
515 } 517 }
516 for (auto&& interface : interfaces) { 518 for (auto&& interface : interfaces) {
517 std::string name{interface.name}; 519 std::string name{interface.name()};
518 auto res = object->interfaces.emplace(std::move(name), std::move(interface)); 520 auto res = object->interfaces.emplace(std::move(name), std::move(interface));
519 if (!res.second) { 521 if (!res.second) {
520 *error = "Duplicated interface entry \"" + res.first->first + 522 *error = "Duplicated interface entry \"" + res.first->first +
@@ -663,8 +665,7 @@ struct ManifestHalConverter : public XmlNodeConverter<ManifestHal> {
663 665
664 object->interfaces.clear(); 666 object->interfaces.clear();
665 for (auto &&interface : interfaces) { 667 for (auto &&interface : interfaces) {
666 auto res = object->interfaces.emplace(interface.name, 668 auto res = object->interfaces.emplace(interface.name(), std::move(interface));
667 std::move(interface));
668 if (!res.second) { 669 if (!res.second) {
669 *error = "Duplicated interface entry \"" + res.first->first + 670 *error = "Duplicated interface entry \"" + res.first->first +
670 "\"; if additional instances are needed, add them to the " 671 "\"; if additional instances are needed, add them to the "