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 LIBVINTF_TARGET
18 #define LOG_TAG "libvintf"
19 #include <android-base/logging.h>
20 #endif
21
22 #include "ManifestInstance.h"
23
24 #include <utility>
25
26 #include "parse_string.h"
27
28 namespace android {
29 namespace vintf {
30
31 ManifestInstance::ManifestInstance() = default;
32
33 ManifestInstance::ManifestInstance(const ManifestInstance&) = default;
34
35 ManifestInstance::ManifestInstance(ManifestInstance&&) noexcept = default;
36
37 ManifestInstance& ManifestInstance::operator=(const ManifestInstance&) = default;
38
39 ManifestInstance& ManifestInstance::operator=(ManifestInstance&&) noexcept = default;
40
ManifestInstance(FqInstance && fqInstance,TransportArch && ta,HalFormat fmt)41 ManifestInstance::ManifestInstance(FqInstance&& fqInstance, TransportArch&& ta, HalFormat fmt)
42 : mFqInstance(std::move(fqInstance)), mTransportArch(std::move(ta)), mHalFormat(fmt) {}
ManifestInstance(const FqInstance & fqInstance,const TransportArch & ta,HalFormat fmt)43 ManifestInstance::ManifestInstance(const FqInstance& fqInstance, const TransportArch& ta,
44 HalFormat fmt)
45 : mFqInstance(fqInstance), mTransportArch(ta), mHalFormat(fmt) {}
46
package() const47 const std::string& ManifestInstance::package() const {
48 return mFqInstance.getPackage();
49 }
50
version() const51 Version ManifestInstance::version() const {
52 return mFqInstance.getVersion();
53 }
54
interface() const55 const std::string& ManifestInstance::interface() const {
56 return mFqInstance.getInterface();
57 }
58
instance() const59 const std::string& ManifestInstance::instance() const {
60 return mFqInstance.getInstance();
61 }
62
transport() const63 Transport ManifestInstance::transport() const {
64 return mTransportArch.transport;
65 }
66
arch() const67 Arch ManifestInstance::arch() const {
68 return mTransportArch.arch;
69 }
70
format() const71 HalFormat ManifestInstance::format() const {
72 return mHalFormat;
73 }
74
getFqInstance() const75 const FqInstance& ManifestInstance::getFqInstance() const {
76 return mFqInstance;
77 }
78
operator ==(const ManifestInstance & other) const79 bool ManifestInstance::operator==(const ManifestInstance& other) const {
80 return mFqInstance == other.mFqInstance && mTransportArch == other.mTransportArch &&
81 mHalFormat == other.mHalFormat;
82 }
operator <(const ManifestInstance & other) const83 bool ManifestInstance::operator<(const ManifestInstance& other) const {
84 if (mFqInstance < other.mFqInstance) return true;
85 if (other.mFqInstance < mFqInstance) return false;
86 if (mTransportArch < other.mTransportArch) return true;
87 if (other.mTransportArch < mTransportArch) return false;
88 return mHalFormat < other.mHalFormat;
89 }
90
getSimpleFqInstance() const91 std::string ManifestInstance::getSimpleFqInstance() const {
92 FqInstance e;
93 bool success = false;
94 switch (format()) {
95 case HalFormat::AIDL: {
96 // Hide fake version when printing human-readable message or to manifest XML.
97 success = e.setTo(interface(), instance());
98 } break;
99 case HalFormat::HIDL:
100 [[fallthrough]];
101 case HalFormat::NATIVE: {
102 success = e.setTo(version().majorVer, version().minorVer, interface(), instance());
103 } break;
104 }
105 #ifndef LIBVINTF_TARGET
106 CHECK(success) << "Cannot get simple fqinstnance from '" << mFqInstance.string() << "'";
107 #endif
108 return success ? e.string() : "";
109 }
110
description() const111 std::string ManifestInstance::description() const {
112 switch (format()) {
113 case HalFormat::AIDL: {
114 return toAidlFqnameString(package(), interface(), instance());
115 } break;
116 case HalFormat::HIDL:
117 [[fallthrough]];
118 case HalFormat::NATIVE: {
119 return getFqInstance().string();
120 } break;
121 }
122 }
123
124 } // namespace vintf
125 } // namespace android
126