Home | History | Annotate | Download | only in vintf
      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 
     43     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 
     59     inline Transport transport() const {
     60         return transportArch.transport;
     61     }
     62 
     63     inline const std::string& getName() const { return name; }
     64     bool forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const;
     65 
     66     bool isOverride() const { return mIsOverride; }
     67 
     68     // When true, the existence of this <hal> tag means the component does NOT
     69     // exist on the device. This is useful for ODM manifests to specify that
     70     // a HAL is disabled on certain products.
     71     bool isDisabledHal() const;
     72 
     73     // insert instance to <interface> <instance>.
     74     void insertLegacyInstance(const std::string& interface, const std::string& instance);
     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 insertInstances(const std::set<FqInstance>& fqInstances, std::string* error = nullptr);
     97 };
     98 
     99 } // namespace vintf
    100 } // namespace android
    101 
    102 #endif // ANDROID_VINTF_MANIFEST_HAL_H
    103