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