Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 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 | #include "CompatibilityMatrix.h" |
| 18 | |
| 19 | namespace android { |
| 20 | namespace vintf { |
| 21 | |
| 22 | constexpr Version CompatibilityMatrix::kVersion; |
| 23 | |
| 24 | bool CompatibilityMatrix::add(MatrixHal &&hal) { |
Yifan Hong | ec34286 | 2017-02-16 17:57:06 -0800 | [diff] [blame] | 25 | return mHals.emplace(hal.name, std::move(hal)).second; |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | bool CompatibilityMatrix::add(MatrixKernel &&kernel) { |
Yifan Hong | 7c7d706 | 2017-04-04 16:26:51 -0700 | [diff] [blame^] | 29 | if (mType != SchemaType::FRAMEWORK) { |
| 30 | return false; |
| 31 | } |
| 32 | framework.mKernels.push_back(std::move(kernel)); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 33 | return true; |
| 34 | } |
| 35 | |
| 36 | void CompatibilityMatrix::clear() { |
Yifan Hong | ec34286 | 2017-02-16 17:57:06 -0800 | [diff] [blame] | 37 | mHals.clear(); |
Yifan Hong | 7c7d706 | 2017-04-04 16:26:51 -0700 | [diff] [blame^] | 38 | framework.mKernels.clear(); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Yifan Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 41 | ConstMapValueIterable<std::string, MatrixHal> CompatibilityMatrix::getHals() const { |
Yifan Hong | ec34286 | 2017-02-16 17:57:06 -0800 | [diff] [blame] | 42 | return ConstMapValueIterable<std::string, MatrixHal>(mHals); |
Yifan Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | const MatrixKernel *CompatibilityMatrix::findKernel(const KernelVersion &v) const { |
Yifan Hong | 7c7d706 | 2017-04-04 16:26:51 -0700 | [diff] [blame^] | 46 | if (mType != SchemaType::FRAMEWORK) { |
| 47 | return nullptr; |
| 48 | } |
| 49 | for (const MatrixKernel &matrixKernel : framework.mKernels) { |
Yifan Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 50 | 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 Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 58 | } // namespace vintf |
| 59 | } // namespace android |