blob: 017c145bfb4c6768a6fc04b3f9d1148869b70024 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
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
27struct pollfd;
28
29namespace android {
30
31class 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 */
43class EventHub : public RefBase
44{
45public:
46 EventHub();
47
48 status_t errorCheck() const;
49
50 // bit fields for classes of devices.
51 enum {
52 CLASS_KEYBOARD = 0x00000001,
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080053 CLASS_ALPHAKEY = 0x00000002,
54 CLASS_TOUCHSCREEN = 0x00000004,
55 CLASS_TRACKBALL = 0x00000008
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070056 };
57 uint32_t getDeviceClasses(int32_t deviceId) const;
58
59 String8 getDeviceName(int32_t deviceId) const;
60
61 int getAbsoluteInfo(int32_t deviceId, int axis, int *outMinValue,
62 int* outMaxValue, int* outFlat, int* outFuzz) const;
63
64 int getSwitchState(int sw) const;
65 int getSwitchState(int32_t deviceId, int sw) const;
66
67 int getScancodeState(int key) const;
68 int getScancodeState(int32_t deviceId, int key) const;
69
70 int getKeycodeState(int key) const;
71 int getKeycodeState(int32_t deviceId, int key) const;
72
73 // special type codes when devices are added/removed.
74 enum {
75 DEVICE_ADDED = 0x10000000,
76 DEVICE_REMOVED = 0x20000000
77 };
78
79 virtual bool getEvent(int32_t* outDeviceId, int32_t* outType,
80 int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,
81 int32_t* outValue, nsecs_t* outWhen);
82
83protected:
84 virtual ~EventHub();
85 virtual void onFirstRef();
86
87private:
88 bool openPlatformInput(void);
89 int32_t convertDeviceKey_TI_P2(int code);
90
91 int open_device(const char *device);
92 int close_device(const char *device);
93 int scan_dir(const char *dirname);
94 int read_notify(int nfd);
95
96 status_t mError;
97
98 struct device_t {
99 const int32_t id;
100 const String8 path;
101 String8 name;
102 uint32_t classes;
103 KeyLayoutMap* layoutMap;
104 String8 keylayoutFilename;
105 device_t* next;
106
107 device_t(int32_t _id, const char* _path);
108 ~device_t();
109 };
110
111 device_t* getDevice(int32_t deviceId) const;
112
113 // Protect all internal state.
114 mutable Mutex mLock;
115
116 bool mHaveFirstKeyboard;
117 int32_t mFirstKeyboardId; // the API is that the build in keyboard is id 0, so map it
118
119 struct device_ent {
120 device_t* device;
121 uint32_t seq;
122 };
123 device_ent *mDevicesById;
124 int mNumDevicesById;
125
126 device_t *mOpeningDevices;
127 device_t *mClosingDevices;
128
129 device_t **mDevices;
130 struct pollfd *mFDs;
131 int mFDCount;
132
133 // device ids that report particular switches.
134#ifdef EV_SW
135 int32_t mSwitches[SW_MAX+1];
136#endif
137
138 KeyLayoutMap * mLayoutMap;
139};
140
141}; // namespace android
142
143#endif // _RUNTIME_EVENT_HUB_H