blob: dd007dd83c4815e482711bfb060ca915d684d304 [file] [log] [blame]
Yifan Hong2a90ffe2018-03-05 17:45:34 -08001/*
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#include "MatrixInstance.h"
18
19#include <utility>
20
21namespace android {
22namespace vintf {
23
Yifan Hongcf231a92018-03-13 14:19:13 -070024MatrixInstance::MatrixInstance() = default;
25
26MatrixInstance::MatrixInstance(const MatrixInstance&) = default;
27
28MatrixInstance::MatrixInstance(MatrixInstance&&) = default;
29
30MatrixInstance& MatrixInstance::operator=(const MatrixInstance&) = default;
31
32MatrixInstance& MatrixInstance::operator=(MatrixInstance&&) = default;
33
Yifan Hong85103c62018-03-20 15:43:34 -070034MatrixInstance::MatrixInstance(FqInstance&& fqInstance, VersionRange&& range, bool optional,
35 bool isRegex)
36 : mFqInstance(std::move(fqInstance)),
37 mRange(std::move(range)),
38 mOptional(optional),
39 mIsRegex(isRegex) {}
Yifan Hong2a90ffe2018-03-05 17:45:34 -080040
41MatrixInstance::MatrixInstance(const FqInstance fqInstance, const VersionRange& range,
Yifan Hong85103c62018-03-20 15:43:34 -070042 bool optional, bool isRegex)
43 : mFqInstance(fqInstance), mRange(range), mOptional(optional), mIsRegex(isRegex) {}
Yifan Hong2a90ffe2018-03-05 17:45:34 -080044
45const std::string& MatrixInstance::package() const {
46 return mFqInstance.getPackage();
47}
48
49const VersionRange& MatrixInstance::versionRange() const {
50 return mRange;
51}
52
53const std::string& MatrixInstance::interface() const {
54 return mFqInstance.getInterface();
55}
56
57const std::string& MatrixInstance::instance() const {
58 return mFqInstance.getInstance();
59}
60
61bool MatrixInstance::optional() const {
62 return mOptional;
63}
64
Yifan Hong075b3632018-03-14 16:03:11 -070065bool MatrixInstance::isSatisfiedBy(const FqInstance& provided) const {
66 return package() == provided.getPackage() &&
67 versionRange().supportedBy(provided.getVersion()) &&
Yifan Hong85103c62018-03-20 15:43:34 -070068 interface() == provided.getInterface() && matchInstance(provided.getInstance());
69}
70
71bool MatrixInstance::matchInstance(const std::string& e) const {
72 if (!isRegex()) {
73 return exactInstance() == e;
74 }
75 return false; // FIXME: do matching.
76}
77
78const std::string& MatrixInstance::regexPattern() const {
79 static const std::string kEmptyString;
80 return kEmptyString;
81}
82
83const std::string& MatrixInstance::exactInstance() const {
84 return mFqInstance.getInstance();
85}
86
87bool MatrixInstance::isRegex() const {
88 return mIsRegex;
Yifan Hong075b3632018-03-14 16:03:11 -070089}
90
Yifan Hong2a90ffe2018-03-05 17:45:34 -080091} // namespace vintf
92} // namespace android