blob: a6f88af4b4d689237d32565a41aa60ea6fd489c8 [file] [log] [blame]
Yao Chen729093d2017-10-16 10:33:26 -07001/*
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-mac20877162017-12-22 17:19:39 -080022#include "stats_util.h"
Yao Chen729093d2017-10-16 10:33:26 -070023
24namespace android {
25namespace os {
26namespace statsd {
27
Stefan Lafona5b51912017-12-05 21:43:52 -080028// Held by MetricProducer, to query a condition state with input defined in MetricConditionLink.
Yao Chen729093d2017-10-16 10:33:26 -070029class ConditionWizard : public virtual android::RefBase {
30public:
Yao Chen5154a372017-10-30 22:57:06 -070031 ConditionWizard(){}; // for testing
Yao Chen729093d2017-10-16 10:33:26 -070032 ConditionWizard(std::vector<sp<ConditionTracker>>& conditionTrackers)
33 : mAllConditions(conditionTrackers){};
34
Yao Chen5154a372017-10-30 22:57:06 -070035 virtual ~ConditionWizard(){};
36
Yao Chen729093d2017-10-16 10:33:26 -070037 // 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 Chen8a8d16c2018-02-08 14:50:40 -080042 virtual ConditionState query(const int conditionIndex, const ConditionKey& conditionParameters,
43 const vector<Matcher>& dimensionFields,
Yangster13fb7e42018-03-07 17:30:49 -080044 const bool isSubOutputDimensionFields,
45 const bool isPartialLink,
Yao Chen8a8d16c2018-02-08 14:50:40 -080046 std::unordered_set<HashableDimensionKey>* dimensionKeySet);
Yangster-mac93694462018-01-22 20:49:31 -080047
48 virtual ConditionState getMetConditionDimension(
Yao Chen8a8d16c2018-02-08 14:50:40 -080049 const int index, const vector<Matcher>& dimensionFields,
Yangster13fb7e42018-03-07 17:30:49 -080050 const bool isSubOutputDimensionFields,
Yao Chen8a8d16c2018-02-08 14:50:40 -080051 std::unordered_set<HashableDimensionKey>* dimensionsKeySet) const;
Yao Chen729093d2017-10-16 10:33:26 -070052
Yao Chen580ea3212018-02-26 14:21:54 -080053 virtual const std::set<HashableDimensionKey>* getChangedToTrueDimensions(const int index) const;
54 virtual const std::set<HashableDimensionKey>* getChangedToFalseDimensions(
55 const int index) const;
Yangster13fb7e42018-03-07 17:30:49 -080056 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 Chen580ea3212018-02-26 14:21:54 -080068
Yao Chen729093d2017-10-16 10:33:26 -070069private:
Yao Chen5154a372017-10-30 22:57:06 -070070 std::vector<sp<ConditionTracker>> mAllConditions;
Yao Chen729093d2017-10-16 10:33:26 -070071};
72
73} // namespace statsd
74} // namespace os
75} // namespace android
76#endif // CONDITION_WIZARD_H