| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 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" |
| Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 17 | #include <unordered_set> |
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 18 | |
| 19 | namespace android { |
| 20 | namespace os { |
| 21 | namespace statsd { |
| 22 | |
| 23 | using std::map; |
| 24 | using std::string; |
| 25 | using std::vector; |
| 26 | |
| Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 27 | ConditionState ConditionWizard::query(const int index, const ConditionKey& parameters, |
| 28 | const vector<Matcher>& dimensionFields, |
| Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 29 | const bool isSubOutputDimensionFields, |
| 30 | const bool isPartialLink, |
| Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 31 | std::unordered_set<HashableDimensionKey>* dimensionKeySet) { |
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 32 | vector<ConditionState> cache(mAllConditions.size(), ConditionState::kNotEvaluated); |
| 33 | |
| Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 34 | mAllConditions[index]->isConditionMet( |
| Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 35 | parameters, mAllConditions, dimensionFields, isSubOutputDimensionFields, isPartialLink, |
| 36 | cache, *dimensionKeySet); |
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 37 | return cache[index]; |
| 38 | } |
| 39 | |
| Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 40 | ConditionState ConditionWizard::getMetConditionDimension( |
| Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 41 | const int index, const vector<Matcher>& dimensionFields, |
| Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 42 | const bool isSubOutputDimensionFields, |
| Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 43 | std::unordered_set<HashableDimensionKey>* dimensionsKeySet) const { |
| Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 44 | return mAllConditions[index]->getMetConditionDimension(mAllConditions, dimensionFields, |
| Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 45 | isSubOutputDimensionFields, |
| 46 | *dimensionsKeySet); |
| Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| Yao Chen | 580ea321 | 2018-02-26 14:21:54 -0800 | [diff] [blame] | 49 | const set<HashableDimensionKey>* ConditionWizard::getChangedToTrueDimensions( |
| 50 | const int index) const { |
| 51 | return mAllConditions[index]->getChangedToTrueDimensions(mAllConditions); |
| 52 | } |
| 53 | |
| 54 | const set<HashableDimensionKey>* ConditionWizard::getChangedToFalseDimensions( |
| 55 | const int index) const { |
| 56 | return mAllConditions[index]->getChangedToFalseDimensions(mAllConditions); |
| 57 | } |
| 58 | |
| Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 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 | |
| 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 | |
| 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 | |
| Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 83 | } // namespace statsd |
| 84 | } // namespace os |
| 85 | } // namespace android |