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