1 /*
2  * Copyright (c) 2023 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 <cstdint>
20 #include <vector>
21 
22 #include <linux/uinput.h>
23 
24 #include "nocopyable.h"
25 #include "v1_0/hid_ddk_types.h"
26 
27 namespace OHOS {
28 namespace ExternalDeviceManager {
29 using namespace OHOS::HDI::Input::Ddk::V1_0;
30 class VirtualDevice {
31 public:
32     VirtualDevice(const char *deviceName, uint16_t productId);
33     VirtualDevice(const Hid_Device &hidDevice, const Hid_EventProperties &hidEventProperties);
34     DISALLOW_COPY_AND_MOVE(VirtualDevice);
35     virtual ~VirtualDevice();
36     bool EmitEvent(uint16_t type, uint16_t code, uint32_t value) const;
37     bool SetUp();
38     bool CreateKey();
39 
40 protected:
41     virtual const std::vector<uint32_t> &GetEventTypes() const;
42     virtual const std::vector<uint32_t> &GetKeys() const;
43     virtual const std::vector<uint32_t> &GetProperties() const;
44     virtual const std::vector<uint32_t> &GetAbs() const;
45     virtual const std::vector<uint32_t> &GetRelBits() const;
46     virtual const std::vector<uint32_t> &GetLeds() const;
47     virtual const std::vector<uint32_t> &GetMiscellaneous() const;
48     virtual const std::vector<uint32_t> &GetRepeats() const;
49     virtual const std::vector<uint32_t> &GetSwitches() const;
50     bool SetAttribute();
51     int32_t fd_ {-1};
52     const char * const deviceName_;
53     const uint16_t busType_;
54     const uint16_t vendorId_;
55     const uint16_t productId_;
56     const uint16_t version_;
57     struct uinput_user_dev uinputDev_ {};
58     struct uinput_abs_setup uinputAbs_ {};
59     std::vector<uinput_abs_setup> absInit_;
60     std::vector<uint32_t> eventTypes_;
61     std::vector<uint32_t> keys_;
62     std::vector<uint32_t> properties_;
63     std::vector<uint32_t> abs_;
64     std::vector<uint32_t> relBits_;
65     std::vector<uint32_t> leds_;
66     std::vector<uint32_t> miscellaneous_;
67     std::vector<uint32_t> switches_;
68     std::vector<uint32_t> repeats_;
69 };
70 } // namespace ExternalDeviceManager
71 } // namespace OHOS
72 #endif // VIRTUAL_DEVICE_H