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 <algorithm> 20 #include <fstream> 21 #include <queue> 22 #include <sys/stat.h> 23 #include <unistd.h> 24 25 #include "pointer_event.h" 26 #include "key_event.h" 27 #include "switch_event.h" 28 29 namespace OHOS { 30 namespace MMI { 31 class EventStatistic final { 32 public: 33 static void PushEventStr(std::string eventStr); 34 static void PushPointerEvent(std::shared_ptr<PointerEvent> eventPtr); 35 static void PushKeyEvent(std::shared_ptr<KeyEvent> eventPtr); 36 static void PushSwitchEvent(std::shared_ptr<SwitchEvent> eventPtr); 37 static void PushPointerRecord(std::shared_ptr<PointerEvent> eventPtr); 38 static int32_t QueryPointerRecord(int32_t count, std::vector<std::shared_ptr<PointerEvent>> &pointerList); 39 static std::string PopEvent(); 40 static void WriteEventFile(); 41 static void Dump(int32_t fd, const std::vector<std::string> &args); 42 static std::string ConvertInputEventToStr(const std::shared_ptr<InputEvent> eventPtr); 43 static std::string ConvertTimeToStr(int64_t timestamp); 44 static const char* ConvertEventTypeToString(int32_t eventType); 45 static const char* ConvertSourceTypeToString(int32_t sourceType_); 46 static const char* ConvertPointerActionToString(std::shared_ptr<PointerEvent> eventPtr); 47 static const char* ConvertKeyActionToString(int32_t keyAction); 48 static const char* ConvertSwitchTypeToString(int32_t switchType); 49 50 private: 51 struct PointerEventRecord { 52 int64_t actionTime; 53 int32_t sourceType; 54 bool isInject; 55 std::vector<double> pressures; 56 std::vector<double> tiltXs; 57 std::vector<double> tiltYs; PointerEventRecordPointerEventRecord58 PointerEventRecord(int64_t actionTime, int32_t sourceType, bool isInject, std::vector<double> pressures, 59 std::vector<double> tiltXs, std::vector<double> tiltYs) 60 : actionTime(actionTime), sourceType(sourceType), isInject(isInject), pressures(pressures), tiltXs(tiltXs), 61 tiltYs(tiltYs) 62 {} 63 }; 64 static std::queue<std::string> eventQueue_; 65 static std::list<std::string> dumperEventList_; 66 static std::mutex queueMutex_; 67 static std::condition_variable queueCondition_; 68 static bool writeFileEnabled_; 69 static std::deque<EventStatistic::PointerEventRecord> pointerRecordDeque_; 70 }; 71 } // namespace MMI 72 } // namespace OHOS 73 #endif // EVENT_STATISTIC_H