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