Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51b46e2a authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

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
parent 096257cc
Loading
Loading
Loading
Loading
+26 −22
Original line number Diff line number Diff line
@@ -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();
}
+2 −0
Original line number Diff line number Diff line
@@ -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);
};

/*