• 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 
18 #ifndef ANDROID_VINTF_MANIFEST_HAL_H
19 #define ANDROID_VINTF_MANIFEST_HAL_H
20 
21 #include <map>
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 #include <hidl-util/FqInstance.h>
27 
28 #include "HalFormat.h"
29 #include "HalInterface.h"
30 #include "ManifestInstance.h"
31 #include "TransportArch.h"
32 #include "Version.h"
33 
34 namespace android {
35 namespace vintf {
36 
37 // A component of HalManifest.
38 struct ManifestHal {
39     using InstanceType = ManifestInstance;
40 
41     ManifestHal() = default;
42 
ManifestHalManifestHal43     ManifestHal(HalFormat fmt, std::string&& n, std::vector<Version>&& vs, TransportArch ta,
44                 std::map<std::string, HalInterface>&& intf)
45         : format(fmt),
46           name(std::move(n)),
47           versions(std::move(vs)),
48           transportArch(ta),
49           interfaces(std::move(intf)) {}
50 
51     bool operator==(const ManifestHal &other) const;
52 
53     HalFormat format = HalFormat::HIDL;
54     std::string name;
55     std::vector<Version> versions;
56     TransportArch transportArch;
57     std::map<std::string, HalInterface> interfaces;
58 
transportManifestHal59     inline Transport transport() const {
60         return transportArch.transport;
61     }
62 
archManifestHal63     inline Arch arch() const { return transportArch.arch; }
64 
getNameManifestHal65     inline const std::string& getName() const { return name; }
66     bool forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const;
67 
isOverrideManifestHal68     bool isOverride() const { return mIsOverride; }
69 
70     // When true, the existence of this <hal> tag means the component does NOT
71     // exist on the device. This is useful for ODM manifests to specify that
72     // a HAL is disabled on certain products.
73     bool isDisabledHal() const;
74 
75    private:
76     friend struct LibVintfTest;
77     friend struct ManifestHalConverter;
78     friend struct HalManifest;
79     friend bool parse(const std::string &s, ManifestHal *hal);
80 
81     // Whether this hal is a valid one. Note that an empty ManifestHal
82     // (constructed via ManifestHal()) is valid.
83     bool isValid() const;
84 
85     // Return all versions mentioned by <version>s and <fqname>s.
86     void appendAllVersions(std::set<Version>* ret) const;
87 
88     bool mIsOverride = false;
89     // Additional instances to <version> x <interface> x <instance>.
90     std::set<ManifestInstance> mAdditionalInstances;
91 
92     // insert instances to mAdditionalInstances.
93     // Existing instances will be ignored.
94     // Pre: all instances to be inserted must satisfy
95     // !hasPackage() && hasVersion() && hasInterface() && hasInstance()
96     bool insertInstance(const FqInstance& fqInstance, std::string* error = nullptr);
97     bool insertInstances(const std::set<FqInstance>& fqInstances, std::string* error = nullptr);
98 
99     // Verify instance before inserting.
100     bool verifyInstance(const FqInstance& fqInstance, std::string* error = nullptr) const;
101 };
102 
103 } // namespace vintf
104 } // namespace android
105 
106 #endif // ANDROID_VINTF_MANIFEST_HAL_H
107