blob: 92e0af21c34b14d84f1ec7f04888120340140b84 [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
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
24#include "EventHub.h"
25#include "InputReader.h"
26#include "InputDispatcher.h"
27
28#include <input/Input.h>
29#include <input/InputTransport.h>
30#include <utils/Errors.h>
31#include <utils/Vector.h>
32#include <utils/Timers.h>
33#include <utils/RefBase.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080034
35namespace android {
36
37/*
38 * The input manager is the core of the system event processing.
39 *
40 * The input manager uses two threads.
41 *
42 * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events,
43 * applies policy, and posts messages to a queue managed by the DispatcherThread.
44 * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the
45 * queue and asynchronously dispatches them to applications.
46 *
47 * By design, the InputReaderThread class and InputDispatcherThread class do not share any
48 * internal state. Moreover, all communication is done one way from the InputReaderThread
49 * into the InputDispatcherThread and never the reverse. Both classes may interact with the
50 * InputDispatchPolicy, however.
51 *
52 * The InputManager class never makes any calls into Java itself. Instead, the
53 * InputDispatchPolicy is responsible for performing all external interactions with the
54 * system, including calling DVM services.
55 */
56class InputManagerInterface : public virtual RefBase {
57protected:
58 InputManagerInterface() { }
59 virtual ~InputManagerInterface() { }
60
61public:
62 /* Starts the input manager threads. */
63 virtual status_t start() = 0;
64
65 /* Stops the input manager threads and waits for them to exit. */
66 virtual status_t stop() = 0;
67
68 /* Gets the input reader. */
69 virtual sp<InputReaderInterface> getReader() = 0;
70
71 /* Gets the input dispatcher. */
72 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
73};
74
75class InputManager : public InputManagerInterface {
76protected:
77 virtual ~InputManager();
78
79public:
80 InputManager(
81 const sp<EventHubInterface>& eventHub,
82 const sp<InputReaderPolicyInterface>& readerPolicy,
83 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
84
85 // (used for testing purposes)
86 InputManager(
87 const sp<InputReaderInterface>& reader,
88 const sp<InputDispatcherInterface>& dispatcher);
89
90 virtual status_t start();
91 virtual status_t stop();
92
93 virtual sp<InputReaderInterface> getReader();
94 virtual sp<InputDispatcherInterface> getDispatcher();
95
96private:
97 sp<InputReaderInterface> mReader;
98 sp<InputReaderThread> mReaderThread;
99
100 sp<InputDispatcherInterface> mDispatcher;
101 sp<InputDispatcherThread> mDispatcherThread;
102
103 void initialize();
104};
105
106} // namespace android
107
108#endif // _UI_INPUT_MANAGER_H