Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Mathias Agopian | b93a03f8 | 2012-02-17 15:34:57 -0800 | [diff] [blame] | 17 | #ifndef _ANDROIDFW_INPUT_TRANSPORT_H |
| 18 | #define _ANDROIDFW_INPUT_TRANSPORT_H |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Native input transport. |
| 22 | * |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 23 | * The InputChannel provides a mechanism for exchanging InputMessage structures across processes. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 24 | * |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 25 | * The InputPublisher and InputConsumer each handle one end-point of an input channel. |
| 26 | * The InputPublisher is used by the input dispatcher to send events to the application. |
| 27 | * The InputConsumer is used by the application to receive events from the input dispatcher. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 28 | */ |
| 29 | |
Mathias Agopian | b93a03f8 | 2012-02-17 15:34:57 -0800 | [diff] [blame] | 30 | #include <androidfw/Input.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 31 | #include <utils/Errors.h> |
| 32 | #include <utils/Timers.h> |
| 33 | #include <utils/RefBase.h> |
| 34 | #include <utils/String8.h> |
Mathias Agopian | b93a03f8 | 2012-02-17 15:34:57 -0800 | [diff] [blame] | 35 | #include <utils/Vector.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 36 | |
| 37 | namespace android { |
| 38 | |
| 39 | /* |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 40 | * Intermediate representation used to send input events and related signals. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 41 | */ |
| 42 | struct InputMessage { |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 43 | enum { |
| 44 | TYPE_KEY = 1, |
| 45 | TYPE_MOTION = 2, |
| 46 | TYPE_FINISHED = 3, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 49 | struct Header { |
| 50 | uint32_t type; |
| 51 | uint32_t padding; // 8 byte alignment for the body that follows |
| 52 | } header; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 53 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 54 | union Body { |
| 55 | struct Key { |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 56 | uint32_t seq; |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 57 | nsecs_t eventTime; |
| 58 | int32_t deviceId; |
| 59 | int32_t source; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 60 | int32_t action; |
| 61 | int32_t flags; |
| 62 | int32_t keyCode; |
| 63 | int32_t scanCode; |
| 64 | int32_t metaState; |
| 65 | int32_t repeatCount; |
| 66 | nsecs_t downTime; |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 67 | |
| 68 | inline size_t size() const { |
| 69 | return sizeof(Key); |
| 70 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 71 | } key; |
| 72 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 73 | struct Motion { |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 74 | uint32_t seq; |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 75 | nsecs_t eventTime; |
| 76 | int32_t deviceId; |
| 77 | int32_t source; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 78 | int32_t action; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 79 | int32_t flags; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 80 | int32_t metaState; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 81 | int32_t buttonState; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 82 | int32_t edgeFlags; |
| 83 | nsecs_t downTime; |
| 84 | float xOffset; |
| 85 | float yOffset; |
| 86 | float xPrecision; |
| 87 | float yPrecision; |
| 88 | size_t pointerCount; |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 89 | struct Pointer { |
| 90 | PointerProperties properties; |
| 91 | PointerCoords coords; |
| 92 | } pointers[MAX_POINTERS]; |
| 93 | |
| 94 | inline size_t size() const { |
| 95 | return sizeof(Motion) - sizeof(Pointer) * MAX_POINTERS |
| 96 | + sizeof(Pointer) * pointerCount; |
| 97 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 98 | } motion; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 99 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 100 | struct Finished { |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 101 | uint32_t seq; |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 102 | bool handled; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 103 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 104 | inline size_t size() const { |
| 105 | return sizeof(Finished); |
| 106 | } |
| 107 | } finished; |
| 108 | } body; |
| 109 | |
| 110 | bool isValid(size_t actualSize) const; |
| 111 | size_t size() const; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /* |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 115 | * An input channel consists of a local unix domain socket used to send and receive |
| 116 | * input messages across processes. Each channel has a descriptive name for debugging purposes. |
| 117 | * |
| 118 | * Each endpoint has its own InputChannel object that specifies its file descriptor. |
| 119 | * |
| 120 | * The input channel is closed when all references to it are released. |
| 121 | */ |
| 122 | class InputChannel : public RefBase { |
| 123 | protected: |
| 124 | virtual ~InputChannel(); |
| 125 | |
| 126 | public: |
Jeff Brown | 91e3289 | 2012-02-14 15:56:29 -0800 | [diff] [blame] | 127 | InputChannel(const String8& name, int fd); |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 128 | |
| 129 | /* Creates a pair of input channels. |
| 130 | * |
| 131 | * Returns OK on success. |
| 132 | */ |
| 133 | static status_t openInputChannelPair(const String8& name, |
| 134 | sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel); |
| 135 | |
| 136 | inline String8 getName() const { return mName; } |
Jeff Brown | 91e3289 | 2012-02-14 15:56:29 -0800 | [diff] [blame] | 137 | inline int getFd() const { return mFd; } |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 138 | |
| 139 | /* Sends a message to the other endpoint. |
| 140 | * |
| 141 | * If the channel is full then the message is guaranteed not to have been sent at all. |
| 142 | * Try again after the consumer has sent a finished signal indicating that it has |
| 143 | * consumed some of the pending messages from the channel. |
| 144 | * |
| 145 | * Returns OK on success. |
| 146 | * Returns WOULD_BLOCK if the channel is full. |
| 147 | * Returns DEAD_OBJECT if the channel's peer has been closed. |
| 148 | * Other errors probably indicate that the channel is broken. |
| 149 | */ |
| 150 | status_t sendMessage(const InputMessage* msg); |
| 151 | |
| 152 | /* Receives a message sent by the other endpoint. |
| 153 | * |
| 154 | * If there is no message present, try again after poll() indicates that the fd |
| 155 | * is readable. |
| 156 | * |
| 157 | * Returns OK on success. |
| 158 | * Returns WOULD_BLOCK if there is no message present. |
| 159 | * Returns DEAD_OBJECT if the channel's peer has been closed. |
| 160 | * Other errors probably indicate that the channel is broken. |
| 161 | */ |
| 162 | status_t receiveMessage(InputMessage* msg); |
| 163 | |
| 164 | private: |
| 165 | String8 mName; |
Jeff Brown | 91e3289 | 2012-02-14 15:56:29 -0800 | [diff] [blame] | 166 | int mFd; |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | /* |
| 170 | * Publishes input events to an input channel. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 171 | */ |
| 172 | class InputPublisher { |
| 173 | public: |
| 174 | /* Creates a publisher associated with an input channel. */ |
| 175 | explicit InputPublisher(const sp<InputChannel>& channel); |
| 176 | |
| 177 | /* Destroys the publisher and releases its input channel. */ |
| 178 | ~InputPublisher(); |
| 179 | |
| 180 | /* Gets the underlying input channel. */ |
| 181 | inline sp<InputChannel> getChannel() { return mChannel; } |
| 182 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 183 | /* Publishes a key event to the input channel. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 184 | * |
| 185 | * Returns OK on success. |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 186 | * Returns WOULD_BLOCK if the channel is full. |
| 187 | * Returns DEAD_OBJECT if the channel's peer has been closed. |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 188 | * Returns BAD_VALUE if seq is 0. |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 189 | * Other errors probably indicate that the channel is broken. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 190 | */ |
| 191 | status_t publishKeyEvent( |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 192 | uint32_t seq, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 193 | int32_t deviceId, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 194 | int32_t source, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 195 | int32_t action, |
| 196 | int32_t flags, |
| 197 | int32_t keyCode, |
| 198 | int32_t scanCode, |
| 199 | int32_t metaState, |
| 200 | int32_t repeatCount, |
| 201 | nsecs_t downTime, |
| 202 | nsecs_t eventTime); |
| 203 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 204 | /* Publishes a motion event to the input channel. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 205 | * |
| 206 | * Returns OK on success. |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 207 | * Returns WOULD_BLOCK if the channel is full. |
| 208 | * Returns DEAD_OBJECT if the channel's peer has been closed. |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 209 | * Returns BAD_VALUE if seq is 0 or if pointerCount is less than 1 or greater than MAX_POINTERS. |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 210 | * Other errors probably indicate that the channel is broken. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 211 | */ |
| 212 | status_t publishMotionEvent( |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 213 | uint32_t seq, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 214 | int32_t deviceId, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 215 | int32_t source, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 216 | int32_t action, |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 217 | int32_t flags, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 218 | int32_t edgeFlags, |
| 219 | int32_t metaState, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 220 | int32_t buttonState, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 221 | float xOffset, |
| 222 | float yOffset, |
| 223 | float xPrecision, |
| 224 | float yPrecision, |
| 225 | nsecs_t downTime, |
| 226 | nsecs_t eventTime, |
| 227 | size_t pointerCount, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 228 | const PointerProperties* pointerProperties, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 229 | const PointerCoords* pointerCoords); |
| 230 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 231 | /* Receives the finished signal from the consumer in reply to the original dispatch signal. |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 232 | * If a signal was received, returns the message sequence number, |
| 233 | * and whether the consumer handled the message. |
| 234 | * |
| 235 | * The returned sequence number is never 0 unless the operation failed. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 236 | * |
| 237 | * Returns OK on success. |
| 238 | * Returns WOULD_BLOCK if there is no signal present. |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 239 | * Returns DEAD_OBJECT if the channel's peer has been closed. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 240 | * Other errors probably indicate that the channel is broken. |
| 241 | */ |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 242 | status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 243 | |
| 244 | private: |
| 245 | sp<InputChannel> mChannel; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | /* |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 249 | * Consumes input events from an input channel. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 250 | */ |
| 251 | class InputConsumer { |
| 252 | public: |
| 253 | /* Creates a consumer associated with an input channel. */ |
| 254 | explicit InputConsumer(const sp<InputChannel>& channel); |
| 255 | |
| 256 | /* Destroys the consumer and releases its input channel. */ |
| 257 | ~InputConsumer(); |
| 258 | |
| 259 | /* Gets the underlying input channel. */ |
| 260 | inline sp<InputChannel> getChannel() { return mChannel; } |
| 261 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 262 | /* Consumes an input event from the input channel and copies its contents into |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 263 | * an InputEvent object created using the specified factory. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 264 | * |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 265 | * Tries to combine a series of move events into larger batches whenever possible. |
| 266 | * |
| 267 | * If consumeBatches is false, then defers consuming pending batched events if it |
| 268 | * is possible for additional samples to be added to them later. Call hasPendingBatch() |
| 269 | * to determine whether a pending batch is available to be consumed. |
| 270 | * |
| 271 | * If consumeBatches is true, then events are still batched but they are consumed |
| 272 | * immediately as soon as the input channel is exhausted. |
| 273 | * |
| 274 | * The returned sequence number is never 0 unless the operation failed. |
| 275 | * |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 276 | * Returns OK on success. |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 277 | * Returns WOULD_BLOCK if there is no event present. |
| 278 | * Returns DEAD_OBJECT if the channel's peer has been closed. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 279 | * Returns NO_MEMORY if the event could not be created. |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 280 | * Other errors probably indicate that the channel is broken. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 281 | */ |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 282 | status_t consume(InputEventFactoryInterface* factory, bool consumeBatches, |
| 283 | uint32_t* outSeq, InputEvent** outEvent); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 284 | |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 285 | /* Sends a finished signal to the publisher to inform it that the message |
| 286 | * with the specified sequence number has finished being process and whether |
| 287 | * the message was handled by the consumer. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 288 | * |
| 289 | * Returns OK on success. |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 290 | * Returns BAD_VALUE if seq is 0. |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 291 | * Other errors probably indicate that the channel is broken. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 292 | */ |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 293 | status_t sendFinishedSignal(uint32_t seq, bool handled); |
| 294 | |
Jeff Brown | 2b6c32c | 2012-03-13 15:00:09 -0700 | [diff] [blame^] | 295 | /* Returns true if there is a deferred event waiting. |
| 296 | * |
| 297 | * Should be called after calling consume() to determine whether the consumer |
| 298 | * has a deferred event to be processed. Deferred events are somewhat special in |
| 299 | * that they have already been removed from the input channel. If the input channel |
| 300 | * becomes empty, the client may need to do extra work to ensure that it processes |
| 301 | * the deferred event despite the fact that the inptu channel's file descriptor |
| 302 | * is not readable. |
| 303 | * |
| 304 | * One option is simply to call consume() in a loop until it returns WOULD_BLOCK. |
| 305 | * This guarantees that all deferred events will be processed. |
| 306 | * |
| 307 | * Alternately, the caller can call hasDeferredEvent() to determine whether there is |
| 308 | * a deferred event waiting and then ensure that its event loop wakes up at least |
| 309 | * one more time to consume the deferred event. |
| 310 | */ |
| 311 | bool hasDeferredEvent() const; |
| 312 | |
| 313 | /* Returns true if there is a pending batch. |
| 314 | * |
| 315 | * Should be called after calling consume() with consumeBatches == false to determine |
| 316 | * whether consume() should be called again later on with consumeBatches == true. |
| 317 | */ |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 318 | bool hasPendingBatch() const; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 319 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 320 | private: |
| 321 | sp<InputChannel> mChannel; |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 322 | |
Jeff Brown | 90fde93 | 2012-02-13 12:44:01 -0800 | [diff] [blame] | 323 | // The current input message. |
| 324 | InputMessage mMsg; |
| 325 | |
| 326 | // True if mMsg contains a valid input message that was deferred from the previous |
| 327 | // call to consume and that still needs to be handled. |
| 328 | bool mMsgDeferred; |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 329 | |
| 330 | // Batched motion events per device and source. |
| 331 | struct Batch { |
Jeff Brown | 2d34e0c | 2012-02-13 13:18:09 -0800 | [diff] [blame] | 332 | uint32_t seq; // sequence number of last input message batched in the event |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 333 | MotionEvent event; |
| 334 | }; |
| 335 | Vector<Batch> mBatches; |
| 336 | |
Jeff Brown | 2d34e0c | 2012-02-13 13:18:09 -0800 | [diff] [blame] | 337 | // Chain of batched sequence numbers. When multiple input messages are combined into |
| 338 | // a batch, we append a record here that associates the last sequence number in the |
| 339 | // batch with the previous one. When the finished signal is sent, we traverse the |
| 340 | // chain to individually finish all input messages that were part of the batch. |
| 341 | struct SeqChain { |
| 342 | uint32_t seq; // sequence number of batched input message |
| 343 | uint32_t chain; // sequence number of previous batched input message |
| 344 | }; |
| 345 | Vector<SeqChain> mSeqChains; |
| 346 | |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 347 | ssize_t findBatch(int32_t deviceId, int32_t source) const; |
Jeff Brown | 2d34e0c | 2012-02-13 13:18:09 -0800 | [diff] [blame] | 348 | status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled); |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 349 | |
| 350 | static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); |
| 351 | static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); |
| 352 | static bool canAppendSamples(const MotionEvent* event, const InputMessage* msg); |
| 353 | static void appendSamples(MotionEvent* event, const InputMessage* msg); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | } // namespace android |
| 357 | |
Mathias Agopian | b93a03f8 | 2012-02-17 15:34:57 -0800 | [diff] [blame] | 358 | #endif // _ANDROIDFW_INPUT_TRANSPORT_H |