1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_VINTF_MATRIX_HAL_H 18 #define ANDROID_VINTF_MATRIX_HAL_H 19 20 #include <map> 21 #include <set> 22 #include <string> 23 #include <vector> 24 25 #include "ExclusiveTo.h" 26 #include "HalFormat.h" 27 #include "HalInterface.h" 28 #include "MatrixInstance.h" 29 #include "VersionRange.h" 30 31 namespace android { 32 namespace vintf { 33 34 // A HAL entry to a compatibility matrix 35 struct MatrixHal { 36 using InstanceType = MatrixInstance; 37 38 bool operator==(const MatrixHal &other) const; 39 // Check whether the MatrixHal contains the given version. 40 bool containsVersion(const Version& version) const; 41 42 HalFormat format = HalFormat::HIDL; 43 std::string name; 44 std::vector<VersionRange> versionRanges; 45 bool optional = false; 46 ExclusiveTo exclusiveTo = ExclusiveTo::EMPTY; 47 bool updatableViaApex = false; 48 std::map<std::string, HalInterface> interfaces; 49 getNameMatrixHal50 inline const std::string& getName() const { return name; } 51 52 // Assumes isValid(). 53 bool forEachInstance(const std::function<bool(const MatrixInstance&)>& func) const; 54 55 private: 56 friend struct HalManifest; 57 friend struct CompatibilityMatrix; 58 friend struct MatrixHalConverter; 59 60 // Whether this hal is a valid one. Note that an empty MatrixHal 61 // (constructed via MatrixHal()) is valid. 62 [[nodiscard]] bool isValid(std::string* error = nullptr) const; 63 64 friend std::string expandInstances(const MatrixHal& req, const VersionRange& vr, bool brace); 65 friend std::vector<std::string> expandInstances(const MatrixHal& req); 66 67 // Loop over interface/instance for a specific VersionRange. 68 // Assumes isValid(). 69 bool forEachInstance(const VersionRange& vr, 70 const std::function<bool(const MatrixInstance&)>& func) const; 71 // Loop over interface/instance. VersionRange is supplied to the function as a vector. 72 // Assumes isValid(). 73 bool forEachInstance( 74 const std::function<bool(const std::vector<VersionRange>&, const std::string&, 75 const std::string& instanceOrPattern, bool isRegex)>& func) const; 76 77 bool isCompatible(const std::set<FqInstance>& providedInstances, 78 const std::set<Version>& providedVersions) const; 79 bool isCompatible(const VersionRange& vr, const std::set<FqInstance>& providedInstances, 80 const std::set<Version>& providedVersions) const; 81 82 void setOptional(bool o); 83 void insertVersionRanges(const std::vector<VersionRange>& other); 84 // Return size of all interface/instance pairs. 85 size_t instancesCount() const; 86 void insertInstance(const std::string& interface, const std::string& instance, bool isRegex); 87 // Remove a specific interface/instances. Return true if removed, false otherwise. 88 bool removeInstance(const std::string& interface, const std::string& instance, bool isRegex); 89 // Remove all <interface> tags. 90 void clearInstances(); 91 }; 92 93 } // namespace vintf 94 } // namespace android 95 96 #endif // ANDROID_VINTF_MATRIX_HAL_H 97