1 /* 2 * Copyright (c) 2025 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_RECORDER_H 17 #define EVENT_RECORDER_H 18 19 #include <fstream> 20 #include <string> 21 #include <unordered_map> 22 #include <vector> 23 24 #include "input_device.h" 25 26 namespace OHOS { 27 namespace MMI { 28 class EventRecorder { 29 public: 30 EventRecorder(const std::string& outputPath); 31 ~EventRecorder(); 32 33 bool Start(std::vector<InputDevice>& devices); 34 void Stop(); 35 36 private: 37 void ProcessDeviceEvents(fd_set& readFds); 38 void MainLoop(); 39 void FlushDeviceEvents(const EventRecord& record); 40 static std::string GetEventTypeString(uint16_t type); 41 static std::string GetSecondaryEventCodeString(uint16_t type, uint16_t code); 42 static std::string GetEventCodeString(uint16_t type, uint16_t code); 43 void WriteEventText(const EventRecord& record); 44 45 std::string outputPath_; 46 std::ofstream outputFile_; 47 std::vector<InputDevice> devices_; 48 std::unordered_map<uint32_t, std::vector<EventRecord>> deviceEventBuffers_; 49 bool running_; 50 }; 51 } // namespace MMI 52 } // namespace OHOS 53 #endif // EVENT_RECORDER_H