blob: e3d860127780a73f2789a17ae752c707db921862 [file] [log] [blame]
Yao Chencaf339d2017-10-06 16:01:10 -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 COMBINATION_CONDITION_TRACKER_H
18#define COMBINATION_CONDITION_TRACKER_H
19
20#include "ConditionTracker.h"
21#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
22
23namespace android {
24namespace os {
25namespace statsd {
26
27class CombinationConditionTracker : public virtual ConditionTracker {
28public:
Yangster-mac94e197c2018-01-02 16:03:03 -080029 CombinationConditionTracker(const int64_t& id, const int index);
Yao Chencaf339d2017-10-06 16:01:10 -070030
31 ~CombinationConditionTracker();
32
Stefan Lafon12d01fa2017-12-04 20:56:09 -080033 bool init(const std::vector<Predicate>& allConditionConfig,
Yao Chencaf339d2017-10-06 16:01:10 -070034 const std::vector<sp<ConditionTracker>>& allConditionTrackers,
Yangster-mac94e197c2018-01-02 16:03:03 -080035 const std::unordered_map<int64_t, int>& conditionIdIndexMap,
Yao Chencaf339d2017-10-06 16:01:10 -070036 std::vector<bool>& stack) override;
37
Yao Chen967b2052017-11-07 16:36:43 -080038 void evaluateCondition(const LogEvent& event,
Yao Chencaf339d2017-10-06 16:01:10 -070039 const std::vector<MatchingState>& eventMatcherValues,
40 const std::vector<sp<ConditionTracker>>& mAllConditions,
41 std::vector<ConditionState>& conditionCache,
Yao Chen967b2052017-11-07 16:36:43 -080042 std::vector<bool>& changedCache) override;
Yao Chen729093d2017-10-16 10:33:26 -070043
Yao Chen8a8d16c2018-02-08 14:50:40 -080044 void isConditionMet(const ConditionKey& conditionParameters,
45 const std::vector<sp<ConditionTracker>>& allConditions,
Yangster13fb7e42018-03-07 17:30:49 -080046 const bool isPartialLink,
tsaichristine76853372019-08-06 17:17:03 -070047 std::vector<ConditionState>& conditionCache) const override;
Yao Chen8a8d16c2018-02-08 14:50:40 -080048
Yao Chen580ea3212018-02-26 14:21:54 -080049 // Only one child predicate can have dimension.
50 const std::set<HashableDimensionKey>* getChangedToTrueDimensions(
51 const std::vector<sp<ConditionTracker>>& allConditions) const override {
52 for (const auto& child : mChildren) {
53 auto result = allConditions[child]->getChangedToTrueDimensions(allConditions);
54 if (result != nullptr) {
55 return result;
56 }
57 }
58 return nullptr;
59 }
Yangster13fb7e42018-03-07 17:30:49 -080060
Yao Chen580ea3212018-02-26 14:21:54 -080061 // Only one child predicate can have dimension.
62 const std::set<HashableDimensionKey>* getChangedToFalseDimensions(
63 const std::vector<sp<ConditionTracker>>& allConditions) const override {
64 for (const auto& child : mChildren) {
65 auto result = allConditions[child]->getChangedToFalseDimensions(allConditions);
66 if (result != nullptr) {
67 return result;
68 }
69 }
70 return nullptr;
71 }
72
Yangster13fb7e42018-03-07 17:30:49 -080073 bool IsSimpleCondition() const override { return false; }
74
75 bool IsChangedDimensionTrackable() const override {
76 return mLogicalOperation == LogicalOperation::AND && mSlicedChildren.size() == 1;
77 }
78
79 bool equalOutputDimensions(
80 const std::vector<sp<ConditionTracker>>& allConditions,
81 const vector<Matcher>& dimensions) const override;
82
83 void getTrueSlicedDimensions(
84 const std::vector<sp<ConditionTracker>>& allConditions,
85 std::set<HashableDimensionKey>* dimensions) const override {
86 if (mSlicedChildren.size() == 1) {
87 return allConditions[mSlicedChildren.front()]->getTrueSlicedDimensions(
88 allConditions, dimensions);
89 }
90 }
91
92
Yao Chencaf339d2017-10-06 16:01:10 -070093private:
94 LogicalOperation mLogicalOperation;
Yangster-mac93694462018-01-22 20:49:31 -080095
Stefan Lafon12d01fa2017-12-04 20:56:09 -080096 // Store index of the children Predicates.
Yao Chencaf339d2017-10-06 16:01:10 -070097 // We don't store string name of the Children, because we want to get rid of the hash map to
98 // map the name to object. We don't want to store smart pointers to children, because it
99 // increases the risk of circular dependency and memory leak.
100 std::vector<int> mChildren;
Yangster13fb7e42018-03-07 17:30:49 -0800101
102 std::vector<int> mSlicedChildren;
103 std::vector<int> mUnSlicedChildren;
104
Yao Chencaf339d2017-10-06 16:01:10 -0700105};
106
107} // namespace statsd
108} // namespace os
109} // namespace android
110
111#endif // COMBINATION_CONDITION_TRACKER_H