blob: 88159e77b3745413ac4e1791b273d2790e1b88ea [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//
18#ifndef _RUNTIME_EVENT_HUB_H
19#define _RUNTIME_EVENT_HUB_H
20
Mathias Agopianb93a03f82012-02-17 15:34:57 -080021#include <androidfw/Input.h>
Jeff Brown9f25b7f2012-04-10 14:30:49 -070022#include <androidfw/InputDevice.h>
Mathias Agopianb93a03f82012-02-17 15:34:57 -080023#include <androidfw/Keyboard.h>
24#include <androidfw/KeyLayoutMap.h>
25#include <androidfw/KeyCharacterMap.h>
26#include <androidfw/VirtualKeyMap.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/String8.h>
28#include <utils/threads.h>
Mathias Agopian3b4062e2009-05-31 19:13:00 -070029#include <utils/Log.h>
30#include <utils/threads.h>
31#include <utils/List.h>
32#include <utils/Errors.h>
Jeff Brown47e6b1b2010-11-29 17:37:49 -080033#include <utils/PropertyMap.h>
Jeff Brown90655042010-12-02 13:50:46 -080034#include <utils/Vector.h>
Jeff Brown93fa9b32011-06-14 17:09:25 -070035#include <utils/KeyedVector.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37#include <linux/input.h>
Jeff Brown93fa9b32011-06-14 17:09:25 -070038#include <sys/epoll.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Jeff Brown46b9ac02010-04-22 18:58:52 -070040/* Convenience constants. */
41
Jeff Brown49ccac52012-04-11 18:27:33 -070042#define BTN_FIRST 0x100 // first button code
43#define BTN_LAST 0x15f // last button code
Jeff Brown46b9ac02010-04-22 18:58:52 -070044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045namespace android {
46
Jeff Brown9f25b7f2012-04-10 14:30:49 -070047enum {
48 // Device id of a special "virtual" keyboard that is always present.
49 VIRTUAL_KEYBOARD_ID = -1,
50 // Device id of the "built-in" keyboard if there is one.
51 BUILT_IN_KEYBOARD_ID = 0,
52};
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054/*
Jeff Brown6d0fec22010-07-23 21:28:06 -070055 * A raw event as retrieved from the EventHub.
56 */
57struct RawEvent {
58 nsecs_t when;
59 int32_t deviceId;
60 int32_t type;
Jeff Brown49ccac52012-04-11 18:27:33 -070061 int32_t code;
Jeff Brown6d0fec22010-07-23 21:28:06 -070062 int32_t value;
Jeff Brown6d0fec22010-07-23 21:28:06 -070063};
64
65/* Describes an absolute axis. */
66struct RawAbsoluteAxisInfo {
67 bool valid; // true if the information is valid, false otherwise
68
69 int32_t minValue; // minimum value
70 int32_t maxValue; // maximum value
71 int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8
72 int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
Jeff Brownb3a2d132011-06-12 18:14:50 -070073 int32_t resolution; // resolution in units per mm or radians per mm
Jeff Brown6d0fec22010-07-23 21:28:06 -070074
Jeff Brown8d608662010-08-30 03:02:23 -070075 inline void clear() {
76 valid = false;
77 minValue = 0;
78 maxValue = 0;
79 flat = 0;
80 fuzz = 0;
Jeff Brownb3a2d132011-06-12 18:14:50 -070081 resolution = 0;
Jeff Brown8d608662010-08-30 03:02:23 -070082 }
Jeff Brown6d0fec22010-07-23 21:28:06 -070083};
84
85/*
Jeff Brownc5ed5912010-07-14 18:48:53 -070086 * Input device classes.
87 */
88enum {
Jeff Browncb1404e2011-01-15 18:14:15 -080089 /* The input device is a keyboard or has buttons. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070090 INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001,
91
92 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
93 INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002,
94
Jeff Brown58a2da82011-01-25 16:02:22 -080095 /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
96 INPUT_DEVICE_CLASS_TOUCH = 0x00000004,
Jeff Brownc5ed5912010-07-14 18:48:53 -070097
Jeff Brown83c09682010-12-23 17:50:18 -080098 /* The input device is a cursor device such as a trackball or mouse. */
99 INPUT_DEVICE_CLASS_CURSOR = 0x00000008,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700100
101 /* The input device is a multi-touch touchscreen. */
Jeff Brown58a2da82011-01-25 16:02:22 -0800102 INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700103
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700104 /* The input device is a directional pad (implies keyboard, has DPAD keys). */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105 INPUT_DEVICE_CLASS_DPAD = 0x00000020,
106
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700107 /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700108 INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040,
109
110 /* The input device has switches. */
111 INPUT_DEVICE_CLASS_SWITCH = 0x00000080,
Jeff Browncb1404e2011-01-15 18:14:15 -0800112
113 /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
114 INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100,
Jeff Brown56194eb2011-03-02 19:23:13 -0800115
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700116 /* The input device is virtual (not a real device, not part of UI configuration). */
117 INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000,
118
Jeff Brown56194eb2011-03-02 19:23:13 -0800119 /* The input device is external (not built-in). */
120 INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700121};
122
123/*
Jeff Brown9ee285a2011-08-31 12:56:34 -0700124 * Gets the class that owns an axis, in cases where multiple classes might claim
125 * the same axis for different purposes.
126 */
127extern uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses);
128
129/*
Jeff Brown46b9ac02010-04-22 18:58:52 -0700130 * Grand Central Station for events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 *
Jeff Brown46b9ac02010-04-22 18:58:52 -0700132 * The event hub aggregates input events received across all known input
133 * devices on the system, including devices that may be emulated by the simulator
134 * environment. In addition, the event hub generates fake input events to indicate
135 * when devices are added or removed.
136 *
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800137 * The event hub provides a stream of input events (via the getEvent function).
Jeff Brown46b9ac02010-04-22 18:58:52 -0700138 * It also supports querying the current actual state of input devices such as identifying
139 * which keys are currently down. Finally, the event hub keeps track of the capabilities of
140 * individual input devices, such as their class and the set of key codes that they support.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700142class EventHubInterface : public virtual RefBase {
143protected:
144 EventHubInterface() { }
145 virtual ~EventHubInterface() { }
146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147public:
Jeff Brown46b9ac02010-04-22 18:58:52 -0700148 // Synthetic raw event type codes produced when devices are added or removed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 enum {
Jeff Brown7342bb92010-10-01 18:55:43 -0700150 // Sent when a device is added.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 DEVICE_ADDED = 0x10000000,
Jeff Brown7342bb92010-10-01 18:55:43 -0700152 // Sent when a device is removed.
153 DEVICE_REMOVED = 0x20000000,
154 // Sent when all added/removed devices from the most recent scan have been reported.
155 // This event is always sent at least once.
156 FINISHED_DEVICE_SCAN = 0x30000000,
Jeff Brownb7198742011-03-18 18:14:26 -0700157
158 FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 };
Jeff Brown46b9ac02010-04-22 18:58:52 -0700160
161 virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0;
162
Jeff Browne38fdfa2012-04-06 14:51:01 -0700163 virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700164
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800165 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0;
166
Jeff Brown6d0fec22010-07-23 21:28:06 -0700167 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
168 RawAbsoluteAxisInfo* outAxisInfo) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700169
Jeff Browncc0c1592011-02-19 05:07:28 -0800170 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0;
171
Jeff Brown80fd47c2011-05-24 01:07:44 -0700172 virtual bool hasInputProperty(int32_t deviceId, int property) const = 0;
173
Jeff Brown49ccac52012-04-11 18:27:33 -0700174 virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700175 int32_t* outKeycode, uint32_t* outFlags) const = 0;
176
Jeff Brown49ccac52012-04-11 18:27:33 -0700177 virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
Jeff Brown3a22fa02011-03-04 13:07:49 -0800178 AxisInfo* outAxisInfo) const = 0;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800179
Jeff Brown1a84fd12011-06-02 01:26:32 -0700180 // Sets devices that are excluded from opening.
181 // This can be used to ignore input devices for sensors.
182 virtual void setExcludedDevices(const Vector<String8>& devices) = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700183
184 /*
Jeff Brownb7198742011-03-18 18:14:26 -0700185 * Wait for events to become available and returns them.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700186 * After returning, the EventHub holds onto a wake lock until the next call to getEvent.
187 * This ensures that the device will not go to sleep while the event is being processed.
188 * If the device needs to remain awake longer than that, then the caller is responsible
189 * for taking care of it (say, by poking the power manager user activity timer).
Jeff Brownaa3855d2011-03-17 01:34:19 -0700190 *
191 * The timeout is advisory only. If the device is asleep, it will not wake just to
192 * service the timeout.
193 *
Jeff Brownb7198742011-03-18 18:14:26 -0700194 * Returns the number of events obtained, or 0 if the timeout expired.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700195 */
Jeff Brownb7198742011-03-18 18:14:26 -0700196 virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700197
198 /*
199 * Query current input state.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700200 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700201 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0;
202 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0;
203 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0;
Jeff Brown2717eff2011-06-30 23:53:07 -0700204 virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
205 int32_t* outValue) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700206
207 /*
208 * Examine key input devices for specific framework keycode support
209 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700210 virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700211 uint8_t* outFlags) const = 0;
Jeff Brownf2f48712010-10-01 17:46:21 -0700212
Jeff Brown49754db2011-07-01 17:37:58 -0700213 virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
Jeff Brown497a92c2010-09-12 17:55:08 -0700214 virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
215 virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0;
216
Jeff Brown90655042010-12-02 13:50:46 -0800217 virtual void getVirtualKeyDefinitions(int32_t deviceId,
218 Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0;
219
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700220 virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0;
Jeff Brown1e08fe92011-11-15 17:48:10 -0800221
Jeff Brown93fa9b32011-06-14 17:09:25 -0700222 /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */
223 virtual void requestReopenDevices() = 0;
224
225 /* Wakes up getEvents() if it is blocked on a read. */
226 virtual void wake() = 0;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700227
Jeff Brown89ef0722011-08-10 16:25:21 -0700228 /* Dump EventHub state to a string. */
Jeff Brownf2f48712010-10-01 17:46:21 -0700229 virtual void dump(String8& dump) = 0;
Jeff Brown89ef0722011-08-10 16:25:21 -0700230
231 /* Called by the heatbeat to ensures that the reader has not deadlocked. */
232 virtual void monitor() = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700233};
234
235class EventHub : public EventHubInterface
236{
237public:
238 EventHub();
239
Jeff Brown46b9ac02010-04-22 18:58:52 -0700240 virtual uint32_t getDeviceClasses(int32_t deviceId) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700241
Jeff Browne38fdfa2012-04-06 14:51:01 -0700242 virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700243
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800244 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const;
245
Jeff Brown6d0fec22010-07-23 21:28:06 -0700246 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
247 RawAbsoluteAxisInfo* outAxisInfo) const;
248
Jeff Browncc0c1592011-02-19 05:07:28 -0800249 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const;
250
Jeff Brown80fd47c2011-05-24 01:07:44 -0700251 virtual bool hasInputProperty(int32_t deviceId, int property) const;
252
Jeff Brown49ccac52012-04-11 18:27:33 -0700253 virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700254 int32_t* outKeycode, uint32_t* outFlags) const;
255
Jeff Brown49ccac52012-04-11 18:27:33 -0700256 virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
Jeff Brown3a22fa02011-03-04 13:07:49 -0800257 AxisInfo* outAxisInfo) const;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800258
Jeff Brown1a84fd12011-06-02 01:26:32 -0700259 virtual void setExcludedDevices(const Vector<String8>& devices);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700260
Jeff Brown6d0fec22010-07-23 21:28:06 -0700261 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const;
262 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const;
263 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const;
Jeff Brown2717eff2011-06-30 23:53:07 -0700264 virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700265
Jeff Brown6d0fec22010-07-23 21:28:06 -0700266 virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
267 const int32_t* keyCodes, uint8_t* outFlags) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268
Jeff Brownb7198742011-03-18 18:14:26 -0700269 virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize);
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400270
Jeff Brown49754db2011-07-01 17:37:58 -0700271 virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700272 virtual bool hasLed(int32_t deviceId, int32_t led) const;
273 virtual void setLedState(int32_t deviceId, int32_t led, bool on);
274
Jeff Brown90655042010-12-02 13:50:46 -0800275 virtual void getVirtualKeyDefinitions(int32_t deviceId,
276 Vector<VirtualKeyDefinition>& outVirtualKeys) const;
277
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700278 virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const;
Jeff Brown1e08fe92011-11-15 17:48:10 -0800279
Jeff Brown93fa9b32011-06-14 17:09:25 -0700280 virtual void requestReopenDevices();
281
282 virtual void wake();
Jeff Brown1a84fd12011-06-02 01:26:32 -0700283
Jeff Brownf2f48712010-10-01 17:46:21 -0700284 virtual void dump(String8& dump);
Jeff Brown89ef0722011-08-10 16:25:21 -0700285 virtual void monitor();
Jeff Brownf2f48712010-10-01 17:46:21 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287protected:
288 virtual ~EventHub();
Jeff Brown93fa9b32011-06-14 17:09:25 -0700289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290private:
Jeff Brown90655042010-12-02 13:50:46 -0800291 struct Device {
292 Device* next;
293
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700294 int fd; // may be -1 if device is virtual
Jeff Brown90655042010-12-02 13:50:46 -0800295 const int32_t id;
296 const String8 path;
297 const InputDeviceIdentifier identifier;
298
299 uint32_t classes;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700300
301 uint8_t keyBitmask[(KEY_MAX + 1) / 8];
302 uint8_t absBitmask[(ABS_MAX + 1) / 8];
303 uint8_t relBitmask[(REL_MAX + 1) / 8];
304 uint8_t swBitmask[(SW_MAX + 1) / 8];
305 uint8_t ledBitmask[(LED_MAX + 1) / 8];
306 uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8];
307
Jeff Brown90655042010-12-02 13:50:46 -0800308 String8 configurationFile;
309 PropertyMap* configuration;
310 VirtualKeyMap* virtualKeyMap;
311 KeyMap keyMap;
312
313 Device(int fd, int32_t id, const String8& path, const InputDeviceIdentifier& identifier);
314 ~Device();
315
316 void close();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700317
318 inline bool isVirtual() const { return fd < 0; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 };
320
Jeff Brown93fa9b32011-06-14 17:09:25 -0700321 status_t openDeviceLocked(const char *devicePath);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700322 void createVirtualKeyboardLocked();
323 void addDeviceLocked(Device* device);
Jeff Brown93fa9b32011-06-14 17:09:25 -0700324
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700325 status_t closeDeviceByPathLocked(const char *devicePath);
Jeff Brown93fa9b32011-06-14 17:09:25 -0700326 void closeDeviceLocked(Device* device);
327 void closeAllDevicesLocked();
328
329 status_t scanDirLocked(const char *dirname);
330 void scanDevicesLocked();
331 status_t readNotifyLocked();
332
Jeff Brown90655042010-12-02 13:50:46 -0800333 Device* getDeviceLocked(int32_t deviceId) const;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700334 Device* getDeviceByPathLocked(const char* devicePath) const;
335
Jeff Brown90655042010-12-02 13:50:46 -0800336 bool hasKeycodeLocked(Device* device, int keycode) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700337
Jeff Brown93fa9b32011-06-14 17:09:25 -0700338 void loadConfigurationLocked(Device* device);
339 status_t loadVirtualKeyMapLocked(Device* device);
340 status_t loadKeyMapLocked(Device* device);
Jeff Brown497a92c2010-09-12 17:55:08 -0700341
Jeff Brown93fa9b32011-06-14 17:09:25 -0700342 bool isExternalDeviceLocked(Device* device);
Jeff Brown56194eb2011-03-02 19:23:13 -0800343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 // Protect all internal state.
Jeff Brown90655042010-12-02 13:50:46 -0800345 mutable Mutex mLock;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400346
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700347 // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none.
Jeff Brown90655042010-12-02 13:50:46 -0800348 // EventHub remaps the built-in keyboard to id 0 externally as required by the API.
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700349 enum {
350 // Must not conflict with any other assigned device ids, including
351 // the virtual keyboard id (-1).
352 NO_BUILT_IN_KEYBOARD = -2,
353 };
Jeff Brown90655042010-12-02 13:50:46 -0800354 int32_t mBuiltInKeyboardId;
355
356 int32_t mNextDeviceId;
357
Jeff Brown93fa9b32011-06-14 17:09:25 -0700358 KeyedVector<int32_t, Device*> mDevices;
Jeff Brown90655042010-12-02 13:50:46 -0800359
360 Device *mOpeningDevices;
361 Device *mClosingDevices;
362
Jeff Brown90655042010-12-02 13:50:46 -0800363 bool mNeedToSendFinishedDeviceScan;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700364 bool mNeedToReopenDevices;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700365 bool mNeedToScanDevices;
366 Vector<String8> mExcludedDevices;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400367
Jeff Brown93fa9b32011-06-14 17:09:25 -0700368 int mEpollFd;
369 int mINotifyFd;
370 int mWakeReadPipeFd;
371 int mWakeWritePipeFd;
Jeff Browncc2e7172010-08-17 16:48:25 -0700372
Jeff Brown93fa9b32011-06-14 17:09:25 -0700373 // Ids used for epoll notifications not associated with devices.
374 static const uint32_t EPOLL_ID_INOTIFY = 0x80000001;
375 static const uint32_t EPOLL_ID_WAKE = 0x80000002;
376
377 // Epoll FD list size hint.
378 static const int EPOLL_SIZE_HINT = 8;
379
380 // Maximum number of signalled FDs to handle at a time.
381 static const int EPOLL_MAX_EVENTS = 16;
382
383 // The array of pending epoll events and the index of the next event to be handled.
384 struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS];
385 size_t mPendingEventCount;
386 size_t mPendingEventIndex;
387 bool mPendingINotify;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388};
389
390}; // namespace android
391
392#endif // _RUNTIME_EVENT_HUB_H