blob: df4d299ed3b381e6cc84d4ecf97afbdaf1c8b239 [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
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 Brownb4ff35d2011-01-02 16:37:43 -080024#include "EventHub.h"
25#include "InputReader.h"
26#include "InputDispatcher.h"
27
Jeff Brown46b9ac02010-04-22 18:58:52 -070028#include <ui/Input.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080029#include <ui/InputTransport.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070030#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
36namespace android {
37
Jeff Brown46b9ac02010-04-22 18:58:52 -070038/*
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 */
57class InputManagerInterface : public virtual RefBase {
58protected:
59 InputManagerInterface() { }
60 virtual ~InputManagerInterface() { }
61
62public:
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 Brownb88102f2010-09-08 11:49:43 -070069 /* Gets the input reader. */
70 virtual sp<InputReaderInterface> getReader() = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -070071
Jeff Brownb88102f2010-09-08 11:49:43 -070072 /* Gets the input dispatcher. */
73 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -070074};
75
76class InputManager : public InputManagerInterface {
77protected:
78 virtual ~InputManager();
79
80public:
Jeff Brown9c3cda02010-06-15 01:31:58 -070081 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 Brown46b9ac02010-04-22 18:58:52 -070090
91 virtual status_t start();
92 virtual status_t stop();
93
Jeff Brownb88102f2010-09-08 11:49:43 -070094 virtual sp<InputReaderInterface> getReader();
95 virtual sp<InputDispatcherInterface> getDispatcher();
Jeff Brown46b9ac02010-04-22 18:58:52 -070096
97private:
Jeff Brown9c3cda02010-06-15 01:31:58 -070098 sp<InputReaderInterface> mReader;
Jeff Brown46b9ac02010-04-22 18:58:52 -070099 sp<InputReaderThread> mReaderThread;
100
Jeff Brown9c3cda02010-06-15 01:31:58 -0700101 sp<InputDispatcherInterface> mDispatcher;
102 sp<InputDispatcherThread> mDispatcherThread;
103
104 void initialize();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700105};
106
107} // namespace android
108
109#endif // _UI_INPUT_MANAGER_H