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_TOOL_H 17#define HISYSEVENT_TOOL_H 18 19#include <functional> 20#include <map> 21#include <string> 22#include <thread> 23 24#include "hisysevent_manager.h" 25 26namespace OHOS { 27namespace HiviewDFX { 28struct ArgStuct { 29 bool real; 30 bool checkValidEvent; 31 std::string domain; 32 std::string eventName; 33 std::string tag; 34 RuleType ruleType; 35 bool history; 36 bool isDebug; 37 long long beginTime; 38 long long endTime; 39 int maxEvents; 40 uint32_t eventType; 41}; 42 43using OptHandler = std::function<void(struct ArgStuct&, const char*)>; 44 45class HiSysEventTool { 46public: 47 HiSysEventTool(bool autoExit = true); 48 ~HiSysEventTool() {} 49 50public: 51 void DoCmdHelp(); 52 bool DoAction(); 53 void NotifyClient(); 54 bool ParseCmdLine(int argc, char** argv); 55 void WaitClient(); 56 57private: 58 bool CheckCmdLine(); 59 void HandleInput(int argc, char** argv, const char* selection); 60 61private: 62 struct ArgStuct clientCmdArg; 63 bool autoExit = true; 64 std::condition_variable condvClient; 65 std::mutex mutexClient; 66 std::map<int, OptHandler> optHandlers; 67}; 68} // namespace HiviewDFX 69} // namespace OHOS 70 71#endif // HISYSEVENT_TOOL_H 72