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