blob: 23a9d371145e7ae6440797dc7181db263e7fb8d1 [file] [log] [blame]
Yao Chen729093d2017-10-16 10:33:26 -07001/*
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"
Yangster-mac93694462018-01-22 20:49:31 -080017#include <unordered_set>
Yao Chen729093d2017-10-16 10:33:26 -070018
19namespace android {
20namespace os {
21namespace statsd {
22
23using std::map;
24using std::string;
25using std::vector;
26
Yao Chen8a8d16c2018-02-08 14:50:40 -080027ConditionState ConditionWizard::query(const int index, const ConditionKey& parameters,
28 const vector<Matcher>& dimensionFields,
Yangster13fb7e42018-03-07 17:30:49 -080029 const bool isSubOutputDimensionFields,
30 const bool isPartialLink,
Yao Chen8a8d16c2018-02-08 14:50:40 -080031 std::unordered_set<HashableDimensionKey>* dimensionKeySet) {
Yao Chen729093d2017-10-16 10:33:26 -070032 vector<ConditionState> cache(mAllConditions.size(), ConditionState::kNotEvaluated);
33
Yangster-mac93694462018-01-22 20:49:31 -080034 mAllConditions[index]->isConditionMet(
Yangster13fb7e42018-03-07 17:30:49 -080035 parameters, mAllConditions, dimensionFields, isSubOutputDimensionFields, isPartialLink,
36 cache, *dimensionKeySet);
Yao Chen729093d2017-10-16 10:33:26 -070037 return cache[index];
38}
39
Yangster-mac93694462018-01-22 20:49:31 -080040ConditionState ConditionWizard::getMetConditionDimension(
Yao Chen8a8d16c2018-02-08 14:50:40 -080041 const int index, const vector<Matcher>& dimensionFields,
Yangster13fb7e42018-03-07 17:30:49 -080042 const bool isSubOutputDimensionFields,
Yao Chen8a8d16c2018-02-08 14:50:40 -080043 std::unordered_set<HashableDimensionKey>* dimensionsKeySet) const {
Yangster-mac93694462018-01-22 20:49:31 -080044 return mAllConditions[index]->getMetConditionDimension(mAllConditions, dimensionFields,
Yangster13fb7e42018-03-07 17:30:49 -080045 isSubOutputDimensionFields,
46 *dimensionsKeySet);
Yangster-mac93694462018-01-22 20:49:31 -080047}
48
Yao Chen580ea3212018-02-26 14:21:54 -080049const 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
Yangster13fb7e42018-03-07 17:30:49 -080059bool 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
Yao Chen729093d2017-10-16 10:33:26 -070083} // namespace statsd
84} // namespace os
85} // namespace android