1 /* 2 * Copyright (C) 2011 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 #pragma once 18 19 #include <vector> 20 21 #include <input/Input.h> 22 #include <input/InputDevice.h> 23 #include <input/TouchVideoFrame.h> 24 #include "NotifyArgs.h" 25 26 namespace android { 27 28 std::list<NotifyArgs>& operator+=(std::list<NotifyArgs>& keep, std::list<NotifyArgs>&& consume); 29 30 /* 31 * The interface used by the InputReader to notify the InputListener about input events. 32 */ 33 class InputListenerInterface { 34 public: InputListenerInterface()35 InputListenerInterface() { } 36 InputListenerInterface(const InputListenerInterface&) = delete; 37 InputListenerInterface& operator=(const InputListenerInterface&) = delete; ~InputListenerInterface()38 virtual ~InputListenerInterface() { } 39 40 virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) = 0; 41 virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) = 0; 42 virtual void notifyKey(const NotifyKeyArgs& args) = 0; 43 virtual void notifyMotion(const NotifyMotionArgs& args) = 0; 44 virtual void notifySwitch(const NotifySwitchArgs& args) = 0; 45 virtual void notifySensor(const NotifySensorArgs& args) = 0; 46 virtual void notifyVibratorState(const NotifyVibratorStateArgs& args) = 0; 47 virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) = 0; 48 virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) = 0; 49 50 void notify(const NotifyArgs& args); 51 }; 52 53 /* 54 * An implementation of the listener interface that queues up and defers dispatch 55 * of decoded events until flushed. 56 */ 57 class QueuedInputListener : public InputListenerInterface { 58 59 public: 60 explicit QueuedInputListener(InputListenerInterface& innerListener); 61 62 virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override; 63 virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override; 64 virtual void notifyKey(const NotifyKeyArgs& args) override; 65 virtual void notifyMotion(const NotifyMotionArgs& args) override; 66 virtual void notifySwitch(const NotifySwitchArgs& args) override; 67 virtual void notifySensor(const NotifySensorArgs& args) override; 68 virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) override; 69 void notifyVibratorState(const NotifyVibratorStateArgs& args) override; 70 void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override; 71 72 void flush(); 73 74 private: 75 InputListenerInterface& mInnerListener; 76 std::vector<NotifyArgs> mArgsQueue; 77 }; 78 79 /* 80 * An implementation of the listener interface that traces the calls to its inner listener. 81 */ 82 class TracedInputListener : public InputListenerInterface { 83 public: 84 explicit TracedInputListener(const char* name, InputListenerInterface& innerListener); 85 86 virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override; 87 virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override; 88 virtual void notifyKey(const NotifyKeyArgs& args) override; 89 virtual void notifyMotion(const NotifyMotionArgs& args) override; 90 virtual void notifySwitch(const NotifySwitchArgs& args) override; 91 virtual void notifySensor(const NotifySensorArgs& args) override; 92 virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) override; 93 void notifyVibratorState(const NotifyVibratorStateArgs& args) override; 94 void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override; 95 96 private: 97 InputListenerInterface& mInnerListener; 98 const char* mName; 99 }; 100 101 } // namespace android 102