xref: /aosp_15_r20/frameworks/native/services/inputflinger/include/InputListener.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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 notifyKey(const NotifyKeyArgs& args) = 0;
42     virtual void notifyMotion(const NotifyMotionArgs& args) = 0;
43     virtual void notifySwitch(const NotifySwitchArgs& args) = 0;
44     virtual void notifySensor(const NotifySensorArgs& args) = 0;
45     virtual void notifyVibratorState(const NotifyVibratorStateArgs& args) = 0;
46     virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) = 0;
47     virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) = 0;
48 
49     void notify(const NotifyArgs& args);
50 };
51 
52 /*
53  * An implementation of the listener interface that queues up and defers dispatch
54  * of decoded events until flushed.
55  */
56 class QueuedInputListener : public InputListenerInterface {
57 
58 public:
59     explicit QueuedInputListener(InputListenerInterface& innerListener);
60 
61     virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
62     virtual void notifyKey(const NotifyKeyArgs& args) override;
63     virtual void notifyMotion(const NotifyMotionArgs& args) override;
64     virtual void notifySwitch(const NotifySwitchArgs& args) override;
65     virtual void notifySensor(const NotifySensorArgs& args) override;
66     virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
67     void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
68     void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
69 
70     void flush();
71 
72 private:
73     InputListenerInterface& mInnerListener;
74     std::vector<NotifyArgs> mArgsQueue;
75 };
76 
77 /*
78  * An implementation of the listener interface that traces the calls to its inner listener.
79  */
80 class TracedInputListener : public InputListenerInterface {
81 public:
82     explicit TracedInputListener(const char* name, InputListenerInterface& innerListener);
83 
84     virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
85     virtual void notifyKey(const NotifyKeyArgs& args) override;
86     virtual void notifyMotion(const NotifyMotionArgs& args) override;
87     virtual void notifySwitch(const NotifySwitchArgs& args) override;
88     virtual void notifySensor(const NotifySensorArgs& args) override;
89     virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
90     void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
91     void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
92 
93 private:
94     InputListenerInterface& mInnerListener;
95     const char* mName;
96 };
97 
98 } // namespace android
99