blob: d9c0af2117035f61eae351cee52abb75e3b39569 [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
Dianne Hackbornc968c3a2009-07-14 12:06:54 -070076 status_t scancodeToKeycode(int32_t deviceId, int scancode,
77 int32_t* outKeycode, uint32_t* outFlags) const;
78
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 // special type codes when devices are added/removed.
80 enum {
81 DEVICE_ADDED = 0x10000000,
82 DEVICE_REMOVED = 0x20000000
83 };
84
85 // examine key input devices for specific framework keycode support
86 bool hasKeys(size_t numCodes, int32_t* keyCodes, uint8_t* outFlags);
87
88 virtual bool getEvent(int32_t* outDeviceId, int32_t* outType,
89 int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,
90 int32_t* outValue, nsecs_t* outWhen);
91
92protected:
93 virtual ~EventHub();
94 virtual void onFirstRef();
95
96private:
97 bool openPlatformInput(void);
98 int32_t convertDeviceKey_TI_P2(int code);
99
100 int open_device(const char *device);
101 int close_device(const char *device);
102 int scan_dir(const char *dirname);
103 int read_notify(int nfd);
104
105 status_t mError;
106
107 struct device_t {
108 const int32_t id;
109 const String8 path;
110 String8 name;
111 uint32_t classes;
112 uint8_t* keyBitmask;
113 KeyLayoutMap* layoutMap;
114 String8 keylayoutFilename;
115 device_t* next;
116
117 device_t(int32_t _id, const char* _path);
118 ~device_t();
119 };
120
121 device_t* getDevice(int32_t deviceId) const;
122
123 // Protect all internal state.
124 mutable Mutex mLock;
125
126 bool mHaveFirstKeyboard;
Dianne Hackbornc968c3a2009-07-14 12:06:54 -0700127 int32_t mFirstKeyboardId; // the API is that the built-in keyboard is id 0, so map it
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128
129 struct device_ent {
130 device_t* device;
131 uint32_t seq;
132 };
133 device_ent *mDevicesById;
134 int mNumDevicesById;
135
136 device_t *mOpeningDevices;
137 device_t *mClosingDevices;
138
139 device_t **mDevices;
140 struct pollfd *mFDs;
141 int mFDCount;
142
143 // device ids that report particular switches.
144#ifdef EV_SW
145 int32_t mSwitches[SW_MAX+1];
146#endif
147};
148
149}; // namespace android
150
151#endif // _RUNTIME_EVENT_HUB_H