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 | |
| 17 | #ifndef CONDITION_WIZARD_H |
| 18 | #define CONDITION_WIZARD_H |
| 19 | |
| 20 | #include "ConditionTracker.h" |
| 21 | #include "condition_util.h" |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 22 | #include "stats_util.h" |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | namespace os { |
| 26 | namespace statsd { |
| 27 | |
Stefan Lafon | a5b5191 | 2017-12-05 21:43:52 -0800 | [diff] [blame] | 28 | // Held by MetricProducer, to query a condition state with input defined in MetricConditionLink. |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 29 | class ConditionWizard : public virtual android::RefBase { |
| 30 | public: |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 31 | ConditionWizard(){}; // for testing |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 32 | ConditionWizard(std::vector<sp<ConditionTracker>>& conditionTrackers) |
| 33 | : mAllConditions(conditionTrackers){}; |
| 34 | |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 35 | virtual ~ConditionWizard(){}; |
| 36 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 37 | // Query condition state, for a ConditionTracker at [conditionIndex], with [conditionParameters] |
| 38 | // [conditionParameters] mapping from condition name to the HashableDimensionKey to query the |
| 39 | // condition. |
| 40 | // The ConditionTracker at [conditionIndex] can be a CombinationConditionTracker. In this case, |
| 41 | // the conditionParameters contains the parameters for it's children SimpleConditionTrackers. |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 42 | virtual ConditionState query(const int conditionIndex, const ConditionKey& conditionParameters, |
| 43 | const vector<Matcher>& dimensionFields, |
Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 44 | const bool isSubOutputDimensionFields, |
| 45 | const bool isPartialLink, |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 46 | std::unordered_set<HashableDimensionKey>* dimensionKeySet); |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 47 | |
| 48 | virtual ConditionState getMetConditionDimension( |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 49 | const int index, const vector<Matcher>& dimensionFields, |
Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 50 | const bool isSubOutputDimensionFields, |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 51 | std::unordered_set<HashableDimensionKey>* dimensionsKeySet) const; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 52 | |
Yao Chen | 580ea321 | 2018-02-26 14:21:54 -0800 | [diff] [blame] | 53 | virtual const std::set<HashableDimensionKey>* getChangedToTrueDimensions(const int index) const; |
| 54 | virtual const std::set<HashableDimensionKey>* getChangedToFalseDimensions( |
| 55 | const int index) const; |
Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 56 | bool equalOutputDimensions(const int index, const vector<Matcher>& dimensions); |
| 57 | |
| 58 | bool IsChangedDimensionTrackable(const int index); |
| 59 | bool IsSimpleCondition(const int index); |
| 60 | |
| 61 | ConditionState getUnSlicedPartConditionState(const int index) { |
| 62 | return mAllConditions[index]->getUnSlicedPartConditionState(); |
| 63 | } |
| 64 | void getTrueSlicedDimensions(const int index, |
| 65 | std::set<HashableDimensionKey>* trueDimensions) const { |
| 66 | return mAllConditions[index]->getTrueSlicedDimensions(mAllConditions, trueDimensions); |
| 67 | } |
Yao Chen | 580ea321 | 2018-02-26 14:21:54 -0800 | [diff] [blame] | 68 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 69 | private: |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 70 | std::vector<sp<ConditionTracker>> mAllConditions; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace statsd |
| 74 | } // namespace os |
| 75 | } // namespace android |
| 76 | #endif // CONDITION_WIZARD_H |