widget/gonk/libui/InputManager.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/libui/InputManager.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +/*
     1.5 + * Copyright (C) 2010 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#define LOG_TAG "InputManager"
    1.21 +
    1.22 +//#define LOG_NDEBUG 0
    1.23 +
    1.24 +#include "InputManager.h"
    1.25 +
    1.26 +#include "cutils_log.h"
    1.27 +
    1.28 +namespace android {
    1.29 +
    1.30 +InputManager::InputManager(
    1.31 +        const sp<EventHubInterface>& eventHub,
    1.32 +        const sp<InputReaderPolicyInterface>& readerPolicy,
    1.33 +        const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) {
    1.34 +    mDispatcher = new InputDispatcher(dispatcherPolicy);
    1.35 +    mReader = new InputReader(eventHub, readerPolicy, mDispatcher);
    1.36 +    initialize();
    1.37 +}
    1.38 +
    1.39 +InputManager::InputManager(
    1.40 +        const sp<InputReaderInterface>& reader,
    1.41 +        const sp<InputDispatcherInterface>& dispatcher) :
    1.42 +        mReader(reader),
    1.43 +        mDispatcher(dispatcher) {
    1.44 +    initialize();
    1.45 +}
    1.46 +
    1.47 +InputManager::~InputManager() {
    1.48 +    stop();
    1.49 +}
    1.50 +
    1.51 +void InputManager::initialize() {
    1.52 +    mReaderThread = new InputReaderThread(mReader);
    1.53 +    mDispatcherThread = new InputDispatcherThread(mDispatcher);
    1.54 +}
    1.55 +
    1.56 +status_t InputManager::start() {
    1.57 +    status_t result = mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY);
    1.58 +    if (result) {
    1.59 +        ALOGE("Could not start InputDispatcher thread due to error %d.", result);
    1.60 +        return result;
    1.61 +    }
    1.62 +
    1.63 +    result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY);
    1.64 +    if (result) {
    1.65 +        ALOGE("Could not start InputReader thread due to error %d.", result);
    1.66 +
    1.67 +        mDispatcherThread->requestExit();
    1.68 +        return result;
    1.69 +    }
    1.70 +
    1.71 +    return OK;
    1.72 +}
    1.73 +
    1.74 +status_t InputManager::stop() {
    1.75 +    status_t result = mReaderThread->requestExitAndWait();
    1.76 +    if (result) {
    1.77 +        ALOGW("Could not stop InputReader thread due to error %d.", result);
    1.78 +    }
    1.79 +
    1.80 +    result = mDispatcherThread->requestExitAndWait();
    1.81 +    if (result) {
    1.82 +        ALOGW("Could not stop InputDispatcher thread due to error %d.", result);
    1.83 +    }
    1.84 +
    1.85 +    return OK;
    1.86 +}
    1.87 +
    1.88 +sp<InputReaderInterface> InputManager::getReader() {
    1.89 +    return mReader;
    1.90 +}
    1.91 +
    1.92 +sp<InputDispatcherInterface> InputManager::getDispatcher() {
    1.93 +    return mDispatcher;
    1.94 +}
    1.95 +
    1.96 +} // namespace android

mercurial