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 bool isPartialLink);
44 
45     virtual const std::set<HashableDimensionKey>* getChangedToTrueDimensions(const int index) const;
46     virtual const std::set<HashableDimensionKey>* getChangedToFalseDimensions(
47             const int index) const;
48     bool equalOutputDimensions(const int index, const vector<Matcher>& dimensions);
49 
50     bool IsChangedDimensionTrackable(const int index);
51     bool IsSimpleCondition(const int index);
52 
getUnSlicedPartConditionState(const int index)53     ConditionState getUnSlicedPartConditionState(const int index) {
54         return mAllConditions[index]->getUnSlicedPartConditionState();
55     }
getTrueSlicedDimensions(const int index,std::set<HashableDimensionKey> * trueDimensions)56     void getTrueSlicedDimensions(const int index,
57         std::set<HashableDimensionKey>* trueDimensions) const {
58         return mAllConditions[index]->getTrueSlicedDimensions(mAllConditions, trueDimensions);
59     }
60 
61 private:
62     std::vector<sp<ConditionTracker>> mAllConditions;
63 };
64 
65 }  // namespace statsd
66 }  // namespace os
67 }  // namespace android
68 #endif  // CONDITION_WIZARD_H
69