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 
19 namespace android {
20 namespace os {
21 namespace statsd {
22 
23 using std::map;
24 using std::string;
25 using std::vector;
26 
query(const int index,const ConditionKey & parameters,const vector<Matcher> & dimensionFields,const bool isSubOutputDimensionFields,const bool isPartialLink,std::unordered_set<HashableDimensionKey> * dimensionKeySet)27 ConditionState 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 
getMetConditionDimension(const int index,const vector<Matcher> & dimensionFields,const bool isSubOutputDimensionFields,std::unordered_set<HashableDimensionKey> * dimensionsKeySet) const40 ConditionState 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 
getChangedToTrueDimensions(const int index) const49 const set<HashableDimensionKey>* ConditionWizard::getChangedToTrueDimensions(
50         const int index) const {
51     return mAllConditions[index]->getChangedToTrueDimensions(mAllConditions);
52 }
53 
getChangedToFalseDimensions(const int index) const54 const set<HashableDimensionKey>* ConditionWizard::getChangedToFalseDimensions(
55         const int index) const {
56     return mAllConditions[index]->getChangedToFalseDimensions(mAllConditions);
57 }
58 
IsChangedDimensionTrackable(const int index)59 bool 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 
IsSimpleCondition(const int index)67 bool 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 
equalOutputDimensions(const int index,const vector<Matcher> & dimensions)75 bool 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