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 25 #include "InputDevice.h" 26 #include "InputHub.h" 27 28 namespace android { 29 30 /** 31 * InputDeviceManager keeps the mapping of InputDeviceNodes to 32 * InputDeviceInterfaces and handles the callbacks from the InputHub, delegating 33 * them to the appropriate InputDeviceInterface. 34 */ 35 class InputDeviceManager : public InputCallbackInterface { 36 public: 37 virtual ~InputDeviceManager() override = default; 38 39 virtual void onInputEvent(std::shared_ptr<InputDeviceNode> node, InputEvent& event, 40 nsecs_t event_time) override; 41 virtual void onDeviceAdded(std::shared_ptr<InputDeviceNode> node) override; 42 virtual void onDeviceRemoved(std::shared_ptr<InputDeviceNode> node) override; 43 44 private: 45 template<class T, class U> 46 using DeviceMap = std::unordered_map<std::shared_ptr<T>, std::shared_ptr<U>>; 47 48 DeviceMap<InputDeviceNode, InputDeviceInterface> mDevices; 49 }; 50 51 } // namespace android 52 53 #endif // ANDROID_INPUT_DEVICE_MANAGER_H_ 54