/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef VIRTUAL_DEVICE_H #define VIRTUAL_DEVICE_H #include "nocopyable.h" #include "virtual_device_config.h" namespace OHOS { namespace MMI { class VirtualDevice { public: static std::vector BrowseDirectory(const std::string& filePath); static std::string ReadFile(const std::string& filePath); static int32_t GetFileSize(const std::string& filePath); static std::string ReadUinputToolFile(const std::string& filePath); static bool ClearFileResidues(const std::string& fileName); static bool CreateHandle(const std::string& deviceArgv); static bool AddDevice(const std::string& startDeviceName); static bool CloseDevice(const std::string& closeDeviceName, const std::vector& deviceList); static bool CheckCommand(int32_t argc, char **argv); static bool SelectOptions(int32_t argc, char **argv, int32_t &opt); static bool ListOption(int32_t argc, char **argv); static bool StartOption(int32_t argc, char **argv); static bool CloseOption(int32_t argc, char **argv); static bool HelpOption(int32_t argc, char **argv); static void ShowUsage(); VirtualDevice(const std::string& deviceName, uint16_t busType, uint16_t vendorId, uint16_t productId); DISALLOW_COPY_AND_MOVE(VirtualDevice); virtual ~VirtualDevice(); bool SetUp(); void Close(); bool CreateKey(); bool SetAbsResolution(); bool SetPhys(const std::string& deviceName); bool DoIoctl(int32_t fd, int32_t request, const uint32_t value); void SetDeviceId(); protected: void SetResolution(const ResolutionInfo& resolutionInfo); void SetAbsValue(const AbsInfo& absInfo); virtual const std::vector& GetAbs() const; virtual const std::vector& GetEventTypes() const; virtual const std::vector& GetKeys() const; virtual const std::vector& GetLeds() const; virtual const std::vector& GetMiscellaneous() const; virtual const std::vector& GetProperties() const; virtual const std::vector& GetRelBits() const; virtual const std::vector& GetRepeats() const; virtual const std::vector& GetSwitches() const; protected: int32_t fd_ { -1 }; std::string deviceName_; const uint16_t busTtype_ { 0 }; const uint16_t vendorId_ { 0 }; const uint16_t productId_ { 0 }; const uint16_t version_ { 0 }; struct uinput_user_dev uinputDev_ {}; struct uinput_abs_setup uinputAbs_ {}; std::vector absInit_; std::vector eventTypes_; std::vector keys_; std::vector properties_; std::vector abs_; std::vector relBits_; std::vector leds_; std::vector miscellaneous_; std::vector switches_; std::vector repeats_; }; } // namespace MMI } // namespace OHOS #endif // VIRTUAL_DEVICE_H