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" 22 #include "stats_util.h" 23 24 namespace android { 25 namespace os { 26 namespace statsd { 27 28 // Held by MetricProducer, to query a condition state with input defined in MetricConditionLink. 29 class ConditionWizard : public virtual android::RefBase { 30 public: ConditionWizard()31 ConditionWizard(){}; // for testing ConditionWizard(std::vector<sp<ConditionTracker>> & conditionTrackers)32 explicit ConditionWizard(std::vector<sp<ConditionTracker>>& conditionTrackers) 33 : mAllConditions(conditionTrackers){}; 34 ~ConditionWizard()35 virtual ~ConditionWizard(){}; 36 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. 42 virtual ConditionState query(const int conditionIndex, const ConditionKey& conditionParameters, 43 const vector<Matcher>& dimensionFields, 44 const bool isSubOutputDimensionFields, 45 const bool isPartialLink, 46 std::unordered_set<HashableDimensionKey>* dimensionKeySet); 47 48 virtual ConditionState getMetConditionDimension( 49 const int index, const vector<Matcher>& dimensionFields, 50 const bool isSubOutputDimensionFields, 51 std::unordered_set<HashableDimensionKey>* dimensionsKeySet) const; 52 53 virtual const std::set<HashableDimensionKey>* getChangedToTrueDimensions(const int index) const; 54 virtual const std::set<HashableDimensionKey>* getChangedToFalseDimensions( 55 const int index) const; 56 bool equalOutputDimensions(const int index, const vector<Matcher>& dimensions); 57 58 bool IsChangedDimensionTrackable(const int index); 59 bool IsSimpleCondition(const int index); 60 getUnSlicedPartConditionState(const int index)61 ConditionState getUnSlicedPartConditionState(const int index) { 62 return mAllConditions[index]->getUnSlicedPartConditionState(); 63 } getTrueSlicedDimensions(const int index,std::set<HashableDimensionKey> * trueDimensions)64 void getTrueSlicedDimensions(const int index, 65 std::set<HashableDimensionKey>* trueDimensions) const { 66 return mAllConditions[index]->getTrueSlicedDimensions(mAllConditions, trueDimensions); 67 } 68 69 private: 70 std::vector<sp<ConditionTracker>> mAllConditions; 71 }; 72 73 } // namespace statsd 74 } // namespace os 75 } // namespace android 76 #endif // CONDITION_WIZARD_H 77