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