/* * Deskflow -- mouse and keyboard sharing utility * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception */ #pragma once #include "IEventJob.h" //! Use a member function as an event job /*! An event job class that invokes a member function. */ template class TMethodEventJob : public IEventJob { public: //! run(event) invokes \c object->method(event, arg) TMethodEventJob(T *object, void (T::*method)(const Event &, void *), void *arg = nullptr); ~TMethodEventJob() override = default; // IJob overrides void run(const Event &) override; private: T *m_object; void (T::*m_method)(const Event &, void *); void *m_arg; }; template inline TMethodEventJob::TMethodEventJob(T *object, void (T::*method)(const Event &, void *), void *arg) : m_object(object), m_method(method), m_arg(arg) { // do nothing } template inline void TMethodEventJob::run(const Event &event) { if (m_object != nullptr) { (m_object->*m_method)(event, m_arg); } }