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 /MatrixHal.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 'MatrixHal.cpp')
-rw-r--r--MatrixHal.cpp59
1 files changed, 33 insertions, 26 deletions
diff --git a/MatrixHal.cpp b/MatrixHal.cpp
index a7a3b2d..da6b55f 100644
--- a/MatrixHal.cpp
+++ b/MatrixHal.cpp
@@ -55,15 +55,20 @@ bool MatrixHal::forEachInstance(const std::function<bool(const MatrixInstance&)>
55bool MatrixHal::forEachInstance(const VersionRange& vr, 55bool MatrixHal::forEachInstance(const VersionRange& vr,
56 const std::function<bool(const MatrixInstance&)>& func) const { 56 const std::function<bool(const MatrixInstance&)>& func) const {
57 for (const auto& intf : iterateValues(interfaces)) { 57 for (const auto& intf : iterateValues(interfaces)) {
58 for (const auto& instance : intf.instances) { 58 bool cont =
59 // TODO(b/73556059): Store MatrixInstance as well to avoid creating temps 59 intf.forEachInstance([&](const auto& interface, const auto& instance, bool isRegex) {
60 FqInstance fqInstance; 60 // TODO(b/73556059): Store MatrixInstance as well to avoid creating temps
61 if (fqInstance.setTo(getName(), vr.majorVer, vr.minMinor, intf.name, instance)) { 61 FqInstance fqInstance;
62 if (!func(MatrixInstance(std::move(fqInstance), VersionRange(vr), optional, 62 if (fqInstance.setTo(getName(), vr.majorVer, vr.minMinor, interface, instance)) {
63 false /* isRegex */))) { 63 if (!func(MatrixInstance(std::move(fqInstance), VersionRange(vr), optional,
64 return false; 64 isRegex))) {
65 return false;
66 }
65 } 67 }
66 } 68 return true;
69 });
70 if (!cont) {
71 return false;
67 } 72 }
68 } 73 }
69 return true; 74 return true;
@@ -71,12 +76,14 @@ bool MatrixHal::forEachInstance(const VersionRange& vr,
71 76
72bool MatrixHal::forEachInstance( 77bool MatrixHal::forEachInstance(
73 const std::function<bool(const std::vector<VersionRange>&, const std::string&, 78 const std::function<bool(const std::vector<VersionRange>&, const std::string&,
74 const std::string&)>& func) const { 79 const std::string&, bool isRegex)>& func) const {
75 for (const auto& intf : iterateValues(interfaces)) { 80 for (const auto& intf : iterateValues(interfaces)) {
76 for (const auto& instance : intf.instances) { 81 bool cont =
77 if (!func(versionRanges, intf.name, instance)) { 82 intf.forEachInstance([&](const auto& interface, const auto& instance, bool isRegex) {
78 return false; 83 return func(this->versionRanges, interface, instance, isRegex);
79 } 84 });
85 if (!cont) {
86 return false;
80 } 87 }
81 } 88 }
82 return true; 89 return true;
@@ -141,16 +148,7 @@ void MatrixHal::insertInstance(const std::string& interface, const std::string&
141 auto it = interfaces.find(interface); 148 auto it = interfaces.find(interface);
142 if (it == interfaces.end()) 149 if (it == interfaces.end())
143 it = interfaces.emplace(interface, HalInterface{interface, {}}).first; 150 it = interfaces.emplace(interface, HalInterface{interface, {}}).first;
144 it->second.instances.insert(instance); 151 it->second.insertInstance(instance, false /* isRegex */);
145}
146
147bool MatrixHal::hasAnyInstance() const {
148 bool found = false;
149 forEachInstance([&](const auto&) {
150 found = true;
151 return false; // break if any instance
152 });
153 return found;
154} 152}
155 153
156bool MatrixHal::hasInstance(const std::string& interface, const std::string& instance) const { 154bool MatrixHal::hasInstance(const std::string& interface, const std::string& instance) const {
@@ -163,6 +161,15 @@ bool MatrixHal::hasInstance(const std::string& interface, const std::string& ins
163 return found; 161 return found;
164} 162}
165 163
164size_t MatrixHal::instancesCount() const {
165 size_t count = 0;
166 forEachInstance([&](const MatrixInstance&) {
167 ++count;
168 return true; // continue;
169 });
170 return count;
171}
172
166bool MatrixHal::hasOnlyInstance(const std::string& interface, const std::string& instance) const { 173bool MatrixHal::hasOnlyInstance(const std::string& interface, const std::string& instance) const {
167 bool found = false; 174 bool found = false;
168 bool foundOthers = false; 175 bool foundOthers = false;
@@ -183,9 +190,9 @@ bool MatrixHal::hasOnlyInstance(const std::string& interface, const std::string&
183bool MatrixHal::removeInstance(const std::string& interface, const std::string& instance) { 190bool MatrixHal::removeInstance(const std::string& interface, const std::string& instance) {
184 auto it = interfaces.find(interface); 191 auto it = interfaces.find(interface);
185 if (it == interfaces.end()) return false; 192 if (it == interfaces.end()) return false;
186 it->second.instances.erase(instance); 193 bool removed = it->second.removeInstance(instance, false /* isRegex */);
187 if (it->second.instances.empty()) interfaces.erase(it); 194 if (!it->second.hasAnyInstance()) interfaces.erase(it);
188 return true; 195 return removed;
189} 196}
190 197
191void MatrixHal::clearInstances() { 198void MatrixHal::clearInstances() {