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> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
| 35 | #include <linux/input.h> |
| 36 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 37 | /* These constants are not defined in linux/input.h but they are part of the multitouch |
| 38 | * input protocol. */ |
| 39 | |
| 40 | #define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ |
| 41 | #define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */ |
| 42 | #define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ |
| 43 | #define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ |
| 44 | #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ |
| 45 | #define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */ |
| 46 | #define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */ |
| 47 | #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device (finger, pen, ...) */ |
| 48 | #define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ |
| 49 | #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ |
| 50 | #define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ |
| 51 | |
| 52 | #define MT_TOOL_FINGER 0 /* Identifies a finger */ |
| 53 | #define MT_TOOL_PEN 1 /* Identifies a pen */ |
| 54 | |
| 55 | #define SYN_MT_REPORT 2 |
| 56 | |
| 57 | /* Convenience constants. */ |
| 58 | |
| 59 | #define BTN_FIRST 0x100 // first button scancode |
| 60 | #define BTN_LAST 0x15f // last button scancode |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | struct pollfd; |
| 63 | |
| 64 | namespace android { |
| 65 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | /* |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 67 | * A raw event as retrieved from the EventHub. |
| 68 | */ |
| 69 | struct RawEvent { |
| 70 | nsecs_t when; |
| 71 | int32_t deviceId; |
| 72 | int32_t type; |
| 73 | int32_t scanCode; |
| 74 | int32_t keyCode; |
| 75 | int32_t value; |
| 76 | uint32_t flags; |
| 77 | }; |
| 78 | |
| 79 | /* Describes an absolute axis. */ |
| 80 | struct RawAbsoluteAxisInfo { |
| 81 | bool valid; // true if the information is valid, false otherwise |
| 82 | |
| 83 | int32_t minValue; // minimum value |
| 84 | int32_t maxValue; // maximum value |
| 85 | int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8 |
| 86 | int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise |
| 87 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 88 | inline void clear() { |
| 89 | valid = false; |
| 90 | minValue = 0; |
| 91 | maxValue = 0; |
| 92 | flat = 0; |
| 93 | fuzz = 0; |
| 94 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 98 | * Input device classes. |
| 99 | */ |
| 100 | enum { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 101 | /* The input device is a keyboard or has buttons. */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 102 | INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, |
| 103 | |
| 104 | /* The input device is an alpha-numeric keyboard (not just a dial pad). */ |
| 105 | INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, |
| 106 | |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 107 | /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ |
| 108 | INPUT_DEVICE_CLASS_TOUCH = 0x00000004, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 109 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 110 | /* The input device is a cursor device such as a trackball or mouse. */ |
| 111 | INPUT_DEVICE_CLASS_CURSOR = 0x00000008, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 112 | |
| 113 | /* The input device is a multi-touch touchscreen. */ |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 114 | INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 115 | |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 116 | /* The input device is a directional pad (implies keyboard, has DPAD keys). */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 117 | INPUT_DEVICE_CLASS_DPAD = 0x00000020, |
| 118 | |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 119 | /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 120 | INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040, |
| 121 | |
| 122 | /* The input device has switches. */ |
| 123 | INPUT_DEVICE_CLASS_SWITCH = 0x00000080, |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 124 | |
| 125 | /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ |
| 126 | INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100, |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 127 | |
| 128 | /* The input device is external (not built-in). */ |
| 129 | INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /* |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 133 | * Grand Central Station for events. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | * |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 135 | * The event hub aggregates input events received across all known input |
| 136 | * devices on the system, including devices that may be emulated by the simulator |
| 137 | * environment. In addition, the event hub generates fake input events to indicate |
| 138 | * when devices are added or removed. |
| 139 | * |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 140 | * The event hub provides a stream of input events (via the getEvent function). |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 141 | * It also supports querying the current actual state of input devices such as identifying |
| 142 | * which keys are currently down. Finally, the event hub keeps track of the capabilities of |
| 143 | * 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] | 144 | */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 145 | class EventHubInterface : public virtual RefBase { |
| 146 | protected: |
| 147 | EventHubInterface() { } |
| 148 | virtual ~EventHubInterface() { } |
| 149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | public: |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 151 | // 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] | 152 | enum { |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 153 | // Sent when a device is added. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | DEVICE_ADDED = 0x10000000, |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 155 | // Sent when a device is removed. |
| 156 | DEVICE_REMOVED = 0x20000000, |
| 157 | // Sent when all added/removed devices from the most recent scan have been reported. |
| 158 | // This event is always sent at least once. |
| 159 | FINISHED_DEVICE_SCAN = 0x30000000, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | }; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 161 | |
| 162 | virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0; |
| 163 | |
| 164 | virtual String8 getDeviceName(int32_t deviceId) const = 0; |
| 165 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 166 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0; |
| 167 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 168 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 169 | RawAbsoluteAxisInfo* outAxisInfo) const = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 170 | |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 171 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0; |
| 172 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 173 | virtual status_t mapKey(int32_t deviceId, int scancode, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 174 | int32_t* outKeycode, uint32_t* outFlags) const = 0; |
| 175 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 176 | virtual status_t mapAxis(int32_t deviceId, int scancode, |
| 177 | int32_t* outAxis) const = 0; |
| 178 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 179 | // exclude a particular device from opening |
| 180 | // this can be used to ignore input devices for sensors |
| 181 | virtual void addExcludedDevice(const char* deviceName) = 0; |
| 182 | |
| 183 | /* |
| 184 | * Wait for the next event to become available and return it. |
| 185 | * After returning, the EventHub holds onto a wake lock until the next call to getEvent. |
| 186 | * This ensures that the device will not go to sleep while the event is being processed. |
| 187 | * If the device needs to remain awake longer than that, then the caller is responsible |
| 188 | * for taking care of it (say, by poking the power manager user activity timer). |
| 189 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 190 | virtual bool getEvent(RawEvent* outEvent) = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * Query current input state. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 194 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 195 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0; |
| 196 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0; |
| 197 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 198 | |
| 199 | /* |
| 200 | * Examine key input devices for specific framework keycode support |
| 201 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 202 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 203 | uint8_t* outFlags) const = 0; |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 204 | |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 205 | virtual bool hasLed(int32_t deviceId, int32_t led) const = 0; |
| 206 | virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0; |
| 207 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 208 | virtual void getVirtualKeyDefinitions(int32_t deviceId, |
| 209 | Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; |
| 210 | |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 211 | virtual void dump(String8& dump) = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | class EventHub : public EventHubInterface |
| 215 | { |
| 216 | public: |
| 217 | EventHub(); |
| 218 | |
| 219 | status_t errorCheck() const; |
| 220 | |
| 221 | virtual uint32_t getDeviceClasses(int32_t deviceId) const; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 222 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 223 | virtual String8 getDeviceName(int32_t deviceId) const; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 224 | |
Jeff Brown | 47e6b1b | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 225 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const; |
| 226 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 227 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 228 | RawAbsoluteAxisInfo* outAxisInfo) const; |
| 229 | |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 230 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const; |
| 231 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 232 | virtual status_t mapKey(int32_t deviceId, int scancode, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 233 | int32_t* outKeycode, uint32_t* outFlags) const; |
| 234 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 235 | virtual status_t mapAxis(int32_t deviceId, int scancode, |
| 236 | int32_t* outAxis) const; |
| 237 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 238 | virtual void addExcludedDevice(const char* deviceName); |
| 239 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 240 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const; |
| 241 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const; |
| 242 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 243 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 244 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, |
| 245 | const int32_t* keyCodes, uint8_t* outFlags) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 247 | virtual bool getEvent(RawEvent* outEvent); |
Mike Lockwood | 1d9dfc5 | 2009-07-16 11:11:18 -0400 | [diff] [blame] | 248 | |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 249 | virtual bool hasLed(int32_t deviceId, int32_t led) const; |
| 250 | virtual void setLedState(int32_t deviceId, int32_t led, bool on); |
| 251 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 252 | virtual void getVirtualKeyDefinitions(int32_t deviceId, |
| 253 | Vector<VirtualKeyDefinition>& outVirtualKeys) const; |
| 254 | |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 255 | virtual void dump(String8& dump); |
| 256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | protected: |
| 258 | virtual ~EventHub(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | |
| 260 | private: |
| 261 | bool openPlatformInput(void); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 263 | int openDevice(const char *devicePath); |
| 264 | int closeDevice(const char *devicePath); |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 265 | int closeDeviceAtIndexLocked(int index); |
Jeff Brown | 7342bb9 | 2010-10-01 18:55:43 -0700 | [diff] [blame] | 266 | int scanDir(const char *dirname); |
| 267 | int readNotify(int nfd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | |
| 269 | status_t mError; |
| 270 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 271 | struct Device { |
| 272 | Device* next; |
| 273 | |
| 274 | int fd; |
| 275 | const int32_t id; |
| 276 | const String8 path; |
| 277 | const InputDeviceIdentifier identifier; |
| 278 | |
| 279 | uint32_t classes; |
| 280 | uint8_t* keyBitmask; |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 281 | uint8_t* relBitmask; |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 282 | String8 configurationFile; |
| 283 | PropertyMap* configuration; |
| 284 | VirtualKeyMap* virtualKeyMap; |
| 285 | KeyMap keyMap; |
| 286 | |
| 287 | Device(int fd, int32_t id, const String8& path, const InputDeviceIdentifier& identifier); |
| 288 | ~Device(); |
| 289 | |
| 290 | void close(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | }; |
| 292 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 293 | Device* getDeviceLocked(int32_t deviceId) const; |
| 294 | bool hasKeycodeLocked(Device* device, int keycode) const; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 295 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 296 | int32_t getScanCodeStateLocked(Device* device, int32_t scanCode) const; |
| 297 | int32_t getKeyCodeStateLocked(Device* device, int32_t keyCode) const; |
| 298 | int32_t getSwitchStateLocked(Device* device, int32_t sw) const; |
| 299 | bool markSupportedKeyCodesLocked(Device* device, size_t numCodes, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 300 | const int32_t* keyCodes, uint8_t* outFlags) const; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 301 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 302 | void loadConfiguration(Device* device); |
| 303 | status_t loadVirtualKeyMap(Device* device); |
| 304 | status_t loadKeyMap(Device* device); |
| 305 | void setKeyboardProperties(Device* device, bool builtInKeyboard); |
| 306 | void clearKeyboardProperties(Device* device, bool builtInKeyboard); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 307 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 308 | bool isExternalDevice(Device* device); |
| 309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | // Protect all internal state. |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 311 | mutable Mutex mLock; |
Mike Lockwood | 1d9dfc5 | 2009-07-16 11:11:18 -0400 | [diff] [blame] | 312 | |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 313 | // The actual id of the built-in keyboard, or -1 if none. |
| 314 | // EventHub remaps the built-in keyboard to id 0 externally as required by the API. |
| 315 | int32_t mBuiltInKeyboardId; |
| 316 | |
| 317 | int32_t mNextDeviceId; |
| 318 | |
| 319 | // Parallel arrays of fds and devices. |
| 320 | // First index is reserved for inotify. |
| 321 | Vector<struct pollfd> mFds; |
| 322 | Vector<Device*> mDevices; |
| 323 | |
| 324 | Device *mOpeningDevices; |
| 325 | Device *mClosingDevices; |
| 326 | |
| 327 | bool mOpened; |
| 328 | bool mNeedToSendFinishedDeviceScan; |
| 329 | List<String8> mExcludedDevices; |
Mike Lockwood | 1d9dfc5 | 2009-07-16 11:11:18 -0400 | [diff] [blame] | 330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | // device ids that report particular switches. |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 332 | int32_t mSwitches[SW_MAX + 1]; |
Jeff Brown | cc2e717 | 2010-08-17 16:48:25 -0700 | [diff] [blame] | 333 | |
| 334 | static const int INPUT_BUFFER_SIZE = 64; |
| 335 | struct input_event mInputBufferData[INPUT_BUFFER_SIZE]; |
Jeff Brown | 9065504 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 336 | size_t mInputBufferIndex; |
| 337 | size_t mInputBufferCount; |
| 338 | size_t mInputFdIndex; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | }; // namespace android |
| 342 | |
| 343 | #endif // _RUNTIME_EVENT_HUB_H |