1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ARG_RULES_H 17 #define ARG_RULES_H 18 19 #include <limits> 20 #include <string> 21 #include <vector> 22 23 #include "rule_type.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 struct QueryArg { 28 long long beginTime; 29 long long endTime; 30 int maxEvents; 31 long long fromSeq; 32 long long toSeq; 33 34 QueryArg(const long long beginTime = -1, const long long endTime = -1, const int maxEvents = -1, 35 const long long fromSeq = -1, const long long toSeq = -1) 36 { 37 this->beginTime = beginTime < 0 ? 0 : beginTime; 38 this->endTime = endTime < 0 ? std::numeric_limits<long long>::max() : endTime; 39 this->maxEvents = maxEvents < 0 ? std::numeric_limits<int>::max() : maxEvents; 40 this->fromSeq = fromSeq; 41 this->toSeq = toSeq; 42 } 43 QueryArgQueryArg44 QueryArg(): beginTime(0), endTime(0), maxEvents(0), fromSeq(-1), toSeq(-1) {} 45 }; 46 47 class ListenerRule { 48 public: 49 ListenerRule(const std::string& domain, const std::string& eventName, 50 const std::string& tag, RuleType ruleType = RuleType::WHOLE_WORD, uint32_t eventType = 0) : domain(domain), 51 eventName(eventName), tag(tag), ruleType(ruleType), eventType(eventType) {} 52 ListenerRule(const std::string& domain, const std::string& eventName, 53 RuleType ruleType = RuleType::WHOLE_WORD) : ListenerRule(domain, eventName, "", ruleType) {} 54 ListenerRule(const std::string& tag, RuleType ruleType = RuleType::WHOLE_WORD) 55 : ListenerRule("", "", tag, ruleType) {} 56 57 public: GetDomain()58 std::string GetDomain() const 59 { 60 return domain; 61 } GetEventName()62 std::string GetEventName() const 63 { 64 return eventName; 65 } GetTag()66 std::string GetTag() const 67 { 68 return tag; 69 } GetRuleType()70 RuleType GetRuleType() const 71 { 72 return ruleType; 73 } GetEventType()74 uint32_t GetEventType() const 75 { 76 return eventType; 77 } 78 79 private: 80 std::string domain; 81 std::string eventName; 82 std::string tag; 83 RuleType ruleType; 84 uint32_t eventType; 85 }; 86 87 class QueryRule { 88 public: 89 QueryRule(const std::string& domain, const std::vector<std::string>& eventList, 90 RuleType ruleType = RuleType::WHOLE_WORD, uint32_t eventType = 0, const std::string& cond = "") 91 : domain(domain), eventList(eventList), ruleType(ruleType), eventType(eventType), condition(cond) {} 92 93 public: GetDomain()94 std::string GetDomain() const 95 { 96 return domain; 97 } GetEventList()98 std::vector<std::string> GetEventList() const 99 { 100 return eventList; 101 } GetRuleType()102 RuleType GetRuleType() const 103 { 104 return ruleType; 105 } GetEventType()106 uint32_t GetEventType() const 107 { 108 return eventType; 109 } GetCondition()110 std::string GetCondition() const 111 { 112 return condition; 113 } 114 115 private: 116 std::string domain; 117 std::vector<std::string> eventList; 118 RuleType ruleType; 119 uint32_t eventType; 120 std::string condition; 121 }; 122 } // namespace HiviewDFX 123 } // namespace OHOS 124 125 #endif // ARG_RULES_H 126 127