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 | |
| 17 | #ifndef _UI_INPUT_MANAGER_H |
| 18 | #define _UI_INPUT_MANAGER_H |
| 19 | |
| 20 | /** |
| 21 | * Native input manager. |
| 22 | */ |
| 23 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 24 | #include "EventHub.h" |
| 25 | #include "InputReader.h" |
| 26 | #include "InputDispatcher.h" |
| 27 | |
Jeff Brown | 9d3b1a4 | 2013-07-01 19:07:15 -0700 | [diff] [blame] | 28 | #include <input/Input.h> |
| 29 | #include <input/InputTransport.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 30 | #include <utils/Errors.h> |
| 31 | #include <utils/Vector.h> |
| 32 | #include <utils/Timers.h> |
| 33 | #include <utils/RefBase.h> |
| 34 | #include <utils/String8.h> |
| 35 | |
| 36 | namespace android { |
| 37 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 38 | /* |
| 39 | * The input manager is the core of the system event processing. |
| 40 | * |
| 41 | * The input manager uses two threads. |
| 42 | * |
| 43 | * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events, |
| 44 | * applies policy, and posts messages to a queue managed by the DispatcherThread. |
| 45 | * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the |
| 46 | * queue and asynchronously dispatches them to applications. |
| 47 | * |
| 48 | * By design, the InputReaderThread class and InputDispatcherThread class do not share any |
| 49 | * internal state. Moreover, all communication is done one way from the InputReaderThread |
| 50 | * into the InputDispatcherThread and never the reverse. Both classes may interact with the |
| 51 | * InputDispatchPolicy, however. |
| 52 | * |
| 53 | * The InputManager class never makes any calls into Java itself. Instead, the |
| 54 | * InputDispatchPolicy is responsible for performing all external interactions with the |
| 55 | * system, including calling DVM services. |
| 56 | */ |
| 57 | class InputManagerInterface : public virtual RefBase { |
| 58 | protected: |
| 59 | InputManagerInterface() { } |
| 60 | virtual ~InputManagerInterface() { } |
| 61 | |
| 62 | public: |
| 63 | /* Starts the input manager threads. */ |
| 64 | virtual status_t start() = 0; |
| 65 | |
| 66 | /* Stops the input manager threads and waits for them to exit. */ |
| 67 | virtual status_t stop() = 0; |
| 68 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 69 | /* Gets the input reader. */ |
| 70 | virtual sp<InputReaderInterface> getReader() = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 71 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 72 | /* Gets the input dispatcher. */ |
| 73 | virtual sp<InputDispatcherInterface> getDispatcher() = 0; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | class InputManager : public InputManagerInterface { |
| 77 | protected: |
| 78 | virtual ~InputManager(); |
| 79 | |
| 80 | public: |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 81 | InputManager( |
| 82 | const sp<EventHubInterface>& eventHub, |
| 83 | const sp<InputReaderPolicyInterface>& readerPolicy, |
| 84 | const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); |
| 85 | |
| 86 | // (used for testing purposes) |
| 87 | InputManager( |
| 88 | const sp<InputReaderInterface>& reader, |
| 89 | const sp<InputDispatcherInterface>& dispatcher); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 90 | |
| 91 | virtual status_t start(); |
| 92 | virtual status_t stop(); |
| 93 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 94 | virtual sp<InputReaderInterface> getReader(); |
| 95 | virtual sp<InputDispatcherInterface> getDispatcher(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 96 | |
| 97 | private: |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 98 | sp<InputReaderInterface> mReader; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 99 | sp<InputReaderThread> mReaderThread; |
| 100 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 101 | sp<InputDispatcherInterface> mDispatcher; |
| 102 | sp<InputDispatcherThread> mDispatcherThread; |
| 103 | |
| 104 | void initialize(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | } // namespace android |
| 108 | |
| 109 | #endif // _UI_INPUT_MANAGER_H |