blob: d62fd7d1af6a853180126a4fb239047ed63e6ba3 [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;
Mike Lockwoodb4411062009-07-16 11:11:18 -040078
79 // exclude a particular device from opening
80 // this can be used to ignore input devices for sensors
81 void addExcludedDevice(const char* deviceName);
82
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 // special type codes when devices are added/removed.
84 enum {
85 DEVICE_ADDED = 0x10000000,
86 DEVICE_REMOVED = 0x20000000
87 };
88
89 // examine key input devices for specific framework keycode support
90 bool hasKeys(size_t numCodes, int32_t* keyCodes, uint8_t* outFlags);
91
92 virtual bool getEvent(int32_t* outDeviceId, int32_t* outType,
93 int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,
94 int32_t* outValue, nsecs_t* outWhen);
Mike Lockwoodb4411062009-07-16 11:11:18 -040095
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096protected:
97 virtual ~EventHub();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098
99private:
100 bool openPlatformInput(void);
101 int32_t convertDeviceKey_TI_P2(int code);
102
103 int open_device(const char *device);
104 int close_device(const char *device);
105 int scan_dir(const char *dirname);
106 int read_notify(int nfd);
107
108 status_t mError;
109
110 struct device_t {
111 const int32_t id;
112 const String8 path;
113 String8 name;
114 uint32_t classes;
115 uint8_t* keyBitmask;
116 KeyLayoutMap* layoutMap;
117 String8 keylayoutFilename;
118 device_t* next;
119
120 device_t(int32_t _id, const char* _path);
121 ~device_t();
122 };
123
124 device_t* getDevice(int32_t deviceId) const;
125
126 // Protect all internal state.
127 mutable Mutex mLock;
128
129 bool mHaveFirstKeyboard;
Dianne Hackbornc968c3a2009-07-14 12:06:54 -0700130 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 -0800131
132 struct device_ent {
133 device_t* device;
134 uint32_t seq;
135 };
136 device_ent *mDevicesById;
137 int mNumDevicesById;
138
139 device_t *mOpeningDevices;
140 device_t *mClosingDevices;
141
142 device_t **mDevices;
143 struct pollfd *mFDs;
144 int mFDCount;
Mike Lockwoodb4411062009-07-16 11:11:18 -0400145
146 bool mOpened;
147 List<String8> mExcludedDevices;
148
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149 // device ids that report particular switches.
150#ifdef EV_SW
151 int32_t mSwitches[SW_MAX+1];
152#endif
153};
154
155}; // namespace android
156
157#endif // _RUNTIME_EVENT_HUB_H