blob: 7ffec5b1af372b6356ebfe8f29f594f5f21eff20 [file] [log] [blame]
Tim Kilbourn73475a42015-02-13 10:35:20 -08001/*
2 * Copyright (C) 2015 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 ANDROID_INPUT_DEVICE_MANAGER_H_
18#define ANDROID_INPUT_DEVICE_MANAGER_H_
19
20#include <memory>
21#include <unordered_map>
22
23#include <utils/Timers.h>
24
25#include "InputDevice.h"
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070026#include "InputHost.h"
Tim Kilbourn73475a42015-02-13 10:35:20 -080027#include "InputHub.h"
28
29namespace android {
30
31/**
32 * InputDeviceManager keeps the mapping of InputDeviceNodes to
33 * InputDeviceInterfaces and handles the callbacks from the InputHub, delegating
34 * them to the appropriate InputDeviceInterface.
35 */
36class InputDeviceManager : public InputCallbackInterface {
37public:
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070038 explicit InputDeviceManager(InputHostInterface* host) :
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070039 mHost(host) {}
Tim Kilbourn73475a42015-02-13 10:35:20 -080040 virtual ~InputDeviceManager() override = default;
41
Tim Kilbournc929d252015-04-29 13:50:17 -070042 virtual void onInputEvent(const std::shared_ptr<InputDeviceNode>& node, InputEvent& event,
Tim Kilbourn73475a42015-02-13 10:35:20 -080043 nsecs_t event_time) override;
Tim Kilbournc929d252015-04-29 13:50:17 -070044 virtual void onDeviceAdded(const std::shared_ptr<InputDeviceNode>& node) override;
45 virtual void onDeviceRemoved(const std::shared_ptr<InputDeviceNode>& node) override;
Tim Kilbourn73475a42015-02-13 10:35:20 -080046
47private:
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070048 InputHostInterface* mHost;
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070049
Tim Kilbourn73475a42015-02-13 10:35:20 -080050 template<class T, class U>
51 using DeviceMap = std::unordered_map<std::shared_ptr<T>, std::shared_ptr<U>>;
52
53 DeviceMap<InputDeviceNode, InputDeviceInterface> mDevices;
54};
55
56} // namespace android
57
58#endif // ANDROID_INPUT_DEVICE_MANAGER_H_