1 /*
2  * Copyright (c) 2024 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 EVENT_STATISTIC_H
17 #define EVENT_STATISTIC_H
18 
19 #include <atomic>
20 #include <chrono>
21 #include <condition_variable>
22 #include <ctime>
23 #include <fstream>
24 #include <iomanip>
25 #include <iostream>
26 #include <list>
27 #include <memory>
28 #include <mutex>
29 #include <queue>
30 #include <sstream>
31 #include <stdio.h>
32 #include <string>
33 #include <sys/stat.h>
34 #include <thread>
35 #include <unistd.h>
36 #include <vector>
37 
38 #include "input_event.h"
39 #include "key_event.h"
40 #include "pointer_event.h"
41 #include "switch_event.h"
42 
43 namespace OHOS {
44 namespace MMI {
45 class EventStatistic final {
46 public:
47     static void PushEvent(std::shared_ptr<InputEvent> eventPtr);
48     static void PushPointerEvent(std::shared_ptr<PointerEvent> eventPtr);
49     static std::string PopEvent();
50     static void WriteEventFile();
51     static void Dump(int32_t fd, const std::vector<std::string> &args);
52     static std::string ConvertEventToStr(const std::shared_ptr<InputEvent> eventPtr);
53     static std::string ConvertTimeToStr(int64_t timestamp);
54 
55 private:
56     static std::queue<std::string> eventQueue_;
57     static std::list<std::string> dumperEventList_;
58     static std::mutex queueMutex_;
59     static std::condition_variable queueCondition_;
60     static bool writeFileEnabled_;
61 };
62 } // namespace MMI
63 } // namespace OHOS
64 #endif // EVENT_STATISTIC_H