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 "HalFormat.h" 26 #include "HalInterface.h" 27 #include "MatrixInstance.h" 28 #include "VersionRange.h" 29 30 namespace android { 31 namespace vintf { 32 33 // A HAL entry to a compatibility matrix 34 struct MatrixHal { 35 using InstanceType = MatrixInstance; 36 37 bool operator==(const MatrixHal &other) const; 38 // Check whether the MatrixHal contains the given version. 39 bool containsVersion(const Version& version) const; 40 41 HalFormat format = HalFormat::HIDL; 42 std::string name; 43 std::vector<VersionRange> versionRanges; 44 bool optional = false; 45 std::map<std::string, HalInterface> interfaces; 46 getNameMatrixHal47 inline const std::string& getName() const { return name; } 48 49 bool forEachInstance(const std::function<bool(const MatrixInstance&)>& func) const; 50 51 private: 52 friend struct HalManifest; 53 friend struct CompatibilityMatrix; 54 friend std::string expandInstances(const MatrixHal& req, const VersionRange& vr, bool brace); 55 friend std::vector<std::string> expandInstances(const MatrixHal& req); 56 57 // Loop over interface/instance for a specific VersionRange. 58 bool forEachInstance(const VersionRange& vr, 59 const std::function<bool(const MatrixInstance&)>& func) const; 60 // Loop over interface/instance. VersionRange is supplied to the function as a vector. 61 bool forEachInstance( 62 const std::function<bool(const std::vector<VersionRange>&, const std::string&, 63 const std::string& instanceOrPattern, bool isRegex)>& func) const; 64 65 bool isCompatible(const std::set<FqInstance>& providedInstances, 66 const std::set<Version>& providedVersions) const; 67 bool isCompatible(const VersionRange& vr, const std::set<FqInstance>& providedInstances, 68 const std::set<Version>& providedVersions) const; 69 70 void setOptional(bool o); 71 void insertVersionRanges(const std::vector<VersionRange>& other); 72 // Return size of all interface/instance pairs. 73 size_t instancesCount() const; 74 void insertInstance(const std::string& interface, const std::string& instance, bool isRegex); 75 // Remove a specific interface/instances. Return true if removed, false otherwise. 76 bool removeInstance(const std::string& interface, const std::string& instance, bool isRegex); 77 // Remove all <interface> tags. 78 void clearInstances(); 79 }; 80 81 } // namespace vintf 82 } // namespace android 83 84 #endif // ANDROID_VINTF_MATRIX_HAL_H 85