blob: fbe9a5f7d08800959c2ef144e535234db09fb569 [file] [log] [blame]
Yifan Hong676447a2016-11-15 12:57:23 -08001/*
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#include "MatrixHal.h"
18
Yifan Hong2a90ffe2018-03-05 17:45:34 -080019#include "MapValueIterator.h"
20
Yifan Hong676447a2016-11-15 12:57:23 -080021namespace android {
22namespace vintf {
23
24bool MatrixHal::operator==(const MatrixHal &other) const {
25 if (format != other.format)
26 return false;
27 if (name != other.name)
28 return false;
29 if (versionRanges != other.versionRanges)
30 return false;
Yifan Hong43e2aae2017-05-17 18:36:08 -070031 if (interfaces != other.interfaces)
32 return false;
Yifan Hong676447a2016-11-15 12:57:23 -080033 // do not compare optional
34 return true;
35}
36
Zhuoyao Zhangc7e75bd2017-10-29 17:20:19 -070037bool MatrixHal::containsVersion(const Version& version) const {
38 for (VersionRange vRange : versionRanges) {
39 if (vRange.contains(version)) return true;
40 }
41 return false;
42}
43
44std::set<std::string> MatrixHal::getInstances(const std::string& interfaceName) const {
45 std::set<std::string> ret;
46 auto it = interfaces.find(interfaceName);
47 if (it != interfaces.end()) {
48 ret.insert(it->second.instances.begin(), it->second.instances.end());
49 }
50 return ret;
51}
52
Yifan Hongdbe9db32017-12-11 19:06:11 -080053bool MatrixHal::containsInstances(const MatrixHal& other) const {
54 for (const auto& pair : other.interfaces) {
55 const std::string& interfaceName = pair.first;
56 auto thisIt = interfaces.find(interfaceName);
57 if (thisIt == interfaces.end()) {
58 return false;
59 }
60
61 const std::set<std::string>& thisInstances = thisIt->second.instances;
62 const std::set<std::string>& otherInstances = pair.second.instances;
63 if (!std::includes(thisInstances.begin(), thisInstances.end(), otherInstances.begin(),
64 otherInstances.end())) {
65 return false;
66 }
67 }
68 return true;
69}
70
Yifan Hong2a90ffe2018-03-05 17:45:34 -080071bool MatrixHal::forEachInstance(const std::function<bool(const MatrixInstance&)>& func) const {
72 for (const auto& vr : versionRanges) {
73 for (const auto& intf : iterateValues(interfaces)) {
74 for (const auto& instance : intf.instances) {
75 // TODO(b/73556059): Store MatrixInstance as well to avoid creating temps
76 FqInstance fqInstance;
77 if (fqInstance.setTo(getName(), vr.majorVer, vr.minMinor, intf.name, instance)) {
78 if (!func(MatrixInstance(std::move(fqInstance), VersionRange(vr), optional))) {
79 return false;
80 }
81 }
82 }
83 }
84 }
85 return true;
86}
87
Yifan Hong676447a2016-11-15 12:57:23 -080088} // namespace vintf
89} // namespace android