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