blob: 09fce38d9c18c01bc4635768b612f3174af49d3a [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001//
2// Copyright 2010 The Android Open Source Project
3//
4// The input manager.
5//
6#define LOG_TAG "InputManager"
7
8//#define LOG_NDEBUG 0
9
10#include <cutils/log.h>
11#include <ui/InputManager.h>
12#include <ui/InputReader.h>
13#include <ui/InputDispatcher.h>
14
15namespace android {
16
Jeff Brown9c3cda02010-06-15 01:31:58 -070017InputManager::InputManager(
18 const sp<EventHubInterface>& eventHub,
19 const sp<InputReaderPolicyInterface>& readerPolicy,
20 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) {
21 mDispatcher = new InputDispatcher(dispatcherPolicy);
22 mReader = new InputReader(eventHub, readerPolicy, mDispatcher);
23 initialize();
24}
Jeff Brown46b9ac02010-04-22 18:58:52 -070025
Jeff Brown9c3cda02010-06-15 01:31:58 -070026InputManager::InputManager(
27 const sp<InputReaderInterface>& reader,
28 const sp<InputDispatcherInterface>& dispatcher) :
29 mReader(reader),
30 mDispatcher(dispatcher) {
31 initialize();
Jeff Brown46b9ac02010-04-22 18:58:52 -070032}
33
34InputManager::~InputManager() {
35 stop();
36}
37
Jeff Brown9c3cda02010-06-15 01:31:58 -070038void InputManager::initialize() {
39 mReaderThread = new InputReaderThread(mReader);
40 mDispatcherThread = new InputDispatcherThread(mDispatcher);
Jeff Brown46b9ac02010-04-22 18:58:52 -070041}
42
43status_t InputManager::start() {
44 status_t result = mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY);
45 if (result) {
46 LOGE("Could not start InputDispatcher thread due to error %d.", result);
47 return result;
48 }
49
50 result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY);
51 if (result) {
52 LOGE("Could not start InputReader thread due to error %d.", result);
53
54 mDispatcherThread->requestExit();
55 return result;
56 }
57
58 return OK;
59}
60
61status_t InputManager::stop() {
62 status_t result = mReaderThread->requestExitAndWait();
63 if (result) {
64 LOGW("Could not stop InputReader thread due to error %d.", result);
65 }
66
67 result = mDispatcherThread->requestExitAndWait();
68 if (result) {
69 LOGW("Could not stop InputDispatcher thread due to error %d.", result);
70 }
71
72 return OK;
73}
74
Jeff Brownb88102f2010-09-08 11:49:43 -070075sp<InputReaderInterface> InputManager::getReader() {
76 return mReader;
Jeff Brown46b9ac02010-04-22 18:58:52 -070077}
78
Jeff Brownb88102f2010-09-08 11:49:43 -070079sp<InputDispatcherInterface> InputManager::getDispatcher() {
80 return mDispatcher;
Jeff Brown46b9ac02010-04-22 18:58:52 -070081}
82
83} // namespace android