1*e01b6f76SAndroid Build Coastguard Worker /* 2*e01b6f76SAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*e01b6f76SAndroid Build Coastguard Worker * 4*e01b6f76SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*e01b6f76SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*e01b6f76SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*e01b6f76SAndroid Build Coastguard Worker * 8*e01b6f76SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*e01b6f76SAndroid Build Coastguard Worker * 10*e01b6f76SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*e01b6f76SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*e01b6f76SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e01b6f76SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*e01b6f76SAndroid Build Coastguard Worker * limitations under the License. 15*e01b6f76SAndroid Build Coastguard Worker */ 16*e01b6f76SAndroid Build Coastguard Worker 17*e01b6f76SAndroid Build Coastguard Worker #ifndef ANDROID_INPUT_MAPPER_H_ 18*e01b6f76SAndroid Build Coastguard Worker #define ANDROID_INPUT_MAPPER_H_ 19*e01b6f76SAndroid Build Coastguard Worker 20*e01b6f76SAndroid Build Coastguard Worker struct input_device_handle; 21*e01b6f76SAndroid Build Coastguard Worker 22*e01b6f76SAndroid Build Coastguard Worker namespace android { 23*e01b6f76SAndroid Build Coastguard Worker 24*e01b6f76SAndroid Build Coastguard Worker class InputDeviceNode; 25*e01b6f76SAndroid Build Coastguard Worker class InputReport; 26*e01b6f76SAndroid Build Coastguard Worker class InputReportDefinition; 27*e01b6f76SAndroid Build Coastguard Worker struct InputEvent; 28*e01b6f76SAndroid Build Coastguard Worker using InputDeviceHandle = struct input_device_handle; 29*e01b6f76SAndroid Build Coastguard Worker 30*e01b6f76SAndroid Build Coastguard Worker /** 31*e01b6f76SAndroid Build Coastguard Worker * An InputMapper processes raw evdev input events and combines them into 32*e01b6f76SAndroid Build Coastguard Worker * Android input HAL reports. A given InputMapper will focus on a particular 33*e01b6f76SAndroid Build Coastguard Worker * type of input, like key presses or touch events. A single InputDevice may 34*e01b6f76SAndroid Build Coastguard Worker * have multiple InputMappers, corresponding to the different types of inputs it 35*e01b6f76SAndroid Build Coastguard Worker * supports. 36*e01b6f76SAndroid Build Coastguard Worker */ 37*e01b6f76SAndroid Build Coastguard Worker class InputMapper { 38*e01b6f76SAndroid Build Coastguard Worker public: 39*e01b6f76SAndroid Build Coastguard Worker InputMapper() = default; ~InputMapper()40*e01b6f76SAndroid Build Coastguard Worker virtual ~InputMapper() {} 41*e01b6f76SAndroid Build Coastguard Worker 42*e01b6f76SAndroid Build Coastguard Worker /** 43*e01b6f76SAndroid Build Coastguard Worker * If the mapper supports input events from the InputDevice, 44*e01b6f76SAndroid Build Coastguard Worker * configureInputReport will populate the InputReportDefinition and return 45*e01b6f76SAndroid Build Coastguard Worker * true. If input is not supported, false is returned, and the InputDevice 46*e01b6f76SAndroid Build Coastguard Worker * may free or re-use the InputReportDefinition. 47*e01b6f76SAndroid Build Coastguard Worker */ configureInputReport(InputDeviceNode * devNode,InputReportDefinition * report)48*e01b6f76SAndroid Build Coastguard Worker virtual bool configureInputReport(InputDeviceNode* devNode, InputReportDefinition* report) { 49*e01b6f76SAndroid Build Coastguard Worker return false; 50*e01b6f76SAndroid Build Coastguard Worker } 51*e01b6f76SAndroid Build Coastguard Worker 52*e01b6f76SAndroid Build Coastguard Worker /** 53*e01b6f76SAndroid Build Coastguard Worker * If the mapper supports output events from the InputDevice, 54*e01b6f76SAndroid Build Coastguard Worker * configureOutputReport will populate the InputReportDefinition and return 55*e01b6f76SAndroid Build Coastguard Worker * true. If output is not supported, false is returned, and the InputDevice 56*e01b6f76SAndroid Build Coastguard Worker * may free or re-use the InputReportDefinition. 57*e01b6f76SAndroid Build Coastguard Worker */ configureOutputReport(InputDeviceNode * devNode,InputReportDefinition * report)58*e01b6f76SAndroid Build Coastguard Worker virtual bool configureOutputReport(InputDeviceNode* devNode, InputReportDefinition* report) { 59*e01b6f76SAndroid Build Coastguard Worker return false; 60*e01b6f76SAndroid Build Coastguard Worker } 61*e01b6f76SAndroid Build Coastguard Worker 62*e01b6f76SAndroid Build Coastguard Worker // Set the InputDeviceHandle after registering the device with the host. setDeviceHandle(InputDeviceHandle * handle)63*e01b6f76SAndroid Build Coastguard Worker virtual void setDeviceHandle(InputDeviceHandle* handle) { mDeviceHandle = handle; } 64*e01b6f76SAndroid Build Coastguard Worker // Process the InputEvent. 65*e01b6f76SAndroid Build Coastguard Worker virtual void process(const InputEvent& event) = 0; 66*e01b6f76SAndroid Build Coastguard Worker 67*e01b6f76SAndroid Build Coastguard Worker protected: setInputReportDefinition(InputReportDefinition * reportDef)68*e01b6f76SAndroid Build Coastguard Worker virtual void setInputReportDefinition(InputReportDefinition* reportDef) final { 69*e01b6f76SAndroid Build Coastguard Worker mInputReportDef = reportDef; 70*e01b6f76SAndroid Build Coastguard Worker } setOutputReportDefinition(InputReportDefinition * reportDef)71*e01b6f76SAndroid Build Coastguard Worker virtual void setOutputReportDefinition(InputReportDefinition* reportDef) final { 72*e01b6f76SAndroid Build Coastguard Worker mOutputReportDef = reportDef; 73*e01b6f76SAndroid Build Coastguard Worker } getInputReportDefinition()74*e01b6f76SAndroid Build Coastguard Worker virtual InputReportDefinition* getInputReportDefinition() final { return mInputReportDef; } getOutputReportDefinition()75*e01b6f76SAndroid Build Coastguard Worker virtual InputReportDefinition* getOutputReportDefinition() final { return mOutputReportDef; } getDeviceHandle()76*e01b6f76SAndroid Build Coastguard Worker virtual InputDeviceHandle* getDeviceHandle() final { return mDeviceHandle; } 77*e01b6f76SAndroid Build Coastguard Worker virtual InputReport* getInputReport() final; 78*e01b6f76SAndroid Build Coastguard Worker 79*e01b6f76SAndroid Build Coastguard Worker private: 80*e01b6f76SAndroid Build Coastguard Worker InputReportDefinition* mInputReportDef = nullptr; 81*e01b6f76SAndroid Build Coastguard Worker InputReportDefinition* mOutputReportDef = nullptr; 82*e01b6f76SAndroid Build Coastguard Worker InputDeviceHandle* mDeviceHandle = nullptr; 83*e01b6f76SAndroid Build Coastguard Worker InputReport* mReport = nullptr; 84*e01b6f76SAndroid Build Coastguard Worker }; 85*e01b6f76SAndroid Build Coastguard Worker 86*e01b6f76SAndroid Build Coastguard Worker } // namespace android 87*e01b6f76SAndroid Build Coastguard Worker 88*e01b6f76SAndroid Build Coastguard Worker #endif // ANDROID_INPUT_MAPPER_H_ 89