Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | #define LOG_TAG "input" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include <android/input.h> |
| 21 | #include <ui/Input.h> |
| 22 | #include <ui/InputTransport.h> |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 23 | #include <utils/PollLoop.h> |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame^] | 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/Vector.h> |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 26 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 27 | #include <android_runtime/android_app_NativeActivity.h> |
| 28 | |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 29 | #include <poll.h> |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame^] | 30 | #include <errno.h> |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 31 | |
| 32 | using android::InputEvent; |
| 33 | using android::KeyEvent; |
| 34 | using android::MotionEvent; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame^] | 35 | using android::InputDeviceInfo; |
| 36 | using android::InputDeviceProxy; |
| 37 | using android::sp; |
| 38 | using android::Vector; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 39 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 40 | int32_t AInputEvent_getType(const AInputEvent* event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 41 | return static_cast<const InputEvent*>(event)->getType(); |
| 42 | } |
| 43 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 44 | int32_t AInputEvent_getDeviceId(const AInputEvent* event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 45 | return static_cast<const InputEvent*>(event)->getDeviceId(); |
| 46 | } |
| 47 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 48 | int32_t AInputEvent_getSource(const AInputEvent* event) { |
| 49 | return static_cast<const InputEvent*>(event)->getSource(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 52 | int32_t AKeyEvent_getAction(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 53 | return static_cast<const KeyEvent*>(key_event)->getAction(); |
| 54 | } |
| 55 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 56 | int32_t AKeyEvent_getFlags(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 57 | return static_cast<const KeyEvent*>(key_event)->getFlags(); |
| 58 | } |
| 59 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 60 | int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 61 | return static_cast<const KeyEvent*>(key_event)->getKeyCode(); |
| 62 | } |
| 63 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 64 | int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 65 | return static_cast<const KeyEvent*>(key_event)->getScanCode(); |
| 66 | } |
| 67 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 68 | int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 69 | return static_cast<const KeyEvent*>(key_event)->getMetaState(); |
| 70 | } |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 71 | int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 72 | return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); |
| 73 | } |
| 74 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 75 | int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 76 | return static_cast<const KeyEvent*>(key_event)->getDownTime(); |
| 77 | } |
| 78 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 79 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 80 | int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 81 | return static_cast<const KeyEvent*>(key_event)->getEventTime(); |
| 82 | } |
| 83 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 84 | int32_t AMotionEvent_getAction(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 85 | return static_cast<const MotionEvent*>(motion_event)->getAction(); |
| 86 | } |
| 87 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 88 | int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 89 | return static_cast<const MotionEvent*>(motion_event)->getMetaState(); |
| 90 | } |
| 91 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 92 | int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 93 | return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); |
| 94 | } |
| 95 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 96 | int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 97 | return static_cast<const MotionEvent*>(motion_event)->getDownTime(); |
| 98 | } |
| 99 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 100 | int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 101 | return static_cast<const MotionEvent*>(motion_event)->getEventTime(); |
| 102 | } |
| 103 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 104 | float AMotionEvent_getXOffset(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 105 | return static_cast<const MotionEvent*>(motion_event)->getXOffset(); |
| 106 | } |
| 107 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 108 | float AMotionEvent_getYOffset(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 109 | return static_cast<const MotionEvent*>(motion_event)->getYOffset(); |
| 110 | } |
| 111 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 112 | float AMotionEvent_getXPrecision(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 113 | return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); |
| 114 | } |
| 115 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 116 | float AMotionEvent_getYPrecision(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 117 | return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); |
| 118 | } |
| 119 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 120 | size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 121 | return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); |
| 122 | } |
| 123 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 124 | int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 125 | return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); |
| 126 | } |
| 127 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 128 | float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 129 | return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); |
| 130 | } |
| 131 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 132 | float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 133 | return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); |
| 134 | } |
| 135 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 136 | float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 137 | return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); |
| 138 | } |
| 139 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 140 | float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 141 | return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); |
| 142 | } |
| 143 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 144 | float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 145 | return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); |
| 146 | } |
| 147 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 148 | float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 149 | return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); |
| 150 | } |
| 151 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 152 | float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index) { |
| 153 | return static_cast<const MotionEvent*>(motion_event)->getTouchMajor(pointer_index); |
| 154 | } |
| 155 | |
| 156 | float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index) { |
| 157 | return static_cast<const MotionEvent*>(motion_event)->getTouchMinor(pointer_index); |
| 158 | } |
| 159 | |
| 160 | float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index) { |
| 161 | return static_cast<const MotionEvent*>(motion_event)->getToolMajor(pointer_index); |
| 162 | } |
| 163 | |
| 164 | float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index) { |
| 165 | return static_cast<const MotionEvent*>(motion_event)->getToolMinor(pointer_index); |
| 166 | } |
| 167 | |
| 168 | float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index) { |
| 169 | return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index); |
| 170 | } |
| 171 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 172 | size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 173 | return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); |
| 174 | } |
| 175 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 176 | int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 177 | size_t history_index) { |
| 178 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( |
| 179 | history_index); |
| 180 | } |
| 181 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 182 | float AMotionEvent_getHistoricalRawX(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 183 | size_t history_index) { |
| 184 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( |
| 185 | pointer_index, history_index); |
| 186 | } |
| 187 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 188 | float AMotionEvent_getHistoricalRawY(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 189 | size_t history_index) { |
| 190 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( |
| 191 | pointer_index, history_index); |
| 192 | } |
| 193 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 194 | float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 195 | size_t history_index) { |
| 196 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( |
| 197 | pointer_index, history_index); |
| 198 | } |
| 199 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 200 | float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 201 | size_t history_index) { |
| 202 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( |
| 203 | pointer_index, history_index); |
| 204 | } |
| 205 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 206 | float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 207 | size_t history_index) { |
| 208 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( |
| 209 | pointer_index, history_index); |
| 210 | } |
| 211 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 212 | float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 213 | size_t history_index) { |
| 214 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( |
| 215 | pointer_index, history_index); |
| 216 | } |
| 217 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 218 | float AMotionEvent_getHistoricalTouchMajor(AInputEvent* motion_event, size_t pointer_index, |
| 219 | size_t history_index) { |
| 220 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMajor( |
| 221 | pointer_index, history_index); |
| 222 | } |
| 223 | |
| 224 | float AMotionEvent_getHistoricalTouchMinor(AInputEvent* motion_event, size_t pointer_index, |
| 225 | size_t history_index) { |
| 226 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMinor( |
| 227 | pointer_index, history_index); |
| 228 | } |
| 229 | |
| 230 | float AMotionEvent_getHistoricalToolMajor(AInputEvent* motion_event, size_t pointer_index, |
| 231 | size_t history_index) { |
| 232 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMajor( |
| 233 | pointer_index, history_index); |
| 234 | } |
| 235 | |
| 236 | float AMotionEvent_getHistoricalToolMinor(AInputEvent* motion_event, size_t pointer_index, |
| 237 | size_t history_index) { |
| 238 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMinor( |
| 239 | pointer_index, history_index); |
| 240 | } |
| 241 | |
| 242 | float AMotionEvent_getHistoricalOrientation(AInputEvent* motion_event, size_t pointer_index, |
| 243 | size_t history_index) { |
| 244 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalOrientation( |
| 245 | pointer_index, history_index); |
| 246 | } |
| 247 | |
| 248 | |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 249 | void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, |
Dianne Hackborn | 85448bb | 2010-07-07 14:27:31 -0700 | [diff] [blame] | 250 | ALooper_callbackFunc* callback, void* data) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 251 | queue->attachLooper(looper, callback, data); |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void AInputQueue_detachLooper(AInputQueue* queue) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 255 | queue->detachLooper(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 258 | int32_t AInputQueue_hasEvents(AInputQueue* queue) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 259 | return queue->hasEvents(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 262 | int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 263 | return queue->getEvent(outEvent); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 266 | int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event) { |
| 267 | return queue->preDispatchEvent(event) ? 1 : 0; |
| 268 | } |
| 269 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 270 | void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) { |
| 271 | queue->finishEvent(event, handled != 0); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 272 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame^] | 273 | |
| 274 | |
| 275 | int32_t AInputDevice_getDeviceIds(int32_t* idBuf, size_t nMax, size_t* nActual) { |
| 276 | Vector<int32_t> ids; |
| 277 | InputDeviceProxy::getDeviceIds(ids); |
| 278 | |
| 279 | if (nActual) { |
| 280 | *nActual = ids.size(); |
| 281 | } |
| 282 | |
| 283 | if (idBuf && ids.size() < nMax) { |
| 284 | memcpy(idBuf, ids.array(), ids.size() * sizeof(int32_t)); |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | return -ENOMEM; |
| 289 | } |
| 290 | |
| 291 | AInputDevice* AInputDevice_acquire(int32_t deviceId) { |
| 292 | sp<InputDeviceProxy> proxy(InputDeviceProxy::getDevice(deviceId)); |
| 293 | if (proxy == NULL) { |
| 294 | return NULL; |
| 295 | } |
| 296 | proxy->incStrong((void*)AInputDevice_acquire); |
| 297 | return static_cast<AInputDevice*>(proxy.get()); |
| 298 | } |
| 299 | |
| 300 | void AInputDevice_release(AInputDevice* device) { |
| 301 | if (device) { |
| 302 | InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); |
| 303 | proxy->decStrong((void*)AInputDevice_acquire); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | const char* AInputDevice_getName(AInputDevice* device) { |
| 308 | InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); |
| 309 | return proxy->getInfo()->getName().string(); |
| 310 | } |
| 311 | |
| 312 | uint32_t AInputDevice_getSources(AInputDevice* device) { |
| 313 | InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); |
| 314 | return proxy->getInfo()->getSources(); |
| 315 | } |
| 316 | |
| 317 | int32_t AInputDevice_getKeyboardType(AInputDevice* device) { |
| 318 | InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); |
| 319 | return proxy->getInfo()->getKeyboardType(); |
| 320 | } |
| 321 | |
| 322 | int32_t AInputDevice_getMotionRange(AInputDevice* device, int32_t rangeType, |
| 323 | float* outMin, float* outMax, float* outFlat, float* outFuzz) { |
| 324 | InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); |
| 325 | const InputDeviceInfo::MotionRange* range = proxy->getInfo()->getMotionRange(rangeType); |
| 326 | if (range) { |
| 327 | if (outMin) { |
| 328 | *outMin = range->min; |
| 329 | } |
| 330 | if (outMax) { |
| 331 | *outMax = range->max; |
| 332 | } |
| 333 | if (outFlat) { |
| 334 | *outFlat = range->flat; |
| 335 | } |
| 336 | if (outFuzz) { |
| 337 | *outFuzz = range->fuzz; |
| 338 | } |
| 339 | return 0; |
| 340 | } else { |
| 341 | return -ENOTSUP; |
| 342 | } |
| 343 | } |