1/*
2 * Copyright (C) 2017 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#include "ConditionWizard.h"
17#include <unordered_set>
18
19namespace android {
20namespace os {
21namespace statsd {
22
23using std::map;
24using std::string;
25using std::vector;
26
27ConditionState ConditionWizard::query(const int index, const ConditionKey& parameters,
28                                      const vector<Matcher>& dimensionFields,
29                                      const bool isSubOutputDimensionFields,
30                                      const bool isPartialLink,
31                                      std::unordered_set<HashableDimensionKey>* dimensionKeySet) {
32    vector<ConditionState> cache(mAllConditions.size(), ConditionState::kNotEvaluated);
33
34    mAllConditions[index]->isConditionMet(
35        parameters, mAllConditions, dimensionFields, isSubOutputDimensionFields, isPartialLink,
36        cache, *dimensionKeySet);
37    return cache[index];
38}
39
40ConditionState ConditionWizard::getMetConditionDimension(
41        const int index, const vector<Matcher>& dimensionFields,
42        const bool isSubOutputDimensionFields,
43        std::unordered_set<HashableDimensionKey>* dimensionsKeySet) const {
44    return mAllConditions[index]->getMetConditionDimension(mAllConditions, dimensionFields,
45                                                           isSubOutputDimensionFields,
46                                                           *dimensionsKeySet);
47}
48
49const set<HashableDimensionKey>* ConditionWizard::getChangedToTrueDimensions(
50        const int index) const {
51    return mAllConditions[index]->getChangedToTrueDimensions(mAllConditions);
52}
53
54const set<HashableDimensionKey>* ConditionWizard::getChangedToFalseDimensions(
55        const int index) const {
56    return mAllConditions[index]->getChangedToFalseDimensions(mAllConditions);
57}
58
59bool ConditionWizard::IsChangedDimensionTrackable(const int index) {
60    if (index >= 0 && index < (int)mAllConditions.size()) {
61        return mAllConditions[index]->IsChangedDimensionTrackable();
62    } else {
63        return false;
64    }
65}
66
67bool ConditionWizard::IsSimpleCondition(const int index) {
68    if (index >= 0 && index < (int)mAllConditions.size()) {
69        return mAllConditions[index]->IsSimpleCondition();
70    } else {
71        return false;
72    }
73}
74
75bool ConditionWizard::equalOutputDimensions(const int index, const vector<Matcher>& dimensions) {
76    if (index >= 0 && index < (int)mAllConditions.size()) {
77        return mAllConditions[index]->equalOutputDimensions(mAllConditions, dimensions);
78    } else {
79        return false;
80    }
81}
82
83}  // namespace statsd
84}  // namespace os
85}  // namespace android