Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [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 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 17 | #define LOG_TAG "InputManager" |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 21 | #include "InputManager.h" |
| 22 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 23 | #include <cutils/log.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 27 | InputManager::InputManager( |
| 28 | const sp<EventHubInterface>& eventHub, |
| 29 | const sp<InputReaderPolicyInterface>& readerPolicy, |
| 30 | const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) { |
| 31 | mDispatcher = new InputDispatcher(dispatcherPolicy); |
| 32 | mReader = new InputReader(eventHub, readerPolicy, mDispatcher); |
| 33 | initialize(); |
| 34 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 35 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 36 | InputManager::InputManager( |
| 37 | const sp<InputReaderInterface>& reader, |
| 38 | const sp<InputDispatcherInterface>& dispatcher) : |
| 39 | mReader(reader), |
| 40 | mDispatcher(dispatcher) { |
| 41 | initialize(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | InputManager::~InputManager() { |
| 45 | stop(); |
| 46 | } |
| 47 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 48 | void InputManager::initialize() { |
| 49 | mReaderThread = new InputReaderThread(mReader); |
| 50 | mDispatcherThread = new InputDispatcherThread(mDispatcher); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | status_t InputManager::start() { |
| 54 | status_t result = mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY); |
| 55 | if (result) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 56 | ALOGE("Could not start InputDispatcher thread due to error %d.", result); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 57 | return result; |
| 58 | } |
| 59 | |
| 60 | result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY); |
| 61 | if (result) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 62 | ALOGE("Could not start InputReader thread due to error %d.", result); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 63 | |
| 64 | mDispatcherThread->requestExit(); |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | return OK; |
| 69 | } |
| 70 | |
| 71 | status_t InputManager::stop() { |
| 72 | status_t result = mReaderThread->requestExitAndWait(); |
| 73 | if (result) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 74 | ALOGW("Could not stop InputReader thread due to error %d.", result); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | result = mDispatcherThread->requestExitAndWait(); |
| 78 | if (result) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 79 | ALOGW("Could not stop InputDispatcher thread due to error %d.", result); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | return OK; |
| 83 | } |
| 84 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 85 | sp<InputReaderInterface> InputManager::getReader() { |
| 86 | return mReader; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 89 | sp<InputDispatcherInterface> InputManager::getDispatcher() { |
| 90 | return mDispatcher; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | } // namespace android |