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 <hidl-util/FqInstance.h>
23 
24 #include "HalFormat.h"
25 #include "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, FqInstance&& fqInstance, VersionRange&& range, bool optional,
41                    bool isRegex);
42     MatrixInstance(HalFormat format, const FqInstance fqInstance, const VersionRange& range,
43                    bool optional, bool isRegex);
44     const std::string& package() const;
45     const VersionRange& versionRange() const;
46     const std::string& interface() const;
47     bool optional() const;
48     HalFormat format() const;
49 
50     bool isSatisfiedBy(const FqInstance& provided) const;
51 
52     // If isRegex, return true if instance matches the pattern.
53     // If !isRegex, return true if e == instance().
54     // Follows rules of "Extended Regular Expression" (ERE).
55     bool matchInstance(const std::string& e) const;
56 
57     // If isRegex, return the regex pattern. Else empty string.
58     const std::string& regexPattern() const;
59 
60     // If !isRegex, return the exact instance name. Else empty string.
61     const std::string& exactInstance() const;
62 
63     bool isRegex() const;
64 
65     // Return a human-readable description of the interface.
66     // Version is replaced by replaceVersion.
67     // e.g. [email protected]::IFoo (HIDL),
68     //      android.hardware.foo.IFoo (AIDL)
69     std::string interfaceDescription(Version replaceVersion) const;
70 
71     // Return a human-readable description of the instance.
72     // Version is replaced by replaceVersion.
73     // e.g. [email protected]::IFoo/default (HIDL),
74     //      android.hardware.foo.IFoo/default (AIDL)
75     std::string description(Version replaceVersion) const;
76 
77    private:
78     HalFormat mFormat = HalFormat::HIDL;
79     FqInstance mFqInstance;
80     VersionRange mRange;
81     bool mOptional = false;
82     bool mIsRegex = false;
83 };
84 
85 }  // namespace vintf
86 }  // namespace android
87 
88 #endif  // ANDROID_VINTF_MATRIX_INSTANCE_H
89