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_REPLAYER_H 17 #define EVENT_REPLAYER_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 #include <unordered_map> 23 24 #include "input_device.h" 25 26 namespace OHOS { 27 namespace MMI { 28 class EventReplayer { 29 public: 30 EventReplayer(const std::string& inputPath, const std::map<uint16_t, uint16_t>& deviceMapping = {}); 31 bool Replay(); 32 33 static bool ParseInputLine(const std::string& line, uint32_t& deviceId, struct input_event& evt); 34 35 private: 36 bool SeekToDevicesSection(std::ifstream& inputFile); 37 bool SeekToEventsSection(std::ifstream& inputFile); 38 bool ProcessDeviceLines(std::ifstream& inputFile, 39 std::map<uint32_t, std::unique_ptr<InputDevice>>& outputDevices, uint32_t deviceCount); 40 bool InitializeOutputDevices(std::ifstream& inputFile, 41 std::map<uint32_t, std::unique_ptr<InputDevice>>& outputDevices); 42 bool ReplayEvents(std::ifstream& inputFile, 43 const std::map<uint32_t, std::unique_ptr<InputDevice>>& outputDevices); 44 void ApplyEventDelay(const struct input_event& currentEvent); 45 46 std::string inputPath_; 47 std::unordered_map<uint32_t, std::vector<input_event>> deviceEventBuffers_; 48 std::map<uint16_t, std::string> deviceMapping_; 49 std::map<std::string, std::string> hashToDevicePath_; 50 long lastSec_{0}; 51 long lastUsec_{0}; 52 bool firstEvent_{true}; 53 }; 54 } // namespace MMI 55 } // namespace OHOS 56 #endif // EVENT_REPLAYER_H