xref: /aosp_15_r20/system/libvintf/include/vintf/ManifestInstance.h (revision 70a7ec852fcefd15a4fb57f8f183a8b1c3aacb08)
1 /*
2  * Copyright (C) 2018 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_MANIFEST_INSTANCE_H
18 #define ANDROID_VINTF_MANIFEST_INSTANCE_H
19 
20 #include <optional>
21 #include <string>
22 
23 #include <vintf/ExclusiveTo.h>
24 #include <vintf/FqInstance.h>
25 #include <vintf/HalFormat.h>
26 #include <vintf/TransportArch.h>
27 #include <vintf/Version.h>
28 
29 namespace android {
30 namespace vintf {
31 
32 class ManifestInstance {
33    public:
34     ManifestInstance();
35     ManifestInstance(const ManifestInstance&);
36     ManifestInstance(ManifestInstance&&) noexcept;
37     ManifestInstance& operator=(const ManifestInstance&);
38     ManifestInstance& operator=(ManifestInstance&&) noexcept;
39 
40     using VersionType = Version;
41     ManifestInstance(FqInstance&& fqInstance, TransportArch&& ta, HalFormat fmt,
42                      std::optional<std::string>&& updatableViaApex, ExclusiveTo exclusiveTo,
43                      std::optional<std::string>&& accessor, bool updatableViaSystem);
44     ManifestInstance(const FqInstance& fqInstance, const TransportArch& ta, HalFormat fmt,
45                      const std::optional<std::string>& updatableViaApex, ExclusiveTo exclusiveTo,
46                      const std::optional<std::string>& accessor, bool updatableViaSystem);
47     const std::string& package() const;
48     Version version() const;
49     std::string interface() const;
50     const std::string& instance() const;
51     Transport transport() const;
52     Arch arch() const;
53     HalFormat format() const;
54     ExclusiveTo exclusiveTo() const;
55     const std::optional<std::string>& accessor() const;
56     const std::optional<std::string>& updatableViaApex() const;
57     const std::optional<std::string> ip() const;
58     const std::optional<uint64_t> port() const;
59     bool updatableViaSystem() const;
60 
61     bool operator==(const ManifestInstance& other) const;
62     bool operator<(const ManifestInstance& other) const;
63 
64     // Convenience methods.
65     // return package@version::interface/instance
66     const FqInstance& getFqInstance() const;
67 
68     // This is for writing the XML <fqname> tag.
69     // For AIDL, return "interface/instance".
70     // For others, return "@version::interface/instance".
71     std::string getSimpleFqInstance() const;
72 
73     // For AIDL, return "package.interface/instance (@version)".
74     // For others, return "package@version::interface/instance".
75     std::string description() const;
76 
77     // Similar to description() but without package name.
78     // For AIDL, return "interface/instance (@version)".
79     // For others, return "@version::interface/instance".
80     std::string descriptionWithoutPackage() const;
81 
82     // Returns name with version. e.g. "android.hardware.camera.device@1"
83     std::string nameWithVersion() const;
84 
85     // Return a new ManifestInstance that's the same as this, but with the given version.
86     ManifestInstance withVersion(const Version& v) const;
87 
88    private:
89     FqInstance mFqInstance;
90     TransportArch mTransportArch;
91     HalFormat mHalFormat;
92     std::optional<std::string> mUpdatableViaApex;
93     ExclusiveTo mExclusiveTo;
94     std::optional<std::string> mAccessor;
95     bool mUpdatableViaSystem;
96 };
97 
98 }  // namespace vintf
99 }  // namespace android
100 
101 #endif  // ANDROID_VINTF_MANIFEST_INSTANCE_H
102