Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [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_MAPPER_H_ |
| 18 | #define ANDROID_INPUT_MAPPER_H_ |
| 19 | |
Tim Kilbourn | dbc8c16 | 2015-05-19 15:04:30 -0700 | [diff] [blame] | 20 | struct input_device_handle; |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 21 | |
| 22 | namespace android { |
| 23 | |
Tim Kilbourn | dbc8c16 | 2015-05-19 15:04:30 -0700 | [diff] [blame] | 24 | class InputDeviceNode; |
| 25 | class InputReport; |
| 26 | class InputReportDefinition; |
| 27 | struct InputEvent; |
| 28 | using InputDeviceHandle = struct input_device_handle; |
| 29 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 30 | /** |
| 31 | * An InputMapper processes raw evdev input events and combines them into |
| 32 | * Android input HAL reports. A given InputMapper will focus on a particular |
| 33 | * type of input, like key presses or touch events. A single InputDevice may |
| 34 | * have multiple InputMappers, corresponding to the different types of inputs it |
| 35 | * supports. |
| 36 | */ |
| 37 | class InputMapper { |
| 38 | public: |
Tim Kilbourn | dbc8c16 | 2015-05-19 15:04:30 -0700 | [diff] [blame] | 39 | InputMapper() = default; |
| 40 | virtual ~InputMapper() {} |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * If the mapper supports input events from the InputDevice, |
| 44 | * configureInputReport will populate the InputReportDefinition and return |
| 45 | * true. If input is not supported, false is returned, and the InputDevice |
| 46 | * may free or re-use the InputReportDefinition. |
| 47 | */ |
| 48 | virtual bool configureInputReport(InputDeviceNode* devNode, InputReportDefinition* report) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * If the mapper supports output events from the InputDevice, |
| 54 | * configureOutputReport will populate the InputReportDefinition and return |
| 55 | * true. If output is not supported, false is returned, and the InputDevice |
| 56 | * may free or re-use the InputReportDefinition. |
| 57 | */ |
| 58 | virtual bool configureOutputReport(InputDeviceNode* devNode, InputReportDefinition* report) { |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | // Set the InputDeviceHandle after registering the device with the host. |
| 63 | virtual void setDeviceHandle(InputDeviceHandle* handle) { mDeviceHandle = handle; } |
| 64 | // Process the InputEvent. |
| 65 | virtual void process(const InputEvent& event) = 0; |
| 66 | |
| 67 | protected: |
| 68 | virtual void setInputReportDefinition(InputReportDefinition* reportDef) final { |
| 69 | mInputReportDef = reportDef; |
| 70 | } |
| 71 | virtual void setOutputReportDefinition(InputReportDefinition* reportDef) final { |
| 72 | mOutputReportDef = reportDef; |
| 73 | } |
| 74 | virtual InputReportDefinition* getInputReportDefinition() final { return mInputReportDef; } |
| 75 | virtual InputReportDefinition* getOutputReportDefinition() final { return mOutputReportDef; } |
| 76 | virtual InputDeviceHandle* getDeviceHandle() final { return mDeviceHandle; } |
| 77 | virtual InputReport* getInputReport() final; |
| 78 | |
| 79 | private: |
| 80 | InputReportDefinition* mInputReportDef = nullptr; |
| 81 | InputReportDefinition* mOutputReportDef = nullptr; |
| 82 | InputDeviceHandle* mDeviceHandle = nullptr; |
| 83 | InputReport* mReport = nullptr; |
| 84 | }; |
| 85 | |
| 86 | } // namespace android |
| 87 | |
| 88 | #endif // ANDROID_INPUT_MAPPER_H_ |