- made unit testing easier by (mostly) removing the event queue singleton.

- fixed code style in many places (mostly indentation).
This commit is contained in:
Nick Bolton 2013-06-29 14:17:49 +00:00
parent 13b2649fa0
commit 608074c041
143 changed files with 2220 additions and 2163 deletions

View File

@ -26,6 +26,7 @@
#include "CArchMiscWindows.h"
#include "resource.h"
#include "CMSWindowsScreen.h"
#include "CEventQueue.h"
//
// CMSWindowsClientTaskBarReceiver
@ -41,8 +42,8 @@ const UINT CMSWindowsClientTaskBarReceiver::s_stateToIconID[kMaxState] =
};
CMSWindowsClientTaskBarReceiver::CMSWindowsClientTaskBarReceiver(
HINSTANCE appInstance, const CBufferedLogOutputter* logBuffer) :
CClientTaskBarReceiver(),
HINSTANCE appInstance, const CBufferedLogOutputter* logBuffer, IEventQueue* events) :
CClientTaskBarReceiver(events),
m_appInstance(appInstance),
m_window(NULL),
m_logBuffer(logBuffer)
@ -357,7 +358,7 @@ CMSWindowsClientTaskBarReceiver::staticDlgProc(HWND hwnd,
}
IArchTaskBarReceiver*
createTaskBarReceiver(const CBufferedLogOutputter* logBuffer)
createTaskBarReceiver(const CBufferedLogOutputter* logBuffer, IEventQueue* events)
{
CArchMiscWindows::setIcons(
(HICON)LoadImage(CArchMiscWindows::instanceWin32(),
@ -370,5 +371,5 @@ createTaskBarReceiver(const CBufferedLogOutputter* logBuffer)
16, 16, LR_SHARED));
return new CMSWindowsClientTaskBarReceiver(
CMSWindowsScreen::getWindowInstance(), logBuffer);
CMSWindowsScreen::getWindowInstance(), logBuffer, events);
}

View File

@ -25,11 +25,12 @@
#include <windows.h>
class CBufferedLogOutputter;
class IEventQueue;
//! Implementation of CClientTaskBarReceiver for Microsoft Windows
class CMSWindowsClientTaskBarReceiver : public CClientTaskBarReceiver {
public:
CMSWindowsClientTaskBarReceiver(HINSTANCE, const CBufferedLogOutputter*);
CMSWindowsClientTaskBarReceiver(HINSTANCE, const CBufferedLogOutputter*, IEventQueue* events);
virtual ~CMSWindowsClientTaskBarReceiver();
// IArchTaskBarReceiver overrides
@ -63,6 +64,7 @@ private:
HMENU m_menu;
HICON m_icon[kMaxState];
const CBufferedLogOutputter* m_logBuffer;
static const UINT s_stateToIconID[];
};

View File

@ -45,6 +45,6 @@ main(int argc, char** argv)
CLog log;
CEventQueue events;
CClientApp app(createTaskBarReceiver);
CClientApp app(&events, createTaskBarReceiver);
return app.run(argc, argv);
}

View File

@ -26,6 +26,7 @@
#include "resource.h"
#include "CArchMiscWindows.h"
#include "CMSWindowsScreen.h"
#include "CEventQueue.h"
//
// CMSWindowsPortableTaskBarReceiver
@ -40,8 +41,9 @@ const UINT CMSWindowsPortableTaskBarReceiver::s_stateToIconID[kMaxState] =
};
CMSWindowsPortableTaskBarReceiver::CMSWindowsPortableTaskBarReceiver(
HINSTANCE appInstance, const CBufferedLogOutputter* logBuffer) :
CPortableTaskBarReceiver(),
HINSTANCE appInstance, const CBufferedLogOutputter* logBuffer, IEventQueue* events) :
CPortableTaskBarReceiver(events),
m_events(events),
m_appInstance(appInstance),
m_window(NULL),
m_logBuffer(logBuffer)
@ -178,18 +180,18 @@ CMSWindowsPortableTaskBarReceiver::runMenu(int x, int y)
break;
case IDC_RELOAD_CONFIG:
EVENTQUEUE->addEvent(CEvent(getReloadConfigEvent(),
IEventQueue::getSystemTarget()));
m_events->addEvent(CEvent(m_events->forCServerApp().reloadConfig(),
m_events->getSystemTarget()));
break;
case IDC_FORCE_RECONNECT:
EVENTQUEUE->addEvent(CEvent(getForceReconnectEvent(),
IEventQueue::getSystemTarget()));
m_events->addEvent(CEvent(m_events->forCServerApp().forceReconnect(),
m_events->getSystemTarget()));
break;
case ID_SYNERGY_RESETSERVER:
EVENTQUEUE->addEvent(CEvent(getResetServerEvent(),
IEventQueue::getSystemTarget()));
m_events->addEvent(CEvent(m_events->forCServerApp().resetServer(),
m_events->getSystemTarget()));
break;
case IDC_TASKBAR_LOG_LEVEL_ERROR:
@ -374,7 +376,7 @@ CMSWindowsPortableTaskBarReceiver::staticDlgProc(HWND hwnd,
}
IArchTaskBarReceiver*
createTaskBarReceiver(const CBufferedLogOutputter* logBuffer)
createTaskBarReceiver(const CBufferedLogOutputter* logBuffer, IEventQueue* events)
{
CArchMiscWindows::setIcons(
(HICON)LoadImage(CArchMiscWindows::instanceWin32(),
@ -387,5 +389,5 @@ createTaskBarReceiver(const CBufferedLogOutputter* logBuffer)
16, 16, LR_SHARED));
return new CMSWindowsPortableTaskBarReceiver(
CMSWindowsScreen::getWindowInstance(), logBuffer);
CMSWindowsScreen::getWindowInstance(), logBuffer, events);
}

View File

@ -24,11 +24,12 @@
#include <windows.h>
class CBufferedLogOutputter;
class IEventQueue;
//! Implementation of CPortableTaskBarReceiver for Microsoft Windows
class CMSWindowsPortableTaskBarReceiver : public CPortableTaskBarReceiver {
public:
CMSWindowsPortableTaskBarReceiver(HINSTANCE, const CBufferedLogOutputter*);
CMSWindowsPortableTaskBarReceiver(HINSTANCE, const CBufferedLogOutputter*, IEventQueue* events);
virtual ~CMSWindowsPortableTaskBarReceiver();
// IArchTaskBarReceiver overrides
@ -62,5 +63,7 @@ private:
HMENU m_menu;
HICON m_icon[kMaxState];
const CBufferedLogOutputter* m_logBuffer;
IEventQueue* m_events;
static const UINT s_stateToIconID[];
};

View File

@ -79,11 +79,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdSh
}
if (server) {
CServerApp app(createTaskBarReceiver);
CServerApp app(&events, createTaskBarReceiver);
return app.run(argc, argv);
}
else if (client) {
CClientApp app(createTaskBarReceiver);
CClientApp app(&events, createTaskBarReceiver);
return app.run(argc, argv);
}

View File

@ -27,6 +27,7 @@
#include "resource.h"
#include "CArchMiscWindows.h"
#include "CMSWindowsScreen.h"
#include "CEventQueue.h"
//
// CMSWindowsServerTaskBarReceiver
@ -41,8 +42,9 @@ const UINT CMSWindowsServerTaskBarReceiver::s_stateToIconID[kMaxState] =
};
CMSWindowsServerTaskBarReceiver::CMSWindowsServerTaskBarReceiver(
HINSTANCE appInstance, const CBufferedLogOutputter* logBuffer) :
CServerTaskBarReceiver(),
HINSTANCE appInstance, const CBufferedLogOutputter* logBuffer, IEventQueue* events) :
CServerTaskBarReceiver(events),
m_events(events),
m_appInstance(appInstance),
m_window(NULL),
m_logBuffer(logBuffer)
@ -192,18 +194,18 @@ CMSWindowsServerTaskBarReceiver::runMenu(int x, int y)
break;
case IDC_RELOAD_CONFIG:
EVENTQUEUE->addEvent(CEvent(getReloadConfigEvent(),
IEventQueue::getSystemTarget()));
m_events->addEvent(CEvent(m_events->forCServerApp().reloadConfig(),
m_events->getSystemTarget()));
break;
case IDC_FORCE_RECONNECT:
EVENTQUEUE->addEvent(CEvent(getForceReconnectEvent(),
IEventQueue::getSystemTarget()));
m_events->addEvent(CEvent(m_events->forCServerApp().forceReconnect(),
m_events->getSystemTarget()));
break;
case ID_SYNERGY_RESETSERVER:
EVENTQUEUE->addEvent(CEvent(getResetServerEvent(),
IEventQueue::getSystemTarget()));
m_events->addEvent(CEvent(m_events->forCServerApp().resetServer(),
m_events->getSystemTarget()));
break;
case IDC_TASKBAR_LOG_LEVEL_ERROR:
@ -388,7 +390,7 @@ CMSWindowsServerTaskBarReceiver::staticDlgProc(HWND hwnd,
}
IArchTaskBarReceiver*
createTaskBarReceiver(const CBufferedLogOutputter* logBuffer)
createTaskBarReceiver(const CBufferedLogOutputter* logBuffer, IEventQueue* events)
{
CArchMiscWindows::setIcons(
(HICON)LoadImage(CArchMiscWindows::instanceWin32(),
@ -401,5 +403,5 @@ createTaskBarReceiver(const CBufferedLogOutputter* logBuffer)
16, 16, LR_SHARED));
return new CMSWindowsServerTaskBarReceiver(
CMSWindowsScreen::getWindowInstance(), logBuffer);
CMSWindowsScreen::getWindowInstance(), logBuffer, events);
}

View File

@ -25,11 +25,12 @@
#include <windows.h>
class CBufferedLogOutputter;
class IEventQueue;
//! Implementation of CServerTaskBarReceiver for Microsoft Windows
class CMSWindowsServerTaskBarReceiver : public CServerTaskBarReceiver {
public:
CMSWindowsServerTaskBarReceiver(HINSTANCE, const CBufferedLogOutputter*);
CMSWindowsServerTaskBarReceiver(HINSTANCE, const CBufferedLogOutputter*, IEventQueue* events);
virtual ~CMSWindowsServerTaskBarReceiver();
// IArchTaskBarReceiver overrides
@ -63,6 +64,8 @@ private:
HMENU m_menu;
HICON m_icon[kMaxState];
const CBufferedLogOutputter* m_logBuffer;
IEventQueue* m_events;
static const UINT s_stateToIconID[];
};

View File

@ -45,6 +45,6 @@ main(int argc, char** argv)
CLog log;
CEventQueue events;
CServerApp app(createTaskBarReceiver);
CServerApp app(&events, createTaskBarReceiver);
return app.run(argc, argv);
}

View File

@ -27,6 +27,6 @@ CArchPluginUnix::~CArchPluginUnix()
}
void
CArchPluginUnix::init(void* eventTarget)
CArchPluginUnix::init(void* eventTarget, IEventQueue* events)
{
}

View File

@ -22,6 +22,8 @@
#define ARCH_PLUGIN CArchPluginUnix
class IEventQueue;
//! Unix implementation of IArchPlugin
class CArchPluginUnix : public IArchPlugin {
public:
@ -29,5 +31,5 @@ public:
virtual ~CArchPluginUnix();
// IArchPlugin overrides
void init(void* eventTarget);
void init(void* eventTarget, IEventQueue* events);
};

View File

@ -22,7 +22,6 @@
#include "IEventQueue.h"
#include "CEvent.h"
#include "CScreen.h"
#include "IPlatformScreen.h" // temp
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
@ -30,7 +29,8 @@
typedef int (*initFunc)(void (*sendEvent)(const char*, void*), void (*log)(const char*));
void* CArchPluginWindows::m_eventTarget = NULL;
void* g_eventTarget = NULL;
IEventQueue* g_events = NULL;
CArchPluginWindows::CArchPluginWindows()
{
@ -41,9 +41,10 @@ CArchPluginWindows::~CArchPluginWindows()
}
void
CArchPluginWindows::init(void* eventTarget)
CArchPluginWindows::init(void* eventTarget, IEventQueue* events)
{
m_eventTarget = eventTarget;
g_eventTarget = eventTarget;
g_events = events;
CString dir = getPluginsDir();
LOG((CLOG_DEBUG "plugins dir: %s", dir.c_str()));
@ -115,8 +116,8 @@ void
sendEvent(const char* eventName, void* data)
{
LOG((CLOG_DEBUG5 "plugin sending event"));
CEvent::Type type = EVENTQUEUE->getRegisteredType(eventName);
EVENTQUEUE->addEvent(CEvent(type, CArchPluginWindows::m_eventTarget, data));
CEvent::Type type = g_events->getRegisteredType(eventName);
g_events->addEvent(CEvent(type, g_eventTarget, data));
}
void

View File

@ -25,6 +25,7 @@
#define ARCH_PLUGIN CArchPluginWindows
class CScreen;
class IEventQueue;
//! Windows implementation of IArchPlugin
class CArchPluginWindows : public IArchPlugin {
@ -33,9 +34,7 @@ public:
virtual ~CArchPluginWindows();
// IArchPlugin overrides
void init(void* eventTarget);
static void* m_eventTarget;
void init(void* eventTarget, IEventQueue* events);
private:
CString getModuleDir();

View File

@ -22,6 +22,8 @@
#include "IInterface.h"
class IEventQueue;
//! Interface for plugin manager.
/*!
A plugin manager should load all 3rd party plugins from the plugins dir,
@ -36,7 +38,7 @@ public:
/*!
Scan the plugins dir and load plugins.
*/
virtual void init(void* eventTarget) = 0;
virtual void init(void* eventTarget, IEventQueue* events) = 0;
//@}
};

View File

@ -54,7 +54,6 @@ public:
//! Create \c CEvent with data (POD)
/*!
The \p type must have been registered using \c registerType().
The \p data must be POD (plain old data) allocated by malloc(),
which means it cannot have a constructor, destructor or be
composed of any types that do. For non-POD (normal C++ objects

View File

@ -22,13 +22,35 @@
#include "CStopwatch.h"
#include "IEventJob.h"
#include "CArch.h"
#include "CEventTypes.h"
EVENT_TYPE_ACCESSOR(CClient)
EVENT_TYPE_ACCESSOR(IStream)
EVENT_TYPE_ACCESSOR(CIpcClient)
EVENT_TYPE_ACCESSOR(CIpcClientProxy)
EVENT_TYPE_ACCESSOR(CIpcServer)
EVENT_TYPE_ACCESSOR(CIpcServerProxy)
EVENT_TYPE_ACCESSOR(IDataSocket)
EVENT_TYPE_ACCESSOR(IListenSocket)
EVENT_TYPE_ACCESSOR(ISocket)
EVENT_TYPE_ACCESSOR(COSXScreen)
EVENT_TYPE_ACCESSOR(CClientListener)
EVENT_TYPE_ACCESSOR(CClientProxy)
EVENT_TYPE_ACCESSOR(CClientProxyUnknown)
EVENT_TYPE_ACCESSOR(CServer)
EVENT_TYPE_ACCESSOR(CServerApp)
EVENT_TYPE_ACCESSOR(IKeyState)
EVENT_TYPE_ACCESSOR(IPrimaryScreen)
EVENT_TYPE_ACCESSOR(IScreen)
EVENT_TYPE_ACCESSOR(ISecondaryScreen)
// interrupt handler. this just adds a quit event to the queue.
static
void
interrupt(CArch::ESignal, void*)
interrupt(CArch::ESignal, void* data)
{
EVENTQUEUE->addEvent(CEvent(CEvent::kQuit));
CEventQueue* events = reinterpret_cast<CEventQueue*>(data);
events->addEvent(CEvent(CEvent::kQuit));
}
@ -37,12 +59,30 @@ interrupt(CArch::ESignal, void*)
//
CEventQueue::CEventQueue() :
m_nextType(CEvent::kLast)
m_systemTarget(0),
m_nextType(CEvent::kLast),
m_typesForIStream(NULL),
m_typesForCIpcClient(NULL),
m_typesForCIpcClientProxy(NULL),
m_typesForCIpcServer(NULL),
m_typesForCIpcServerProxy(NULL),
m_typesForIDataSocket(NULL),
m_typesForIListenSocket(NULL),
m_typesForISocket(NULL),
m_typesForCOSXScreen(NULL),
m_typesForCClientListener(NULL),
m_typesForCClientProxy(NULL),
m_typesForCClientProxyUnknown(NULL),
m_typesForCServer(NULL),
m_typesForCServerApp(NULL),
m_typesForIKeyState(NULL),
m_typesForIPrimaryScreen(NULL),
m_typesForIScreen(NULL),
m_typesForISecondaryScreen(NULL)
{
setInstance(this);
m_mutex = ARCH->newMutex();
ARCH->setSignalHandler(CArch::kINTERRUPT, &interrupt, NULL);
ARCH->setSignalHandler(CArch::kTERMINATE, &interrupt, NULL);
ARCH->setSignalHandler(CArch::kINTERRUPT, &interrupt, this);
ARCH->setSignalHandler(CArch::kTERMINATE, &interrupt, this);
m_buffer = new CSimpleEventQueueBuffer;
}
@ -52,7 +92,6 @@ CEventQueue::~CEventQueue()
ARCH->setSignalHandler(CArch::kINTERRUPT, NULL, NULL);
ARCH->setSignalHandler(CArch::kTERMINATE, NULL, NULL);
ARCH->closeMutex(m_mutex);
setInstance(NULL);
}
void
@ -67,16 +106,6 @@ CEventQueue::loop()
}
}
CEvent::Type
CEventQueue::registerType(const char* name)
{
CArchMutexLock lock(m_mutex);
m_typeMap.insert(std::make_pair(m_nextType, name));
m_nameMap.insert(std::make_pair(name, m_nextType));
LOG((CLOG_DEBUG1 "registered event type %s as %d", name, m_nextType));
return m_nextType++;
}
CEvent::Type
CEventQueue::registerTypeOnce(CEvent::Type& type, const char* name)
{
@ -488,6 +517,12 @@ CEventQueue::getRegisteredType(const CString& name) const
return CEvent::kUnknown;
}
void*
CEventQueue::getSystemTarget()
{
// any unique arbitrary pointer will do
return &m_systemTarget;
}
//
// CEventQueue::CTimer

View File

@ -52,8 +52,6 @@ public:
void* target, IEventJob* handler);
virtual void removeHandler(CEvent::Type type, void* target);
virtual void removeHandlers(void* target);
virtual CEvent::Type
registerType(const char* name);
virtual CEvent::Type
registerTypeOnce(CEvent::Type& type, const char* name);
virtual bool isEmpty() const;
@ -61,6 +59,7 @@ public:
virtual const char* getTypeName(CEvent::Type type);
virtual CEvent::Type
getRegisteredType(const CString& name) const;
void* getSystemTarget();
private:
UInt32 saveEvent(const CEvent& event);
@ -96,6 +95,7 @@ private:
bool m_oneShot;
double m_time;
};
typedef std::set<CEventQueueTimer*> CTimers;
typedef CPriorityQueue<CTimer> CTimerQueue;
typedef std::map<UInt32, CEvent> CEventTable;
@ -105,6 +105,7 @@ private:
typedef std::map<CEvent::Type, IEventJob*> CTypeHandlerTable;
typedef std::map<void*, CTypeHandlerTable> CHandlerTable;
int m_systemTarget;
CArchMutex m_mutex;
// registered events
@ -127,6 +128,61 @@ private:
// event handlers
CHandlerTable m_handlers;
public:
//
// Event type providers.
//
CClientEvents& forCClient();
IStreamEvents& forIStream();
CIpcClientEvents& forCIpcClient();
CIpcClientProxyEvents& forCIpcClientProxy();
CIpcServerEvents& forCIpcServer();
CIpcServerProxyEvents& forCIpcServerProxy();
IDataSocketEvents& forIDataSocket();
IListenSocketEvents& forIListenSocket();
ISocketEvents& forISocket();
COSXScreenEvents& forCOSXScreen();
CClientListenerEvents& forCClientListener();
CClientProxyEvents& forCClientProxy();
CClientProxyUnknownEvents& forCClientProxyUnknown();
CServerEvents& forCServer();
CServerAppEvents& forCServerApp();
IKeyStateEvents& forIKeyState();
IPrimaryScreenEvents& forIPrimaryScreen();
IScreenEvents& forIScreen();
ISecondaryScreenEvents& forISecondaryScreen();
private:
CClientEvents* m_typesForCClient;
IStreamEvents* m_typesForIStream;
CIpcClientEvents* m_typesForCIpcClient;
CIpcClientProxyEvents* m_typesForCIpcClientProxy;
CIpcServerEvents* m_typesForCIpcServer;
CIpcServerProxyEvents* m_typesForCIpcServerProxy;
IDataSocketEvents* m_typesForIDataSocket;
IListenSocketEvents* m_typesForIListenSocket;
ISocketEvents* m_typesForISocket;
COSXScreenEvents* m_typesForCOSXScreen;
CClientListenerEvents* m_typesForCClientListener;
CClientProxyEvents* m_typesForCClientProxy;
CClientProxyUnknownEvents* m_typesForCClientProxyUnknown;
CServerEvents* m_typesForCServer;
CServerAppEvents* m_typesForCServerApp;
IKeyStateEvents* m_typesForIKeyState;
IPrimaryScreenEvents* m_typesForIPrimaryScreen;
IScreenEvents* m_typesForIScreen;
ISecondaryScreenEvents* m_typesForISecondaryScreen;
};
#define EVENT_TYPE_ACCESSOR(type_) \
type_##Events& \
CEventQueue::for##type_##() { \
if (m_typesFor##type_ == NULL) { \
m_typesFor##type_ = new type_##Events(); \
m_typesFor##type_->setEvents(dynamic_cast<IEventQueue*>(this)); \
} \
return *m_typesFor##type_; \
}
#endif

View File

@ -0,0 +1,196 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Bolton Software Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CEventTypes.h"
#include "IEventQueue.h"
#include <assert.h>
#include <stddef.h>
CEventTypes::CEventTypes() :
m_events(NULL)
{
}
IEventQueue*
CEventTypes::events() const
{
assert(m_events != NULL);
return m_events;
}
void
CEventTypes::setEvents(IEventQueue* events)
{
m_events = events;
}
//
// CClient
//
REGISTER_EVENT(CClient, connected)
REGISTER_EVENT(CClient, connectionFailed)
REGISTER_EVENT(CClient, disconnected)
//
// IStream
//
REGISTER_EVENT(IStream, inputReady)
REGISTER_EVENT(IStream, outputFlushed)
REGISTER_EVENT(IStream, outputError)
REGISTER_EVENT(IStream, inputShutdown)
REGISTER_EVENT(IStream, outputShutdown)
//
// CIpcClient
//
REGISTER_EVENT(CIpcClient, connected)
REGISTER_EVENT(CIpcClient, messageReceived)
//
// CIpcClientProxy
//
REGISTER_EVENT(CIpcClientProxy, messageReceived)
REGISTER_EVENT(CIpcClientProxy, disconnected)
//
// CIpcServerProxy
//
REGISTER_EVENT(CIpcServerProxy, messageReceived)
//
// IDataSocket
//
REGISTER_EVENT(IDataSocket, connected)
REGISTER_EVENT(IDataSocket, connectionFailed)
//
// IListenSocket
//
REGISTER_EVENT(IListenSocket, connecting)
//
// ISocket
//
REGISTER_EVENT(ISocket, disconnected)
//
// COSXScreen
//
REGISTER_EVENT(COSXScreen, confirmSleep)
//
// CClientListener
//
REGISTER_EVENT(CClientListener, connected)
//
// CClientProxy
//
REGISTER_EVENT(CClientProxy, ready)
REGISTER_EVENT(CClientProxy, disconnected)
REGISTER_EVENT(CClientProxy, clipboardChanged)
//
// CClientProxyUnknown
//
REGISTER_EVENT(CClientProxyUnknown, success)
REGISTER_EVENT(CClientProxyUnknown, failure)
//
// CServer
//
REGISTER_EVENT(CServer, error)
REGISTER_EVENT(CServer, connected)
REGISTER_EVENT(CServer, disconnected)
REGISTER_EVENT(CServer, switchToScreen)
REGISTER_EVENT(CServer, switchInDirection)
REGISTER_EVENT(CServer, keyboardBroadcast)
REGISTER_EVENT(CServer, lockCursorToScreen)
REGISTER_EVENT(CServer, screenSwitched)
//
// CServerApp
//
REGISTER_EVENT(CServerApp, reloadConfig)
REGISTER_EVENT(CServerApp, forceReconnect)
REGISTER_EVENT(CServerApp, resetServer)
//
// IKeyState
//
REGISTER_EVENT(IKeyState, keyDown)
REGISTER_EVENT(IKeyState, keyUp)
REGISTER_EVENT(IKeyState, keyRepeat)
//
// IPrimaryScreen
//
REGISTER_EVENT(IPrimaryScreen, buttonDown)
REGISTER_EVENT(IPrimaryScreen, buttonUp)
REGISTER_EVENT(IPrimaryScreen, motionOnPrimary)
REGISTER_EVENT(IPrimaryScreen, motionOnSecondary)
REGISTER_EVENT(IPrimaryScreen, wheel)
REGISTER_EVENT(IPrimaryScreen, screensaverActivated)
REGISTER_EVENT(IPrimaryScreen, screensaverDeactivated)
REGISTER_EVENT(IPrimaryScreen, hotKeyDown)
REGISTER_EVENT(IPrimaryScreen, hotKeyUp)
REGISTER_EVENT(IPrimaryScreen, fakeInputBegin)
REGISTER_EVENT(IPrimaryScreen, fakeInputEnd)
REGISTER_EVENT(IPrimaryScreen, gameDeviceButtons)
REGISTER_EVENT(IPrimaryScreen, gameDeviceSticks)
REGISTER_EVENT(IPrimaryScreen, gameDeviceTriggers)
REGISTER_EVENT(IPrimaryScreen, gameDeviceTimingReq)
//
// IScreen
//
REGISTER_EVENT(IScreen, error)
REGISTER_EVENT(IScreen, shapeChanged)
REGISTER_EVENT(IScreen, clipboardGrabbed)
REGISTER_EVENT(IScreen, suspend)
REGISTER_EVENT(IScreen, resume)
//
// ISecondaryScreen
//
REGISTER_EVENT(ISecondaryScreen, gameDeviceTimingResp)
REGISTER_EVENT(ISecondaryScreen, gameDeviceFeedback)
//
// CIpcServer
//
REGISTER_EVENT(CIpcServer, clientConnected)
REGISTER_EVENT(CIpcServer, messageReceived)

721
src/lib/base/CEventTypes.h Normal file
View File

@ -0,0 +1,721 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Bolton Software Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "CEvent.h"
class IEventQueue;
class CEventTypes {
public:
CEventTypes();
void setEvents(IEventQueue* events);
protected:
IEventQueue* events() const;
private:
IEventQueue* m_events;
};
#define REGISTER_EVENT(type_, name_) \
CEvent::Type \
type_##Events::name_() \
{ \
return events()->registerTypeOnce(m_##name_, __FUNCTION__); \
}
class CClientEvents : public CEventTypes {
public:
CClientEvents() :
m_connected(CEvent::kUnknown),
m_connectionFailed(CEvent::kUnknown),
m_disconnected(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get connected event type
/*!
Returns the connected event type. This is sent when the client has
successfully connected to the server.
*/
CEvent::Type connected();
//! Get connection failed event type
/*!
Returns the connection failed event type. This is sent when the
server fails for some reason. The event data is a CFailInfo*.
*/
CEvent::Type connectionFailed();
//! Get disconnected event type
/*!
Returns the disconnected event type. This is sent when the client
has disconnected from the server (and only after having successfully
connected).
*/
CEvent::Type disconnected();
//@}
private:
CEvent::Type m_connected;
CEvent::Type m_connectionFailed;
CEvent::Type m_disconnected;
};
class IStreamEvents : public CEventTypes {
public:
IStreamEvents() :
m_inputReady(CEvent::kUnknown),
m_outputFlushed(CEvent::kUnknown),
m_outputError(CEvent::kUnknown),
m_inputShutdown(CEvent::kUnknown),
m_outputShutdown(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get input ready event type
/*!
Returns the input ready event type. A stream sends this event
when \c read() will return with data.
*/
CEvent::Type inputReady();
//! Get output flushed event type
/*!
Returns the output flushed event type. A stream sends this event
when the output buffer has been flushed. If there have been no
writes since the event was posted, calling \c shutdownOutput() or
\c close() will not discard any data and \c flush() will return
immediately.
*/
CEvent::Type outputFlushed();
//! Get output error event type
/*!
Returns the output error event type. A stream sends this event
when a write has failed.
*/
CEvent::Type outputError();
//! Get input shutdown event type
/*!
Returns the input shutdown event type. This is sent when the
input side of the stream has shutdown. When the input has
shutdown, no more data will ever be available to read.
*/
CEvent::Type inputShutdown();
//! Get output shutdown event type
/*!
Returns the output shutdown event type. This is sent when the
output side of the stream has shutdown. When the output has
shutdown, no more data can ever be written to the stream. Any
attempt to do so will generate a output error event.
*/
CEvent::Type outputShutdown();
//@}
private:
CEvent::Type m_inputReady;
CEvent::Type m_outputFlushed;
CEvent::Type m_outputError;
CEvent::Type m_inputShutdown;
CEvent::Type m_outputShutdown;
};
class CIpcClientEvents : public CEventTypes {
public:
CIpcClientEvents() :
m_connected(CEvent::kUnknown),
m_messageReceived(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Raised when the socket is connected.
CEvent::Type connected();
//! Raised when a message is received.
CEvent::Type messageReceived();
//@}
private:
CEvent::Type m_connected;
CEvent::Type m_messageReceived;
};
class CIpcClientProxyEvents : public CEventTypes {
public:
CIpcClientProxyEvents() :
m_messageReceived(CEvent::kUnknown),
m_disconnected(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Raised when the server receives a message from a client.
CEvent::Type messageReceived();
//! Raised when the client disconnects from the server.
CEvent::Type disconnected();
//@}
private:
CEvent::Type m_messageReceived;
CEvent::Type m_disconnected;
};
class CIpcServerEvents : public CEventTypes {
public:
CIpcServerEvents() :
m_clientConnected(CEvent::kUnknown),
m_messageReceived(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Raised when we have created the client proxy.
CEvent::Type clientConnected();
//! Raised when a message is received through a client proxy.
CEvent::Type messageReceived();
//@}
private:
CEvent::Type m_clientConnected;
CEvent::Type m_messageReceived;
};
class CIpcServerProxyEvents : public CEventTypes {
public:
CIpcServerProxyEvents() :
m_messageReceived(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Raised when the client receives a message from the server.
CEvent::Type messageReceived();
//@}
private:
CEvent::Type m_messageReceived;
};
class IDataSocketEvents : public CEventTypes {
public:
IDataSocketEvents() :
m_connected(CEvent::kUnknown),
m_connectionFailed(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get connected event type
/*!
Returns the socket connected event type. A socket sends this
event when a remote connection has been established.
*/
CEvent::Type connected();
//! Get connection failed event type
/*!
Returns the socket connection failed event type. A socket sends
this event when an attempt to connect to a remote port has failed.
The data is a pointer to a CConnectionFailedInfo.
*/
CEvent::Type connectionFailed();
//@}
private:
CEvent::Type m_connected;
CEvent::Type m_connectionFailed;
};
class IListenSocketEvents : public CEventTypes {
public:
IListenSocketEvents() :
m_connecting(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get connecting event type
/*!
Returns the socket connecting event type. A socket sends this
event when a remote connection is waiting to be accepted.
*/
CEvent::Type connecting();
//@}
private:
CEvent::Type m_connecting;
};
class ISocketEvents : public CEventTypes {
public:
ISocketEvents() :
m_disconnected(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get disconnected event type
/*!
Returns the socket disconnected event type. A socket sends this
event when the remote side of the socket has disconnected or
shutdown both input and output.
*/
CEvent::Type disconnected();
//@}
private:
CEvent::Type m_disconnected;
};
class COSXScreenEvents : public CEventTypes {
public:
COSXScreenEvents() :
m_confirmSleep(CEvent::kUnknown) { }
//! @name accessors
//@{
CEvent::Type confirmSleep();
//@}
private:
CEvent::Type m_confirmSleep;
};
class CClientListenerEvents : public CEventTypes {
public:
CClientListenerEvents() :
m_connected(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get connected event type
/*!
Returns the connected event type. This is sent whenever a
a client connects.
*/
CEvent::Type connected();
//@}
private:
CEvent::Type m_connected;
};
class CClientProxyEvents : public CEventTypes {
public:
CClientProxyEvents() :
m_ready(CEvent::kUnknown),
m_disconnected(CEvent::kUnknown),
m_clipboardChanged(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get ready event type
/*!
Returns the ready event type. This is sent when the client has
completed the initial handshake. Until it is sent, the client is
not fully connected.
*/
CEvent::Type ready();
//! Get disconnect event type
/*!
Returns the disconnect event type. This is sent when the client
disconnects or is disconnected. The target is getEventTarget().
*/
CEvent::Type disconnected();
//! Get clipboard changed event type
/*!
Returns the clipboard changed event type. This is sent whenever the
contents of the clipboard has changed. The data is a pointer to a
IScreen::CClipboardInfo.
*/
CEvent::Type clipboardChanged();
//@}
private:
CEvent::Type m_ready;
CEvent::Type m_disconnected;
CEvent::Type m_clipboardChanged;
};
class CClientProxyUnknownEvents : public CEventTypes {
public:
CClientProxyUnknownEvents() :
m_success(CEvent::kUnknown),
m_failure(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get success event type
/*!
Returns the success event type. This is sent when the client has
correctly responded to the hello message. The target is this.
*/
CEvent::Type success();
//! Get failure event type
/*!
Returns the failure event type. This is sent when a client fails
to correctly respond to the hello message. The target is this.
*/
CEvent::Type failure();
//@}
private:
CEvent::Type m_success;
CEvent::Type m_failure;
};
class CServerEvents : public CEventTypes {
public:
CServerEvents() :
m_error(CEvent::kUnknown),
m_connected(CEvent::kUnknown),
m_disconnected(CEvent::kUnknown),
m_switchToScreen(CEvent::kUnknown),
m_switchInDirection(CEvent::kUnknown),
m_keyboardBroadcast(CEvent::kUnknown),
m_lockCursorToScreen(CEvent::kUnknown),
m_screenSwitched(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get error event type
/*!
Returns the error event type. This is sent when the server fails
for some reason.
*/
CEvent::Type error();
//! Get connected event type
/*!
Returns the connected event type. This is sent when a client screen
has connected. The event data is a \c CScreenConnectedInfo* that
indicates the connected screen.
*/
CEvent::Type connected();
//! Get disconnected event type
/*!
Returns the disconnected event type. This is sent when all the
clients have disconnected.
*/
CEvent::Type disconnected();
//! Get switch to screen event type
/*!
Returns the switch to screen event type. The server responds to this
by switching screens. The event data is a \c CSwitchToScreenInfo*
that indicates the target screen.
*/
CEvent::Type switchToScreen();
//! Get switch in direction event type
/*!
Returns the switch in direction event type. The server responds to this
by switching screens. The event data is a \c CSwitchInDirectionInfo*
that indicates the target direction.
*/
CEvent::Type switchInDirection();
//! Get keyboard broadcast event type
/*!
Returns the keyboard broadcast event type. The server responds
to this by turning on keyboard broadcasting or turning it off. The
event data is a \c CKeyboardBroadcastInfo*.
*/
CEvent::Type keyboardBroadcast();
//! Get lock cursor event type
/*!
Returns the lock cursor event type. The server responds to this
by locking the cursor to the active screen or unlocking it. The
event data is a \c CLockCursorToScreenInfo*.
*/
CEvent::Type lockCursorToScreen();
//! Get screen switched event type
/*!
Returns the screen switched event type. This is raised when the
screen has been switched to a client.
*/
CEvent::Type screenSwitched();
//@}
private:
CEvent::Type m_error;
CEvent::Type m_connected;
CEvent::Type m_disconnected;
CEvent::Type m_switchToScreen;
CEvent::Type m_switchInDirection;
CEvent::Type m_keyboardBroadcast;
CEvent::Type m_lockCursorToScreen;
CEvent::Type m_screenSwitched;
};
class CServerAppEvents : public CEventTypes {
public:
CServerAppEvents() :
m_reloadConfig(CEvent::kUnknown),
m_forceReconnect(CEvent::kUnknown),
m_resetServer(CEvent::kUnknown) { }
//! @name accessors
//@{
CEvent::Type reloadConfig();
CEvent::Type forceReconnect();
CEvent::Type resetServer();
//@}
private:
CEvent::Type m_reloadConfig;
CEvent::Type m_forceReconnect;
CEvent::Type m_resetServer;
};
class IKeyStateEvents : public CEventTypes {
public:
IKeyStateEvents() :
m_keyDown(CEvent::kUnknown),
m_keyUp(CEvent::kUnknown),
m_keyRepeat(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get key down event type. Event data is CKeyInfo*, count == 1.
CEvent::Type keyDown();
//! Get key up event type. Event data is CKeyInfo*, count == 1.
CEvent::Type keyUp();
//! Get key repeat event type. Event data is CKeyInfo*.
CEvent::Type keyRepeat();
//@}
private:
CEvent::Type m_keyDown;
CEvent::Type m_keyUp;
CEvent::Type m_keyRepeat;
};
class IPrimaryScreenEvents : public CEventTypes {
public:
IPrimaryScreenEvents() :
m_buttonDown(CEvent::kUnknown),
m_buttonUp(CEvent::kUnknown),
m_motionOnPrimary(CEvent::kUnknown),
m_motionOnSecondary(CEvent::kUnknown),
m_wheel(CEvent::kUnknown),
m_screensaverActivated(CEvent::kUnknown),
m_screensaverDeactivated(CEvent::kUnknown),
m_hotKeyDown(CEvent::kUnknown),
m_hotKeyUp(CEvent::kUnknown),
m_fakeInputBegin(CEvent::kUnknown),
m_fakeInputEnd(CEvent::kUnknown),
m_gameDeviceButtons(CEvent::kUnknown),
m_gameDeviceSticks(CEvent::kUnknown),
m_gameDeviceTriggers(CEvent::kUnknown),
m_gameDeviceTimingReq(CEvent::kUnknown) { }
//! @name accessors
//@{
//! button down event type. Event data is CButtonInfo*.
CEvent::Type buttonDown();
//! button up event type. Event data is CButtonInfo*.
CEvent::Type buttonUp();
//! mouse motion on the primary screen event type
/*!
Event data is CMotionInfo* and the values are an absolute position.
*/
CEvent::Type motionOnPrimary();
//! mouse motion on a secondary screen event type
/*!
Event data is CMotionInfo* and the values are motion deltas not
absolute coordinates.
*/
CEvent::Type motionOnSecondary();
//! mouse wheel event type. Event data is CWheelInfo*.
CEvent::Type wheel();
//! screensaver activated event type
CEvent::Type screensaverActivated();
//! screensaver deactivated event type
CEvent::Type screensaverDeactivated();
//! hot key down event type. Event data is CHotKeyInfo*.
CEvent::Type hotKeyDown();
//! hot key up event type. Event data is CHotKeyInfo*.
CEvent::Type hotKeyUp();
//! start of fake input event type
CEvent::Type fakeInputBegin();
//! end of fake input event type
CEvent::Type fakeInputEnd();
//! game device buttons event type.
CEvent::Type gameDeviceButtons();
//! game device sticks event type.
CEvent::Type gameDeviceSticks();
//! game device triggers event type.
CEvent::Type gameDeviceTriggers();
//! game device timing request event type.
CEvent::Type gameDeviceTimingReq();
//@}
private:
CEvent::Type m_buttonDown;
CEvent::Type m_buttonUp;
CEvent::Type m_motionOnPrimary;
CEvent::Type m_motionOnSecondary;
CEvent::Type m_wheel;
CEvent::Type m_screensaverActivated;
CEvent::Type m_screensaverDeactivated;
CEvent::Type m_hotKeyDown;
CEvent::Type m_hotKeyUp;
CEvent::Type m_fakeInputBegin;
CEvent::Type m_fakeInputEnd;
CEvent::Type m_gameDeviceButtons;
CEvent::Type m_gameDeviceSticks;
CEvent::Type m_gameDeviceTriggers;
CEvent::Type m_gameDeviceTimingReq;
};
class IScreenEvents : public CEventTypes {
public:
IScreenEvents() :
m_error(CEvent::kUnknown),
m_shapeChanged(CEvent::kUnknown),
m_clipboardGrabbed(CEvent::kUnknown),
m_suspend(CEvent::kUnknown),
m_resume(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get error event type
/*!
Returns the error event type. This is sent whenever the screen has
failed for some reason (e.g. the X Windows server died).
*/
CEvent::Type error();
//! Get shape changed event type
/*!
Returns the shape changed event type. This is sent whenever the
screen's shape changes.
*/
CEvent::Type shapeChanged();
//! Get clipboard grabbed event type
/*!
Returns the clipboard grabbed event type. This is sent whenever the
clipboard is grabbed by some other application so we don't own it
anymore. The data is a pointer to a CClipboardInfo.
*/
CEvent::Type clipboardGrabbed();
//! Get suspend event type
/*!
Returns the suspend event type. This is sent whenever the system goes
to sleep or a user session is deactivated (fast user switching).
*/
CEvent::Type suspend();
//! Get resume event type
/*!
Returns the suspend event type. This is sent whenever the system wakes
up or a user session is activated (fast user switching).
*/
CEvent::Type resume();
//@}
private:
CEvent::Type m_error;
CEvent::Type m_shapeChanged;
CEvent::Type m_clipboardGrabbed;
CEvent::Type m_suspend;
CEvent::Type m_resume;
};
class ISecondaryScreenEvents : public CEventTypes {
public:
ISecondaryScreenEvents() :
m_gameDeviceTimingResp(CEvent::kUnknown),
m_gameDeviceFeedback(CEvent::kUnknown) { }
//! @name accessors
//@{
//! Get game device timing response event type.
CEvent::Type gameDeviceTimingResp();
//! Get game device feedback event type.
CEvent::Type gameDeviceFeedback();
//@}
private:
CEvent::Type m_gameDeviceTimingResp;
CEvent::Type m_gameDeviceFeedback;
};

View File

@ -17,6 +17,7 @@
set(inc
CEvent.h
CEventQueue.h
CEventTypes.h
CFunctionEventJob.h
CFunctionJob.h
CLog.h
@ -41,6 +42,7 @@ set(inc
set(src
CEvent.cpp
CEventQueue.cpp
CEventTypes.cpp
CFunctionEventJob.cpp
CFunctionJob.cpp
CLog.cpp
@ -48,7 +50,6 @@ set(src
CStopwatch.cpp
CStringUtil.cpp
CUnicode.cpp
IEventQueue.cpp
LogOutputters.cpp
XBase.cpp
)

View File

@ -1,66 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Bolton Software Ltd.
* Copyright (C) 2004 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "IEventQueue.h"
#include "CLog.h"
#if WINAPI_CARBON
#include <execinfo.h>
#include <stdio.h>
#endif
//
// IEventQueue
//
static int g_systemTarget = 0;
IEventQueue* IEventQueue::s_instance = NULL;
void*
IEventQueue::getSystemTarget()
{
// any unique arbitrary pointer will do
return &g_systemTarget;
}
IEventQueue*
IEventQueue::getInstance()
{
if (s_instance == NULL) {
LOG((CLOG_ERR "null event queue"));
#if WINAPI_CARBON
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
printf("%s\n", strs[i]);
}
free(strs);
#endif
}
assert(s_instance != NULL);
return s_instance;
}
void
IEventQueue::setInstance(IEventQueue* instance)
{
assert(s_instance == NULL || instance == NULL);
s_instance = instance;
}

View File

@ -23,8 +23,6 @@
#include "CEvent.h"
#include "CString.h"
#define EVENTQUEUE IEventQueue::getInstance()
class IEventJob;
class IEventQueueBuffer;
@ -32,6 +30,27 @@ class IEventQueueBuffer;
// IEventQueueBuffer.
class CEventQueueTimer;
// Event type registration classes.
class CClientEvents;
class IStreamEvents;
class CIpcClientEvents;
class CIpcClientProxyEvents;
class CIpcServerEvents;
class CIpcServerProxyEvents;
class IDataSocketEvents;
class IListenSocketEvents;
class ISocketEvents;
class COSXScreenEvents;
class CClientListenerEvents;
class CClientProxyEvents;
class CClientProxyUnknownEvents;
class CServerEvents;
class CServerAppEvents;
class IKeyStateEvents;
class IPrimaryScreenEvents;
class IScreenEvents;
class ISecondaryScreenEvents;
//! Event queue interface
/*!
An event queue provides a queue of CEvents. Clients can block waiting
@ -149,13 +168,6 @@ public:
*/
virtual void removeHandlers(void* target) = 0;
//! Creates a new event type
/*!
Returns a unique event type id.
*/
virtual CEvent::Type
registerType(const char* name) = 0;
//! Creates a new event type
/*!
If \p type contains \c kUnknown then it is set to a unique event
@ -201,30 +213,33 @@ public:
/*!
Returns the target to use for dispatching \c CEvent::kSystem events.
*/
static void* getSystemTarget();
//! Get the singleton instance
/*!
Returns the singleton instance of the event queue
*/
static IEventQueue* getInstance();
virtual void* getSystemTarget() = 0;
//@}
protected:
//! @name manipulators
//@{
//
// Event type providers.
//
//! Set the singleton instance
/*!
Sets the singleton instance of the event queue
*/
static void setInstance(IEventQueue*);
//@}
private:
static IEventQueue* s_instance;
virtual CClientEvents& forCClient() = 0;
virtual IStreamEvents& forIStream() = 0;
virtual CIpcClientEvents& forCIpcClient() = 0;
virtual CIpcClientProxyEvents& forCIpcClientProxy() = 0;
virtual CIpcServerEvents& forCIpcServer() = 0;
virtual CIpcServerProxyEvents& forCIpcServerProxy() = 0;
virtual IDataSocketEvents& forIDataSocket() = 0;
virtual IListenSocketEvents& forIListenSocket() = 0;
virtual ISocketEvents& forISocket() = 0;
virtual COSXScreenEvents& forCOSXScreen() = 0;
virtual CClientListenerEvents& forCClientListener() = 0;
virtual CClientProxyEvents& forCClientProxy() = 0;
virtual CClientProxyUnknownEvents& forCClientProxyUnknown() = 0;
virtual CServerEvents& forCServer() = 0;
virtual CServerAppEvents& forCServerApp() = 0;
virtual IKeyStateEvents& forIKeyState() = 0;
virtual IPrimaryScreenEvents& forIPrimaryScreen() = 0;
virtual IScreenEvents& forIScreen() = 0;
virtual ISecondaryScreenEvents& forISecondaryScreen() = 0;
};
#endif

View File

@ -40,11 +40,7 @@
// CClient
//
CEvent::Type CClient::s_connectedEvent = CEvent::kUnknown;
CEvent::Type CClient::s_connectionFailedEvent = CEvent::kUnknown;
CEvent::Type CClient::s_disconnectedEvent = CEvent::kUnknown;
CClient::CClient(IEventQueue* eventQueue,
CClient::CClient(IEventQueue* events,
const CString& name, const CNetworkAddress& address,
ISocketFactory* socketFactory,
IStreamFilterFactory* streamFilterFactory,
@ -63,7 +59,7 @@ CClient::CClient(IEventQueue* eventQueue,
m_active(false),
m_suspended(false),
m_connectOnResume(false),
m_eventQueue(eventQueue),
m_events(events),
m_cryptoStream(NULL),
m_crypto(crypto)
{
@ -71,19 +67,19 @@ CClient::CClient(IEventQueue* eventQueue,
assert(m_screen != NULL);
// register suspend/resume event handlers
m_eventQueue->adoptHandler(IScreen::getSuspendEvent(),
m_events->adoptHandler(m_events->forIScreen().suspend(),
getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleSuspend));
m_eventQueue->adoptHandler(IScreen::getResumeEvent(),
m_events->adoptHandler(m_events->forIScreen().resume(),
getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleResume));
m_eventQueue->adoptHandler(IPlatformScreen::getGameDeviceTimingRespEvent(),
m_events->adoptHandler(m_events->forISecondaryScreen().gameDeviceTimingResp(),
getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleGameDeviceTimingResp));
m_eventQueue->adoptHandler(IPlatformScreen::getGameDeviceFeedbackEvent(),
m_events->adoptHandler(m_events->forISecondaryScreen().gameDeviceFeedback(),
getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleGameDeviceFeedback));
@ -95,9 +91,9 @@ CClient::~CClient()
return;
}
m_eventQueue->removeHandler(IScreen::getSuspendEvent(),
m_events->removeHandler(m_events->forIScreen().suspend(),
getEventTarget());
m_eventQueue->removeHandler(IScreen::getResumeEvent(),
m_events->removeHandler(m_events->forIScreen().resume(),
getEventTarget());
cleanupTimer();
@ -144,11 +140,11 @@ CClient::connect()
if (m_streamFilterFactory != NULL) {
m_stream = m_streamFilterFactory->create(m_stream, true);
}
m_stream = new CPacketStreamFilter(m_stream, true);
m_stream = new CPacketStreamFilter(m_events, m_stream, true);
if (m_crypto.m_mode != kDisabled) {
m_cryptoStream = new CCryptoStream(
EVENTQUEUE, m_stream, m_crypto, true);
m_events, m_stream, m_crypto, true);
m_stream = m_cryptoStream;
}
@ -181,7 +177,7 @@ CClient::disconnect(const char* msg)
sendConnectionFailedEvent(msg);
}
else {
sendEvent(getDisconnectedEvent(), NULL);
sendEvent(m_events->forCClient().disconnected(), NULL);
}
}
@ -190,7 +186,7 @@ CClient::handshakeComplete()
{
m_ready = true;
m_screen->enable();
sendEvent(getConnectedEvent(), NULL);
sendEvent(m_events->forCClient().connected(), NULL);
}
void
@ -219,27 +215,6 @@ CClient::getServerAddress() const
return m_serverAddress;
}
CEvent::Type
CClient::getConnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_connectedEvent,
"CClient::connected");
}
CEvent::Type
CClient::getConnectionFailedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_connectionFailedEvent,
"CClient::failed");
}
CEvent::Type
CClient::getDisconnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_disconnectedEvent,
"CClient::disconnected");
}
void*
CClient::getEventTarget() const
{
@ -446,7 +421,7 @@ CClient::sendClipboard(ClipboardID id)
void
CClient::sendEvent(CEvent::Type type, void* data)
{
m_eventQueue->addEvent(CEvent(type, getEventTarget(), data));
m_events->addEvent(CEvent(type, getEventTarget(), data));
}
void
@ -454,8 +429,8 @@ CClient::sendConnectionFailedEvent(const char* msg)
{
CFailInfo* info = new CFailInfo(msg);
info->m_retry = true;
CEvent event(getConnectionFailedEvent(), getEventTarget(), info, CEvent::kDontFreeData);
m_eventQueue->addEvent(event);
CEvent event(m_events->forCClient().connectionFailed(), getEventTarget(), info, CEvent::kDontFreeData);
m_events->addEvent(event);
}
void
@ -463,11 +438,11 @@ CClient::setupConnecting()
{
assert(m_stream != NULL);
m_eventQueue->adoptHandler(IDataSocket::getConnectedEvent(),
m_events->adoptHandler(m_events->forIDataSocket().connected(),
m_stream->getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleConnected));
m_eventQueue->adoptHandler(IDataSocket::getConnectionFailedEvent(),
m_events->adoptHandler(m_events->forIDataSocket().connectionFailed(),
m_stream->getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleConnectionFailed));
@ -478,23 +453,23 @@ CClient::setupConnection()
{
assert(m_stream != NULL);
m_eventQueue->adoptHandler(ISocket::getDisconnectedEvent(),
m_events->adoptHandler(m_events->forISocket().disconnected(),
m_stream->getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleDisconnected));
m_eventQueue->adoptHandler(m_stream->getInputReadyEvent(),
m_events->adoptHandler(m_events->forIStream().inputReady(),
m_stream->getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleHello));
m_eventQueue->adoptHandler(m_stream->getOutputErrorEvent(),
m_events->adoptHandler(m_events->forIStream().outputError(),
m_stream->getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleOutputError));
m_eventQueue->adoptHandler(m_stream->getInputShutdownEvent(),
m_events->adoptHandler(m_events->forIStream().inputShutdown(),
m_stream->getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleDisconnected));
m_eventQueue->adoptHandler(m_stream->getOutputShutdownEvent(),
m_events->adoptHandler(m_events->forIStream().outputShutdown(),
m_stream->getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleDisconnected));
@ -506,12 +481,12 @@ CClient::setupScreen()
assert(m_server == NULL);
m_ready = false;
m_server = new CServerProxy(this, m_stream, m_eventQueue);
m_eventQueue->adoptHandler(IScreen::getShapeChangedEvent(),
m_server = new CServerProxy(this, m_stream, m_events);
m_events->adoptHandler(m_events->forIScreen().shapeChanged(),
getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleShapeChanged));
m_eventQueue->adoptHandler(IScreen::getClipboardGrabbedEvent(),
m_events->adoptHandler(m_events->forIScreen().clipboardGrabbed(),
getEventTarget(),
new TMethodEventJob<CClient>(this,
&CClient::handleClipboardGrabbed));
@ -522,8 +497,8 @@ CClient::setupTimer()
{
assert(m_timer == NULL);
m_timer = m_eventQueue->newOneShotTimer(15.0, NULL);
m_eventQueue->adoptHandler(CEvent::kTimer, m_timer,
m_timer = m_events->newOneShotTimer(15.0, NULL);
m_events->adoptHandler(CEvent::kTimer, m_timer,
new TMethodEventJob<CClient>(this,
&CClient::handleConnectTimeout));
}
@ -532,9 +507,9 @@ void
CClient::cleanupConnecting()
{
if (m_stream != NULL) {
m_eventQueue->removeHandler(IDataSocket::getConnectedEvent(),
m_events->removeHandler(m_events->forIDataSocket().connected(),
m_stream->getEventTarget());
m_eventQueue->removeHandler(IDataSocket::getConnectionFailedEvent(),
m_events->removeHandler(m_events->forIDataSocket().connectionFailed(),
m_stream->getEventTarget());
}
}
@ -543,15 +518,15 @@ void
CClient::cleanupConnection()
{
if (m_stream != NULL) {
m_eventQueue->removeHandler(m_stream->getInputReadyEvent(),
m_events->removeHandler(m_events->forIStream().inputReady(),
m_stream->getEventTarget());
m_eventQueue->removeHandler(m_stream->getOutputErrorEvent(),
m_events->removeHandler(m_events->forIStream().outputError(),
m_stream->getEventTarget());
m_eventQueue->removeHandler(m_stream->getInputShutdownEvent(),
m_events->removeHandler(m_events->forIStream().inputShutdown(),
m_stream->getEventTarget());
m_eventQueue->removeHandler(m_stream->getOutputShutdownEvent(),
m_events->removeHandler(m_events->forIStream().outputShutdown(),
m_stream->getEventTarget());
m_eventQueue->removeHandler(ISocket::getDisconnectedEvent(),
m_events->removeHandler(m_events->forISocket().disconnected(),
m_stream->getEventTarget());
delete m_stream;
m_stream = NULL;
@ -566,9 +541,9 @@ CClient::cleanupScreen()
m_screen->disable();
m_ready = false;
}
m_eventQueue->removeHandler(IScreen::getShapeChangedEvent(),
m_events->removeHandler(m_events->forIScreen().shapeChanged(),
getEventTarget());
m_eventQueue->removeHandler(IScreen::getClipboardGrabbedEvent(),
m_events->removeHandler(m_events->forIScreen().clipboardGrabbed(),
getEventTarget());
delete m_server;
m_server = NULL;
@ -579,8 +554,8 @@ void
CClient::cleanupTimer()
{
if (m_timer != NULL) {
m_eventQueue->removeHandler(CEvent::kTimer, m_timer);
m_eventQueue->deleteTimer(m_timer);
m_events->removeHandler(CEvent::kTimer, m_timer);
m_events->deleteTimer(m_timer);
m_timer = NULL;
}
}
@ -634,7 +609,7 @@ CClient::handleOutputError(const CEvent&, void*)
cleanupScreen();
cleanupConnection();
LOG((CLOG_WARN "error sending to server"));
sendEvent(getDisconnectedEvent(), NULL);
sendEvent(m_events->forCClient().disconnected(), NULL);
}
void
@ -644,7 +619,7 @@ CClient::handleDisconnected(const CEvent&, void*)
cleanupScreen();
cleanupConnection();
LOG((CLOG_DEBUG1 "disconnected"));
sendEvent(getDisconnectedEvent(), NULL);
sendEvent(m_events->forCClient().disconnected(), NULL);
}
void
@ -710,7 +685,7 @@ CClient::handleHello(const CEvent&, void*)
// receive another event for already pending messages so we fake
// one.
if (m_stream->isReady()) {
m_eventQueue->addEvent(CEvent(m_stream->getInputReadyEvent(),
m_events->addEvent(CEvent(m_events->forIStream().inputReady(),
m_stream->getEventTarget()));
}
}

View File

@ -24,6 +24,7 @@
#include "CNetworkAddress.h"
#include "INode.h"
#include "CCryptoOptions.h"
#include "CEventTypes.h"
class CEventQueueTimer;
class CScreen;
@ -54,7 +55,7 @@ public:
as its name and \p address as the server's address and \p factory
to create the socket. \p screen is the local screen.
*/
CClient(IEventQueue* eventQueue,
CClient(IEventQueue* events,
const CString& name, const CNetworkAddress& address,
ISocketFactory* socketFactory,
IStreamFilterFactory* streamFilterFactory,
@ -63,7 +64,7 @@ public:
~CClient();
#ifdef TEST_ENV
CClient() { }
CClient() : m_mock(true), m_events(NULL) { }
#endif
//! @name manipulators
@ -115,28 +116,6 @@ public:
*/
CNetworkAddress getServerAddress() const;
//! Get connected event type
/*!
Returns the connected event type. This is sent when the client has
successfully connected to the server.
*/
static CEvent::Type getConnectedEvent();
//! Get connection failed event type
/*!
Returns the connection failed event type. This is sent when the
server fails for some reason. The event data is a CFailInfo*.
*/
static CEvent::Type getConnectionFailedEvent();
//! Get disconnected event type
/*!
Returns the disconnected event type. This is sent when the client
has disconnected from the server (and only after having successfully
connected).
*/
static CEvent::Type getDisconnectedEvent();
//@}
// IScreen overrides
@ -217,13 +196,9 @@ private:
bool m_sentClipboard[kClipboardEnd];
IClipboard::Time m_timeClipboard[kClipboardEnd];
CString m_dataClipboard[kClipboardEnd];
IEventQueue* m_eventQueue;
IEventQueue* m_events;
CCryptoStream* m_cryptoStream;
CCryptoOptions m_crypto;
static CEvent::Type s_connectedEvent;
static CEvent::Type s_connectionFailedEvent;
static CEvent::Type s_disconnectedEvent;
};
#endif

View File

@ -35,7 +35,7 @@
// CServerProxy
//
CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue* eventQueue) :
CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue* events) :
m_client(client),
m_stream(stream),
m_seqNum(0),
@ -49,7 +49,7 @@ CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueu
m_keepAliveAlarm(0.0),
m_keepAliveAlarmTimer(NULL),
m_parser(&CServerProxy::parseHandshakeMessage),
m_eventQueue(eventQueue)
m_events(events)
{
assert(m_client != NULL);
assert(m_stream != NULL);
@ -59,7 +59,7 @@ CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueu
m_modifierTranslationTable[id] = id;
// handle data on stream
m_eventQueue->adoptHandler(m_stream->getInputReadyEvent(),
m_events->adoptHandler(m_events->forIStream().inputReady(),
m_stream->getEventTarget(),
new TMethodEventJob<CServerProxy>(this,
&CServerProxy::handleData));
@ -71,7 +71,7 @@ CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueu
CServerProxy::~CServerProxy()
{
setKeepAliveRate(-1.0);
m_eventQueue->removeHandler(m_stream->getInputReadyEvent(),
m_events->removeHandler(m_events->forIStream().inputReady(),
m_stream->getEventTarget());
}
@ -79,14 +79,14 @@ void
CServerProxy::resetKeepAliveAlarm()
{
if (m_keepAliveAlarmTimer != NULL) {
m_eventQueue->removeHandler(CEvent::kTimer, m_keepAliveAlarmTimer);
m_eventQueue->deleteTimer(m_keepAliveAlarmTimer);
m_events->removeHandler(CEvent::kTimer, m_keepAliveAlarmTimer);
m_events->deleteTimer(m_keepAliveAlarmTimer);
m_keepAliveAlarmTimer = NULL;
}
if (m_keepAliveAlarm > 0.0) {
m_keepAliveAlarmTimer =
m_eventQueue->newOneShotTimer(m_keepAliveAlarm, NULL);
m_eventQueue->adoptHandler(CEvent::kTimer, m_keepAliveAlarmTimer,
m_events->newOneShotTimer(m_keepAliveAlarm, NULL);
m_events->adoptHandler(CEvent::kTimer, m_keepAliveAlarmTimer,
new TMethodEventJob<CServerProxy>(this,
&CServerProxy::handleKeepAliveAlarm));
}

View File

@ -42,7 +42,7 @@ public:
Process messages from the server on \p stream and forward to
\p client.
*/
CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue* eventQueue);
CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue* events);
~CServerProxy();
//! @name manipulators
@ -127,7 +127,7 @@ private:
CEventQueueTimer* m_keepAliveAlarmTimer;
MessageParser m_parser;
IEventQueue* m_eventQueue;
IEventQueue* m_events;
};
#endif

View File

@ -26,11 +26,11 @@ using namespace CryptoPP;
using namespace synergy::crypto;
CCryptoStream::CCryptoStream(
IEventQueue* eventQueue,
IEventQueue* events,
synergy::IStream* stream,
const CCryptoOptions& options,
bool adoptStream) :
CStreamFilter(eventQueue, stream, adoptStream),
CStreamFilter(events, stream, adoptStream),
m_key(NULL),
m_encryption(options.m_mode, true),
m_decryption(options.m_mode, false)

View File

@ -33,7 +33,7 @@ Encrypts (on write) and decrypts (on read) to and from an underlying stream.
*/
class CCryptoStream : public CStreamFilter {
public:
CCryptoStream(IEventQueue* eventQueue, synergy::IStream* stream, const CCryptoOptions& options, bool adoptStream = true);
CCryptoStream(IEventQueue* events, synergy::IStream* stream, const CCryptoOptions& options, bool adoptStream = true);
virtual ~CCryptoStream();
//! @name manipulators

View File

@ -29,7 +29,6 @@ set(inc
set(src
CStreamBuffer.cpp
CStreamFilter.cpp
IStream.cpp
XIO.cpp
CCryptoStream.cpp
CCryptoMode.cpp

View File

@ -24,21 +24,22 @@
// CStreamFilter
//
CStreamFilter::CStreamFilter(IEventQueue* eventQueue, synergy::IStream* stream, bool adoptStream) :
IStream(eventQueue),
CStreamFilter::CStreamFilter(IEventQueue* events, synergy::IStream* stream, bool adoptStream) :
IStream(events),
m_events(events),
m_stream(stream),
m_adopted(adoptStream)
{
// replace handlers for m_stream
getEventQueue().removeHandlers(m_stream->getEventTarget());
getEventQueue().adoptHandler(CEvent::kUnknown, m_stream->getEventTarget(),
m_events->removeHandlers(m_stream->getEventTarget());
m_events->adoptHandler(CEvent::kUnknown, m_stream->getEventTarget(),
new TMethodEventJob<CStreamFilter>(this,
&CStreamFilter::handleUpstreamEvent));
}
CStreamFilter::~CStreamFilter()
{
getEventQueue().removeHandler(CEvent::kUnknown, m_stream->getEventTarget());
m_events->removeHandler(CEvent::kUnknown, m_stream->getEventTarget());
if (m_adopted) {
delete m_stream;
}
@ -107,7 +108,7 @@ CStreamFilter::getStream() const
void
CStreamFilter::filterEvent(const CEvent& event)
{
getEventQueue().dispatchEvent(CEvent(event.getType(),
m_events->dispatchEvent(CEvent(event.getType(),
getEventTarget(), event.getData()));
}

View File

@ -34,7 +34,7 @@ public:
this object takes ownership of the stream and will delete it in the
d'tor.
*/
CStreamFilter(IEventQueue* eventQueue, synergy::IStream* stream, bool adoptStream = true);
CStreamFilter(IEventQueue* events, synergy::IStream* stream, bool adoptStream = true);
virtual ~CStreamFilter();
// IStream overrides
@ -70,6 +70,7 @@ private:
private:
synergy::IStream* m_stream;
bool m_adopted;
IEventQueue* m_events;
};
#endif

View File

@ -1,74 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Bolton Software Ltd.
* Copyright (C) 2004 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "IStream.h"
#include "CEventQueue.h"
using namespace synergy;
//
// IStream
//
CEvent::Type IStream::s_inputReadyEvent = CEvent::kUnknown;
CEvent::Type IStream::s_outputFlushedEvent = CEvent::kUnknown;
CEvent::Type IStream::s_outputErrorEvent = CEvent::kUnknown;
CEvent::Type IStream::s_inputShutdownEvent = CEvent::kUnknown;
CEvent::Type IStream::s_outputShutdownEvent = CEvent::kUnknown;
CEvent::Type
IStream::getInputReadyEvent()
{
return m_eventQueue->registerTypeOnce(s_inputReadyEvent,
"IStream::inputReady");
}
CEvent::Type
IStream::getOutputFlushedEvent()
{
return m_eventQueue->registerTypeOnce(s_outputFlushedEvent,
"IStream::outputFlushed");
}
CEvent::Type
IStream::getOutputErrorEvent()
{
return m_eventQueue->registerTypeOnce(s_outputErrorEvent,
"IStream::outputError");
}
CEvent::Type
IStream::getInputShutdownEvent()
{
return m_eventQueue->registerTypeOnce(s_inputShutdownEvent,
"IStream::inputShutdown");
}
CEvent::Type
IStream::getOutputShutdownEvent()
{
return m_eventQueue->registerTypeOnce(s_outputShutdownEvent,
"IStream::outputShutdown");
}
IEventQueue&
IStream::getEventQueue() const
{
assert(m_eventQueue != NULL);
return *m_eventQueue;
}

View File

@ -22,6 +22,7 @@
#include "IInterface.h"
#include "CEvent.h"
#include "IEventQueue.h"
#include "CEventTypes.h"
class IEventQueue;
@ -33,8 +34,7 @@ Defines the interface for all streams.
*/
class IStream : public IInterface {
public:
IStream() : m_eventQueue(EVENTQUEUE) { }
IStream(IEventQueue* eventQueue) : m_eventQueue(eventQueue) { }
IStream(IEventQueue* events) : m_events(events) { }
//! @name manipulators
//@{
@ -115,60 +115,10 @@ public:
*/
virtual UInt32 getSize() const = 0;
//! Get input ready event type
/*!
Returns the input ready event type. A stream sends this event
when \c read() will return with data.
*/
virtual CEvent::Type getInputReadyEvent();
//! Get output flushed event type
/*!
Returns the output flushed event type. A stream sends this event
when the output buffer has been flushed. If there have been no
writes since the event was posted, calling \c shutdownOutput() or
\c close() will not discard any data and \c flush() will return
immediately.
*/
virtual CEvent::Type getOutputFlushedEvent();
//! Get output error event type
/*!
Returns the output error event type. A stream sends this event
when a write has failed.
*/
virtual CEvent::Type getOutputErrorEvent();
//! Get input shutdown event type
/*!
Returns the input shutdown event type. This is sent when the
input side of the stream has shutdown. When the input has
shutdown, no more data will ever be available to read.
*/
virtual CEvent::Type getInputShutdownEvent();
//! Get output shutdown event type
/*!
Returns the output shutdown event type. This is sent when the
output side of the stream has shutdown. When the output has
shutdown, no more data can ever be written to the stream. Any
attempt to do so will generate a output error event.
*/
virtual CEvent::Type getOutputShutdownEvent();
//! Get the event queue
IEventQueue& getEventQueue() const;
//@}
private:
static CEvent::Type s_inputReadyEvent;
static CEvent::Type s_outputFlushedEvent;
static CEvent::Type s_outputErrorEvent;
static CEvent::Type s_inputShutdownEvent;
static CEvent::Type s_outputShutdownEvent;
IEventQueue* m_eventQueue;
IEventQueue* m_events;
};
}

View File

@ -22,19 +22,24 @@
#include "TMethodEventJob.h"
#include "CIpcMessage.h"
CEvent::Type CIpcClient::s_connectedEvent = CEvent::kUnknown;
CEvent::Type CIpcClient::s_messageReceivedEvent = CEvent::kUnknown;
//
// CIpcClient
//
CIpcClient::CIpcClient() :
m_serverAddress(CNetworkAddress(IPC_HOST, IPC_PORT)),
m_server(nullptr)
CIpcClient::CIpcClient(IEventQueue* events) :
m_serverAddress(CNetworkAddress(IPC_HOST, IPC_PORT)),
m_server(nullptr),
m_socket(events),
m_events(events)
{
init();
}
CIpcClient::CIpcClient(int port) :
m_serverAddress(CNetworkAddress(IPC_HOST, port)),
m_server(nullptr)
CIpcClient::CIpcClient(IEventQueue* events, int port) :
m_serverAddress(CNetworkAddress(IPC_HOST, port)),
m_server(nullptr),
m_socket(events),
m_events(events)
{
init();
}
@ -52,16 +57,16 @@ CIpcClient::~CIpcClient()
void
CIpcClient::connect()
{
EVENTQUEUE->adoptHandler(
IDataSocket::getConnectedEvent(), m_socket.getEventTarget(),
m_events->adoptHandler(
m_events->forIDataSocket().connected(), m_socket.getEventTarget(),
new TMethodEventJob<CIpcClient>(
this, &CIpcClient::handleConnected));
m_socket.connect(m_serverAddress);
m_server = new CIpcServerProxy(m_socket);
m_server = new CIpcServerProxy(m_socket, m_events);
EVENTQUEUE->adoptHandler(
CIpcServerProxy::getMessageReceivedEvent(), m_server,
m_events->adoptHandler(
m_events->forCIpcServerProxy().messageReceived(), m_server,
new TMethodEventJob<CIpcClient>(
this, &CIpcClient::handleMessageReceived));
}
@ -69,8 +74,8 @@ CIpcClient::connect()
void
CIpcClient::disconnect()
{
EVENTQUEUE->removeHandler(IDataSocket::getConnectedEvent(), m_socket.getEventTarget());
EVENTQUEUE->removeHandler(CIpcServerProxy::getMessageReceivedEvent(), m_server);
m_events->removeHandler(m_events->forIDataSocket().connected(), m_socket.getEventTarget());
m_events->removeHandler(m_events->forCIpcServerProxy().messageReceived(), m_server);
m_server->disconnect();
delete m_server;
@ -84,25 +89,11 @@ CIpcClient::send(const CIpcMessage& message)
m_server->send(message);
}
CEvent::Type
CIpcClient::getConnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(
s_connectedEvent, "CIpcClient::connected");
}
CEvent::Type
CIpcClient::getMessageReceivedEvent()
{
return EVENTQUEUE->registerTypeOnce(
s_messageReceivedEvent, "CIpcClient::messageReceived");
}
void
CIpcClient::handleConnected(const CEvent&, void*)
{
EVENTQUEUE->addEvent(CEvent(
getConnectedEvent(), this, m_server, CEvent::kDontFreeData));
m_events->addEvent(CEvent(
m_events->forCIpcClient().connected(), this, m_server, CEvent::kDontFreeData));
CIpcHelloMessage message(kIpcClientNode);
send(message);
@ -111,7 +102,7 @@ CIpcClient::handleConnected(const CEvent&, void*)
void
CIpcClient::handleMessageReceived(const CEvent& e, void*)
{
CEvent event(getMessageReceivedEvent(), this);
CEvent event(m_events->forCIpcClient().messageReceived(), this);
event.setDataObject(e.getDataObject());
EVENTQUEUE->addEvent(event);
m_events->addEvent(event);
}

View File

@ -20,9 +20,11 @@
#include "CNetworkAddress.h"
#include "CTCPSocket.h"
#include "CEventTypes.h"
class CIpcServerProxy;
class CIpcMessage;
class IEventQueue;
//! IPC client for communication between daemon and GUI.
/*!
@ -30,8 +32,8 @@ class CIpcMessage;
*/
class CIpcClient {
public:
CIpcClient();
CIpcClient(int port);
CIpcClient(IEventQueue* events);
CIpcClient(IEventQueue* events, int port);
virtual ~CIpcClient();
//! @name manipulators
@ -47,14 +49,6 @@ public:
void send(const CIpcMessage& message);
//@}
//! @name accessors
//@{
//! Raised when the socket is connected.
static CEvent::Type getConnectedEvent();
static CEvent::Type getMessageReceivedEvent();
//@}
private:
void init();
@ -65,7 +59,5 @@ private:
CNetworkAddress m_serverAddress;
CTCPSocket m_socket;
CIpcServerProxy* m_server;
static CEvent::Type s_connectedEvent;
static CEvent::Type s_messageReceivedEvent;
IEventQueue* m_events;
};

View File

@ -25,47 +25,49 @@
#include "CProtocolUtil.h"
#include "CArch.h"
CEvent::Type CIpcClientProxy::s_messageReceivedEvent = CEvent::kUnknown;
CEvent::Type CIpcClientProxy::s_disconnectedEvent = CEvent::kUnknown;
//
// CIpcClientProxy
//
CIpcClientProxy::CIpcClientProxy(synergy::IStream& stream) :
m_stream(stream),
m_clientType(kIpcClientUnknown),
m_disconnecting(false),
m_readMutex(ARCH->newMutex()),
m_writeMutex(ARCH->newMutex())
CIpcClientProxy::CIpcClientProxy(synergy::IStream& stream, IEventQueue* events) :
m_stream(stream),
m_clientType(kIpcClientUnknown),
m_disconnecting(false),
m_readMutex(ARCH->newMutex()),
m_writeMutex(ARCH->newMutex()),
m_events(events)
{
EVENTQUEUE->adoptHandler(
m_stream.getInputReadyEvent(), stream.getEventTarget(),
m_events->adoptHandler(
m_events->forIStream().inputReady(), stream.getEventTarget(),
new TMethodEventJob<CIpcClientProxy>(
this, &CIpcClientProxy::handleData));
EVENTQUEUE->adoptHandler(
m_stream.getOutputErrorEvent(), stream.getEventTarget(),
m_events->adoptHandler(
m_events->forIStream().outputError(), stream.getEventTarget(),
new TMethodEventJob<CIpcClientProxy>(
this, &CIpcClientProxy::handleWriteError));
EVENTQUEUE->adoptHandler(
m_stream.getInputShutdownEvent(), stream.getEventTarget(),
m_events->adoptHandler(
m_events->forIStream().inputShutdown(), stream.getEventTarget(),
new TMethodEventJob<CIpcClientProxy>(
this, &CIpcClientProxy::handleDisconnect));
EVENTQUEUE->adoptHandler(
m_stream.getOutputShutdownEvent(), stream.getEventTarget(),
m_events->adoptHandler(
m_events->forIStream().outputShutdown(), stream.getEventTarget(),
new TMethodEventJob<CIpcClientProxy>(
this, &CIpcClientProxy::handleWriteError));
}
CIpcClientProxy::~CIpcClientProxy()
{
EVENTQUEUE->removeHandler(
m_stream.getInputReadyEvent(), m_stream.getEventTarget());
EVENTQUEUE->removeHandler(
m_stream.getOutputErrorEvent(), m_stream.getEventTarget());
EVENTQUEUE->removeHandler(
m_stream.getInputShutdownEvent(), m_stream.getEventTarget());
EVENTQUEUE->removeHandler(
m_stream.getOutputShutdownEvent(), m_stream.getEventTarget());
m_events->removeHandler(
m_events->forIStream().inputReady(), m_stream.getEventTarget());
m_events->removeHandler(
m_events->forIStream().outputError(), m_stream.getEventTarget());
m_events->removeHandler(
m_events->forIStream().inputShutdown(), m_stream.getEventTarget());
m_events->removeHandler(
m_events->forIStream().outputShutdown(), m_stream.getEventTarget());
// don't delete the stream while it's being used.
ARCH->lockMutex(m_readMutex);
@ -120,9 +122,9 @@ CIpcClientProxy::handleData(const CEvent&, void*)
}
// don't delete with this event; the data is passed to a new event.
CEvent e(getMessageReceivedEvent(), this, NULL, CEvent::kDontFreeData);
CEvent e(m_events->forCIpcClientProxy().messageReceived(), this, NULL, CEvent::kDontFreeData);
e.setDataObject(m);
EVENTQUEUE->addEvent(e);
m_events->addEvent(e);
n = m_stream.read(code, 4);
}
@ -187,19 +189,5 @@ CIpcClientProxy::disconnect()
LOG((CLOG_DEBUG "ipc disconnect, closing stream"));
m_disconnecting = true;
m_stream.close();
EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), this));
}
CEvent::Type
CIpcClientProxy::getMessageReceivedEvent()
{
return EVENTQUEUE->registerTypeOnce(
s_messageReceivedEvent, "CIpcClientProxy::messageReceived");
}
CEvent::Type
CIpcClientProxy::getDisconnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(
s_disconnectedEvent, "CIpcClientProxy::disconnected");
m_events->addEvent(CEvent(m_events->forCIpcClientProxy().disconnected(), this));
}

View File

@ -21,29 +21,23 @@
#include "CEvent.h"
#include "Ipc.h"
#include "IArchMultithread.h"
#include "CEventTypes.h"
namespace synergy { class IStream; }
class CIpcMessage;
class CIpcCommandMessage;
class CIpcHelloMessage;
class IEventQueue;
class CIpcClientProxy {
friend class CIpcServer;
public:
CIpcClientProxy(synergy::IStream& stream);
CIpcClientProxy(synergy::IStream& stream, IEventQueue* events);
virtual ~CIpcClientProxy();
private:
//! Send a message to the client.
void send(const CIpcMessage& message);
//! Raised when the server receives a message from a client.
static CEvent::Type getMessageReceivedEvent();
//! Raised when the client disconnects from the server.
static CEvent::Type getDisconnectedEvent();
void handleData(const CEvent&, void*);
void handleDisconnect(const CEvent&, void*);
void handleWriteError(const CEvent&, void*);
@ -57,7 +51,5 @@ private:
bool m_disconnecting;
CArchMutex m_readMutex;
CArchMutex m_writeMutex;
static CEvent::Type s_messageReceivedEvent;
static CEvent::Type s_disconnectedEvent;
IEventQueue* m_events;
};

View File

@ -27,17 +27,22 @@
#include "IDataSocket.h"
#include "CIpcMessage.h"
CEvent::Type CIpcServer::s_clientConnectedEvent = CEvent::kUnknown;
CEvent::Type CIpcServer::s_messageReceivedEvent = CEvent::kUnknown;
//
// CIpcServer
//
CIpcServer::CIpcServer() :
m_address(CNetworkAddress(IPC_HOST, IPC_PORT))
CIpcServer::CIpcServer(IEventQueue* events) :
m_events(events),
m_socket(events),
m_address(CNetworkAddress(IPC_HOST, IPC_PORT))
{
init();
}
CIpcServer::CIpcServer(int port) :
m_address(CNetworkAddress(IPC_HOST, port))
CIpcServer::CIpcServer(IEventQueue* events, int port) :
m_events(events),
m_socket(events),
m_address(CNetworkAddress(IPC_HOST, port))
{
init();
}
@ -48,8 +53,8 @@ CIpcServer::init()
m_clientsMutex = ARCH->newMutex();
m_address.resolve();
EVENTQUEUE->adoptHandler(
IListenSocket::getConnectingEvent(), &m_socket,
m_events->adoptHandler(
m_events->forIListenSocket().connecting(), &m_socket,
new TMethodEventJob<CIpcServer>(
this, &CIpcServer::handleClientConnecting));
}
@ -65,7 +70,7 @@ CIpcServer::~CIpcServer()
ARCH->unlockMutex(m_clientsMutex);
ARCH->closeMutex(m_clientsMutex);
EVENTQUEUE->removeHandler(m_socket.getConnectingEvent(), &m_socket);
m_events->removeHandler(m_events->forIListenSocket().connecting(), &m_socket);
}
void
@ -85,22 +90,22 @@ CIpcServer::handleClientConnecting(const CEvent&, void*)
LOG((CLOG_DEBUG "accepted ipc client connection"));
ARCH->lockMutex(m_clientsMutex);
CIpcClientProxy* proxy = new CIpcClientProxy(*stream);
CIpcClientProxy* proxy = new CIpcClientProxy(*stream, m_events);
m_clients.push_back(proxy);
ARCH->unlockMutex(m_clientsMutex);
EVENTQUEUE->adoptHandler(
CIpcClientProxy::getDisconnectedEvent(), proxy,
m_events->adoptHandler(
m_events->forCIpcClientProxy().disconnected(), proxy,
new TMethodEventJob<CIpcServer>(
this, &CIpcServer::handleClientDisconnected));
EVENTQUEUE->adoptHandler(
CIpcClientProxy::getMessageReceivedEvent(), proxy,
m_events->adoptHandler(
m_events->forCIpcClientProxy().messageReceived(), proxy,
new TMethodEventJob<CIpcServer>(
this, &CIpcServer::handleMessageReceived));
EVENTQUEUE->addEvent(CEvent(
getClientConnectedEvent(), this, proxy, CEvent::kDontFreeData));
m_events->addEvent(CEvent(
m_events->forCIpcServer().clientConnected(), this, proxy, CEvent::kDontFreeData));
}
void
@ -118,16 +123,16 @@ CIpcServer::handleClientDisconnected(const CEvent& e, void*)
void
CIpcServer::handleMessageReceived(const CEvent& e, void*)
{
CEvent event(getMessageReceivedEvent(), this);
CEvent event(m_events->forCIpcServer().messageReceived(), this);
event.setDataObject(e.getDataObject());
EVENTQUEUE->addEvent(event);
m_events->addEvent(event);
}
void
CIpcServer::deleteClient(CIpcClientProxy* proxy)
{
EVENTQUEUE->removeHandler(CIpcClientProxy::getMessageReceivedEvent(), proxy);
EVENTQUEUE->removeHandler(CIpcClientProxy::getDisconnectedEvent(), proxy);
m_events->removeHandler(m_events->forCIpcClientProxy().messageReceived(), proxy);
m_events->removeHandler(m_events->forCIpcClientProxy().disconnected(), proxy);
delete proxy;
}
@ -153,20 +158,6 @@ CIpcServer::hasClients(EIpcClientType clientType) const
return false;
}
CEvent::Type
CIpcServer::getClientConnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(
s_clientConnectedEvent, "CIpcServer::clientConnected");
}
CEvent::Type
CIpcServer::getMessageReceivedEvent()
{
return EVENTQUEUE->registerTypeOnce(
s_messageReceivedEvent, "CIpcServer::messageReceived");
}
void
CIpcServer::send(const CIpcMessage& message, EIpcClientType filterType)
{

View File

@ -23,10 +23,12 @@
#include "Ipc.h"
#include <list>
#include "CArch.h"
#include "CEventTypes.h"
class CEvent;
class CIpcClientProxy;
class CIpcMessage;
class IEventQueue;
//! IPC server for communication between daemon and GUI.
/*!
@ -37,8 +39,8 @@ and allows the daemon and client/server to send log data to the GUI.
*/
class CIpcServer {
public:
CIpcServer();
CIpcServer(int port);
CIpcServer(IEventQueue* events);
CIpcServer(IEventQueue* events, int port);
virtual ~CIpcServer();
//! @name manipulators
@ -57,12 +59,6 @@ public:
//! Returns true when there are clients of the specified type connected.
bool hasClients(EIpcClientType clientType) const;
//! Raised when we have created the client proxy.
static CEvent::Type getClientConnectedEvent();
//! Raised when a message is received through a client proxy.
static CEvent::Type getMessageReceivedEvent();
//@}
private:
@ -79,7 +75,5 @@ private:
CNetworkAddress m_address;
CClientList m_clients;
CArchMutex m_clientsMutex;
static CEvent::Type s_clientConnectedEvent;
static CEvent::Type s_messageReceivedEvent;
IEventQueue* m_events;
};

View File

@ -24,12 +24,15 @@
#include "Ipc.h"
#include "CProtocolUtil.h"
CEvent::Type CIpcServerProxy::s_messageReceivedEvent = CEvent::kUnknown;
//
// CIpcServerProxy
//
CIpcServerProxy::CIpcServerProxy(synergy::IStream& stream) :
m_stream(stream)
CIpcServerProxy::CIpcServerProxy(synergy::IStream& stream, IEventQueue* events) :
m_events(events),
m_stream(stream)
{
EVENTQUEUE->adoptHandler(m_stream.getInputReadyEvent(),
m_events->adoptHandler(m_events->forIStream().inputReady(),
stream.getEventTarget(),
new TMethodEventJob<CIpcServerProxy>(
this, &CIpcServerProxy::handleData));
@ -37,7 +40,7 @@ m_stream(stream)
CIpcServerProxy::~CIpcServerProxy()
{
EVENTQUEUE->removeHandler(m_stream.getInputReadyEvent(),
m_events->removeHandler(m_events->forIStream().inputReady(),
m_stream.getEventTarget());
}
@ -66,9 +69,9 @@ CIpcServerProxy::handleData(const CEvent&, void*)
}
// don't delete with this event; the data is passed to a new event.
CEvent e(getMessageReceivedEvent(), this, NULL, CEvent::kDontFreeData);
CEvent e(m_events->forCIpcServerProxy().messageReceived(), this, NULL, CEvent::kDontFreeData);
e.setDataObject(m);
EVENTQUEUE->addEvent(e);
m_events->addEvent(e);
n = m_stream.read(code, 4);
}
@ -117,10 +120,3 @@ CIpcServerProxy::disconnect()
LOG((CLOG_DEBUG "ipc disconnect, closing stream"));
m_stream.close();
}
CEvent::Type
CIpcServerProxy::getMessageReceivedEvent()
{
return EVENTQUEUE->registerTypeOnce(
s_messageReceivedEvent, "CIpcServerProxy::messageReceived");
}

View File

@ -19,16 +19,18 @@
#pragma once
#include "CEvent.h"
#include "CEventTypes.h"
namespace synergy { class IStream; }
class CIpcMessage;
class CIpcLogLineMessage;
class IEventQueue;
class CIpcServerProxy {
friend class CIpcClient;
public:
CIpcServerProxy(synergy::IStream& stream);
CIpcServerProxy(synergy::IStream& stream, IEventQueue* events);
virtual ~CIpcServerProxy();
private:
@ -38,11 +40,7 @@ private:
CIpcLogLineMessage* parseLogLine();
void disconnect();
//! Raised when the client receives a message from the server.
static CEvent::Type getMessageReceivedEvent();
private:
synergy::IStream& m_stream;
static CEvent::Type s_messageReceivedEvent;
IEventQueue* m_events;
};

View File

@ -36,8 +36,6 @@ set(src
CTCPSocket.cpp
CTCPSocketFactory.cpp
IDataSocket.cpp
IListenSocket.cpp
ISocket.cpp
XSocket.cpp
)

View File

@ -33,7 +33,8 @@
// CTCPListenSocket
//
CTCPListenSocket::CTCPListenSocket()
CTCPListenSocket::CTCPListenSocket(IEventQueue* events) :
m_events(events)
{
m_mutex = new CMutex;
try {
@ -107,7 +108,7 @@ CTCPListenSocket::accept()
{
IDataSocket* socket = NULL;
try {
socket = new CTCPSocket(ARCH->acceptSocket(m_socket, NULL));
socket = new CTCPSocket(m_events, ARCH->acceptSocket(m_socket, NULL));
if (socket != NULL) {
CSocketMultiplexer::getInstance()->addSocket(this,
new TSocketMultiplexerMethodJob<CTCPListenSocket>(
@ -139,7 +140,7 @@ CTCPListenSocket::serviceListening(ISocketMultiplexerJob* job,
return NULL;
}
if (read) {
EVENTQUEUE->addEvent(CEvent(getConnectingEvent(), this, NULL));
m_events->addEvent(CEvent(m_events->forIListenSocket().connecting(), this, NULL));
// stop polling on this socket until the client accepts
return NULL;
}

View File

@ -24,6 +24,7 @@
class CMutex;
class ISocketMultiplexerJob;
class IEventQueue;
//! TCP listen socket
/*!
@ -31,7 +32,7 @@ A listen socket using TCP.
*/
class CTCPListenSocket : public IListenSocket {
public:
CTCPListenSocket();
CTCPListenSocket(IEventQueue* events);
~CTCPListenSocket();
// ISocket overrides
@ -50,6 +51,7 @@ private:
private:
CArchSocket m_socket;
CMutex* m_mutex;
IEventQueue* m_events;
};
#endif

View File

@ -35,7 +35,9 @@
// CTCPSocket
//
CTCPSocket::CTCPSocket() :
CTCPSocket::CTCPSocket(IEventQueue* events) :
IDataSocket(events),
m_events(events),
m_mutex(),
m_flushed(&m_mutex, true)
{
@ -49,7 +51,9 @@ CTCPSocket::CTCPSocket() :
init();
}
CTCPSocket::CTCPSocket(CArchSocket socket) :
CTCPSocket::CTCPSocket(IEventQueue* events, CArchSocket socket) :
IDataSocket(events),
m_events(events),
m_mutex(),
m_socket(socket),
m_flushed(&m_mutex, true)
@ -96,7 +100,7 @@ CTCPSocket::close()
// clear buffers and enter disconnected state
if (m_connected) {
sendEvent(getDisconnectedEvent());
sendEvent(m_events->forISocket().disconnected());
}
onDisconnected();
@ -136,7 +140,7 @@ CTCPSocket::read(void* buffer, UInt32 n)
// if no more data and we cannot read or write then send disconnected
if (n > 0 && m_inputBuffer.getSize() == 0 && !m_readable && !m_writable) {
sendEvent(getDisconnectedEvent());
sendEvent(m_events->forISocket().disconnected());
m_connected = false;
}
@ -152,7 +156,7 @@ CTCPSocket::write(const void* buffer, UInt32 n)
// must not have shutdown output
if (!m_writable) {
sendEvent(getOutputErrorEvent());
sendEvent(m_events->forIStream().outputError());
return;
}
@ -201,7 +205,7 @@ CTCPSocket::shutdownInput()
// shutdown buffer for reading
if (m_readable) {
sendEvent(getInputShutdownEvent());
sendEvent(m_events->forIStream().inputShutdown());
onInputShutdown();
useNewJob = true;
}
@ -228,7 +232,7 @@ CTCPSocket::shutdownOutput()
// shutdown buffer for writing
if (m_writable) {
sendEvent(getOutputShutdownEvent());
sendEvent(m_events->forIStream().outputShutdown());
onOutputShutdown();
useNewJob = true;
}
@ -266,7 +270,7 @@ CTCPSocket::connect(const CNetworkAddress& addr)
try {
if (ARCH->connectSocket(m_socket, addr.getAddress())) {
sendEvent(getConnectedEvent());
sendEvent(m_events->forIDataSocket().connected());
onConnected();
}
else {
@ -351,14 +355,14 @@ void
CTCPSocket::sendConnectionFailedEvent(const char* msg)
{
CConnectionFailedInfo* info = new CConnectionFailedInfo(msg);
EVENTQUEUE->addEvent(CEvent(getConnectionFailedEvent(),
m_events->addEvent(CEvent(m_events->forIDataSocket().connectionFailed(),
getEventTarget(), info, CEvent::kDontFreeData));
}
void
CTCPSocket::sendEvent(CEvent::Type type)
{
EVENTQUEUE->addEvent(CEvent(type, getEventTarget(), NULL));
m_events->addEvent(CEvent(type, getEventTarget(), NULL));
}
void
@ -432,7 +436,7 @@ CTCPSocket::serviceConnecting(ISocketMultiplexerJob* job,
}
if (write) {
sendEvent(getConnectedEvent());
sendEvent(m_events->forIDataSocket().connected());
onConnected();
return newJob();
}
@ -447,7 +451,7 @@ CTCPSocket::serviceConnected(ISocketMultiplexerJob* job,
CLock lock(&m_mutex);
if (error) {
sendEvent(getDisconnectedEvent());
sendEvent(m_events->forISocket().disconnected());
onDisconnected();
return newJob();
}
@ -465,7 +469,7 @@ CTCPSocket::serviceConnected(ISocketMultiplexerJob* job,
if (n > 0) {
m_outputBuffer.pop(n);
if (m_outputBuffer.getSize() == 0) {
sendEvent(getOutputFlushedEvent());
sendEvent(m_events->forIStream().outputFlushed());
m_flushed = true;
m_flushed.broadcast();
needNewJob = true;
@ -476,9 +480,9 @@ CTCPSocket::serviceConnected(ISocketMultiplexerJob* job,
// remote read end of stream hungup. our output side
// has therefore shutdown.
onOutputShutdown();
sendEvent(getOutputShutdownEvent());
sendEvent(m_events->forIStream().outputShutdown());
if (!m_readable && m_inputBuffer.getSize() == 0) {
sendEvent(getDisconnectedEvent());
sendEvent(m_events->forISocket().disconnected());
m_connected = false;
}
needNewJob = true;
@ -486,15 +490,15 @@ CTCPSocket::serviceConnected(ISocketMultiplexerJob* job,
catch (XArchNetworkDisconnected&) {
// stream hungup
onDisconnected();
sendEvent(getDisconnectedEvent());
sendEvent(m_events->forISocket().disconnected());
needNewJob = true;
}
catch (XArchNetwork& e) {
// other write error
LOG((CLOG_WARN "error writing socket: %s", e.what().c_str()));
onDisconnected();
sendEvent(getOutputErrorEvent());
sendEvent(getDisconnectedEvent());
sendEvent(m_events->forIStream().outputError());
sendEvent(m_events->forISocket().disconnected());
needNewJob = true;
}
}
@ -514,16 +518,16 @@ CTCPSocket::serviceConnected(ISocketMultiplexerJob* job,
// send input ready if input buffer was empty
if (wasEmpty) {
sendEvent(getInputReadyEvent());
sendEvent(m_events->forIStream().inputReady());
}
}
else {
// remote write end of stream hungup. our input side
// has therefore shutdown but don't flush our buffer
// since there's still data to be read.
sendEvent(getInputShutdownEvent());
sendEvent(m_events->forIStream().inputShutdown());
if (!m_writable && m_inputBuffer.getSize() == 0) {
sendEvent(getDisconnectedEvent());
sendEvent(m_events->forISocket().disconnected());
m_connected = false;
}
m_readable = false;
@ -532,7 +536,7 @@ CTCPSocket::serviceConnected(ISocketMultiplexerJob* job,
}
catch (XArchNetworkDisconnected&) {
// stream hungup
sendEvent(getDisconnectedEvent());
sendEvent(m_events->forISocket().disconnected());
onDisconnected();
needNewJob = true;
}

View File

@ -28,6 +28,7 @@
class CMutex;
class CThread;
class ISocketMultiplexerJob;
class IEventQueue;
//! TCP data socket
/*!
@ -35,8 +36,8 @@ A data socket using TCP.
*/
class CTCPSocket : public IDataSocket {
public:
CTCPSocket();
CTCPSocket(CArchSocket);
CTCPSocket(IEventQueue* events);
CTCPSocket(IEventQueue* events, CArchSocket socket);
~CTCPSocket();
// ISocket overrides
@ -85,6 +86,7 @@ private:
bool m_connected;
bool m_readable;
bool m_writable;
IEventQueue* m_events;
};
#endif

View File

@ -24,7 +24,8 @@
// CTCPSocketFactory
//
CTCPSocketFactory::CTCPSocketFactory()
CTCPSocketFactory::CTCPSocketFactory(IEventQueue* events) :
m_events(events)
{
// do nothing
}
@ -37,11 +38,11 @@ CTCPSocketFactory::~CTCPSocketFactory()
IDataSocket*
CTCPSocketFactory::create() const
{
return new CTCPSocket;
return new CTCPSocket(m_events);
}
IListenSocket*
CTCPSocketFactory::createListen() const
{
return new CTCPListenSocket;
return new CTCPListenSocket(m_events);
}

View File

@ -21,15 +21,20 @@
#include "ISocketFactory.h"
class IEventQueue;
//! Socket factory for TCP sockets
class CTCPSocketFactory : public ISocketFactory {
public:
CTCPSocketFactory();
CTCPSocketFactory(IEventQueue* events);
virtual ~CTCPSocketFactory();
// ISocketFactory overrides
virtual IDataSocket* create() const;
virtual IListenSocket* createListen() const;
private:
IEventQueue* m_events;
};
#endif

View File

@ -23,23 +23,6 @@
// IDataSocket
//
CEvent::Type IDataSocket::s_connectedEvent = CEvent::kUnknown;
CEvent::Type IDataSocket::s_failedEvent = CEvent::kUnknown;
CEvent::Type
IDataSocket::getConnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_connectedEvent,
"IDataSocket::connected");
}
CEvent::Type
IDataSocket::getConnectionFailedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_failedEvent,
"IDataSocket::failed");
}
void
IDataSocket::close()
{

View File

@ -22,6 +22,7 @@
#include "ISocket.h"
#include "IStream.h"
#include "CString.h"
#include "CEventTypes.h"
//! Data stream socket interface
/*!
@ -36,6 +37,8 @@ public:
CString m_what;
};
IDataSocket(IEventQueue* events) : IStream(events) { }
//! @name manipulators
//@{
@ -48,25 +51,6 @@ public:
*/
virtual void connect(const CNetworkAddress&) = 0;
//@}
//! @name accessors
//@{
//! Get connected event type
/*!
Returns the socket connected event type. A socket sends this
event when a remote connection has been established.
*/
static CEvent::Type getConnectedEvent();
//! Get connection failed event type
/*!
Returns the socket connection failed event type. A socket sends
this event when an attempt to connect to a remote port has failed.
The data is a pointer to a CConnectionFailedInfo.
*/
static CEvent::Type getConnectionFailedEvent();
//@}
// ISocket overrides
@ -86,10 +70,6 @@ public:
virtual void shutdownOutput() = 0;
virtual bool isReady() const = 0;
virtual UInt32 getSize() const = 0;
private:
static CEvent::Type s_connectedEvent;
static CEvent::Type s_failedEvent;
};
#endif

View File

@ -1,33 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Bolton Software Ltd.
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "IListenSocket.h"
#include "CEventQueue.h"
//
// IListenSocket
//
CEvent::Type IListenSocket::s_connectingEvent = CEvent::kUnknown;
CEvent::Type
IListenSocket::getConnectingEvent()
{
return EVENTQUEUE->registerTypeOnce(s_connectingEvent,
"IListenSocket::connecting");
}

View File

@ -20,6 +20,7 @@
#define ILISTENSOCKET_H
#include "ISocket.h"
#include "CEventTypes.h"
class IDataSocket;
@ -41,26 +42,12 @@ public:
*/
virtual IDataSocket* accept() = 0;
//@}
//! @name accessors
//@{
//! Get connecting event type
/*!
Returns the socket connecting event type. A socket sends this
event when a remote connection is waiting to be accepted.
*/
static CEvent::Type getConnectingEvent();
//@}
// ISocket overrides
virtual void bind(const CNetworkAddress&) = 0;
virtual void close() = 0;
virtual void* getEventTarget() const = 0;
private:
static CEvent::Type s_connectingEvent;
};
#endif

View File

@ -1,33 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Bolton Software Ltd.
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ISocket.h"
#include "CEventQueue.h"
//
// ISocket
//
CEvent::Type ISocket::s_disconnectedEvent = CEvent::kUnknown;
CEvent::Type
ISocket::getDisconnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_disconnectedEvent,
"ISocket::disconnected");
}

View File

@ -21,6 +21,7 @@
#include "IInterface.h"
#include "CEvent.h"
#include "CEventTypes.h"
class CNetworkAddress;
@ -56,18 +57,7 @@ public:
*/
virtual void* getEventTarget() const = 0;
//! Get disconnected event type
/*!
Returns the socket disconnected event type. A socket sends this
event when the remote side of the socket has disconnected or
shutdown both input and output.
*/
static CEvent::Type getDisconnectedEvent();
//@}
private:
static CEvent::Type s_disconnectedEvent;
};
#endif

View File

@ -92,7 +92,7 @@
CMSWindowsDesks::CMSWindowsDesks(
bool isPrimary, bool noHooks, HINSTANCE hookLibrary,
const IScreenSaver* screensaver, IEventQueue& eventQueue,
const IScreenSaver* screensaver, IEventQueue* events,
IJob* updateKeys, bool stopOnDeskSwitch) :
m_isPrimary(isPrimary),
m_noHooks(noHooks),
@ -111,7 +111,7 @@ CMSWindowsDesks::CMSWindowsDesks(
m_mutex(),
m_deskReady(&m_mutex, false),
m_updateKeys(updateKeys),
m_eventQueue(eventQueue),
m_events(events),
m_stopOnDeskSwitch(stopOnDeskSwitch)
{
if (hookLibrary != NULL)
@ -143,8 +143,8 @@ CMSWindowsDesks::enable()
// which desk is active and reinstalls the hooks as necessary.
// we wouldn't need this if windows notified us of a desktop
// change but as far as i can tell it doesn't.
m_timer = m_eventQueue.newTimer(0.2, NULL);
m_eventQueue.adoptHandler(CEvent::kTimer, m_timer,
m_timer = m_events->newTimer(0.2, NULL);
m_events->adoptHandler(CEvent::kTimer, m_timer,
new TMethodEventJob<CMSWindowsDesks>(
this, &CMSWindowsDesks::handleCheckDesk));
@ -156,8 +156,8 @@ CMSWindowsDesks::disable()
{
// remove timer
if (m_timer != NULL) {
m_eventQueue.removeHandler(CEvent::kTimer, m_timer);
m_eventQueue.deleteTimer(m_timer);
m_events->removeHandler(CEvent::kTimer, m_timer);
m_events->deleteTimer(m_timer);
m_timer = NULL;
}
@ -912,7 +912,7 @@ CMSWindowsDesks::checkDesk()
// first switch, then shut down.
if (m_stopOnDeskSwitch && m_activeDesk != NULL && name != m_activeDeskName) {
LOG((CLOG_DEBUG "shutting down because of desk switch to \"%s\"", name.c_str()));
EVENTQUEUE->addEvent(CEvent(CEvent::kQuit));
m_events->addEvent(CEvent(CEvent::kQuit));
return;
}

View File

@ -66,7 +66,7 @@ public:
*/
CMSWindowsDesks(
bool isPrimary, bool noHooks, HINSTANCE hookLibrary,
const IScreenSaver* screensaver, IEventQueue& eventQueue,
const IScreenSaver* screensaver, IEventQueue* events,
IJob* updateKeys, bool stopOnDeskSwitch);
~CMSWindowsDesks();
@ -305,7 +305,7 @@ private:
// options
bool m_leaveForegroundOption;
IEventQueue& m_eventQueue;
IEventQueue* m_events;
// true if program should stop on desk switch.
bool m_stopOnDeskSwitch;

View File

@ -32,7 +32,8 @@ class CEventQueueTimer { };
// CMSWindowsEventQueueBuffer
//
CMSWindowsEventQueueBuffer::CMSWindowsEventQueueBuffer()
CMSWindowsEventQueueBuffer::CMSWindowsEventQueueBuffer(IEventQueue* events) :
m_events(events)
{
// remember thread. we'll be posting messages to it.
m_thread = GetCurrentThreadId();
@ -111,7 +112,7 @@ CMSWindowsEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
}
else {
event = CEvent(CEvent::kSystem,
IEventQueue::getSystemTarget(), &m_event);
m_events->getSystemTarget(), &m_event);
return kSystem;
}
}

View File

@ -23,10 +23,12 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
class IEventQueue;
//! Event queue buffer for Win32
class CMSWindowsEventQueueBuffer : public IEventQueueBuffer {
public:
CMSWindowsEventQueueBuffer();
CMSWindowsEventQueueBuffer(IEventQueue* events);
virtual ~CMSWindowsEventQueueBuffer();
// IEventQueueBuffer overrides
@ -43,6 +45,7 @@ private:
UINT m_userEvent;
MSG m_event;
UINT m_daemonQuit;
IEventQueue* m_events;
};
#endif

View File

@ -576,7 +576,8 @@ static const CWin32Modifiers s_modifiers[] =
};
CMSWindowsKeyState::CMSWindowsKeyState(
CMSWindowsDesks* desks, void* eventTarget) :
CMSWindowsDesks* desks, void* eventTarget, IEventQueue* events) :
CKeyState(events),
m_is95Family(CArchMiscWindows::isWindows95Family()),
m_eventTarget(eventTarget),
m_desks(desks),
@ -586,14 +587,14 @@ CMSWindowsKeyState::CMSWindowsKeyState(
m_useSavedModifiers(false),
m_savedModifiers(0),
m_originalSavedModifiers(0),
m_eventQueue(*EVENTQUEUE)
m_events(events)
{
init();
}
CMSWindowsKeyState::CMSWindowsKeyState(
CMSWindowsDesks* desks, void* eventTarget, IEventQueue& eventQueue, CKeyMap& keyMap) :
CKeyState(eventQueue, keyMap),
CMSWindowsDesks* desks, void* eventTarget, IEventQueue* events, CKeyMap& keyMap) :
CKeyState(events, keyMap),
m_is95Family(CArchMiscWindows::isWindows95Family()),
m_eventTarget(eventTarget),
m_desks(desks),
@ -603,7 +604,7 @@ CMSWindowsKeyState::CMSWindowsKeyState(
m_useSavedModifiers(false),
m_savedModifiers(0),
m_originalSavedModifiers(0),
m_eventQueue(eventQueue)
m_events(events)
{
init();
}
@ -625,8 +626,8 @@ void
CMSWindowsKeyState::disable()
{
if (m_fixTimer != NULL) {
getEventQueue().removeHandler(CEvent::kTimer, m_fixTimer);
getEventQueue().deleteTimer(m_fixTimer);
m_events->removeHandler(CEvent::kTimer, m_fixTimer);
m_events->deleteTimer(m_fixTimer);
m_fixTimer = NULL;
}
m_lastDown = 0;
@ -1401,15 +1402,15 @@ CMSWindowsKeyState::fixKeys()
if (fix && m_fixTimer == NULL) {
// schedule check
m_fixTimer = EVENTQUEUE->newTimer(0.1, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
m_fixTimer = m_events->newTimer(0.1, NULL);
m_events->adoptHandler(CEvent::kTimer, m_fixTimer,
new TMethodEventJob<CMSWindowsKeyState>(
this, &CMSWindowsKeyState::handleFixKeys));
}
else if (!fix && m_fixTimer != NULL) {
// remove scheduled check
EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);
EVENTQUEUE->deleteTimer(m_fixTimer);
m_events->removeHandler(CEvent::kTimer, m_fixTimer);
m_events->deleteTimer(m_fixTimer);
m_fixTimer = NULL;
}
}

View File

@ -36,8 +36,8 @@ This class maps KeyIDs to keystrokes.
*/
class CMSWindowsKeyState : public CKeyState {
public:
CMSWindowsKeyState(CMSWindowsDesks* desks, void* eventTarget);
CMSWindowsKeyState(CMSWindowsDesks* desks, void* eventTarget, IEventQueue& eventQueue, CKeyMap& keyMap);
CMSWindowsKeyState(CMSWindowsDesks* desks, void* eventTarget, IEventQueue* events);
CMSWindowsKeyState(CMSWindowsDesks* desks, void* eventTarget, IEventQueue* events, CKeyMap& keyMap);
virtual ~CMSWindowsKeyState();
//! @name manipulators
@ -195,7 +195,7 @@ private:
UINT m_buttonToNumpadVK[512];
KeyButton m_virtualKeyToButton[256];
KeyToVKMap m_keyToVKMap;
IEventQueue& m_eventQueue;
IEventQueue* m_events;
// the timer used to check for fixing key state
CEventQueueTimer* m_fixTimer;

View File

@ -85,7 +85,9 @@ CMSWindowsScreen::CMSWindowsScreen(
bool isPrimary,
bool noHooks,
const CGameDeviceInfo& gameDeviceInfo,
bool stopOnDeskSwitch) :
bool stopOnDeskSwitch,
IEventQueue* events) :
CPlatformScreen(events),
m_isPrimary(isPrimary),
m_noHooks(noHooks),
m_is95Family(CArchMiscWindows::isWindows95Family()),
@ -113,7 +115,8 @@ CMSWindowsScreen::CMSWindowsScreen(
m_hasMouse(GetSystemMetrics(SM_MOUSEPRESENT) != 0),
m_showingMouse(false),
m_gameDeviceInfo(gameDeviceInfo),
m_gameDevice(NULL)
m_gameDevice(NULL),
m_events(events)
{
assert(s_windowInstance != NULL);
assert(s_screen == NULL);
@ -127,11 +130,11 @@ CMSWindowsScreen::CMSWindowsScreen(
m_desks = new CMSWindowsDesks(
m_isPrimary, m_noHooks,
m_hookLibrary, m_screensaver,
*EVENTQUEUE,
m_events,
new TMethodJob<CMSWindowsScreen>(this,
&CMSWindowsScreen::updateKeysCB),
stopOnDeskSwitch);
m_keyState = new CMSWindowsKeyState(m_desks, getEventTarget());
m_keyState = new CMSWindowsKeyState(m_desks, getEventTarget(), m_events);
updateScreenShape();
m_class = createWindowClass();
m_window = createWindow(m_class, "Synergy");
@ -154,12 +157,12 @@ CMSWindowsScreen::CMSWindowsScreen(
}
// install event handlers
EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(),
m_events->adoptHandler(CEvent::kSystem, m_events->getSystemTarget(),
new TMethodEventJob<CMSWindowsScreen>(this,
&CMSWindowsScreen::handleSystemEvent));
// install the platform event queue
EVENTQUEUE->adoptBuffer(new CMSWindowsEventQueueBuffer);
m_events->adoptBuffer(new CMSWindowsEventQueueBuffer(m_events));
if ((gameDeviceInfo.m_mode == CGameDeviceInfo::kGameModeXInput) &&
(gameDeviceInfo.m_poll != CGameDeviceInfo::kGamePollDynamic))
@ -186,8 +189,8 @@ CMSWindowsScreen::~CMSWindowsScreen()
assert(s_screen != NULL);
disable();
EVENTQUEUE->adoptBuffer(NULL);
EVENTQUEUE->removeHandler(CEvent::kSystem, IEventQueue::getSystemTarget());
m_events->adoptBuffer(NULL);
m_events->removeHandler(CEvent::kSystem, m_events->getSystemTarget());
delete m_keyState;
delete m_desks;
delete m_screensaver;
@ -224,8 +227,8 @@ CMSWindowsScreen::enable()
assert(m_isOnScreen == m_isPrimary);
// we need to poll some things to fix them
m_fixTimer = EVENTQUEUE->newTimer(1.0, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
m_fixTimer = m_events->newTimer(1.0, NULL);
m_events->adoptHandler(CEvent::kTimer, m_fixTimer,
new TMethodEventJob<CMSWindowsScreen>(this,
&CMSWindowsScreen::handleFixes));
@ -282,8 +285,8 @@ CMSWindowsScreen::disable()
// uninstall fix timer
if (m_fixTimer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);
EVENTQUEUE->deleteTimer(m_fixTimer);
m_events->removeHandler(CEvent::kTimer, m_fixTimer);
m_events->deleteTimer(m_fixTimer);
m_fixTimer = NULL;
}
@ -403,8 +406,8 @@ CMSWindowsScreen::checkClipboards()
if (m_ownClipboard && !CMSWindowsClipboard::isOwnedBySynergy()) {
LOG((CLOG_DEBUG "clipboard changed: lost ownership and no notification received"));
m_ownClipboard = false;
sendClipboardEvent(getClipboardGrabbedEvent(), kClipboardClipboard);
sendClipboardEvent(getClipboardGrabbedEvent(), kClipboardSelection);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection);
}
}
@ -905,7 +908,7 @@ CMSWindowsScreen::destroyWindow(HWND hwnd) const
void
CMSWindowsScreen::sendEvent(CEvent::Type type, void* data)
{
EVENTQUEUE->addEvent(CEvent(type, getEventTarget(), data));
m_events->addEvent(CEvent(type, getEventTarget(), data));
}
void
@ -1051,7 +1054,7 @@ CMSWindowsScreen::onEvent(HWND, UINT msg,
case WM_ENDSESSION:
if (m_is95Family) {
if (wParam == TRUE && lParam == 0) {
EVENTQUEUE->addEvent(CEvent(CEvent::kQuit));
m_events->addEvent(CEvent(CEvent::kQuit));
}
return true;
}
@ -1084,13 +1087,13 @@ CMSWindowsScreen::onEvent(HWND, UINT msg,
case PBT_APMRESUMEAUTOMATIC:
case PBT_APMRESUMECRITICAL:
case PBT_APMRESUMESUSPEND:
EVENTQUEUE->addEvent(CEvent(IScreen::getResumeEvent(),
m_events->addEvent(CEvent(m_events->forIScreen().resume(),
getEventTarget(), NULL,
CEvent::kDeliverImmediately));
break;
case PBT_APMSUSPEND:
EVENTQUEUE->addEvent(CEvent(IScreen::getSuspendEvent(),
m_events->addEvent(CEvent(m_events->forIScreen().suspend(),
getEventTarget(), NULL,
CEvent::kDeliverImmediately));
break;
@ -1296,14 +1299,14 @@ CMSWindowsScreen::onHotKey(WPARAM wParam, LPARAM lParam)
// ignore key repeats but it counts as a hot key
return true;
}
type = getHotKeyDownEvent();
type = m_events->forIPrimaryScreen().hotKeyDown();
}
else {
type = getHotKeyUpEvent();
type = m_events->forIPrimaryScreen().hotKeyUp();
}
// generate event
EVENTQUEUE->addEvent(CEvent(type, getEventTarget(),
m_events->addEvent(CEvent(type, getEventTarget(),
CHotKeyInfo::alloc(i->second)));
return true;
@ -1332,14 +1335,14 @@ CMSWindowsScreen::onMouseButton(WPARAM wParam, LPARAM lParam)
if (pressed) {
LOG((CLOG_DEBUG1 "event: button press button=%d", button));
if (button != kButtonNone) {
sendEvent(getButtonDownEvent(),
sendEvent(m_events->forIPrimaryScreen().buttonDown(),
CButtonInfo::alloc(button, mask));
}
}
else {
LOG((CLOG_DEBUG1 "event: button release button=%d", button));
if (button != kButtonNone) {
sendEvent(getButtonUpEvent(),
sendEvent(m_events->forIPrimaryScreen().buttonUp(),
CButtonInfo::alloc(button, mask));
}
}
@ -1381,7 +1384,7 @@ CMSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
// motion on primary screen
sendEvent(
getMotionOnPrimaryEvent(),
m_events->forIPrimaryScreen().motionOnPrimary(),
CMotionInfo::alloc(m_xCursor, m_yCursor));
}
else
@ -1408,7 +1411,7 @@ CMSWindowsScreen::onMouseMove(SInt32 mx, SInt32 my)
}
else {
// send motion
sendEvent(getMotionOnSecondaryEvent(), CMotionInfo::alloc(x, y));
sendEvent(m_events->forIPrimaryScreen().motionOnSecondary(), CMotionInfo::alloc(x, y));
}
}
@ -1421,7 +1424,7 @@ CMSWindowsScreen::onMouseWheel(SInt32 xDelta, SInt32 yDelta)
// ignore message if posted prior to last mark change
if (!ignore()) {
LOG((CLOG_DEBUG1 "event: button wheel delta=%+d,%+d", xDelta, yDelta));
sendEvent(getWheelEvent(), CWheelInfo::alloc(xDelta, yDelta));
sendEvent(m_events->forIPrimaryScreen().wheel(), CWheelInfo::alloc(xDelta, yDelta));
}
return true;
}
@ -1447,7 +1450,7 @@ CMSWindowsScreen::onScreensaver(bool activated)
if (!m_screensaverActive &&
m_screensaver->checkStarted(SYNERGY_MSG_SCREEN_SAVER, FALSE, 0)) {
m_screensaverActive = true;
sendEvent(getScreensaverActivatedEvent());
sendEvent(m_events->forIPrimaryScreen().screensaverActivated());
// enable display power down
CArchMiscWindows::removeBusyState(CArchMiscWindows::kDISPLAY);
@ -1456,7 +1459,7 @@ CMSWindowsScreen::onScreensaver(bool activated)
else {
if (m_screensaverActive) {
m_screensaverActive = false;
sendEvent(getScreensaverDeactivatedEvent());
sendEvent(m_events->forIPrimaryScreen().screensaverDeactivated());
// disable display power down
CArchMiscWindows::addBusyState(CArchMiscWindows::kDISPLAY);
@ -1492,7 +1495,7 @@ CMSWindowsScreen::onDisplayChange()
}
// send new screen info
sendEvent(getShapeChangedEvent());
sendEvent(m_events->forIScreen().shapeChanged());
LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_multimon ? "(multi-monitor)" : ""));
}
@ -1509,8 +1512,8 @@ CMSWindowsScreen::onClipboardChange()
if (m_ownClipboard) {
LOG((CLOG_DEBUG "clipboard changed: lost ownership"));
m_ownClipboard = false;
sendClipboardEvent(getClipboardGrabbedEvent(), kClipboardClipboard);
sendClipboardEvent(getClipboardGrabbedEvent(), kClipboardSelection);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection);
}
}
else if (!m_ownClipboard) {

View File

@ -45,7 +45,8 @@ public:
bool isPrimary,
bool noHooks,
const CGameDeviceInfo &gameDevice,
bool stopOnDeskSwitch);
bool stopOnDeskSwitch,
IEventQueue* events);
virtual ~CMSWindowsScreen();
//! @name manipulators
@ -215,6 +216,9 @@ private: // HACK
// our window proc
static LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
// save last position of mouse to compute next delta movement
void saveMousePosition(SInt32 x, SInt32 y);
private:
struct CHotKeyItem {
public:
@ -330,8 +334,7 @@ private:
static CMSWindowsScreen* s_screen;
// save last position of mouse to compute next delta movement
void saveMousePosition(SInt32 x, SInt32 y);
IEventQueue* m_events;
};
#endif

View File

@ -269,7 +269,7 @@ CMSWindowsXInput::xInputPollThread(void*)
LOG((CLOG_DEBUG "xinput buttons changed"));
// xinput buttons convert exactly to synergy buttons
m_screen->sendEvent(m_screen->getGameDeviceButtonsEvent(),
m_screen->sendEvent(m_events->forIScreen().gameDeviceButtons(),
new IPrimaryScreen::CGameDeviceButtonInfo(index, state.Gamepad.wButtons));
eventSent = true;
@ -279,7 +279,7 @@ CMSWindowsXInput::xInputPollThread(void*)
{
LOG((CLOG_DEBUG "xinput sticks changed"));
m_screen->sendEvent(m_screen->getGameDeviceSticksEvent(),
m_screen->sendEvent(m_events->forIScreen().gameDeviceSticks(),
new IPrimaryScreen::CGameDeviceStickInfo(
index,
m_gameLeftStickXLast, m_gameLeftStickYLast,
@ -293,7 +293,7 @@ CMSWindowsXInput::xInputPollThread(void*)
LOG((CLOG_DEBUG "xinput triggers changed"));
// @todo seems wrong re-using x/y for a single value...
m_screen->sendEvent(m_screen->getGameDeviceTriggersEvent(),
m_screen->sendEvent(m_events->forIScreen().gameDeviceTriggers(),
new IPrimaryScreen::CGameDeviceTriggerInfo(
index,
state.Gamepad.bLeftTrigger,
@ -304,7 +304,7 @@ CMSWindowsXInput::xInputPollThread(void*)
if (/*eventSent && */!m_gameTimingWaiting && (ARCH->time() - m_gameLastTimingSent > .5))
{
m_screen->sendEvent(m_screen->getGameDeviceTimingReqEvent(), NULL);
m_screen->sendEvent(m_events->forIScreen().gameDeviceTimingReq(), NULL);
m_gameLastTimingSent = ARCH->time();
m_gameTimingWaiting = true;
@ -332,7 +332,7 @@ CMSWindowsXInput::xInputTimingThread(void*)
if (DequeueXInputTimingResp())
{
LOG((CLOG_DEBUG "dequeued game device timing response"));
m_screen->sendEvent(m_screen->getGameDeviceTimingRespEvent(),
m_screen->sendEvent(m_events->forIScreen().gameDeviceTimingResp(),
new IPrimaryScreen::CGameDeviceTimingRespInfo(GetXInputFakeFreqMillis()));
}
@ -354,7 +354,7 @@ CMSWindowsXInput::xInputFeedbackThread(void*)
if (DequeueXInputFeedback(&leftMotor, &rightMotor))
{
LOG((CLOG_DEBUG "dequeued game device feedback"));
m_screen->sendEvent(m_screen->getGameDeviceFeedbackEvent(),
m_screen->sendEvent(m_events->forIScreen().gameDeviceFeedback(),
new IPrimaryScreen::CGameDeviceFeedbackInfo(index, leftMotor, rightMotor));
}

View File

@ -80,7 +80,7 @@ COSXEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
default:
event = CEvent(CEvent::kSystem,
IEventQueue::getSystemTarget(), &m_event);
m_events->getSystemTarget(), &m_event);
return kSystem;
}
}

View File

@ -180,14 +180,14 @@ static const CKeyEntry s_controlKeys[] = {
// COSXKeyState
//
COSXKeyState::COSXKeyState() :
COSXKeyState::COSXKeyState(IEventQueue* events) :
m_deadKeyState(0)
{
init();
}
COSXKeyState::COSXKeyState(IEventQueue& eventQueue, CKeyMap& keyMap) :
CKeyState(eventQueue, keyMap),
COSXKeyState::COSXKeyState(IEventQueue* events, CKeyMap& keyMap) :
CKeyState(events, keyMap),
m_deadKeyState(0)
{
init();

View File

@ -39,8 +39,8 @@ class COSXKeyState : public CKeyState {
public:
typedef std::vector<KeyID> CKeyIDs;
COSXKeyState();
COSXKeyState(IEventQueue& eventQueue, CKeyMap& keyMap);
COSXKeyState(IEventQueue* events);
COSXKeyState(IEventQueue* events, CKeyMap& keyMap);
virtual ~COSXKeyState();
//! @name modifiers

View File

@ -61,11 +61,8 @@ enum {
// COSXScreen
//
bool COSXScreen::s_testedForGHOM = false;
bool COSXScreen::s_hasGHOM = false;
CEvent::Type COSXScreen::s_confirmSleepEvent = CEvent::kUnknown;
COSXScreen::COSXScreen(bool isPrimary, bool autoShowHideCursor) :
MouseButtonEventMap(NumButtonIDs),
@ -134,7 +131,7 @@ COSXScreen::COSXScreen(bool isPrimary, bool autoShowHideCursor) :
constructMouseButtonEventMap();
// watch for requests to sleep
EVENTQUEUE->adoptHandler(COSXScreen::getConfirmSleepEvent(),
m_events->adoptHandler(m_events->forCOSXScreen().confirmSleep(),
getEventTarget(),
new TMethodEventJob<COSXScreen>(this,
&COSXScreen::handleConfirmSleep));
@ -146,7 +143,7 @@ COSXScreen::COSXScreen(bool isPrimary, bool autoShowHideCursor) :
(this, &COSXScreen::watchSystemPowerThread));
}
catch (...) {
EVENTQUEUE->removeHandler(COSXScreen::getConfirmSleepEvent(),
m_events->removeHandler(m_events->forCOSXScreen().confirmSleep(),
getEventTarget());
if (m_switchEventHandlerRef != 0) {
RemoveEventHandler(m_switchEventHandlerRef);
@ -176,19 +173,19 @@ COSXScreen::COSXScreen(bool isPrimary, bool autoShowHideCursor) :
}
// install event handlers
EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(),
m_events->adoptHandler(CEvent::kSystem, m_events->getSystemTarget(),
new TMethodEventJob<COSXScreen>(this,
&COSXScreen::handleSystemEvent));
// install the platform event queue
EVENTQUEUE->adoptBuffer(new COSXEventQueueBuffer);
m_events->adoptBuffer(new COSXEventQueueBuffer);
}
COSXScreen::~COSXScreen()
{
disable();
EVENTQUEUE->adoptBuffer(NULL);
EVENTQUEUE->removeHandler(CEvent::kSystem, IEventQueue::getSystemTarget());
m_events->adoptBuffer(NULL);
m_events->removeHandler(CEvent::kSystem, m_events->getSystemTarget());
if (m_pmWatchThread) {
// make sure the thread has setup the runloop.
@ -209,7 +206,7 @@ COSXScreen::~COSXScreen()
delete m_pmThreadReady;
delete m_pmMutex;
EVENTQUEUE->removeHandler(COSXScreen::getConfirmSleepEvent(),
m_events->removeHandler(m_events->forCOSXScreen().confirmSleep(),
getEventTarget());
RemoveEventHandler(m_switchEventHandlerRef);
@ -707,8 +704,8 @@ void
COSXScreen::enable()
{
// watch the clipboard
m_clipboardTimer = EVENTQUEUE->newTimer(1.0, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_clipboardTimer,
m_clipboardTimer = m_events->newTimer(1.0, NULL);
m_events->adoptHandler(CEvent::kTimer, m_clipboardTimer,
new TMethodEventJob<COSXScreen>(this,
&COSXScreen::handleClipboardCheck));
@ -778,8 +775,8 @@ COSXScreen::disable()
// uninstall clipboard timer
if (m_clipboardTimer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_clipboardTimer);
EVENTQUEUE->deleteTimer(m_clipboardTimer);
m_events->removeHandler(CEvent::kTimer, m_clipboardTimer);
m_events->deleteTimer(m_clipboardTimer);
m_clipboardTimer = NULL;
}
@ -865,8 +862,8 @@ COSXScreen::checkClipboards()
LOG((CLOG_DEBUG2 "checking clipboard"));
if (m_pasteboard.synchronize()) {
LOG((CLOG_DEBUG "clipboard changed"));
sendClipboardEvent(getClipboardGrabbedEvent(), kClipboardClipboard);
sendClipboardEvent(getClipboardGrabbedEvent(), kClipboardSelection);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection);
}
}
@ -925,7 +922,7 @@ COSXScreen::isPrimary() const
void
COSXScreen::sendEvent(CEvent::Type type, void* data) const
{
EVENTQUEUE->addEvent(CEvent(type, getEventTarget(), data));
m_events->addEvent(CEvent(type, getEventTarget(), data));
}
void
@ -1039,7 +1036,7 @@ COSXScreen::onMouseMove(SInt32 mx, SInt32 my)
if (m_isOnScreen) {
// motion on primary screen
sendEvent(getMotionOnPrimaryEvent(),
sendEvent(m_events->forIScreen().motionOnPrimary(),
CMotionInfo::alloc(m_xCursor, m_yCursor));
}
else {
@ -1061,7 +1058,7 @@ COSXScreen::onMouseMove(SInt32 mx, SInt32 my)
}
else {
// send motion
sendEvent(getMotionOnSecondaryEvent(), CMotionInfo::alloc(x, y));
sendEvent(m_events->forIScreen().motionOnSecondary(), CMotionInfo::alloc(x, y));
}
}
@ -1078,14 +1075,14 @@ COSXScreen::onMouseButton(bool pressed, UInt16 macButton)
LOG((CLOG_DEBUG1 "event: button press button=%d", button));
if (button != kButtonNone) {
KeyModifierMask mask = m_keyState->getActiveModifiers();
sendEvent(getButtonDownEvent(), CButtonInfo::alloc(button, mask));
sendEvent(m_events->forIPrimaryScreen().buttonDown(), CButtonInfo::alloc(button, mask));
}
}
else {
LOG((CLOG_DEBUG1 "event: button release button=%d", button));
if (button != kButtonNone) {
KeyModifierMask mask = m_keyState->getActiveModifiers();
sendEvent(getButtonUpEvent(), CButtonInfo::alloc(button, mask));
sendEvent(m_events->forIPrimaryScreen().buttonUp(), CButtonInfo::alloc(button, mask));
}
}
@ -1112,7 +1109,7 @@ bool
COSXScreen::onMouseWheel(SInt32 xDelta, SInt32 yDelta) const
{
LOG((CLOG_DEBUG1 "event: button wheel delta=%+d,%+d", xDelta, yDelta));
sendEvent(getWheelEvent(), CWheelInfo::alloc(xDelta, yDelta));
sendEvent(m_events->forIPrimaryScreen().wheel(), CWheelInfo::alloc(xDelta, yDelta));
return true;
}
@ -1152,7 +1149,7 @@ COSXScreen::onDisplayChange()
}
// send new screen info
sendEvent(getShapeChangedEvent());
sendEvent(m_events->forIPrimaryScreen().shapeChanged());
}
return true;
@ -1204,7 +1201,7 @@ COSXScreen::onKey(CGEventRef event)
if (m_modifierHotKeys.count(newMask) > 0) {
m_activeModifierHotKey = m_modifierHotKeys[newMask];
m_activeModifierHotKeyMask = newMask;
EVENTQUEUE->addEvent(CEvent(getHotKeyDownEvent(),
m_events->addEvent(CEvent(m_events->forIPrimaryScreen().hotKeyDown(),
getEventTarget(),
CHotKeyInfo::alloc(m_activeModifierHotKey)));
}
@ -1215,7 +1212,7 @@ COSXScreen::onKey(CGEventRef event)
else if (m_activeModifierHotKey != 0) {
KeyModifierMask mask = (newMask & m_activeModifierHotKeyMask);
if (mask != m_activeModifierHotKeyMask) {
EVENTQUEUE->addEvent(CEvent(getHotKeyUpEvent(),
m_events->addEvent(CEvent(m_events->forIPrimaryScreen().hotKeyUp(),
getEventTarget(),
CHotKeyInfo::alloc(m_activeModifierHotKey)));
m_activeModifierHotKey = 0;
@ -1242,16 +1239,16 @@ COSXScreen::onKey(CGEventRef event)
CEvent::Type type;
//UInt32 eventKind = GetEventKind(event);
if (eventKind == kCGEventKeyDown) {
type = getHotKeyDownEvent();
type = m_events->forIPrimaryScreen().hotKeyDown();
}
else if (eventKind == kCGEventKeyUp) {
type = getHotKeyUpEvent();
type = m_events->forIPrimaryScreen().hotKeyUp();
}
else {
return false;
}
EVENTQUEUE->addEvent(CEvent(type, getEventTarget(),
m_events->addEvent(CEvent(type, getEventTarget(),
CHotKeyInfo::alloc(id)));
return true;
@ -1315,16 +1312,16 @@ COSXScreen::onHotKey(EventRef event) const
CEvent::Type type;
UInt32 eventKind = GetEventKind(event);
if (eventKind == kEventHotKeyPressed) {
type = getHotKeyDownEvent();
type = m_events->forIPrimaryScreen().hotKeyDown();
}
else if (eventKind == kEventHotKeyReleased) {
type = getHotKeyUpEvent();
type = m_events->forIPrimaryScreen().hotKeyUp();
}
else {
return false;
}
EVENTQUEUE->addEvent(CEvent(type, getEventTarget(),
m_events->addEvent(CEvent(type, getEventTarget(),
CHotKeyInfo::alloc(id)));
return true;
@ -1403,15 +1400,15 @@ COSXScreen::enableDragTimer(bool enable)
MouseTrackingResult res;
if (enable && m_dragTimer == NULL) {
m_dragTimer = EVENTQUEUE->newTimer(0.01, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_dragTimer,
m_dragTimer = m_events->newTimer(0.01, NULL);
m_events->adoptHandler(CEvent::kTimer, m_dragTimer,
new TMethodEventJob<COSXScreen>(this,
&COSXScreen::handleDrag));
TrackMouseLocationWithOptions(NULL, 0, 0, &m_dragLastPoint, &modifiers, &res);
}
else if (!enable && m_dragTimer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_dragTimer);
EVENTQUEUE->deleteTimer(m_dragTimer);
m_events->removeHandler(CEvent::kTimer, m_dragTimer);
m_events->deleteTimer(m_dragTimer);
m_dragTimer = NULL;
}
}
@ -1497,7 +1494,7 @@ COSXScreen::updateScreenShape()
delete[] displays;
// We want to notify the peer screen whether we are primary screen or not
sendEvent(getShapeChangedEvent());
sendEvent(m_events->forIPrimaryScreen().shapeChanged());
LOG((CLOG_DEBUG "screen shape: center=%d,%d size=%dx%d on %u %s",
m_x, m_y, m_w, m_h, displayCount,
@ -1524,12 +1521,12 @@ COSXScreen::userSwitchCallback(EventHandlerCallRef nextHandler,
if (kind == kEventSystemUserSessionDeactivated) {
LOG((CLOG_DEBUG "user session deactivated"));
EVENTQUEUE->addEvent(CEvent(IScreen::getSuspendEvent(),
m_events->addEvent(CEvent(m_events->forIScreen().suspend(),
screen->getEventTarget()));
}
else if (kind == kEventSystemUserSessionActivated) {
LOG((CLOG_DEBUG "user session activated"));
EVENTQUEUE->addEvent(CEvent(IScreen::getResumeEvent(),
m_events->addEvent(CEvent(m_events->forIScreen().resume(),
screen->getEventTarget()));
}
return (CallNextEventHandler(nextHandler, theEvent));
@ -1614,14 +1611,14 @@ COSXScreen::handlePowerChangeRequest(natural_t messageType, void* messageArg)
// COSXScreen has to handle this in the main thread so we have to
// queue a confirm sleep event here. we actually don't allow the
// system to sleep until the event is handled.
EVENTQUEUE->addEvent(CEvent(COSXScreen::getConfirmSleepEvent(),
m_events->addEvent(CEvent(m_events->forCOSXScreen().confirmSleep(),
getEventTarget(), messageArg,
CEvent::kDontFreeData));
return;
case kIOMessageSystemHasPoweredOn:
LOG((CLOG_DEBUG "system wakeup"));
EVENTQUEUE->addEvent(CEvent(IScreen::getResumeEvent(),
m_events->addEvent(CEvent(m_events->forIScreen().resume(),
getEventTarget()));
break;
@ -1635,13 +1632,6 @@ COSXScreen::handlePowerChangeRequest(natural_t messageType, void* messageArg)
}
}
CEvent::Type
COSXScreen::getConfirmSleepEvent()
{
return EVENTQUEUE->registerTypeOnce(s_confirmSleepEvent,
"COSXScreen::confirmSleep");
}
void
COSXScreen::handleConfirmSleep(const CEvent& event, void*)
{
@ -1650,7 +1640,7 @@ COSXScreen::handleConfirmSleep(const CEvent& event, void*)
CLock lock(m_pmMutex);
if (m_pmRootPort != 0) {
// deliver suspend event immediately.
EVENTQUEUE->addEvent(CEvent(IScreen::getSuspendEvent(),
m_events->addEvent(CEvent(m_events->forIScreen().suspend(),
getEventTarget(), NULL,
CEvent::kDeliverImmediately));

View File

@ -27,6 +27,7 @@
#include <Carbon/Carbon.h>
#include "COSXClipboard.h"
#include "CPlatformScreen.h"
#include "CEventTypes.h"
#include <mach/mach_port.h>
#include <mach/mach_interface.h>
@ -181,7 +182,6 @@ private:
void handlePowerChangeRequest(natural_t messageType,
void* messageArgument);
static CEvent::Type getConfirmSleepEvent();
void handleConfirmSleep(const CEvent& event, void*);
// global hotkey operating mode
@ -323,9 +323,6 @@ private:
static bool s_testedForGHOM;
static bool s_hasGHOM;
// events
static CEvent::Type s_confirmSleepEvent;
// Quartz input event support
CFMachPortRef m_eventTapPort;
CFRunLoopSourceRef m_eventTapRLSR;

View File

@ -125,8 +125,8 @@ COSXScreenSaver::processLaunched(ProcessSerialNumber psn)
m_screenSaverPSN = psn;
LOG((CLOG_DEBUG1 "ScreenSaverEngine launched. Enabled=%d", m_enabled));
if (m_enabled) {
EVENTQUEUE->addEvent(
CEvent(IPrimaryScreen::getScreensaverActivatedEvent(),
m_events->addEvent(
CEvent(m_events->forIPrimaryScreen().screensaverActivated(),
m_eventTarget));
}
}
@ -139,8 +139,8 @@ COSXScreenSaver::processTerminated(ProcessSerialNumber psn)
m_screenSaverPSN.lowLongOfPSN == psn.lowLongOfPSN) {
LOG((CLOG_DEBUG1 "ScreenSaverEngine terminated. Enabled=%d", m_enabled));
if (m_enabled) {
EVENTQUEUE->addEvent(
CEvent(IPrimaryScreen::getScreensaverDeactivatedEvent(),
m_events->addEvent(
CEvent(m_events->forIPrimaryScreen().screensaverDeactivated(),
m_eventTarget));
}

View File

@ -213,7 +213,7 @@ CXWindowsEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
}
else {
event = CEvent(CEvent::kSystem,
IEventQueue::getSystemTarget(), &m_event);
m_events->getSystemTarget(), &m_event);
return kSystem;
}
}

View File

@ -47,8 +47,8 @@ CXWindowsKeyState::CXWindowsKeyState(Display* display, bool useXKB) :
CXWindowsKeyState::CXWindowsKeyState(
Display* display, bool useXKB,
IEventQueue& eventQueue, CKeyMap& keyMap) :
CKeyState(eventQueue, keyMap),
IEventQueue* events, CKeyMap& keyMap) :
CKeyState(events, keyMap),
m_display(display),
m_modifierFromX(ModifiersFromXDefaultSize)
{

View File

@ -50,7 +50,7 @@ public:
CXWindowsKeyState(Display*, bool useXKB);
CXWindowsKeyState(Display*, bool useXKB,
IEventQueue& eventQueue, CKeyMap& keyMap);
IEventQueue* events, CKeyMap& keyMap);
~CXWindowsKeyState();
//! @name modifiers

View File

@ -88,7 +88,7 @@ static int xi_opcode;
CXWindowsScreen* CXWindowsScreen::s_screen = NULL;
CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, IEventQueue& eventQueue) :
CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, IEventQueue* events) :
m_isPrimary(isPrimary),
m_mouseScrollDelta(mouseScrollDelta),
m_display(NULL),
@ -113,8 +113,8 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool d
m_xkb(false),
m_xi2detected(false),
m_xrandr(false),
m_eventQueue(eventQueue),
CPlatformScreen(eventQueue)
m_events(events),
CPlatformScreen(events)
{
assert(s_screen == NULL);
@ -138,8 +138,8 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool d
saveShape();
m_window = openWindow();
m_screensaver = new CXWindowsScreenSaver(m_display,
m_window, getEventTarget(), eventQueue);
m_keyState = new CXWindowsKeyState(m_display, m_xkb, eventQueue, m_keyMap);
m_window, getEventTarget(), events);
m_keyState = new CXWindowsKeyState(m_display, m_xkb, events, m_keyMap);
LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_xinerama ? "(xinerama)" : ""));
LOG((CLOG_DEBUG "window is 0x%08x", m_window));
}
@ -180,12 +180,12 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool d
}
// install event handlers
m_eventQueue.adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(),
m_events->adoptHandler(CEvent::kSystem, m_events->getSystemTarget(),
new TMethodEventJob<CXWindowsScreen>(this,
&CXWindowsScreen::handleSystemEvent));
// install the platform event queue
m_eventQueue.adoptBuffer(new CXWindowsEventQueueBuffer(m_display, m_window));
m_events->adoptBuffer(new CXWindowsEventQueueBuffer(m_display, m_window));
}
CXWindowsScreen::~CXWindowsScreen()
@ -193,8 +193,8 @@ CXWindowsScreen::~CXWindowsScreen()
assert(s_screen != NULL);
assert(m_display != NULL);
m_eventQueue.adoptBuffer(NULL);
m_eventQueue.removeHandler(CEvent::kSystem, IEventQueue::getSystemTarget());
m_events->adoptBuffer(NULL);
m_events->removeHandler(CEvent::kSystem, m_events->getSystemTarget());
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
delete m_clipboard[id];
}
@ -1139,7 +1139,7 @@ CXWindowsScreen::openIM()
void
CXWindowsScreen::sendEvent(CEvent::Type type, void* data)
{
m_eventQueue.addEvent(CEvent(type, getEventTarget(), data));
m_events->addEvent(CEvent(type, getEventTarget(), data));
}
void
@ -1317,7 +1317,7 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*)
if (id != kClipboardEnd) {
LOG((CLOG_DEBUG "lost clipboard %d ownership at time %d", id, xevent->xselectionclear.time));
m_clipboard[id]->lost(xevent->xselectionclear.time);
sendClipboardEvent(getClipboardGrabbedEvent(), id);
sendClipboardEvent(m_events->forIPrimaryScreen().clipboardGrabbed(), id);
return;
}
}
@ -1531,10 +1531,10 @@ CXWindowsScreen::onHotKey(XKeyEvent& xkey, bool isRepeat)
// find what kind of event
CEvent::Type type;
if (xkey.type == KeyPress) {
type = getHotKeyDownEvent();
type = m_events->forIPrimaryScreen().hotKeyDown();
}
else if (xkey.type == KeyRelease) {
type = getHotKeyUpEvent();
type = m_events->forIPrimaryScreen().hotKeyUp();
}
else {
return false;
@ -1542,7 +1542,7 @@ CXWindowsScreen::onHotKey(XKeyEvent& xkey, bool isRepeat)
// generate event (ignore key repeats)
if (!isRepeat) {
m_eventQueue.addEvent(CEvent(type, getEventTarget(),
m_events->addEvent(CEvent(type, getEventTarget(),
CHotKeyInfo::alloc(i->second)));
}
return true;
@ -1555,7 +1555,7 @@ CXWindowsScreen::onMousePress(const XButtonEvent& xbutton)
ButtonID button = mapButtonFromX(&xbutton);
KeyModifierMask mask = m_keyState->mapModifiersFromX(xbutton.state);
if (button != kButtonNone) {
sendEvent(getButtonDownEvent(), CButtonInfo::alloc(button, mask));
sendEvent(m_events->forIPrimaryScreen().buttonDown(), CButtonInfo::alloc(button, mask));
}
}
@ -1566,15 +1566,15 @@ CXWindowsScreen::onMouseRelease(const XButtonEvent& xbutton)
ButtonID button = mapButtonFromX(&xbutton);
KeyModifierMask mask = m_keyState->mapModifiersFromX(xbutton.state);
if (button != kButtonNone) {
sendEvent(getButtonUpEvent(), CButtonInfo::alloc(button, mask));
sendEvent(m_events->forIPrimaryScreen().buttonUp(), CButtonInfo::alloc(button, mask));
}
else if (xbutton.button == 4) {
// wheel forward (away from user)
sendEvent(getWheelEvent(), CWheelInfo::alloc(0, 120));
sendEvent(m_events->forIPrimaryScreen().wheel(), CWheelInfo::alloc(0, 120));
}
else if (xbutton.button == 5) {
// wheel backward (toward user)
sendEvent(getWheelEvent(), CWheelInfo::alloc(0, -120));
sendEvent(m_events->forIPrimaryScreen().wheel(), CWheelInfo::alloc(0, -120));
}
// XXX -- support x-axis scrolling
}
@ -1612,7 +1612,7 @@ CXWindowsScreen::onMouseMove(const XMotionEvent& xmotion)
}
else if (m_isOnScreen) {
// motion on primary screen
sendEvent(getMotionOnPrimaryEvent(),
sendEvent(m_events->forIPrimaryScreen().motionOnPrimary(),
CMotionInfo::alloc(m_xCursor, m_yCursor));
}
else {
@ -1643,7 +1643,7 @@ CXWindowsScreen::onMouseMove(const XMotionEvent& xmotion)
// warping to the primary screen's enter position,
// effectively overriding it.
if (x != 0 || y != 0) {
sendEvent(getMotionOnSecondaryEvent(), CMotionInfo::alloc(x, y));
sendEvent(m_events->forIPrimaryScreen().motionOnSecondary(), CMotionInfo::alloc(x, y));
}
}
}
@ -1725,13 +1725,13 @@ void
CXWindowsScreen::onError()
{
// prevent further access to the X display
m_eventQueue.adoptBuffer(NULL);
m_events->adoptBuffer(NULL);
m_screensaver->destroy();
m_screensaver = NULL;
m_display = NULL;
// notify of failure
sendEvent(getErrorEvent(), NULL);
sendEvent(m_events->forIPrimaryScreen().error(), NULL);
// FIXME -- should ensure that we ignore operations that involve
// m_display from now on. however, Xlib will simply exit the

View File

@ -36,7 +36,7 @@ class CXWindowsScreenSaver;
//! Implementation of IPlatformScreen for X11
class CXWindowsScreen : public CPlatformScreen {
public:
CXWindowsScreen(const char* displayName, bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, IEventQueue& eventQueue);
CXWindowsScreen(const char* displayName, bool isPrimary, bool disableXInitThreads, int mouseScrollDelta, IEventQueue* events);
virtual ~CXWindowsScreen();
//! @name manipulators
@ -247,7 +247,7 @@ private:
bool m_xrandr;
int m_xrandrEventBase;
IEventQueue& m_eventQueue;
IEventQueue* m_events;
CKeyMap m_keyMap;
// pointer to (singleton) screen. this is only needed by

View File

@ -57,7 +57,7 @@ extern Status DPMSInfo(Display *, CARD16 *, BOOL *);
//
CXWindowsScreenSaver::CXWindowsScreenSaver(
Display* display, Window window, void* eventTarget, IEventQueue& eventQueue) :
Display* display, Window window, void* eventTarget, IEventQueue* events) :
m_display(display),
m_xscreensaverSink(window),
m_eventTarget(eventTarget),
@ -68,7 +68,7 @@ CXWindowsScreenSaver::CXWindowsScreenSaver(
m_suppressDisable(false),
m_disableTimer(NULL),
m_disablePos(0),
m_eventQueue(eventQueue)
m_events(events)
{
// get atoms
m_atomScreenSaver = XInternAtom(m_display,
@ -120,7 +120,7 @@ CXWindowsScreenSaver::CXWindowsScreenSaver(
}
// install disable timer event handler
m_eventQueue.adoptHandler(CEvent::kTimer, this,
m_events->adoptHandler(CEvent::kTimer, this,
new TMethodEventJob<CXWindowsScreenSaver>(this,
&CXWindowsScreenSaver::handleDisableTimer));
}
@ -129,9 +129,9 @@ CXWindowsScreenSaver::~CXWindowsScreenSaver()
{
// done with disable job
if (m_disableTimer != NULL) {
m_eventQueue.deleteTimer(m_disableTimer);
m_events->deleteTimer(m_disableTimer);
}
m_eventQueue.removeHandler(CEvent::kTimer, this);
m_events->removeHandler(CEvent::kTimer, this);
if (m_display != NULL) {
enableDPMS(m_dpmsEnabled);
@ -397,13 +397,13 @@ CXWindowsScreenSaver::setXScreenSaverActive(bool activated)
updateDisableTimer();
if (activated) {
m_eventQueue.addEvent(CEvent(
IPlatformScreen::getScreensaverActivatedEvent(),
m_events->addEvent(CEvent(
m_events->forIPlatformScreen().screensaverActivated(),
m_eventTarget));
}
else {
m_eventQueue.addEvent(CEvent(
IPlatformScreen::getScreensaverDeactivatedEvent(),
m_events->addEvent(CEvent(
m_events->forIPlatformScreen().screensaverDeactivated(),
m_eventTarget));
}
}
@ -504,10 +504,10 @@ CXWindowsScreenSaver::updateDisableTimer()
{
if (m_disabled && !m_suppressDisable && m_disableTimer == NULL) {
// 5 seconds should be plenty often to suppress the screen saver
m_disableTimer = m_eventQueue.newTimer(5.0, this);
m_disableTimer = m_events->newTimer(5.0, this);
}
else if ((!m_disabled || m_suppressDisable) && m_disableTimer != NULL) {
m_eventQueue.deleteTimer(m_disableTimer);
m_events->deleteTimer(m_disableTimer);
m_disableTimer = NULL;
}
}

View File

@ -34,7 +34,7 @@ class CEventQueueTimer;
//! X11 screen saver implementation
class CXWindowsScreenSaver : public IScreenSaver {
public:
CXWindowsScreenSaver(Display*, Window, void* eventTarget, IEventQueue& eventQueue);
CXWindowsScreenSaver(Display*, Window, void* eventTarget, IEventQueue* events);
virtual ~CXWindowsScreenSaver();
//! @name manipulators
@ -165,7 +165,7 @@ private:
// pixels to be considered significant.
SInt32 m_disablePos;
IEventQueue& m_eventQueue;
IEventQueue* m_events;
};
#endif

View File

@ -31,24 +31,20 @@
#include "CCryptoStream.h"
#include "CCryptoOptions.h"
// TODO: these are just for testing -- make sure they're gone by release!
const byte g_key[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const byte g_iv[] = "aaaaaaaaaaaaaaa";
//
// CClientListener
//
CEvent::Type CClientListener::s_connectedEvent = CEvent::kUnknown;
CClientListener::CClientListener(const CNetworkAddress& address,
ISocketFactory* socketFactory,
IStreamFilterFactory* streamFilterFactory,
const CCryptoOptions& crypto) :
const CCryptoOptions& crypto,
IEventQueue* events) :
m_socketFactory(socketFactory),
m_streamFilterFactory(streamFilterFactory),
m_server(NULL),
m_crypto(crypto)
m_crypto(crypto),
m_events(events)
{
assert(m_socketFactory != NULL);
@ -75,7 +71,7 @@ CClientListener::CClientListener(const CNetworkAddress& address,
LOG((CLOG_DEBUG1 "listening for clients"));
// setup event handler
EVENTQUEUE->adoptHandler(m_listen->getConnectingEvent(), m_listen,
m_events->adoptHandler(m_events->forIListenSocket().connecting(), m_listen,
new TMethodEventJob<CClientListener>(this,
&CClientListener::handleClientConnecting));
}
@ -88,12 +84,12 @@ CClientListener::~CClientListener()
for (CNewClients::iterator index = m_newClients.begin();
index != m_newClients.end(); ++index) {
CClientProxyUnknown* client = *index;
EVENTQUEUE->removeHandler(
CClientProxyUnknown::getSuccessEvent(), client);
EVENTQUEUE->removeHandler(
CClientProxyUnknown::getFailureEvent(), client);
EVENTQUEUE->removeHandler(
CClientProxy::getDisconnectedEvent(), client);
m_events->removeHandler(
m_events->forCClientProxyUnknown().success(), client);
m_events->removeHandler(
m_events->forCClientProxyUnknown().failure(), client);
m_events->removeHandler(
m_events->forCClientProxy().disconnected(), client);
delete client;
}
@ -104,7 +100,7 @@ CClientListener::~CClientListener()
client = getNextClient();
}
EVENTQUEUE->removeHandler(m_listen->getConnectingEvent(), m_listen);
m_events->removeHandler(m_events->forIListenSocket().connecting(), m_listen);
delete m_listen;
delete m_socketFactory;
delete m_streamFilterFactory;
@ -124,18 +120,11 @@ CClientListener::getNextClient()
if (!m_waitingClients.empty()) {
client = m_waitingClients.front();
m_waitingClients.pop_front();
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(), client);
m_events->removeHandler(m_events->forCClientProxy().disconnected(), client);
}
return client;
}
CEvent::Type
CClientListener::getConnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_connectedEvent,
"CClientListener::connected");
}
void
CClientListener::handleClientConnecting(const CEvent&, void*)
{
@ -150,25 +139,25 @@ CClientListener::handleClientConnecting(const CEvent&, void*)
if (m_streamFilterFactory != NULL) {
stream = m_streamFilterFactory->create(stream, true);
}
stream = new CPacketStreamFilter(stream, true);
stream = new CPacketStreamFilter(m_events, stream, true);
if (m_crypto.m_mode != kDisabled) {
CCryptoStream* cryptoStream = new CCryptoStream(
EVENTQUEUE, stream, m_crypto, true);
m_events, stream, m_crypto, true);
stream = cryptoStream;
}
assert(m_server != NULL);
// create proxy for unknown client
CClientProxyUnknown* client = new CClientProxyUnknown(stream, 30.0, m_server);
CClientProxyUnknown* client = new CClientProxyUnknown(stream, 30.0, m_server, m_events);
m_newClients.insert(client);
// watch for events from unknown client
EVENTQUEUE->adoptHandler(CClientProxyUnknown::getSuccessEvent(), client,
m_events->adoptHandler(m_events->forCClientProxyUnknown().success(), client,
new TMethodEventJob<CClientListener>(this,
&CClientListener::handleUnknownClient, client));
EVENTQUEUE->adoptHandler(CClientProxyUnknown::getFailureEvent(), client,
m_events->adoptHandler(m_events->forCClientProxyUnknown().failure(), client,
new TMethodEventJob<CClientListener>(this,
&CClientListener::handleUnknownClient, client));
}
@ -187,18 +176,18 @@ CClientListener::handleUnknownClient(const CEvent&, void* vclient)
if (client != NULL) {
// handshake was successful
m_waitingClients.push_back(client);
EVENTQUEUE->addEvent(CEvent(getConnectedEvent(), this));
m_events->addEvent(CEvent(m_events->forCClientListener().connected(), this));
// watch for client to disconnect while it's in our queue
EVENTQUEUE->adoptHandler(CClientProxy::getDisconnectedEvent(), client,
m_events->adoptHandler(m_events->forCClientProxy().disconnected(), client,
new TMethodEventJob<CClientListener>(this,
&CClientListener::handleClientDisconnected,
client));
}
// now finished with unknown client
EVENTQUEUE->removeHandler(CClientProxyUnknown::getSuccessEvent(), client);
EVENTQUEUE->removeHandler(CClientProxyUnknown::getFailureEvent(), client);
m_events->removeHandler(m_events->forCClientProxyUnknown().success(), client);
m_events->removeHandler(m_events->forCClientProxyUnknown().failure(), client);
m_newClients.erase(unknownClient);
delete unknownClient;
}
@ -213,7 +202,7 @@ CClientListener::handleClientDisconnected(const CEvent&, void* vclient)
n = m_waitingClients.end(); i != n; ++i) {
if (*i == client) {
m_waitingClients.erase(i);
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(),
m_events->removeHandler(m_events->forCClientProxy().disconnected(),
client);
delete client;
break;

View File

@ -24,6 +24,7 @@
#include "stddeque.h"
#include "stdset.h"
#include "CCryptoOptions.h"
#include "CEventTypes.h"
class CClientProxy;
class CClientProxyUnknown;
@ -32,6 +33,7 @@ class IListenSocket;
class ISocketFactory;
class IStreamFilterFactory;
class CServer;
class IEventQueue;
class CClientListener {
public:
@ -39,7 +41,8 @@ public:
CClientListener(const CNetworkAddress&,
ISocketFactory*,
IStreamFilterFactory*,
const CCryptoOptions& crypto);
const CCryptoOptions& crypto,
IEventQueue* events);
~CClientListener();
//! @name manipulators
@ -60,13 +63,6 @@ public:
*/
CClientProxy* getNextClient();
//! Get connected event type
/*!
Returns the connected event type. This is sent whenever a
a client connects.
*/
static CEvent::Type getConnectedEvent();
//@}
private:
@ -86,8 +82,7 @@ private:
CWaitingClients m_waitingClients;
CServer* m_server;
CCryptoOptions m_crypto;
static CEvent::Type s_connectedEvent;
IEventQueue* m_events;
};
#endif

View File

@ -26,11 +26,6 @@
// CClientProxy
//
CEvent::Type CClientProxy::s_readyEvent = CEvent::kUnknown;
CEvent::Type CClientProxy::s_disconnectedEvent = CEvent::kUnknown;
CEvent::Type CClientProxy::s_clipboardChangedEvent= CEvent::kUnknown;
CEvent::Type CClientProxy::s_gameDeviceTimingRecvEvent= CEvent::kUnknown;
CClientProxy::CClientProxy(const CString& name, synergy::IStream* stream) :
CBaseClientProxy(name),
m_stream(stream)
@ -58,34 +53,6 @@ CClientProxy::getStream() const
return m_stream;
}
CEvent::Type
CClientProxy::getReadyEvent()
{
return EVENTQUEUE->registerTypeOnce(s_readyEvent,
"CClientProxy::ready");
}
CEvent::Type
CClientProxy::getDisconnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_disconnectedEvent,
"CClientProxy::disconnected");
}
CEvent::Type
CClientProxy::getClipboardChangedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_clipboardChangedEvent,
"CClientProxy::clipboardChanged");
}
CEvent::Type
CClientProxy::getGameDeviceTimingRespEvent()
{
return EVENTQUEUE->registerTypeOnce(s_gameDeviceTimingRecvEvent,
"CClientProxy::gameDeviceTimingRecv");
}
void*
CClientProxy::getEventTarget() const
{

View File

@ -22,6 +22,7 @@
#include "CBaseClientProxy.h"
#include "CEvent.h"
#include "CString.h"
#include "CEventTypes.h"
namespace synergy { class IStream; }
@ -54,36 +55,6 @@ public:
*/
synergy::IStream* getStream() const;
//! Get ready event type
/*!
Returns the ready event type. This is sent when the client has
completed the initial handshake. Until it is sent, the client is
not fully connected.
*/
static CEvent::Type getReadyEvent();
//! Get disconnect event type
/*!
Returns the disconnect event type. This is sent when the client
disconnects or is disconnected. The target is getEventTarget().
*/
static CEvent::Type getDisconnectedEvent();
//! Get clipboard changed event type
/*!
Returns the clipboard changed event type. This is sent whenever the
contents of the clipboard has changed. The data is a pointer to a
IScreen::CClipboardInfo.
*/
static CEvent::Type getClipboardChangedEvent();
//! Get game device timing receive event type
/*!
Returns the game device timing receive event type. This is set
whenever the server receives to a timing event response from a client.
*/
static CEvent::Type getGameDeviceTimingRespEvent();
//@}
// IScreen
@ -121,11 +92,6 @@ public:
private:
synergy::IStream* m_stream;
static CEvent::Type s_readyEvent;
static CEvent::Type s_disconnectedEvent;
static CEvent::Type s_clipboardChangedEvent;
static CEvent::Type s_gameDeviceTimingRecvEvent;
};
#endif

View File

@ -29,30 +29,30 @@
// CClientProxy1_0
//
CClientProxy1_0::CClientProxy1_0(const CString& name, synergy::IStream* stream, IEventQueue* eventQueue) :
CClientProxy1_0::CClientProxy1_0(const CString& name, synergy::IStream* stream, IEventQueue* events) :
CClientProxy(name, stream),
m_heartbeatTimer(NULL),
m_parser(&CClientProxy1_0::parseHandshakeMessage),
m_eventQueue(eventQueue)
m_events(events)
{
// install event handlers
m_eventQueue->adoptHandler(stream->getInputReadyEvent(),
m_events->adoptHandler(m_events->forIStream().inputReady(),
stream->getEventTarget(),
new TMethodEventJob<CClientProxy1_0>(this,
&CClientProxy1_0::handleData, NULL));
m_eventQueue->adoptHandler(stream->getOutputErrorEvent(),
m_events->adoptHandler(m_events->forIStream().outputError(),
stream->getEventTarget(),
new TMethodEventJob<CClientProxy1_0>(this,
&CClientProxy1_0::handleWriteError, NULL));
m_eventQueue->adoptHandler(stream->getInputShutdownEvent(),
m_events->adoptHandler(m_events->forIStream().inputShutdown(),
stream->getEventTarget(),
new TMethodEventJob<CClientProxy1_0>(this,
&CClientProxy1_0::handleDisconnect, NULL));
m_eventQueue->adoptHandler(stream->getOutputShutdownEvent(),
m_events->adoptHandler(m_events->forIStream().outputShutdown(),
stream->getEventTarget(),
new TMethodEventJob<CClientProxy1_0>(this,
&CClientProxy1_0::handleWriteError, NULL));
m_eventQueue->adoptHandler(CEvent::kTimer, this,
m_events->adoptHandler(CEvent::kTimer, this,
new TMethodEventJob<CClientProxy1_0>(this,
&CClientProxy1_0::handleFlatline, NULL));
@ -72,22 +72,22 @@ CClientProxy1_0::disconnect()
{
removeHandlers();
getStream()->close();
m_eventQueue->addEvent(CEvent(getDisconnectedEvent(), getEventTarget()));
m_events->addEvent(CEvent(m_events->forCClientProxy().disconnected(), getEventTarget()));
}
void
CClientProxy1_0::removeHandlers()
{
// uninstall event handlers
m_eventQueue->removeHandler(getStream()->getInputReadyEvent(),
m_events->removeHandler(m_events->forIStream().inputReady(),
getStream()->getEventTarget());
m_eventQueue->removeHandler(getStream()->getOutputErrorEvent(),
m_events->removeHandler(m_events->forIStream().outputError(),
getStream()->getEventTarget());
m_eventQueue->removeHandler(getStream()->getInputShutdownEvent(),
m_events->removeHandler(m_events->forIStream().inputShutdown(),
getStream()->getEventTarget());
m_eventQueue->removeHandler(getStream()->getOutputShutdownEvent(),
m_events->removeHandler(m_events->forIStream().outputShutdown(),
getStream()->getEventTarget());
m_eventQueue->removeHandler(CEvent::kTimer, this);
m_events->removeHandler(CEvent::kTimer, this);
// remove timer
removeHeartbeatTimer();
@ -97,7 +97,7 @@ void
CClientProxy1_0::addHeartbeatTimer()
{
if (m_heartbeatAlarm > 0.0) {
m_heartbeatTimer = m_eventQueue->newOneShotTimer(m_heartbeatAlarm, this);
m_heartbeatTimer = m_events->newOneShotTimer(m_heartbeatAlarm, this);
}
}
@ -105,7 +105,7 @@ void
CClientProxy1_0::removeHeartbeatTimer()
{
if (m_heartbeatTimer != NULL) {
m_eventQueue->deleteTimer(m_heartbeatTimer);
m_events->deleteTimer(m_heartbeatTimer);
m_heartbeatTimer = NULL;
}
}
@ -172,7 +172,7 @@ CClientProxy1_0::parseHandshakeMessage(const UInt8* code)
// future messages get parsed by parseMessage
m_parser = &CClientProxy1_0::parseMessage;
if (recvInfo()) {
m_eventQueue->addEvent(CEvent(getReadyEvent(), getEventTarget()));
m_events->addEvent(CEvent(m_events->forCClientProxy().ready(), getEventTarget()));
addHeartbeatTimer();
return true;
}
@ -185,8 +185,8 @@ CClientProxy1_0::parseMessage(const UInt8* code)
{
if (memcmp(code, kMsgDInfo, 4) == 0) {
if (recvInfo()) {
m_eventQueue->addEvent(
CEvent(getShapeChangedEvent(), getEventTarget()));
m_events->addEvent(
CEvent(m_events->forIScreen().shapeChanged(), getEventTarget()));
return true;
}
return false;
@ -492,7 +492,7 @@ CClientProxy1_0::recvClipboard()
CClipboardInfo* info = new CClipboardInfo;
info->m_id = id;
info->m_sequenceNumber = seqNum;
m_eventQueue->addEvent(CEvent(getClipboardChangedEvent(),
m_events->addEvent(CEvent(m_events->forCClientProxy().clipboardChanged(),
getEventTarget(), info));
return true;
@ -518,7 +518,7 @@ CClientProxy1_0::recvGrabClipboard()
CClipboardInfo* info = new CClipboardInfo;
info->m_id = id;
info->m_sequenceNumber = seqNum;
m_eventQueue->addEvent(CEvent(getClipboardGrabbedEvent(),
m_events->addEvent(CEvent(m_events->forIScreen().clipboardGrabbed(),
getEventTarget(), info));
return true;

View File

@ -30,7 +30,7 @@ class IEventQueue;
//! Proxy for client implementing protocol version 1.0
class CClientProxy1_0 : public CClientProxy {
public:
CClientProxy1_0(const CString& name, synergy::IStream* adoptedStream, IEventQueue* eventQueue);
CClientProxy1_0(const CString& name, synergy::IStream* adoptedStream, IEventQueue* events);
~CClientProxy1_0();
// IScreen
@ -105,7 +105,7 @@ private:
double m_heartbeatAlarm;
CEventQueueTimer* m_heartbeatTimer;
MessageParser m_parser;
IEventQueue* m_eventQueue;
IEventQueue* m_events;
};
#endif

View File

@ -25,8 +25,8 @@
// CClientProxy1_1
//
CClientProxy1_1::CClientProxy1_1(const CString& name, synergy::IStream* stream, IEventQueue* eventQueue) :
CClientProxy1_0(name, stream, eventQueue)
CClientProxy1_1::CClientProxy1_1(const CString& name, synergy::IStream* stream, IEventQueue* events) :
CClientProxy1_0(name, stream, events)
{
// do nothing
}

View File

@ -24,7 +24,7 @@
//! Proxy for client implementing protocol version 1.1
class CClientProxy1_1 : public CClientProxy1_0 {
public:
CClientProxy1_1(const CString& name, synergy::IStream* adoptedStream, IEventQueue* eventQueue);
CClientProxy1_1(const CString& name, synergy::IStream* adoptedStream, IEventQueue* events);
~CClientProxy1_1();
// IClient overrides

View File

@ -24,8 +24,8 @@
// CClientProxy1_1
//
CClientProxy1_2::CClientProxy1_2(const CString& name, synergy::IStream* stream, IEventQueue* eventQueue) :
CClientProxy1_1(name, stream, eventQueue)
CClientProxy1_2::CClientProxy1_2(const CString& name, synergy::IStream* stream, IEventQueue* events) :
CClientProxy1_1(name, stream, events)
{
// do nothing
}

View File

@ -26,7 +26,7 @@ class IEventQueue;
//! Proxy for client implementing protocol version 1.2
class CClientProxy1_2 : public CClientProxy1_1 {
public:
CClientProxy1_2(const CString& name, synergy::IStream* adoptedStream, IEventQueue* eventQueue);
CClientProxy1_2(const CString& name, synergy::IStream* adoptedStream, IEventQueue* events);
~CClientProxy1_2();
// IClient overrides

View File

@ -28,8 +28,9 @@
// CClientProxy1_3
//
CClientProxy1_3::CClientProxy1_3(const CString& name, synergy::IStream* stream, IEventQueue* eventQueue) :
CClientProxy1_2(name, stream, eventQueue),
CClientProxy1_3::CClientProxy1_3(const CString& name, synergy::IStream* stream, IEventQueue* events) :
CClientProxy1_2(name, stream, events),
m_events(events),
m_keepAliveRate(kKeepAliveRate),
m_keepAliveTimer(NULL)
{
@ -89,8 +90,8 @@ CClientProxy1_3::addHeartbeatTimer()
{
// create and install a timer to periodically send keep alives
if (m_keepAliveRate > 0.0) {
m_keepAliveTimer = EVENTQUEUE->newTimer(m_keepAliveRate, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_keepAliveTimer,
m_keepAliveTimer = m_events->newTimer(m_keepAliveRate, NULL);
m_events->adoptHandler(CEvent::kTimer, m_keepAliveTimer,
new TMethodEventJob<CClientProxy1_3>(this,
&CClientProxy1_3::handleKeepAlive, NULL));
}
@ -104,8 +105,8 @@ CClientProxy1_3::removeHeartbeatTimer()
{
// remove the timer that sends keep alives periodically
if (m_keepAliveTimer != NULL) {
EVENTQUEUE->removeHandler(CEvent::kTimer, m_keepAliveTimer);
EVENTQUEUE->deleteTimer(m_keepAliveTimer);
m_events->removeHandler(CEvent::kTimer, m_keepAliveTimer);
m_events->deleteTimer(m_keepAliveTimer);
m_keepAliveTimer = NULL;
}

View File

@ -24,7 +24,7 @@
//! Proxy for client implementing protocol version 1.3
class CClientProxy1_3 : public CClientProxy1_2 {
public:
CClientProxy1_3(const CString& name, synergy::IStream* adoptedStream, IEventQueue* eventQueue);
CClientProxy1_3(const CString& name, synergy::IStream* adoptedStream, IEventQueue* events);
~CClientProxy1_3();
// IClient overrides
@ -46,6 +46,7 @@ private:
private:
double m_keepAliveRate;
CEventQueueTimer* m_keepAliveTimer;
IEventQueue* m_events;
};
#endif

View File

@ -30,8 +30,8 @@
// CClientProxy1_4
//
CClientProxy1_4::CClientProxy1_4(const CString& name, synergy::IStream* stream, CServer* server, IEventQueue* eventQueue) :
CClientProxy1_3(name, stream, eventQueue), m_server(server)
CClientProxy1_4::CClientProxy1_4(const CString& name, synergy::IStream* stream, CServer* server, IEventQueue* events) :
CClientProxy1_3(name, stream, events), m_server(server)
{
assert(m_server != NULL);
}

View File

@ -26,7 +26,7 @@ class CServer;
//! Proxy for client implementing protocol version 1.4
class CClientProxy1_4 : public CClientProxy1_3 {
public:
CClientProxy1_4(const CString& name, synergy::IStream* adoptedStream, CServer* server, IEventQueue* eventQueue);
CClientProxy1_4(const CString& name, synergy::IStream* adoptedStream, CServer* server, IEventQueue* events);
~CClientProxy1_4();
// IClient overrides

View File

@ -37,10 +37,8 @@
// CClientProxyUnknown
//
CEvent::Type CClientProxyUnknown::s_successEvent = CEvent::kUnknown;
CEvent::Type CClientProxyUnknown::s_failureEvent = CEvent::kUnknown;
CClientProxyUnknown::CClientProxyUnknown(synergy::IStream* stream, double timeout, CServer* server) :
CClientProxyUnknown::CClientProxyUnknown(synergy::IStream* stream, double timeout, CServer* server, IEventQueue* events) :
m_events(events),
m_stream(stream),
m_proxy(NULL),
m_ready(false),
@ -48,10 +46,10 @@ CClientProxyUnknown::CClientProxyUnknown(synergy::IStream* stream, double timeou
{
assert(m_server != NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, this,
m_events->adoptHandler(CEvent::kTimer, this,
new TMethodEventJob<CClientProxyUnknown>(this,
&CClientProxyUnknown::handleTimeout, NULL));
m_timer = EVENTQUEUE->newOneShotTimer(timeout, this);
m_timer = m_events->newOneShotTimer(timeout, this);
addStreamHandlers();
LOG((CLOG_DEBUG1 "saying hello"));
@ -82,26 +80,12 @@ CClientProxyUnknown::orphanClientProxy()
}
}
CEvent::Type
CClientProxyUnknown::getSuccessEvent()
{
return EVENTQUEUE->registerTypeOnce(s_successEvent,
"CClientProxy::success");
}
CEvent::Type
CClientProxyUnknown::getFailureEvent()
{
return EVENTQUEUE->registerTypeOnce(s_failureEvent,
"CClientProxy::failure");
}
void
CClientProxyUnknown::sendSuccess()
{
m_ready = true;
removeTimer();
EVENTQUEUE->addEvent(CEvent(getSuccessEvent(), this));
m_events->addEvent(CEvent(m_events->forCClientProxyUnknown().success(), this));
}
void
@ -112,7 +96,7 @@ CClientProxyUnknown::sendFailure()
m_ready = false;
removeHandlers();
removeTimer();
EVENTQUEUE->addEvent(CEvent(getFailureEvent(), this));
m_events->addEvent(CEvent(m_events->forCClientProxyUnknown().failure(), this));
}
void
@ -120,19 +104,19 @@ CClientProxyUnknown::addStreamHandlers()
{
assert(m_stream != NULL);
EVENTQUEUE->adoptHandler(m_stream->getInputReadyEvent(),
m_events->adoptHandler(m_events->forIStream().inputReady(),
m_stream->getEventTarget(),
new TMethodEventJob<CClientProxyUnknown>(this,
&CClientProxyUnknown::handleData));
EVENTQUEUE->adoptHandler(m_stream->getOutputErrorEvent(),
m_events->adoptHandler(m_events->forIStream().outputError(),
m_stream->getEventTarget(),
new TMethodEventJob<CClientProxyUnknown>(this,
&CClientProxyUnknown::handleWriteError));
EVENTQUEUE->adoptHandler(m_stream->getInputShutdownEvent(),
m_events->adoptHandler(m_events->forIStream().inputShutdown(),
m_stream->getEventTarget(),
new TMethodEventJob<CClientProxyUnknown>(this,
&CClientProxyUnknown::handleDisconnect));
EVENTQUEUE->adoptHandler(m_stream->getOutputShutdownEvent(),
m_events->adoptHandler(m_events->forIStream().outputShutdown(),
m_stream->getEventTarget(),
new TMethodEventJob<CClientProxyUnknown>(this,
&CClientProxyUnknown::handleWriteError));
@ -143,11 +127,11 @@ CClientProxyUnknown::addProxyHandlers()
{
assert(m_proxy != NULL);
EVENTQUEUE->adoptHandler(CClientProxy::getReadyEvent(),
m_events->adoptHandler(m_events->forCClientProxy().ready(),
m_proxy,
new TMethodEventJob<CClientProxyUnknown>(this,
&CClientProxyUnknown::handleReady));
EVENTQUEUE->adoptHandler(CClientProxy::getDisconnectedEvent(),
m_events->adoptHandler(m_events->forCClientProxy().disconnected(),
m_proxy,
new TMethodEventJob<CClientProxyUnknown>(this,
&CClientProxyUnknown::handleDisconnect));
@ -157,19 +141,19 @@ void
CClientProxyUnknown::removeHandlers()
{
if (m_stream != NULL) {
EVENTQUEUE->removeHandler(m_stream->getInputReadyEvent(),
m_events->removeHandler(m_events->forIStream().inputReady(),
m_stream->getEventTarget());
EVENTQUEUE->removeHandler(m_stream->getOutputErrorEvent(),
m_events->removeHandler(m_events->forIStream().outputError(),
m_stream->getEventTarget());
EVENTQUEUE->removeHandler(m_stream->getInputShutdownEvent(),
m_events->removeHandler(m_events->forIStream().inputShutdown(),
m_stream->getEventTarget());
EVENTQUEUE->removeHandler(m_stream->getOutputShutdownEvent(),
m_events->removeHandler(m_events->forIStream().outputShutdown(),
m_stream->getEventTarget());
}
if (m_proxy != NULL) {
EVENTQUEUE->removeHandler(CClientProxy::getReadyEvent(),
m_events->removeHandler(m_events->forCClientProxy().ready(),
m_proxy);
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(),
m_events->removeHandler(m_events->forCClientProxy().disconnected(),
m_proxy);
}
}
@ -178,8 +162,8 @@ void
CClientProxyUnknown::removeTimer()
{
if (m_timer != NULL) {
EVENTQUEUE->deleteTimer(m_timer);
EVENTQUEUE->removeHandler(CEvent::kTimer, this);
m_events->deleteTimer(m_timer);
m_events->removeHandler(CEvent::kTimer, this);
m_timer = NULL;
}
}
@ -219,23 +203,23 @@ CClientProxyUnknown::handleData(const CEvent&, void*)
if (major == 1) {
switch (minor) {
case 0:
m_proxy = new CClientProxy1_0(name, m_stream, EVENTQUEUE);
m_proxy = new CClientProxy1_0(name, m_stream, m_events);
break;
case 1:
m_proxy = new CClientProxy1_1(name, m_stream, EVENTQUEUE);
m_proxy = new CClientProxy1_1(name, m_stream, m_events);
break;
case 2:
m_proxy = new CClientProxy1_2(name, m_stream, EVENTQUEUE);
m_proxy = new CClientProxy1_2(name, m_stream, m_events);
break;
case 3:
m_proxy = new CClientProxy1_3(name, m_stream, EVENTQUEUE);
m_proxy = new CClientProxy1_3(name, m_stream, m_events);
break;
case 4:
m_proxy = new CClientProxy1_4(name, m_stream, m_server, EVENTQUEUE);
m_proxy = new CClientProxy1_4(name, m_stream, m_server, m_events);
break;
}
}

View File

@ -20,15 +20,17 @@
#define CCLIENTPROXYUNKNOWN_H
#include "CEvent.h"
#include "CEventTypes.h"
class CClientProxy;
class CEventQueueTimer;
namespace synergy { class IStream; }
class CServer;
class IEventQueue;
class CClientProxyUnknown {
public:
CClientProxyUnknown(synergy::IStream* stream, double timeout, CServer* server);
CClientProxyUnknown(synergy::IStream* stream, double timeout, CServer* server, IEventQueue* events);
~CClientProxyUnknown();
//! @name manipulators
@ -43,24 +45,6 @@ public:
CClientProxy* orphanClientProxy();
//@}
//! @name accessors
//@{
//! Get success event type
/*!
Returns the success event type. This is sent when the client has
correctly responded to the hello message. The target is this.
*/
static CEvent::Type getSuccessEvent();
//! Get failure event type
/*!
Returns the failure event type. This is sent when a client fails
to correctly respond to the hello message. The target is this.
*/
static CEvent::Type getFailureEvent();
//@}
private:
void sendSuccess();
@ -80,10 +64,8 @@ private:
CEventQueueTimer* m_timer;
CClientProxy* m_proxy;
bool m_ready;
static CEvent::Type s_successEvent;
static CEvent::Type s_failureEvent;
CServer* m_server;
IEventQueue* m_events;
};
#endif

View File

@ -24,12 +24,16 @@
#include "stdistream.h"
#include "stdostream.h"
#include <cstdlib>
#include "IEventQueue.h"
//
// CConfig
//
CConfig::CConfig() : m_hasLockToScreenAction(false)
CConfig::CConfig(IEventQueue* events) :
m_events(events),
m_hasLockToScreenAction(false),
m_inputFilter(events)
{
// do nothing
}
@ -610,7 +614,7 @@ CConfig::operator!=(const CConfig& x) const
void
CConfig::read(CConfigReadContext& context)
{
CConfig tmp;
CConfig tmp(m_events);
while (context) {
tmp.readSection(context);
}
@ -1048,7 +1052,7 @@ CConfig::parseCondition(CConfigReadContext& s,
IPlatformScreen::CKeyInfo* keyInfo = s.parseKeystroke(args[0]);
return new CInputFilter::CKeystrokeCondition(keyInfo);
return new CInputFilter::CKeystrokeCondition(m_events, keyInfo);
}
if (name == "mousebutton") {
@ -1058,7 +1062,7 @@ CConfig::parseCondition(CConfigReadContext& s,
IPlatformScreen::CButtonInfo* mouseInfo = s.parseMouse(args[0]);
return new CInputFilter::CMouseButtonCondition(mouseInfo);
return new CInputFilter::CMouseButtonCondition(m_events, mouseInfo);
}
if (name == "connect") {
@ -1074,7 +1078,7 @@ CConfig::parseCondition(CConfigReadContext& s,
throw XConfigRead(s, "unknown screen name \"%{1}\" in connect", screen);
}
return new CInputFilter::CScreenConnectedCondition(screen);
return new CInputFilter::CScreenConnectedCondition(m_events, screen);
}
throw XConfigRead(s, "unknown argument \"%{1}\"", name);
@ -1105,16 +1109,16 @@ CConfig::parseAction(CConfigReadContext& s,
if (name == "keystroke") {
IPlatformScreen::CKeyInfo* keyInfo2 =
IKeyState::CKeyInfo::alloc(*keyInfo);
action = new CInputFilter::CKeystrokeAction(keyInfo2, true);
action = new CInputFilter::CKeystrokeAction(m_events, keyInfo2, true);
rule.adoptAction(action, true);
action = new CInputFilter::CKeystrokeAction(keyInfo, false);
action = new CInputFilter::CKeystrokeAction(m_events, keyInfo, false);
activate = false;
}
else if (name == "keyDown") {
action = new CInputFilter::CKeystrokeAction(keyInfo, true);
action = new CInputFilter::CKeystrokeAction(m_events, keyInfo, true);
}
else {
action = new CInputFilter::CKeystrokeAction(keyInfo, false);
action = new CInputFilter::CKeystrokeAction(m_events, keyInfo, false);
}
}
@ -1129,16 +1133,16 @@ CConfig::parseAction(CConfigReadContext& s,
if (name == "mousebutton") {
IPlatformScreen::CButtonInfo* mouseInfo2 =
IPlatformScreen::CButtonInfo::alloc(*mouseInfo);
action = new CInputFilter::CMouseButtonAction(mouseInfo2, true);
action = new CInputFilter::CMouseButtonAction(m_events, mouseInfo2, true);
rule.adoptAction(action, true);
action = new CInputFilter::CMouseButtonAction(mouseInfo, false);
action = new CInputFilter::CMouseButtonAction(m_events, mouseInfo, false);
activate = false;
}
else if (name == "mouseDown") {
action = new CInputFilter::CMouseButtonAction(mouseInfo, true);
action = new CInputFilter::CMouseButtonAction(m_events, mouseInfo, true);
}
else {
action = new CInputFilter::CMouseButtonAction(mouseInfo, false);
action = new CInputFilter::CMouseButtonAction(m_events, mouseInfo, false);
}
}
@ -1167,7 +1171,7 @@ CConfig::parseAction(CConfigReadContext& s,
throw XConfigRead(s, "unknown screen name in switchToScreen");
}
action = new CInputFilter::CSwitchToScreenAction(screen);
action = new CInputFilter::CSwitchToScreenAction(m_events, screen);
}
else if (name == "switchInDirection") {
@ -1192,7 +1196,7 @@ CConfig::parseAction(CConfigReadContext& s,
throw XConfigRead(s, "unknown direction \"%{1}\" in switchToScreen", args[0]);
}
action = new CInputFilter::CSwitchInDirectionAction(direction);
action = new CInputFilter::CSwitchInDirectionAction(m_events, direction);
}
else if (name == "lockCursorToScreen") {
@ -1221,7 +1225,7 @@ CConfig::parseAction(CConfigReadContext& s,
m_hasLockToScreenAction = true;
}
action = new CInputFilter::CLockCursorToScreenAction(mode);
action = new CInputFilter::CLockCursorToScreenAction(m_events, mode);
}
else if (name == "keyboardBroadcast") {
@ -1251,7 +1255,7 @@ CConfig::parseAction(CConfigReadContext& s,
parseScreens(s, args[1], screens);
}
action = new CInputFilter::CKeyboardBroadcastAction(mode, screens);
action = new CInputFilter::CKeyboardBroadcastAction(m_events, mode, screens);
}
else {

View File

@ -32,6 +32,7 @@
class CConfig;
class CConfigReadContext;
class IEventQueue;
namespace std {
template <>
@ -172,7 +173,7 @@ public:
internal_const_iterator m_i;
};
CConfig();
CConfig(IEventQueue* events);
virtual ~CConfig();
//! @name manipulators
@ -468,6 +469,7 @@ private:
CScreenOptions m_globalOptions;
CInputFilter m_inputFilter;
bool m_hasLockToScreenAction;
IEventQueue* m_events;
};
//! Configuration read context

View File

@ -52,7 +52,8 @@ CInputFilter::CCondition::disablePrimary(CPrimaryClient*)
}
CInputFilter::CKeystrokeCondition::CKeystrokeCondition(
IPlatformScreen::CKeyInfo* info) :
IEventQueue* events, IPlatformScreen::CKeyInfo* info) :
m_events(events),
m_id(0),
m_key(info->m_key),
m_mask(info->m_mask)
@ -61,7 +62,8 @@ CInputFilter::CKeystrokeCondition::CKeystrokeCondition(
}
CInputFilter::CKeystrokeCondition::CKeystrokeCondition(
KeyID key, KeyModifierMask mask) :
IEventQueue* events, KeyID key, KeyModifierMask mask) :
m_events(events),
m_id(0),
m_key(key),
m_mask(mask)
@ -89,7 +91,7 @@ CInputFilter::CKeystrokeCondition::getMask() const
CInputFilter::CCondition*
CInputFilter::CKeystrokeCondition::clone() const
{
return new CKeystrokeCondition(m_key, m_mask);
return new CKeystrokeCondition(m_events, m_key, m_mask);
}
CString
@ -106,10 +108,10 @@ CInputFilter::CKeystrokeCondition::match(const CEvent& event)
// check for hotkey events
CEvent::Type type = event.getType();
if (type == IPrimaryScreen::getHotKeyDownEvent()) {
if (type == m_events->forIPrimaryScreen().hotKeyDown()) {
status = kActivate;
}
else if (type == IPrimaryScreen::getHotKeyUpEvent()) {
else if (type == m_events->forIPrimaryScreen().hotKeyUp()) {
status = kDeactivate;
}
else {
@ -140,7 +142,8 @@ CInputFilter::CKeystrokeCondition::disablePrimary(CPrimaryClient* primary)
}
CInputFilter::CMouseButtonCondition::CMouseButtonCondition(
IPlatformScreen::CButtonInfo* info) :
IEventQueue* events, IPlatformScreen::CButtonInfo* info) :
m_events(events),
m_button(info->m_button),
m_mask(info->m_mask)
{
@ -148,7 +151,8 @@ CInputFilter::CMouseButtonCondition::CMouseButtonCondition(
}
CInputFilter::CMouseButtonCondition::CMouseButtonCondition(
ButtonID button, KeyModifierMask mask) :
IEventQueue* events, ButtonID button, KeyModifierMask mask) :
m_events(events),
m_button(button),
m_mask(mask)
{
@ -175,7 +179,7 @@ CInputFilter::CMouseButtonCondition::getMask() const
CInputFilter::CCondition*
CInputFilter::CMouseButtonCondition::clone() const
{
return new CMouseButtonCondition(m_button, m_mask);
return new CMouseButtonCondition(m_events, m_button, m_mask);
}
CString
@ -199,10 +203,10 @@ CInputFilter::CMouseButtonCondition::match(const CEvent& event)
// check for hotkey events
CEvent::Type type = event.getType();
if (type == IPrimaryScreen::getButtonDownEvent()) {
if (type == m_events->forIPrimaryScreen().buttonDown()) {
status = kActivate;
}
else if (type == IPrimaryScreen::getButtonUpEvent()) {
else if (type == m_events->forIPrimaryScreen().buttonUp()) {
status = kDeactivate;
}
else {
@ -222,7 +226,8 @@ CInputFilter::CMouseButtonCondition::match(const CEvent& event)
}
CInputFilter::CScreenConnectedCondition::CScreenConnectedCondition(
const CString& screen) :
IEventQueue* events, const CString& screen) :
m_events(events),
m_screen(screen)
{
// do nothing
@ -236,7 +241,7 @@ CInputFilter::CScreenConnectedCondition::~CScreenConnectedCondition()
CInputFilter::CCondition*
CInputFilter::CScreenConnectedCondition::clone() const
{
return new CScreenConnectedCondition(m_screen);
return new CScreenConnectedCondition(m_events, m_screen);
}
CString
@ -248,7 +253,7 @@ CInputFilter::CScreenConnectedCondition::format() const
CInputFilter::EFilterStatus
CInputFilter::CScreenConnectedCondition::match(const CEvent& event)
{
if (event.getType() == CServer::getConnectedEvent()) {
if (event.getType() == m_events->forCServer().connected()) {
CServer::CScreenConnectedInfo* info =
reinterpret_cast<CServer::CScreenConnectedInfo*>(event.getData());
if (m_screen == info->m_screen || m_screen.empty()) {
@ -272,7 +277,9 @@ CInputFilter::CAction::~CAction()
// do nothing
}
CInputFilter::CLockCursorToScreenAction::CLockCursorToScreenAction(Mode mode) :
CInputFilter::CLockCursorToScreenAction::CLockCursorToScreenAction(
IEventQueue* events, Mode mode) :
m_events(events),
m_mode(mode)
{
// do nothing
@ -310,13 +317,14 @@ CInputFilter::CLockCursorToScreenAction::perform(const CEvent& event)
// send event
CServer::CLockCursorToScreenInfo* info =
CServer::CLockCursorToScreenInfo::alloc(s_state[m_mode]);
EVENTQUEUE->addEvent(CEvent(CServer::getLockCursorToScreenEvent(),
m_events->addEvent(CEvent(m_events->forCServer().lockCursorToScreen(),
event.getTarget(), info,
CEvent::kDeliverImmediately));
}
CInputFilter::CSwitchToScreenAction::CSwitchToScreenAction(
const CString& screen) :
IEventQueue* events, const CString& screen) :
m_events(events),
m_screen(screen)
{
// do nothing
@ -346,7 +354,7 @@ CInputFilter::CSwitchToScreenAction::perform(const CEvent& event)
// pick screen name. if m_screen is empty then use the screen from
// event if it has one.
CString screen = m_screen;
if (screen.empty() && event.getType() == CServer::getConnectedEvent()) {
if (screen.empty() && event.getType() == m_events->forCServer().connected()) {
CServer::CScreenConnectedInfo* info =
reinterpret_cast<CServer::CScreenConnectedInfo*>(event.getData());
screen = info->m_screen;
@ -355,13 +363,14 @@ CInputFilter::CSwitchToScreenAction::perform(const CEvent& event)
// send event
CServer::CSwitchToScreenInfo* info =
CServer::CSwitchToScreenInfo::alloc(screen);
EVENTQUEUE->addEvent(CEvent(CServer::getSwitchToScreenEvent(),
m_events->addEvent(CEvent(m_events->forCServer().switchToScreen(),
event.getTarget(), info,
CEvent::kDeliverImmediately));
}
CInputFilter::CSwitchInDirectionAction::CSwitchInDirectionAction(
EDirection direction) :
IEventQueue* events, EDirection direction) :
m_events(events),
m_direction(direction)
{
// do nothing
@ -398,20 +407,24 @@ CInputFilter::CSwitchInDirectionAction::perform(const CEvent& event)
{
CServer::CSwitchInDirectionInfo* info =
CServer::CSwitchInDirectionInfo::alloc(m_direction);
EVENTQUEUE->addEvent(CEvent(CServer::getSwitchInDirectionEvent(),
m_events->addEvent(CEvent(m_events->forCServer().switchInDirection(),
event.getTarget(), info,
CEvent::kDeliverImmediately));
}
CInputFilter::CKeyboardBroadcastAction::CKeyboardBroadcastAction(Mode mode) :
CInputFilter::CKeyboardBroadcastAction::CKeyboardBroadcastAction(
IEventQueue* events, Mode mode) :
m_events(events),
m_mode(mode)
{
// do nothing
}
CInputFilter::CKeyboardBroadcastAction::CKeyboardBroadcastAction(
IEventQueue* events,
Mode mode,
const std::set<CString>& screens) :
m_events(events),
m_mode(mode),
m_screens(IKeyState::CKeyInfo::join(screens))
{
@ -466,13 +479,14 @@ CInputFilter::CKeyboardBroadcastAction::perform(const CEvent& event)
// send event
CServer::CKeyboardBroadcastInfo* info =
CServer::CKeyboardBroadcastInfo::alloc(s_state[m_mode], m_screens);
EVENTQUEUE->addEvent(CEvent(CServer::getKeyboardBroadcastEvent(),
m_events->addEvent(CEvent(m_events->forCServer().keyboardBroadcast(),
event.getTarget(), info,
CEvent::kDeliverImmediately));
}
CInputFilter::CKeystrokeAction::CKeystrokeAction(
IPlatformScreen::CKeyInfo* info, bool press) :
IEventQueue* events, IPlatformScreen::CKeyInfo* info, bool press) :
m_events(events),
m_keyInfo(info),
m_press(press)
{
@ -507,7 +521,7 @@ CInputFilter::CAction*
CInputFilter::CKeystrokeAction::clone() const
{
IKeyState::CKeyInfo* info = IKeyState::CKeyInfo::alloc(*m_keyInfo);
return new CKeystrokeAction(info, m_press);
return new CKeystrokeAction(m_events, info, m_press);
}
CString
@ -537,15 +551,17 @@ CInputFilter::CKeystrokeAction::format() const
void
CInputFilter::CKeystrokeAction::perform(const CEvent& event)
{
CEvent::Type type = m_press ? IPlatformScreen::getKeyDownEvent(*EVENTQUEUE) :
IPlatformScreen::getKeyUpEvent(*EVENTQUEUE);
EVENTQUEUE->addEvent(CEvent(IPlatformScreen::getFakeInputBeginEvent(),
CEvent::Type type = m_press ?
m_events->forIKeyState().keyDown() :
m_events->forIKeyState().keyUp();
m_events->addEvent(CEvent(m_events->forIPrimaryScreen().fakeInputBegin(),
event.getTarget(), NULL,
CEvent::kDeliverImmediately));
EVENTQUEUE->addEvent(CEvent(type, event.getTarget(), m_keyInfo,
m_events->addEvent(CEvent(type, event.getTarget(), m_keyInfo,
CEvent::kDeliverImmediately |
CEvent::kDontFreeData));
EVENTQUEUE->addEvent(CEvent(IPlatformScreen::getFakeInputEndEvent(),
m_events->addEvent(CEvent(m_events->forIPrimaryScreen().fakeInputEnd(),
event.getTarget(), NULL,
CEvent::kDeliverImmediately));
}
@ -557,7 +573,8 @@ CInputFilter::CKeystrokeAction::formatName() const
}
CInputFilter::CMouseButtonAction::CMouseButtonAction(
IPlatformScreen::CButtonInfo* info, bool press) :
IEventQueue* events, IPlatformScreen::CButtonInfo* info, bool press) :
m_events(events),
m_buttonInfo(info),
m_press(press)
{
@ -586,7 +603,7 @@ CInputFilter::CMouseButtonAction::clone() const
{
IPlatformScreen::CButtonInfo* info =
IPrimaryScreen::CButtonInfo::alloc(*m_buttonInfo);
return new CMouseButtonAction(info, m_press);
return new CMouseButtonAction(m_events, info, m_press);
}
CString
@ -610,15 +627,15 @@ CInputFilter::CMouseButtonAction::perform(const CEvent& event)
KeyID key = m_press ? kKeySetModifiers : kKeyClearModifiers;
modifierInfo =
IKeyState::CKeyInfo::alloc(key, m_buttonInfo->m_mask, 0, 1);
EVENTQUEUE->addEvent(CEvent(IPlatformScreen::getKeyDownEvent(*EVENTQUEUE),
m_events->addEvent(CEvent(m_events->forIKeyState().keyDown(),
event.getTarget(), modifierInfo,
CEvent::kDeliverImmediately));
}
// send button
CEvent::Type type = m_press ? IPlatformScreen::getButtonDownEvent() :
IPlatformScreen::getButtonUpEvent();
EVENTQUEUE->addEvent(CEvent(type, event.getTarget(), m_buttonInfo,
CEvent::Type type = m_press ? m_events->forIPrimaryScreen().buttonDown() :
m_events->forIPrimaryScreen().buttonUp();
m_events->addEvent(CEvent(type, event.getTarget(), m_buttonInfo,
CEvent::kDeliverImmediately |
CEvent::kDontFreeData));
}
@ -869,13 +886,15 @@ CInputFilter::CRule::getAction(bool onActivation, UInt32 index) const
// -----------------------------------------------------------------------------
// Input Filter Class
// -----------------------------------------------------------------------------
CInputFilter::CInputFilter() :
CInputFilter::CInputFilter(IEventQueue* events) :
m_events(events),
m_primaryClient(NULL)
{
// do nothing
}
CInputFilter::CInputFilter(const CInputFilter& x) :
m_events(x.m_events),
m_ruleList(x.m_ruleList),
m_primaryClient(NULL)
{
@ -938,56 +957,56 @@ CInputFilter::setPrimaryClient(CPrimaryClient* client)
rule->disable(m_primaryClient);
}
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyDownEvent(*EVENTQUEUE),
m_events->removeHandler(m_events->forIKeyState().keyDown(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyUpEvent(*EVENTQUEUE),
m_events->removeHandler(m_events->forIKeyState().keyUp(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyRepeatEvent(*EVENTQUEUE),
m_events->removeHandler(m_events->forIKeyState().keyRepeat(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getButtonDownEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().buttonDown(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getButtonUpEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().buttonUp(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getHotKeyDownEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().hotKeyDown(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getHotKeyUpEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().hotKeyUp(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(CServer::getConnectedEvent(),
m_events->removeHandler(m_events->forCServer().connected(),
m_primaryClient->getEventTarget());
}
m_primaryClient = client;
if (m_primaryClient != NULL) {
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyDownEvent(*EVENTQUEUE),
m_events->adoptHandler(m_events->forIKeyState().keyDown(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyUpEvent(*EVENTQUEUE),
m_events->adoptHandler(m_events->forIKeyState().keyUp(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyRepeatEvent(*EVENTQUEUE),
m_events->adoptHandler(m_events->forIKeyState().keyRepeat(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonDownEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().buttonDown(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonUpEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().buttonUp(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getHotKeyDownEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().hotKeyDown(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getHotKeyUpEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().hotKeyUp(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
EVENTQUEUE->adoptHandler(CServer::getConnectedEvent(),
m_events->adoptHandler(m_events->forCServer().connected(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CInputFilter>(this,
&CInputFilter::handleEvent));
@ -1066,5 +1085,5 @@ CInputFilter::handleEvent(const CEvent& event, void*)
}
// not handled so pass through
EVENTQUEUE->addEvent(myEvent);
m_events->addEvent(myEvent);
}

View File

@ -29,6 +29,7 @@
class CPrimaryClient;
class CEvent;
class IEventQueue;
class CInputFilter {
public:
@ -58,8 +59,8 @@ public:
// CKeystrokeCondition
class CKeystrokeCondition : public CCondition {
public:
CKeystrokeCondition(IPlatformScreen::CKeyInfo*);
CKeystrokeCondition(KeyID key, KeyModifierMask mask);
CKeystrokeCondition(IEventQueue* events, IPlatformScreen::CKeyInfo*);
CKeystrokeCondition(IEventQueue* events, KeyID key, KeyModifierMask mask);
virtual ~CKeystrokeCondition();
KeyID getKey() const;
@ -76,13 +77,14 @@ public:
UInt32 m_id;
KeyID m_key;
KeyModifierMask m_mask;
IEventQueue* m_events;
};
// CMouseButtonCondition
class CMouseButtonCondition : public CCondition {
public:
CMouseButtonCondition(IPlatformScreen::CButtonInfo*);
CMouseButtonCondition(ButtonID, KeyModifierMask mask);
CMouseButtonCondition(IEventQueue* events, IPlatformScreen::CButtonInfo*);
CMouseButtonCondition(IEventQueue* events, ButtonID, KeyModifierMask mask);
virtual ~CMouseButtonCondition();
ButtonID getButton() const;
@ -96,12 +98,13 @@ public:
private:
ButtonID m_button;
KeyModifierMask m_mask;
IEventQueue* m_events;
};
// CScreenConnectedCondition
class CScreenConnectedCondition : public CCondition {
public:
CScreenConnectedCondition(const CString& screen);
CScreenConnectedCondition(IEventQueue* events, const CString& screen);
virtual ~CScreenConnectedCondition();
// CCondition overrides
@ -111,6 +114,7 @@ public:
private:
CString m_screen;
IEventQueue* m_events;
};
// -------------------------------------------------------------------------
@ -133,7 +137,7 @@ public:
public:
enum Mode { kOff, kOn, kToggle };
CLockCursorToScreenAction(Mode = kToggle);
CLockCursorToScreenAction(IEventQueue* events, Mode = kToggle);
Mode getMode() const;
@ -144,12 +148,13 @@ public:
private:
Mode m_mode;
IEventQueue* m_events;
};
// CSwitchToScreenAction
class CSwitchToScreenAction : public CAction {
public:
CSwitchToScreenAction(const CString& screen);
CSwitchToScreenAction(IEventQueue* events, const CString& screen);
CString getScreen() const;
@ -160,12 +165,13 @@ public:
private:
CString m_screen;
IEventQueue* m_events;
};
// CSwitchInDirectionAction
class CSwitchInDirectionAction : public CAction {
public:
CSwitchInDirectionAction(EDirection);
CSwitchInDirectionAction(IEventQueue* events, EDirection);
EDirection getDirection() const;
@ -176,6 +182,7 @@ public:
private:
EDirection m_direction;
IEventQueue* m_events;
};
// CKeyboardBroadcastAction
@ -183,8 +190,8 @@ public:
public:
enum Mode { kOff, kOn, kToggle };
CKeyboardBroadcastAction(Mode = kToggle);
CKeyboardBroadcastAction(Mode, const std::set<CString>& screens);
CKeyboardBroadcastAction(IEventQueue* events, Mode = kToggle);
CKeyboardBroadcastAction(IEventQueue* events, Mode, const std::set<CString>& screens);
Mode getMode() const;
std::set<CString> getScreens() const;
@ -197,12 +204,13 @@ public:
private:
Mode m_mode;
CString m_screens;
IEventQueue* m_events;
};
// CKeystrokeAction
class CKeystrokeAction : public CAction {
public:
CKeystrokeAction(IPlatformScreen::CKeyInfo* adoptedInfo, bool press);
CKeystrokeAction(IEventQueue* events, IPlatformScreen::CKeyInfo* adoptedInfo, bool press);
~CKeystrokeAction();
void adoptInfo(IPlatformScreen::CKeyInfo*);
@ -221,12 +229,14 @@ public:
private:
IPlatformScreen::CKeyInfo* m_keyInfo;
bool m_press;
IEventQueue* m_events;
};
// CMouseButtonAction -- modifier combinations not implemented yet
class CMouseButtonAction : public CAction {
public:
CMouseButtonAction(IPlatformScreen::CButtonInfo* adoptedInfo,
CMouseButtonAction(IEventQueue* events,
IPlatformScreen::CButtonInfo* adoptedInfo,
bool press);
~CMouseButtonAction();
@ -245,6 +255,7 @@ public:
private:
IPlatformScreen::CButtonInfo* m_buttonInfo;
bool m_press;
IEventQueue* m_events;
};
class CRule {
@ -306,7 +317,7 @@ public:
// -------------------------------------------------------------------------
typedef std::vector<CRule> CRuleList;
CInputFilter();
CInputFilter(IEventQueue* events);
CInputFilter(const CInputFilter&);
virtual ~CInputFilter();
@ -343,6 +354,7 @@ private:
private:
CRuleList m_ruleList;
CPrimaryClient* m_primaryClient;
IEventQueue* m_events;
};
#endif

View File

@ -41,16 +41,8 @@
// CServer
//
CEvent::Type CServer::s_errorEvent = CEvent::kUnknown;
CEvent::Type CServer::s_connectedEvent = CEvent::kUnknown;
CEvent::Type CServer::s_disconnectedEvent = CEvent::kUnknown;
CEvent::Type CServer::s_switchToScreen = CEvent::kUnknown;
CEvent::Type CServer::s_switchInDirection = CEvent::kUnknown;
CEvent::Type CServer::s_keyboardBroadcast = CEvent::kUnknown;
CEvent::Type CServer::s_lockCursorToScreen = CEvent::kUnknown;
CEvent::Type CServer::s_screenSwitched = CEvent::kUnknown;
CServer::CServer(const CConfig& config, CPrimaryClient* primaryClient, CScreen* screen) :
CServer::CServer(const CConfig& config, CPrimaryClient* primaryClient, CScreen* screen, IEventQueue* events) :
m_events(events),
m_mock(false),
m_primaryClient(primaryClient),
m_active(primaryClient),
@ -59,7 +51,7 @@ CServer::CServer(const CConfig& config, CPrimaryClient* primaryClient, CScreen*
m_yDelta(0),
m_xDelta2(0),
m_yDelta2(0),
m_config(),
m_config(events),
m_inputFilter(m_config.getInputFilter()),
m_activeSaver(NULL),
m_switchDir(kNoDirection),
@ -98,86 +90,86 @@ CServer::CServer(const CConfig& config, CPrimaryClient* primaryClient, CScreen*
}
// install event handlers
EVENTQUEUE->adoptHandler(CEvent::kTimer, this,
m_events->adoptHandler(CEvent::kTimer, this,
new TMethodEventJob<CServer>(this,
&CServer::handleSwitchWaitTimeout));
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyDownEvent(*EVENTQUEUE),
m_events->adoptHandler(m_events->forIKeyState().keyDown(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleKeyDownEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyUpEvent(*EVENTQUEUE),
m_events->adoptHandler(m_events->forIKeyState().keyUp(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleKeyUpEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyRepeatEvent(* EVENTQUEUE),
m_events->adoptHandler(m_events->forIKeyState().keyRepeat(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleKeyRepeatEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonDownEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().buttonDown(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleButtonDownEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonUpEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().buttonUp(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleButtonUpEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getMotionOnPrimaryEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().motionOnPrimary(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleMotionPrimaryEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getMotionOnSecondaryEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().motionOnSecondary(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleMotionSecondaryEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getWheelEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().wheel(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleWheelEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getGameDeviceButtonsEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().gameDeviceButtons(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleGameDeviceButtons));
EVENTQUEUE->adoptHandler(IPlatformScreen::getGameDeviceSticksEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().gameDeviceSticks(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleGameDeviceSticks));
EVENTQUEUE->adoptHandler(IPlatformScreen::getGameDeviceTriggersEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().gameDeviceTriggers(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleGameDeviceTriggers));
EVENTQUEUE->adoptHandler(IPlatformScreen::getGameDeviceTimingReqEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().gameDeviceTimingReq(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleGameDeviceTimingReq));
EVENTQUEUE->adoptHandler(IPlatformScreen::getScreensaverActivatedEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().screensaverActivated(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleScreensaverActivatedEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getScreensaverDeactivatedEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().screensaverDeactivated(),
m_primaryClient->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleScreensaverDeactivatedEvent));
EVENTQUEUE->adoptHandler(getSwitchToScreenEvent(),
m_events->adoptHandler(m_events->forCServer().switchToScreen(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleSwitchToScreenEvent));
EVENTQUEUE->adoptHandler(getSwitchInDirectionEvent(),
m_events->adoptHandler(m_events->forCServer().switchInDirection(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleSwitchInDirectionEvent));
EVENTQUEUE->adoptHandler(getKeyboardBroadcastEvent(),
m_events->adoptHandler(m_events->forCServer().keyboardBroadcast(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleKeyboardBroadcastEvent));
EVENTQUEUE->adoptHandler(getLockCursorToScreenEvent(),
m_events->adoptHandler(m_events->forCServer().lockCursorToScreen(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleLockCursorToScreenEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getFakeInputBeginEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().fakeInputBegin(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleFakeInputBeginEvent));
EVENTQUEUE->adoptHandler(IPlatformScreen::getFakeInputEndEvent(),
m_events->adoptHandler(m_events->forIPrimaryScreen().fakeInputEnd(),
m_inputFilter,
new TMethodEventJob<CServer>(this,
&CServer::handleFakeInputEndEvent));
@ -208,31 +200,31 @@ CServer::~CServer()
}
// remove event handlers and timers
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyDownEvent(*EVENTQUEUE),
m_events->removeHandler(m_events->forIKeyState().keyDown(),
m_inputFilter);
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyUpEvent(*EVENTQUEUE),
m_events->removeHandler(m_events->forIKeyState().keyUp(),
m_inputFilter);
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyRepeatEvent(*EVENTQUEUE),
m_events->removeHandler(m_events->forIKeyState().keyRepeat(),
m_inputFilter);
EVENTQUEUE->removeHandler(IPlatformScreen::getButtonDownEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().buttonDown(),
m_inputFilter);
EVENTQUEUE->removeHandler(IPlatformScreen::getButtonUpEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().buttonUp(),
m_inputFilter);
EVENTQUEUE->removeHandler(IPlatformScreen::getMotionOnPrimaryEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().motionOnPrimary(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getMotionOnSecondaryEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().motionOnSecondary(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getWheelEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().wheel(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getScreensaverActivatedEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().screensaverActivated(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getScreensaverDeactivatedEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().screensaverDeactivated(),
m_primaryClient->getEventTarget());
EVENTQUEUE->removeHandler(IPlatformScreen::getFakeInputBeginEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().fakeInputBegin(),
m_inputFilter);
EVENTQUEUE->removeHandler(IPlatformScreen::getFakeInputEndEvent(),
m_events->removeHandler(m_events->forIPrimaryScreen().fakeInputEnd(),
m_inputFilter);
EVENTQUEUE->removeHandler(CEvent::kTimer, this);
m_events->removeHandler(CEvent::kTimer, this);
stopSwitch();
// force immediate disconnection of secondary clients
@ -240,9 +232,9 @@ CServer::~CServer()
for (COldClients::iterator index = m_oldClients.begin();
index != m_oldClients.begin(); ++index) {
CBaseClientProxy* client = index->first;
EVENTQUEUE->deleteTimer(index->second);
EVENTQUEUE->removeHandler(CEvent::kTimer, client);
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(), client);
m_events->deleteTimer(index->second);
m_events->removeHandler(CEvent::kTimer, client);
m_events->removeHandler(m_events->forCClientProxy().disconnected(), client);
delete client;
}
@ -280,8 +272,8 @@ CServer::setConfig(const CConfig& config)
if (!m_config.hasLockToScreenAction()) {
IPlatformScreen::CKeyInfo* key =
IPlatformScreen::CKeyInfo::alloc(kKeyScrollLock, 0, 0, 0);
CInputFilter::CRule rule(new CInputFilter::CKeystrokeCondition(key));
rule.adoptAction(new CInputFilter::CLockCursorToScreenAction, true);
CInputFilter::CRule rule(new CInputFilter::CKeystrokeCondition(m_events, key));
rule.adoptAction(new CInputFilter::CLockCursorToScreenAction(m_events), true);
m_inputFilter->addFilterRule(rule);
}
@ -304,7 +296,7 @@ CServer::adoptClient(CBaseClientProxy* client)
assert(client != NULL);
// watch for client disconnection
EVENTQUEUE->adoptHandler(CClientProxy::getDisconnectedEvent(), client,
m_events->adoptHandler(m_events->forCClientProxy().disconnected(), client,
new TMethodEventJob<CServer>(this,
&CServer::handleClientDisconnected, client));
@ -335,7 +327,7 @@ CServer::adoptClient(CBaseClientProxy* client)
// send notification
CServer::CScreenConnectedInfo* info =
new CServer::CScreenConnectedInfo(getName(client));
EVENTQUEUE->addEvent(CEvent(CServer::getConnectedEvent(),
m_events->addEvent(CEvent(m_events->forCServer().connected(),
m_primaryClient->getEventTarget(), info));
}
@ -344,11 +336,11 @@ CServer::disconnect()
{
// close all secondary clients
if (m_clients.size() > 1 || !m_oldClients.empty()) {
CConfig emptyConfig;
CConfig emptyConfig(m_events);
closeClients(emptyConfig);
}
else {
EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), this));
m_events->addEvent(CEvent(m_events->forCServer().disconnected(), this));
}
}
@ -380,62 +372,6 @@ CServer::getClients(std::vector<CString>& list) const
}
}
CEvent::Type
CServer::getErrorEvent()
{
return EVENTQUEUE->registerTypeOnce(s_errorEvent,
"CServer::error");
}
CEvent::Type
CServer::getConnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_connectedEvent,
"CServer::connected");
}
CEvent::Type
CServer::getDisconnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_disconnectedEvent,
"CServer::disconnected");
}
CEvent::Type
CServer::getSwitchToScreenEvent()
{
return EVENTQUEUE->registerTypeOnce(s_switchToScreen,
"CServer::switchToScreen");
}
CEvent::Type
CServer::getSwitchInDirectionEvent()
{
return EVENTQUEUE->registerTypeOnce(s_switchInDirection,
"CServer::switchInDirection");
}
CEvent::Type
CServer::getKeyboardBroadcastEvent()
{
return EVENTQUEUE->registerTypeOnce(s_keyboardBroadcast,
"CServer:keyboardBroadcast");
}
CEvent::Type
CServer::getLockCursorToScreenEvent()
{
return EVENTQUEUE->registerTypeOnce(s_lockCursorToScreen,
"CServer::lockCursorToScreen");
}
CEvent::Type
CServer::getScreenSwitchedEvent()
{
return EVENTQUEUE->registerTypeOnce(s_screenSwitched,
"CServer::screenSwitched");
}
CString
CServer::getName(const CBaseClientProxy* client) const
{
@ -571,7 +507,7 @@ CServer::switchScreen(CBaseClientProxy* dst,
CServer::CSwitchToScreenInfo* info =
CServer::CSwitchToScreenInfo::alloc(m_active->getName());
EVENTQUEUE->addEvent(CEvent(CServer::getScreenSwitchedEvent(), this, info));
m_events->addEvent(CEvent(m_events->forCServer().screenSwitched(), this, info));
}
else {
m_active->mouseMove(x, y);
@ -1052,7 +988,7 @@ CServer::startSwitchWait(SInt32 x, SInt32 y)
stopSwitchWait();
m_switchWaitX = x;
m_switchWaitY = y;
m_switchWaitTimer = EVENTQUEUE->newOneShotTimer(m_switchWaitDelay, this);
m_switchWaitTimer = m_events->newOneShotTimer(m_switchWaitDelay, this);
LOG((CLOG_DEBUG1 "waiting to switch"));
}
@ -1060,7 +996,7 @@ void
CServer::stopSwitchWait()
{
if (m_switchWaitTimer != NULL) {
EVENTQUEUE->deleteTimer(m_switchWaitTimer);
m_events->deleteTimer(m_switchWaitTimer);
m_switchWaitTimer = NULL;
}
}
@ -2043,15 +1979,15 @@ CServer::addClient(CBaseClientProxy* client)
}
// add event handlers
EVENTQUEUE->adoptHandler(IScreen::getShapeChangedEvent(),
m_events->adoptHandler(m_events->forIScreen().shapeChanged(),
client->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleShapeChanged, client));
EVENTQUEUE->adoptHandler(IScreen::getClipboardGrabbedEvent(),
m_events->adoptHandler(m_events->forIScreen().clipboardGrabbed(),
client->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleClipboardGrabbed, client));
EVENTQUEUE->adoptHandler(CClientProxy::getClipboardChangedEvent(),
m_events->adoptHandler(m_events->forCClientProxy().clipboardChanged(),
client->getEventTarget(),
new TMethodEventJob<CServer>(this,
&CServer::handleClipboardChanged, client));
@ -2081,11 +2017,11 @@ CServer::removeClient(CBaseClientProxy* client)
}
// remove event handlers
EVENTQUEUE->removeHandler(IScreen::getShapeChangedEvent(),
m_events->removeHandler(m_events->forIScreen().shapeChanged(),
client->getEventTarget());
EVENTQUEUE->removeHandler(IScreen::getClipboardGrabbedEvent(),
m_events->removeHandler(m_events->forIScreen().clipboardGrabbed(),
client->getEventTarget());
EVENTQUEUE->removeHandler(CClientProxy::getClipboardChangedEvent(),
m_events->removeHandler(m_events->forCClientProxy().clipboardChanged(),
client->getEventTarget());
// remove from list
@ -2117,8 +2053,8 @@ CServer::closeClient(CBaseClientProxy* client, const char* msg)
// install timer. wait timeout seconds for client to close.
double timeout = 5.0;
CEventQueueTimer* timer = EVENTQUEUE->newOneShotTimer(timeout, NULL);
EVENTQUEUE->adoptHandler(CEvent::kTimer, timer,
CEventQueueTimer* timer = m_events->newOneShotTimer(timeout, NULL);
m_events->adoptHandler(CEvent::kTimer, timer,
new TMethodEventJob<CServer>(this,
&CServer::handleClientCloseTimeout, client));
@ -2161,9 +2097,9 @@ CServer::removeActiveClient(CBaseClientProxy* client)
{
if (removeClient(client)) {
forceLeaveClient(client);
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(), client);
m_events->removeHandler(m_events->forCClientProxy().disconnected(), client);
if (m_clients.size() == 1 && m_oldClients.empty()) {
EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), this));
m_events->addEvent(CEvent(m_events->forCServer().disconnected(), this));
}
}
}
@ -2173,12 +2109,12 @@ CServer::removeOldClient(CBaseClientProxy* client)
{
COldClients::iterator i = m_oldClients.find(client);
if (i != m_oldClients.end()) {
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(), client);
EVENTQUEUE->removeHandler(CEvent::kTimer, i->second);
EVENTQUEUE->deleteTimer(i->second);
m_events->removeHandler(m_events->forCClientProxy().disconnected(), client);
m_events->removeHandler(CEvent::kTimer, i->second);
m_events->deleteTimer(i->second);
m_oldClients.erase(i);
if (m_clients.size() == 1 && m_oldClients.empty()) {
EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), this));
m_events->addEvent(CEvent(m_events->forCServer().disconnected(), this));
}
}
}

View File

@ -30,12 +30,14 @@
#include "stdset.h"
#include "stdvector.h"
#include "INode.h"
#include "CEventTypes.h"
class CBaseClientProxy;
class CEventQueueTimer;
class CPrimaryClient;
class CInputFilter;
class CScreen;
class IEventQueue;
//! Synergy server
/*!
@ -101,11 +103,11 @@ public:
client (local screen) \p primaryClient. The client retains
ownership of \p primaryClient.
*/
CServer(const CConfig& config, CPrimaryClient* primaryClient, CScreen* screen);
CServer(const CConfig& config, CPrimaryClient* primaryClient, CScreen* screen, IEventQueue* events);
~CServer();
#ifdef TEST_ENV
CServer() { }
CServer() : m_mock(true), m_events(NULL), m_config(NULL) { }
#endif
//! @name manipulators
@ -157,67 +159,6 @@ public:
*/
void getClients(std::vector<CString>& list) const;
//! Get error event type
/*!
Returns the error event type. This is sent when the server fails
for some reason.
*/
static CEvent::Type getErrorEvent();
//! Get connected event type
/*!
Returns the connected event type. This is sent when a client screen
has connected. The event data is a \c CScreenConnectedInfo* that
indicates the connected screen.
*/
static CEvent::Type getConnectedEvent();
//! Get disconnected event type
/*!
Returns the disconnected event type. This is sent when all the
clients have disconnected.
*/
static CEvent::Type getDisconnectedEvent();
//! Get switch to screen event type
/*!
Returns the switch to screen event type. The server responds to this
by switching screens. The event data is a \c CSwitchToScreenInfo*
that indicates the target screen.
*/
static CEvent::Type getSwitchToScreenEvent();
//! Get switch in direction event type
/*!
Returns the switch in direction event type. The server responds to this
by switching screens. The event data is a \c CSwitchInDirectionInfo*
that indicates the target direction.
*/
static CEvent::Type getSwitchInDirectionEvent();
//! Get keyboard broadcast event type
/*!
Returns the keyboard broadcast event type. The server responds
to this by turning on keyboard broadcasting or turning it off. The
event data is a \c CKeyboardBroadcastInfo*.
*/
static CEvent::Type getKeyboardBroadcastEvent();
//! Get lock cursor event type
/*!
Returns the lock cursor event type. The server responds to this
by locking the cursor to the active screen or unlocking it. The
event data is a \c CLockCursorToScreenInfo*.
*/
static CEvent::Type getLockCursorToScreenEvent();
//! Get screen switched event type
/*!
Returns the screen switched event type. This is raised when the
screen has been switched to a client.
*/
static CEvent::Type getScreenSwitchedEvent();
//@}
private:
@ -493,14 +434,7 @@ private:
// server screen
CScreen* m_screen;
static CEvent::Type s_errorEvent;
static CEvent::Type s_connectedEvent;
static CEvent::Type s_disconnectedEvent;
static CEvent::Type s_switchToScreen;
static CEvent::Type s_switchInDirection;
static CEvent::Type s_keyboardBroadcast;
static CEvent::Type s_lockCursorToScreen;
static CEvent::Type s_screenSwitched;
IEventQueue* m_events;
};
#endif

View File

@ -47,13 +47,15 @@
CApp* CApp::s_instance = nullptr;
CApp::CApp(CreateTaskBarReceiverFunc createTaskBarReceiver, CArgsBase* args) :
m_createTaskBarReceiver(createTaskBarReceiver),
m_args(args),
m_bye(&exit),
m_taskBarReceiver(NULL),
m_suspended(false),
m_ipcClient(nullptr)
CApp::CApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver, CArgsBase* args) :
m_events(events),
m_createTaskBarReceiver(createTaskBarReceiver),
m_args(args),
m_bye(&exit),
m_taskBarReceiver(NULL),
m_suspended(false),
m_ipcClient(nullptr),
m_appUtil(events)
{
assert(s_instance == nullptr);
s_instance = this;
@ -348,18 +350,18 @@ CApp::initApp(int argc, const char** argv)
// make the task bar receiver. the user can control this app
// through the task bar.
m_taskBarReceiver = m_createTaskBarReceiver(logBuffer);
m_taskBarReceiver = m_createTaskBarReceiver(logBuffer, m_events);
}
}
void
CApp::initIpcClient()
{
m_ipcClient = new CIpcClient();
m_ipcClient = new CIpcClient(m_events);
m_ipcClient->connect();
EVENTQUEUE->adoptHandler(
CIpcClient::getMessageReceivedEvent(), m_ipcClient,
m_events->adoptHandler(
m_events->forCIpcClient().messageReceived(), m_ipcClient,
new TMethodEventJob<CApp>(this, &CApp::handleIpcMessage));
}
@ -367,7 +369,7 @@ void
CApp::cleanupIpcClient()
{
m_ipcClient->disconnect();
EVENTQUEUE->removeHandler(CIpcClient::getMessageReceivedEvent(), m_ipcClient);
m_events->removeHandler(m_events->forCIpcClient().messageReceived(), m_ipcClient);
delete m_ipcClient;
}
@ -377,6 +379,6 @@ CApp::handleIpcMessage(const CEvent& e, void*)
CIpcMessage* m = static_cast<CIpcMessage*>(e.getDataObject());
if (m->type() == kIpcShutdown) {
LOG((CLOG_INFO "got ipc shutdown message"));
EVENTQUEUE->addEvent(CEvent(CEvent::kQuit));
m_events->addEvent(CEvent(CEvent::kQuit));
}
}

View File

@ -34,12 +34,13 @@ class CBufferedLogOutputter;
class ILogOutputter;
class CFileLogOutputter;
class CScreen;
class IEventQueue;
typedef IArchTaskBarReceiver* (*CreateTaskBarReceiverFunc)(const CBufferedLogOutputter*);
typedef IArchTaskBarReceiver* (*CreateTaskBarReceiverFunc)(const CBufferedLogOutputter*, IEventQueue* events);
class CApp : public IApp {
public:
CApp(CreateTaskBarReceiverFunc createTaskBarReceiver, CArgsBase* args);
CApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver, CArgsBase* args);
virtual ~CApp();
// Returns args that are common between server and client.
@ -94,6 +95,8 @@ public:
virtual void setByeFunc(void(*bye)(int)) { m_bye = bye; }
virtual void bye(int error) { m_bye(error); }
virtual IEventQueue* events() const { return m_events; }
private:
void handleIpcMessage(const CEvent&, void*);
@ -113,6 +116,7 @@ private:
CreateTaskBarReceiverFunc m_createTaskBarReceiver;
ARCH_APP_UTIL m_appUtil;
CIpcClient* m_ipcClient;
IEventQueue* m_events;
};
#define BYE "\nTry `%s --help' for more information."

Some files were not shown because too many files have changed in this diff Show More