The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [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 | |
| 21 | #include <utils/String8.h> |
| 22 | #include <utils/threads.h> |
| 23 | #include <utils.h> |
| 24 | |
| 25 | #include <linux/input.h> |
| 26 | |
| 27 | struct pollfd; |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | class KeyLayoutMap; |
| 32 | |
| 33 | /* |
| 34 | * Grand Central Station for events. With a single call to waitEvent() |
| 35 | * you can wait for: |
| 36 | * - input events from the keypad of a real device |
| 37 | * - input events and meta-events (e.g. "quit") from the simulator |
| 38 | * - synthetic events from the runtime (e.g. "URL fetch completed") |
| 39 | * - real or forged "vsync" events |
| 40 | * |
| 41 | * Do not instantiate this class. Instead, call startUp(). |
| 42 | */ |
| 43 | class EventHub : public RefBase |
| 44 | { |
| 45 | public: |
| 46 | EventHub(); |
| 47 | |
| 48 | status_t errorCheck() const; |
| 49 | |
| 50 | // bit fields for classes of devices. |
| 51 | enum { |
| 52 | CLASS_KEYBOARD = 0x00000001, |
| 53 | CLASS_TOUCHSCREEN = 0x00000002, |
| 54 | CLASS_TRACKBALL = 0x00000004 |
| 55 | }; |
| 56 | uint32_t getDeviceClasses(int32_t deviceId) const; |
| 57 | |
| 58 | String8 getDeviceName(int32_t deviceId) const; |
| 59 | |
| 60 | int getAbsoluteInfo(int32_t deviceId, int axis, int *outMinValue, |
| 61 | int* outMaxValue, int* outFlat, int* outFuzz) const; |
| 62 | |
| 63 | int getSwitchState(int sw) const; |
| 64 | int getSwitchState(int32_t deviceId, int sw) const; |
| 65 | |
| 66 | int getScancodeState(int key) const; |
| 67 | int getScancodeState(int32_t deviceId, int key) const; |
| 68 | |
| 69 | int getKeycodeState(int key) const; |
| 70 | int getKeycodeState(int32_t deviceId, int key) const; |
| 71 | |
| 72 | // special type codes when devices are added/removed. |
| 73 | enum { |
| 74 | DEVICE_ADDED = 0x10000000, |
| 75 | DEVICE_REMOVED = 0x20000000 |
| 76 | }; |
| 77 | |
| 78 | virtual bool getEvent(int32_t* outDeviceId, int32_t* outType, |
| 79 | int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags, |
| 80 | int32_t* outValue, nsecs_t* outWhen); |
| 81 | |
| 82 | protected: |
| 83 | virtual ~EventHub(); |
| 84 | virtual void onFirstRef(); |
| 85 | |
| 86 | private: |
| 87 | bool openPlatformInput(void); |
| 88 | int32_t convertDeviceKey_TI_P2(int code); |
| 89 | |
| 90 | int open_device(const char *device); |
| 91 | int close_device(const char *device); |
| 92 | int scan_dir(const char *dirname); |
| 93 | int read_notify(int nfd); |
| 94 | |
| 95 | status_t mError; |
| 96 | |
| 97 | struct device_t { |
| 98 | const int32_t id; |
| 99 | const String8 path; |
| 100 | String8 name; |
| 101 | uint32_t classes; |
| 102 | KeyLayoutMap* layoutMap; |
| 103 | String8 keylayoutFilename; |
| 104 | device_t* next; |
| 105 | |
| 106 | device_t(int32_t _id, const char* _path); |
| 107 | ~device_t(); |
| 108 | }; |
| 109 | |
| 110 | device_t* getDevice(int32_t deviceId) const; |
| 111 | |
| 112 | // Protect all internal state. |
| 113 | mutable Mutex mLock; |
| 114 | |
| 115 | bool mHaveFirstKeyboard; |
| 116 | int32_t mFirstKeyboardId; // the API is that the build in keyboard is id 0, so map it |
| 117 | |
| 118 | struct device_ent { |
| 119 | device_t* device; |
| 120 | uint32_t seq; |
| 121 | }; |
| 122 | device_ent *mDevicesById; |
| 123 | int mNumDevicesById; |
| 124 | |
| 125 | device_t *mOpeningDevices; |
| 126 | device_t *mClosingDevices; |
| 127 | |
| 128 | device_t **mDevices; |
| 129 | struct pollfd *mFDs; |
| 130 | int mFDCount; |
| 131 | |
| 132 | // device ids that report particular switches. |
| 133 | #ifdef EV_SW |
| 134 | int32_t mSwitches[SW_MAX+1]; |
| 135 | #endif |
| 136 | |
| 137 | KeyLayoutMap * mLayoutMap; |
| 138 | }; |
| 139 | |
| 140 | }; // namespace android |
| 141 | |
| 142 | #endif // _RUNTIME_EVENT_HUB_H |