• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 OHOS_DISTRIBUTED_INPUT_CONSTANTS_H
17 #define OHOS_DISTRIBUTED_INPUT_CONSTANTS_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include <linux/uinput.h>
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 namespace DistributedInput {
28 #define INPUT_KEY_WHEN  "when"
29 #define INPUT_KEY_TYPE  "type"
30 #define INPUT_KEY_CODE  "code"
31 #define INPUT_KEY_VALUE "value"
32 #define INPUT_KEY_DESCRIPTOR  "descriptor"
33 #define INPUT_KEY_PATH "path"
34 
35 #define VIRTUAL_DEVICE_NAME "DistributedInput "
36 #define LONG_BITS (sizeof(long) * 8)
37 #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
38 
39     const char INPUT_STRING_SPLIT_POINT = '.';
40     const uint32_t KEY_DOWN_STATE = 1;
41     const uint32_t KEY_UP_STATE = 0;
42     const uint32_t KEY_REPEAT = 2;
43     const uint32_t READ_SLEEP_TIME_MS = 50;
44     const uint32_t READ_RETRY_MAX = 5;
45     const uint32_t DH_ID_LENGTH_MAX = 256;
46     const uint32_t DEV_ID_LENGTH_MAX = 256;
47     const uint32_t STRING_MAX_SIZE = 40 * 1024 * 1024;
48     const uint32_t SCREEN_MSG_MAX = 40 * 1024 * 1024;
49     const uint32_t AUTH_SESSION_SIDE_SERVER = 0;
50     const uint32_t IPC_VECTOR_MAX_SIZE = 32;
51 
52     /*
53      * Device Type definitions
54      */
55     enum class DInputDeviceType : uint32_t {
56         NONE = 0x0000,
57         MOUSE = 0x0001,
58         KEYBOARD = 0x0002,
59         TOUCHSCREEN = 0x0004,
60         TOUCHPAD = MOUSE,
61         ALL = MOUSE | KEYBOARD | TOUCHSCREEN,
62     };
63 
64     const char * const DEVICE_PATH = "/dev/input";
65 
66     /*
67      * Maximum number of signalled FDs to handle at a time.
68      */
69     constexpr uint32_t EPOLL_MAX_EVENTS = 16;
70 
71     /*
72      * Maximum number of event buffer size.
73      */
74     constexpr uint32_t INPUT_EVENT_BUFFER_SIZE = 256;
75 
76     constexpr int32_t INPUT_LOAD_SA_TIMEOUT_MS = 10000;
77 
78     constexpr int32_t INPUT_LATENCY_DELAYTIME_US = 50 * 1000;
79 
80     constexpr uint32_t INPUT_LATENCY_DELAY_TIMES = 60;
81 
82     constexpr int32_t SESSION_WAIT_TIMEOUT_SECOND = 5;
83 
84     constexpr int32_t EPOLL_WAITTIME = 100;
85 
86     constexpr uint64_t WATCHDOG_INTERVAL_TIME_MS = 20 * 1000;
87 
88     /* The input device is a keyboard or has buttons. */
89     constexpr uint32_t INPUT_DEVICE_CLASS_KEYBOARD      = 0x00000001;
90 
91     /* The input device is an alpha-numeric keyboard (not just a dial pad). */
92     constexpr uint32_t INPUT_DEVICE_CLASS_ALPHAKEY      = 0x00000002;
93 
94     /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
95     constexpr uint32_t INPUT_DEVICE_CLASS_TOUCH         = 0x00000004;
96 
97     /* The input device is a cursor device such as a trackball or mouse. */
98     constexpr uint32_t INPUT_DEVICE_CLASS_CURSOR        = 0x00000008;
99 
100     /* The input device is a multi-touch touchscreen. */
101     constexpr uint32_t INPUT_DEVICE_CLASS_TOUCH_MT      = 0x00000010;
102 
103     /* The input device is a directional pad (implies keyboard, has DPAD keys). */
104     constexpr uint32_t INPUT_DEVICE_CLASS_DPAD          = 0x00000020;
105 
106     /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
107     constexpr uint32_t INPUT_DEVICE_CLASS_GAMEPAD       = 0x00000040;
108 
109     /* The input device has switches. */
110     constexpr uint32_t INPUT_DEVICE_CLASS_SWITCH        = 0x00000080;
111 
112     /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
113     constexpr uint32_t INPUT_DEVICE_CLASS_JOYSTICK      = 0x00000100;
114 
115     /* The input device has a vibrator (supports FF_RUMBLE). */
116     constexpr uint32_t INPUT_DEVICE_CLASS_VIBRATOR      = 0x00000200;
117 
118     /* The input device has a microphone. */
119     constexpr uint32_t INPUT_DEVICE_CLASS_MIC           = 0x00000400;
120 
121     /* The input device is an external stylus (has data we want to fuse with touch data). */
122     constexpr uint32_t INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800;
123 
124     /* The input device has a rotary encoder. */
125     constexpr uint32_t INPUT_DEVICE_CLASS_ROTARY_ENCODER = 0x00001000;
126 
127     /* The input device is virtual (not a real device, not part of UI configuration). */
128     constexpr uint32_t INPUT_DEVICE_CLASS_VIRTUAL       = 0x40000000;
129 
130     /* The input device is external (not built-in). */
131     constexpr uint32_t INPUT_DEVICE_CLASS_EXTERNAL      = 0x80000000;
132 
133     constexpr uint32_t MAX_SIZE_OF_DEVICE_NAME = UINPUT_MAX_NAME_SIZE - 1;
134 
135     const std::string DH_ID_PREFIX = "Input_";
136 
137     const std::string DINPUT_SPLIT_COMMA = ", ";
138 
139     const char VIR_NODE_SPLIT_CHAR = '|';
140     const std::string VIR_NODE_SPLIT = "|";
141     const std::string VIR_NODE_PID_SPLIT = "/";
142     const uint32_t VIR_NODE_PHY_LEN = 3;
143     const uint32_t VIR_NODE_PHY_DEVID_IDX = 1;
144     const uint32_t VIR_NODE_PHY_DHID_IDX = 2;
145 
146     const std::string SOURCE_DEVICE_ID = "sourceDevId";
147 
148     const std::string SINK_DEVICE_ID = "sinkDevId";
149 
150     const std::string SOURCE_WINDOW_ID = "sourceWinId";
151 
152     const std::string SINK_SHOW_WINDOW_ID = "sinkShowWinId";
153 
154     const std::string SOURCE_WINDOW_WIDTH = "sourceWinWidth";
155 
156     const std::string SOURCE_WINDOW_HEIGHT = "sourceWinHeight";
157 
158     const std::string SINK_PROJECT_SHOW_WIDTH = "sinkProjShowWidth";
159 
160     const std::string SINK_PROJECT_SHOW_HEIGHT = "sinkProjShowHeight";
161 
162     const std::string SINK_WINDOW_SHOW_X = "sinkWinShowX";
163 
164     const std::string SINK_WINDOW_SHOW_Y = "sinkWinShowY";
165 
166     const std::string DEVICE_NAME = "name";
167 
168     const std::string PHYSICAL_PATH = "physicalPath";
169 
170     const std::string UNIQUE_ID = "uniqueId";
171 
172     const std::string BUS = "bus";
173 
174     const std::string VENDOR = "vendor";
175 
176     const std::string PRODUCT = "product";
177 
178     const std::string VERSION = "version";
179 
180     const std::string DESCRIPTOR = "descriptor";
181 
182     const std::string CLASSES = "classes";
183 
184     const std::string EVENT_TYPES = "eventTypes";
185 
186     const std::string EVENT_KEYS = "eventKeys";
187 
188     const std::string ABS_TYPES = "absTypes";
189 
190     const std::string ABS_INFOS = "absInfos";
191 
192     const std::string REL_TYPES = "relTypes";
193 
194     const std::string PROPERTIES = "properties";
195 
196     const std::string MISCELLANEOUS = "miscellaneous";
197 
198     const std::string LEDS = "leds";
199 
200     const std::string REPEATS = "repeats";
201 
202     const std::string SWITCHS = "switchs";
203 
204     const std::string DH_TOUCH_PAD = "touchpad";
205 
206     const std::string DINPUT_LOG_TITLE_TAG = "DINPUT";
207 
208     constexpr const char* LATENCY_COUNT_THREAD_NAME = "latencyCount";
209 
210     constexpr const char* EVENT_INJECT_THREAD_NAME = "eventInject";
211 
212     constexpr const char* COLLECT_EVENT_THREAD_NAME = "collectEvents";
213 
214     constexpr const char* CHECK_KEY_STATUS_THREAD_NAME = "checkKeyStatus";
215 
216     constexpr int32_t LOG_MAX_LEN = 4096;
217 
218     constexpr uint32_t SCREEN_ID_DEFAULT = 0;
219 
220     constexpr uint32_t DEFAULT_VALUE = 0;
221 
222     constexpr int32_t UN_INIT_FD_VALUE = -1;
223 
224     constexpr int32_t SINK_SCREEN_INFO_SIZE = 4;
225 
226     enum class EHandlerMsgType {
227         DINPUT_SINK_EVENT_HANDLER_MSG = 1,
228         DINPUT_SOURCE_EVENT_HANDLER_MSG = 2
229     };
230 
231     struct BusinessEvent {
232         std::vector<int32_t> pressedKeys;
233         int32_t keyCode;
234         int32_t keyAction;
235     };
236 
237     struct TouchScreenEvent {
238         uint32_t absX;
239         uint32_t absY;
240     };
241 
242     /*
243      * A raw event as retrieved from the input_event.
244      */
245     struct RawEvent {
246         int64_t when;
247         uint32_t type;
248         uint32_t code;
249         int32_t value;
250         std::string descriptor;
251         std::string path;
252 
253         bool operator == (const RawEvent &e)
254         {
255             return this->type == e.type && this->code == e.code &&
256                 this->descriptor == e.descriptor && this->path == e.path;
257         }
258     };
259 
260     /*
261      * Input device Info retrieved from the kernel.
262      */
263     struct InputDevice {
InputDeviceInputDevice264         inline InputDevice() : name(""), physicalPath(""), uniqueId(""), bus(0), vendor(0), product(0),
265             version(0), descriptor(""), classes(0) {}
266         std::string name;
267         std::string physicalPath;
268         std::string uniqueId;
269         uint16_t bus;
270         uint16_t vendor;
271         uint16_t product;
272         uint16_t version;
273         std::string descriptor;
274         uint32_t classes;
275         std::vector<uint32_t> eventTypes;
276         std::vector<uint32_t> eventKeys;
277         std::vector<uint32_t> absTypes;
278         std::map<uint32_t, std::vector<int32_t>> absInfos;
279         std::vector<uint32_t> relTypes;
280         std::vector<uint32_t> properties;
281 
282         std::vector<uint32_t> miscellaneous;
283         std::vector<uint32_t> leds;
284         std::vector<uint32_t> switchs;
285         std::vector<uint32_t> repeats;
286     };
287 
288     /*
289      * Distributed Hardware Handle
290      */
291     struct HardwareHandle {
292         // equipment ID
293         std::string eqId;
294 
295         // Hardware ID
296         std::string hhId;
297 
298         // Hardware detailed information
299         std::string hdInfo;
300     };
301 
302     // Synthetic raw event type codes produced when devices are added or removed.
303     enum class DeviceType {
304         // Sent when a device is added.
305         DEVICE_ADDED = 0x10000000,
306 
307         // Sent when a device is removed.
308         DEVICE_REMOVED = 0x20000000,
309 
310         // Sent when all added/removed devices from the most recent scan have been reported.
311         // This event is always sent at least once.
312         FINISHED_DEVICE_SCAN = 0x30000000,
313 
314         FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
315     };
316 
317     /*
318      * Input device connection status
319      */
320     struct InputDeviceEvent {
321         DeviceType type;
322         InputDevice deviceInfo;
323     };
324 
325     /*
326      * Device Type definitions
327      */
328     enum class DInputServerType {
329         /*
330          * null server
331          */
332         NULL_SERVER_TYPE = 0,
333 
334         /*
335          * source server
336          */
337         SOURCE_SERVER_TYPE = 1,
338 
339         /*
340          * sink server.
341          */
342         SINK_SERVER_TYPE = 2,
343     };
344 
345     // Current Input Session Status
346     enum class SessionStatus : uint32_t {
347         CLOSED = 0x00,
348         OPENING = 0x01,
349         OPENED = 0x02,
350         CLOSING = 0x03,
351     };
352 } // namespace DistributedInput
353 } // namespace DistributedHardware
354 } // namespace OHOS
355 
356 #endif // OHOS_DISTRIBUTED_INPUT_CONSTANTS_H
357