• 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 <hidl-util/FqInstance.h>
23 
24 #include "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(FqInstance&& fqInstance, VersionRange&& range, bool optional, bool isRegex);
40     MatrixInstance(const FqInstance fqInstance, const VersionRange& range, bool optional,
41                    bool isRegex);
42     const std::string& package() const;
43     const VersionRange& versionRange() const;
44     const std::string& interface() const;
45     bool optional() const;
46 
47     bool isSatisfiedBy(const FqInstance& provided) const;
48 
49     // If isRegex, return true if instance matches the pattern.
50     // If !isRegex, return true if e == instance().
51     // Follows rules of "Extended Regular Expression" (ERE).
52     bool matchInstance(const std::string& e) const;
53 
54     // If isRegex, return the regex pattern. Else empty string.
55     const std::string& regexPattern() const;
56 
57     // If !isRegex, return the exact instance name. Else empty string.
58     const std::string& exactInstance() const;
59 
60     bool isRegex() const;
61 
62    private:
63     FqInstance mFqInstance;
64     VersionRange mRange;
65     bool mOptional = false;
66     bool mIsRegex = false;
67 };
68 
69 }  // namespace vintf
70 }  // namespace android
71 
72 #endif  // ANDROID_VINTF_MATRIX_INSTANCE_H
73