• 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 CommandBranch(std::vector<std::string>& argvList);
34     VirtualDevice(const std::string& deviceName, uint16_t busType, uint16_t vendorId, uint16_t productId);
35     DISALLOW_COPY_AND_MOVE(VirtualDevice);
36     virtual ~VirtualDevice();
37     bool SetUp();
38     void Close();
39     bool CreateKey();
40     bool SetAbsResolution();
41     bool SetPhys(const std::string& deviceName);
42     bool DoIoctl(int32_t fd, int32_t request, const uint32_t value);
43     void SetDeviceId();
44 
45 protected:
46     void SetResolution(const ResolutionInfo& resolutionInfo);
47     void SetAbsValue(const AbsInfo& absInfo);
48     virtual const std::vector<uint32_t>& GetAbs() const;
49     virtual const std::vector<uint32_t>& GetEventTypes() const;
50     virtual const std::vector<uint32_t>& GetKeys() const;
51     virtual const std::vector<uint32_t>& GetLeds() const;
52     virtual const std::vector<uint32_t>& GetMiscellaneous() const;
53     virtual const std::vector<uint32_t>& GetProperties() const;
54     virtual const std::vector<uint32_t>& GetRelBits() const;
55     virtual const std::vector<uint32_t>& GetRepeats() const;
56     virtual const std::vector<uint32_t>& GetSwitches() const;
57 
58 protected:
59     int32_t fd_ { -1 };
60     std::string deviceName_;
61     const uint16_t busTtype_ { 0 };
62     const uint16_t vendorId_ { 0 };
63     const uint16_t productId_ { 0 };
64     const uint16_t version_ { 0 };
65     struct uinput_user_dev uinputDev_ {};
66     struct uinput_abs_setup uinputAbs_ {};
67     std::vector<uinput_abs_setup> absInit_;
68     std::vector<uint32_t> eventTypes_;
69     std::vector<uint32_t> keys_;
70     std::vector<uint32_t> properties_;
71     std::vector<uint32_t> abs_;
72     std::vector<uint32_t> relBits_;
73     std::vector<uint32_t> leds_;
74     std::vector<uint32_t> miscellaneous_;
75     std::vector<uint32_t> switches_;
76     std::vector<uint32_t> repeats_;
77 };
78 } // namespace MMI
79 } // namespace OHOS
80 #endif  // VIRTUAL_DEVICE_H
81