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