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 INPUT_DEVICE_H 17 #define INPUT_DEVICE_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 #include "common.h" 24 25 namespace OHOS { 26 namespace MMI { 27 class InputDevice { 28 public: 29 InputDevice(const InputDevice&) = delete; 30 InputDevice& operator=(const InputDevice&) = delete; 31 InputDevice(); 32 InputDevice(const std::string& path, uint32_t id); 33 InputDevice(InputDevice&& other) noexcept; 34 ~InputDevice(); 35 36 InputDevice& operator=(InputDevice&& other) noexcept; 37 38 bool IsOpen() const; 39 void Close(); 40 bool OpenForReading(); 41 bool OpenForWriting(); 42 43 int32_t GetFd() const; 44 const std::string& GetPath() const; 45 const std::string& GetName() const; 46 uint32_t GetId() const; 47 std::string GetHash() const; 48 49 void SetId(uint32_t id); 50 void SetPath(const std::string& path); 51 void SetName(const std::string& name); 52 53 bool ReadEvent(input_event& event); 54 bool WriteEvents(const std::vector<input_event>& events); 55 bool InitFromTextLine(const std::string& line); 56 57 private: 58 bool VerifyDeviceMatch() const; 59 bool OpenDevice(int32_t flags); 60 void QueryDeviceInfo(); 61 void CalculateDeviceHash(); 62 63 std::string path_; 64 std::string name_; 65 std::string hash_; 66 uint32_t id_; 67 int32_t fd_; 68 std::map<int32_t, int32_t> deviceMapping_; 69 }; 70 } // namespace MMI 71 } // namespace OHOS 72 #endif // INPUT_DEVICE_H