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 | #define LOG_TAG "InputDeviceManager" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
Tim Kilbourn | dbc8c16 | 2015-05-19 15:04:30 -0700 | [diff] [blame] | 20 | #include "InputDeviceManager.h" |
| 21 | |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 22 | #include <utils/Log.h> |
| 23 | |
| 24 | #include "InputDevice.h" |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | |
Tim Kilbourn | c929d25 | 2015-04-29 13:50:17 -0700 | [diff] [blame] | 28 | void InputDeviceManager::onInputEvent(const std::shared_ptr<InputDeviceNode>& node, InputEvent& event, |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 29 | nsecs_t event_time) { |
| 30 | if (mDevices[node] == nullptr) { |
| 31 | ALOGE("got input event for unknown node %s", node->getPath().c_str()); |
| 32 | return; |
| 33 | } |
| 34 | mDevices[node]->processInput(event, event_time); |
| 35 | } |
| 36 | |
Tim Kilbourn | c929d25 | 2015-04-29 13:50:17 -0700 | [diff] [blame] | 37 | void InputDeviceManager::onDeviceAdded(const std::shared_ptr<InputDeviceNode>& node) { |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 38 | mDevices[node] = std::make_shared<EvdevDevice>(mHost, node); |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Tim Kilbourn | c929d25 | 2015-04-29 13:50:17 -0700 | [diff] [blame] | 41 | void InputDeviceManager::onDeviceRemoved(const std::shared_ptr<InputDeviceNode>& node) { |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 42 | if (mDevices[node] == nullptr) { |
| 43 | ALOGE("could not remove unknown node %s", node->getPath().c_str()); |
| 44 | return; |
| 45 | } |
| 46 | // TODO: tell the InputDevice and InputDeviceNode that they are being |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 47 | // removed so they can run any cleanup, including unregistering from the |
| 48 | // host. |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 49 | mDevices.erase(node); |
| 50 | } |
| 51 | |
| 52 | } // namespace android |