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 ANDROID_VINTF_MATRIX_INSTANCE_H 18 #define ANDROID_VINTF_MATRIX_INSTANCE_H 19 20 #include <string> 21 22 #include <vintf/ExclusiveTo.h> 23 #include <vintf/FqInstance.h> 24 #include <vintf/HalFormat.h> 25 #include <vintf/VersionRange.h> 26 27 namespace android { 28 namespace vintf { 29 30 class MatrixInstance { 31 public: 32 MatrixInstance(); 33 MatrixInstance(const MatrixInstance&); 34 MatrixInstance(MatrixInstance&&) noexcept; 35 MatrixInstance& operator=(const MatrixInstance&); 36 MatrixInstance& operator=(MatrixInstance&&) noexcept; 37 38 using VersionType = VersionRange; 39 // fqInstance.version is ignored. Version range is provided separately. 40 MatrixInstance(HalFormat format, ExclusiveTo exclusiveTo, FqInstance&& fqInstance, 41 VersionRange&& range, bool optional, bool isRegex); 42 MatrixInstance(HalFormat format, ExclusiveTo exclusiveTo, const FqInstance fqInstance, 43 const VersionRange& range, bool optional, bool isRegex); 44 const std::string& package() const; 45 const VersionRange& versionRange() const; 46 std::string interface() const; 47 bool optional() const; 48 HalFormat format() const; 49 ExclusiveTo exclusiveTo() const; 50 51 bool isSatisfiedBy(const FqInstance& provided) const; 52 53 // If isRegex, return true if instance matches the pattern. 54 // If !isRegex, return true if e == instance(). 55 // Follows rules of "Extended Regular Expression" (ERE). 56 bool matchInstance(const std::string& e) const; 57 58 // If isRegex, return the regex pattern. Else empty string. 59 const std::string& regexPattern() const; 60 61 // If !isRegex, return the exact instance name. Else empty string. 62 const std::string& exactInstance() const; 63 64 bool isRegex() const; 65 66 // Return a human-readable description of the interface. 67 // Version is replaced by replaceVersion. 68 // e.g. for HIDL, [email protected]::IFoo, 69 // for AIDL, android.hardware.foo.IFoo (@1) 70 std::string interfaceDescription(Version replaceVersion) const; 71 72 // Return a human-readable description of the instance. 73 // Version is replaced by replaceVersion. 74 // e.g. for HIDL, [email protected]::IFoo/default, 75 // for AIDL, android.hardware.foo.IFoo/default (@1) 76 std::string description(Version replaceVersion) const; 77 78 private: 79 HalFormat mFormat = HalFormat::HIDL; 80 ExclusiveTo mExclusiveTo = ExclusiveTo::EMPTY; 81 FqInstance mFqInstance; 82 VersionRange mRange; 83 bool mOptional = false; 84 bool mIsRegex = false; 85 }; 86 87 } // namespace vintf 88 } // namespace android 89 90 #endif // ANDROID_VINTF_MATRIX_INSTANCE_H 91