1 /* 2 * Copyright (c) 2021-2022 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 VIRTUAL_DEVICE_H 17 #define VIRTUAL_DEVICE_H 18 19 #include "nocopyable.h" 20 #include "virtual_device_config.h" 21 22 namespace OHOS { 23 namespace MMI { 24 class VirtualDevice { 25 public: 26 static std::vector<std::string> BrowseDirectory(const std::string& filePath); 27 static std::string ReadFile(const std::string& filePath); 28 static int32_t GetFileSize(const std::string& filePath); 29 static std::string ReadUinputToolFile(const std::string& filePath); 30 static bool ClearFileResidues(const std::string& fileName); 31 static bool CreateHandle(const std::string& deviceArgv); 32 static bool AddDevice(const std::string& startDeviceName); 33 static bool CloseDevice(const std::string& closeDeviceName, const std::vector<std::string>& deviceList); 34 static bool CheckCommand(int32_t argc, char **argv); 35 static bool SelectOptions(int32_t argc, char **argv, int32_t &opt); 36 static bool ListOption(int32_t argc, char **argv); 37 static bool StartOption(int32_t argc, char **argv); 38 static bool CloseOption(int32_t argc, char **argv); 39 static bool HelpOption(int32_t argc, char **argv); 40 static void ShowUsage(); 41 VirtualDevice(const std::string& deviceName, uint16_t busType, uint16_t vendorId, uint16_t productId); 42 DISALLOW_COPY_AND_MOVE(VirtualDevice); 43 virtual ~VirtualDevice(); 44 bool SetUp(); 45 void Close(); 46 bool CreateKey(); 47 bool SetAbsResolution(); 48 bool SetPhys(const std::string& deviceName); 49 bool DoIoctl(int32_t fd, int32_t request, const uint32_t value); 50 void SetDeviceId(); 51 52 protected: 53 void SetResolution(const ResolutionInfo& resolutionInfo); 54 void SetAbsValue(const AbsInfo& absInfo); 55 virtual const std::vector<uint32_t>& GetAbs() const; 56 virtual const std::vector<uint32_t>& GetEventTypes() const; 57 virtual const std::vector<uint32_t>& GetKeys() const; 58 virtual const std::vector<uint32_t>& GetLeds() const; 59 virtual const std::vector<uint32_t>& GetMiscellaneous() const; 60 virtual const std::vector<uint32_t>& GetProperties() const; 61 virtual const std::vector<uint32_t>& GetRelBits() const; 62 virtual const std::vector<uint32_t>& GetRepeats() const; 63 virtual const std::vector<uint32_t>& GetSwitches() const; 64 65 protected: 66 int32_t fd_ { -1 }; 67 std::string deviceName_; 68 const uint16_t busTtype_ { 0 }; 69 const uint16_t vendorId_ { 0 }; 70 const uint16_t productId_ { 0 }; 71 const uint16_t version_ { 0 }; 72 struct uinput_user_dev uinputDev_ {}; 73 struct uinput_abs_setup uinputAbs_ {}; 74 std::vector<uinput_abs_setup> absInit_; 75 std::vector<uint32_t> eventTypes_; 76 std::vector<uint32_t> keys_; 77 std::vector<uint32_t> properties_; 78 std::vector<uint32_t> abs_; 79 std::vector<uint32_t> relBits_; 80 std::vector<uint32_t> leds_; 81 std::vector<uint32_t> miscellaneous_; 82 std::vector<uint32_t> switches_; 83 std::vector<uint32_t> repeats_; 84 }; 85 } // namespace MMI 86 } // namespace OHOS 87 #endif // VIRTUAL_DEVICE_H 88