The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 21 | #include <ui/Input.h> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 22 | #include <ui/Keyboard.h> |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 23 | #include <ui/KeyLayoutMap.h> |
| 24 | #include <ui/KeyCharacterMap.h> |
| 25 | #include <ui/VirtualKeyMap.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <utils/String8.h> |
| 27 | #include <utils/threads.h> |
Mathias Agopian | 3b4062e | 2009-05-31 19:13:00 -0700 | [diff] [blame] | 28 | #include <utils/Log.h> |
| 29 | #include <utils/threads.h> |
| 30 | #include <utils/List.h> |
| 31 | #include <utils/Errors.h> |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 32 | #include <utils/PropertyMap.h> |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 33 | #include <utils/Vector.h> |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 34 | #include <utils/KeyedVector.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | #include <linux/input.h> |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 37 | #include <sys/epoll.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 39 | /* Convenience constants. */ |
| 40 | |
| 41 | #define BTN_FIRST 0x100 // first button scancode |
| 42 | #define BTN_LAST 0x15f // last button scancode |
| 43 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | namespace android { |
| 45 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | /* |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 47 | * A raw event as retrieved from the EventHub. |
| 48 | */ |
| 49 | struct RawEvent { |
| 50 | nsecs_t when; |
| 51 | int32_t deviceId; |
| 52 | int32_t type; |
| 53 | int32_t scanCode; |
| 54 | int32_t keyCode; |
| 55 | int32_t value; |
| 56 | uint32_t flags; |
| 57 | }; |
| 58 | |
| 59 | /* Describes an absolute axis. */ |
| 60 | struct RawAbsoluteAxisInfo { |
| 61 | bool valid; // true if the information is valid, false otherwise |
| 62 | |
| 63 | int32_t minValue; // minimum value |
| 64 | int32_t maxValue; // maximum value |
| 65 | int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8 |
| 66 | int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise |
Jeff Brown | b3a2d13 | 2011-06-12 18:14:50 -0700 | [diff] [blame] | 67 | int32_t resolution; // resolution in units per mm or radians per mm |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 68 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 69 | inline void clear() { |
| 70 | valid = false; |
| 71 | minValue = 0; |
| 72 | maxValue = 0; |
| 73 | flat = 0; |
| 74 | fuzz = 0; |
Jeff Brown | b3a2d13 | 2011-06-12 18:14:50 -0700 | [diff] [blame] | 75 | resolution = 0; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 76 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 80 | * Input device classes. |
| 81 | */ |
| 82 | enum { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 83 | /* The input device is a keyboard or has buttons. */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 84 | INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, |
| 85 | |
| 86 | /* The input device is an alpha-numeric keyboard (not just a dial pad). */ |
| 87 | INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, |
| 88 | |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 89 | /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ |
| 90 | INPUT_DEVICE_CLASS_TOUCH = 0x00000004, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 91 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 92 | /* The input device is a cursor device such as a trackball or mouse. */ |
| 93 | INPUT_DEVICE_CLASS_CURSOR = 0x00000008, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 94 | |
| 95 | /* The input device is a multi-touch touchscreen. */ |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 96 | INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 97 | |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 98 | /* The input device is a directional pad (implies keyboard, has DPAD keys). */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 99 | INPUT_DEVICE_CLASS_DPAD = 0x00000020, |
| 100 | |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 101 | /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 102 | INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040, |
| 103 | |
| 104 | /* The input device has switches. */ |
| 105 | INPUT_DEVICE_CLASS_SWITCH = 0x00000080, |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 106 | |
| 107 | /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ |
| 108 | INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100, |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 109 | |
| 110 | /* The input device is external (not built-in). */ |
| 111 | INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /* |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 115 | * Grand Central Station for events. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | * |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 117 | * The event hub aggregates input events received across all known input |
| 118 | * devices on the system, including devices that may be emulated by the simulator |
| 119 | * environment. In addition, the event hub generates fake input events to indicate |
| 120 | * when devices are added or removed. |
| 121 | * |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 122 | * The event hub provides a stream of input events (via the getEvent function). |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 123 | * It also supports querying the current actual state of input devices such as identifying |
| 124 | * which keys are currently down. Finally, the event hub keeps track of the capabilities of |
| 125 | * individual input devices, such as their class and the set of key codes that they support. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | */ |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 127 | class EventHubInterface : public virtual RefBase { |
| 128 | protected: |
| 129 | EventHubInterface() { } |
| 130 | virtual ~EventHubInterface() { } |
| 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | public: |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 133 | // Synthetic raw event type codes produced when devices are added or removed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | enum { |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 135 | // Sent when a device is added. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | DEVICE_ADDED = 0x10000000, |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 137 | // Sent when a device is removed. |
| 138 | DEVICE_REMOVED = 0x20000000, |
| 139 | // Sent when all added/removed devices from the most recent scan have been reported. |
| 140 | // This event is always sent at least once. |
| 141 | FINISHED_DEVICE_SCAN = 0x30000000, |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 142 | |
| 143 | FIRST_SYNTHETIC_EVENT = DEVICE_ADDED, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | }; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 145 | |
| 146 | virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0; |
| 147 | |
| 148 | virtual String8 getDeviceName(int32_t deviceId) const = 0; |
| 149 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 150 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0; |
| 151 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 152 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 153 | RawAbsoluteAxisInfo* outAxisInfo) const = 0; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 154 | |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 155 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0; |
| 156 | |
Jeff Brown | 80fd47c | 2011-05-24 01:07:44 -0700 | [diff] [blame] | 157 | virtual bool hasInputProperty(int32_t deviceId, int property) const = 0; |
| 158 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 159 | virtual status_t mapKey(int32_t deviceId, int scancode, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 160 | int32_t* outKeycode, uint32_t* outFlags) const = 0; |
| 161 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 162 | virtual status_t mapAxis(int32_t deviceId, int scancode, |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 163 | AxisInfo* outAxisInfo) const = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 164 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 165 | // Sets devices that are excluded from opening. |
| 166 | // This can be used to ignore input devices for sensors. |
| 167 | virtual void setExcludedDevices(const Vector<String8>& devices) = 0; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 168 | |
| 169 | /* |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 170 | * Wait for events to become available and returns them. |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 171 | * After returning, the EventHub holds onto a wake lock until the next call to getEvent. |
| 172 | * This ensures that the device will not go to sleep while the event is being processed. |
| 173 | * If the device needs to remain awake longer than that, then the caller is responsible |
| 174 | * for taking care of it (say, by poking the power manager user activity timer). |
Jeff Brown | aa3855d | 2011-03-17 01:34:19 -0700 | [diff] [blame] | 175 | * |
| 176 | * The timeout is advisory only. If the device is asleep, it will not wake just to |
| 177 | * service the timeout. |
| 178 | * |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 179 | * Returns the number of events obtained, or 0 if the timeout expired. |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 180 | */ |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 181 | virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 182 | |
| 183 | /* |
| 184 | * Query current input state. |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 185 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 186 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0; |
| 187 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0; |
| 188 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0; |
Jeff Brown | 2717eff | 2011-06-30 23:53:07 -0700 | [diff] [blame] | 189 | virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
| 190 | int32_t* outValue) const = 0; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * Examine key input devices for specific framework keycode support |
| 194 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 195 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 196 | uint8_t* outFlags) const = 0; |
Jeff Brown | f2f48718 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 197 | |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 198 | virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 199 | virtual bool hasLed(int32_t deviceId, int32_t led) const = 0; |
| 200 | virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0; |
| 201 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 202 | virtual void getVirtualKeyDefinitions(int32_t deviceId, |
| 203 | Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; |
| 204 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 205 | /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */ |
| 206 | virtual void requestReopenDevices() = 0; |
| 207 | |
| 208 | /* Wakes up getEvents() if it is blocked on a read. */ |
| 209 | virtual void wake() = 0; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 210 | |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame^] | 211 | /* Dump EventHub state to a string. */ |
Jeff Brown | f2f48718 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 212 | virtual void dump(String8& dump) = 0; |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame^] | 213 | |
| 214 | /* Called by the heatbeat to ensures that the reader has not deadlocked. */ |
| 215 | virtual void monitor() = 0; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | class EventHub : public EventHubInterface |
| 219 | { |
| 220 | public: |
| 221 | EventHub(); |
| 222 | |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 223 | virtual uint32_t getDeviceClasses(int32_t deviceId) const; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 224 | |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 225 | virtual String8 getDeviceName(int32_t deviceId) const; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 226 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 227 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const; |
| 228 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 229 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 230 | RawAbsoluteAxisInfo* outAxisInfo) const; |
| 231 | |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 232 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const; |
| 233 | |
Jeff Brown | 80fd47c | 2011-05-24 01:07:44 -0700 | [diff] [blame] | 234 | virtual bool hasInputProperty(int32_t deviceId, int property) const; |
| 235 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 236 | virtual status_t mapKey(int32_t deviceId, int scancode, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 237 | int32_t* outKeycode, uint32_t* outFlags) const; |
| 238 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 239 | virtual status_t mapAxis(int32_t deviceId, int scancode, |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 240 | AxisInfo* outAxisInfo) const; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 241 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 242 | virtual void setExcludedDevices(const Vector<String8>& devices); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 243 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 244 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const; |
| 245 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const; |
| 246 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const; |
Jeff Brown | 2717eff | 2011-06-30 23:53:07 -0700 | [diff] [blame] | 247 | virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 248 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 249 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, |
| 250 | const int32_t* keyCodes, uint8_t* outFlags) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 252 | virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize); |
Mike Lockwood | 1d9dfc5 | 2009-07-16 11:11:18 -0400 | [diff] [blame] | 253 | |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 254 | virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 255 | virtual bool hasLed(int32_t deviceId, int32_t led) const; |
| 256 | virtual void setLedState(int32_t deviceId, int32_t led, bool on); |
| 257 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 258 | virtual void getVirtualKeyDefinitions(int32_t deviceId, |
| 259 | Vector<VirtualKeyDefinition>& outVirtualKeys) const; |
| 260 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 261 | virtual void requestReopenDevices(); |
| 262 | |
| 263 | virtual void wake(); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 264 | |
Jeff Brown | f2f48718 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 265 | virtual void dump(String8& dump); |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame^] | 266 | virtual void monitor(); |
Jeff Brown | f2f48718 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | protected: |
| 269 | virtual ~EventHub(); |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | private: |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 272 | struct Device { |
| 273 | Device* next; |
| 274 | |
| 275 | int fd; |
| 276 | const int32_t id; |
| 277 | const String8 path; |
| 278 | const InputDeviceIdentifier identifier; |
| 279 | |
| 280 | uint32_t classes; |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 281 | |
| 282 | uint8_t keyBitmask[(KEY_MAX + 1) / 8]; |
| 283 | uint8_t absBitmask[(ABS_MAX + 1) / 8]; |
| 284 | uint8_t relBitmask[(REL_MAX + 1) / 8]; |
| 285 | uint8_t swBitmask[(SW_MAX + 1) / 8]; |
| 286 | uint8_t ledBitmask[(LED_MAX + 1) / 8]; |
| 287 | uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8]; |
| 288 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 289 | String8 configurationFile; |
| 290 | PropertyMap* configuration; |
| 291 | VirtualKeyMap* virtualKeyMap; |
| 292 | KeyMap keyMap; |
| 293 | |
| 294 | Device(int fd, int32_t id, const String8& path, const InputDeviceIdentifier& identifier); |
| 295 | ~Device(); |
| 296 | |
| 297 | void close(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | }; |
| 299 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 300 | status_t openDeviceLocked(const char *devicePath); |
| 301 | status_t closeDeviceByPathLocked(const char *devicePath); |
| 302 | |
| 303 | void closeDeviceLocked(Device* device); |
| 304 | void closeAllDevicesLocked(); |
| 305 | |
| 306 | status_t scanDirLocked(const char *dirname); |
| 307 | void scanDevicesLocked(); |
| 308 | status_t readNotifyLocked(); |
| 309 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 310 | Device* getDeviceLocked(int32_t deviceId) const; |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 311 | Device* getDeviceByPathLocked(const char* devicePath) const; |
| 312 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 313 | bool hasKeycodeLocked(Device* device, int keycode) const; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 314 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 315 | void loadConfigurationLocked(Device* device); |
| 316 | status_t loadVirtualKeyMapLocked(Device* device); |
| 317 | status_t loadKeyMapLocked(Device* device); |
| 318 | void setKeyboardPropertiesLocked(Device* device, bool builtInKeyboard); |
| 319 | void clearKeyboardPropertiesLocked(Device* device, bool builtInKeyboard); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 320 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 321 | bool isExternalDeviceLocked(Device* device); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | // Protect all internal state. |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 324 | mutable Mutex mLock; |
Mike Lockwood | 1d9dfc5 | 2009-07-16 11:11:18 -0400 | [diff] [blame] | 325 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 326 | // The actual id of the built-in keyboard, or -1 if none. |
| 327 | // EventHub remaps the built-in keyboard to id 0 externally as required by the API. |
| 328 | int32_t mBuiltInKeyboardId; |
| 329 | |
| 330 | int32_t mNextDeviceId; |
| 331 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 332 | KeyedVector<int32_t, Device*> mDevices; |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 333 | |
| 334 | Device *mOpeningDevices; |
| 335 | Device *mClosingDevices; |
| 336 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 337 | bool mNeedToSendFinishedDeviceScan; |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 338 | bool mNeedToReopenDevices; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 339 | bool mNeedToScanDevices; |
| 340 | Vector<String8> mExcludedDevices; |
Mike Lockwood | 1d9dfc5 | 2009-07-16 11:11:18 -0400 | [diff] [blame] | 341 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 342 | int mEpollFd; |
| 343 | int mINotifyFd; |
| 344 | int mWakeReadPipeFd; |
| 345 | int mWakeWritePipeFd; |
Jeff Brown | cc2e717 | 2010-08-17 16:48:25 -0700 | [diff] [blame] | 346 | |
Jeff Brown | 93fa9b3 | 2011-06-14 17:09:25 -0700 | [diff] [blame] | 347 | // Ids used for epoll notifications not associated with devices. |
| 348 | static const uint32_t EPOLL_ID_INOTIFY = 0x80000001; |
| 349 | static const uint32_t EPOLL_ID_WAKE = 0x80000002; |
| 350 | |
| 351 | // Epoll FD list size hint. |
| 352 | static const int EPOLL_SIZE_HINT = 8; |
| 353 | |
| 354 | // Maximum number of signalled FDs to handle at a time. |
| 355 | static const int EPOLL_MAX_EVENTS = 16; |
| 356 | |
| 357 | // The array of pending epoll events and the index of the next event to be handled. |
| 358 | struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS]; |
| 359 | size_t mPendingEventCount; |
| 360 | size_t mPendingEventIndex; |
| 361 | bool mPendingINotify; |
Jeff Brown | b719874 | 2011-03-18 18:14:26 -0700 | [diff] [blame] | 362 | |
| 363 | // Set to the number of CPUs. |
| 364 | int32_t mNumCpus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | }; // namespace android |
| 368 | |
| 369 | #endif // _RUNTIME_EVENT_HUB_H |