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

Commit 454b64e3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Avoid using raw pointers in QueuedInputListener"

parents 4f0ed394 542398ea
Loading
Loading
Loading
Loading
+9 −19
Original line number Diff line number Diff line
@@ -334,60 +334,50 @@ static inline void traceEvent(const char* functionName, int32_t id) {
QueuedInputListener::QueuedInputListener(InputListenerInterface& innerListener)
      : mInnerListener(innerListener) {}

QueuedInputListener::~QueuedInputListener() {
    size_t count = mArgsQueue.size();
    for (size_t i = 0; i < count; i++) {
        delete mArgsQueue[i];
    }
}

void QueuedInputListener::notifyConfigurationChanged(
        const NotifyConfigurationChangedArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyConfigurationChangedArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyConfigurationChangedArgs>(*args));
}

void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyKeyArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyKeyArgs>(*args));
}

void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyMotionArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyMotionArgs>(*args));
}

void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifySwitchArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifySwitchArgs>(*args));
}

void QueuedInputListener::notifySensor(const NotifySensorArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifySensorArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifySensorArgs>(*args));
}

void QueuedInputListener::notifyVibratorState(const NotifyVibratorStateArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyVibratorStateArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyVibratorStateArgs>(*args));
}

void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyDeviceResetArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyDeviceResetArgs>(*args));
}

void QueuedInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) {
    traceEvent(__func__, args->id);
    mArgsQueue.push_back(new NotifyPointerCaptureChangedArgs(*args));
    mArgsQueue.emplace_back(std::make_unique<NotifyPointerCaptureChangedArgs>(*args));
}

void QueuedInputListener::flush() {
    size_t count = mArgsQueue.size();
    for (size_t i = 0; i < count; i++) {
        NotifyArgs* args = mArgsQueue[i];
    for (const std::unique_ptr<NotifyArgs>& args : mArgsQueue) {
        args->notify(mInnerListener);
        delete args;
    }
    mArgsQueue.clear();
}
+1 −2
Original line number Diff line number Diff line
@@ -274,7 +274,6 @@ class QueuedInputListener : public InputListenerInterface {

public:
    explicit QueuedInputListener(InputListenerInterface& innerListener);
    virtual ~QueuedInputListener();

    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
    virtual void notifyKey(const NotifyKeyArgs* args) override;
@@ -289,7 +288,7 @@ public:

private:
    InputListenerInterface& mInnerListener;
    std::vector<NotifyArgs*> mArgsQueue;
    std::vector<std::unique_ptr<NotifyArgs>> mArgsQueue;
};

} // namespace android