Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 25 | #include "InputHub.h" |
| 26 | |
| 27 | namespace android { |
| 28 | |
Tim Kilbourn | dbc8c16 | 2015-05-19 15:04:30 -0700 | [diff] [blame] | 29 | class InputDeviceInterface; |
| 30 | class InputHostInterface; |
| 31 | |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 32 | /** |
| 33 | * InputDeviceManager keeps the mapping of InputDeviceNodes to |
| 34 | * InputDeviceInterfaces and handles the callbacks from the InputHub, delegating |
| 35 | * them to the appropriate InputDeviceInterface. |
| 36 | */ |
| 37 | class InputDeviceManager : public InputCallbackInterface { |
| 38 | public: |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 39 | explicit InputDeviceManager(InputHostInterface* host) : |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 40 | mHost(host) {} |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 41 | virtual ~InputDeviceManager() override = default; |
| 42 | |
Tim Kilbourn | c929d25 | 2015-04-29 13:50:17 -0700 | [diff] [blame] | 43 | virtual void onInputEvent(const std::shared_ptr<InputDeviceNode>& node, InputEvent& event, |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 44 | nsecs_t event_time) override; |
Tim Kilbourn | c929d25 | 2015-04-29 13:50:17 -0700 | [diff] [blame] | 45 | virtual void onDeviceAdded(const std::shared_ptr<InputDeviceNode>& node) override; |
| 46 | virtual void onDeviceRemoved(const std::shared_ptr<InputDeviceNode>& node) override; |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 47 | |
| 48 | private: |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 49 | InputHostInterface* mHost; |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 50 | |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 51 | template<class T, class U> |
| 52 | using DeviceMap = std::unordered_map<std::shared_ptr<T>, std::shared_ptr<U>>; |
| 53 | |
| 54 | DeviceMap<InputDeviceNode, InputDeviceInterface> mDevices; |
| 55 | }; |
| 56 | |
| 57 | } // namespace android |
| 58 | |
| 59 | #endif // ANDROID_INPUT_DEVICE_MANAGER_H_ |