blob: f27a0194d507d1b688e22df9a83611904a794c67 [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 "CompatibilityMatrix.h"
18
19namespace android {
20namespace vintf {
21
22constexpr Version CompatibilityMatrix::kVersion;
23
24bool CompatibilityMatrix::add(MatrixHal &&hal) {
Yifan Hongec342862017-02-16 17:57:06 -080025 return mHals.emplace(hal.name, std::move(hal)).second;
Yifan Hong676447a2016-11-15 12:57:23 -080026}
27
28bool CompatibilityMatrix::add(MatrixKernel &&kernel) {
Yifan Hong7c7d7062017-04-04 16:26:51 -070029 if (mType != SchemaType::FRAMEWORK) {
30 return false;
31 }
32 framework.mKernels.push_back(std::move(kernel));
Yifan Hong676447a2016-11-15 12:57:23 -080033 return true;
34}
35
36void CompatibilityMatrix::clear() {
Yifan Hongec342862017-02-16 17:57:06 -080037 mHals.clear();
Yifan Hong7c7d7062017-04-04 16:26:51 -070038 framework.mKernels.clear();
Yifan Hong676447a2016-11-15 12:57:23 -080039}
40
Yifan Hongc66ad1e2017-02-08 20:19:45 -080041ConstMapValueIterable<std::string, MatrixHal> CompatibilityMatrix::getHals() const {
Yifan Hongec342862017-02-16 17:57:06 -080042 return ConstMapValueIterable<std::string, MatrixHal>(mHals);
Yifan Hongc66ad1e2017-02-08 20:19:45 -080043}
44
45const MatrixKernel *CompatibilityMatrix::findKernel(const KernelVersion &v) const {
Yifan Hong7c7d7062017-04-04 16:26:51 -070046 if (mType != SchemaType::FRAMEWORK) {
47 return nullptr;
48 }
49 for (const MatrixKernel &matrixKernel : framework.mKernels) {
Yifan Hongc66ad1e2017-02-08 20:19:45 -080050 if (matrixKernel.minLts().version == v.version &&
51 matrixKernel.minLts().majorRev == v.majorRev) {
52 return matrixKernel.minLts().minorRev <= v.minorRev ? &matrixKernel : nullptr;
53 }
54 }
55 return nullptr;
56}
57
Yifan Hong676447a2016-11-15 12:57:23 -080058} // namespace vintf
59} // namespace android