• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 namespace OHOS {
27 namespace HiviewDFX {
28 struct 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     long long beginTime;
37     long long endTime;
38     int maxEvents;
39     uint32_t eventType;
40 };
41 
42 using OptHandler = std::function<void(struct ArgStuct&, const char*)>;
43 
44 class HiSysEventTool {
45 public:
46     HiSysEventTool(bool autoExit = true);
~HiSysEventTool()47     ~HiSysEventTool() {}
48 
49 public:
50     void DoCmdHelp();
51     bool DoAction();
52     void NotifyClient();
53     bool ParseCmdLine(int argc, char** argv);
54     void WaitClient();
55 
56 private:
57     bool CheckCmdLine();
58     void HandleInput(int argc, char** argv, const char* selection);
59 
60 private:
61     struct ArgStuct clientCmdArg;
62     bool autoExit = true;
63     std::condition_variable condvClient;
64     std::mutex mutexClient;
65     std::map<int, OptHandler> optHandlers;
66 };
67 } // namespace HiviewDFX
68 } // namespace OHOS
69 
70 #endif // HISYSEVENT_TOOL_H
71