From 3a35b183d35598b6ac5b6f18635decf08f2d30eb Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Wed, 18 Jun 2025 00:17:54 -0400 Subject: [PATCH] refactor: use std::function for Event callback based on https://github.com/input-leap/input-leap/pull/1552/commits/6d347337c3596cf7c70d4812651287964628643e --- src/lib/base/CMakeLists.txt | 1 - src/lib/base/EventQueue.cpp | 56 ++---- src/lib/base/EventQueue.h | 7 +- src/lib/base/IEventQueue.h | 17 +- src/lib/base/TMethodEventJob.h | 46 ----- src/lib/client/Client.cpp | 109 +++++------ src/lib/client/Client.h | 23 +-- src/lib/client/ServerProxy.cpp | 26 +-- src/lib/client/ServerProxy.h | 7 +- src/lib/deskflow/ClientApp.cpp | 59 +++--- src/lib/deskflow/ClientApp.h | 13 +- src/lib/deskflow/DaemonApp.h | 1 - src/lib/deskflow/IPlatformScreen.h | 8 +- src/lib/deskflow/PacketStreamFilter.cpp | 1 - src/lib/deskflow/PlatformScreen.h | 2 +- src/lib/deskflow/Screen.cpp | 1 - src/lib/deskflow/ServerApp.cpp | 90 ++++----- src/lib/deskflow/ServerApp.h | 23 +-- src/lib/io/StreamFilter.cpp | 11 +- src/lib/io/StreamFilter.h | 3 +- src/lib/net/SecureSocket.cpp | 11 +- src/lib/net/SecureSocket.h | 2 +- src/lib/net/TCPSocket.cpp | 1 - src/lib/platform/EiScreen.cpp | 27 ++- src/lib/platform/EiScreen.h | 6 +- src/lib/platform/MSWindowsDesks.cpp | 8 +- src/lib/platform/MSWindowsDesks.h | 3 +- src/lib/platform/MSWindowsScreen.cpp | 17 +- src/lib/platform/MSWindowsScreen.h | 5 +- src/lib/platform/OSXScreen.h | 7 +- src/lib/platform/OSXScreen.mm | 26 ++- src/lib/platform/XWindowsScreen.cpp | 11 +- src/lib/platform/XWindowsScreen.h | 3 +- src/lib/platform/XWindowsScreenSaver.cpp | 8 +- src/lib/platform/XWindowsScreenSaver.h | 3 +- src/lib/server/ClientListener.cpp | 52 ++--- src/lib/server/ClientListener.h | 10 +- src/lib/server/ClientProxy1_0.cpp | 47 ++--- src/lib/server/ClientProxy1_0.h | 9 +- src/lib/server/ClientProxy1_3.cpp | 9 +- src/lib/server/ClientProxy1_3.h | 3 +- src/lib/server/ClientProxy1_4.cpp | 1 - src/lib/server/ClientProxy1_5.cpp | 1 - src/lib/server/ClientProxy1_6.cpp | 8 +- src/lib/server/ClientProxy1_6.h | 2 +- src/lib/server/ClientProxy1_7.cpp | 1 - src/lib/server/ClientProxyUnknown.cpp | 62 +++--- src/lib/server/ClientProxyUnknown.h | 11 +- src/lib/server/InputFilter.cpp | 60 +++--- src/lib/server/InputFilter.h | 5 +- src/lib/server/Server.cpp | 185 ++++++++---------- src/lib/server/Server.h | 45 ++--- .../mock/deskflow/MockEventQueue.h | 3 +- 53 files changed, 476 insertions(+), 680 deletions(-) delete mode 100644 src/lib/base/TMethodEventJob.h diff --git a/src/lib/base/CMakeLists.txt b/src/lib/base/CMakeLists.txt index e89aca717..e654cd696 100644 --- a/src/lib/base/CMakeLists.txt +++ b/src/lib/base/CMakeLists.txt @@ -33,7 +33,6 @@ add_library(base STATIC Stopwatch.h String.cpp String.h - TMethodEventJob.h TMethodJob.h Unicode.cpp Unicode.h diff --git a/src/lib/base/EventQueue.cpp b/src/lib/base/EventQueue.cpp index 37ad8a2fe..6f93aa9d1 100644 --- a/src/lib/base/EventQueue.cpp +++ b/src/lib/base/EventQueue.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -8,7 +9,6 @@ #include "base/EventQueue.h" #include "arch/Arch.h" -#include "base/IEventJob.h" #include "base/Log.h" #include "base/SimpleEventQueueBuffer.h" #include "mt/Lock.h" @@ -159,12 +159,12 @@ bool EventQueue::getEvent(Event &event, double timeout) bool EventQueue::dispatchEvent(const Event &event) { void *target = event.getTarget(); - IEventJob *job = getHandler(event.getType(), target); - if (job == nullptr) { - job = getHandler(EventTypes::Unknown, target); + if (const auto *type_handler = getHandler(event.getType(), target); type_handler) { + (*type_handler)(event); + return true; } - if (job != nullptr) { - job->run(event); + if (const auto *any_handler = getHandler(EventTypes::Unknown, target); any_handler) { + (*any_handler)(event); return true; } return false; @@ -257,46 +257,32 @@ void EventQueue::deleteTimer(EventQueueTimer *timer) m_buffer->deleteTimer(timer); } -void EventQueue::adoptHandler(EventTypes type, void *target, IEventJob *handler) +void EventQueue::addHandler(EventTypes type, void *target, const EventHandler &handler) { std::scoped_lock lock{m_mutex}; - m_handlers[target][type].reset(handler); + m_handlers[target][type] = handler; } void EventQueue::removeHandler(EventTypes type, void *target) { - std::unique_ptr handler; - { - std::scoped_lock lock{m_mutex}; - HandlerTable::iterator index = m_handlers.find(target); - if (index != m_handlers.end()) { - TypeHandlerTable &typeHandlers = index->second; - TypeHandlerTable::iterator index2 = typeHandlers.find(type); - if (index2 != typeHandlers.end()) { - handler = std::move(index2->second); - typeHandlers.erase(index2); - } + std::scoped_lock lock{m_mutex}; + HandlerTable::iterator index = m_handlers.find(target); + if (index != m_handlers.end()) { + TypeHandlerTable &typeHandlers = index->second; + TypeHandlerTable::iterator index2 = typeHandlers.find(type); + if (index2 != typeHandlers.end()) { + typeHandlers.erase(index2); } } - // handler is erased here. It is done outside of lock in order to avoid potential deadlock. } void EventQueue::removeHandlers(void *target) { - std::vector> handlers; - { - std::scoped_lock lock{m_mutex}; - HandlerTable::iterator index = m_handlers.find(target); - if (index != m_handlers.end()) { - // copy to handlers array and clear table for target - TypeHandlerTable &typeHandlers = index->second; - for (auto &[key, value] : typeHandlers) { - handlers.push_back(std::move(value)); - } - typeHandlers.clear(); - } + std::scoped_lock lock{m_mutex}; + HandlerTable::iterator index = m_handlers.find(target); + if (index != m_handlers.end()) { + index->second.clear(); } - // handler is erased here. It is done outside of lock in order to avoid potential deadlock. } bool EventQueue::isEmpty() const @@ -304,14 +290,14 @@ bool EventQueue::isEmpty() const return (m_buffer->isEmpty() && getNextTimerTimeout() != 0.0); } -IEventJob *EventQueue::getHandler(EventTypes type, void *target) const +const EventQueue::EventHandler *EventQueue::getHandler(EventTypes type, void *target) const { std::scoped_lock lock{m_mutex}; if (HandlerTable::const_iterator index = m_handlers.find(target); index != m_handlers.end()) { const TypeHandlerTable &typeHandlers = index->second; TypeHandlerTable::const_iterator index2 = typeHandlers.find(type); if (index2 != typeHandlers.end()) { - return index2->second.get(); + return &index2->second; } } return nullptr; diff --git a/src/lib/base/EventQueue.h b/src/lib/base/EventQueue.h index 4a91bb83b..f3548f654 100644 --- a/src/lib/base/EventQueue.h +++ b/src/lib/base/EventQueue.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -43,15 +44,15 @@ public: EventQueueTimer *newTimer(double duration, void *target) override; EventQueueTimer *newOneShotTimer(double duration, void *target) override; void deleteTimer(EventQueueTimer *) override; - void adoptHandler(EventTypes type, void *target, IEventJob *handler) override; + void addHandler(EventTypes type, void *target, const EventHandler &handler) override; void removeHandler(EventTypes type, void *target) override; void removeHandlers(void *target) override; bool isEmpty() const override; - IEventJob *getHandler(EventTypes type, void *target) const override; void *getSystemTarget() override; void waitForReady() const override; private: + const EventHandler *getHandler(EventTypes type, void *target) const; uint32_t saveEvent(const Event &event); Event removeEvent(uint32_t eventID); bool hasTimerExpired(Event &event); @@ -99,7 +100,7 @@ private: using TimerQueue = PriorityQueue; using EventTable = std::map; using EventIDList = std::vector; - using TypeHandlerTable = std::map>; + using TypeHandlerTable = std::map; using HandlerTable = std::map; int m_systemTarget = 0; diff --git a/src/lib/base/IEventQueue.h b/src/lib/base/IEventQueue.h index bd1a0701d..584e3c680 100644 --- a/src/lib/base/IEventQueue.h +++ b/src/lib/base/IEventQueue.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -10,9 +11,10 @@ #include "base/Event.h" #include "base/EventTypes.h" #include "common/IInterface.h" + +#include #include -class IEventJob; class IEventQueueBuffer; // Opaque type for timer info. This is defined by subclasses of @@ -29,6 +31,7 @@ timers which generate events periodically. class IEventQueue : public IInterface { public: + using EventHandler = std::function; class TimerEvent { public: @@ -64,6 +67,9 @@ public: /*! Looks up the dispatcher for the event's target and invokes it. Returns true iff a dispatcher exists for the target. + + The caller must ensure that the target of the event is not removed by removeHandler() or + removeHandlers(). */ virtual bool dispatchEvent(const Event &event) = 0; @@ -119,7 +125,7 @@ public: of type \p type. If no such handler exists it will use the handler for \p target and type \p kUnknown if it exists. */ - virtual void adoptHandler(EventTypes type, void *target, IEventJob *handler) = 0; + virtual void addHandler(EventTypes type, void *target, const EventHandler &handler) = 0; //! Unregister an event handler for an event type /*! @@ -152,13 +158,6 @@ public: */ virtual bool isEmpty() const = 0; - //! Get an event handler - /*! - Finds and returns the event handler for the \p type, \p target pair - if it exists, otherwise it returns nullptr. - */ - virtual IEventJob *getHandler(EventTypes type, void *target) const = 0; - //! Get the system event type target /*! Returns the target to use for dispatching \c EventTypes::System events. diff --git a/src/lib/base/TMethodEventJob.h b/src/lib/base/TMethodEventJob.h deleted file mode 100644 index c2cf0d87b..000000000 --- a/src/lib/base/TMethodEventJob.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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); - } -} diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 597dfc9d0..f9f62cc25 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -11,7 +11,6 @@ #include "arch/Arch.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "base/TMethodJob.h" #include "client/ServerProxy.h" #include "deskflow/AppUtil.h" @@ -60,12 +59,8 @@ Client::Client( assert(m_screen != nullptr); // register suspend/resume event handlers - m_events->adoptHandler( - EventTypes::ScreenSuspend, getEventTarget(), new TMethodEventJob(this, &Client::handleSuspend) - ); - m_events->adoptHandler( - EventTypes::ScreenResume, getEventTarget(), new TMethodEventJob(this, &Client::handleResume) - ); + m_events->addHandler(EventTypes::ScreenSuspend, getEventTarget(), [this](const auto &) { handleSuspend(); }); + m_events->addHandler(EventTypes::ScreenResume, getEventTarget(), [this](const auto &) { handleResume(); }); m_pHelloBack = std::make_unique(std::make_shared( [this]() { @@ -395,51 +390,41 @@ void Client::setupConnecting() assert(m_stream != nullptr); if (m_args.m_enableCrypto) { - m_events->adoptHandler( - EventTypes::DataSocketSecureConnected, m_stream->getEventTarget(), - new TMethodEventJob(this, &Client::handleConnected) - ); + m_events->addHandler(EventTypes::DataSocketSecureConnected, m_stream->getEventTarget(), [this](const auto &) { + handleConnected(); + }); } else { - m_events->adoptHandler( - EventTypes::DataSocketConnected, m_stream->getEventTarget(), - new TMethodEventJob(this, &Client::handleConnected) - ); + m_events->addHandler(EventTypes::DataSocketConnected, m_stream->getEventTarget(), [this](const auto &) { + handleConnected(); + }); } - - m_events->adoptHandler( - EventTypes::DataSocketConnectionFailed, m_stream->getEventTarget(), - new TMethodEventJob(this, &Client::handleConnectionFailed) - ); + m_events->addHandler(EventTypes::DataSocketConnectionFailed, m_stream->getEventTarget(), [this](const auto &e) { + handleConnectionFailed(e); + }); } void Client::setupConnection() { assert(m_stream != nullptr); - m_events->adoptHandler( - EventTypes::SocketDisconnected, m_stream->getEventTarget(), - new TMethodEventJob(this, &Client::handleDisconnected) - ); - m_events->adoptHandler( - EventTypes::StreamInputReady, m_stream->getEventTarget(), new TMethodEventJob(this, &Client::handleHello) - ); - m_events->adoptHandler( - EventTypes::StreamOutputError, m_stream->getEventTarget(), - new TMethodEventJob(this, &Client::handleOutputError) - ); - m_events->adoptHandler( - EventTypes::StreamInputShutdown, m_stream->getEventTarget(), - new TMethodEventJob(this, &Client::handleDisconnected) - ); - m_events->adoptHandler( - EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), - new TMethodEventJob(this, &Client::handleDisconnected) - ); - - m_events->adoptHandler( - EventTypes::SocketStopRetry, m_stream->getEventTarget(), - new TMethodEventJob(this, &Client::handleStopRetry) - ); + m_events->addHandler(EventTypes::SocketDisconnected, m_stream->getEventTarget(), [this](const auto &) { + handleDisconnected(); + }); + m_events->addHandler(EventTypes::StreamInputReady, m_stream->getEventTarget(), [this](const auto &) { + handleHello(); + }); + m_events->addHandler(EventTypes::StreamOutputError, m_stream->getEventTarget(), [this](const auto &) { + handleOutputError(); + }); + m_events->addHandler(EventTypes::StreamInputShutdown, m_stream->getEventTarget(), [this](const auto &) { + handleDisconnected(); + }); + m_events->addHandler(EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), [this](const auto &) { + handleDisconnected(); + }); + m_events->addHandler(EventTypes::SocketStopRetry, m_stream->getEventTarget(), [this](const auto &) { + handleStopRetry(); + }); } void Client::setupScreen() @@ -448,19 +433,19 @@ void Client::setupScreen() m_ready = false; m_server = new ServerProxy(this, m_stream, m_events); - m_events->adoptHandler( - EventTypes::ScreenShapeChanged, getEventTarget(), new TMethodEventJob(this, &Client::handleShapeChanged) - ); - m_events->adoptHandler( - EventTypes::ClipboardGrabbed, getEventTarget(), new TMethodEventJob(this, &Client::handleClipboardGrabbed) - ); + m_events->addHandler(EventTypes::ScreenShapeChanged, getEventTarget(), [this](const auto &) { + handleShapeChanged(); + }); + m_events->addHandler(EventTypes::ClipboardGrabbed, getEventTarget(), [this](const auto &e) { + handleClipboardGrabbed(e); + }); } void Client::setupTimer() { assert(m_timer == nullptr); m_timer = m_events->newOneShotTimer(2.0, nullptr); - m_events->adoptHandler(EventTypes::Timer, m_timer, new TMethodEventJob(this, &Client::handleConnectTimeout)); + m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { handleConnectTimeout(); }); } void Client::cleanup() @@ -522,7 +507,7 @@ void Client::cleanupStream() m_stream = nullptr; } -void Client::handleConnected(const Event &, void *) +void Client::handleConnected() { LOG((CLOG_DEBUG1 "connected, waiting for hello")); cleanupConnecting(); @@ -536,7 +521,7 @@ void Client::handleConnected(const Event &, void *) } } -void Client::handleConnectionFailed(const Event &event, void *) +void Client::handleConnectionFailed(const Event &event) { auto *info = static_cast(event.getData()); @@ -548,7 +533,7 @@ void Client::handleConnectionFailed(const Event &event, void *) delete info; } -void Client::handleConnectTimeout(const Event &, void *) +void Client::handleConnectTimeout() { cleanupTimer(); cleanupConnecting(); @@ -558,7 +543,7 @@ void Client::handleConnectTimeout(const Event &, void *) sendConnectionFailedEvent("Timed out"); } -void Client::handleOutputError(const Event &, void *) +void Client::handleOutputError() { cleanupTimer(); cleanupScreen(); @@ -567,7 +552,7 @@ void Client::handleOutputError(const Event &, void *) sendEvent(EventTypes::ClientDisconnected, nullptr); } -void Client::handleDisconnected(const Event &, void *) +void Client::handleDisconnected() { cleanupTimer(); cleanupScreen(); @@ -576,13 +561,13 @@ void Client::handleDisconnected(const Event &, void *) sendEvent(EventTypes::ClientDisconnected, nullptr); } -void Client::handleShapeChanged(const Event &, void *) +void Client::handleShapeChanged() { LOG((CLOG_DEBUG "resolution changed")); m_server->onInfoChanged(); } -void Client::handleClipboardGrabbed(const Event &event, void *) +void Client::handleClipboardGrabbed(const Event &event) { if (!m_enableClipboard || (m_maximumClipboardSize == 0)) { return; @@ -605,7 +590,7 @@ void Client::handleClipboardGrabbed(const Event &event, void *) } } -void Client::handleHello(const Event &, void *) +void Client::handleHello() { m_pHelloBack->handleHello(m_stream, m_name); @@ -621,7 +606,7 @@ void Client::handleHello(const Event &, void *) } } -void Client::handleSuspend(const Event &, void *) +void Client::handleSuspend() { if (!m_suspended) { LOG((CLOG_INFO "suspend")); @@ -632,7 +617,7 @@ void Client::handleSuspend(const Event &, void *) } } -void Client::handleResume(const Event &, void *) +void Client::handleResume() { if (m_suspended) { LOG((CLOG_INFO "resume")); @@ -661,7 +646,7 @@ void Client::bindNetworkInterface(IDataSocket *socket) const } } -void Client::handleStopRetry(const Event &, void *) +void Client::handleStopRetry() { m_args.m_restartable = false; } diff --git a/src/lib/client/Client.h b/src/lib/client/Client.h index e0c1cb11f..0a85bf9d8 100644 --- a/src/lib/client/Client.h +++ b/src/lib/client/Client.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -168,17 +169,17 @@ private: void cleanupScreen(); void cleanupTimer(); void cleanupStream(); - void handleConnected(const Event &, void *); - void handleConnectionFailed(const Event &, void *); - void handleConnectTimeout(const Event &, void *); - void handleOutputError(const Event &, void *); - void handleDisconnected(const Event &, void *); - void handleShapeChanged(const Event &, void *); - void handleClipboardGrabbed(const Event &, void *); - void handleHello(const Event &, void *); - void handleSuspend(const Event &event, void *); - void handleResume(const Event &event, void *); - void handleStopRetry(const Event &, void *); + void handleConnected(); + void handleConnectionFailed(const Event &event); + void handleConnectTimeout(); + void handleOutputError(); + void handleDisconnected(); + void handleShapeChanged(); + void handleClipboardGrabbed(const Event &event); + void handleHello(); + void handleSuspend(); + void handleResume(); + void handleStopRetry(); void sendClipboardThread(void *); void bindNetworkInterface(IDataSocket *socket) const; diff --git a/src/lib/client/ServerProxy.cpp b/src/lib/client/ServerProxy.cpp index 15e03f457..689501e78 100644 --- a/src/lib/client/ServerProxy.cpp +++ b/src/lib/client/ServerProxy.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -9,7 +10,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "base/XBase.h" #include "client/Client.h" #include "deskflow/AppUtil.h" @@ -44,15 +44,10 @@ ServerProxy::ServerProxy(Client *client, deskflow::IStream *stream, IEventQueue m_modifierTranslationTable[id] = id; // handle data on stream - m_events->adoptHandler( - EventTypes::StreamInputReady, m_stream->getEventTarget(), - new TMethodEventJob(this, &ServerProxy::handleData) - ); - - m_events->adoptHandler( - EventTypes::ClipboardSending, this, - new TMethodEventJob(this, &ServerProxy::handleClipboardSendingEvent) - ); + m_events->addHandler(EventTypes::StreamInputReady, m_stream->getEventTarget(), [this](const auto &) { + handleData(); + }); + m_events->addHandler(EventTypes::ClipboardSending, this, [this](const auto &e) { handleClipboardSendingEvent(e); }); // send heartbeat setKeepAliveRate(kKeepAliveRate); @@ -73,10 +68,7 @@ void ServerProxy::resetKeepAliveAlarm() } if (m_keepAliveAlarm > 0.0) { m_keepAliveAlarmTimer = m_events->newOneShotTimer(m_keepAliveAlarm, nullptr); - m_events->adoptHandler( - EventTypes::Timer, m_keepAliveAlarmTimer, - new TMethodEventJob(this, &ServerProxy::handleKeepAliveAlarm) - ); + m_events->addHandler(EventTypes::Timer, m_keepAliveAlarmTimer, [this](const auto &) { handleKeepAliveAlarm(); }); } } @@ -86,7 +78,7 @@ void ServerProxy::setKeepAliveRate(double rate) resetKeepAliveAlarm(); } -void ServerProxy::handleData(const Event &, void *) +void ServerProxy::handleData() { // handle messages until there are no more. first read message code. uint8_t code[4]; @@ -333,7 +325,7 @@ ServerProxy::EResult ServerProxy::parseMessage(const uint8_t *code) return kOkay; } -void ServerProxy::handleKeepAliveAlarm(const Event &, void *) +void ServerProxy::handleKeepAliveAlarm() { LOG((CLOG_NOTE "server is dead")); m_client->disconnect("server is not responding"); @@ -813,7 +805,7 @@ void ServerProxy::infoAcknowledgment() m_ignoreMouse = false; } -void ServerProxy::handleClipboardSendingEvent(const Event &event, void *) +void ServerProxy::handleClipboardSendingEvent(const Event &event) { ClipboardChunk::send(m_stream, event.getDataObject()); } diff --git a/src/lib/client/ServerProxy.h b/src/lib/client/ServerProxy.h index c16b42728..a74c9ba35 100644 --- a/src/lib/client/ServerProxy.h +++ b/src/lib/client/ServerProxy.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -74,8 +75,8 @@ private: KeyModifierMask translateModifierMask(KeyModifierMask) const; // event handlers - void handleData(const Event &, void *); - void handleKeepAliveAlarm(const Event &, void *); + void handleData(); + void handleKeepAliveAlarm(); // message handlers void enter(); @@ -95,7 +96,7 @@ private: void setOptions(); void queryInfo(); void infoAcknowledgment(); - void handleClipboardSendingEvent(const Event &, void *); + void handleClipboardSendingEvent(const Event &event); void secureInputNotification(); void setServerLanguages(); void setActiveServerLanguage(const std::string &language); diff --git a/src/lib/deskflow/ClientApp.cpp b/src/lib/deskflow/ClientApp.cpp index bc86c62f9..36733e7b4 100644 --- a/src/lib/deskflow/ClientApp.cpp +++ b/src/lib/deskflow/ClientApp.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -11,7 +12,6 @@ #include "base/Event.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "client/Client.h" #include "common/Constants.h" #include "deskflow/ArgParser.h" @@ -200,7 +200,7 @@ void ClientApp::updateStatus(const std::string &msg) const // do nothing } -void ClientApp::handleScreenError(const Event &, void *) +void ClientApp::handleScreenError() { LOG((CLOG_CRIT "error on screen")); m_events->addEvent(Event(EventTypes::Quit)); @@ -209,10 +209,9 @@ void ClientApp::handleScreenError(const Event &, void *) deskflow::Screen *ClientApp::openClientScreen() { deskflow::Screen *screen = createScreen(); - m_events->adoptHandler( - EventTypes::ScreenError, screen->getEventTarget(), - new TMethodEventJob(this, &ClientApp::handleScreenError) - ); + m_events->addHandler(EventTypes::ScreenError, screen->getEventTarget(), [this](const auto &) { + handleScreenError(); + }); return screen; } @@ -224,10 +223,9 @@ void ClientApp::closeClientScreen(deskflow::Screen *screen) } } -void ClientApp::handleClientRestart(const Event &, void *vtimer) +void ClientApp::handleClientRestart(const Event &, EventQueueTimer *timer) { // discard old timer - auto *timer = static_cast(vtimer); m_events->deleteTimer(timer); m_events->removeHandler(EventTypes::Timer, timer); @@ -240,18 +238,16 @@ void ClientApp::scheduleClientRestart(double retryTime) // install a timer and handler to retry later LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); EventQueueTimer *timer = m_events->newOneShotTimer(retryTime, nullptr); - m_events->adoptHandler( - EventTypes::Timer, timer, new TMethodEventJob(this, &ClientApp::handleClientRestart, timer) - ); + m_events->addHandler(EventTypes::Timer, timer, [this, timer](const auto &e) { handleClientRestart(e, timer); }); } -void ClientApp::handleClientConnected(const Event &, void *) +void ClientApp::handleClientConnected() { LOG((CLOG_NOTE "connected to server")); updateStatus(); } -void ClientApp::handleClientFailed(const Event &e, void *) +void ClientApp::handleClientFailed(const Event &e) { if ((++m_lastServerAddressIndex) < m_client->getLastResolvedAddressesCount()) { std::unique_ptr info(static_cast(e.getData())); @@ -263,11 +259,11 @@ void ClientApp::handleClientFailed(const Event &e, void *) } } else { m_lastServerAddressIndex = 0; - handleClientRefused(e, nullptr); + handleClientRefused(e); } } -void ClientApp::handleClientRefused(const Event &e, void *) +void ClientApp::handleClientRefused(const Event &e) { std::unique_ptr info(static_cast(e.getData())); @@ -283,7 +279,7 @@ void ClientApp::handleClientRefused(const Event &e, void *) } } -void ClientApp::handleClientDisconnected(const Event &, void *) +void ClientApp::handleClientDisconnected() { LOG((CLOG_NOTE "disconnected from server")); if (!args().m_restartable) { @@ -299,25 +295,18 @@ Client *ClientApp::openClient(const std::string &name, const NetworkAddress &add auto *client = new Client(m_events, name, address, getSocketFactory(), screen, args()); try { - m_events->adoptHandler( - EventTypes::ClientConnected, client->getEventTarget(), - new TMethodEventJob(this, &ClientApp::handleClientConnected) - ); - - m_events->adoptHandler( - EventTypes::ClientConnectionFailed, client->getEventTarget(), - new TMethodEventJob(this, &ClientApp::handleClientFailed) - ); - - m_events->adoptHandler( - EventTypes::ClientConnectionRefused, client->getEventTarget(), - new TMethodEventJob(this, &ClientApp::handleClientRefused) - ); - - m_events->adoptHandler( - EventTypes::ClientDisconnected, client->getEventTarget(), - new TMethodEventJob(this, &ClientApp::handleClientDisconnected) - ); + m_events->addHandler(EventTypes::ClientConnected, client->getEventTarget(), [this](const auto &) { + handleClientConnected(); + }); + m_events->addHandler(EventTypes::ClientConnectionFailed, client->getEventTarget(), [this](const auto &e) { + handleClientFailed(e); + }); + m_events->addHandler(EventTypes::ClientConnectionRefused, client->getEventTarget(), [this](const auto &e) { + handleClientRefused(e); + }); + m_events->addHandler(EventTypes::ClientDisconnected, client->getEventTarget(), [this](const auto &) { + handleClientDisconnected(); + }); } catch (std::bad_alloc &ba) { delete client; diff --git a/src/lib/deskflow/ClientApp.h b/src/lib/deskflow/ClientApp.h index 3f8424be8..cb4982ed9 100644 --- a/src/lib/deskflow/ClientApp.h +++ b/src/lib/deskflow/ClientApp.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -64,15 +65,15 @@ public: void updateStatus() const; void updateStatus(const std::string &msg) const; - void handleScreenError(const Event &, void *); + void handleScreenError(); deskflow::Screen *openClientScreen(); void closeClientScreen(deskflow::Screen *screen); - void handleClientRestart(const Event &, void *vtimer); + void handleClientRestart(const Event &, EventQueueTimer *vtimer); void scheduleClientRestart(double retryTime); - void handleClientConnected(const Event &, void *); - void handleClientFailed(const Event &e, void *); - void handleClientRefused(const Event &e, void *); - void handleClientDisconnected(const Event &, void *); + void handleClientConnected(); + void handleClientFailed(const Event &e); + void handleClientRefused(const Event &e); + void handleClientDisconnected(); Client *openClient(const std::string &name, const NetworkAddress &address, deskflow::Screen *screen); void closeClient(Client *client); bool startClient(); diff --git a/src/lib/deskflow/DaemonApp.h b/src/lib/deskflow/DaemonApp.h index bb680b4f3..ea71c00de 100644 --- a/src/lib/deskflow/DaemonApp.h +++ b/src/lib/deskflow/DaemonApp.h @@ -60,7 +60,6 @@ public: private: void daemonize(); void handleError(const char *message); - void handleIpcMessage(const Event &e, void *); int mainLoop(); int daemonLoop(); void saveLogLevel(const QString &logLevel) const; diff --git a/src/lib/deskflow/IPlatformScreen.h b/src/lib/deskflow/IPlatformScreen.h index e2408b6bf..c148db811 100644 --- a/src/lib/deskflow/IPlatformScreen.h +++ b/src/lib/deskflow/IPlatformScreen.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -192,10 +193,9 @@ protected: A platform screen is expected to install a handler for system events in its c'tor like so: \code - m_events->adoptHandler(EventTypes::System, + m_events->addHandler(EventTypes::System, m_events->getSystemTarget(), - new TMethodEventJob(this, - &CXXXPlatformScreen::handleSystemEvent)); + [this] (const auto &e) {handleSystemEvent(e);}); \endcode It should remove the handler in its d'tor. Override the \c handleSystemEvent() method to process system events. @@ -211,5 +211,5 @@ protected: The target of all events should be the value returned by \c getEventTarget(). */ - virtual void handleSystemEvent(const Event &event, void *) = 0; + virtual void handleSystemEvent(const Event &event) = 0; }; diff --git a/src/lib/deskflow/PacketStreamFilter.cpp b/src/lib/deskflow/PacketStreamFilter.cpp index 7f604771d..2569dd513 100644 --- a/src/lib/deskflow/PacketStreamFilter.cpp +++ b/src/lib/deskflow/PacketStreamFilter.cpp @@ -7,7 +7,6 @@ #include "deskflow/PacketStreamFilter.h" #include "base/IEventQueue.h" -#include "base/TMethodEventJob.h" #include "deskflow/ProtocolTypes.h" #include diff --git a/src/lib/deskflow/PlatformScreen.h b/src/lib/deskflow/PlatformScreen.h index a05a2d074..c3a059d9e 100644 --- a/src/lib/deskflow/PlatformScreen.h +++ b/src/lib/deskflow/PlatformScreen.h @@ -96,7 +96,7 @@ protected: virtual IKeyState *getKeyState() const = 0; // IPlatformScreen overrides - void handleSystemEvent(const Event &event, void *) override = 0; + void handleSystemEvent(const Event &event) override = 0; /*! * \brief mapClientScrollDirection diff --git a/src/lib/deskflow/Screen.cpp b/src/lib/deskflow/Screen.cpp index ea1cfe058..700d6805d 100644 --- a/src/lib/deskflow/Screen.cpp +++ b/src/lib/deskflow/Screen.cpp @@ -8,7 +8,6 @@ #include "deskflow/Screen.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/IPlatformScreen.h" #include "deskflow/ProtocolTypes.h" #include "server/ClientProxy.h" diff --git a/src/lib/deskflow/ServerApp.cpp b/src/lib/deskflow/ServerApp.cpp index 6a8d06a24..ad2acd613 100644 --- a/src/lib/deskflow/ServerApp.cpp +++ b/src/lib/deskflow/ServerApp.cpp @@ -12,7 +12,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" #include "base/Path.h" -#include "base/TMethodEventJob.h" #include "deskflow/App.h" #include "deskflow/ArgParser.h" #include "deskflow/Screen.h" @@ -150,7 +149,7 @@ void ServerApp::reloadSignalHandler(Arch::ESignal, void *) events->addEvent(Event(EventTypes::ServerAppReloadConfig, events->getSystemTarget())); } -void ServerApp::reloadConfig(const Event &, void *) +void ServerApp::reloadConfig() { LOG((CLOG_DEBUG "reload configuration")); if (loadConfig(args().m_configFile)) { @@ -195,16 +194,15 @@ bool ServerApp::loadConfig(const std::string &pathname) return false; } -void ServerApp::forceReconnect(const Event &, void *) +void ServerApp::forceReconnect() { if (m_server != nullptr) { m_server->disconnect(); } } -void ServerApp::handleClientConnected(const Event &, void *vlistener) +void ServerApp::handleClientConnected(const Event &, ClientListener *listener) { - auto *listener = static_cast(vlistener); ClientProxy *client = listener->getNextClient(); if (client != nullptr) { m_server->adoptClient(client); @@ -212,7 +210,7 @@ void ServerApp::handleClientConnected(const Event &, void *vlistener) } } -void ServerApp::handleClientsDisconnected(const Event &, void *) +void ServerApp::handleClientsDisconnected() { m_events->addEvent(Event(EventTypes::Quit)); } @@ -229,13 +227,8 @@ void ServerApp::closeServer(Server *server) // wait for clients to disconnect for up to timeout seconds double timeout = 3.0; EventQueueTimer *timer = m_events->newOneShotTimer(timeout, nullptr); - m_events->adoptHandler( - EventTypes::Timer, timer, new TMethodEventJob(this, &ServerApp::handleClientsDisconnected) - ); - m_events->adoptHandler( - EventTypes::ServerDisconnected, server, - new TMethodEventJob(this, &ServerApp::handleClientsDisconnected) - ); + m_events->addHandler(EventTypes::Timer, timer, [this](const auto &) { handleClientsDisconnected(); }); + m_events->addHandler(EventTypes::ServerDisconnected, server, [this](const auto &) { handleClientsDisconnected(); }); m_events->loop(); @@ -323,7 +316,7 @@ void ServerApp::cleanupServer() assert(m_serverState == kUninitialized); } -void ServerApp::retryHandler(const Event &, void *) +void ServerApp::retryHandler() { // discard old timer assert(m_timer != nullptr); @@ -410,7 +403,7 @@ bool ServerApp::initServer() assert(m_timer == nullptr); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); m_timer = m_events->newOneShotTimer(retryTime, nullptr); - m_events->adoptHandler(EventTypes::Timer, m_timer, new TMethodEventJob(this, &ServerApp::retryHandler)); + m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { retryHandler(); }); m_serverState = kInitializing; return true; } else { @@ -422,17 +415,11 @@ bool ServerApp::initServer() deskflow::Screen *ServerApp::openServerScreen() { deskflow::Screen *screen = createScreen(); - m_events->adoptHandler( - EventTypes::ScreenError, screen->getEventTarget(), - new TMethodEventJob(this, &ServerApp::handleScreenError) - ); - m_events->adoptHandler( - EventTypes::ScreenSuspend, screen->getEventTarget(), - new TMethodEventJob(this, &ServerApp::handleSuspend) - ); - m_events->adoptHandler( - EventTypes::ScreenResume, screen->getEventTarget(), new TMethodEventJob(this, &ServerApp::handleResume) - ); + m_events->addHandler(EventTypes::ScreenError, screen->getEventTarget(), [this](const auto &) { + handleScreenError(); + }); + m_events->addHandler(EventTypes::ScreenSuspend, screen->getEventTarget(), [this](const auto &) { handleSuspend(); }); + m_events->addHandler(EventTypes::ScreenResume, screen->getEventTarget(), [this](const auto &) { handleResume(); }); return screen; } @@ -488,7 +475,7 @@ bool ServerApp::startServer() const auto retryTime = 10.0; LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); m_timer = m_events->newOneShotTimer(retryTime, nullptr); - m_events->adoptHandler(EventTypes::Timer, m_timer, new TMethodEventJob(this, &ServerApp::retryHandler)); + m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { retryHandler(); }); m_serverState = kStarting; return true; } else { @@ -528,13 +515,13 @@ PrimaryClient *ServerApp::openPrimaryClient(const std::string &name, deskflow::S return new PrimaryClient(name, screen); } -void ServerApp::handleScreenError(const Event &, void *) +void ServerApp::handleScreenError() { LOG((CLOG_CRIT "error on screen")); m_events->addEvent(Event(EventTypes::Quit)); } -void ServerApp::handleSuspend(const Event &, void *) +void ServerApp::handleSuspend() { if (!m_suspended) { LOG((CLOG_INFO "suspend")); @@ -543,7 +530,7 @@ void ServerApp::handleSuspend(const Event &, void *) } } -void ServerApp::handleResume(const Event &, void *) +void ServerApp::handleResume() { if (m_suspended) { LOG((CLOG_INFO "resume")); @@ -559,10 +546,9 @@ ClientListener *ServerApp::openClientListener(const NetworkAddress &address) auto *listen = new ClientListener(getAddress(address), getSocketFactory(), m_events, securityLevel); - m_events->adoptHandler( - EventTypes::ClientListenerAccepted, listen, - new TMethodEventJob(this, &ServerApp::handleClientConnected, listen) - ); + m_events->addHandler(EventTypes::ClientListenerAccepted, listen, [this, listen](const auto &e) { + handleClientConnected(e, listen); + }); return listen; } @@ -571,13 +557,8 @@ Server *ServerApp::openServer(ServerConfig &config, PrimaryClient *primaryClient { auto *server = new Server(config, primaryClient, m_serverScreen, m_events, args()); try { - m_events->adoptHandler( - EventTypes::ServerDisconnected, server, new TMethodEventJob(this, &ServerApp::handleNoClients) - ); - - m_events->adoptHandler( - EventTypes::ServerScreenSwitched, server, new TMethodEventJob(this, &ServerApp::handleScreenSwitched) - ); + m_events->addHandler(EventTypes::ServerDisconnected, server, [this](const auto &) { handleNoClients(); }); + m_events->addHandler(EventTypes::ServerScreenSwitched, server, [this](const auto &e) { handleScreenSwitched(e); }); } catch (std::bad_alloc &ba) { delete server; @@ -587,12 +568,12 @@ Server *ServerApp::openServer(ServerConfig &config, PrimaryClient *primaryClient return server; } -void ServerApp::handleNoClients(const Event &, void *) +void ServerApp::handleNoClients() { updateStatus(); } -void ServerApp::handleScreenSwitched(const Event &e, void *) +void ServerApp::handleScreenSwitched(const Event &e) { // do nothing } @@ -640,24 +621,21 @@ int ServerApp::mainLoop() // handle hangup signal by reloading the server's configuration ARCH->setSignalHandler(Arch::kHANGUP, &reloadSignalHandler, nullptr); - m_events->adoptHandler( - EventTypes::ServerAppReloadConfig, m_events->getSystemTarget(), - new TMethodEventJob(this, &ServerApp::reloadConfig) - ); + m_events->addHandler(EventTypes::ServerAppReloadConfig, m_events->getSystemTarget(), [this](const auto &) { + reloadConfig(); + }); // handle force reconnect event by disconnecting clients. they'll // reconnect automatically. - m_events->adoptHandler( - EventTypes::ServerAppForceReconnect, m_events->getSystemTarget(), - new TMethodEventJob(this, &ServerApp::forceReconnect) - ); + m_events->addHandler(EventTypes::ServerAppForceReconnect, m_events->getSystemTarget(), [this](const auto &) { + forceReconnect(); + }); // to work around the sticky meta keys problem, we'll give users // the option to reset the state of the server. - m_events->adoptHandler( - EventTypes::ServerAppResetServer, m_events->getSystemTarget(), - new TMethodEventJob(this, &ServerApp::resetServer) - ); + m_events->addHandler(EventTypes::ServerAppResetServer, m_events->getSystemTarget(), [this](const auto &) { + resetServer(); + }); // run event loop. if startServer() failed we're supposed to retry // later. the timer installed by startServer() will take care of @@ -690,7 +668,7 @@ int ServerApp::mainLoop() return kExitSuccess; } -void ServerApp::resetServer(const Event &, void *) +void ServerApp::resetServer() { LOG((CLOG_DEBUG1 "resetting server")); stopServer(); diff --git a/src/lib/deskflow/ServerApp.h b/src/lib/deskflow/ServerApp.h index 79dd79057..0858cc6c3 100644 --- a/src/lib/deskflow/ServerApp.h +++ b/src/lib/deskflow/ServerApp.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -78,11 +79,11 @@ public: // Regular functions // - void reloadConfig(const Event &, void *); - void forceReconnect(const Event &, void *); - void resetServer(const Event &, void *); - void handleClientConnected(const Event &, void *vlistener); - void handleClientsDisconnected(const Event &, void *); + void reloadConfig(); + void forceReconnect(); + void resetServer(); + void handleClientConnected(const Event &e, ClientListener *listener); + void handleClientsDisconnected(); void closeServer(Server *server); void stopRetryTimer(); void updateStatus() const; @@ -93,15 +94,15 @@ public: void closeServerScreen(deskflow::Screen *screen); void cleanupServer(); bool initServer(); - void retryHandler(const Event &, void *); + void retryHandler(); deskflow::Screen *openServerScreen(); PrimaryClient *openPrimaryClient(const std::string &name, deskflow::Screen *screen); - void handleScreenError(const Event &, void *); - void handleSuspend(const Event &, void *); - void handleResume(const Event &, void *); + void handleScreenError(); + void handleSuspend(); + void handleResume(); ClientListener *openClientListener(const NetworkAddress &address); Server *openServer(ServerConfig &config, PrimaryClient *primaryClient); - void handleNoClients(const Event &, void *); + void handleNoClients(); bool startServer(); Server *getServerPtr() { @@ -124,7 +125,7 @@ public: } private: - void handleScreenSwitched(const Event &, void *data); + void handleScreenSwitched(const Event &e); ISocketFactory *getSocketFactory() const; NetworkAddress getAddress(const NetworkAddress &address) const; diff --git a/src/lib/io/StreamFilter.cpp b/src/lib/io/StreamFilter.cpp index b15a6a12a..f8ba77091 100644 --- a/src/lib/io/StreamFilter.cpp +++ b/src/lib/io/StreamFilter.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -7,7 +8,6 @@ #include "io/StreamFilter.h" #include "base/IEventQueue.h" -#include "base/TMethodEventJob.h" // // StreamFilter @@ -20,10 +20,9 @@ StreamFilter::StreamFilter(IEventQueue *events, deskflow::IStream *stream, bool { // replace handlers for m_stream m_events->removeHandlers(m_stream->getEventTarget()); - m_events->adoptHandler( - EventTypes::Unknown, m_stream->getEventTarget(), - new TMethodEventJob(this, &StreamFilter::handleUpstreamEvent) - ); + m_events->addHandler(EventTypes::Unknown, m_stream->getEventTarget(), [this](const auto &e) { + handleUpstreamEvent(e); + }); } StreamFilter::~StreamFilter() @@ -89,7 +88,7 @@ void StreamFilter::filterEvent(const Event &event) m_events->dispatchEvent(Event(event.getType(), getEventTarget(), event.getData())); } -void StreamFilter::handleUpstreamEvent(const Event &event, void *) +void StreamFilter::handleUpstreamEvent(const Event &event) { filterEvent(event); } diff --git a/src/lib/io/StreamFilter.h b/src/lib/io/StreamFilter.h index 4b8478ea6..bfe437d74 100644 --- a/src/lib/io/StreamFilter.h +++ b/src/lib/io/StreamFilter.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -59,7 +60,7 @@ protected: virtual void filterEvent(const Event &); private: - void handleUpstreamEvent(const Event &, void *); + void handleUpstreamEvent(const Event &); private: deskflow::IStream *m_stream; diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp index 88ddbddfe..e8dc4f1ea 100644 --- a/src/lib/net/SecureSocket.cpp +++ b/src/lib/net/SecureSocket.cpp @@ -12,7 +12,6 @@ #include "base/Log.h" #include "base/Path.h" #include "base/String.h" -#include "base/TMethodEventJob.h" #include "common/Settings.h" #include "mt/Lock.h" #include "net/FingerprintDatabase.h" @@ -87,11 +86,9 @@ void SecureSocket::close() void SecureSocket::connect(const NetworkAddress &addr) { - m_events->adoptHandler( - EventTypes::DataSocketConnected, getEventTarget(), - new TMethodEventJob(this, &SecureSocket::handleTCPConnected) - ); - + m_events->addHandler(EventTypes::DataSocketConnected, getEventTarget(), [this](const auto &e) { + handleTCPConnected(e); + }); TCPSocket::connect(addr); } @@ -728,7 +725,7 @@ ISocketMultiplexerJob *SecureSocket::serviceAccept(ISocketMultiplexerJob *job, b ); } -void SecureSocket::handleTCPConnected(const Event &, void *) +void SecureSocket::handleTCPConnected(const Event &) { if (getSocket() == nullptr) { LOG((CLOG_DEBUG "disregarding stale connect event")); diff --git a/src/lib/net/SecureSocket.h b/src/lib/net/SecureSocket.h index 01bf70c41..3561055dc 100644 --- a/src/lib/net/SecureSocket.h +++ b/src/lib/net/SecureSocket.h @@ -83,7 +83,7 @@ private: ISocketMultiplexerJob *serviceAccept(ISocketMultiplexerJob *, bool, bool, bool); - void handleTCPConnected(const Event &event, void *); + void handleTCPConnected(const Event &event); private: // all accesses to m_ssl must be protected by this mutex. The only function that is called diff --git a/src/lib/net/TCPSocket.cpp b/src/lib/net/TCPSocket.cpp index 86b4884f6..fb1dd7b04 100644 --- a/src/lib/net/TCPSocket.cpp +++ b/src/lib/net/TCPSocket.cpp @@ -9,7 +9,6 @@ #include "arch/Arch.h" #include "arch/XArch.h" -#include "base/IEventJob.h" #include "base/IEventQueue.h" #include "base/Log.h" #include "mt/Lock.h" diff --git a/src/lib/platform/EiScreen.cpp b/src/lib/platform/EiScreen.cpp index 0c3aa0c97..7d1ef5599 100644 --- a/src/lib/platform/EiScreen.cpp +++ b/src/lib/platform/EiScreen.cpp @@ -13,7 +13,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" #include "base/Stopwatch.h" -#include "base/TMethodEventJob.h" #include "common/Constants.h" #include "deskflow/Clipboard.h" #include "deskflow/KeyMap.h" @@ -50,22 +49,18 @@ EiScreen::EiScreen(bool is_primary, IEventQueue *events, bool use_portal) init_ei(); key_state_ = new EiKeyState(this, events); // install event handlers - events_->adoptHandler( - EventTypes::System, events_->getSystemTarget(), new TMethodEventJob(this, &EiScreen::handleSystemEvent) - ); + events_->addHandler(EventTypes::System, events_->getSystemTarget(), [this](const auto &e) { handleSystemEvent(e); }); if (use_portal) { - events_->adoptHandler( - EventTypes::EIConnected, getEventTarget(), - new TMethodEventJob(this, &EiScreen::handle_connected_to_eis_event) - ); + events_->addHandler(EventTypes::EIConnected, getEventTarget(), [this](const auto &e) { + handle_connected_to_eis_event(e); + }); if (is_primary) { portal_input_capture_ = new PortalInputCapture(this, events_); } else { - events_->adoptHandler( - EventTypes::EISessionClosed, getEventTarget(), - new TMethodEventJob(this, &EiScreen::handle_portal_session_closed) - ); + events_->addHandler(EventTypes::EISessionClosed, getEventTarget(), [this](const auto &) { + handle_portal_session_closed(); + }); portal_remote_desktop_ = new PortalRemoteDesktop(this, events_); } } else { @@ -698,7 +693,7 @@ void EiScreen::on_abs_motion_event(const ei_event *event) const assert(is_primary_); } -void EiScreen::handle_connected_to_eis_event(const Event &event, void *) +void EiScreen::handle_connected_to_eis_event(const Event &event) { int fd = static_cast(event.getData())->m_fd; LOG_DEBUG("eis connection established, fd=%d", fd); @@ -709,7 +704,7 @@ void EiScreen::handle_connected_to_eis_event(const Event &event, void *) } } -void EiScreen::handle_portal_session_closed(const Event &event, void *) +void EiScreen::handle_portal_session_closed() { // Portal may or may not EI_EVENT_DISCONNECT us before sending the DBus Closed // signal. Let's clean up either way. @@ -718,7 +713,7 @@ void EiScreen::handle_portal_session_closed(const Event &event, void *) init_ei(); } -void EiScreen::handleSystemEvent(const Event &sysevent, void *) +void EiScreen::handleSystemEvent(const Event &sysevent) { std::scoped_lock lock{mutex_}; @@ -779,7 +774,7 @@ void EiScreen::handleSystemEvent(const Event &sysevent, void *) portal_input_capture_ = new PortalInputCapture(this, this->events_); } } - this->handle_portal_session_closed(sysevent, nullptr); + this->handle_portal_session_closed(); break; case EI_EVENT_DEVICE_PAUSED: LOG_DEBUG("device %s is paused", ei_device_get_name(device)); diff --git a/src/lib/platform/EiScreen.h b/src/lib/platform/EiScreen.h index be7410533..2b8130d02 100644 --- a/src/lib/platform/EiScreen.h +++ b/src/lib/platform/EiScreen.h @@ -76,7 +76,7 @@ public: protected: // IPlatformScreen overrides - void handleSystemEvent(const Event &event, void *) override; + void handleSystemEvent(const Event &event) override; void updateButtons() override; IKeyState *getKeyState() const override; std::string getSecureInputApp() const override; @@ -100,8 +100,8 @@ private: bool on_hotkey(KeyID key, bool is_press, KeyModifierMask mask); void handle_ei_log_event(ei_log_priority priority, const char *message) const; - void handle_connected_to_eis_event(const Event &event, void *); - void handle_portal_session_closed(const Event &event, void *); + void handle_connected_to_eis_event(const Event &event); + void handle_portal_session_closed(); static void cb_handle_ei_log_event(ei *ei, ei_log_priority priority, const char *message, ei_log_context *context) { diff --git a/src/lib/platform/MSWindowsDesks.cpp b/src/lib/platform/MSWindowsDesks.cpp index e2ba4da14..76b9b43a2 100644 --- a/src/lib/platform/MSWindowsDesks.cpp +++ b/src/lib/platform/MSWindowsDesks.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -11,7 +12,6 @@ #include "base/IEventQueue.h" #include "base/IJob.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "base/TMethodJob.h" #include "deskflow/IScreenSaver.h" #include "deskflow/XScreen.h" @@ -144,9 +144,7 @@ void MSWindowsDesks::enable() // we wouldn't need this if windows notified us of a desktop // change but as far as i can tell it doesn't. m_timer = m_events->newTimer(0.2, nullptr); - m_events->adoptHandler( - EventTypes::Timer, m_timer, new TMethodEventJob(this, &MSWindowsDesks::handleCheckDesk) - ); + m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { handleCheckDesk(); }); updateKeys(); } @@ -807,7 +805,7 @@ void MSWindowsDesks::waitForDesk() const self->m_deskReady = false; } -void MSWindowsDesks::handleCheckDesk(const Event &, void *) +void MSWindowsDesks::handleCheckDesk() { checkDesk(); diff --git a/src/lib/platform/MSWindowsDesks.h b/src/lib/platform/MSWindowsDesks.h index d4e366012..e791142b5 100644 --- a/src/lib/platform/MSWindowsDesks.h +++ b/src/lib/platform/MSWindowsDesks.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -210,7 +211,7 @@ private: void removeDesks(); void checkDesk(); bool isDeskAccessible(const Desk *desk) const; - void handleCheckDesk(const Event &event, void *); + void handleCheckDesk(); // communication with desk threads void waitForDesk() const; diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index 85eedc988..341779dca 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -12,7 +13,6 @@ #include "arch/win32/XArchWindows.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "base/TMethodJob.h" #include "client/Client.h" #include "common/Constants.h" @@ -131,10 +131,9 @@ MSWindowsScreen::MSWindowsScreen( } // install event handlers - m_events->adoptHandler( - EventTypes::System, m_events->getSystemTarget(), - new TMethodEventJob(this, &MSWindowsScreen::handleSystemEvent) - ); + m_events->addHandler(EventTypes::System, m_events->getSystemTarget(), [this](const auto &e) { + handleSystemEvent(e); + }); // install the platform event queue m_events->adoptBuffer(new MSWindowsEventQueueBuffer(m_events)); @@ -178,9 +177,7 @@ void MSWindowsScreen::enable() // we need to poll some things to fix them m_fixTimer = m_events->newTimer(1.0, nullptr); - m_events->adoptHandler( - EventTypes::Timer, m_fixTimer, new TMethodEventJob(this, &MSWindowsScreen::handleFixes) - ); + m_events->addHandler(EventTypes::Timer, m_fixTimer, [this](const auto &) { handleFixes(); }); // install our clipboard snooper if (!AddClipboardFormatListener(m_window)) { @@ -830,7 +827,7 @@ void MSWindowsScreen::sendClipboardEvent(EventTypes type, ClipboardID id) sendEvent(type, info); } -void MSWindowsScreen::handleSystemEvent(const Event &event, void *) +void MSWindowsScreen::handleSystemEvent(const Event &event) { MSG *msg = static_cast(event.getData()); assert(msg != nullptr); @@ -1424,7 +1421,7 @@ void MSWindowsScreen::updateScreenShape() m_desks->setShape(m_x, m_y, m_w, m_h, m_xCenter, m_yCenter, m_multimon); } -void MSWindowsScreen::handleFixes(const Event &, void *) +void MSWindowsScreen::handleFixes() { // fix clipboard chain fixClipboardViewer(); diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h index af88275b6..d64ae5de6 100644 --- a/src/lib/platform/MSWindowsScreen.h +++ b/src/lib/platform/MSWindowsScreen.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -126,7 +127,7 @@ public: protected: // IPlatformScreen overrides - void handleSystemEvent(const Event &, void *) override; + void handleSystemEvent(const Event &event) override; void updateButtons() override; IKeyState *getKeyState() const override; @@ -190,7 +191,7 @@ private: // HACK void updateScreenShape(); // fix timer callback - void handleFixes(const Event &, void *); + void handleFixes(); // fix the clipboard viewer chain void fixClipboardViewer(); diff --git a/src/lib/platform/OSXScreen.h b/src/lib/platform/OSXScreen.h index 03512a03e..cde47c95d 100644 --- a/src/lib/platform/OSXScreen.h +++ b/src/lib/platform/OSXScreen.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -99,7 +100,7 @@ public: protected: // IPlatformScreen overrides - void handleSystemEvent(const Event &, void *) override; + void handleSystemEvent(const Event &e) override; void updateButtons() override; IKeyState *getKeyState() const override; @@ -148,7 +149,7 @@ private: double getScrollSpeed() const; // clipboard check timer handler - void handleClipboardCheck(const Event &, void *); + void handleClipboardCheck(); // Resolution switch callback static void displayReconfigurationCallback(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void *); @@ -162,7 +163,7 @@ private: static void powerChangeCallback(void *refcon, io_service_t service, natural_t messageType, void *messageArgument); void handlePowerChangeRequest(natural_t messageType, void *messageArgument); - void handleConfirmSleep(const Event &event, void *); + void handleConfirmSleep(const Event &event); // global hotkey operating mode static bool isGlobalHotKeyOperatingModeAvailable(); diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index efbab7437..ac7fd0b5c 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -11,7 +12,6 @@ #include "base/EventQueue.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "base/TMethodJob.h" #include "client/Client.h" #include "deskflow/ClientApp.h" @@ -142,10 +142,9 @@ OSXScreen::OSXScreen( constructMouseButtonEventMap(); // watch for requests to sleep - m_events->adoptHandler( - EventTypes::OsxScreenConfirmSleep, getEventTarget(), - new TMethodEventJob(this, &OSXScreen::handleConfirmSleep) - ); + m_events->addHandler(EventTypes::OsxScreenConfirmSleep, getEventTarget(), [this](const auto &e) { + handleConfirmSleep(e); + }); // create thread for monitoring system power state. *m_pmThreadReady = false; @@ -167,10 +166,9 @@ OSXScreen::OSXScreen( } // install event handlers - m_events->adoptHandler( - EventTypes::System, m_events->getSystemTarget(), - new TMethodEventJob(this, &OSXScreen::handleSystemEvent) - ); + m_events->addHandler(EventTypes::System, m_events->getSystemTarget(), [this](const auto &e) { + handleSystemEvent(e); + }); // install the platform event queue m_events->adoptBuffer(new OSXEventQueueBuffer(m_events)); @@ -649,9 +647,7 @@ void OSXScreen::enable() { // watch the clipboard m_clipboardTimer = m_events->newTimer(1.0, nullptr); - m_events->adoptHandler( - EventTypes::Timer, m_clipboardTimer, new TMethodEventJob(this, &OSXScreen::handleClipboardCheck) - ); + m_events->addHandler(EventTypes::Timer, m_clipboardTimer, [this](const auto &) { handleClipboardCheck(); }); if (m_isPrimary) { // FIXME -- start watching jump zones @@ -836,7 +832,7 @@ void OSXScreen::sendClipboardEvent(EventTypes type, ClipboardID id) const sendEvent(type, info); } -void OSXScreen::handleSystemEvent(const Event &event, void *) +void OSXScreen::handleSystemEvent(const Event &event) { EventRef *carbonEvent = static_cast(event.getData()); assert(carbonEvent != nullptr); @@ -996,7 +992,7 @@ bool OSXScreen::onMouseWheel(int32_t xDelta, int32_t yDelta) const return true; } -void OSXScreen::handleClipboardCheck(const Event &, void *) +void OSXScreen::handleClipboardCheck() { checkClipboards(); } @@ -1448,7 +1444,7 @@ void OSXScreen::handlePowerChangeRequest(natural_t messageType, void *messageArg } } -void OSXScreen::handleConfirmSleep(const Event &event, void *) +void OSXScreen::handleConfirmSleep(const Event &event) { long messageArg = (long)event.getData(); if (messageArg != 0) { diff --git a/src/lib/platform/XWindowsScreen.cpp b/src/lib/platform/XWindowsScreen.cpp index f84a8c3e8..3f5b69b02 100644 --- a/src/lib/platform/XWindowsScreen.cpp +++ b/src/lib/platform/XWindowsScreen.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -12,7 +13,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" #include "base/Stopwatch.h" -#include "base/TMethodEventJob.h" #include "deskflow/App.h" #include "deskflow/ArgsBase.h" #include "deskflow/ClientApp.h" @@ -151,10 +151,9 @@ XWindowsScreen::XWindowsScreen( } // install event handlers - m_events->adoptHandler( - EventTypes::System, m_events->getSystemTarget(), - new TMethodEventJob(this, &XWindowsScreen::handleSystemEvent) - ); + m_events->addHandler(EventTypes::System, m_events->getSystemTarget(), [this](const auto &e) { + handleSystemEvent(e); + }); // install the platform event queue m_events->adoptBuffer(new XWindowsEventQueueBuffer(m_display, m_window, m_events)); @@ -1111,7 +1110,7 @@ Bool XWindowsScreen::findKeyEvent(Display *, XEvent *xevent, XPointer arg) : False; } -void XWindowsScreen::handleSystemEvent(const Event &event, void *) +void XWindowsScreen::handleSystemEvent(const Event &event) { auto *xevent = static_cast(event.getData()); assert(xevent != nullptr); diff --git a/src/lib/platform/XWindowsScreen.h b/src/lib/platform/XWindowsScreen.h index 839607e51..b476d80e4 100644 --- a/src/lib/platform/XWindowsScreen.h +++ b/src/lib/platform/XWindowsScreen.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -79,7 +80,7 @@ public: protected: // IPlatformScreen overrides - void handleSystemEvent(const Event &, void *) override; + void handleSystemEvent(const Event &event) override; void updateButtons() override; IKeyState *getKeyState() const override; diff --git a/src/lib/platform/XWindowsScreenSaver.cpp b/src/lib/platform/XWindowsScreenSaver.cpp index 0d1c5f314..1f93b8ea6 100644 --- a/src/lib/platform/XWindowsScreenSaver.cpp +++ b/src/lib/platform/XWindowsScreenSaver.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -10,7 +11,6 @@ #include "base/Event.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/IPlatformScreen.h" #include "platform/XWindowsUtil.h" @@ -82,9 +82,7 @@ XWindowsScreenSaver::XWindowsScreenSaver(Display *display, Window window, void * } // install disable timer event handler - m_events->adoptHandler( - EventTypes::Timer, this, new TMethodEventJob(this, &XWindowsScreenSaver::handleDisableTimer) - ); + m_events->addHandler(EventTypes::Timer, this, [this](const auto &) { handleDisableTimer(); }); } XWindowsScreenSaver::~XWindowsScreenSaver() @@ -446,7 +444,7 @@ void XWindowsScreenSaver::updateDisableTimer() } } -void XWindowsScreenSaver::handleDisableTimer(const Event &, void *) +void XWindowsScreenSaver::handleDisableTimer() { // send fake mouse motion directly to xscreensaver if (m_xscreensaver != None) { diff --git a/src/lib/platform/XWindowsScreenSaver.h b/src/lib/platform/XWindowsScreenSaver.h index eb8d03d0c..3d77ad458 100644 --- a/src/lib/platform/XWindowsScreenSaver.h +++ b/src/lib/platform/XWindowsScreenSaver.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -87,7 +88,7 @@ private: void updateDisableTimer(); // called periodically to prevent the screen saver from starting - void handleDisableTimer(const Event &, void *); + void handleDisableTimer(); // force DPMS to activate or deactivate void activateDPMS(bool activate); diff --git a/src/lib/server/ClientListener.cpp b/src/lib/server/ClientListener.cpp index 2dd7d1073..489588320 100644 --- a/src/lib/server/ClientListener.cpp +++ b/src/lib/server/ClientListener.cpp @@ -11,7 +11,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/PacketStreamFilter.h" #include "net/IDataSocket.h" #include "net/IListenSocket.h" @@ -76,10 +75,9 @@ void ClientListener::start() m_listen = m_socketFactory->createListen(ARCH->getAddrFamily(m_address.getAddress()), m_securityLevel); // setup event handler - m_events->adoptHandler( - EventTypes::ListenSocketConnecting, m_listen, - new TMethodEventJob(this, &ClientListener::handleClientConnecting) - ); + m_events->addHandler(EventTypes::ListenSocketConnecting, m_listen, [this](const auto &) { + handleClientConnecting(); + }); // bind listen address LOG((CLOG_DEBUG1 "binding listen socket")); @@ -121,7 +119,7 @@ void ClientListener::removeUnknownClient(ClientProxyUnknown *unknownClient) } } -void ClientListener::handleClientConnecting(const Event &, void *) +void ClientListener::handleClientConnecting() { // accept client connection auto socket = m_listen->accept(); @@ -132,9 +130,9 @@ void ClientListener::handleClientConnecting(const Event &, void *) auto rawSocketPointer = socket.release(); m_clientSockets.insert(rawSocketPointer); - m_events->adoptHandler( + m_events->addHandler( EventTypes::ClientListenerAccepted, rawSocketPointer->getEventTarget(), - new TMethodEventJob(this, &ClientListener::handleClientAccepted, rawSocketPointer) + [this, rawSocketPointer](const auto &) { handleClientAccepted(rawSocketPointer); } ); // When using non SSL, server accepts clients immediately, while SSL @@ -144,12 +142,10 @@ void ClientListener::handleClientConnecting(const Event &, void *) } } -void ClientListener::handleClientAccepted(const Event &, void *vsocket) +void ClientListener::handleClientAccepted(IDataSocket *socket) { LOG((CLOG_NOTE "accepted client connection")); - auto *socket = static_cast(vsocket); - // filter socket messages, including a packetizing filter deskflow::IStream *stream = new PacketStreamFilter(m_events, socket, false); assert(m_server != nullptr); @@ -160,20 +156,16 @@ void ClientListener::handleClientAccepted(const Event &, void *vsocket) m_newClients.insert(client); // watch for events from unknown client - m_events->adoptHandler( - EventTypes::ClientProxyUnknownSuccess, client, - new TMethodEventJob(this, &ClientListener::handleUnknownClient, client) - ); - m_events->adoptHandler( - EventTypes::ClientProxyUnknownFailure, client, - new TMethodEventJob(this, &ClientListener::handleUnknownClientFailure, client) - ); + m_events->addHandler(EventTypes::ClientProxyUnknownSuccess, client, [this, client](const auto &) { + handleUnknownClient(client); + }); + m_events->addHandler(EventTypes::ClientProxyUnknownFailure, client, [this, client](const auto &) { + handleUnknownClientFailure(client); + }); } -void ClientListener::handleUnknownClient(const Event &, void *vclient) +void ClientListener::handleUnknownClient(ClientProxyUnknown *unknownClient) { - auto unknownClient = static_cast(vclient); - // we should have the client in our new client list assert(m_newClients.count(unknownClient) == 1); @@ -184,10 +176,9 @@ void ClientListener::handleUnknownClient(const Event &, void *vclient) m_events->addEvent(Event(EventTypes::ClientListenerAccepted, this)); // watch for client to disconnect while it's in our queue - m_events->adoptHandler( - EventTypes::ClientProxyDisconnected, client, - new TMethodEventJob(this, &ClientListener::handleClientDisconnected, client) - ); + m_events->addHandler(EventTypes::ClientProxyDisconnected, client, [this, client](const auto &e) { + handleClientDisconnected(client); + }); } else { auto *stream = unknownClient->getStream(); if (stream) { @@ -199,16 +190,13 @@ void ClientListener::handleUnknownClient(const Event &, void *vclient) removeUnknownClient(unknownClient); } -void ClientListener::handleUnknownClientFailure(const Event &, void *vclient) +void ClientListener::handleUnknownClientFailure(ClientProxyUnknown *client) { - auto unknownClient = static_cast(vclient); - removeUnknownClient(unknownClient); + removeUnknownClient(client); } -void ClientListener::handleClientDisconnected(const Event &, void *vclient) +void ClientListener::handleClientDisconnected(ClientProxy *client) { - auto *client = static_cast(vclient); - // find client in waiting clients queue for (WaitingClients::iterator i = m_waitingClients.begin(), n = m_waitingClients.end(); i != n; ++i) { if (*i == client) { diff --git a/src/lib/server/ClientListener.h b/src/lib/server/ClientListener.h index 9e20b82d7..300dda639 100644 --- a/src/lib/server/ClientListener.h +++ b/src/lib/server/ClientListener.h @@ -64,11 +64,11 @@ public: private: // client connection event handlers - void handleClientConnecting(const Event &, void *); - void handleClientAccepted(const Event &, void *); - void handleUnknownClient(const Event &, void *); - void handleUnknownClientFailure(const Event &, void *); - void handleClientDisconnected(const Event &, void *); + void handleClientConnecting(); + void handleClientAccepted(IDataSocket *socket); + void handleUnknownClient(ClientProxyUnknown *unknownClient); + void handleUnknownClientFailure(ClientProxyUnknown *client); + void handleClientDisconnected(ClientProxy *client); void cleanupListenSocket(); void cleanupClientSockets(); diff --git a/src/lib/server/ClientProxy1_0.cpp b/src/lib/server/ClientProxy1_0.cpp index b72dc2e96..385452214 100644 --- a/src/lib/server/ClientProxy1_0.cpp +++ b/src/lib/server/ClientProxy1_0.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -9,7 +10,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/ProtocolUtil.h" #include "deskflow/XDeskflow.h" #include "io/IStream.h" @@ -26,29 +26,20 @@ ClientProxy1_0::ClientProxy1_0(const std::string &name, deskflow::IStream *strea m_events(events) { // install event handlers - m_events->adoptHandler( - EventTypes::StreamInputReady, stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleData, nullptr) - ); - m_events->adoptHandler( - EventTypes::StreamOutputError, stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleWriteError, nullptr) - ); - m_events->adoptHandler( - EventTypes::StreamInputShutdown, stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleDisconnect, nullptr) - ); - m_events->adoptHandler( - EventTypes::StreamInputFormatError, stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleDisconnect, nullptr) - ); - m_events->adoptHandler( - EventTypes::StreamOutputShutdown, stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxy1_0::handleWriteError, nullptr) - ); - m_events->adoptHandler( - EventTypes::Timer, this, new TMethodEventJob(this, &ClientProxy1_0::handleFlatline, nullptr) - ); + m_events->addHandler(EventTypes::StreamInputReady, stream->getEventTarget(), [this](const auto &) { handleData(); }); + m_events->addHandler(EventTypes::StreamOutputError, stream->getEventTarget(), [this](const auto &) { + handleWriteError(); + }); + m_events->addHandler(EventTypes::StreamInputShutdown, stream->getEventTarget(), [this](const auto &) { + handleDisconnect(); + }); + m_events->addHandler(EventTypes::StreamInputFormatError, stream->getEventTarget(), [this](const auto &) { + handleDisconnect(); + }); + m_events->addHandler(EventTypes::StreamOutputShutdown, stream->getEventTarget(), [this](const auto &) { + handleWriteError(); + }); + m_events->addHandler(EventTypes::Timer, this, [this](const auto &) { handleFlatline(); }); setHeartbeatRate(kHeartRate, kHeartRate * kHeartBeatsUntilDeath); @@ -114,7 +105,7 @@ void ClientProxy1_0::setHeartbeatRate(double, double alarm) m_heartbeatAlarm = alarm; } -void ClientProxy1_0::handleData(const Event &, void *) +void ClientProxy1_0::handleData() { // handle messages until there are no more. first read message code. uint8_t code[4]; @@ -192,19 +183,19 @@ bool ClientProxy1_0::parseMessage(const uint8_t *code) return false; } -void ClientProxy1_0::handleDisconnect(const Event &, void *) +void ClientProxy1_0::handleDisconnect() { LOG((CLOG_NOTE "client \"%s\" has disconnected", getName().c_str())); disconnect(); } -void ClientProxy1_0::handleWriteError(const Event &, void *) +void ClientProxy1_0::handleWriteError() { LOG((CLOG_WARN "error writing to client \"%s\"", getName().c_str())); disconnect(); } -void ClientProxy1_0::handleFlatline(const Event &, void *) +void ClientProxy1_0::handleFlatline() { // didn't get a heartbeat fast enough. assume client is dead. LOG((CLOG_NOTE "client \"%s\" is dead", getName().c_str())); diff --git a/src/lib/server/ClientProxy1_0.h b/src/lib/server/ClientProxy1_0.h index f5d529aed..bec1b403e 100644 --- a/src/lib/server/ClientProxy1_0.h +++ b/src/lib/server/ClientProxy1_0.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -69,10 +70,10 @@ private: void disconnect(); void removeHandlers(); - void handleData(const Event &, void *); - void handleDisconnect(const Event &, void *); - void handleWriteError(const Event &, void *); - void handleFlatline(const Event &, void *); + void handleData(); + void handleDisconnect(); + void handleWriteError(); + void handleFlatline(); bool recvInfo(); bool recvGrabClipboard(); diff --git a/src/lib/server/ClientProxy1_3.cpp b/src/lib/server/ClientProxy1_3.cpp index 88ee55754..a7abd2c13 100644 --- a/src/lib/server/ClientProxy1_3.cpp +++ b/src/lib/server/ClientProxy1_3.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2006 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -9,7 +10,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/ProtocolUtil.h" #include @@ -73,10 +73,7 @@ void ClientProxy1_3::addHeartbeatTimer() // create and install a timer to periodically send keep alives if (m_keepAliveRate > 0.0) { m_keepAliveTimer = m_events->newTimer(m_keepAliveRate, nullptr); - m_events->adoptHandler( - EventTypes::Timer, m_keepAliveTimer, - new TMethodEventJob(this, &ClientProxy1_3::handleKeepAlive, nullptr) - ); + m_events->addHandler(EventTypes::Timer, m_keepAliveTimer, [this](const auto &) { handleKeepAlive(); }); } // superclass does the alarm @@ -96,7 +93,7 @@ void ClientProxy1_3::removeHeartbeatTimer() ClientProxy1_2::removeHeartbeatTimer(); } -void ClientProxy1_3::handleKeepAlive(const Event &, void *) +void ClientProxy1_3::handleKeepAlive() { keepAlive(); } diff --git a/src/lib/server/ClientProxy1_3.h b/src/lib/server/ClientProxy1_3.h index 0651923b0..6a76dd01e 100644 --- a/src/lib/server/ClientProxy1_3.h +++ b/src/lib/server/ClientProxy1_3.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2006 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -24,7 +25,7 @@ public: // IClient overrides void mouseWheel(int32_t xDelta, int32_t yDelta) override; - void handleKeepAlive(const Event &, void *); + void handleKeepAlive(); protected: // ClientProxy overrides diff --git a/src/lib/server/ClientProxy1_4.cpp b/src/lib/server/ClientProxy1_4.cpp index 122664718..748b9ad1f 100644 --- a/src/lib/server/ClientProxy1_4.cpp +++ b/src/lib/server/ClientProxy1_4.cpp @@ -9,7 +9,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/ProtocolUtil.h" #include "server/Server.h" diff --git a/src/lib/server/ClientProxy1_5.cpp b/src/lib/server/ClientProxy1_5.cpp index 0b4828b9f..a468fc951 100644 --- a/src/lib/server/ClientProxy1_5.cpp +++ b/src/lib/server/ClientProxy1_5.cpp @@ -7,7 +7,6 @@ #include "server/ClientProxy1_5.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/ProtocolUtil.h" #include "deskflow/StreamChunker.h" #include "io/IStream.h" diff --git a/src/lib/server/ClientProxy1_6.cpp b/src/lib/server/ClientProxy1_6.cpp index 66601038c..8322496c7 100644 --- a/src/lib/server/ClientProxy1_6.cpp +++ b/src/lib/server/ClientProxy1_6.cpp @@ -7,7 +7,6 @@ #include "server/ClientProxy1_6.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/ClipboardChunk.h" #include "deskflow/ProtocolUtil.h" #include "deskflow/StreamChunker.h" @@ -22,10 +21,7 @@ ClientProxy1_6::ClientProxy1_6(const std::string &name, deskflow::IStream *strea : ClientProxy1_5(name, stream, server, events), m_events(events) { - m_events->adoptHandler( - EventTypes::ClipboardSending, this, - new TMethodEventJob(this, &ClientProxy1_6::handleClipboardSendingEvent) - ); + m_events->addHandler(EventTypes::ClipboardSending, this, [this](const auto &e) { handleClipboardSendingEvent(e); }); } void ClientProxy1_6::setClipboard(ClipboardID id, const IClipboard *clipboard) @@ -45,7 +41,7 @@ void ClientProxy1_6::setClipboard(ClipboardID id, const IClipboard *clipboard) } } -void ClientProxy1_6::handleClipboardSendingEvent(const Event &event, void *) +void ClientProxy1_6::handleClipboardSendingEvent(const Event &event) { ClipboardChunk::send(getStream(), event.getDataObject()); } diff --git a/src/lib/server/ClientProxy1_6.h b/src/lib/server/ClientProxy1_6.h index a395624aa..6b1b66475 100644 --- a/src/lib/server/ClientProxy1_6.h +++ b/src/lib/server/ClientProxy1_6.h @@ -22,7 +22,7 @@ public: bool recvClipboard() override; private: - void handleClipboardSendingEvent(const Event &, void *); + void handleClipboardSendingEvent(const Event &e); private: IEventQueue *m_events; diff --git a/src/lib/server/ClientProxy1_7.cpp b/src/lib/server/ClientProxy1_7.cpp index 5d990489c..4d539494b 100644 --- a/src/lib/server/ClientProxy1_7.cpp +++ b/src/lib/server/ClientProxy1_7.cpp @@ -6,7 +6,6 @@ #include "server/ClientProxy1_7.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/AppUtil.h" #include "deskflow/ProtocolUtil.h" #include "server/Server.h" diff --git a/src/lib/server/ClientProxyUnknown.cpp b/src/lib/server/ClientProxyUnknown.cpp index 251c677b7..20b60be98 100644 --- a/src/lib/server/ClientProxyUnknown.cpp +++ b/src/lib/server/ClientProxyUnknown.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -9,7 +10,6 @@ #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/AppUtil.h" #include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolUtil.h" @@ -41,10 +41,7 @@ ClientProxyUnknown::ClientProxyUnknown(deskflow::IStream *stream, double timeout { assert(m_server != nullptr); - m_events->adoptHandler( - EventTypes::Timer, this, - new TMethodEventJob(this, &ClientProxyUnknown::handleTimeout, nullptr) - ); + m_events->addHandler(EventTypes::Timer, this, [this](const auto &) { handleTimeout(); }); m_timer = m_events->newOneShotTimer(timeout, this); addStreamHandlers(); @@ -95,40 +92,29 @@ void ClientProxyUnknown::sendFailure() void ClientProxyUnknown::addStreamHandlers() { assert(m_stream != nullptr); - m_events->adoptHandler( - EventTypes::StreamInputReady, m_stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxyUnknown::handleData) - ); - m_events->adoptHandler( - EventTypes::StreamOutputError, m_stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxyUnknown::handleWriteError) - ); - m_events->adoptHandler( - EventTypes::StreamInputShutdown, m_stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxyUnknown::handleDisconnect) - ); - m_events->adoptHandler( - EventTypes::StreamInputFormatError, m_stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxyUnknown::handleDisconnect) - ); - m_events->adoptHandler( - EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), - new TMethodEventJob(this, &ClientProxyUnknown::handleWriteError) - ); + m_events->addHandler(EventTypes::StreamInputReady, m_stream->getEventTarget(), [this](const auto &) { + handleData(); + }); + m_events->addHandler(EventTypes::StreamOutputError, m_stream->getEventTarget(), [this](const auto &) { + handleWriteError(); + }); + m_events->addHandler(EventTypes::StreamInputShutdown, m_stream->getEventTarget(), [this](const auto &) { + handleDisconnect(); + }); + m_events->addHandler(EventTypes::StreamInputFormatError, m_stream->getEventTarget(), [this](const auto &) { + handleDisconnect(); + }); + m_events->addHandler(EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), [this](const auto &) { + handleWriteError(); + }); } void ClientProxyUnknown::addProxyHandlers() { assert(m_proxy != nullptr); - m_events->adoptHandler( - EventTypes::ClientProxyReady, m_proxy, - new TMethodEventJob(this, &ClientProxyUnknown::handleReady) - ); - m_events->adoptHandler( - EventTypes::ClientProxyDisconnected, m_proxy, - new TMethodEventJob(this, &ClientProxyUnknown::handleDisconnect) - ); + m_events->addHandler(EventTypes::ClientProxyReady, m_proxy, [this](const auto &e) { handleReady(); }); + m_events->addHandler(EventTypes::ClientProxyDisconnected, m_proxy, [this](const auto &e) { handleDisconnect(); }); } void ClientProxyUnknown::removeHandlers() @@ -203,7 +189,7 @@ void ClientProxyUnknown::initProxy(const std::string &name, int major, int minor } } -void ClientProxyUnknown::handleData(const Event &, void *) +void ClientProxyUnknown::handleData() { LOG((CLOG_DEBUG1 "parsing hello reply")); @@ -258,25 +244,25 @@ void ClientProxyUnknown::handleData(const Event &, void *) sendFailure(); } -void ClientProxyUnknown::handleWriteError(const Event &, void *) +void ClientProxyUnknown::handleWriteError() { LOG((CLOG_NOTE "error communicating with new client")); sendFailure(); } -void ClientProxyUnknown::handleTimeout(const Event &, void *) +void ClientProxyUnknown::handleTimeout() { LOG((CLOG_NOTE "new client is unresponsive")); sendFailure(); } -void ClientProxyUnknown::handleDisconnect(const Event &, void *) +void ClientProxyUnknown::handleDisconnect() { LOG((CLOG_NOTE "new client disconnected")); sendFailure(); } -void ClientProxyUnknown::handleReady(const Event &, void *) +void ClientProxyUnknown::handleReady() { sendSuccess(); } diff --git a/src/lib/server/ClientProxyUnknown.h b/src/lib/server/ClientProxyUnknown.h index 798021544..32a7b9e0f 100644 --- a/src/lib/server/ClientProxyUnknown.h +++ b/src/lib/server/ClientProxyUnknown.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -59,11 +60,11 @@ private: void removeHandlers(); void initProxy(const std::string &name, int major, int minor); void removeTimer(); - void handleData(const Event &, void *); - void handleWriteError(const Event &, void *); - void handleTimeout(const Event &, void *); - void handleDisconnect(const Event &, void *); - void handleReady(const Event &, void *); + void handleData(); + void handleWriteError(); + void handleTimeout(); + void handleDisconnect(); + void handleReady(); private: deskflow::IStream *m_stream = nullptr; diff --git a/src/lib/server/InputFilter.cpp b/src/lib/server/InputFilter.cpp index a52e7deb9..4f7269483 100644 --- a/src/lib/server/InputFilter.cpp +++ b/src/lib/server/InputFilter.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2005 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -8,7 +9,6 @@ #include "server/InputFilter.h" #include "base/EventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "deskflow/KeyMap.h" #include "server/PrimaryClient.h" #include "server/Server.h" @@ -796,38 +796,30 @@ void InputFilter::setPrimaryClient(PrimaryClient *client) m_primaryClient = client; if (m_primaryClient != nullptr) { - m_events->adoptHandler( - EventTypes::KeyStateKeyDown, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &InputFilter::handleEvent) - ); - m_events->adoptHandler( - EventTypes::KeyStateKeyUp, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &InputFilter::handleEvent) - ); - m_events->adoptHandler( - EventTypes::KeyStateKeyRepeat, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &InputFilter::handleEvent) - ); - m_events->adoptHandler( - EventTypes::PrimaryScreenButtonDown, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &InputFilter::handleEvent) - ); - m_events->adoptHandler( - EventTypes::PrimaryScreenButtonUp, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &InputFilter::handleEvent) - ); - m_events->adoptHandler( - EventTypes::PrimaryScreenHotkeyDown, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &InputFilter::handleEvent) - ); - m_events->adoptHandler( - EventTypes::PrimaryScreenHotkeyUp, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &InputFilter::handleEvent) - ); - m_events->adoptHandler( - EventTypes::ServerConnected, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &InputFilter::handleEvent) - ); + m_events->addHandler(EventTypes::KeyStateKeyDown, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleEvent(e); + }); + m_events->addHandler(EventTypes::KeyStateKeyUp, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleEvent(e); + }); + m_events->addHandler(EventTypes::KeyStateKeyRepeat, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleEvent(e); + }); + m_events->addHandler(EventTypes::PrimaryScreenButtonDown, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleEvent(e); + }); + m_events->addHandler(EventTypes::PrimaryScreenButtonUp, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleEvent(e); + }); + m_events->addHandler(EventTypes::PrimaryScreenHotkeyDown, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleEvent(e); + }); + m_events->addHandler(EventTypes::PrimaryScreenHotkeyUp, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleEvent(e); + }); + m_events->addHandler(EventTypes::ServerConnected, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleEvent(e); + }); for (auto rule = m_ruleList.begin(); rule != m_ruleList.end(); ++rule) { rule->enable(m_primaryClient); @@ -878,7 +870,7 @@ bool InputFilter::operator!=(const InputFilter &x) const return !operator==(x); } -void InputFilter::handleEvent(const Event &event, void *) +void InputFilter::handleEvent(const Event &event) { // copy event and adjust target Event myEvent( diff --git a/src/lib/server/InputFilter.h b/src/lib/server/InputFilter.h index 7e9836628..3ad18deef 100644 --- a/src/lib/server/InputFilter.h +++ b/src/lib/server/InputFilter.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2005 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -324,7 +325,7 @@ public: void disable(PrimaryClient *); // event handling - bool handleEvent(const Event &); + bool handleEvent(const Event &e); // convert rule to a string std::string format() const; @@ -387,7 +388,7 @@ public: private: // event handling - void handleEvent(const Event &, void *); + void handleEvent(const Event &); private: RuleList m_ruleList; diff --git a/src/lib/server/Server.cpp b/src/lib/server/Server.cpp index a977e7654..d6a206198 100644 --- a/src/lib/server/Server.cpp +++ b/src/lib/server/Server.cpp @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers. * SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -10,7 +11,6 @@ #include "arch/Arch.h" #include "base/IEventQueue.h" #include "base/Log.h" -#include "base/TMethodEventJob.h" #include "base/TMethodJob.h" #include "deskflow/AppUtil.h" #include "deskflow/IPlatformScreen.h" @@ -71,67 +71,55 @@ Server::Server( } // install event handlers - m_events->adoptHandler(EventTypes::Timer, this, new TMethodEventJob(this, &Server::handleSwitchWaitTimeout)); - m_events->adoptHandler( - EventTypes::KeyStateKeyDown, m_inputFilter, new TMethodEventJob(this, &Server::handleKeyDownEvent) - ); - m_events->adoptHandler( - EventTypes::KeyStateKeyUp, m_inputFilter, new TMethodEventJob(this, &Server::handleKeyUpEvent) - ); - m_events->adoptHandler( - EventTypes::KeyStateKeyRepeat, m_inputFilter, new TMethodEventJob(this, &Server::handleKeyRepeatEvent) - ); - m_events->adoptHandler( - EventTypes::PrimaryScreenButtonDown, m_inputFilter, - new TMethodEventJob(this, &Server::handleButtonDownEvent) - ); - m_events->adoptHandler( - EventTypes::PrimaryScreenButtonUp, m_inputFilter, new TMethodEventJob(this, &Server::handleButtonUpEvent) - ); - m_events->adoptHandler( + m_events->addHandler(EventTypes::Timer, this, [this](const auto &) { handleSwitchWaitTimeout(); }); + m_events->addHandler(EventTypes::KeyStateKeyDown, m_inputFilter, [this](const auto &e) { handleKeyDownEvent(e); }); + m_events->addHandler(EventTypes::KeyStateKeyUp, m_inputFilter, [this](const auto &e) { handleKeyUpEvent(e); }); + m_events->addHandler(EventTypes::KeyStateKeyRepeat, m_inputFilter, [this](const auto &e) { + handleKeyRepeatEvent(e); + }); + m_events->addHandler(EventTypes::PrimaryScreenButtonDown, m_inputFilter, [this](const auto &e) { + handleButtonDownEvent(e); + }); + m_events->addHandler(EventTypes::PrimaryScreenButtonUp, m_inputFilter, [this](const auto &e) { + handleButtonUpEvent(e); + }); + m_events->addHandler( EventTypes::PrimaryScreenMotionOnPrimary, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &Server::handleMotionPrimaryEvent) + [this](const auto &e) { handleMotionPrimaryEvent(e); } ); - m_events->adoptHandler( + m_events->addHandler( EventTypes::PrimaryScreenMotionOnSecondary, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &Server::handleMotionSecondaryEvent) + [this](const auto &e) { handleMotionSecondaryEvent(e); } ); - m_events->adoptHandler( - EventTypes::PrimaryScreenWheel, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &Server::handleWheelEvent) - ); - m_events->adoptHandler( + m_events->addHandler(EventTypes::PrimaryScreenWheel, m_primaryClient->getEventTarget(), [this](const auto &e) { + handleWheelEvent(e); + }); + m_events->addHandler( EventTypes::PrimaryScreenSaverActivated, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &Server::handleScreensaverActivatedEvent) + [this](const auto &) { handleScreensaverActivatedEvent(); } ); - m_events->adoptHandler( + m_events->addHandler( EventTypes::PrimaryScreenSaverDeactivated, m_primaryClient->getEventTarget(), - new TMethodEventJob(this, &Server::handleScreensaverDeactivatedEvent) - ); - m_events->adoptHandler( - EventTypes::ServerSwitchToScreen, m_inputFilter, - new TMethodEventJob(this, &Server::handleSwitchToScreenEvent) - ); - m_events->adoptHandler( - EventTypes::ServerSwitchInDirection, m_inputFilter, - new TMethodEventJob(this, &Server::handleSwitchInDirectionEvent) - ); - m_events->adoptHandler( - EventTypes::ServerKeyboardBroadcast, m_inputFilter, - new TMethodEventJob(this, &Server::handleKeyboardBroadcastEvent) - ); - m_events->adoptHandler( - EventTypes::ServerLockCursorToScreen, m_inputFilter, - new TMethodEventJob(this, &Server::handleLockCursorToScreenEvent) - ); - m_events->adoptHandler( - EventTypes::PrimaryScreenFakeInputBegin, m_inputFilter, - new TMethodEventJob(this, &Server::handleFakeInputBeginEvent) - ); - m_events->adoptHandler( - EventTypes::PrimaryScreenFakeInputEnd, m_inputFilter, - new TMethodEventJob(this, &Server::handleFakeInputEndEvent) + [this](const auto &) { handleScreensaverDeactivatedEvent(); } ); + m_events->addHandler(EventTypes::ServerSwitchToScreen, m_inputFilter, [this](const auto &e) { + handleSwitchToScreenEvent(e); + }); + m_events->addHandler(EventTypes::ServerSwitchInDirection, m_inputFilter, [this](const auto &e) { + handleSwitchInDirectionEvent(e); + }); + m_events->addHandler(EventTypes::ServerKeyboardBroadcast, m_inputFilter, [this](const auto &e) { + handleKeyboardBroadcastEvent(e); + }); + m_events->addHandler(EventTypes::ServerLockCursorToScreen, m_inputFilter, [this](const auto &e) { + handleLockCursorToScreenEvent(e); + }); + m_events->addHandler(EventTypes::PrimaryScreenFakeInputBegin, m_inputFilter, [this](const auto &) { + handleFakeInputBeginEvent(); + }); + m_events->addHandler(EventTypes::PrimaryScreenFakeInputEnd, m_inputFilter, [this](const auto &) { + handleFakeInputEndEvent(); + }); // add connection addClient(m_primaryClient); @@ -237,10 +225,9 @@ void Server::adoptClient(BaseClientProxy *client) assert(client != nullptr); // watch for client disconnection - m_events->adoptHandler( - EventTypes::ClientProxyDisconnected, client, - new TMethodEventJob(this, &Server::handleClientDisconnected, client) - ); + m_events->addHandler(EventTypes::ClientProxyDisconnected, client, [this, client](const auto &e) { + handleClientDisconnected(client); + }); // name must be in our configuration if (!m_config->isScreen(client->getName())) { @@ -1128,10 +1115,8 @@ void Server::processOptions() m_relativeMoves = newRelativeMoves; } -void Server::handleShapeChanged(const Event &, void *vclient) +void Server::handleShapeChanged(BaseClientProxy *client) { - // ignore events from unknown clients - auto *client = static_cast(vclient); if (m_clientSet.count(client) == 0) { return; } @@ -1160,14 +1145,13 @@ void Server::handleShapeChanged(const Event &, void *vclient) } } -void Server::handleClipboardGrabbed(const Event &event, void *vclient) +void Server::handleClipboardGrabbed(const Event &event, BaseClientProxy *grabber) { if (!m_enableClipboard || (m_maximumClipboardSize == 0)) { return; } // ignore events from unknown clients - auto *grabber = static_cast(vclient); if (m_clientSet.count(grabber) == 0) { return; } @@ -1216,78 +1200,77 @@ void Server::handleClipboardGrabbed(const Event &event, void *vclient) } } -void Server::handleClipboardChanged(const Event &event, void *vclient) +void Server::handleClipboardChanged(const Event &event, BaseClientProxy *client) { // ignore events from unknown clients - auto *sender = static_cast(vclient); - if (m_clientSet.count(sender) == 0) { + if (m_clientSet.count(client) == 0) { return; } const auto *info = static_cast(event.getData()); - onClipboardChanged(sender, info->m_id, info->m_sequenceNumber); + onClipboardChanged(client, info->m_id, info->m_sequenceNumber); } -void Server::handleKeyDownEvent(const Event &event, void *) +void Server::handleKeyDownEvent(const Event &event) { const auto *info = static_cast(event.getData()); auto lang = AppUtil::instance().getCurrentLanguageCode(); onKeyDown(info->m_key, info->m_mask, info->m_button, lang, info->m_screens); } -void Server::handleKeyUpEvent(const Event &event, void *) +void Server::handleKeyUpEvent(const Event &event) { auto *info = static_cast(event.getData()); onKeyUp(info->m_key, info->m_mask, info->m_button, info->m_screens); } -void Server::handleKeyRepeatEvent(const Event &event, void *) +void Server::handleKeyRepeatEvent(const Event &event) { const auto *info = static_cast(event.getData()); auto lang = AppUtil::instance().getCurrentLanguageCode(); onKeyRepeat(info->m_key, info->m_mask, info->m_count, info->m_button, lang); } -void Server::handleButtonDownEvent(const Event &event, void *) +void Server::handleButtonDownEvent(const Event &event) { const auto *info = static_cast(event.getData()); onMouseDown(info->m_button); } -void Server::handleButtonUpEvent(const Event &event, void *) +void Server::handleButtonUpEvent(const Event &event) { const auto *info = static_cast(event.getData()); onMouseUp(info->m_button); } -void Server::handleMotionPrimaryEvent(const Event &event, void *) +void Server::handleMotionPrimaryEvent(const Event &event) { const auto *info = static_cast(event.getData()); onMouseMovePrimary(info->m_x, info->m_y); } -void Server::handleMotionSecondaryEvent(const Event &event, void *) +void Server::handleMotionSecondaryEvent(const Event &event) { const auto *info = static_cast(event.getData()); onMouseMoveSecondary(info->m_x, info->m_y); } -void Server::handleWheelEvent(const Event &event, void *) +void Server::handleWheelEvent(const Event &event) { const auto *info = static_cast(event.getData()); onMouseWheel(info->m_xDelta, info->m_yDelta); } -void Server::handleScreensaverActivatedEvent(const Event &, void *) +void Server::handleScreensaverActivatedEvent() { onScreensaver(true); } -void Server::handleScreensaverDeactivatedEvent(const Event &, void *) +void Server::handleScreensaverDeactivatedEvent() { onScreensaver(false); } -void Server::handleSwitchWaitTimeout(const Event &, void *) +void Server::handleSwitchWaitTimeout() { // ignore if mouse is locked to screen if (isLockedToScreen()) { @@ -1300,28 +1283,26 @@ void Server::handleSwitchWaitTimeout(const Event &, void *) switchScreen(m_switchScreen, m_switchWaitX, m_switchWaitY, false); } -void Server::handleClientDisconnected(const Event &, void *vclient) +void Server::handleClientDisconnected(BaseClientProxy *client) { // client has disconnected. it might be an old client or an // active client. we don't care so just handle it both ways. - auto *client = static_cast(vclient); removeActiveClient(client); removeOldClient(client); delete client; } -void Server::handleClientCloseTimeout(const Event &, void *vclient) +void Server::handleClientCloseTimeout(BaseClientProxy *client) { // client took too long to disconnect. just dump it. - auto *client = static_cast(vclient); LOG((CLOG_NOTE "forced disconnection of client \"%s\"", getName(client).c_str())); removeOldClient(client); delete client; } -void Server::handleSwitchToScreenEvent(const Event &event, void *) +void Server::handleSwitchToScreenEvent(const Event &event) { auto *info = static_cast(event.getData()); @@ -1333,7 +1314,7 @@ void Server::handleSwitchToScreenEvent(const Event &event, void *) } } -void Server::handleSwitchInDirectionEvent(const Event &event, void *) +void Server::handleSwitchInDirectionEvent(const Event &event) { const auto *info = static_cast(event.getData()); @@ -1348,7 +1329,7 @@ void Server::handleSwitchInDirectionEvent(const Event &event, void *) } } -void Server::handleKeyboardBroadcastEvent(const Event &event, void *) +void Server::handleKeyboardBroadcastEvent(const Event &event) { const auto *info = (KeyboardBroadcastInfo *)event.getData(); @@ -1380,7 +1361,7 @@ void Server::handleKeyboardBroadcastEvent(const Event &event, void *) } } -void Server::handleLockCursorToScreenEvent(const Event &event, void *) +void Server::handleLockCursorToScreenEvent(const Event &event) { const auto *info = (LockCursorToScreenInfo *)event.getData(); @@ -1413,12 +1394,12 @@ void Server::handleLockCursorToScreenEvent(const Event &event, void *) } } -void Server::handleFakeInputBeginEvent(const Event &, void *) +void Server::handleFakeInputBeginEvent() { m_primaryClient->fakeInputBegin(); } -void Server::handleFakeInputEndEvent(const Event &, void *) +void Server::handleFakeInputEndEvent() { m_primaryClient->fakeInputEnd(); } @@ -1884,18 +1865,15 @@ bool Server::addClient(BaseClientProxy *client) } // add event handlers - m_events->adoptHandler( - EventTypes::ScreenShapeChanged, client->getEventTarget(), - new TMethodEventJob(this, &Server::handleShapeChanged, client) - ); - m_events->adoptHandler( - EventTypes::ClipboardGrabbed, client->getEventTarget(), - new TMethodEventJob(this, &Server::handleClipboardGrabbed, client) - ); - m_events->adoptHandler( - EventTypes::ClipboardChanged, client->getEventTarget(), - new TMethodEventJob(this, &Server::handleClipboardChanged, client) - ); + m_events->addHandler(EventTypes::ScreenShapeChanged, client->getEventTarget(), [this, client](const auto &e) { + handleShapeChanged(client); + }); + m_events->addHandler(EventTypes::ClipboardGrabbed, client->getEventTarget(), [this, client](const auto &e) { + handleClipboardGrabbed(e, client); + }); + m_events->addHandler(EventTypes::ClipboardChanged, client->getEventTarget(), [this, client](const auto &e) { + handleClipboardChanged(e, client); + }); // add to list m_clientSet.insert(client); @@ -1950,14 +1928,13 @@ void Server::closeClient(BaseClientProxy *client, const char *msg) // send message // FIXME -- avoid type cast (kinda hard, though) - ((ClientProxy *)client)->close(msg); + auto clientProxy = static_cast(client); + clientProxy->close(msg); // install timer. wait timeout seconds for client to close. double timeout = 5.0; EventQueueTimer *timer = m_events->newOneShotTimer(timeout, nullptr); - m_events->adoptHandler( - EventTypes::Timer, timer, new TMethodEventJob(this, &Server::handleClientCloseTimeout, client) - ); + m_events->addHandler(EventTypes::Timer, timer, [this, client](const auto &e) { handleClientCloseTimeout(client); }); // move client to closing list removeClient(client); diff --git a/src/lib/server/Server.h b/src/lib/server/Server.h index 26f15dd44..b5f86f14d 100644 --- a/src/lib/server/Server.h +++ b/src/lib/server/Server.h @@ -1,5 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers * SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -289,28 +290,28 @@ private: void processOptions(); // event handlers - void handleShapeChanged(const Event &, void *); - void handleClipboardGrabbed(const Event &, void *); - void handleClipboardChanged(const Event &, void *); - void handleKeyDownEvent(const Event &, void *); - void handleKeyUpEvent(const Event &, void *); - void handleKeyRepeatEvent(const Event &, void *); - void handleButtonDownEvent(const Event &, void *); - void handleButtonUpEvent(const Event &, void *); - void handleMotionPrimaryEvent(const Event &, void *); - void handleMotionSecondaryEvent(const Event &, void *); - void handleWheelEvent(const Event &, void *); - void handleScreensaverActivatedEvent(const Event &, void *); - void handleScreensaverDeactivatedEvent(const Event &, void *); - void handleSwitchWaitTimeout(const Event &, void *); - void handleClientDisconnected(const Event &, void *); - void handleClientCloseTimeout(const Event &, void *); - void handleSwitchToScreenEvent(const Event &, void *); - void handleSwitchInDirectionEvent(const Event &, void *); - void handleKeyboardBroadcastEvent(const Event &, void *); - void handleLockCursorToScreenEvent(const Event &, void *); - void handleFakeInputBeginEvent(const Event &, void *); - void handleFakeInputEndEvent(const Event &, void *); + void handleShapeChanged(BaseClientProxy *client); + void handleClipboardGrabbed(const Event &event, BaseClientProxy *client); + void handleClipboardChanged(const Event &event, BaseClientProxy *client); + void handleKeyDownEvent(const Event &event); + void handleKeyUpEvent(const Event &event); + void handleKeyRepeatEvent(const Event &event); + void handleButtonDownEvent(const Event &event); + void handleButtonUpEvent(const Event &event); + void handleMotionPrimaryEvent(const Event &event); + void handleMotionSecondaryEvent(const Event &event); + void handleWheelEvent(const Event &event); + void handleScreensaverActivatedEvent(); + void handleScreensaverDeactivatedEvent(); + void handleSwitchWaitTimeout(); + void handleClientDisconnected(BaseClientProxy *client); + void handleClientCloseTimeout(BaseClientProxy *client); + void handleSwitchToScreenEvent(const Event &event); + void handleSwitchInDirectionEvent(const Event &event); + void handleKeyboardBroadcastEvent(const Event &event); + void handleLockCursorToScreenEvent(const Event &event); + void handleFakeInputBeginEvent(); + void handleFakeInputEndEvent(); // event processing void onClipboardChanged(const BaseClientProxy *sender, ClipboardID id, uint32_t seqNum); diff --git a/src/unittests/legacytests/mock/deskflow/MockEventQueue.h b/src/unittests/legacytests/mock/deskflow/MockEventQueue.h index c640ad87e..1945b792a 100644 --- a/src/unittests/legacytests/mock/deskflow/MockEventQueue.h +++ b/src/unittests/legacytests/mock/deskflow/MockEventQueue.h @@ -22,11 +22,10 @@ public: MOCK_METHOD(void, removeHandlers, (void *), (override)); MOCK_METHOD(EventTypes, registerType, (const char *)); MOCK_METHOD(bool, isEmpty, (), (const, override)); - MOCK_METHOD(void, adoptHandler, (EventTypes, void *, IEventJob *), (override)); + MOCK_METHOD(void, addHandler, (EventTypes, void *, const EventHandler &), (override)); MOCK_METHOD(void, addEvent, (const Event &), (override)); MOCK_METHOD(void, removeHandler, (EventTypes, void *), (override)); MOCK_METHOD(bool, dispatchEvent, (const Event &), (override)); - MOCK_METHOD(IEventJob *, getHandler, (EventTypes, void *), (const, override)); MOCK_METHOD(void, deleteTimer, (EventQueueTimer *), (override)); MOCK_METHOD(void *, getSystemTarget, (), (override)); MOCK_METHOD(void, waitForReady, (), (const, override));