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
diff --git a/VintfObject.cpp b/VintfObject.cpp
index 88bcce2..367dc17 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -578,28 +578,28 @@
bool VintfObject::isHalDeprecated(const MatrixHal& oldMatrixHal,
const CompatibilityMatrix& targetMatrix,
const IsInstanceInUse& isInstanceInUse, std::string* error) {
- for (const VersionRange& range : oldMatrixHal.versionRanges) {
- for (const HalInterface& interface : iterateValues(oldMatrixHal.interfaces)) {
- for (const std::string& instance : interface.instances) {
- if (isInstanceDeprecated(oldMatrixHal.name, range.minVer(), interface.name,
- instance, targetMatrix, isInstanceInUse, error)) {
- return true;
- }
- }
+ bool isDeprecated = false;
+ oldMatrixHal.forEachInstance([&](const MatrixInstance& oldMatrixInstance) {
+ if (isInstanceDeprecated(oldMatrixInstance, targetMatrix, isInstanceInUse, error)) {
+ isDeprecated = true;
}
- }
- return false;
+ return !isDeprecated; // continue if no deprecated instance is found.
+ });
+ return isDeprecated;
}
// If isInstanceInUse(package@x.y::interface/instance), return true iff:
// 1. package@x.?::interface/instance is not in targetMatrix; OR
// 2. package@x.z::interface/instance is in targetMatrix but
// !isInstanceInUse(package@x.z::interface/instance)
-bool VintfObject::isInstanceDeprecated(const std::string& package, Version version,
- const std::string& interface, const std::string& instance,
+bool VintfObject::isInstanceDeprecated(const MatrixInstance& oldMatrixInstance,
const CompatibilityMatrix& targetMatrix,
- const IsInstanceInUse& isInstanceInUse,
- std::string* error) {
+ const IsInstanceInUse& isInstanceInUse, std::string* error) {
+ const std::string& package = oldMatrixInstance.package();
+ const Version& version = oldMatrixInstance.versionRange().minVer();
+ const std::string& interface = oldMatrixInstance.interface();
+ const std::string& instance = oldMatrixInstance.instance();
+
bool oldVersionIsServed;
Version servedVersion;
std::tie(oldVersionIsServed, servedVersion) =