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 ExclusiveTo exclusiveTo = ExclusiveTo::EMPTY; 46 bool updatableViaApex = false; 47 std::map<std::string, HalInterface> interfaces; 48 getNameMatrixHal49 inline const std::string& getName() const { return name; } 50 51 // Assumes isValid(). 52 bool forEachInstance(const std::function<bool(const MatrixInstance&)>& func) const; 53 54 private: 55 friend struct HalManifest; 56 friend struct CompatibilityMatrix; 57 friend struct MatrixHalConverter; 58 59 // Whether this hal is a valid one. Note that an empty MatrixHal 60 // (constructed via MatrixHal()) is valid. 61 [[nodiscard]] bool isValid(std::string* error = nullptr) const; 62 63 friend std::string expandInstances(const MatrixHal& req, const VersionRange& vr, bool brace); 64 friend std::vector<std::string> expandInstances(const MatrixHal& req); 65 66 // Loop over interface/instance for a specific VersionRange. 67 // Assumes isValid(). 68 bool forEachInstance(const VersionRange& vr, 69 const std::function<bool(const MatrixInstance&)>& func) const; 70 // Loop over interface/instance. VersionRange is supplied to the function as a vector. 71 // Assumes isValid(). 72 bool forEachInstance( 73 const std::function<bool(const std::vector<VersionRange>&, const std::string&, 74 const std::string& instanceOrPattern, bool isRegex)>& func) const; 75 76 void insertVersionRanges(const std::vector<VersionRange>& other); 77 // Return size of all interface/instance pairs. 78 size_t instancesCount() const; 79 void insertInstance(const std::string& interface, const std::string& instance, bool isRegex); 80 // Remove a specific interface/instances. Return true if removed, false otherwise. 81 bool removeInstance(const std::string& interface, const std::string& instance, bool isRegex); 82 // Remove all <interface> tags. 83 void clearInstances(); 84 }; 85 86 } // namespace vintf 87 } // namespace android 88 89 #endif // ANDROID_VINTF_MATRIX_HAL_H 90