refactor: use std::function for Event callback

based on 6d347337c3
This commit is contained in:
sithlord48 2025-06-18 00:17:54 -04:00 committed by Nick Bolton
parent c15214aee7
commit 3a35b183d3
53 changed files with 476 additions and 680 deletions

View file

@ -33,7 +33,6 @@ add_library(base STATIC
Stopwatch.h Stopwatch.h
String.cpp String.cpp
String.h String.h
TMethodEventJob.h
TMethodJob.h TMethodJob.h
Unicode.cpp Unicode.cpp
Unicode.h Unicode.h

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -8,7 +9,6 @@
#include "base/EventQueue.h" #include "base/EventQueue.h"
#include "arch/Arch.h" #include "arch/Arch.h"
#include "base/IEventJob.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/SimpleEventQueueBuffer.h" #include "base/SimpleEventQueueBuffer.h"
#include "mt/Lock.h" #include "mt/Lock.h"
@ -159,12 +159,12 @@ bool EventQueue::getEvent(Event &event, double timeout)
bool EventQueue::dispatchEvent(const Event &event) bool EventQueue::dispatchEvent(const Event &event)
{ {
void *target = event.getTarget(); void *target = event.getTarget();
IEventJob *job = getHandler(event.getType(), target); if (const auto *type_handler = getHandler(event.getType(), target); type_handler) {
if (job == nullptr) { (*type_handler)(event);
job = getHandler(EventTypes::Unknown, target); return true;
} }
if (job != nullptr) { if (const auto *any_handler = getHandler(EventTypes::Unknown, target); any_handler) {
job->run(event); (*any_handler)(event);
return true; return true;
} }
return false; return false;
@ -257,46 +257,32 @@ void EventQueue::deleteTimer(EventQueueTimer *timer)
m_buffer->deleteTimer(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}; std::scoped_lock lock{m_mutex};
m_handlers[target][type].reset(handler); m_handlers[target][type] = handler;
} }
void EventQueue::removeHandler(EventTypes type, void *target) void EventQueue::removeHandler(EventTypes type, void *target)
{ {
std::unique_ptr<IEventJob> handler; std::scoped_lock lock{m_mutex};
{ HandlerTable::iterator index = m_handlers.find(target);
std::scoped_lock lock{m_mutex}; if (index != m_handlers.end()) {
HandlerTable::iterator index = m_handlers.find(target); TypeHandlerTable &typeHandlers = index->second;
if (index != m_handlers.end()) { TypeHandlerTable::iterator index2 = typeHandlers.find(type);
TypeHandlerTable &typeHandlers = index->second; if (index2 != typeHandlers.end()) {
TypeHandlerTable::iterator index2 = typeHandlers.find(type); typeHandlers.erase(index2);
if (index2 != typeHandlers.end()) {
handler = std::move(index2->second);
typeHandlers.erase(index2);
}
} }
} }
// handler is erased here. It is done outside of lock in order to avoid potential deadlock.
} }
void EventQueue::removeHandlers(void *target) void EventQueue::removeHandlers(void *target)
{ {
std::vector<std::unique_ptr<IEventJob>> handlers; std::scoped_lock lock{m_mutex};
{ HandlerTable::iterator index = m_handlers.find(target);
std::scoped_lock lock{m_mutex}; if (index != m_handlers.end()) {
HandlerTable::iterator index = m_handlers.find(target); index->second.clear();
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();
}
} }
// handler is erased here. It is done outside of lock in order to avoid potential deadlock.
} }
bool EventQueue::isEmpty() const bool EventQueue::isEmpty() const
@ -304,14 +290,14 @@ bool EventQueue::isEmpty() const
return (m_buffer->isEmpty() && getNextTimerTimeout() != 0.0); 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}; std::scoped_lock lock{m_mutex};
if (HandlerTable::const_iterator index = m_handlers.find(target); index != m_handlers.end()) { if (HandlerTable::const_iterator index = m_handlers.find(target); index != m_handlers.end()) {
const TypeHandlerTable &typeHandlers = index->second; const TypeHandlerTable &typeHandlers = index->second;
TypeHandlerTable::const_iterator index2 = typeHandlers.find(type); TypeHandlerTable::const_iterator index2 = typeHandlers.find(type);
if (index2 != typeHandlers.end()) { if (index2 != typeHandlers.end()) {
return index2->second.get(); return &index2->second;
} }
} }
return nullptr; return nullptr;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -43,15 +44,15 @@ public:
EventQueueTimer *newTimer(double duration, void *target) override; EventQueueTimer *newTimer(double duration, void *target) override;
EventQueueTimer *newOneShotTimer(double duration, void *target) override; EventQueueTimer *newOneShotTimer(double duration, void *target) override;
void deleteTimer(EventQueueTimer *) 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 removeHandler(EventTypes type, void *target) override;
void removeHandlers(void *target) override; void removeHandlers(void *target) override;
bool isEmpty() const override; bool isEmpty() const override;
IEventJob *getHandler(EventTypes type, void *target) const override;
void *getSystemTarget() override; void *getSystemTarget() override;
void waitForReady() const override; void waitForReady() const override;
private: private:
const EventHandler *getHandler(EventTypes type, void *target) const;
uint32_t saveEvent(const Event &event); uint32_t saveEvent(const Event &event);
Event removeEvent(uint32_t eventID); Event removeEvent(uint32_t eventID);
bool hasTimerExpired(Event &event); bool hasTimerExpired(Event &event);
@ -99,7 +100,7 @@ private:
using TimerQueue = PriorityQueue<Timer>; using TimerQueue = PriorityQueue<Timer>;
using EventTable = std::map<uint32_t, Event>; using EventTable = std::map<uint32_t, Event>;
using EventIDList = std::vector<uint32_t>; using EventIDList = std::vector<uint32_t>;
using TypeHandlerTable = std::map<EventTypes, std::unique_ptr<IEventJob>>; using TypeHandlerTable = std::map<EventTypes, EventHandler>;
using HandlerTable = std::map<void *, TypeHandlerTable>; using HandlerTable = std::map<void *, TypeHandlerTable>;
int m_systemTarget = 0; int m_systemTarget = 0;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -10,9 +11,10 @@
#include "base/Event.h" #include "base/Event.h"
#include "base/EventTypes.h" #include "base/EventTypes.h"
#include "common/IInterface.h" #include "common/IInterface.h"
#include <functional>
#include <string> #include <string>
class IEventJob;
class IEventQueueBuffer; class IEventQueueBuffer;
// Opaque type for timer info. This is defined by subclasses of // Opaque type for timer info. This is defined by subclasses of
@ -29,6 +31,7 @@ timers which generate events periodically.
class IEventQueue : public IInterface class IEventQueue : public IInterface
{ {
public: public:
using EventHandler = std::function<void(const Event &)>;
class TimerEvent class TimerEvent
{ {
public: public:
@ -64,6 +67,9 @@ public:
/*! /*!
Looks up the dispatcher for the event's target and invokes it. Looks up the dispatcher for the event's target and invokes it.
Returns true iff a dispatcher exists for the target. 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; 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 of type \p type. If no such handler exists it will use the handler
for \p target and type \p kUnknown if it exists. 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 //! Unregister an event handler for an event type
/*! /*!
@ -152,13 +158,6 @@ public:
*/ */
virtual bool isEmpty() const = 0; 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 //! Get the system event type target
/*! /*!
Returns the target to use for dispatching \c EventTypes::System events. Returns the target to use for dispatching \c EventTypes::System events.

View file

@ -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 T> 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 <class T>
inline TMethodEventJob<T>::TMethodEventJob(T *object, void (T::*method)(const Event &, void *), void *arg)
: m_object(object),
m_method(method),
m_arg(arg)
{
// do nothing
}
template <class T> inline void TMethodEventJob<T>::run(const Event &event)
{
if (m_object != nullptr) {
(m_object->*m_method)(event, m_arg);
}
}

View file

@ -11,7 +11,6 @@
#include "arch/Arch.h" #include "arch/Arch.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "client/ServerProxy.h" #include "client/ServerProxy.h"
#include "deskflow/AppUtil.h" #include "deskflow/AppUtil.h"
@ -60,12 +59,8 @@ Client::Client(
assert(m_screen != nullptr); assert(m_screen != nullptr);
// register suspend/resume event handlers // register suspend/resume event handlers
m_events->adoptHandler( m_events->addHandler(EventTypes::ScreenSuspend, getEventTarget(), [this](const auto &) { handleSuspend(); });
EventTypes::ScreenSuspend, getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleSuspend) m_events->addHandler(EventTypes::ScreenResume, getEventTarget(), [this](const auto &) { handleResume(); });
);
m_events->adoptHandler(
EventTypes::ScreenResume, getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleResume)
);
m_pHelloBack = std::make_unique<HelloBack>(std::make_shared<HelloBack::Deps>( m_pHelloBack = std::make_unique<HelloBack>(std::make_shared<HelloBack::Deps>(
[this]() { [this]() {
@ -395,51 +390,41 @@ void Client::setupConnecting()
assert(m_stream != nullptr); assert(m_stream != nullptr);
if (m_args.m_enableCrypto) { if (m_args.m_enableCrypto) {
m_events->adoptHandler( m_events->addHandler(EventTypes::DataSocketSecureConnected, m_stream->getEventTarget(), [this](const auto &) {
EventTypes::DataSocketSecureConnected, m_stream->getEventTarget(), handleConnected();
new TMethodEventJob<Client>(this, &Client::handleConnected) });
);
} else { } else {
m_events->adoptHandler( m_events->addHandler(EventTypes::DataSocketConnected, m_stream->getEventTarget(), [this](const auto &) {
EventTypes::DataSocketConnected, m_stream->getEventTarget(), handleConnected();
new TMethodEventJob<Client>(this, &Client::handleConnected) });
);
} }
m_events->addHandler(EventTypes::DataSocketConnectionFailed, m_stream->getEventTarget(), [this](const auto &e) {
m_events->adoptHandler( handleConnectionFailed(e);
EventTypes::DataSocketConnectionFailed, m_stream->getEventTarget(), });
new TMethodEventJob<Client>(this, &Client::handleConnectionFailed)
);
} }
void Client::setupConnection() void Client::setupConnection()
{ {
assert(m_stream != nullptr); assert(m_stream != nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::SocketDisconnected, m_stream->getEventTarget(), [this](const auto &) {
EventTypes::SocketDisconnected, m_stream->getEventTarget(), handleDisconnected();
new TMethodEventJob<Client>(this, &Client::handleDisconnected) });
); m_events->addHandler(EventTypes::StreamInputReady, m_stream->getEventTarget(), [this](const auto &) {
m_events->adoptHandler( handleHello();
EventTypes::StreamInputReady, m_stream->getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleHello) });
); m_events->addHandler(EventTypes::StreamOutputError, m_stream->getEventTarget(), [this](const auto &) {
m_events->adoptHandler( handleOutputError();
EventTypes::StreamOutputError, m_stream->getEventTarget(), });
new TMethodEventJob<Client>(this, &Client::handleOutputError) m_events->addHandler(EventTypes::StreamInputShutdown, m_stream->getEventTarget(), [this](const auto &) {
); handleDisconnected();
m_events->adoptHandler( });
EventTypes::StreamInputShutdown, m_stream->getEventTarget(), m_events->addHandler(EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), [this](const auto &) {
new TMethodEventJob<Client>(this, &Client::handleDisconnected) handleDisconnected();
); });
m_events->adoptHandler( m_events->addHandler(EventTypes::SocketStopRetry, m_stream->getEventTarget(), [this](const auto &) {
EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), handleStopRetry();
new TMethodEventJob<Client>(this, &Client::handleDisconnected) });
);
m_events->adoptHandler(
EventTypes::SocketStopRetry, m_stream->getEventTarget(),
new TMethodEventJob<Client>(this, &Client::handleStopRetry)
);
} }
void Client::setupScreen() void Client::setupScreen()
@ -448,19 +433,19 @@ void Client::setupScreen()
m_ready = false; m_ready = false;
m_server = new ServerProxy(this, m_stream, m_events); m_server = new ServerProxy(this, m_stream, m_events);
m_events->adoptHandler( m_events->addHandler(EventTypes::ScreenShapeChanged, getEventTarget(), [this](const auto &) {
EventTypes::ScreenShapeChanged, getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleShapeChanged) handleShapeChanged();
); });
m_events->adoptHandler( m_events->addHandler(EventTypes::ClipboardGrabbed, getEventTarget(), [this](const auto &e) {
EventTypes::ClipboardGrabbed, getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleClipboardGrabbed) handleClipboardGrabbed(e);
); });
} }
void Client::setupTimer() void Client::setupTimer()
{ {
assert(m_timer == nullptr); assert(m_timer == nullptr);
m_timer = m_events->newOneShotTimer(2.0, nullptr); m_timer = m_events->newOneShotTimer(2.0, nullptr);
m_events->adoptHandler(EventTypes::Timer, m_timer, new TMethodEventJob<Client>(this, &Client::handleConnectTimeout)); m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { handleConnectTimeout(); });
} }
void Client::cleanup() void Client::cleanup()
@ -522,7 +507,7 @@ void Client::cleanupStream()
m_stream = nullptr; m_stream = nullptr;
} }
void Client::handleConnected(const Event &, void *) void Client::handleConnected()
{ {
LOG((CLOG_DEBUG1 "connected, waiting for hello")); LOG((CLOG_DEBUG1 "connected, waiting for hello"));
cleanupConnecting(); 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<IDataSocket::ConnectionFailedInfo *>(event.getData()); auto *info = static_cast<IDataSocket::ConnectionFailedInfo *>(event.getData());
@ -548,7 +533,7 @@ void Client::handleConnectionFailed(const Event &event, void *)
delete info; delete info;
} }
void Client::handleConnectTimeout(const Event &, void *) void Client::handleConnectTimeout()
{ {
cleanupTimer(); cleanupTimer();
cleanupConnecting(); cleanupConnecting();
@ -558,7 +543,7 @@ void Client::handleConnectTimeout(const Event &, void *)
sendConnectionFailedEvent("Timed out"); sendConnectionFailedEvent("Timed out");
} }
void Client::handleOutputError(const Event &, void *) void Client::handleOutputError()
{ {
cleanupTimer(); cleanupTimer();
cleanupScreen(); cleanupScreen();
@ -567,7 +552,7 @@ void Client::handleOutputError(const Event &, void *)
sendEvent(EventTypes::ClientDisconnected, nullptr); sendEvent(EventTypes::ClientDisconnected, nullptr);
} }
void Client::handleDisconnected(const Event &, void *) void Client::handleDisconnected()
{ {
cleanupTimer(); cleanupTimer();
cleanupScreen(); cleanupScreen();
@ -576,13 +561,13 @@ void Client::handleDisconnected(const Event &, void *)
sendEvent(EventTypes::ClientDisconnected, nullptr); sendEvent(EventTypes::ClientDisconnected, nullptr);
} }
void Client::handleShapeChanged(const Event &, void *) void Client::handleShapeChanged()
{ {
LOG((CLOG_DEBUG "resolution changed")); LOG((CLOG_DEBUG "resolution changed"));
m_server->onInfoChanged(); m_server->onInfoChanged();
} }
void Client::handleClipboardGrabbed(const Event &event, void *) void Client::handleClipboardGrabbed(const Event &event)
{ {
if (!m_enableClipboard || (m_maximumClipboardSize == 0)) { if (!m_enableClipboard || (m_maximumClipboardSize == 0)) {
return; 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); 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) { if (!m_suspended) {
LOG((CLOG_INFO "suspend")); 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) { if (m_suspended) {
LOG((CLOG_INFO "resume")); 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; m_args.m_restartable = false;
} }

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -168,17 +169,17 @@ private:
void cleanupScreen(); void cleanupScreen();
void cleanupTimer(); void cleanupTimer();
void cleanupStream(); void cleanupStream();
void handleConnected(const Event &, void *); void handleConnected();
void handleConnectionFailed(const Event &, void *); void handleConnectionFailed(const Event &event);
void handleConnectTimeout(const Event &, void *); void handleConnectTimeout();
void handleOutputError(const Event &, void *); void handleOutputError();
void handleDisconnected(const Event &, void *); void handleDisconnected();
void handleShapeChanged(const Event &, void *); void handleShapeChanged();
void handleClipboardGrabbed(const Event &, void *); void handleClipboardGrabbed(const Event &event);
void handleHello(const Event &, void *); void handleHello();
void handleSuspend(const Event &event, void *); void handleSuspend();
void handleResume(const Event &event, void *); void handleResume();
void handleStopRetry(const Event &, void *); void handleStopRetry();
void sendClipboardThread(void *); void sendClipboardThread(void *);
void bindNetworkInterface(IDataSocket *socket) const; void bindNetworkInterface(IDataSocket *socket) const;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -9,7 +10,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/XBase.h" #include "base/XBase.h"
#include "client/Client.h" #include "client/Client.h"
#include "deskflow/AppUtil.h" #include "deskflow/AppUtil.h"
@ -44,15 +44,10 @@ ServerProxy::ServerProxy(Client *client, deskflow::IStream *stream, IEventQueue
m_modifierTranslationTable[id] = id; m_modifierTranslationTable[id] = id;
// handle data on stream // handle data on stream
m_events->adoptHandler( m_events->addHandler(EventTypes::StreamInputReady, m_stream->getEventTarget(), [this](const auto &) {
EventTypes::StreamInputReady, m_stream->getEventTarget(), handleData();
new TMethodEventJob<ServerProxy>(this, &ServerProxy::handleData) });
); m_events->addHandler(EventTypes::ClipboardSending, this, [this](const auto &e) { handleClipboardSendingEvent(e); });
m_events->adoptHandler(
EventTypes::ClipboardSending, this,
new TMethodEventJob<ServerProxy>(this, &ServerProxy::handleClipboardSendingEvent)
);
// send heartbeat // send heartbeat
setKeepAliveRate(kKeepAliveRate); setKeepAliveRate(kKeepAliveRate);
@ -73,10 +68,7 @@ void ServerProxy::resetKeepAliveAlarm()
} }
if (m_keepAliveAlarm > 0.0) { if (m_keepAliveAlarm > 0.0) {
m_keepAliveAlarmTimer = m_events->newOneShotTimer(m_keepAliveAlarm, nullptr); m_keepAliveAlarmTimer = m_events->newOneShotTimer(m_keepAliveAlarm, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, m_keepAliveAlarmTimer, [this](const auto &) { handleKeepAliveAlarm(); });
EventTypes::Timer, m_keepAliveAlarmTimer,
new TMethodEventJob<ServerProxy>(this, &ServerProxy::handleKeepAliveAlarm)
);
} }
} }
@ -86,7 +78,7 @@ void ServerProxy::setKeepAliveRate(double rate)
resetKeepAliveAlarm(); resetKeepAliveAlarm();
} }
void ServerProxy::handleData(const Event &, void *) void ServerProxy::handleData()
{ {
// handle messages until there are no more. first read message code. // handle messages until there are no more. first read message code.
uint8_t code[4]; uint8_t code[4];
@ -333,7 +325,7 @@ ServerProxy::EResult ServerProxy::parseMessage(const uint8_t *code)
return kOkay; return kOkay;
} }
void ServerProxy::handleKeepAliveAlarm(const Event &, void *) void ServerProxy::handleKeepAliveAlarm()
{ {
LOG((CLOG_NOTE "server is dead")); LOG((CLOG_NOTE "server is dead"));
m_client->disconnect("server is not responding"); m_client->disconnect("server is not responding");
@ -813,7 +805,7 @@ void ServerProxy::infoAcknowledgment()
m_ignoreMouse = false; m_ignoreMouse = false;
} }
void ServerProxy::handleClipboardSendingEvent(const Event &event, void *) void ServerProxy::handleClipboardSendingEvent(const Event &event)
{ {
ClipboardChunk::send(m_stream, event.getDataObject()); ClipboardChunk::send(m_stream, event.getDataObject());
} }

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -74,8 +75,8 @@ private:
KeyModifierMask translateModifierMask(KeyModifierMask) const; KeyModifierMask translateModifierMask(KeyModifierMask) const;
// event handlers // event handlers
void handleData(const Event &, void *); void handleData();
void handleKeepAliveAlarm(const Event &, void *); void handleKeepAliveAlarm();
// message handlers // message handlers
void enter(); void enter();
@ -95,7 +96,7 @@ private:
void setOptions(); void setOptions();
void queryInfo(); void queryInfo();
void infoAcknowledgment(); void infoAcknowledgment();
void handleClipboardSendingEvent(const Event &, void *); void handleClipboardSendingEvent(const Event &event);
void secureInputNotification(); void secureInputNotification();
void setServerLanguages(); void setServerLanguages();
void setActiveServerLanguage(const std::string &language); void setActiveServerLanguage(const std::string &language);

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -11,7 +12,6 @@
#include "base/Event.h" #include "base/Event.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "client/Client.h" #include "client/Client.h"
#include "common/Constants.h" #include "common/Constants.h"
#include "deskflow/ArgParser.h" #include "deskflow/ArgParser.h"
@ -200,7 +200,7 @@ void ClientApp::updateStatus(const std::string &msg) const
// do nothing // do nothing
} }
void ClientApp::handleScreenError(const Event &, void *) void ClientApp::handleScreenError()
{ {
LOG((CLOG_CRIT "error on screen")); LOG((CLOG_CRIT "error on screen"));
m_events->addEvent(Event(EventTypes::Quit)); m_events->addEvent(Event(EventTypes::Quit));
@ -209,10 +209,9 @@ void ClientApp::handleScreenError(const Event &, void *)
deskflow::Screen *ClientApp::openClientScreen() deskflow::Screen *ClientApp::openClientScreen()
{ {
deskflow::Screen *screen = createScreen(); deskflow::Screen *screen = createScreen();
m_events->adoptHandler( m_events->addHandler(EventTypes::ScreenError, screen->getEventTarget(), [this](const auto &) {
EventTypes::ScreenError, screen->getEventTarget(), handleScreenError();
new TMethodEventJob<ClientApp>(this, &ClientApp::handleScreenError) });
);
return screen; 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 // discard old timer
auto *timer = static_cast<EventQueueTimer *>(vtimer);
m_events->deleteTimer(timer); m_events->deleteTimer(timer);
m_events->removeHandler(EventTypes::Timer, timer); m_events->removeHandler(EventTypes::Timer, timer);
@ -240,18 +238,16 @@ void ClientApp::scheduleClientRestart(double retryTime)
// install a timer and handler to retry later // install a timer and handler to retry later
LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
EventQueueTimer *timer = m_events->newOneShotTimer(retryTime, nullptr); EventQueueTimer *timer = m_events->newOneShotTimer(retryTime, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, timer, [this, timer](const auto &e) { handleClientRestart(e, timer); });
EventTypes::Timer, timer, new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientRestart, timer)
);
} }
void ClientApp::handleClientConnected(const Event &, void *) void ClientApp::handleClientConnected()
{ {
LOG((CLOG_NOTE "connected to server")); LOG((CLOG_NOTE "connected to server"));
updateStatus(); updateStatus();
} }
void ClientApp::handleClientFailed(const Event &e, void *) void ClientApp::handleClientFailed(const Event &e)
{ {
if ((++m_lastServerAddressIndex) < m_client->getLastResolvedAddressesCount()) { if ((++m_lastServerAddressIndex) < m_client->getLastResolvedAddressesCount()) {
std::unique_ptr<Client::FailInfo> info(static_cast<Client::FailInfo *>(e.getData())); std::unique_ptr<Client::FailInfo> info(static_cast<Client::FailInfo *>(e.getData()));
@ -263,11 +259,11 @@ void ClientApp::handleClientFailed(const Event &e, void *)
} }
} else { } else {
m_lastServerAddressIndex = 0; m_lastServerAddressIndex = 0;
handleClientRefused(e, nullptr); handleClientRefused(e);
} }
} }
void ClientApp::handleClientRefused(const Event &e, void *) void ClientApp::handleClientRefused(const Event &e)
{ {
std::unique_ptr<Client::FailInfo> info(static_cast<Client::FailInfo *>(e.getData())); std::unique_ptr<Client::FailInfo> info(static_cast<Client::FailInfo *>(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")); LOG((CLOG_NOTE "disconnected from server"));
if (!args().m_restartable) { 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()); auto *client = new Client(m_events, name, address, getSocketFactory(), screen, args());
try { try {
m_events->adoptHandler( m_events->addHandler(EventTypes::ClientConnected, client->getEventTarget(), [this](const auto &) {
EventTypes::ClientConnected, client->getEventTarget(), handleClientConnected();
new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientConnected) });
); m_events->addHandler(EventTypes::ClientConnectionFailed, client->getEventTarget(), [this](const auto &e) {
handleClientFailed(e);
m_events->adoptHandler( });
EventTypes::ClientConnectionFailed, client->getEventTarget(), m_events->addHandler(EventTypes::ClientConnectionRefused, client->getEventTarget(), [this](const auto &e) {
new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientFailed) handleClientRefused(e);
); });
m_events->addHandler(EventTypes::ClientDisconnected, client->getEventTarget(), [this](const auto &) {
m_events->adoptHandler( handleClientDisconnected();
EventTypes::ClientConnectionRefused, client->getEventTarget(), });
new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientRefused)
);
m_events->adoptHandler(
EventTypes::ClientDisconnected, client->getEventTarget(),
new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientDisconnected)
);
} catch (std::bad_alloc &ba) { } catch (std::bad_alloc &ba) {
delete client; delete client;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -64,15 +65,15 @@ public:
void updateStatus() const; void updateStatus() const;
void updateStatus(const std::string &msg) const; void updateStatus(const std::string &msg) const;
void handleScreenError(const Event &, void *); void handleScreenError();
deskflow::Screen *openClientScreen(); deskflow::Screen *openClientScreen();
void closeClientScreen(deskflow::Screen *screen); void closeClientScreen(deskflow::Screen *screen);
void handleClientRestart(const Event &, void *vtimer); void handleClientRestart(const Event &, EventQueueTimer *vtimer);
void scheduleClientRestart(double retryTime); void scheduleClientRestart(double retryTime);
void handleClientConnected(const Event &, void *); void handleClientConnected();
void handleClientFailed(const Event &e, void *); void handleClientFailed(const Event &e);
void handleClientRefused(const Event &e, void *); void handleClientRefused(const Event &e);
void handleClientDisconnected(const Event &, void *); void handleClientDisconnected();
Client *openClient(const std::string &name, const NetworkAddress &address, deskflow::Screen *screen); Client *openClient(const std::string &name, const NetworkAddress &address, deskflow::Screen *screen);
void closeClient(Client *client); void closeClient(Client *client);
bool startClient(); bool startClient();

View file

@ -60,7 +60,6 @@ public:
private: private:
void daemonize(); void daemonize();
void handleError(const char *message); void handleError(const char *message);
void handleIpcMessage(const Event &e, void *);
int mainLoop(); int mainLoop();
int daemonLoop(); int daemonLoop();
void saveLogLevel(const QString &logLevel) const; void saveLogLevel(const QString &logLevel) const;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * 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 A platform screen is expected to install a handler for system
events in its c'tor like so: events in its c'tor like so:
\code \code
m_events->adoptHandler(EventTypes::System, m_events->addHandler(EventTypes::System,
m_events->getSystemTarget(), m_events->getSystemTarget(),
new TMethodEventJob<CXXXPlatformScreen>(this, [this] (const auto &e) {handleSystemEvent(e);});
&CXXXPlatformScreen::handleSystemEvent));
\endcode \endcode
It should remove the handler in its d'tor. Override the It should remove the handler in its d'tor. Override the
\c handleSystemEvent() method to process system events. \c handleSystemEvent() method to process system events.
@ -211,5 +211,5 @@ protected:
The target of all events should be the value returned by The target of all events should be the value returned by
\c getEventTarget(). \c getEventTarget().
*/ */
virtual void handleSystemEvent(const Event &event, void *) = 0; virtual void handleSystemEvent(const Event &event) = 0;
}; };

View file

@ -7,7 +7,6 @@
#include "deskflow/PacketStreamFilter.h" #include "deskflow/PacketStreamFilter.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
#include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolTypes.h"
#include <cstring> #include <cstring>

View file

@ -96,7 +96,7 @@ protected:
virtual IKeyState *getKeyState() const = 0; virtual IKeyState *getKeyState() const = 0;
// IPlatformScreen overrides // IPlatformScreen overrides
void handleSystemEvent(const Event &event, void *) override = 0; void handleSystemEvent(const Event &event) override = 0;
/*! /*!
* \brief mapClientScrollDirection * \brief mapClientScrollDirection

View file

@ -8,7 +8,6 @@
#include "deskflow/Screen.h" #include "deskflow/Screen.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/IPlatformScreen.h" #include "deskflow/IPlatformScreen.h"
#include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolTypes.h"
#include "server/ClientProxy.h" #include "server/ClientProxy.h"

View file

@ -12,7 +12,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/Path.h" #include "base/Path.h"
#include "base/TMethodEventJob.h"
#include "deskflow/App.h" #include "deskflow/App.h"
#include "deskflow/ArgParser.h" #include "deskflow/ArgParser.h"
#include "deskflow/Screen.h" #include "deskflow/Screen.h"
@ -150,7 +149,7 @@ void ServerApp::reloadSignalHandler(Arch::ESignal, void *)
events->addEvent(Event(EventTypes::ServerAppReloadConfig, events->getSystemTarget())); events->addEvent(Event(EventTypes::ServerAppReloadConfig, events->getSystemTarget()));
} }
void ServerApp::reloadConfig(const Event &, void *) void ServerApp::reloadConfig()
{ {
LOG((CLOG_DEBUG "reload configuration")); LOG((CLOG_DEBUG "reload configuration"));
if (loadConfig(args().m_configFile)) { if (loadConfig(args().m_configFile)) {
@ -195,16 +194,15 @@ bool ServerApp::loadConfig(const std::string &pathname)
return false; return false;
} }
void ServerApp::forceReconnect(const Event &, void *) void ServerApp::forceReconnect()
{ {
if (m_server != nullptr) { if (m_server != nullptr) {
m_server->disconnect(); m_server->disconnect();
} }
} }
void ServerApp::handleClientConnected(const Event &, void *vlistener) void ServerApp::handleClientConnected(const Event &, ClientListener *listener)
{ {
auto *listener = static_cast<ClientListener *>(vlistener);
ClientProxy *client = listener->getNextClient(); ClientProxy *client = listener->getNextClient();
if (client != nullptr) { if (client != nullptr) {
m_server->adoptClient(client); 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)); 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 // wait for clients to disconnect for up to timeout seconds
double timeout = 3.0; double timeout = 3.0;
EventQueueTimer *timer = m_events->newOneShotTimer(timeout, nullptr); EventQueueTimer *timer = m_events->newOneShotTimer(timeout, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, timer, [this](const auto &) { handleClientsDisconnected(); });
EventTypes::Timer, timer, new TMethodEventJob<ServerApp>(this, &ServerApp::handleClientsDisconnected) m_events->addHandler(EventTypes::ServerDisconnected, server, [this](const auto &) { handleClientsDisconnected(); });
);
m_events->adoptHandler(
EventTypes::ServerDisconnected, server,
new TMethodEventJob<ServerApp>(this, &ServerApp::handleClientsDisconnected)
);
m_events->loop(); m_events->loop();
@ -323,7 +316,7 @@ void ServerApp::cleanupServer()
assert(m_serverState == kUninitialized); assert(m_serverState == kUninitialized);
} }
void ServerApp::retryHandler(const Event &, void *) void ServerApp::retryHandler()
{ {
// discard old timer // discard old timer
assert(m_timer != nullptr); assert(m_timer != nullptr);
@ -410,7 +403,7 @@ bool ServerApp::initServer()
assert(m_timer == nullptr); assert(m_timer == nullptr);
LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
m_timer = m_events->newOneShotTimer(retryTime, nullptr); m_timer = m_events->newOneShotTimer(retryTime, nullptr);
m_events->adoptHandler(EventTypes::Timer, m_timer, new TMethodEventJob<ServerApp>(this, &ServerApp::retryHandler)); m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { retryHandler(); });
m_serverState = kInitializing; m_serverState = kInitializing;
return true; return true;
} else { } else {
@ -422,17 +415,11 @@ bool ServerApp::initServer()
deskflow::Screen *ServerApp::openServerScreen() deskflow::Screen *ServerApp::openServerScreen()
{ {
deskflow::Screen *screen = createScreen(); deskflow::Screen *screen = createScreen();
m_events->adoptHandler( m_events->addHandler(EventTypes::ScreenError, screen->getEventTarget(), [this](const auto &) {
EventTypes::ScreenError, screen->getEventTarget(), handleScreenError();
new TMethodEventJob<ServerApp>(this, &ServerApp::handleScreenError) });
); m_events->addHandler(EventTypes::ScreenSuspend, screen->getEventTarget(), [this](const auto &) { handleSuspend(); });
m_events->adoptHandler( m_events->addHandler(EventTypes::ScreenResume, screen->getEventTarget(), [this](const auto &) { handleResume(); });
EventTypes::ScreenSuspend, screen->getEventTarget(),
new TMethodEventJob<ServerApp>(this, &ServerApp::handleSuspend)
);
m_events->adoptHandler(
EventTypes::ScreenResume, screen->getEventTarget(), new TMethodEventJob<ServerApp>(this, &ServerApp::handleResume)
);
return screen; return screen;
} }
@ -488,7 +475,7 @@ bool ServerApp::startServer()
const auto retryTime = 10.0; const auto retryTime = 10.0;
LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
m_timer = m_events->newOneShotTimer(retryTime, nullptr); m_timer = m_events->newOneShotTimer(retryTime, nullptr);
m_events->adoptHandler(EventTypes::Timer, m_timer, new TMethodEventJob<ServerApp>(this, &ServerApp::retryHandler)); m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { retryHandler(); });
m_serverState = kStarting; m_serverState = kStarting;
return true; return true;
} else { } else {
@ -528,13 +515,13 @@ PrimaryClient *ServerApp::openPrimaryClient(const std::string &name, deskflow::S
return new PrimaryClient(name, screen); return new PrimaryClient(name, screen);
} }
void ServerApp::handleScreenError(const Event &, void *) void ServerApp::handleScreenError()
{ {
LOG((CLOG_CRIT "error on screen")); LOG((CLOG_CRIT "error on screen"));
m_events->addEvent(Event(EventTypes::Quit)); m_events->addEvent(Event(EventTypes::Quit));
} }
void ServerApp::handleSuspend(const Event &, void *) void ServerApp::handleSuspend()
{ {
if (!m_suspended) { if (!m_suspended) {
LOG((CLOG_INFO "suspend")); 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) { if (m_suspended) {
LOG((CLOG_INFO "resume")); LOG((CLOG_INFO "resume"));
@ -559,10 +546,9 @@ ClientListener *ServerApp::openClientListener(const NetworkAddress &address)
auto *listen = new ClientListener(getAddress(address), getSocketFactory(), m_events, securityLevel); auto *listen = new ClientListener(getAddress(address), getSocketFactory(), m_events, securityLevel);
m_events->adoptHandler( m_events->addHandler(EventTypes::ClientListenerAccepted, listen, [this, listen](const auto &e) {
EventTypes::ClientListenerAccepted, listen, handleClientConnected(e, listen);
new TMethodEventJob<ServerApp>(this, &ServerApp::handleClientConnected, listen) });
);
return 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()); auto *server = new Server(config, primaryClient, m_serverScreen, m_events, args());
try { try {
m_events->adoptHandler( m_events->addHandler(EventTypes::ServerDisconnected, server, [this](const auto &) { handleNoClients(); });
EventTypes::ServerDisconnected, server, new TMethodEventJob<ServerApp>(this, &ServerApp::handleNoClients) m_events->addHandler(EventTypes::ServerScreenSwitched, server, [this](const auto &e) { handleScreenSwitched(e); });
);
m_events->adoptHandler(
EventTypes::ServerScreenSwitched, server, new TMethodEventJob<ServerApp>(this, &ServerApp::handleScreenSwitched)
);
} catch (std::bad_alloc &ba) { } catch (std::bad_alloc &ba) {
delete server; delete server;
@ -587,12 +568,12 @@ Server *ServerApp::openServer(ServerConfig &config, PrimaryClient *primaryClient
return server; return server;
} }
void ServerApp::handleNoClients(const Event &, void *) void ServerApp::handleNoClients()
{ {
updateStatus(); updateStatus();
} }
void ServerApp::handleScreenSwitched(const Event &e, void *) void ServerApp::handleScreenSwitched(const Event &e)
{ {
// do nothing // do nothing
} }
@ -640,24 +621,21 @@ int ServerApp::mainLoop()
// handle hangup signal by reloading the server's configuration // handle hangup signal by reloading the server's configuration
ARCH->setSignalHandler(Arch::kHANGUP, &reloadSignalHandler, nullptr); ARCH->setSignalHandler(Arch::kHANGUP, &reloadSignalHandler, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::ServerAppReloadConfig, m_events->getSystemTarget(), [this](const auto &) {
EventTypes::ServerAppReloadConfig, m_events->getSystemTarget(), reloadConfig();
new TMethodEventJob<ServerApp>(this, &ServerApp::reloadConfig) });
);
// handle force reconnect event by disconnecting clients. they'll // handle force reconnect event by disconnecting clients. they'll
// reconnect automatically. // reconnect automatically.
m_events->adoptHandler( m_events->addHandler(EventTypes::ServerAppForceReconnect, m_events->getSystemTarget(), [this](const auto &) {
EventTypes::ServerAppForceReconnect, m_events->getSystemTarget(), forceReconnect();
new TMethodEventJob<ServerApp>(this, &ServerApp::forceReconnect) });
);
// to work around the sticky meta keys problem, we'll give users // to work around the sticky meta keys problem, we'll give users
// the option to reset the state of the server. // the option to reset the state of the server.
m_events->adoptHandler( m_events->addHandler(EventTypes::ServerAppResetServer, m_events->getSystemTarget(), [this](const auto &) {
EventTypes::ServerAppResetServer, m_events->getSystemTarget(), resetServer();
new TMethodEventJob<ServerApp>(this, &ServerApp::resetServer) });
);
// run event loop. if startServer() failed we're supposed to retry // run event loop. if startServer() failed we're supposed to retry
// later. the timer installed by startServer() will take care of // later. the timer installed by startServer() will take care of
@ -690,7 +668,7 @@ int ServerApp::mainLoop()
return kExitSuccess; return kExitSuccess;
} }
void ServerApp::resetServer(const Event &, void *) void ServerApp::resetServer()
{ {
LOG((CLOG_DEBUG1 "resetting server")); LOG((CLOG_DEBUG1 "resetting server"));
stopServer(); stopServer();

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -78,11 +79,11 @@ public:
// Regular functions // Regular functions
// //
void reloadConfig(const Event &, void *); void reloadConfig();
void forceReconnect(const Event &, void *); void forceReconnect();
void resetServer(const Event &, void *); void resetServer();
void handleClientConnected(const Event &, void *vlistener); void handleClientConnected(const Event &e, ClientListener *listener);
void handleClientsDisconnected(const Event &, void *); void handleClientsDisconnected();
void closeServer(Server *server); void closeServer(Server *server);
void stopRetryTimer(); void stopRetryTimer();
void updateStatus() const; void updateStatus() const;
@ -93,15 +94,15 @@ public:
void closeServerScreen(deskflow::Screen *screen); void closeServerScreen(deskflow::Screen *screen);
void cleanupServer(); void cleanupServer();
bool initServer(); bool initServer();
void retryHandler(const Event &, void *); void retryHandler();
deskflow::Screen *openServerScreen(); deskflow::Screen *openServerScreen();
PrimaryClient *openPrimaryClient(const std::string &name, deskflow::Screen *screen); PrimaryClient *openPrimaryClient(const std::string &name, deskflow::Screen *screen);
void handleScreenError(const Event &, void *); void handleScreenError();
void handleSuspend(const Event &, void *); void handleSuspend();
void handleResume(const Event &, void *); void handleResume();
ClientListener *openClientListener(const NetworkAddress &address); ClientListener *openClientListener(const NetworkAddress &address);
Server *openServer(ServerConfig &config, PrimaryClient *primaryClient); Server *openServer(ServerConfig &config, PrimaryClient *primaryClient);
void handleNoClients(const Event &, void *); void handleNoClients();
bool startServer(); bool startServer();
Server *getServerPtr() Server *getServerPtr()
{ {
@ -124,7 +125,7 @@ public:
} }
private: private:
void handleScreenSwitched(const Event &, void *data); void handleScreenSwitched(const Event &e);
ISocketFactory *getSocketFactory() const; ISocketFactory *getSocketFactory() const;
NetworkAddress getAddress(const NetworkAddress &address) const; NetworkAddress getAddress(const NetworkAddress &address) const;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -7,7 +8,6 @@
#include "io/StreamFilter.h" #include "io/StreamFilter.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
// //
// StreamFilter // StreamFilter
@ -20,10 +20,9 @@ StreamFilter::StreamFilter(IEventQueue *events, deskflow::IStream *stream, bool
{ {
// replace handlers for m_stream // replace handlers for m_stream
m_events->removeHandlers(m_stream->getEventTarget()); m_events->removeHandlers(m_stream->getEventTarget());
m_events->adoptHandler( m_events->addHandler(EventTypes::Unknown, m_stream->getEventTarget(), [this](const auto &e) {
EventTypes::Unknown, m_stream->getEventTarget(), handleUpstreamEvent(e);
new TMethodEventJob<StreamFilter>(this, &StreamFilter::handleUpstreamEvent) });
);
} }
StreamFilter::~StreamFilter() StreamFilter::~StreamFilter()
@ -89,7 +88,7 @@ void StreamFilter::filterEvent(const Event &event)
m_events->dispatchEvent(Event(event.getType(), getEventTarget(), event.getData())); m_events->dispatchEvent(Event(event.getType(), getEventTarget(), event.getData()));
} }
void StreamFilter::handleUpstreamEvent(const Event &event, void *) void StreamFilter::handleUpstreamEvent(const Event &event)
{ {
filterEvent(event); filterEvent(event);
} }

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -59,7 +60,7 @@ protected:
virtual void filterEvent(const Event &); virtual void filterEvent(const Event &);
private: private:
void handleUpstreamEvent(const Event &, void *); void handleUpstreamEvent(const Event &);
private: private:
deskflow::IStream *m_stream; deskflow::IStream *m_stream;

View file

@ -12,7 +12,6 @@
#include "base/Log.h" #include "base/Log.h"
#include "base/Path.h" #include "base/Path.h"
#include "base/String.h" #include "base/String.h"
#include "base/TMethodEventJob.h"
#include "common/Settings.h" #include "common/Settings.h"
#include "mt/Lock.h" #include "mt/Lock.h"
#include "net/FingerprintDatabase.h" #include "net/FingerprintDatabase.h"
@ -87,11 +86,9 @@ void SecureSocket::close()
void SecureSocket::connect(const NetworkAddress &addr) void SecureSocket::connect(const NetworkAddress &addr)
{ {
m_events->adoptHandler( m_events->addHandler(EventTypes::DataSocketConnected, getEventTarget(), [this](const auto &e) {
EventTypes::DataSocketConnected, getEventTarget(), handleTCPConnected(e);
new TMethodEventJob<SecureSocket>(this, &SecureSocket::handleTCPConnected) });
);
TCPSocket::connect(addr); 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) { if (getSocket() == nullptr) {
LOG((CLOG_DEBUG "disregarding stale connect event")); LOG((CLOG_DEBUG "disregarding stale connect event"));

View file

@ -83,7 +83,7 @@ private:
ISocketMultiplexerJob *serviceAccept(ISocketMultiplexerJob *, bool, bool, bool); ISocketMultiplexerJob *serviceAccept(ISocketMultiplexerJob *, bool, bool, bool);
void handleTCPConnected(const Event &event, void *); void handleTCPConnected(const Event &event);
private: private:
// all accesses to m_ssl must be protected by this mutex. The only function that is called // all accesses to m_ssl must be protected by this mutex. The only function that is called

View file

@ -9,7 +9,6 @@
#include "arch/Arch.h" #include "arch/Arch.h"
#include "arch/XArch.h" #include "arch/XArch.h"
#include "base/IEventJob.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "mt/Lock.h" #include "mt/Lock.h"

View file

@ -13,7 +13,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/Stopwatch.h" #include "base/Stopwatch.h"
#include "base/TMethodEventJob.h"
#include "common/Constants.h" #include "common/Constants.h"
#include "deskflow/Clipboard.h" #include "deskflow/Clipboard.h"
#include "deskflow/KeyMap.h" #include "deskflow/KeyMap.h"
@ -50,22 +49,18 @@ EiScreen::EiScreen(bool is_primary, IEventQueue *events, bool use_portal)
init_ei(); init_ei();
key_state_ = new EiKeyState(this, events); key_state_ = new EiKeyState(this, events);
// install event handlers // install event handlers
events_->adoptHandler( events_->addHandler(EventTypes::System, events_->getSystemTarget(), [this](const auto &e) { handleSystemEvent(e); });
EventTypes::System, events_->getSystemTarget(), new TMethodEventJob<EiScreen>(this, &EiScreen::handleSystemEvent)
);
if (use_portal) { if (use_portal) {
events_->adoptHandler( events_->addHandler(EventTypes::EIConnected, getEventTarget(), [this](const auto &e) {
EventTypes::EIConnected, getEventTarget(), handle_connected_to_eis_event(e);
new TMethodEventJob<EiScreen>(this, &EiScreen::handle_connected_to_eis_event) });
);
if (is_primary) { if (is_primary) {
portal_input_capture_ = new PortalInputCapture(this, events_); portal_input_capture_ = new PortalInputCapture(this, events_);
} else { } else {
events_->adoptHandler( events_->addHandler(EventTypes::EISessionClosed, getEventTarget(), [this](const auto &) {
EventTypes::EISessionClosed, getEventTarget(), handle_portal_session_closed();
new TMethodEventJob<EiScreen>(this, &EiScreen::handle_portal_session_closed) });
);
portal_remote_desktop_ = new PortalRemoteDesktop(this, events_); portal_remote_desktop_ = new PortalRemoteDesktop(this, events_);
} }
} else { } else {
@ -698,7 +693,7 @@ void EiScreen::on_abs_motion_event(const ei_event *event) const
assert(is_primary_); 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<EiConnectInfo *>(event.getData())->m_fd; int fd = static_cast<EiConnectInfo *>(event.getData())->m_fd;
LOG_DEBUG("eis connection established, fd=%d", 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 // Portal may or may not EI_EVENT_DISCONNECT us before sending the DBus Closed
// signal. Let's clean up either way. // signal. Let's clean up either way.
@ -718,7 +713,7 @@ void EiScreen::handle_portal_session_closed(const Event &event, void *)
init_ei(); init_ei();
} }
void EiScreen::handleSystemEvent(const Event &sysevent, void *) void EiScreen::handleSystemEvent(const Event &sysevent)
{ {
std::scoped_lock lock{mutex_}; std::scoped_lock lock{mutex_};
@ -779,7 +774,7 @@ void EiScreen::handleSystemEvent(const Event &sysevent, void *)
portal_input_capture_ = new PortalInputCapture(this, this->events_); portal_input_capture_ = new PortalInputCapture(this, this->events_);
} }
} }
this->handle_portal_session_closed(sysevent, nullptr); this->handle_portal_session_closed();
break; break;
case EI_EVENT_DEVICE_PAUSED: case EI_EVENT_DEVICE_PAUSED:
LOG_DEBUG("device %s is paused", ei_device_get_name(device)); LOG_DEBUG("device %s is paused", ei_device_get_name(device));

View file

@ -76,7 +76,7 @@ public:
protected: protected:
// IPlatformScreen overrides // IPlatformScreen overrides
void handleSystemEvent(const Event &event, void *) override; void handleSystemEvent(const Event &event) override;
void updateButtons() override; void updateButtons() override;
IKeyState *getKeyState() const override; IKeyState *getKeyState() const override;
std::string getSecureInputApp() const override; std::string getSecureInputApp() const override;
@ -100,8 +100,8 @@ private:
bool on_hotkey(KeyID key, bool is_press, KeyModifierMask mask); 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_ei_log_event(ei_log_priority priority, const char *message) const;
void handle_connected_to_eis_event(const Event &event, void *); void handle_connected_to_eis_event(const Event &event);
void handle_portal_session_closed(const Event &event, void *); 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) static void cb_handle_ei_log_event(ei *ei, ei_log_priority priority, const char *message, ei_log_context *context)
{ {

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -11,7 +12,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/IJob.h" #include "base/IJob.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "deskflow/IScreenSaver.h" #include "deskflow/IScreenSaver.h"
#include "deskflow/XScreen.h" #include "deskflow/XScreen.h"
@ -144,9 +144,7 @@ void MSWindowsDesks::enable()
// we wouldn't need this if windows notified us of a desktop // we wouldn't need this if windows notified us of a desktop
// change but as far as i can tell it doesn't. // change but as far as i can tell it doesn't.
m_timer = m_events->newTimer(0.2, nullptr); m_timer = m_events->newTimer(0.2, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { handleCheckDesk(); });
EventTypes::Timer, m_timer, new TMethodEventJob<MSWindowsDesks>(this, &MSWindowsDesks::handleCheckDesk)
);
updateKeys(); updateKeys();
} }
@ -807,7 +805,7 @@ void MSWindowsDesks::waitForDesk() const
self->m_deskReady = false; self->m_deskReady = false;
} }
void MSWindowsDesks::handleCheckDesk(const Event &, void *) void MSWindowsDesks::handleCheckDesk()
{ {
checkDesk(); checkDesk();

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -210,7 +211,7 @@ private:
void removeDesks(); void removeDesks();
void checkDesk(); void checkDesk();
bool isDeskAccessible(const Desk *desk) const; bool isDeskAccessible(const Desk *desk) const;
void handleCheckDesk(const Event &event, void *); void handleCheckDesk();
// communication with desk threads // communication with desk threads
void waitForDesk() const; void waitForDesk() const;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -12,7 +13,6 @@
#include "arch/win32/XArchWindows.h" #include "arch/win32/XArchWindows.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "client/Client.h" #include "client/Client.h"
#include "common/Constants.h" #include "common/Constants.h"
@ -131,10 +131,9 @@ MSWindowsScreen::MSWindowsScreen(
} }
// install event handlers // install event handlers
m_events->adoptHandler( m_events->addHandler(EventTypes::System, m_events->getSystemTarget(), [this](const auto &e) {
EventTypes::System, m_events->getSystemTarget(), handleSystemEvent(e);
new TMethodEventJob<MSWindowsScreen>(this, &MSWindowsScreen::handleSystemEvent) });
);
// install the platform event queue // install the platform event queue
m_events->adoptBuffer(new MSWindowsEventQueueBuffer(m_events)); m_events->adoptBuffer(new MSWindowsEventQueueBuffer(m_events));
@ -178,9 +177,7 @@ void MSWindowsScreen::enable()
// we need to poll some things to fix them // we need to poll some things to fix them
m_fixTimer = m_events->newTimer(1.0, nullptr); m_fixTimer = m_events->newTimer(1.0, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, m_fixTimer, [this](const auto &) { handleFixes(); });
EventTypes::Timer, m_fixTimer, new TMethodEventJob<MSWindowsScreen>(this, &MSWindowsScreen::handleFixes)
);
// install our clipboard snooper // install our clipboard snooper
if (!AddClipboardFormatListener(m_window)) { if (!AddClipboardFormatListener(m_window)) {
@ -830,7 +827,7 @@ void MSWindowsScreen::sendClipboardEvent(EventTypes type, ClipboardID id)
sendEvent(type, info); sendEvent(type, info);
} }
void MSWindowsScreen::handleSystemEvent(const Event &event, void *) void MSWindowsScreen::handleSystemEvent(const Event &event)
{ {
MSG *msg = static_cast<MSG *>(event.getData()); MSG *msg = static_cast<MSG *>(event.getData());
assert(msg != nullptr); 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); 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 // fix clipboard chain
fixClipboardViewer(); fixClipboardViewer();

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -126,7 +127,7 @@ public:
protected: protected:
// IPlatformScreen overrides // IPlatformScreen overrides
void handleSystemEvent(const Event &, void *) override; void handleSystemEvent(const Event &event) override;
void updateButtons() override; void updateButtons() override;
IKeyState *getKeyState() const override; IKeyState *getKeyState() const override;
@ -190,7 +191,7 @@ private: // HACK
void updateScreenShape(); void updateScreenShape();
// fix timer callback // fix timer callback
void handleFixes(const Event &, void *); void handleFixes();
// fix the clipboard viewer chain // fix the clipboard viewer chain
void fixClipboardViewer(); void fixClipboardViewer();

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -99,7 +100,7 @@ public:
protected: protected:
// IPlatformScreen overrides // IPlatformScreen overrides
void handleSystemEvent(const Event &, void *) override; void handleSystemEvent(const Event &e) override;
void updateButtons() override; void updateButtons() override;
IKeyState *getKeyState() const override; IKeyState *getKeyState() const override;
@ -148,7 +149,7 @@ private:
double getScrollSpeed() const; double getScrollSpeed() const;
// clipboard check timer handler // clipboard check timer handler
void handleClipboardCheck(const Event &, void *); void handleClipboardCheck();
// Resolution switch callback // Resolution switch callback
static void displayReconfigurationCallback(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void *); 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); static void powerChangeCallback(void *refcon, io_service_t service, natural_t messageType, void *messageArgument);
void handlePowerChangeRequest(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 // global hotkey operating mode
static bool isGlobalHotKeyOperatingModeAvailable(); static bool isGlobalHotKeyOperatingModeAvailable();

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -11,7 +12,6 @@
#include "base/EventQueue.h" #include "base/EventQueue.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "client/Client.h" #include "client/Client.h"
#include "deskflow/ClientApp.h" #include "deskflow/ClientApp.h"
@ -142,10 +142,9 @@ OSXScreen::OSXScreen(
constructMouseButtonEventMap(); constructMouseButtonEventMap();
// watch for requests to sleep // watch for requests to sleep
m_events->adoptHandler( m_events->addHandler(EventTypes::OsxScreenConfirmSleep, getEventTarget(), [this](const auto &e) {
EventTypes::OsxScreenConfirmSleep, getEventTarget(), handleConfirmSleep(e);
new TMethodEventJob<OSXScreen>(this, &OSXScreen::handleConfirmSleep) });
);
// create thread for monitoring system power state. // create thread for monitoring system power state.
*m_pmThreadReady = false; *m_pmThreadReady = false;
@ -167,10 +166,9 @@ OSXScreen::OSXScreen(
} }
// install event handlers // install event handlers
m_events->adoptHandler( m_events->addHandler(EventTypes::System, m_events->getSystemTarget(), [this](const auto &e) {
EventTypes::System, m_events->getSystemTarget(), handleSystemEvent(e);
new TMethodEventJob<OSXScreen>(this, &OSXScreen::handleSystemEvent) });
);
// install the platform event queue // install the platform event queue
m_events->adoptBuffer(new OSXEventQueueBuffer(m_events)); m_events->adoptBuffer(new OSXEventQueueBuffer(m_events));
@ -649,9 +647,7 @@ void OSXScreen::enable()
{ {
// watch the clipboard // watch the clipboard
m_clipboardTimer = m_events->newTimer(1.0, nullptr); m_clipboardTimer = m_events->newTimer(1.0, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, m_clipboardTimer, [this](const auto &) { handleClipboardCheck(); });
EventTypes::Timer, m_clipboardTimer, new TMethodEventJob<OSXScreen>(this, &OSXScreen::handleClipboardCheck)
);
if (m_isPrimary) { if (m_isPrimary) {
// FIXME -- start watching jump zones // FIXME -- start watching jump zones
@ -836,7 +832,7 @@ void OSXScreen::sendClipboardEvent(EventTypes type, ClipboardID id) const
sendEvent(type, info); sendEvent(type, info);
} }
void OSXScreen::handleSystemEvent(const Event &event, void *) void OSXScreen::handleSystemEvent(const Event &event)
{ {
EventRef *carbonEvent = static_cast<EventRef *>(event.getData()); EventRef *carbonEvent = static_cast<EventRef *>(event.getData());
assert(carbonEvent != nullptr); assert(carbonEvent != nullptr);
@ -996,7 +992,7 @@ bool OSXScreen::onMouseWheel(int32_t xDelta, int32_t yDelta) const
return true; return true;
} }
void OSXScreen::handleClipboardCheck(const Event &, void *) void OSXScreen::handleClipboardCheck()
{ {
checkClipboards(); 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(); long messageArg = (long)event.getData();
if (messageArg != 0) { if (messageArg != 0) {

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -12,7 +13,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/Stopwatch.h" #include "base/Stopwatch.h"
#include "base/TMethodEventJob.h"
#include "deskflow/App.h" #include "deskflow/App.h"
#include "deskflow/ArgsBase.h" #include "deskflow/ArgsBase.h"
#include "deskflow/ClientApp.h" #include "deskflow/ClientApp.h"
@ -151,10 +151,9 @@ XWindowsScreen::XWindowsScreen(
} }
// install event handlers // install event handlers
m_events->adoptHandler( m_events->addHandler(EventTypes::System, m_events->getSystemTarget(), [this](const auto &e) {
EventTypes::System, m_events->getSystemTarget(), handleSystemEvent(e);
new TMethodEventJob<XWindowsScreen>(this, &XWindowsScreen::handleSystemEvent) });
);
// install the platform event queue // install the platform event queue
m_events->adoptBuffer(new XWindowsEventQueueBuffer(m_display, m_window, m_events)); m_events->adoptBuffer(new XWindowsEventQueueBuffer(m_display, m_window, m_events));
@ -1111,7 +1110,7 @@ Bool XWindowsScreen::findKeyEvent(Display *, XEvent *xevent, XPointer arg)
: False; : False;
} }
void XWindowsScreen::handleSystemEvent(const Event &event, void *) void XWindowsScreen::handleSystemEvent(const Event &event)
{ {
auto *xevent = static_cast<XEvent *>(event.getData()); auto *xevent = static_cast<XEvent *>(event.getData());
assert(xevent != nullptr); assert(xevent != nullptr);

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -79,7 +80,7 @@ public:
protected: protected:
// IPlatformScreen overrides // IPlatformScreen overrides
void handleSystemEvent(const Event &, void *) override; void handleSystemEvent(const Event &event) override;
void updateButtons() override; void updateButtons() override;
IKeyState *getKeyState() const override; IKeyState *getKeyState() const override;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -10,7 +11,6 @@
#include "base/Event.h" #include "base/Event.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/IPlatformScreen.h" #include "deskflow/IPlatformScreen.h"
#include "platform/XWindowsUtil.h" #include "platform/XWindowsUtil.h"
@ -82,9 +82,7 @@ XWindowsScreenSaver::XWindowsScreenSaver(Display *display, Window window, void *
} }
// install disable timer event handler // install disable timer event handler
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, this, [this](const auto &) { handleDisableTimer(); });
EventTypes::Timer, this, new TMethodEventJob<XWindowsScreenSaver>(this, &XWindowsScreenSaver::handleDisableTimer)
);
} }
XWindowsScreenSaver::~XWindowsScreenSaver() 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 // send fake mouse motion directly to xscreensaver
if (m_xscreensaver != None) { if (m_xscreensaver != None) {

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -87,7 +88,7 @@ private:
void updateDisableTimer(); void updateDisableTimer();
// called periodically to prevent the screen saver from starting // called periodically to prevent the screen saver from starting
void handleDisableTimer(const Event &, void *); void handleDisableTimer();
// force DPMS to activate or deactivate // force DPMS to activate or deactivate
void activateDPMS(bool activate); void activateDPMS(bool activate);

View file

@ -11,7 +11,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/PacketStreamFilter.h" #include "deskflow/PacketStreamFilter.h"
#include "net/IDataSocket.h" #include "net/IDataSocket.h"
#include "net/IListenSocket.h" #include "net/IListenSocket.h"
@ -76,10 +75,9 @@ void ClientListener::start()
m_listen = m_socketFactory->createListen(ARCH->getAddrFamily(m_address.getAddress()), m_securityLevel); m_listen = m_socketFactory->createListen(ARCH->getAddrFamily(m_address.getAddress()), m_securityLevel);
// setup event handler // setup event handler
m_events->adoptHandler( m_events->addHandler(EventTypes::ListenSocketConnecting, m_listen, [this](const auto &) {
EventTypes::ListenSocketConnecting, m_listen, handleClientConnecting();
new TMethodEventJob<ClientListener>(this, &ClientListener::handleClientConnecting) });
);
// bind listen address // bind listen address
LOG((CLOG_DEBUG1 "binding listen socket")); 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 // accept client connection
auto socket = m_listen->accept(); auto socket = m_listen->accept();
@ -132,9 +130,9 @@ void ClientListener::handleClientConnecting(const Event &, void *)
auto rawSocketPointer = socket.release(); auto rawSocketPointer = socket.release();
m_clientSockets.insert(rawSocketPointer); m_clientSockets.insert(rawSocketPointer);
m_events->adoptHandler( m_events->addHandler(
EventTypes::ClientListenerAccepted, rawSocketPointer->getEventTarget(), EventTypes::ClientListenerAccepted, rawSocketPointer->getEventTarget(),
new TMethodEventJob<ClientListener>(this, &ClientListener::handleClientAccepted, rawSocketPointer) [this, rawSocketPointer](const auto &) { handleClientAccepted(rawSocketPointer); }
); );
// When using non SSL, server accepts clients immediately, while SSL // 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")); LOG((CLOG_NOTE "accepted client connection"));
auto *socket = static_cast<IDataSocket *>(vsocket);
// filter socket messages, including a packetizing filter // filter socket messages, including a packetizing filter
deskflow::IStream *stream = new PacketStreamFilter(m_events, socket, false); deskflow::IStream *stream = new PacketStreamFilter(m_events, socket, false);
assert(m_server != nullptr); assert(m_server != nullptr);
@ -160,20 +156,16 @@ void ClientListener::handleClientAccepted(const Event &, void *vsocket)
m_newClients.insert(client); m_newClients.insert(client);
// watch for events from unknown client // watch for events from unknown client
m_events->adoptHandler( m_events->addHandler(EventTypes::ClientProxyUnknownSuccess, client, [this, client](const auto &) {
EventTypes::ClientProxyUnknownSuccess, client, handleUnknownClient(client);
new TMethodEventJob<ClientListener>(this, &ClientListener::handleUnknownClient, client) });
); m_events->addHandler(EventTypes::ClientProxyUnknownFailure, client, [this, client](const auto &) {
m_events->adoptHandler( handleUnknownClientFailure(client);
EventTypes::ClientProxyUnknownFailure, client, });
new TMethodEventJob<ClientListener>(this, &ClientListener::handleUnknownClientFailure, client)
);
} }
void ClientListener::handleUnknownClient(const Event &, void *vclient) void ClientListener::handleUnknownClient(ClientProxyUnknown *unknownClient)
{ {
auto unknownClient = static_cast<ClientProxyUnknown *>(vclient);
// we should have the client in our new client list // we should have the client in our new client list
assert(m_newClients.count(unknownClient) == 1); assert(m_newClients.count(unknownClient) == 1);
@ -184,10 +176,9 @@ void ClientListener::handleUnknownClient(const Event &, void *vclient)
m_events->addEvent(Event(EventTypes::ClientListenerAccepted, this)); m_events->addEvent(Event(EventTypes::ClientListenerAccepted, this));
// watch for client to disconnect while it's in our queue // watch for client to disconnect while it's in our queue
m_events->adoptHandler( m_events->addHandler(EventTypes::ClientProxyDisconnected, client, [this, client](const auto &e) {
EventTypes::ClientProxyDisconnected, client, handleClientDisconnected(client);
new TMethodEventJob<ClientListener>(this, &ClientListener::handleClientDisconnected, client) });
);
} else { } else {
auto *stream = unknownClient->getStream(); auto *stream = unknownClient->getStream();
if (stream) { if (stream) {
@ -199,16 +190,13 @@ void ClientListener::handleUnknownClient(const Event &, void *vclient)
removeUnknownClient(unknownClient); removeUnknownClient(unknownClient);
} }
void ClientListener::handleUnknownClientFailure(const Event &, void *vclient) void ClientListener::handleUnknownClientFailure(ClientProxyUnknown *client)
{ {
auto unknownClient = static_cast<ClientProxyUnknown *>(vclient); removeUnknownClient(client);
removeUnknownClient(unknownClient);
} }
void ClientListener::handleClientDisconnected(const Event &, void *vclient) void ClientListener::handleClientDisconnected(ClientProxy *client)
{ {
auto *client = static_cast<ClientProxy *>(vclient);
// find client in waiting clients queue // find client in waiting clients queue
for (WaitingClients::iterator i = m_waitingClients.begin(), n = m_waitingClients.end(); i != n; ++i) { for (WaitingClients::iterator i = m_waitingClients.begin(), n = m_waitingClients.end(); i != n; ++i) {
if (*i == client) { if (*i == client) {

View file

@ -64,11 +64,11 @@ public:
private: private:
// client connection event handlers // client connection event handlers
void handleClientConnecting(const Event &, void *); void handleClientConnecting();
void handleClientAccepted(const Event &, void *); void handleClientAccepted(IDataSocket *socket);
void handleUnknownClient(const Event &, void *); void handleUnknownClient(ClientProxyUnknown *unknownClient);
void handleUnknownClientFailure(const Event &, void *); void handleUnknownClientFailure(ClientProxyUnknown *client);
void handleClientDisconnected(const Event &, void *); void handleClientDisconnected(ClientProxy *client);
void cleanupListenSocket(); void cleanupListenSocket();
void cleanupClientSockets(); void cleanupClientSockets();

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -9,7 +10,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/ProtocolUtil.h" #include "deskflow/ProtocolUtil.h"
#include "deskflow/XDeskflow.h" #include "deskflow/XDeskflow.h"
#include "io/IStream.h" #include "io/IStream.h"
@ -26,29 +26,20 @@ ClientProxy1_0::ClientProxy1_0(const std::string &name, deskflow::IStream *strea
m_events(events) m_events(events)
{ {
// install event handlers // install event handlers
m_events->adoptHandler( m_events->addHandler(EventTypes::StreamInputReady, stream->getEventTarget(), [this](const auto &) { handleData(); });
EventTypes::StreamInputReady, stream->getEventTarget(), m_events->addHandler(EventTypes::StreamOutputError, stream->getEventTarget(), [this](const auto &) {
new TMethodEventJob<ClientProxy1_0>(this, &ClientProxy1_0::handleData, nullptr) handleWriteError();
); });
m_events->adoptHandler( m_events->addHandler(EventTypes::StreamInputShutdown, stream->getEventTarget(), [this](const auto &) {
EventTypes::StreamOutputError, stream->getEventTarget(), handleDisconnect();
new TMethodEventJob<ClientProxy1_0>(this, &ClientProxy1_0::handleWriteError, nullptr) });
); m_events->addHandler(EventTypes::StreamInputFormatError, stream->getEventTarget(), [this](const auto &) {
m_events->adoptHandler( handleDisconnect();
EventTypes::StreamInputShutdown, stream->getEventTarget(), });
new TMethodEventJob<ClientProxy1_0>(this, &ClientProxy1_0::handleDisconnect, nullptr) m_events->addHandler(EventTypes::StreamOutputShutdown, stream->getEventTarget(), [this](const auto &) {
); handleWriteError();
m_events->adoptHandler( });
EventTypes::StreamInputFormatError, stream->getEventTarget(), m_events->addHandler(EventTypes::Timer, this, [this](const auto &) { handleFlatline(); });
new TMethodEventJob<ClientProxy1_0>(this, &ClientProxy1_0::handleDisconnect, nullptr)
);
m_events->adoptHandler(
EventTypes::StreamOutputShutdown, stream->getEventTarget(),
new TMethodEventJob<ClientProxy1_0>(this, &ClientProxy1_0::handleWriteError, nullptr)
);
m_events->adoptHandler(
EventTypes::Timer, this, new TMethodEventJob<ClientProxy1_0>(this, &ClientProxy1_0::handleFlatline, nullptr)
);
setHeartbeatRate(kHeartRate, kHeartRate * kHeartBeatsUntilDeath); setHeartbeatRate(kHeartRate, kHeartRate * kHeartBeatsUntilDeath);
@ -114,7 +105,7 @@ void ClientProxy1_0::setHeartbeatRate(double, double alarm)
m_heartbeatAlarm = 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. // handle messages until there are no more. first read message code.
uint8_t code[4]; uint8_t code[4];
@ -192,19 +183,19 @@ bool ClientProxy1_0::parseMessage(const uint8_t *code)
return false; return false;
} }
void ClientProxy1_0::handleDisconnect(const Event &, void *) void ClientProxy1_0::handleDisconnect()
{ {
LOG((CLOG_NOTE "client \"%s\" has disconnected", getName().c_str())); LOG((CLOG_NOTE "client \"%s\" has disconnected", getName().c_str()));
disconnect(); disconnect();
} }
void ClientProxy1_0::handleWriteError(const Event &, void *) void ClientProxy1_0::handleWriteError()
{ {
LOG((CLOG_WARN "error writing to client \"%s\"", getName().c_str())); LOG((CLOG_WARN "error writing to client \"%s\"", getName().c_str()));
disconnect(); disconnect();
} }
void ClientProxy1_0::handleFlatline(const Event &, void *) void ClientProxy1_0::handleFlatline()
{ {
// didn't get a heartbeat fast enough. assume client is dead. // didn't get a heartbeat fast enough. assume client is dead.
LOG((CLOG_NOTE "client \"%s\" is dead", getName().c_str())); LOG((CLOG_NOTE "client \"%s\" is dead", getName().c_str()));

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -69,10 +70,10 @@ private:
void disconnect(); void disconnect();
void removeHandlers(); void removeHandlers();
void handleData(const Event &, void *); void handleData();
void handleDisconnect(const Event &, void *); void handleDisconnect();
void handleWriteError(const Event &, void *); void handleWriteError();
void handleFlatline(const Event &, void *); void handleFlatline();
bool recvInfo(); bool recvInfo();
bool recvGrabClipboard(); bool recvGrabClipboard();

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2006 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2006 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -9,7 +10,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/ProtocolUtil.h" #include "deskflow/ProtocolUtil.h"
#include <cstring> #include <cstring>
@ -73,10 +73,7 @@ void ClientProxy1_3::addHeartbeatTimer()
// create and install a timer to periodically send keep alives // create and install a timer to periodically send keep alives
if (m_keepAliveRate > 0.0) { if (m_keepAliveRate > 0.0) {
m_keepAliveTimer = m_events->newTimer(m_keepAliveRate, nullptr); m_keepAliveTimer = m_events->newTimer(m_keepAliveRate, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, m_keepAliveTimer, [this](const auto &) { handleKeepAlive(); });
EventTypes::Timer, m_keepAliveTimer,
new TMethodEventJob<ClientProxy1_3>(this, &ClientProxy1_3::handleKeepAlive, nullptr)
);
} }
// superclass does the alarm // superclass does the alarm
@ -96,7 +93,7 @@ void ClientProxy1_3::removeHeartbeatTimer()
ClientProxy1_2::removeHeartbeatTimer(); ClientProxy1_2::removeHeartbeatTimer();
} }
void ClientProxy1_3::handleKeepAlive(const Event &, void *) void ClientProxy1_3::handleKeepAlive()
{ {
keepAlive(); keepAlive();
} }

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2006 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2006 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -24,7 +25,7 @@ public:
// IClient overrides // IClient overrides
void mouseWheel(int32_t xDelta, int32_t yDelta) override; void mouseWheel(int32_t xDelta, int32_t yDelta) override;
void handleKeepAlive(const Event &, void *); void handleKeepAlive();
protected: protected:
// ClientProxy overrides // ClientProxy overrides

View file

@ -9,7 +9,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/ProtocolUtil.h" #include "deskflow/ProtocolUtil.h"
#include "server/Server.h" #include "server/Server.h"

View file

@ -7,7 +7,6 @@
#include "server/ClientProxy1_5.h" #include "server/ClientProxy1_5.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/ProtocolUtil.h" #include "deskflow/ProtocolUtil.h"
#include "deskflow/StreamChunker.h" #include "deskflow/StreamChunker.h"
#include "io/IStream.h" #include "io/IStream.h"

View file

@ -7,7 +7,6 @@
#include "server/ClientProxy1_6.h" #include "server/ClientProxy1_6.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/ClipboardChunk.h" #include "deskflow/ClipboardChunk.h"
#include "deskflow/ProtocolUtil.h" #include "deskflow/ProtocolUtil.h"
#include "deskflow/StreamChunker.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), : ClientProxy1_5(name, stream, server, events),
m_events(events) m_events(events)
{ {
m_events->adoptHandler( m_events->addHandler(EventTypes::ClipboardSending, this, [this](const auto &e) { handleClipboardSendingEvent(e); });
EventTypes::ClipboardSending, this,
new TMethodEventJob<ClientProxy1_6>(this, &ClientProxy1_6::handleClipboardSendingEvent)
);
} }
void ClientProxy1_6::setClipboard(ClipboardID id, const IClipboard *clipboard) 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()); ClipboardChunk::send(getStream(), event.getDataObject());
} }

View file

@ -22,7 +22,7 @@ public:
bool recvClipboard() override; bool recvClipboard() override;
private: private:
void handleClipboardSendingEvent(const Event &, void *); void handleClipboardSendingEvent(const Event &e);
private: private:
IEventQueue *m_events; IEventQueue *m_events;

View file

@ -6,7 +6,6 @@
#include "server/ClientProxy1_7.h" #include "server/ClientProxy1_7.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/AppUtil.h" #include "deskflow/AppUtil.h"
#include "deskflow/ProtocolUtil.h" #include "deskflow/ProtocolUtil.h"
#include "server/Server.h" #include "server/Server.h"

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -9,7 +10,6 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/AppUtil.h" #include "deskflow/AppUtil.h"
#include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolTypes.h"
#include "deskflow/ProtocolUtil.h" #include "deskflow/ProtocolUtil.h"
@ -41,10 +41,7 @@ ClientProxyUnknown::ClientProxyUnknown(deskflow::IStream *stream, double timeout
{ {
assert(m_server != nullptr); assert(m_server != nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, this, [this](const auto &) { handleTimeout(); });
EventTypes::Timer, this,
new TMethodEventJob<ClientProxyUnknown>(this, &ClientProxyUnknown::handleTimeout, nullptr)
);
m_timer = m_events->newOneShotTimer(timeout, this); m_timer = m_events->newOneShotTimer(timeout, this);
addStreamHandlers(); addStreamHandlers();
@ -95,40 +92,29 @@ void ClientProxyUnknown::sendFailure()
void ClientProxyUnknown::addStreamHandlers() void ClientProxyUnknown::addStreamHandlers()
{ {
assert(m_stream != nullptr); assert(m_stream != nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::StreamInputReady, m_stream->getEventTarget(), [this](const auto &) {
EventTypes::StreamInputReady, m_stream->getEventTarget(), handleData();
new TMethodEventJob<ClientProxyUnknown>(this, &ClientProxyUnknown::handleData) });
); m_events->addHandler(EventTypes::StreamOutputError, m_stream->getEventTarget(), [this](const auto &) {
m_events->adoptHandler( handleWriteError();
EventTypes::StreamOutputError, m_stream->getEventTarget(), });
new TMethodEventJob<ClientProxyUnknown>(this, &ClientProxyUnknown::handleWriteError) m_events->addHandler(EventTypes::StreamInputShutdown, m_stream->getEventTarget(), [this](const auto &) {
); handleDisconnect();
m_events->adoptHandler( });
EventTypes::StreamInputShutdown, m_stream->getEventTarget(), m_events->addHandler(EventTypes::StreamInputFormatError, m_stream->getEventTarget(), [this](const auto &) {
new TMethodEventJob<ClientProxyUnknown>(this, &ClientProxyUnknown::handleDisconnect) handleDisconnect();
); });
m_events->adoptHandler( m_events->addHandler(EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), [this](const auto &) {
EventTypes::StreamInputFormatError, m_stream->getEventTarget(), handleWriteError();
new TMethodEventJob<ClientProxyUnknown>(this, &ClientProxyUnknown::handleDisconnect) });
);
m_events->adoptHandler(
EventTypes::StreamOutputShutdown, m_stream->getEventTarget(),
new TMethodEventJob<ClientProxyUnknown>(this, &ClientProxyUnknown::handleWriteError)
);
} }
void ClientProxyUnknown::addProxyHandlers() void ClientProxyUnknown::addProxyHandlers()
{ {
assert(m_proxy != nullptr); assert(m_proxy != nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::ClientProxyReady, m_proxy, [this](const auto &e) { handleReady(); });
EventTypes::ClientProxyReady, m_proxy, m_events->addHandler(EventTypes::ClientProxyDisconnected, m_proxy, [this](const auto &e) { handleDisconnect(); });
new TMethodEventJob<ClientProxyUnknown>(this, &ClientProxyUnknown::handleReady)
);
m_events->adoptHandler(
EventTypes::ClientProxyDisconnected, m_proxy,
new TMethodEventJob<ClientProxyUnknown>(this, &ClientProxyUnknown::handleDisconnect)
);
} }
void ClientProxyUnknown::removeHandlers() 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")); LOG((CLOG_DEBUG1 "parsing hello reply"));
@ -258,25 +244,25 @@ void ClientProxyUnknown::handleData(const Event &, void *)
sendFailure(); sendFailure();
} }
void ClientProxyUnknown::handleWriteError(const Event &, void *) void ClientProxyUnknown::handleWriteError()
{ {
LOG((CLOG_NOTE "error communicating with new client")); LOG((CLOG_NOTE "error communicating with new client"));
sendFailure(); sendFailure();
} }
void ClientProxyUnknown::handleTimeout(const Event &, void *) void ClientProxyUnknown::handleTimeout()
{ {
LOG((CLOG_NOTE "new client is unresponsive")); LOG((CLOG_NOTE "new client is unresponsive"));
sendFailure(); sendFailure();
} }
void ClientProxyUnknown::handleDisconnect(const Event &, void *) void ClientProxyUnknown::handleDisconnect()
{ {
LOG((CLOG_NOTE "new client disconnected")); LOG((CLOG_NOTE "new client disconnected"));
sendFailure(); sendFailure();
} }
void ClientProxyUnknown::handleReady(const Event &, void *) void ClientProxyUnknown::handleReady()
{ {
sendSuccess(); sendSuccess();
} }

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -59,11 +60,11 @@ private:
void removeHandlers(); void removeHandlers();
void initProxy(const std::string &name, int major, int minor); void initProxy(const std::string &name, int major, int minor);
void removeTimer(); void removeTimer();
void handleData(const Event &, void *); void handleData();
void handleWriteError(const Event &, void *); void handleWriteError();
void handleTimeout(const Event &, void *); void handleTimeout();
void handleDisconnect(const Event &, void *); void handleDisconnect();
void handleReady(const Event &, void *); void handleReady();
private: private:
deskflow::IStream *m_stream = nullptr; deskflow::IStream *m_stream = nullptr;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2005 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2005 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -8,7 +9,6 @@
#include "server/InputFilter.h" #include "server/InputFilter.h"
#include "base/EventQueue.h" #include "base/EventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "deskflow/KeyMap.h" #include "deskflow/KeyMap.h"
#include "server/PrimaryClient.h" #include "server/PrimaryClient.h"
#include "server/Server.h" #include "server/Server.h"
@ -796,38 +796,30 @@ void InputFilter::setPrimaryClient(PrimaryClient *client)
m_primaryClient = client; m_primaryClient = client;
if (m_primaryClient != nullptr) { if (m_primaryClient != nullptr) {
m_events->adoptHandler( m_events->addHandler(EventTypes::KeyStateKeyDown, m_primaryClient->getEventTarget(), [this](const auto &e) {
EventTypes::KeyStateKeyDown, m_primaryClient->getEventTarget(), handleEvent(e);
new TMethodEventJob<InputFilter>(this, &InputFilter::handleEvent) });
); m_events->addHandler(EventTypes::KeyStateKeyUp, m_primaryClient->getEventTarget(), [this](const auto &e) {
m_events->adoptHandler( handleEvent(e);
EventTypes::KeyStateKeyUp, m_primaryClient->getEventTarget(), });
new TMethodEventJob<InputFilter>(this, &InputFilter::handleEvent) m_events->addHandler(EventTypes::KeyStateKeyRepeat, m_primaryClient->getEventTarget(), [this](const auto &e) {
); handleEvent(e);
m_events->adoptHandler( });
EventTypes::KeyStateKeyRepeat, m_primaryClient->getEventTarget(), m_events->addHandler(EventTypes::PrimaryScreenButtonDown, m_primaryClient->getEventTarget(), [this](const auto &e) {
new TMethodEventJob<InputFilter>(this, &InputFilter::handleEvent) handleEvent(e);
); });
m_events->adoptHandler( m_events->addHandler(EventTypes::PrimaryScreenButtonUp, m_primaryClient->getEventTarget(), [this](const auto &e) {
EventTypes::PrimaryScreenButtonDown, m_primaryClient->getEventTarget(), handleEvent(e);
new TMethodEventJob<InputFilter>(this, &InputFilter::handleEvent) });
); m_events->addHandler(EventTypes::PrimaryScreenHotkeyDown, m_primaryClient->getEventTarget(), [this](const auto &e) {
m_events->adoptHandler( handleEvent(e);
EventTypes::PrimaryScreenButtonUp, m_primaryClient->getEventTarget(), });
new TMethodEventJob<InputFilter>(this, &InputFilter::handleEvent) m_events->addHandler(EventTypes::PrimaryScreenHotkeyUp, m_primaryClient->getEventTarget(), [this](const auto &e) {
); handleEvent(e);
m_events->adoptHandler( });
EventTypes::PrimaryScreenHotkeyDown, m_primaryClient->getEventTarget(), m_events->addHandler(EventTypes::ServerConnected, m_primaryClient->getEventTarget(), [this](const auto &e) {
new TMethodEventJob<InputFilter>(this, &InputFilter::handleEvent) handleEvent(e);
); });
m_events->adoptHandler(
EventTypes::PrimaryScreenHotkeyUp, m_primaryClient->getEventTarget(),
new TMethodEventJob<InputFilter>(this, &InputFilter::handleEvent)
);
m_events->adoptHandler(
EventTypes::ServerConnected, m_primaryClient->getEventTarget(),
new TMethodEventJob<InputFilter>(this, &InputFilter::handleEvent)
);
for (auto rule = m_ruleList.begin(); rule != m_ruleList.end(); ++rule) { for (auto rule = m_ruleList.begin(); rule != m_ruleList.end(); ++rule) {
rule->enable(m_primaryClient); rule->enable(m_primaryClient);
@ -878,7 +870,7 @@ bool InputFilter::operator!=(const InputFilter &x) const
return !operator==(x); return !operator==(x);
} }
void InputFilter::handleEvent(const Event &event, void *) void InputFilter::handleEvent(const Event &event)
{ {
// copy event and adjust target // copy event and adjust target
Event myEvent( Event myEvent(

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2005 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2005 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -324,7 +325,7 @@ public:
void disable(PrimaryClient *); void disable(PrimaryClient *);
// event handling // event handling
bool handleEvent(const Event &); bool handleEvent(const Event &e);
// convert rule to a string // convert rule to a string
std::string format() const; std::string format() const;
@ -387,7 +388,7 @@ public:
private: private:
// event handling // event handling
void handleEvent(const Event &, void *); void handleEvent(const Event &);
private: private:
RuleList m_ruleList; RuleList m_ruleList;

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers.
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -10,7 +11,6 @@
#include "arch/Arch.h" #include "arch/Arch.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "deskflow/AppUtil.h" #include "deskflow/AppUtil.h"
#include "deskflow/IPlatformScreen.h" #include "deskflow/IPlatformScreen.h"
@ -71,67 +71,55 @@ Server::Server(
} }
// install event handlers // install event handlers
m_events->adoptHandler(EventTypes::Timer, this, new TMethodEventJob<Server>(this, &Server::handleSwitchWaitTimeout)); m_events->addHandler(EventTypes::Timer, this, [this](const auto &) { handleSwitchWaitTimeout(); });
m_events->adoptHandler( m_events->addHandler(EventTypes::KeyStateKeyDown, m_inputFilter, [this](const auto &e) { handleKeyDownEvent(e); });
EventTypes::KeyStateKeyDown, m_inputFilter, new TMethodEventJob<Server>(this, &Server::handleKeyDownEvent) m_events->addHandler(EventTypes::KeyStateKeyUp, m_inputFilter, [this](const auto &e) { handleKeyUpEvent(e); });
); m_events->addHandler(EventTypes::KeyStateKeyRepeat, m_inputFilter, [this](const auto &e) {
m_events->adoptHandler( handleKeyRepeatEvent(e);
EventTypes::KeyStateKeyUp, m_inputFilter, new TMethodEventJob<Server>(this, &Server::handleKeyUpEvent) });
); m_events->addHandler(EventTypes::PrimaryScreenButtonDown, m_inputFilter, [this](const auto &e) {
m_events->adoptHandler( handleButtonDownEvent(e);
EventTypes::KeyStateKeyRepeat, m_inputFilter, new TMethodEventJob<Server>(this, &Server::handleKeyRepeatEvent) });
); m_events->addHandler(EventTypes::PrimaryScreenButtonUp, m_inputFilter, [this](const auto &e) {
m_events->adoptHandler( handleButtonUpEvent(e);
EventTypes::PrimaryScreenButtonDown, m_inputFilter, });
new TMethodEventJob<Server>(this, &Server::handleButtonDownEvent) m_events->addHandler(
);
m_events->adoptHandler(
EventTypes::PrimaryScreenButtonUp, m_inputFilter, new TMethodEventJob<Server>(this, &Server::handleButtonUpEvent)
);
m_events->adoptHandler(
EventTypes::PrimaryScreenMotionOnPrimary, m_primaryClient->getEventTarget(), EventTypes::PrimaryScreenMotionOnPrimary, m_primaryClient->getEventTarget(),
new TMethodEventJob<Server>(this, &Server::handleMotionPrimaryEvent) [this](const auto &e) { handleMotionPrimaryEvent(e); }
); );
m_events->adoptHandler( m_events->addHandler(
EventTypes::PrimaryScreenMotionOnSecondary, m_primaryClient->getEventTarget(), EventTypes::PrimaryScreenMotionOnSecondary, m_primaryClient->getEventTarget(),
new TMethodEventJob<Server>(this, &Server::handleMotionSecondaryEvent) [this](const auto &e) { handleMotionSecondaryEvent(e); }
); );
m_events->adoptHandler( m_events->addHandler(EventTypes::PrimaryScreenWheel, m_primaryClient->getEventTarget(), [this](const auto &e) {
EventTypes::PrimaryScreenWheel, m_primaryClient->getEventTarget(), handleWheelEvent(e);
new TMethodEventJob<Server>(this, &Server::handleWheelEvent) });
); m_events->addHandler(
m_events->adoptHandler(
EventTypes::PrimaryScreenSaverActivated, m_primaryClient->getEventTarget(), EventTypes::PrimaryScreenSaverActivated, m_primaryClient->getEventTarget(),
new TMethodEventJob<Server>(this, &Server::handleScreensaverActivatedEvent) [this](const auto &) { handleScreensaverActivatedEvent(); }
); );
m_events->adoptHandler( m_events->addHandler(
EventTypes::PrimaryScreenSaverDeactivated, m_primaryClient->getEventTarget(), EventTypes::PrimaryScreenSaverDeactivated, m_primaryClient->getEventTarget(),
new TMethodEventJob<Server>(this, &Server::handleScreensaverDeactivatedEvent) [this](const auto &) { handleScreensaverDeactivatedEvent(); }
);
m_events->adoptHandler(
EventTypes::ServerSwitchToScreen, m_inputFilter,
new TMethodEventJob<Server>(this, &Server::handleSwitchToScreenEvent)
);
m_events->adoptHandler(
EventTypes::ServerSwitchInDirection, m_inputFilter,
new TMethodEventJob<Server>(this, &Server::handleSwitchInDirectionEvent)
);
m_events->adoptHandler(
EventTypes::ServerKeyboardBroadcast, m_inputFilter,
new TMethodEventJob<Server>(this, &Server::handleKeyboardBroadcastEvent)
);
m_events->adoptHandler(
EventTypes::ServerLockCursorToScreen, m_inputFilter,
new TMethodEventJob<Server>(this, &Server::handleLockCursorToScreenEvent)
);
m_events->adoptHandler(
EventTypes::PrimaryScreenFakeInputBegin, m_inputFilter,
new TMethodEventJob<Server>(this, &Server::handleFakeInputBeginEvent)
);
m_events->adoptHandler(
EventTypes::PrimaryScreenFakeInputEnd, m_inputFilter,
new TMethodEventJob<Server>(this, &Server::handleFakeInputEndEvent)
); );
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 // add connection
addClient(m_primaryClient); addClient(m_primaryClient);
@ -237,10 +225,9 @@ void Server::adoptClient(BaseClientProxy *client)
assert(client != nullptr); assert(client != nullptr);
// watch for client disconnection // watch for client disconnection
m_events->adoptHandler( m_events->addHandler(EventTypes::ClientProxyDisconnected, client, [this, client](const auto &e) {
EventTypes::ClientProxyDisconnected, client, handleClientDisconnected(client);
new TMethodEventJob<Server>(this, &Server::handleClientDisconnected, client) });
);
// name must be in our configuration // name must be in our configuration
if (!m_config->isScreen(client->getName())) { if (!m_config->isScreen(client->getName())) {
@ -1128,10 +1115,8 @@ void Server::processOptions()
m_relativeMoves = newRelativeMoves; m_relativeMoves = newRelativeMoves;
} }
void Server::handleShapeChanged(const Event &, void *vclient) void Server::handleShapeChanged(BaseClientProxy *client)
{ {
// ignore events from unknown clients
auto *client = static_cast<BaseClientProxy *>(vclient);
if (m_clientSet.count(client) == 0) { if (m_clientSet.count(client) == 0) {
return; 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)) { if (!m_enableClipboard || (m_maximumClipboardSize == 0)) {
return; return;
} }
// ignore events from unknown clients // ignore events from unknown clients
auto *grabber = static_cast<BaseClientProxy *>(vclient);
if (m_clientSet.count(grabber) == 0) { if (m_clientSet.count(grabber) == 0) {
return; 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 // ignore events from unknown clients
auto *sender = static_cast<BaseClientProxy *>(vclient); if (m_clientSet.count(client) == 0) {
if (m_clientSet.count(sender) == 0) {
return; return;
} }
const auto *info = static_cast<const IScreen::ClipboardInfo *>(event.getData()); const auto *info = static_cast<const IScreen::ClipboardInfo *>(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<IPlatformScreen::KeyInfo *>(event.getData()); const auto *info = static_cast<IPlatformScreen::KeyInfo *>(event.getData());
auto lang = AppUtil::instance().getCurrentLanguageCode(); auto lang = AppUtil::instance().getCurrentLanguageCode();
onKeyDown(info->m_key, info->m_mask, info->m_button, lang, info->m_screens); 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<IPlatformScreen::KeyInfo *>(event.getData()); auto *info = static_cast<IPlatformScreen::KeyInfo *>(event.getData());
onKeyUp(info->m_key, info->m_mask, info->m_button, info->m_screens); 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<IPlatformScreen::KeyInfo *>(event.getData()); const auto *info = static_cast<IPlatformScreen::KeyInfo *>(event.getData());
auto lang = AppUtil::instance().getCurrentLanguageCode(); auto lang = AppUtil::instance().getCurrentLanguageCode();
onKeyRepeat(info->m_key, info->m_mask, info->m_count, info->m_button, lang); 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<IPlatformScreen::ButtonInfo *>(event.getData()); const auto *info = static_cast<IPlatformScreen::ButtonInfo *>(event.getData());
onMouseDown(info->m_button); onMouseDown(info->m_button);
} }
void Server::handleButtonUpEvent(const Event &event, void *) void Server::handleButtonUpEvent(const Event &event)
{ {
const auto *info = static_cast<IPlatformScreen::ButtonInfo *>(event.getData()); const auto *info = static_cast<IPlatformScreen::ButtonInfo *>(event.getData());
onMouseUp(info->m_button); onMouseUp(info->m_button);
} }
void Server::handleMotionPrimaryEvent(const Event &event, void *) void Server::handleMotionPrimaryEvent(const Event &event)
{ {
const auto *info = static_cast<IPlatformScreen::MotionInfo *>(event.getData()); const auto *info = static_cast<IPlatformScreen::MotionInfo *>(event.getData());
onMouseMovePrimary(info->m_x, info->m_y); 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<IPlatformScreen::MotionInfo *>(event.getData()); const auto *info = static_cast<IPlatformScreen::MotionInfo *>(event.getData());
onMouseMoveSecondary(info->m_x, info->m_y); 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<IPlatformScreen::WheelInfo *>(event.getData()); const auto *info = static_cast<IPlatformScreen::WheelInfo *>(event.getData());
onMouseWheel(info->m_xDelta, info->m_yDelta); onMouseWheel(info->m_xDelta, info->m_yDelta);
} }
void Server::handleScreensaverActivatedEvent(const Event &, void *) void Server::handleScreensaverActivatedEvent()
{ {
onScreensaver(true); onScreensaver(true);
} }
void Server::handleScreensaverDeactivatedEvent(const Event &, void *) void Server::handleScreensaverDeactivatedEvent()
{ {
onScreensaver(false); onScreensaver(false);
} }
void Server::handleSwitchWaitTimeout(const Event &, void *) void Server::handleSwitchWaitTimeout()
{ {
// ignore if mouse is locked to screen // ignore if mouse is locked to screen
if (isLockedToScreen()) { if (isLockedToScreen()) {
@ -1300,28 +1283,26 @@ void Server::handleSwitchWaitTimeout(const Event &, void *)
switchScreen(m_switchScreen, m_switchWaitX, m_switchWaitY, false); 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 // client has disconnected. it might be an old client or an
// active client. we don't care so just handle it both ways. // active client. we don't care so just handle it both ways.
auto *client = static_cast<BaseClientProxy *>(vclient);
removeActiveClient(client); removeActiveClient(client);
removeOldClient(client); removeOldClient(client);
delete client; delete client;
} }
void Server::handleClientCloseTimeout(const Event &, void *vclient) void Server::handleClientCloseTimeout(BaseClientProxy *client)
{ {
// client took too long to disconnect. just dump it. // client took too long to disconnect. just dump it.
auto *client = static_cast<BaseClientProxy *>(vclient);
LOG((CLOG_NOTE "forced disconnection of client \"%s\"", getName(client).c_str())); LOG((CLOG_NOTE "forced disconnection of client \"%s\"", getName(client).c_str()));
removeOldClient(client); removeOldClient(client);
delete client; delete client;
} }
void Server::handleSwitchToScreenEvent(const Event &event, void *) void Server::handleSwitchToScreenEvent(const Event &event)
{ {
auto *info = static_cast<SwitchToScreenInfo *>(event.getData()); auto *info = static_cast<SwitchToScreenInfo *>(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<SwitchInDirectionInfo *>(event.getData()); const auto *info = static_cast<SwitchInDirectionInfo *>(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(); 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(); 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(); m_primaryClient->fakeInputBegin();
} }
void Server::handleFakeInputEndEvent(const Event &, void *) void Server::handleFakeInputEndEvent()
{ {
m_primaryClient->fakeInputEnd(); m_primaryClient->fakeInputEnd();
} }
@ -1884,18 +1865,15 @@ bool Server::addClient(BaseClientProxy *client)
} }
// add event handlers // add event handlers
m_events->adoptHandler( m_events->addHandler(EventTypes::ScreenShapeChanged, client->getEventTarget(), [this, client](const auto &e) {
EventTypes::ScreenShapeChanged, client->getEventTarget(), handleShapeChanged(client);
new TMethodEventJob<Server>(this, &Server::handleShapeChanged, client) });
); m_events->addHandler(EventTypes::ClipboardGrabbed, client->getEventTarget(), [this, client](const auto &e) {
m_events->adoptHandler( handleClipboardGrabbed(e, client);
EventTypes::ClipboardGrabbed, client->getEventTarget(), });
new TMethodEventJob<Server>(this, &Server::handleClipboardGrabbed, client) m_events->addHandler(EventTypes::ClipboardChanged, client->getEventTarget(), [this, client](const auto &e) {
); handleClipboardChanged(e, client);
m_events->adoptHandler( });
EventTypes::ClipboardChanged, client->getEventTarget(),
new TMethodEventJob<Server>(this, &Server::handleClipboardChanged, client)
);
// add to list // add to list
m_clientSet.insert(client); m_clientSet.insert(client);
@ -1950,14 +1928,13 @@ void Server::closeClient(BaseClientProxy *client, const char *msg)
// send message // send message
// FIXME -- avoid type cast (kinda hard, though) // FIXME -- avoid type cast (kinda hard, though)
((ClientProxy *)client)->close(msg); auto clientProxy = static_cast<ClientProxy *>(client);
clientProxy->close(msg);
// install timer. wait timeout seconds for client to close. // install timer. wait timeout seconds for client to close.
double timeout = 5.0; double timeout = 5.0;
EventQueueTimer *timer = m_events->newOneShotTimer(timeout, nullptr); EventQueueTimer *timer = m_events->newOneShotTimer(timeout, nullptr);
m_events->adoptHandler( m_events->addHandler(EventTypes::Timer, timer, [this, client](const auto &e) { handleClientCloseTimeout(client); });
EventTypes::Timer, timer, new TMethodEventJob<Server>(this, &Server::handleClientCloseTimeout, client)
);
// move client to closing list // move client to closing list
removeClient(client); removeClient(client);

View file

@ -1,5 +1,6 @@
/* /*
* Deskflow -- mouse and keyboard sharing utility * Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd. * SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
@ -289,28 +290,28 @@ private:
void processOptions(); void processOptions();
// event handlers // event handlers
void handleShapeChanged(const Event &, void *); void handleShapeChanged(BaseClientProxy *client);
void handleClipboardGrabbed(const Event &, void *); void handleClipboardGrabbed(const Event &event, BaseClientProxy *client);
void handleClipboardChanged(const Event &, void *); void handleClipboardChanged(const Event &event, BaseClientProxy *client);
void handleKeyDownEvent(const Event &, void *); void handleKeyDownEvent(const Event &event);
void handleKeyUpEvent(const Event &, void *); void handleKeyUpEvent(const Event &event);
void handleKeyRepeatEvent(const Event &, void *); void handleKeyRepeatEvent(const Event &event);
void handleButtonDownEvent(const Event &, void *); void handleButtonDownEvent(const Event &event);
void handleButtonUpEvent(const Event &, void *); void handleButtonUpEvent(const Event &event);
void handleMotionPrimaryEvent(const Event &, void *); void handleMotionPrimaryEvent(const Event &event);
void handleMotionSecondaryEvent(const Event &, void *); void handleMotionSecondaryEvent(const Event &event);
void handleWheelEvent(const Event &, void *); void handleWheelEvent(const Event &event);
void handleScreensaverActivatedEvent(const Event &, void *); void handleScreensaverActivatedEvent();
void handleScreensaverDeactivatedEvent(const Event &, void *); void handleScreensaverDeactivatedEvent();
void handleSwitchWaitTimeout(const Event &, void *); void handleSwitchWaitTimeout();
void handleClientDisconnected(const Event &, void *); void handleClientDisconnected(BaseClientProxy *client);
void handleClientCloseTimeout(const Event &, void *); void handleClientCloseTimeout(BaseClientProxy *client);
void handleSwitchToScreenEvent(const Event &, void *); void handleSwitchToScreenEvent(const Event &event);
void handleSwitchInDirectionEvent(const Event &, void *); void handleSwitchInDirectionEvent(const Event &event);
void handleKeyboardBroadcastEvent(const Event &, void *); void handleKeyboardBroadcastEvent(const Event &event);
void handleLockCursorToScreenEvent(const Event &, void *); void handleLockCursorToScreenEvent(const Event &event);
void handleFakeInputBeginEvent(const Event &, void *); void handleFakeInputBeginEvent();
void handleFakeInputEndEvent(const Event &, void *); void handleFakeInputEndEvent();
// event processing // event processing
void onClipboardChanged(const BaseClientProxy *sender, ClipboardID id, uint32_t seqNum); void onClipboardChanged(const BaseClientProxy *sender, ClipboardID id, uint32_t seqNum);

View file

@ -22,11 +22,10 @@ public:
MOCK_METHOD(void, removeHandlers, (void *), (override)); MOCK_METHOD(void, removeHandlers, (void *), (override));
MOCK_METHOD(EventTypes, registerType, (const char *)); MOCK_METHOD(EventTypes, registerType, (const char *));
MOCK_METHOD(bool, isEmpty, (), (const, override)); 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, addEvent, (const Event &), (override));
MOCK_METHOD(void, removeHandler, (EventTypes, void *), (override)); MOCK_METHOD(void, removeHandler, (EventTypes, void *), (override));
MOCK_METHOD(bool, dispatchEvent, (const Event &), (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, deleteTimer, (EventQueueTimer *), (override));
MOCK_METHOD(void *, getSystemTarget, (), (override)); MOCK_METHOD(void *, getSystemTarget, (), (override));
MOCK_METHOD(void, waitForReady, (), (const, override)); MOCK_METHOD(void, waitForReady, (), (const, override));