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 #ifndef ANDROID_VINTF_MATRIX_KERNEL_H 18 #define ANDROID_VINTF_MATRIX_KERNEL_H 19 20 #include <string> 21 #include <vector> 22 #include <utility> 23 24 #include "KernelConfigTypedValue.h" 25 #include "Level.h" 26 #include "Version.h" 27 28 namespace android { 29 namespace vintf { 30 31 struct KernelConfigKey : public std::string { KernelConfigKeyKernelConfigKey32 KernelConfigKey() : std::string() {} KernelConfigKeyKernelConfigKey33 KernelConfigKey(const std::string &other) : std::string(other) {} KernelConfigKeyKernelConfigKey34 KernelConfigKey(std::string &&other) : std::string(std::forward<std::string>(other)) {} 35 }; 36 37 using KernelConfig = std::pair<KernelConfigKey, KernelConfigTypedValue>; 38 39 // A <kernel> entry to a compatibility matrix represents a fragment of kernel 40 // config requirements. 41 struct MatrixKernel { 42 MatrixKernelMatrixKernel43 MatrixKernel() {} MatrixKernelMatrixKernel44 MatrixKernel(KernelVersion &&minLts, std::vector<KernelConfig> &&configs) 45 : mMinLts(std::move(minLts)), mConfigs(std::move(configs)) {} 46 47 bool operator==(const MatrixKernel &other) const; 48 minLtsMatrixKernel49 inline const KernelVersion &minLts() const { return mMinLts; } 50 51 // Return an iterable on all kernel configs. Use it as follows: 52 // for (const KernelConfig &config : kernel.configs()) {...} configsMatrixKernel53 const std::vector<KernelConfig> &configs() const { return mConfigs; } 54 55 // Return an iterable on all kernel config conditions. Use it as follows: 56 // for (const KernelConfig &config : kernel.conditions()) {...} conditionsMatrixKernel57 const std::vector<KernelConfig>& conditions() const { return mConditions; } 58 59 private: 60 friend struct MatrixKernelConverter; 61 friend struct MatrixKernelConditionsConverter; 62 friend struct CompatibilityMatrix; 63 friend class AssembleVintfImpl; 64 friend class KernelInfo; 65 66 void setSourceMatrixLevel(Level level); 67 Level getSourceMatrixLevel() const; 68 69 KernelVersion mMinLts; 70 std::vector<KernelConfig> mConfigs; 71 std::vector<KernelConfig> mConditions; 72 73 // The "level" field of compatibility matrix that this <kernel> tag is 74 // originally from. 75 // If UNSPECIFIED, this value should be retrieved from the parent 76 // CompatibilityMatrix object. 77 Level mSourceMatrixLevel = Level::UNSPECIFIED; 78 }; 79 80 } // namespace vintf 81 } // namespace android 82 83 #endif // ANDROID_VINTF_MATRIX_KERNEL_H 84