diff options
| author | 2022-09-15 18:44:37 -0700 | |
|---|---|---|
| committer | 2022-09-27 12:00:46 -0700 | |
| commit | 51b46e2abaab95a07cc66116ffd4479ac1036a7a (patch) | |
| tree | fd4e016e9a868e20163e9bd1cea96e6e2ac92efc | |
| parent | 096257cc2054ac53864908ede08bdd06879d8370 (diff) | |
Add a generic 'notify' function
This new function will know how to route NotifyArgs. The caller doesn't
have to figure out the right invocation based on the args type.
Bug: 211379801
Test: m checkinput
Change-Id: I24cfc4aa0315eb20d008806b08eaf158ae09e719
| -rw-r--r-- | services/inputflinger/InputListener.cpp | 48 | ||||
| -rw-r--r-- | services/inputflinger/include/InputListener.h | 2 |
2 files changed, 28 insertions, 22 deletions
diff --git a/services/inputflinger/InputListener.cpp b/services/inputflinger/InputListener.cpp index 110f08bbe3..54d0e02e1e 100644 --- a/services/inputflinger/InputListener.cpp +++ b/services/inputflinger/InputListener.cpp @@ -231,6 +231,31 @@ NotifyPointerCaptureChangedArgs::NotifyPointerCaptureChangedArgs( int32_t id, nsecs_t eventTime, const PointerCaptureRequest& request) : id(id), eventTime(eventTime), request(request) {} +// --- InputListenerInterface --- + +// Helper to std::visit with lambdas. +template <typename... V> +struct Visitor : V... {}; +// explicit deduction guide (not needed as of C++20) +template <typename... V> +Visitor(V...) -> Visitor<V...>; + +void InputListenerInterface::notify(const NotifyArgs& generalArgs) { + Visitor v{ + [&](const NotifyConfigurationChangedArgs& args) { notifyConfigurationChanged(&args); }, + [&](const NotifyKeyArgs& args) { notifyKey(&args); }, + [&](const NotifyMotionArgs& args) { notifyMotion(&args); }, + [&](const NotifySwitchArgs& args) { notifySwitch(&args); }, + [&](const NotifySensorArgs& args) { notifySensor(&args); }, + [&](const NotifyVibratorStateArgs& args) { notifyVibratorState(&args); }, + [&](const NotifyDeviceResetArgs& args) { notifyDeviceReset(&args); }, + [&](const NotifyPointerCaptureChangedArgs& args) { + notifyPointerCaptureChanged(&args); + }, + }; + std::visit(v, generalArgs); +} + // --- QueuedInputListener --- static inline void traceEvent(const char* functionName, int32_t id) { @@ -284,30 +309,9 @@ void QueuedInputListener::notifyPointerCaptureChanged(const NotifyPointerCapture mArgsQueue.emplace_back(*args); } -// Helper to std::visit with lambdas. -template <typename... V> -struct Visitor : V... {}; -// explicit deduction guide (not needed as of C++20) -template <typename... V> -Visitor(V...) -> Visitor<V...>; - void QueuedInputListener::flush() { - Visitor v{ - [&](const NotifyConfigurationChangedArgs& args) { - mInnerListener.notifyConfigurationChanged(&args); - }, - [&](const NotifyKeyArgs& args) { mInnerListener.notifyKey(&args); }, - [&](const NotifyMotionArgs& args) { mInnerListener.notifyMotion(&args); }, - [&](const NotifySwitchArgs& args) { mInnerListener.notifySwitch(&args); }, - [&](const NotifySensorArgs& args) { mInnerListener.notifySensor(&args); }, - [&](const NotifyVibratorStateArgs& args) { mInnerListener.notifyVibratorState(&args); }, - [&](const NotifyDeviceResetArgs& args) { mInnerListener.notifyDeviceReset(&args); }, - [&](const NotifyPointerCaptureChangedArgs& args) { - mInnerListener.notifyPointerCaptureChanged(&args); - }, - }; for (const NotifyArgs& args : mArgsQueue) { - std::visit(v, args); + mInnerListener.notify(args); } mArgsQueue.clear(); } diff --git a/services/inputflinger/include/InputListener.h b/services/inputflinger/include/InputListener.h index 508d3410e6..036d57e1bb 100644 --- a/services/inputflinger/include/InputListener.h +++ b/services/inputflinger/include/InputListener.h @@ -233,6 +233,8 @@ public: virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) = 0; virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0; virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) = 0; + + void notify(const NotifyArgs& args); }; /* |