1 /* 2 * Copyright (c) 2021 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 HISYSEVENT_MANAGER_H 17 #define HISYSEVENT_MANAGER_H 18 19 #include <string> 20 #include <vector> 21 22 #include "hisysevent_query_callback.h" 23 #include "hisysevent_subscribe_callback.h" 24 #include "sys_event_rule.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 struct QueryArg { 29 long long beginTime; 30 long long endTime; 31 int maxEvents; QueryArgQueryArg32 QueryArg(const long long begin, const long long end, const int max) 33 : beginTime(begin), endTime(end), maxEvents(max) {}; QueryArgQueryArg34 QueryArg() {} 35 }; 36 37 class ListenerRule { 38 public: 39 ListenerRule(const std::string& domain, const std::string& eventName, domain(domain)40 const std::string& tag, RuleType ruleType = RuleType::WHOLE_WORD) : domain(domain), 41 eventName(eventName), tag(tag), ruleType(ruleType) {} 42 ListenerRule(const std::string& domain, const std::string& eventName, 43 RuleType ruleType = RuleType::WHOLE_WORD) : ListenerRule(domain, eventName, "", ruleType) {} 44 ListenerRule(const std::string& tag, RuleType ruleType = RuleType::WHOLE_WORD) 45 : ListenerRule("", "", tag, ruleType) {} 46 47 public: GetDomain()48 std::string GetDomain() const 49 { 50 return domain; 51 } GetEventName()52 std::string GetEventName() const 53 { 54 return eventName; 55 } GetTag()56 std::string GetTag() const 57 { 58 return tag; 59 } GetRuleType()60 RuleType GetRuleType() const 61 { 62 return ruleType; 63 } 64 65 private: 66 std::string domain; 67 std::string eventName; 68 std::string tag; 69 RuleType ruleType; 70 }; 71 72 class QueryRule { 73 public: QueryRule(const std::string & domain,const std::vector<std::string> & eventList)74 QueryRule(const std::string& domain, const std::vector<std::string>& eventList) 75 : domain(domain), eventList(eventList), ruleType(RuleType::WHOLE_WORD) {} 76 77 public: GetDomain()78 std::string GetDomain() const 79 { 80 return domain; 81 } GetEventList()82 std::vector<std::string> GetEventList() const 83 { 84 return eventList; 85 } GetRuleType()86 RuleType GetRuleType() const 87 { 88 return ruleType; 89 } 90 91 private: 92 std::string domain; 93 std::vector<std::string> eventList; 94 RuleType ruleType; 95 }; 96 97 class HiSysEventManager { 98 public: 99 HiSysEventManager() = default; 100 static bool AddEventListener(std::shared_ptr<HiSysEventSubscribeCallBack> listener, 101 std::vector<ListenerRule>& rules); 102 static bool RemoveListener(std::shared_ptr<HiSysEventSubscribeCallBack> listener); 103 static bool QueryHiSysEvent(struct QueryArg& queryArg, 104 std::vector<QueryRule>& queryRules, 105 std::shared_ptr<HiSysEventQueryCallBack> queryCallBack); 106 static bool SetDebugMode(std::shared_ptr<HiSysEventSubscribeCallBack> listener, bool mode); ~HiSysEventManager()107 ~HiSysEventManager() {} 108 }; 109 } // namespace HiviewDFX 110 } // namespace OHOS 111 112 #endif // HISYSEVENT_MANAGER_H 113