michael@0: /* michael@0: * Copyright (C) 2010 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #define LOG_TAG "InputManager" michael@0: michael@0: //#define LOG_NDEBUG 0 michael@0: michael@0: #include "InputManager.h" michael@0: michael@0: #include "cutils_log.h" michael@0: michael@0: namespace android { michael@0: michael@0: InputManager::InputManager( michael@0: const sp& eventHub, michael@0: const sp& readerPolicy, michael@0: const sp& dispatcherPolicy) { michael@0: mDispatcher = new InputDispatcher(dispatcherPolicy); michael@0: mReader = new InputReader(eventHub, readerPolicy, mDispatcher); michael@0: initialize(); michael@0: } michael@0: michael@0: InputManager::InputManager( michael@0: const sp& reader, michael@0: const sp& dispatcher) : michael@0: mReader(reader), michael@0: mDispatcher(dispatcher) { michael@0: initialize(); michael@0: } michael@0: michael@0: InputManager::~InputManager() { michael@0: stop(); michael@0: } michael@0: michael@0: void InputManager::initialize() { michael@0: mReaderThread = new InputReaderThread(mReader); michael@0: mDispatcherThread = new InputDispatcherThread(mDispatcher); michael@0: } michael@0: michael@0: status_t InputManager::start() { michael@0: status_t result = mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY); michael@0: if (result) { michael@0: ALOGE("Could not start InputDispatcher thread due to error %d.", result); michael@0: return result; michael@0: } michael@0: michael@0: result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY); michael@0: if (result) { michael@0: ALOGE("Could not start InputReader thread due to error %d.", result); michael@0: michael@0: mDispatcherThread->requestExit(); michael@0: return result; michael@0: } michael@0: michael@0: return OK; michael@0: } michael@0: michael@0: status_t InputManager::stop() { michael@0: status_t result = mReaderThread->requestExitAndWait(); michael@0: if (result) { michael@0: ALOGW("Could not stop InputReader thread due to error %d.", result); michael@0: } michael@0: michael@0: result = mDispatcherThread->requestExitAndWait(); michael@0: if (result) { michael@0: ALOGW("Could not stop InputDispatcher thread due to error %d.", result); michael@0: } michael@0: michael@0: return OK; michael@0: } michael@0: michael@0: sp InputManager::getReader() { michael@0: return mReader; michael@0: } michael@0: michael@0: sp InputManager::getDispatcher() { michael@0: return mDispatcher; michael@0: } michael@0: michael@0: } // namespace android