Use std::variant for NotifyArgs
Previously, NotifyArgs was a base class and we relied on inheritance in
order to refer to these args in a generic manner.
Unfortunately, this prevents us from being able to cast into a
descendant. If you got NotifyArgs, there was no way to figure out its
type.
In this CL, we switch to std::variant. Doing this allows us to remove
the inheritance, and several other functions. The classes are now mostly
about data.
This allows us to receive a generic NotifyArgs object and cast it into
NotifyMotionArgs (for example). This also allows us to separate
NotifyArgs from the InputListener interface (not done in this CL).
Furthermore, we don't need to store the args as unique_ptr anymore.
Bug: 211379801
Test: m checkinput
Change-Id: I5b10d485a9eb27b4ffb6a3a6e21227f52ac3dede
diff --git a/services/inputflinger/InputProcessor.h b/services/inputflinger/InputProcessor.h
index bbf391e..f4d02b6 100644
--- a/services/inputflinger/InputProcessor.h
+++ b/services/inputflinger/InputProcessor.h
@@ -35,12 +35,12 @@
struct ClassifierEvent {
ClassifierEventType type;
- std::unique_ptr<NotifyArgs> args;
+ std::optional<NotifyArgs> args;
- ClassifierEvent(ClassifierEventType type, std::unique_ptr<NotifyArgs> args);
- ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args);
- ClassifierEvent(std::unique_ptr<NotifyDeviceResetArgs> args);
- ClassifierEvent(ClassifierEvent&& other);
+ ClassifierEvent(ClassifierEventType type, std::optional<NotifyArgs> args);
+ ClassifierEvent(const NotifyMotionArgs& args);
+ ClassifierEvent(const NotifyDeviceResetArgs& args);
+ ClassifierEvent(ClassifierEvent&& other) = default;
ClassifierEvent& operator=(ClassifierEvent&& other);
// Convenience function to create a HAL_RESET event