diff --git a/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp b/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp index 92075dd2..e10f74ff 100644 --- a/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp +++ b/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp @@ -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); } diff --git a/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.h b/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.h index 9b4b0834..92368477 100644 --- a/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.h +++ b/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.h @@ -25,11 +25,12 @@ #include 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[]; }; diff --git a/src/cmd/synergyc/synergyc.cpp b/src/cmd/synergyc/synergyc.cpp index eccf8b9a..0f9f2434 100644 --- a/src/cmd/synergyc/synergyc.cpp +++ b/src/cmd/synergyc/synergyc.cpp @@ -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); } diff --git a/src/cmd/synergyp/CMSWindowsPortableTaskBarReceiver.cpp b/src/cmd/synergyp/CMSWindowsPortableTaskBarReceiver.cpp index 80ffbf06..6f905720 100644 --- a/src/cmd/synergyp/CMSWindowsPortableTaskBarReceiver.cpp +++ b/src/cmd/synergyp/CMSWindowsPortableTaskBarReceiver.cpp @@ -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); } diff --git a/src/cmd/synergyp/CMSWindowsPortableTaskBarReceiver.h b/src/cmd/synergyp/CMSWindowsPortableTaskBarReceiver.h index 88832ae3..cc46d7c5 100644 --- a/src/cmd/synergyp/CMSWindowsPortableTaskBarReceiver.h +++ b/src/cmd/synergyp/CMSWindowsPortableTaskBarReceiver.h @@ -24,11 +24,12 @@ #include 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[]; }; diff --git a/src/cmd/synergyp/synergyp.cpp b/src/cmd/synergyp/synergyp.cpp index eacd530c..af1d1886 100644 --- a/src/cmd/synergyp/synergyp.cpp +++ b/src/cmd/synergyp/synergyp.cpp @@ -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); } diff --git a/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp b/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp index a2fb9589..f8b5d855 100644 --- a/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp +++ b/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp @@ -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); } diff --git a/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.h b/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.h index 321b767b..76c89522 100644 --- a/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.h +++ b/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.h @@ -25,11 +25,12 @@ #include 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[]; }; diff --git a/src/cmd/synergys/synergys.cpp b/src/cmd/synergys/synergys.cpp index 1fba56ba..d6e744df 100644 --- a/src/cmd/synergys/synergys.cpp +++ b/src/cmd/synergys/synergys.cpp @@ -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); } diff --git a/src/lib/arch/CArchPluginUnix.cpp b/src/lib/arch/CArchPluginUnix.cpp index d0a082b6..dad2d339 100644 --- a/src/lib/arch/CArchPluginUnix.cpp +++ b/src/lib/arch/CArchPluginUnix.cpp @@ -27,6 +27,6 @@ CArchPluginUnix::~CArchPluginUnix() } void -CArchPluginUnix::init(void* eventTarget) +CArchPluginUnix::init(void* eventTarget, IEventQueue* events) { } diff --git a/src/lib/arch/CArchPluginUnix.h b/src/lib/arch/CArchPluginUnix.h index 03a2940d..dea0378a 100644 --- a/src/lib/arch/CArchPluginUnix.h +++ b/src/lib/arch/CArchPluginUnix.h @@ -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); }; diff --git a/src/lib/arch/CArchPluginWindows.cpp b/src/lib/arch/CArchPluginWindows.cpp index d54d74fb..a691e5e9 100644 --- a/src/lib/arch/CArchPluginWindows.cpp +++ b/src/lib/arch/CArchPluginWindows.cpp @@ -22,7 +22,6 @@ #include "IEventQueue.h" #include "CEvent.h" #include "CScreen.h" -#include "IPlatformScreen.h" // temp #define WIN32_LEAN_AND_MEAN #include @@ -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 diff --git a/src/lib/arch/CArchPluginWindows.h b/src/lib/arch/CArchPluginWindows.h index 70054135..13169cd5 100644 --- a/src/lib/arch/CArchPluginWindows.h +++ b/src/lib/arch/CArchPluginWindows.h @@ -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(); diff --git a/src/lib/arch/IArchPlugin.h b/src/lib/arch/IArchPlugin.h index 4f161d03..cf23e16a 100644 --- a/src/lib/arch/IArchPlugin.h +++ b/src/lib/arch/IArchPlugin.h @@ -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; //@} }; diff --git a/src/lib/base/CEvent.h b/src/lib/base/CEvent.h index 8201d057..e539330c 100644 --- a/src/lib/base/CEvent.h +++ b/src/lib/base/CEvent.h @@ -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 diff --git a/src/lib/base/CEventQueue.cpp b/src/lib/base/CEventQueue.cpp index c661c4a2..73ecaf9a 100644 --- a/src/lib/base/CEventQueue.cpp +++ b/src/lib/base/CEventQueue.cpp @@ -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(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 diff --git a/src/lib/base/CEventQueue.h b/src/lib/base/CEventQueue.h index 91dba04d..77514751 100644 --- a/src/lib/base/CEventQueue.h +++ b/src/lib/base/CEventQueue.h @@ -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 CTimers; typedef CPriorityQueue CTimerQueue; typedef std::map CEventTable; @@ -105,6 +105,7 @@ private: typedef std::map CTypeHandlerTable; typedef std::map 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(this)); \ + } \ + return *m_typesFor##type_; \ +} + #endif diff --git a/src/lib/base/CEventTypes.cpp b/src/lib/base/CEventTypes.cpp new file mode 100644 index 00000000..5541b4bb --- /dev/null +++ b/src/lib/base/CEventTypes.cpp @@ -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 . + */ + +#include "CEventTypes.h" +#include "IEventQueue.h" +#include +#include + +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) diff --git a/src/lib/base/CEventTypes.h b/src/lib/base/CEventTypes.h new file mode 100644 index 00000000..80e31979 --- /dev/null +++ b/src/lib/base/CEventTypes.h @@ -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 . + */ + +#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; +}; diff --git a/src/lib/base/CMakeLists.txt b/src/lib/base/CMakeLists.txt index 3f610847..b2e0e822 100644 --- a/src/lib/base/CMakeLists.txt +++ b/src/lib/base/CMakeLists.txt @@ -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 ) diff --git a/src/lib/base/IEventQueue.cpp b/src/lib/base/IEventQueue.cpp deleted file mode 100644 index f3027acb..00000000 --- a/src/lib/base/IEventQueue.cpp +++ /dev/null @@ -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 . - */ - -#include "IEventQueue.h" -#include "CLog.h" - -#if WINAPI_CARBON -#include -#include -#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; -} diff --git a/src/lib/base/IEventQueue.h b/src/lib/base/IEventQueue.h index 21de098e..d13ea700 100644 --- a/src/lib/base/IEventQueue.h +++ b/src/lib/base/IEventQueue.h @@ -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; //@} + + // + // Event type providers. + // -protected: - //! @name manipulators - //@{ - - //! 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 diff --git a/src/lib/client/CClient.cpp b/src/lib/client/CClient.cpp index 8c6a862c..c874a969 100644 --- a/src/lib/client/CClient.cpp +++ b/src/lib/client/CClient.cpp @@ -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(this, &CClient::handleSuspend)); - m_eventQueue->adoptHandler(IScreen::getResumeEvent(), + m_events->adoptHandler(m_events->forIScreen().resume(), getEventTarget(), new TMethodEventJob(this, &CClient::handleResume)); - m_eventQueue->adoptHandler(IPlatformScreen::getGameDeviceTimingRespEvent(), + m_events->adoptHandler(m_events->forISecondaryScreen().gameDeviceTimingResp(), getEventTarget(), new TMethodEventJob(this, &CClient::handleGameDeviceTimingResp)); - m_eventQueue->adoptHandler(IPlatformScreen::getGameDeviceFeedbackEvent(), + m_events->adoptHandler(m_events->forISecondaryScreen().gameDeviceFeedback(), getEventTarget(), new TMethodEventJob(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(this, &CClient::handleConnected)); - m_eventQueue->adoptHandler(IDataSocket::getConnectionFailedEvent(), + m_events->adoptHandler(m_events->forIDataSocket().connectionFailed(), m_stream->getEventTarget(), new TMethodEventJob(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(this, &CClient::handleDisconnected)); - m_eventQueue->adoptHandler(m_stream->getInputReadyEvent(), + m_events->adoptHandler(m_events->forIStream().inputReady(), m_stream->getEventTarget(), new TMethodEventJob(this, &CClient::handleHello)); - m_eventQueue->adoptHandler(m_stream->getOutputErrorEvent(), + m_events->adoptHandler(m_events->forIStream().outputError(), m_stream->getEventTarget(), new TMethodEventJob(this, &CClient::handleOutputError)); - m_eventQueue->adoptHandler(m_stream->getInputShutdownEvent(), + m_events->adoptHandler(m_events->forIStream().inputShutdown(), m_stream->getEventTarget(), new TMethodEventJob(this, &CClient::handleDisconnected)); - m_eventQueue->adoptHandler(m_stream->getOutputShutdownEvent(), + m_events->adoptHandler(m_events->forIStream().outputShutdown(), m_stream->getEventTarget(), new TMethodEventJob(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(this, &CClient::handleShapeChanged)); - m_eventQueue->adoptHandler(IScreen::getClipboardGrabbedEvent(), + m_events->adoptHandler(m_events->forIScreen().clipboardGrabbed(), getEventTarget(), new TMethodEventJob(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(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())); } } diff --git a/src/lib/client/CClient.h b/src/lib/client/CClient.h index 06507d3b..05a30566 100644 --- a/src/lib/client/CClient.h +++ b/src/lib/client/CClient.h @@ -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 @@ -114,29 +115,7 @@ public: to connect) to. */ 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 diff --git a/src/lib/client/CServerProxy.cpp b/src/lib/client/CServerProxy.cpp index 31508ce6..b7291b92 100644 --- a/src/lib/client/CServerProxy.cpp +++ b/src/lib/client/CServerProxy.cpp @@ -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(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(this, &CServerProxy::handleKeepAliveAlarm)); } diff --git a/src/lib/client/CServerProxy.h b/src/lib/client/CServerProxy.h index d0f589ed..13735ad3 100644 --- a/src/lib/client/CServerProxy.h +++ b/src/lib/client/CServerProxy.h @@ -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 @@ -110,7 +110,7 @@ private: typedef EResult (CServerProxy::*MessageParser)(const UInt8*); CClient* m_client; - synergy::IStream* m_stream; + synergy::IStream* m_stream; UInt32 m_seqNum; @@ -121,13 +121,13 @@ private: bool m_ignoreMouse; - KeyModifierID m_modifierTranslationTable[kKeyModifierIDLast]; + KeyModifierID m_modifierTranslationTable[kKeyModifierIDLast]; double m_keepAliveAlarm; - CEventQueueTimer* m_keepAliveAlarmTimer; + CEventQueueTimer* m_keepAliveAlarmTimer; - MessageParser m_parser; - IEventQueue* m_eventQueue; + MessageParser m_parser; + IEventQueue* m_events; }; #endif diff --git a/src/lib/io/CCryptoStream.cpp b/src/lib/io/CCryptoStream.cpp index 758277af..9a9a311e 100644 --- a/src/lib/io/CCryptoStream.cpp +++ b/src/lib/io/CCryptoStream.cpp @@ -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) diff --git a/src/lib/io/CCryptoStream.h b/src/lib/io/CCryptoStream.h index 104b1f61..b353541e 100644 --- a/src/lib/io/CCryptoStream.h +++ b/src/lib/io/CCryptoStream.h @@ -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 diff --git a/src/lib/io/CMakeLists.txt b/src/lib/io/CMakeLists.txt index 1215fceb..56745f61 100644 --- a/src/lib/io/CMakeLists.txt +++ b/src/lib/io/CMakeLists.txt @@ -29,7 +29,6 @@ set(inc set(src CStreamBuffer.cpp CStreamFilter.cpp - IStream.cpp XIO.cpp CCryptoStream.cpp CCryptoMode.cpp diff --git a/src/lib/io/CStreamFilter.cpp b/src/lib/io/CStreamFilter.cpp index 569100d1..0ca412a2 100644 --- a/src/lib/io/CStreamFilter.cpp +++ b/src/lib/io/CStreamFilter.cpp @@ -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(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())); } diff --git a/src/lib/io/CStreamFilter.h b/src/lib/io/CStreamFilter.h index d85bc195..e41b3b92 100644 --- a/src/lib/io/CStreamFilter.h +++ b/src/lib/io/CStreamFilter.h @@ -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 diff --git a/src/lib/io/IStream.cpp b/src/lib/io/IStream.cpp deleted file mode 100644 index 9bf1f634..00000000 --- a/src/lib/io/IStream.cpp +++ /dev/null @@ -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 . - */ - -#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; -} diff --git a/src/lib/io/IStream.h b/src/lib/io/IStream.h index 7c667f7d..5e8f34c1 100644 --- a/src/lib/io/IStream.h +++ b/src/lib/io/IStream.h @@ -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; }; } diff --git a/src/lib/ipc/CIpcClient.cpp b/src/lib/ipc/CIpcClient.cpp index 14faa5e9..b7fa31fb 100644 --- a/src/lib/ipc/CIpcClient.cpp +++ b/src/lib/ipc/CIpcClient.cpp @@ -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( 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( 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); } diff --git a/src/lib/ipc/CIpcClient.h b/src/lib/ipc/CIpcClient.h index 623dd5d1..f3cab051 100644 --- a/src/lib/ipc/CIpcClient.h +++ b/src/lib/ipc/CIpcClient.h @@ -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; }; diff --git a/src/lib/ipc/CIpcClientProxy.cpp b/src/lib/ipc/CIpcClientProxy.cpp index 5fd67821..079396ca 100644 --- a/src/lib/ipc/CIpcClientProxy.cpp +++ b/src/lib/ipc/CIpcClientProxy.cpp @@ -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( this, &CIpcClientProxy::handleData)); - EVENTQUEUE->adoptHandler( - m_stream.getOutputErrorEvent(), stream.getEventTarget(), + m_events->adoptHandler( + m_events->forIStream().outputError(), stream.getEventTarget(), new TMethodEventJob( this, &CIpcClientProxy::handleWriteError)); - EVENTQUEUE->adoptHandler( - m_stream.getInputShutdownEvent(), stream.getEventTarget(), + m_events->adoptHandler( + m_events->forIStream().inputShutdown(), stream.getEventTarget(), new TMethodEventJob( this, &CIpcClientProxy::handleDisconnect)); - EVENTQUEUE->adoptHandler( - m_stream.getOutputShutdownEvent(), stream.getEventTarget(), + m_events->adoptHandler( + m_events->forIStream().outputShutdown(), stream.getEventTarget(), new TMethodEventJob( 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)); } diff --git a/src/lib/ipc/CIpcClientProxy.h b/src/lib/ipc/CIpcClientProxy.h index 1e0a9feb..6c3037a2 100644 --- a/src/lib/ipc/CIpcClientProxy.h +++ b/src/lib/ipc/CIpcClientProxy.h @@ -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; }; diff --git a/src/lib/ipc/CIpcServer.cpp b/src/lib/ipc/CIpcServer.cpp index 11715439..037f0c8a 100644 --- a/src/lib/ipc/CIpcServer.cpp +++ b/src/lib/ipc/CIpcServer.cpp @@ -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( 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( this, &CIpcServer::handleClientDisconnected)); - EVENTQUEUE->adoptHandler( - CIpcClientProxy::getMessageReceivedEvent(), proxy, + m_events->adoptHandler( + m_events->forCIpcClientProxy().messageReceived(), proxy, new TMethodEventJob( 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) { diff --git a/src/lib/ipc/CIpcServer.h b/src/lib/ipc/CIpcServer.h index cc738fef..af0b4cdc 100644 --- a/src/lib/ipc/CIpcServer.h +++ b/src/lib/ipc/CIpcServer.h @@ -23,10 +23,12 @@ #include "Ipc.h" #include #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; }; diff --git a/src/lib/ipc/CIpcServerProxy.cpp b/src/lib/ipc/CIpcServerProxy.cpp index 047c4886..d9f5a18a 100644 --- a/src/lib/ipc/CIpcServerProxy.cpp +++ b/src/lib/ipc/CIpcServerProxy.cpp @@ -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( 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"); -} diff --git a/src/lib/ipc/CIpcServerProxy.h b/src/lib/ipc/CIpcServerProxy.h index 8870bf1b..0aedd262 100644 --- a/src/lib/ipc/CIpcServerProxy.h +++ b/src/lib/ipc/CIpcServerProxy.h @@ -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; }; diff --git a/src/lib/net/CMakeLists.txt b/src/lib/net/CMakeLists.txt index 097bd727..726209cd 100644 --- a/src/lib/net/CMakeLists.txt +++ b/src/lib/net/CMakeLists.txt @@ -36,8 +36,6 @@ set(src CTCPSocket.cpp CTCPSocketFactory.cpp IDataSocket.cpp - IListenSocket.cpp - ISocket.cpp XSocket.cpp ) diff --git a/src/lib/net/CTCPListenSocket.cpp b/src/lib/net/CTCPListenSocket.cpp index c609ba95..6acede19 100644 --- a/src/lib/net/CTCPListenSocket.cpp +++ b/src/lib/net/CTCPListenSocket.cpp @@ -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( @@ -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; } diff --git a/src/lib/net/CTCPListenSocket.h b/src/lib/net/CTCPListenSocket.h index 52e65ae2..580c7491 100644 --- a/src/lib/net/CTCPListenSocket.h +++ b/src/lib/net/CTCPListenSocket.h @@ -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 diff --git a/src/lib/net/CTCPSocket.cpp b/src/lib/net/CTCPSocket.cpp index ebc6667a..caaa7836 100644 --- a/src/lib/net/CTCPSocket.cpp +++ b/src/lib/net/CTCPSocket.cpp @@ -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; } diff --git a/src/lib/net/CTCPSocket.h b/src/lib/net/CTCPSocket.h index 9fc32991..2a3645c7 100644 --- a/src/lib/net/CTCPSocket.h +++ b/src/lib/net/CTCPSocket.h @@ -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 diff --git a/src/lib/net/CTCPSocketFactory.cpp b/src/lib/net/CTCPSocketFactory.cpp index 9756a66f..33cdc0ca 100644 --- a/src/lib/net/CTCPSocketFactory.cpp +++ b/src/lib/net/CTCPSocketFactory.cpp @@ -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); } diff --git a/src/lib/net/CTCPSocketFactory.h b/src/lib/net/CTCPSocketFactory.h index 7eb53a13..df41f2c8 100644 --- a/src/lib/net/CTCPSocketFactory.h +++ b/src/lib/net/CTCPSocketFactory.h @@ -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 diff --git a/src/lib/net/IDataSocket.cpp b/src/lib/net/IDataSocket.cpp index b9fa07a9..89308043 100644 --- a/src/lib/net/IDataSocket.cpp +++ b/src/lib/net/IDataSocket.cpp @@ -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() { diff --git a/src/lib/net/IDataSocket.h b/src/lib/net/IDataSocket.h index fc85a73b..627ba710 100644 --- a/src/lib/net/IDataSocket.h +++ b/src/lib/net/IDataSocket.h @@ -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 diff --git a/src/lib/net/IListenSocket.cpp b/src/lib/net/IListenSocket.cpp deleted file mode 100644 index 3c727100..00000000 --- a/src/lib/net/IListenSocket.cpp +++ /dev/null @@ -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 . - */ - -#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"); -} diff --git a/src/lib/net/IListenSocket.h b/src/lib/net/IListenSocket.h index d5a44b72..16b9c775 100644 --- a/src/lib/net/IListenSocket.h +++ b/src/lib/net/IListenSocket.h @@ -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 diff --git a/src/lib/net/ISocket.cpp b/src/lib/net/ISocket.cpp deleted file mode 100644 index 8e7fe494..00000000 --- a/src/lib/net/ISocket.cpp +++ /dev/null @@ -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 . - */ - -#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"); -} diff --git a/src/lib/net/ISocket.h b/src/lib/net/ISocket.h index 7b49959c..6625b301 100644 --- a/src/lib/net/ISocket.h +++ b/src/lib/net/ISocket.h @@ -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 diff --git a/src/lib/platform/CMSWindowsDesks.cpp b/src/lib/platform/CMSWindowsDesks.cpp index 4bf3ee1b..89ebd9bc 100644 --- a/src/lib/platform/CMSWindowsDesks.cpp +++ b/src/lib/platform/CMSWindowsDesks.cpp @@ -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( 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; } diff --git a/src/lib/platform/CMSWindowsDesks.h b/src/lib/platform/CMSWindowsDesks.h index 86624b08..d16d767b 100644 --- a/src/lib/platform/CMSWindowsDesks.h +++ b/src/lib/platform/CMSWindowsDesks.h @@ -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; diff --git a/src/lib/platform/CMSWindowsEventQueueBuffer.cpp b/src/lib/platform/CMSWindowsEventQueueBuffer.cpp index ee6039bc..991b63ac 100644 --- a/src/lib/platform/CMSWindowsEventQueueBuffer.cpp +++ b/src/lib/platform/CMSWindowsEventQueueBuffer.cpp @@ -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; } } diff --git a/src/lib/platform/CMSWindowsEventQueueBuffer.h b/src/lib/platform/CMSWindowsEventQueueBuffer.h index d0674580..1633202a 100644 --- a/src/lib/platform/CMSWindowsEventQueueBuffer.h +++ b/src/lib/platform/CMSWindowsEventQueueBuffer.h @@ -23,10 +23,12 @@ #define WIN32_LEAN_AND_MEAN #include +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 diff --git a/src/lib/platform/CMSWindowsKeyState.cpp b/src/lib/platform/CMSWindowsKeyState.cpp index 3d8ddf3f..9ec8ee0d 100644 --- a/src/lib/platform/CMSWindowsKeyState.cpp +++ b/src/lib/platform/CMSWindowsKeyState.cpp @@ -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( 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; } } diff --git a/src/lib/platform/CMSWindowsKeyState.h b/src/lib/platform/CMSWindowsKeyState.h index 98859fc5..ac0fed99 100644 --- a/src/lib/platform/CMSWindowsKeyState.h +++ b/src/lib/platform/CMSWindowsKeyState.h @@ -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; diff --git a/src/lib/platform/CMSWindowsScreen.cpp b/src/lib/platform/CMSWindowsScreen.cpp index 1dda9266..a35055e6 100644 --- a/src/lib/platform/CMSWindowsScreen.cpp +++ b/src/lib/platform/CMSWindowsScreen.cpp @@ -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(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(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(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) { diff --git a/src/lib/platform/CMSWindowsScreen.h b/src/lib/platform/CMSWindowsScreen.h index 2b11d3a8..37d3c582 100644 --- a/src/lib/platform/CMSWindowsScreen.h +++ b/src/lib/platform/CMSWindowsScreen.h @@ -45,7 +45,8 @@ public: bool isPrimary, bool noHooks, const CGameDeviceInfo &gameDevice, - bool stopOnDeskSwitch); + bool stopOnDeskSwitch, + IEventQueue* events); virtual ~CMSWindowsScreen(); //! @name manipulators @@ -214,6 +215,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 { @@ -329,9 +333,8 @@ private: CGameDevice* m_gameDevice; static CMSWindowsScreen* s_screen; - - // save last position of mouse to compute next delta movement - void saveMousePosition(SInt32 x, SInt32 y); + + IEventQueue* m_events; }; #endif diff --git a/src/lib/platform/CMSWindowsXInput.cpp b/src/lib/platform/CMSWindowsXInput.cpp index 0e0297c4..c0b7d77c 100644 --- a/src/lib/platform/CMSWindowsXInput.cpp +++ b/src/lib/platform/CMSWindowsXInput.cpp @@ -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)); } diff --git a/src/lib/platform/COSXEventQueueBuffer.cpp b/src/lib/platform/COSXEventQueueBuffer.cpp index 7167d147..b2dd3134 100644 --- a/src/lib/platform/COSXEventQueueBuffer.cpp +++ b/src/lib/platform/COSXEventQueueBuffer.cpp @@ -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; } } diff --git a/src/lib/platform/COSXKeyState.cpp b/src/lib/platform/COSXKeyState.cpp index 812f95c8..b85c6b38 100644 --- a/src/lib/platform/COSXKeyState.cpp +++ b/src/lib/platform/COSXKeyState.cpp @@ -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(); diff --git a/src/lib/platform/COSXKeyState.h b/src/lib/platform/COSXKeyState.h index dffc51a3..a7f20f32 100644 --- a/src/lib/platform/COSXKeyState.h +++ b/src/lib/platform/COSXKeyState.h @@ -39,8 +39,8 @@ class COSXKeyState : public CKeyState { public: typedef std::vector CKeyIDs; - COSXKeyState(); - COSXKeyState(IEventQueue& eventQueue, CKeyMap& keyMap); + COSXKeyState(IEventQueue* events); + COSXKeyState(IEventQueue* events, CKeyMap& keyMap); virtual ~COSXKeyState(); //! @name modifiers diff --git a/src/lib/platform/COSXScreen.cpp b/src/lib/platform/COSXScreen.cpp index a445b982..338adb66 100644 --- a/src/lib/platform/COSXScreen.cpp +++ b/src/lib/platform/COSXScreen.cpp @@ -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(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(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(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(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)); diff --git a/src/lib/platform/COSXScreen.h b/src/lib/platform/COSXScreen.h index 5e25847a..a995aaa9 100644 --- a/src/lib/platform/COSXScreen.h +++ b/src/lib/platform/COSXScreen.h @@ -27,6 +27,7 @@ #include #include "COSXClipboard.h" #include "CPlatformScreen.h" +#include "CEventTypes.h" #include #include @@ -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 @@ -322,9 +322,6 @@ private: // global hotkey operating mode static bool s_testedForGHOM; static bool s_hasGHOM; - - // events - static CEvent::Type s_confirmSleepEvent; // Quartz input event support CFMachPortRef m_eventTapPort; diff --git a/src/lib/platform/COSXScreenSaver.cpp b/src/lib/platform/COSXScreenSaver.cpp index a3a4fe80..631726d8 100644 --- a/src/lib/platform/COSXScreenSaver.cpp +++ b/src/lib/platform/COSXScreenSaver.cpp @@ -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)); } diff --git a/src/lib/platform/CXWindowsEventQueueBuffer.cpp b/src/lib/platform/CXWindowsEventQueueBuffer.cpp index 507b2b03..55c56796 100644 --- a/src/lib/platform/CXWindowsEventQueueBuffer.cpp +++ b/src/lib/platform/CXWindowsEventQueueBuffer.cpp @@ -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; } } diff --git a/src/lib/platform/CXWindowsKeyState.cpp b/src/lib/platform/CXWindowsKeyState.cpp index 1b0d088f..0bc644e9 100644 --- a/src/lib/platform/CXWindowsKeyState.cpp +++ b/src/lib/platform/CXWindowsKeyState.cpp @@ -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) { diff --git a/src/lib/platform/CXWindowsKeyState.h b/src/lib/platform/CXWindowsKeyState.h index c2d84656..ca1d1e35 100644 --- a/src/lib/platform/CXWindowsKeyState.h +++ b/src/lib/platform/CXWindowsKeyState.h @@ -50,7 +50,7 @@ public: CXWindowsKeyState(Display*, bool useXKB); CXWindowsKeyState(Display*, bool useXKB, - IEventQueue& eventQueue, CKeyMap& keyMap); + IEventQueue* events, CKeyMap& keyMap); ~CXWindowsKeyState(); //! @name modifiers diff --git a/src/lib/platform/CXWindowsScreen.cpp b/src/lib/platform/CXWindowsScreen.cpp index c6d82769..796cc852 100644 --- a/src/lib/platform/CXWindowsScreen.cpp +++ b/src/lib/platform/CXWindowsScreen.cpp @@ -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)); } @@ -154,15 +154,15 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, bool d if (m_isPrimary) { // start watching for events on other windows selectEvents(m_root); - m_xi2detected = detectXI2(); - - if (m_xi2detected) { -#ifdef HAVE_XI2 - selectXIRawMotion(); -#endif - } else - { - // start watching for events on other windows + m_xi2detected = detectXI2(); + + if (m_xi2detected) { +#ifdef HAVE_XI2 + selectXIRawMotion(); +#endif + } else + { + // start watching for events on other windows selectEvents(m_root); } @@ -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(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 @@ -1229,13 +1229,13 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*) else if (xevent->type == KeyRelease && xevent->xkey.keycode == m_lastKeycode) { m_lastKeycode = 0; - } - - // now filter the event - if (XFilterEvent(xevent, DefaultRootWindow(m_display))) { - if (xevent->type == KeyPress) { - // add filtered presses to the filtered list - m_filtered.insert(m_lastKeycode); + } + + // now filter the event + if (XFilterEvent(xevent, DefaultRootWindow(m_display))) { + if (xevent->type == KeyPress) { + // add filtered presses to the filtered list + m_filtered.insert(m_lastKeycode); } return; } @@ -1252,13 +1252,13 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*) // let screen saver have a go if (m_screensaver->handleXEvent(xevent)) { // screen saver handled it - return; - } - -#ifdef HAVE_XI2 - if (m_xi2detected) { - // Process RawMotion - XGenericEventCookie *cookie = (XGenericEventCookie*)&xevent->xcookie; + return; + } + +#ifdef HAVE_XI2 + if (m_xi2detected) { + // Process RawMotion + XGenericEventCookie *cookie = (XGenericEventCookie*)&xevent->xcookie; if (XGetEventData(m_display, cookie) && cookie->type == GenericEvent && cookie->extension == xi_opcode) { @@ -1283,13 +1283,13 @@ CXWindowsScreen::handleSystemEvent(const CEvent& event, void*) XFreeEventData(m_display, cookie); return; } - XFreeEventData(m_display, cookie); - } - } -#endif - - // handle the event ourself - switch (xevent->type) { + XFreeEventData(m_display, cookie); + } + } +#endif + + // handle the event ourself + switch (xevent->type) { case CreateNotify: if (m_isPrimary) { // select events on new window @@ -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 @@ -2066,17 +2066,17 @@ CXWindowsScreen::CHotKeyItem::operator<(const CHotKeyItem& x) const } bool -CXWindowsScreen::detectXI2() -{ - int event, error; - return XQueryExtension(m_display, - "XInputExtension", &xi_opcode, &event, &error); -} - -#ifdef HAVE_XI2 -void -CXWindowsScreen::selectXIRawMotion() -{ +CXWindowsScreen::detectXI2() +{ + int event, error; + return XQueryExtension(m_display, + "XInputExtension", &xi_opcode, &event, &error); +} + +#ifdef HAVE_XI2 +void +CXWindowsScreen::selectXIRawMotion() +{ XIEventMask mask; mask.deviceid = XIAllDevices; @@ -2086,7 +2086,7 @@ CXWindowsScreen::selectXIRawMotion() memset(mask.mask, 0, 2); XISetMask(mask.mask, XI_RawKeyRelease); XISetMask(mask.mask, XI_RawMotion); - XISelectEvents(m_display, DefaultRootWindow(m_display), &mask, 1); - free(mask.mask); -} -#endif + XISelectEvents(m_display, DefaultRootWindow(m_display), &mask, 1); + free(mask.mask); +} +#endif diff --git a/src/lib/platform/CXWindowsScreen.h b/src/lib/platform/CXWindowsScreen.h index 5251c4de..14b3cfd1 100644 --- a/src/lib/platform/CXWindowsScreen.h +++ b/src/lib/platform/CXWindowsScreen.h @@ -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 @@ -138,15 +138,15 @@ private: bool onHotKey(XKeyEvent&, bool isRepeat); void onMousePress(const XButtonEvent&); void onMouseRelease(const XButtonEvent&); - void onMouseMove(const XMotionEvent&); - - bool detectXI2(); -#ifdef HAVE_XI2 - void selectXIRawMotion(); -#endif - void selectEvents(Window) const; - void doSelectEvents(Window) const; - + void onMouseMove(const XMotionEvent&); + + bool detectXI2(); +#ifdef HAVE_XI2 + void selectXIRawMotion(); +#endif + void selectEvents(Window) const; + void doSelectEvents(Window) const; + KeyID mapKeyFromX(XKeyEvent*) const; ButtonID mapButtonFromX(const XButtonEvent*) const; unsigned int mapButtonToX(ButtonID id) const; @@ -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 diff --git a/src/lib/platform/CXWindowsScreenSaver.cpp b/src/lib/platform/CXWindowsScreenSaver.cpp index 39c8e13d..d82f8ed5 100644 --- a/src/lib/platform/CXWindowsScreenSaver.cpp +++ b/src/lib/platform/CXWindowsScreenSaver.cpp @@ -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(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; } } diff --git a/src/lib/platform/CXWindowsScreenSaver.h b/src/lib/platform/CXWindowsScreenSaver.h index 32008174..87e81c33 100644 --- a/src/lib/platform/CXWindowsScreenSaver.h +++ b/src/lib/platform/CXWindowsScreenSaver.h @@ -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 diff --git a/src/lib/server/CClientListener.cpp b/src/lib/server/CClientListener.cpp index ba775186..b6131116 100644 --- a/src/lib/server/CClientListener.cpp +++ b/src/lib/server/CClientListener.cpp @@ -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(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(this, &CClientListener::handleUnknownClient, client)); - EVENTQUEUE->adoptHandler(CClientProxyUnknown::getFailureEvent(), client, + m_events->adoptHandler(m_events->forCClientProxyUnknown().failure(), client, new TMethodEventJob(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(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; diff --git a/src/lib/server/CClientListener.h b/src/lib/server/CClientListener.h index fd9c2fd9..c824bbc6 100644 --- a/src/lib/server/CClientListener.h +++ b/src/lib/server/CClientListener.h @@ -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: @@ -79,15 +75,14 @@ private: typedef std::set CNewClients; typedef std::deque CWaitingClients; - IListenSocket* m_listen; - ISocketFactory* m_socketFactory; + IListenSocket* m_listen; + ISocketFactory* m_socketFactory; IStreamFilterFactory* m_streamFilterFactory; - CNewClients m_newClients; - CWaitingClients m_waitingClients; - CServer* m_server; - CCryptoOptions m_crypto; - - static CEvent::Type s_connectedEvent; + CNewClients m_newClients; + CWaitingClients m_waitingClients; + CServer* m_server; + CCryptoOptions m_crypto; + IEventQueue* m_events; }; #endif diff --git a/src/lib/server/CClientProxy.cpp b/src/lib/server/CClientProxy.cpp index 895b4d11..91564c69 100644 --- a/src/lib/server/CClientProxy.cpp +++ b/src/lib/server/CClientProxy.cpp @@ -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 { diff --git a/src/lib/server/CClientProxy.h b/src/lib/server/CClientProxy.h index f9298eaa..9225195a 100644 --- a/src/lib/server/CClientProxy.h +++ b/src/lib/server/CClientProxy.h @@ -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 diff --git a/src/lib/server/CClientProxy1_0.cpp b/src/lib/server/CClientProxy1_0.cpp index ce35ba69..d5add895 100644 --- a/src/lib/server/CClientProxy1_0.cpp +++ b/src/lib/server/CClientProxy1_0.cpp @@ -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(this, &CClientProxy1_0::handleData, NULL)); - m_eventQueue->adoptHandler(stream->getOutputErrorEvent(), + m_events->adoptHandler(m_events->forIStream().outputError(), stream->getEventTarget(), new TMethodEventJob(this, &CClientProxy1_0::handleWriteError, NULL)); - m_eventQueue->adoptHandler(stream->getInputShutdownEvent(), + m_events->adoptHandler(m_events->forIStream().inputShutdown(), stream->getEventTarget(), new TMethodEventJob(this, &CClientProxy1_0::handleDisconnect, NULL)); - m_eventQueue->adoptHandler(stream->getOutputShutdownEvent(), + m_events->adoptHandler(m_events->forIStream().outputShutdown(), stream->getEventTarget(), new TMethodEventJob(this, &CClientProxy1_0::handleWriteError, NULL)); - m_eventQueue->adoptHandler(CEvent::kTimer, this, + m_events->adoptHandler(CEvent::kTimer, this, new TMethodEventJob(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; diff --git a/src/lib/server/CClientProxy1_0.h b/src/lib/server/CClientProxy1_0.h index 0e8fd333..31f51e85 100644 --- a/src/lib/server/CClientProxy1_0.h +++ b/src/lib/server/CClientProxy1_0.h @@ -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 diff --git a/src/lib/server/CClientProxy1_1.cpp b/src/lib/server/CClientProxy1_1.cpp index 706b2fa2..6a4303cf 100644 --- a/src/lib/server/CClientProxy1_1.cpp +++ b/src/lib/server/CClientProxy1_1.cpp @@ -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 } diff --git a/src/lib/server/CClientProxy1_1.h b/src/lib/server/CClientProxy1_1.h index 10e25d90..50e8e391 100644 --- a/src/lib/server/CClientProxy1_1.h +++ b/src/lib/server/CClientProxy1_1.h @@ -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 diff --git a/src/lib/server/CClientProxy1_2.cpp b/src/lib/server/CClientProxy1_2.cpp index 9919c128..25b138b7 100644 --- a/src/lib/server/CClientProxy1_2.cpp +++ b/src/lib/server/CClientProxy1_2.cpp @@ -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 } diff --git a/src/lib/server/CClientProxy1_2.h b/src/lib/server/CClientProxy1_2.h index 543be56f..70059147 100644 --- a/src/lib/server/CClientProxy1_2.h +++ b/src/lib/server/CClientProxy1_2.h @@ -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 diff --git a/src/lib/server/CClientProxy1_3.cpp b/src/lib/server/CClientProxy1_3.cpp index fcf452ff..097bc401 100644 --- a/src/lib/server/CClientProxy1_3.cpp +++ b/src/lib/server/CClientProxy1_3.cpp @@ -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(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; } diff --git a/src/lib/server/CClientProxy1_3.h b/src/lib/server/CClientProxy1_3.h index c5238016..82c87c9f 100644 --- a/src/lib/server/CClientProxy1_3.h +++ b/src/lib/server/CClientProxy1_3.h @@ -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 diff --git a/src/lib/server/CClientProxy1_4.cpp b/src/lib/server/CClientProxy1_4.cpp index a77deb23..12a98180 100644 --- a/src/lib/server/CClientProxy1_4.cpp +++ b/src/lib/server/CClientProxy1_4.cpp @@ -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); } diff --git a/src/lib/server/CClientProxy1_4.h b/src/lib/server/CClientProxy1_4.h index d6d1238c..587b6470 100644 --- a/src/lib/server/CClientProxy1_4.h +++ b/src/lib/server/CClientProxy1_4.h @@ -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 diff --git a/src/lib/server/CClientProxyUnknown.cpp b/src/lib/server/CClientProxyUnknown.cpp index 62b19064..a35179b1 100644 --- a/src/lib/server/CClientProxyUnknown.cpp +++ b/src/lib/server/CClientProxyUnknown.cpp @@ -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(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(this, &CClientProxyUnknown::handleData)); - EVENTQUEUE->adoptHandler(m_stream->getOutputErrorEvent(), + m_events->adoptHandler(m_events->forIStream().outputError(), m_stream->getEventTarget(), new TMethodEventJob(this, &CClientProxyUnknown::handleWriteError)); - EVENTQUEUE->adoptHandler(m_stream->getInputShutdownEvent(), + m_events->adoptHandler(m_events->forIStream().inputShutdown(), m_stream->getEventTarget(), new TMethodEventJob(this, &CClientProxyUnknown::handleDisconnect)); - EVENTQUEUE->adoptHandler(m_stream->getOutputShutdownEvent(), + m_events->adoptHandler(m_events->forIStream().outputShutdown(), m_stream->getEventTarget(), new TMethodEventJob(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(this, &CClientProxyUnknown::handleReady)); - EVENTQUEUE->adoptHandler(CClientProxy::getDisconnectedEvent(), + m_events->adoptHandler(m_events->forCClientProxy().disconnected(), m_proxy, new TMethodEventJob(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; } } diff --git a/src/lib/server/CClientProxyUnknown.h b/src/lib/server/CClientProxyUnknown.h index 279fb55a..4b7b0eb3 100644 --- a/src/lib/server/CClientProxyUnknown.h +++ b/src/lib/server/CClientProxyUnknown.h @@ -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 diff --git a/src/lib/server/CConfig.cpp b/src/lib/server/CConfig.cpp index 7b17b163..2b27425d 100644 --- a/src/lib/server/CConfig.cpp +++ b/src/lib/server/CConfig.cpp @@ -24,12 +24,16 @@ #include "stdistream.h" #include "stdostream.h" #include +#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 { diff --git a/src/lib/server/CConfig.h b/src/lib/server/CConfig.h index c02514af..9d196147 100644 --- a/src/lib/server/CConfig.h +++ b/src/lib/server/CConfig.h @@ -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 diff --git a/src/lib/server/CInputFilter.cpp b/src/lib/server/CInputFilter.cpp index b3b3419b..2b9d983b 100644 --- a/src/lib/server/CInputFilter.cpp +++ b/src/lib/server/CInputFilter.cpp @@ -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(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(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& 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(this, &CInputFilter::handleEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyUpEvent(*EVENTQUEUE), + m_events->adoptHandler(m_events->forIKeyState().keyUp(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CInputFilter::handleEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyRepeatEvent(*EVENTQUEUE), + m_events->adoptHandler(m_events->forIKeyState().keyRepeat(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CInputFilter::handleEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonDownEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().buttonDown(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CInputFilter::handleEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonUpEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().buttonUp(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CInputFilter::handleEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getHotKeyDownEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().hotKeyDown(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CInputFilter::handleEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getHotKeyUpEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().hotKeyUp(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CInputFilter::handleEvent)); - EVENTQUEUE->adoptHandler(CServer::getConnectedEvent(), + m_events->adoptHandler(m_events->forCServer().connected(), m_primaryClient->getEventTarget(), new TMethodEventJob(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); } diff --git a/src/lib/server/CInputFilter.h b/src/lib/server/CInputFilter.h index b3f9ebb0..6e1fa76f 100644 --- a/src/lib/server/CInputFilter.h +++ b/src/lib/server/CInputFilter.h @@ -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& screens); + CKeyboardBroadcastAction(IEventQueue* events, Mode = kToggle); + CKeyboardBroadcastAction(IEventQueue* events, Mode, const std::set& screens); Mode getMode() const; std::set 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*); @@ -220,13 +228,15 @@ public: private: IPlatformScreen::CKeyInfo* m_keyInfo; - bool m_press; + 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(); @@ -244,7 +254,8 @@ public: private: IPlatformScreen::CButtonInfo* m_buttonInfo; - bool m_press; + bool m_press; + IEventQueue* m_events; }; class CRule { @@ -306,7 +317,7 @@ public: // ------------------------------------------------------------------------- typedef std::vector 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 diff --git a/src/lib/server/CServer.cpp b/src/lib/server/CServer.cpp index b3e864fc..09c07aee 100644 --- a/src/lib/server/CServer.cpp +++ b/src/lib/server/CServer.cpp @@ -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(this, &CServer::handleSwitchWaitTimeout)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyDownEvent(*EVENTQUEUE), + m_events->adoptHandler(m_events->forIKeyState().keyDown(), m_inputFilter, new TMethodEventJob(this, &CServer::handleKeyDownEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyUpEvent(*EVENTQUEUE), + m_events->adoptHandler(m_events->forIKeyState().keyUp(), m_inputFilter, new TMethodEventJob(this, &CServer::handleKeyUpEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyRepeatEvent(* EVENTQUEUE), + m_events->adoptHandler(m_events->forIKeyState().keyRepeat(), m_inputFilter, new TMethodEventJob(this, &CServer::handleKeyRepeatEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonDownEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().buttonDown(), m_inputFilter, new TMethodEventJob(this, &CServer::handleButtonDownEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonUpEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().buttonUp(), m_inputFilter, new TMethodEventJob(this, &CServer::handleButtonUpEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getMotionOnPrimaryEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().motionOnPrimary(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleMotionPrimaryEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getMotionOnSecondaryEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().motionOnSecondary(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleMotionSecondaryEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getWheelEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().wheel(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleWheelEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getGameDeviceButtonsEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().gameDeviceButtons(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleGameDeviceButtons)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getGameDeviceSticksEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().gameDeviceSticks(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleGameDeviceSticks)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getGameDeviceTriggersEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().gameDeviceTriggers(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleGameDeviceTriggers)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getGameDeviceTimingReqEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().gameDeviceTimingReq(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleGameDeviceTimingReq)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getScreensaverActivatedEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().screensaverActivated(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleScreensaverActivatedEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getScreensaverDeactivatedEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().screensaverDeactivated(), m_primaryClient->getEventTarget(), new TMethodEventJob(this, &CServer::handleScreensaverDeactivatedEvent)); - EVENTQUEUE->adoptHandler(getSwitchToScreenEvent(), + m_events->adoptHandler(m_events->forCServer().switchToScreen(), m_inputFilter, new TMethodEventJob(this, &CServer::handleSwitchToScreenEvent)); - EVENTQUEUE->adoptHandler(getSwitchInDirectionEvent(), + m_events->adoptHandler(m_events->forCServer().switchInDirection(), m_inputFilter, new TMethodEventJob(this, &CServer::handleSwitchInDirectionEvent)); - EVENTQUEUE->adoptHandler(getKeyboardBroadcastEvent(), + m_events->adoptHandler(m_events->forCServer().keyboardBroadcast(), m_inputFilter, new TMethodEventJob(this, &CServer::handleKeyboardBroadcastEvent)); - EVENTQUEUE->adoptHandler(getLockCursorToScreenEvent(), + m_events->adoptHandler(m_events->forCServer().lockCursorToScreen(), m_inputFilter, new TMethodEventJob(this, &CServer::handleLockCursorToScreenEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getFakeInputBeginEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().fakeInputBegin(), m_inputFilter, new TMethodEventJob(this, &CServer::handleFakeInputBeginEvent)); - EVENTQUEUE->adoptHandler(IPlatformScreen::getFakeInputEndEvent(), + m_events->adoptHandler(m_events->forIPrimaryScreen().fakeInputEnd(), m_inputFilter, new TMethodEventJob(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(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& 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(this, &CServer::handleShapeChanged, client)); - EVENTQUEUE->adoptHandler(IScreen::getClipboardGrabbedEvent(), + m_events->adoptHandler(m_events->forIScreen().clipboardGrabbed(), client->getEventTarget(), new TMethodEventJob(this, &CServer::handleClipboardGrabbed, client)); - EVENTQUEUE->adoptHandler(CClientProxy::getClipboardChangedEvent(), + m_events->adoptHandler(m_events->forCClientProxy().clipboardChanged(), client->getEventTarget(), new TMethodEventJob(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(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)); } } } diff --git a/src/lib/server/CServer.h b/src/lib/server/CServer.h index 4b60fafa..466ec5b8 100644 --- a/src/lib/server/CServer.h +++ b/src/lib/server/CServer.h @@ -30,18 +30,20 @@ #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 /*! This class implements the top-level server algorithms for synergy. */ -class CServer : public INode { +class CServer : public INode { public: //! Lock cursor to screen data class CLockCursorToScreenInfo { @@ -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& 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 diff --git a/src/lib/synergy/CApp.cpp b/src/lib/synergy/CApp.cpp index 6379298a..3c5a28ba 100644 --- a/src/lib/synergy/CApp.cpp +++ b/src/lib/synergy/CApp.cpp @@ -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(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(e.getDataObject()); if (m->type() == kIpcShutdown) { LOG((CLOG_INFO "got ipc shutdown message")); - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } } diff --git a/src/lib/synergy/CApp.h b/src/lib/synergy/CApp.h index 0587a302..d388730e 100644 --- a/src/lib/synergy/CApp.h +++ b/src/lib/synergy/CApp.h @@ -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. @@ -93,6 +94,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." diff --git a/src/lib/synergy/CAppUtilWindows.cpp b/src/lib/synergy/CAppUtilWindows.cpp index 309f6637..fb289acc 100644 --- a/src/lib/synergy/CAppUtilWindows.cpp +++ b/src/lib/synergy/CAppUtilWindows.cpp @@ -30,13 +30,15 @@ #include "CArgsBase.h" #include "IEventQueue.h" #include "CEvent.h" +#include "CEventQueue.h" #include #include #include -CAppUtilWindows::CAppUtilWindows() : -m_exitMode(kExitModeNormal) +CAppUtilWindows::CAppUtilWindows(IEventQueue* events) : + m_events(events), + m_exitMode(kExitModeNormal) { if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)consoleHandler, TRUE) == FALSE) { @@ -51,7 +53,8 @@ CAppUtilWindows::~CAppUtilWindows() BOOL WINAPI CAppUtilWindows::consoleHandler(DWORD) { LOG((CLOG_INFO "got shutdown signal")); - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + IEventQueue* events = CAppUtil::instance().app().events(); + events->addEvent(CEvent(CEvent::kQuit)); return TRUE; } diff --git a/src/lib/synergy/CAppUtilWindows.h b/src/lib/synergy/CAppUtilWindows.h index f8977ed8..7b2b9901 100644 --- a/src/lib/synergy/CAppUtilWindows.h +++ b/src/lib/synergy/CAppUtilWindows.h @@ -26,6 +26,8 @@ #define ARCH_APP_UTIL CAppUtilWindows +class IEventQueue; + enum AppExitMode { kExitModeNormal, kExitModeDaemon @@ -33,7 +35,7 @@ enum AppExitMode { class CAppUtilWindows : public CAppUtil { public: - CAppUtilWindows(); + CAppUtilWindows(IEventQueue* events); virtual ~CAppUtilWindows(); bool parseArg(const int& argc, const char* const* argv, int& i); @@ -55,6 +57,8 @@ public: void startNode(); private: - AppExitMode m_exitMode; + AppExitMode m_exitMode; + IEventQueue* m_events; + static BOOL WINAPI consoleHandler(DWORD CEvent); }; diff --git a/src/lib/synergy/CClientApp.cpp b/src/lib/synergy/CClientApp.cpp index ccd66043..93e91813 100644 --- a/src/lib/synergy/CClientApp.cpp +++ b/src/lib/synergy/CClientApp.cpp @@ -42,7 +42,7 @@ #include "CArchMiscWindows.h" #endif -#if SYSAPI_WIN32 && GAME_DEVICE_SUPPORT +#if SYSAPI_WIN32 && GAME_DEVICE_SUPPORT #include #include "XInputHook.h" #endif @@ -60,10 +60,11 @@ #define RETRY_TIME 1.0 -CClientApp::CClientApp(CreateTaskBarReceiverFunc createTaskBarReceiver) : -CApp(createTaskBarReceiver, new CArgs()), -s_client(NULL), -s_clientScreen(NULL) +CClientApp::CClientApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver) : + CApp(events, createTaskBarReceiver, new CArgs()), + m_events(events), + s_client(NULL), + s_clientScreen(NULL) { } @@ -229,11 +230,11 @@ CClientApp::createScreen() { #if WINAPI_MSWINDOWS return new CScreen(new CMSWindowsScreen( - false, args().m_noHooks, args().m_gameDevice, args().m_stopOnDeskSwitch)); + false, args().m_noHooks, args().m_gameDevice, args().m_stopOnDeskSwitch, m_events), m_events); #elif WINAPI_XWINDOWS return new CScreen(new CXWindowsScreen( args().m_display, false, args().m_disableXInitThreads, - args().m_yscroll, *EVENTQUEUE)); + args().m_yscroll, m_events)); #elif WINAPI_CARBON return new CScreen(new COSXScreen(false)); #endif @@ -291,7 +292,7 @@ void CClientApp::handleScreenError(const CEvent&, void*) { LOG((CLOG_CRIT "error on screen")); - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } @@ -299,7 +300,7 @@ CScreen* CClientApp::openClientScreen() { CScreen* screen = createScreen(); - EVENTQUEUE->adoptHandler(IScreen::getErrorEvent(), + m_events->adoptHandler(m_events->forIScreen().error(), screen->getEventTarget(), new TMethodEventJob( this, &CClientApp::handleScreenError)); @@ -311,7 +312,7 @@ void CClientApp::closeClientScreen(CScreen* screen) { if (screen != NULL) { - EVENTQUEUE->removeHandler(IScreen::getErrorEvent(), + m_events->removeHandler(m_events->forIScreen().error(), screen->getEventTarget()); delete screen; } @@ -323,8 +324,8 @@ CClientApp::handleClientRestart(const CEvent&, void* vtimer) { // discard old timer CEventQueueTimer* timer = reinterpret_cast(vtimer); - EVENTQUEUE->deleteTimer(timer); - EVENTQUEUE->removeHandler(CEvent::kTimer, timer); + m_events->deleteTimer(timer); + m_events->removeHandler(CEvent::kTimer, timer); // reconnect startClient(); @@ -336,8 +337,8 @@ CClientApp::scheduleClientRestart(double retryTime) { // install a timer and handler to retry later LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); - CEventQueueTimer* timer = EVENTQUEUE->newOneShotTimer(retryTime, NULL); - EVENTQUEUE->adoptHandler(CEvent::kTimer, timer, + CEventQueueTimer* timer = m_events->newOneShotTimer(retryTime, NULL); + m_events->adoptHandler(CEvent::kTimer, timer, new TMethodEventJob(this, &CClientApp::handleClientRestart, timer)); } @@ -360,7 +361,7 @@ CClientApp::handleClientFailed(const CEvent& e, void*) updateStatus(CString("Failed to connect to server: ") + info->m_what); if (!args().m_restartable || !info->m_retry) { LOG((CLOG_ERR "failed to connect to server: %s", info->m_what.c_str())); - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } else { LOG((CLOG_WARN "failed to connect to server: %s", info->m_what.c_str())); @@ -377,7 +378,7 @@ CClientApp::handleClientDisconnected(const CEvent&, void*) { LOG((CLOG_NOTE "disconnected from server")); if (!args().m_restartable) { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } else if (!m_suspended) { s_client->connect(); @@ -390,21 +391,21 @@ CClient* CClientApp::openClient(const CString& name, const CNetworkAddress& address, CScreen* screen, const CCryptoOptions& crypto) { CClient* client = new CClient( - EVENTQUEUE, name, address, new CTCPSocketFactory, NULL, screen, crypto); + m_events, name, address, new CTCPSocketFactory(m_events), NULL, screen, crypto); try { - EVENTQUEUE->adoptHandler( - CClient::getConnectedEvent(), + m_events->adoptHandler( + m_events->forCClient().connected(), client->getEventTarget(), new TMethodEventJob(this, &CClientApp::handleClientConnected)); - EVENTQUEUE->adoptHandler( - CClient::getConnectionFailedEvent(), + m_events->adoptHandler( + m_events->forCClient().connectionFailed(), client->getEventTarget(), new TMethodEventJob(this, &CClientApp::handleClientFailed)); - EVENTQUEUE->adoptHandler( - CClient::getDisconnectedEvent(), + m_events->adoptHandler( + m_events->forCClient().disconnected(), client->getEventTarget(), new TMethodEventJob(this, &CClientApp::handleClientDisconnected)); @@ -424,9 +425,9 @@ CClientApp::closeClient(CClient* client) return; } - EVENTQUEUE->removeHandler(CClient::getConnectedEvent(), client); - EVENTQUEUE->removeHandler(CClient::getConnectionFailedEvent(), client); - EVENTQUEUE->removeHandler(CClient::getDisconnectedEvent(), client); + m_events->removeHandler(m_events->forCClient().connected(), client); + m_events->removeHandler(m_events->forCClient().connectionFailed(), client); + m_events->removeHandler(m_events->forCClient().disconnected(), client); delete client; } @@ -532,13 +533,13 @@ CClientApp::mainLoop() } // load all available plugins. - ARCH->plugin().init(s_clientScreen->getEventTarget()); + ARCH->plugin().init(s_clientScreen->getEventTarget(), m_events); // run event loop. if startClient() failed we're supposed to retry // later. the timer installed by startClient() will take care of // that. DAEMON_RUNNING(true); - EVENTQUEUE->loop(); + m_events->loop(); DAEMON_RUNNING(false); // close down diff --git a/src/lib/synergy/CClientApp.h b/src/lib/synergy/CClientApp.h index 614a38c0..1a5846b8 100644 --- a/src/lib/synergy/CClientApp.h +++ b/src/lib/synergy/CClientApp.h @@ -39,7 +39,7 @@ public: CNetworkAddress* m_serverAddress; }; - CClientApp(CreateTaskBarReceiverFunc createTaskBarReceiver); + CClientApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver); virtual ~CClientApp(); // Parse client specific command line arguments. @@ -87,6 +87,7 @@ private: virtual bool parseArg(const int& argc, const char* const* argv, int& i); private: - CClient* s_client; - CScreen* s_clientScreen; + CClient* s_client; + CScreen* s_clientScreen; + IEventQueue* m_events; }; diff --git a/src/lib/synergy/CClientTaskBarReceiver.cpp b/src/lib/synergy/CClientTaskBarReceiver.cpp index 53c15606..4e36245b 100644 --- a/src/lib/synergy/CClientTaskBarReceiver.cpp +++ b/src/lib/synergy/CClientTaskBarReceiver.cpp @@ -28,7 +28,8 @@ // CClientTaskBarReceiver // -CClientTaskBarReceiver::CClientTaskBarReceiver() : +CClientTaskBarReceiver::CClientTaskBarReceiver(IEventQueue* events) : + m_events(events), m_state(kNotRunning) { // do nothing @@ -90,7 +91,7 @@ CClientTaskBarReceiver::getErrorMessage() const void CClientTaskBarReceiver::quit() { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } void diff --git a/src/lib/synergy/CClientTaskBarReceiver.h b/src/lib/synergy/CClientTaskBarReceiver.h index b244ce5c..ed842427 100644 --- a/src/lib/synergy/CClientTaskBarReceiver.h +++ b/src/lib/synergy/CClientTaskBarReceiver.h @@ -24,10 +24,12 @@ #include "LogOutputters.h" #include "CClient.h" +class IEventQueue; + //! Implementation of IArchTaskBarReceiver for the synergy server class CClientTaskBarReceiver : public IArchTaskBarReceiver { public: - CClientTaskBarReceiver(); + CClientTaskBarReceiver(IEventQueue* events); virtual ~CClientTaskBarReceiver(); //! @name manipulators @@ -85,8 +87,9 @@ private: EState m_state; CString m_errorMessage; CString m_server; + IEventQueue* m_events; }; -IArchTaskBarReceiver* createTaskBarReceiver(const CBufferedLogOutputter* logBuffer); +IArchTaskBarReceiver* createTaskBarReceiver(const CBufferedLogOutputter* logBuffer, IEventQueue* events); #endif diff --git a/src/lib/synergy/CDaemonApp.cpp b/src/lib/synergy/CDaemonApp.cpp index 45e381ba..af85a086 100644 --- a/src/lib/synergy/CDaemonApp.cpp +++ b/src/lib/synergy/CDaemonApp.cpp @@ -77,11 +77,12 @@ winMainLoopStatic(int, const char**) #endif CDaemonApp::CDaemonApp() : -m_ipcServer(nullptr), -m_ipcLogOutputter(nullptr) -#if SYSAPI_WIN32 -,m_relauncher(nullptr) -#endif + m_events(nullptr), + m_ipcServer(nullptr), + m_ipcLogOutputter(nullptr) + #if SYSAPI_WIN32 + ,m_relauncher(nullptr) + #endif { s_instance = this; } @@ -103,6 +104,7 @@ CDaemonApp::run(int argc, char** argv) CLog log; CEventQueue events; + m_events = &events; bool uninstall = false; try @@ -201,7 +203,7 @@ CDaemonApp::mainLoop(bool logToFile) CSocketMultiplexer multiplexer; // uses event queue, must be created here. - m_ipcServer = new CIpcServer(); + m_ipcServer = new CIpcServer(m_events); // send logging to gui via ipc, log system adopts outputter. m_ipcLogOutputter = new CIpcLogOutputter(*m_ipcServer); @@ -211,8 +213,8 @@ CDaemonApp::mainLoop(bool logToFile) m_relauncher = new CMSWindowsRelauncher(false, *m_ipcServer, *m_ipcLogOutputter); #endif - EVENTQUEUE->adoptHandler( - CIpcServer::getMessageReceivedEvent(), m_ipcServer, + m_events->adoptHandler( + m_events->forCIpcServer().messageReceived(), m_ipcServer, new TMethodEventJob(this, &CDaemonApp::handleIpcMessage)); m_ipcServer->listen(); @@ -222,7 +224,7 @@ CDaemonApp::mainLoop(bool logToFile) // (such as a stop request from the service controller). CMSWindowsScreen::init(CArchMiscWindows::instanceWin32()); CGameDeviceInfo gameDevice; - CScreen dummyScreen(new CMSWindowsScreen(false, true, gameDevice, false)); + CScreen dummyScreen(new CMSWindowsScreen(false, true, gameDevice, false, m_events), m_events); CString command = ARCH->setting("Command"); bool elevate = ARCH->setting("Elevate") == "1"; @@ -234,15 +236,15 @@ CDaemonApp::mainLoop(bool logToFile) m_relauncher->startAsync(); #endif - EVENTQUEUE->loop(); + m_events->loop(); #if SYSAPI_WIN32 m_relauncher->stop(); delete m_relauncher; #endif - EVENTQUEUE->removeHandler( - CIpcServer::getMessageReceivedEvent(), m_ipcServer); + m_events->removeHandler( + m_events->forCIpcServer().messageReceived(), m_ipcServer); CLOG->remove(m_ipcLogOutputter); delete m_ipcLogOutputter; diff --git a/src/lib/synergy/CDaemonApp.h b/src/lib/synergy/CDaemonApp.h index cf212583..75d8caeb 100644 --- a/src/lib/synergy/CDaemonApp.h +++ b/src/lib/synergy/CDaemonApp.h @@ -55,6 +55,7 @@ public: private: CIpcServer* m_ipcServer; CIpcLogOutputter* m_ipcLogOutputter; + IEventQueue* m_events; }; #define LOG_FILENAME "synergyd.log" diff --git a/src/lib/synergy/CKeyState.cpp b/src/lib/synergy/CKeyState.cpp index 7141927f..b14f867f 100644 --- a/src/lib/synergy/CKeyState.cpp +++ b/src/lib/synergy/CKeyState.cpp @@ -382,8 +382,9 @@ static const KeyID s_numpadTable[] = { // CKeyState // -CKeyState::CKeyState() : - IKeyState(), +CKeyState::CKeyState(IEventQueue* events) : + IKeyState(events), + m_events(events), m_mask(0), m_keyMapPtr(new CKeyMap()), m_keyMap(*m_keyMapPtr) @@ -391,8 +392,9 @@ CKeyState::CKeyState() : init(); } -CKeyState::CKeyState(IEventQueue& eventQueue, CKeyMap& keyMap) : - IKeyState(eventQueue), +CKeyState::CKeyState(IEventQueue* events, CKeyMap& keyMap) : + IKeyState(events), + m_events(events), m_mask(0), m_keyMapPtr(0), m_keyMap(keyMap) @@ -450,23 +452,23 @@ CKeyState::sendKeyEvent( // ignore auto-repeat on half-duplex keys } else { - getEventQueue().addEvent(CEvent(getKeyDownEvent(), target, + m_events->addEvent(CEvent(m_events->forIKeyState().keyDown(), target, CKeyInfo::alloc(key, mask, button, 1))); - getEventQueue().addEvent(CEvent(getKeyUpEvent(), target, + m_events->addEvent(CEvent(m_events->forIKeyState().keyUp(), target, CKeyInfo::alloc(key, mask, button, 1))); } } else { if (isAutoRepeat) { - getEventQueue().addEvent(CEvent(getKeyRepeatEvent(), target, + m_events->addEvent(CEvent(m_events->forIKeyState().keyRepeat(), target, CKeyInfo::alloc(key, mask, button, count))); } else if (press) { - getEventQueue().addEvent(CEvent(getKeyDownEvent(), target, + m_events->addEvent(CEvent(m_events->forIKeyState().keyDown(), target, CKeyInfo::alloc(key, mask, button, 1))); } else { - getEventQueue().addEvent(CEvent(getKeyUpEvent(), target, + m_events->addEvent(CEvent(m_events->forIKeyState().keyUp(), target, CKeyInfo::alloc(key, mask, button, 1))); } } diff --git a/src/lib/synergy/CKeyState.h b/src/lib/synergy/CKeyState.h index 078221b6..772338c5 100644 --- a/src/lib/synergy/CKeyState.h +++ b/src/lib/synergy/CKeyState.h @@ -29,8 +29,8 @@ platform specific methods. */ class CKeyState : public IKeyState { public: - CKeyState(); - CKeyState(IEventQueue& eventQueue, CKeyMap& keyMap); + CKeyState(IEventQueue* events); + CKeyState(IEventQueue* events, CKeyMap& keyMap); virtual ~CKeyState(); //! @name manipulators @@ -226,6 +226,8 @@ private: // server keyboard state. an entry is 0 if not the key isn't pressed // otherwise it's the local KeyButton synthesized for the server key. KeyButton m_serverKeys[kNumButtons]; + + IEventQueue* m_events; }; #endif diff --git a/src/lib/synergy/CMakeLists.txt b/src/lib/synergy/CMakeLists.txt index 11a3f98b..84da6be3 100644 --- a/src/lib/synergy/CMakeLists.txt +++ b/src/lib/synergy/CMakeLists.txt @@ -68,12 +68,10 @@ set(src IClipboard.cpp IKeyState.cpp IPrimaryScreen.cpp - IScreen.cpp KeyTypes.cpp ProtocolTypes.cpp XScreen.cpp XSynergy.cpp - ISecondaryScreen.cpp CDaemonApp.cpp CAppUtil.cpp CArgsBase.cpp diff --git a/src/lib/synergy/CPacketStreamFilter.cpp b/src/lib/synergy/CPacketStreamFilter.cpp index 9ff89289..2672e20b 100644 --- a/src/lib/synergy/CPacketStreamFilter.cpp +++ b/src/lib/synergy/CPacketStreamFilter.cpp @@ -27,8 +27,9 @@ // CPacketStreamFilter // -CPacketStreamFilter::CPacketStreamFilter(synergy::IStream* stream, bool adoptStream) : - CStreamFilter(EVENTQUEUE, stream, adoptStream), +CPacketStreamFilter::CPacketStreamFilter(IEventQueue* events, synergy::IStream* stream, bool adoptStream) : + CStreamFilter(events, stream, adoptStream), + m_events(events), m_size(0), m_inputShutdown(false) { @@ -80,7 +81,7 @@ CPacketStreamFilter::read(void* buffer, UInt32 n) readPacketSize(); if (m_inputShutdown && m_size == 0) { - EVENTQUEUE->addEvent(CEvent(getInputShutdownEvent(), + m_events->addEvent(CEvent(m_events->forIStream().inputShutdown(), getEventTarget(), NULL)); } @@ -176,13 +177,13 @@ CPacketStreamFilter::readMore() void CPacketStreamFilter::filterEvent(const CEvent& event) { - if (event.getType() == getInputReadyEvent()) { + if (event.getType() == m_events->forIStream().inputReady()) { CLock lock(&m_mutex); if (!readMore()) { return; } } - else if (event.getType() == getInputShutdownEvent()) { + else if (event.getType() == m_events->forIStream().inputShutdown()) { // discard this if we have buffered data CLock lock(&m_mutex); m_inputShutdown = true; diff --git a/src/lib/synergy/CPacketStreamFilter.h b/src/lib/synergy/CPacketStreamFilter.h index c578185a..09d48a51 100644 --- a/src/lib/synergy/CPacketStreamFilter.h +++ b/src/lib/synergy/CPacketStreamFilter.h @@ -23,13 +23,15 @@ #include "CStreamBuffer.h" #include "CMutex.h" +class IEventQueue; + //! Packetizing stream filter /*! Filters a stream to read and write packets. */ class CPacketStreamFilter : public CStreamFilter { public: - CPacketStreamFilter(synergy::IStream* stream, bool adoptStream = true); + CPacketStreamFilter(IEventQueue* events, synergy::IStream* stream, bool adoptStream = true); ~CPacketStreamFilter(); // IStream overrides @@ -54,6 +56,7 @@ private: UInt32 m_size; CStreamBuffer m_buffer; bool m_inputShutdown; + IEventQueue* m_events; }; #endif diff --git a/src/lib/synergy/CPlatformScreen.cpp b/src/lib/synergy/CPlatformScreen.cpp index 15947b25..0423424a 100644 --- a/src/lib/synergy/CPlatformScreen.cpp +++ b/src/lib/synergy/CPlatformScreen.cpp @@ -18,13 +18,8 @@ #include "CPlatformScreen.h" -CPlatformScreen::CPlatformScreen() -{ - // do nothing -} - -CPlatformScreen::CPlatformScreen(IEventQueue& eventQueue) : - IPlatformScreen(eventQueue) +CPlatformScreen::CPlatformScreen(IEventQueue* events) : + IPlatformScreen(events) { } diff --git a/src/lib/synergy/CPlatformScreen.h b/src/lib/synergy/CPlatformScreen.h index 45d8dd43..eb56b5a2 100644 --- a/src/lib/synergy/CPlatformScreen.h +++ b/src/lib/synergy/CPlatformScreen.h @@ -29,8 +29,7 @@ subclasses to implement the rest. */ class CPlatformScreen : public IPlatformScreen { public: - CPlatformScreen(); - CPlatformScreen(IEventQueue& eventQueue); + CPlatformScreen(IEventQueue* events); virtual ~CPlatformScreen(); // IScreen overrides diff --git a/src/lib/synergy/CPortableTaskBarReceiver.cpp b/src/lib/synergy/CPortableTaskBarReceiver.cpp index 1a7e2026..9b2c7e54 100644 --- a/src/lib/synergy/CPortableTaskBarReceiver.cpp +++ b/src/lib/synergy/CPortableTaskBarReceiver.cpp @@ -27,7 +27,8 @@ // CPortableTaskBarReceiver // -CPortableTaskBarReceiver::CPortableTaskBarReceiver() : +CPortableTaskBarReceiver::CPortableTaskBarReceiver(IEventQueue* events) : + m_events(events), m_state(kNotRunning) { // do nothing @@ -43,17 +44,17 @@ CPortableTaskBarReceiver::updateStatus(INode* node, const CString& errorMsg) { { // update our status - m_errorMessage = errorMsg; - if (node == NULL) { - if (m_errorMessage.empty()) { - m_state = kNotRunning; - } - else { - m_state = kNotWorking; - } - } - else { - m_state = kNotConnected; + m_errorMessage = errorMsg; + if (node == NULL) { + if (m_errorMessage.empty()) { + m_state = kNotRunning; + } + else { + m_state = kNotWorking; + } + } + else { + m_state = kNotConnected; } // let subclasses have a go @@ -79,7 +80,7 @@ CPortableTaskBarReceiver::getErrorMessage() const void CPortableTaskBarReceiver::quit() { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } void @@ -118,24 +119,3 @@ CPortableTaskBarReceiver::getToolTip() const return ""; } } - -CEvent::Type -CPortableTaskBarReceiver::getReloadConfigEvent() -{ - // do nothing - return NULL; -} - -CEvent::Type -CPortableTaskBarReceiver::getForceReconnectEvent() -{ - // do nothing - return NULL; -} - -CEvent::Type -CPortableTaskBarReceiver::getResetServerEvent() -{ - // do nothing - return NULL; -} diff --git a/src/lib/synergy/CPortableTaskBarReceiver.h b/src/lib/synergy/CPortableTaskBarReceiver.h index 7c0d79a4..06e6819b 100644 --- a/src/lib/synergy/CPortableTaskBarReceiver.h +++ b/src/lib/synergy/CPortableTaskBarReceiver.h @@ -24,11 +24,14 @@ #include "CEvent.h" #include "INode.h" #include "LogOutputters.h" +#include "CEventTypes.h" + +class IEventQueue; //! Implementation of IArchTaskBarReceiver for the synergy server class CPortableTaskBarReceiver : public IArchTaskBarReceiver { public: - CPortableTaskBarReceiver(); + CPortableTaskBarReceiver(IEventQueue* events); virtual ~CPortableTaskBarReceiver(); //! @name manipulators @@ -80,17 +83,14 @@ protected: */ virtual void onStatusChanged(INode* node); -protected: - CEvent::Type getReloadConfigEvent(); - CEvent::Type getForceReconnectEvent(); - CEvent::Type getResetServerEvent(); - private: EState m_state; CString m_errorMessage; CString m_server; CClients m_clients; + + IEventQueue* m_events; }; -IArchTaskBarReceiver* createTaskBarReceiver(const CBufferedLogOutputter* logBuffer); +IArchTaskBarReceiver* createTaskBarReceiver(const CBufferedLogOutputter* logBuffer, IEventQueue* events); diff --git a/src/lib/synergy/CScreen.cpp b/src/lib/synergy/CScreen.cpp index 07206301..0ffa4de5 100644 --- a/src/lib/synergy/CScreen.cpp +++ b/src/lib/synergy/CScreen.cpp @@ -28,7 +28,8 @@ // CScreen // -CScreen::CScreen(IPlatformScreen* platformScreen) : +CScreen::CScreen(IPlatformScreen* platformScreen, IEventQueue* events) : + m_events(events), m_screen(platformScreen), m_isPrimary(platformScreen->isPrimary()), m_enabled(false), @@ -462,7 +463,7 @@ CScreen::enablePrimary() m_screen->openScreensaver(true); // claim screen changed size - EVENTQUEUE->addEvent(CEvent(getShapeChangedEvent(), getEventTarget())); + m_events->addEvent(CEvent(m_events->forIScreen().shapeChanged(), getEventTarget())); } void diff --git a/src/lib/synergy/CScreen.h b/src/lib/synergy/CScreen.h index 6c54704c..08434e59 100644 --- a/src/lib/synergy/CScreen.h +++ b/src/lib/synergy/CScreen.h @@ -28,6 +28,7 @@ class IClipboard; class IPlatformScreen; +class IEventQueue; //! Platform independent screen /*! @@ -36,7 +37,7 @@ primary or secondary screen. */ class CScreen : public IScreen { public: - CScreen(IPlatformScreen* platformScreen); + CScreen(IPlatformScreen* platformScreen, IEventQueue* events); virtual ~CScreen(); //! @name manipulators @@ -340,6 +341,8 @@ private: // true if we're faking input on a primary screen bool m_fakeInput; + + IEventQueue* m_events; }; #endif diff --git a/src/lib/synergy/CServerApp.cpp b/src/lib/synergy/CServerApp.cpp index 4cca64c6..0e29e947 100644 --- a/src/lib/synergy/CServerApp.cpp +++ b/src/lib/synergy/CServerApp.cpp @@ -53,18 +53,19 @@ #include "XScreen.h" #include "CTCPSocketFactory.h" -CEvent::Type CServerApp::s_reloadConfigEvent = CEvent::kUnknown; +// +// CServerApp +// -CServerApp::CServerApp(CreateTaskBarReceiverFunc createTaskBarReceiver) : -CApp(createTaskBarReceiver, new CArgs()), -s_server(NULL), -s_forceReconnectEvent(CEvent::kUnknown), -s_resetServerEvent(CEvent::kUnknown), -s_serverState(kUninitialized), -s_serverScreen(NULL), -s_primaryClient(NULL), -s_listener(NULL), -s_timer(NULL) +CServerApp::CServerApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver) : + CApp(events, createTaskBarReceiver, new CArgs()), + m_events(events), + s_server(NULL), + s_serverState(kUninitialized), + s_serverScreen(NULL), + s_primaryClient(NULL), + s_listener(NULL), + s_timer(NULL) { } @@ -202,8 +203,9 @@ CServerApp::help() void CServerApp::reloadSignalHandler(CArch::ESignal, void*) { - EVENTQUEUE->addEvent(CEvent(getReloadConfigEvent(), - IEventQueue::getSystemTarget())); + IEventQueue* events = CApp::instance().events(); + events->addEvent(CEvent(events->forCServerApp().reloadConfig(), + events->getSystemTarget())); } void @@ -288,12 +290,6 @@ CServerApp::loadConfig(const CString& pathname) return false; } -CEvent::Type -CServerApp::getReloadConfigEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_reloadConfigEvent, "reloadConfig"); -} - void CServerApp::forceReconnect(const CEvent&, void*) { @@ -302,18 +298,6 @@ CServerApp::forceReconnect(const CEvent&, void*) } } -CEvent::Type -CServerApp::getForceReconnectEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_forceReconnectEvent, "forceReconnect"); -} - -CEvent::Type -CServerApp::getResetServerEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_resetServerEvent, "resetServer"); -} - void CServerApp::handleClientConnected(const CEvent&, void* vlistener) { @@ -328,7 +312,7 @@ CServerApp::handleClientConnected(const CEvent&, void* vlistener) void CServerApp::handleClientsDisconnected(const CEvent&, void*) { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } void @@ -343,17 +327,17 @@ CServerApp::closeServer(CServer* server) // wait for clients to disconnect for up to timeout seconds double timeout = 3.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(this, &CServerApp::handleClientsDisconnected)); - EVENTQUEUE->adoptHandler(CServer::getDisconnectedEvent(), server, + m_events->adoptHandler(m_events->forCServer().disconnected(), server, new TMethodEventJob(this, &CServerApp::handleClientsDisconnected)); - EVENTQUEUE->loop(); + m_events->loop(); - EVENTQUEUE->removeHandler(CEvent::kTimer, timer); - EVENTQUEUE->deleteTimer(timer); - EVENTQUEUE->removeHandler(CServer::getDisconnectedEvent(), server); + m_events->removeHandler(CEvent::kTimer, timer); + m_events->deleteTimer(timer); + m_events->removeHandler(m_events->forCServer().disconnected(), server); // done with server delete server; @@ -363,8 +347,8 @@ void CServerApp::stopRetryTimer() { if (s_timer != NULL) { - EVENTQUEUE->deleteTimer(s_timer); - EVENTQUEUE->removeHandler(CEvent::kTimer, NULL); + m_events->deleteTimer(s_timer); + m_events->removeHandler(CEvent::kTimer, NULL); s_timer = NULL; } } @@ -387,7 +371,7 @@ void CServerApp::closeClientListener(CClientListener* listen) { if (listen != NULL) { - EVENTQUEUE->removeHandler(CClientListener::getConnectedEvent(), listen); + m_events->removeHandler(m_events->forCClientListener().connected(), listen); delete listen; } } @@ -420,11 +404,11 @@ void CServerApp::closeServerScreen(CScreen* screen) { if (screen != NULL) { - EVENTQUEUE->removeHandler(IScreen::getErrorEvent(), + m_events->removeHandler(m_events->forIScreen().error(), screen->getEventTarget()); - EVENTQUEUE->removeHandler(IScreen::getSuspendEvent(), + m_events->removeHandler(m_events->forIScreen().suspend(), screen->getEventTarget()); - EVENTQUEUE->removeHandler(IScreen::getResumeEvent(), + m_events->removeHandler(m_events->forIScreen().resume(), screen->getEventTarget()); delete screen; } @@ -469,7 +453,7 @@ CServerApp::retryHandler(const CEvent&, void*) LOG((CLOG_DEBUG1 "retry server initialization")); s_serverState = kUninitialized; if (!initServer()) { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } break; @@ -477,12 +461,12 @@ CServerApp::retryHandler(const CEvent&, void*) LOG((CLOG_DEBUG1 "retry server initialization")); s_serverState = kUninitialized; if (!initServer()) { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } else if (s_serverState == kInitialized) { LOG((CLOG_DEBUG1 "starting server")); if (!startServer()) { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } } break; @@ -491,7 +475,7 @@ CServerApp::retryHandler(const CEvent&, void*) LOG((CLOG_DEBUG1 "retry starting server")); s_serverState = kInitialized; if (!startServer()) { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } break; } @@ -541,8 +525,8 @@ bool CServerApp::initServer() // install a timer and handler to retry later assert(s_timer == NULL); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); - s_timer = EVENTQUEUE->newOneShotTimer(retryTime, NULL); - EVENTQUEUE->adoptHandler(CEvent::kTimer, s_timer, + s_timer = m_events->newOneShotTimer(retryTime, NULL); + m_events->adoptHandler(CEvent::kTimer, s_timer, new TMethodEventJob(this, &CServerApp::retryHandler)); s_serverState = kInitializing; return true; @@ -556,15 +540,15 @@ bool CServerApp::initServer() CScreen* CServerApp::openServerScreen() { CScreen* screen = createScreen(); - EVENTQUEUE->adoptHandler(IScreen::getErrorEvent(), + m_events->adoptHandler(m_events->forIScreen().error(), screen->getEventTarget(), new TMethodEventJob( this, &CServerApp::handleScreenError)); - EVENTQUEUE->adoptHandler(IScreen::getSuspendEvent(), + m_events->adoptHandler(m_events->forIScreen().suspend(), screen->getEventTarget(), new TMethodEventJob( this, &CServerApp::handleSuspend)); - EVENTQUEUE->adoptHandler(IScreen::getResumeEvent(), + m_events->adoptHandler(m_events->forIScreen().resume(), screen->getEventTarget(), new TMethodEventJob( this, &CServerApp::handleResume)); @@ -621,8 +605,8 @@ CServerApp::startServer() // install a timer and handler to retry later assert(s_timer == NULL); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); - s_timer = EVENTQUEUE->newOneShotTimer(retryTime, NULL); - EVENTQUEUE->adoptHandler(CEvent::kTimer, s_timer, + s_timer = m_events->newOneShotTimer(retryTime, NULL); + m_events->adoptHandler(CEvent::kTimer, s_timer, new TMethodEventJob(this, &CServerApp::retryHandler)); s_serverState = kStarting; return true; @@ -638,10 +622,10 @@ CServerApp::createScreen() { #if WINAPI_MSWINDOWS return new CScreen(new CMSWindowsScreen( - true, args().m_noHooks, args().m_gameDevice, args().m_stopOnDeskSwitch)); + true, args().m_noHooks, args().m_gameDevice, args().m_stopOnDeskSwitch, m_events), m_events); #elif WINAPI_XWINDOWS return new CScreen(new CXWindowsScreen( - args().m_display, true, args().m_disableXInitThreads, 0, *EVENTQUEUE)); + args().m_display, true, args().m_disableXInitThreads, 0, m_events)); #elif WINAPI_CARBON return new CScreen(new COSXScreen(true)); #endif @@ -659,7 +643,7 @@ void CServerApp::handleScreenError(const CEvent&, void*) { LOG((CLOG_CRIT "error on screen")); - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } void @@ -685,26 +669,30 @@ CServerApp::handleResume(const CEvent&, void*) CClientListener* CServerApp::openClientListener(const CNetworkAddress& address) { - CClientListener* listen = - new CClientListener(address, new CTCPSocketFactory, NULL, args().m_crypto); - EVENTQUEUE->adoptHandler(CClientListener::getConnectedEvent(), listen, + CClientListener* listen = new CClientListener( + address, new CTCPSocketFactory(m_events), + NULL, args().m_crypto, m_events); + + m_events->adoptHandler( + m_events->forCClientListener().connected(), listen, new TMethodEventJob( - this, &CServerApp::handleClientConnected, listen)); + this, &CServerApp::handleClientConnected, listen)); + return listen; } CServer* CServerApp::openServer(const CConfig& config, CPrimaryClient* primaryClient) { - CServer* server = new CServer(config, primaryClient, s_serverScreen); + CServer* server = new CServer(config, primaryClient, s_serverScreen, m_events); try { - EVENTQUEUE->adoptHandler( - CServer::getDisconnectedEvent(), server, + m_events->adoptHandler( + m_events->forCServer().disconnected(), server, new TMethodEventJob(this, &CServerApp::handleNoClients)); - EVENTQUEUE->adoptHandler( - CServer::getScreenSwitchedEvent(), server, + m_events->adoptHandler( + m_events->forCServer().screenSwitched(), server, new TMethodEventJob(this, &CServerApp::handleScreenSwitched)); } catch (std::bad_alloc &ba) { @@ -766,39 +754,39 @@ CServerApp::mainLoop() } // load all available plugins. - ARCH->plugin().init(s_serverScreen->getEventTarget()); + ARCH->plugin().init(s_serverScreen->getEventTarget(), m_events); // handle hangup signal by reloading the server's configuration ARCH->setSignalHandler(CArch::kHANGUP, &reloadSignalHandler, NULL); - EVENTQUEUE->adoptHandler(getReloadConfigEvent(), - IEventQueue::getSystemTarget(), + m_events->adoptHandler(m_events->forCServerApp().reloadConfig(), + m_events->getSystemTarget(), new TMethodEventJob(this, &CServerApp::reloadConfig)); // handle force reconnect event by disconnecting clients. they'll // reconnect automatically. - EVENTQUEUE->adoptHandler(getForceReconnectEvent(), - IEventQueue::getSystemTarget(), + m_events->adoptHandler(m_events->forCServerApp().forceReconnect(), + m_events->getSystemTarget(), new TMethodEventJob(this, &CServerApp::forceReconnect)); // to work around the sticky meta keys problem, we'll give users // the option to reset the state of synergys - EVENTQUEUE->adoptHandler(getResetServerEvent(), - IEventQueue::getSystemTarget(), + m_events->adoptHandler(m_events->forCServerApp().resetServer(), + m_events->getSystemTarget(), new TMethodEventJob(this, &CServerApp::resetServer)); // run event loop. if startServer() failed we're supposed to retry // later. the timer installed by startServer() will take care of // that. DAEMON_RUNNING(true); - EVENTQUEUE->loop(); + m_events->loop(); DAEMON_RUNNING(false); // close down LOG((CLOG_DEBUG1 "stopping server")); - EVENTQUEUE->removeHandler(getForceReconnectEvent(), - IEventQueue::getSystemTarget()); - EVENTQUEUE->removeHandler(getReloadConfigEvent(), - IEventQueue::getSystemTarget()); + m_events->removeHandler(m_events->forCServerApp().forceReconnect(), + m_events->getSystemTarget()); + m_events->removeHandler(m_events->forCServerApp().reloadConfig(), + m_events->getSystemTarget()); cleanupServer(); updateStatus(); LOG((CLOG_NOTE "stopped server")); @@ -823,7 +811,7 @@ CServerApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFun { // general initialization args().m_synergyAddress = new CNetworkAddress; - args().m_config = new CConfig; + args().m_config = new CConfig(m_events); args().m_pname = ARCH->getBasename(argv[0]); // install caller's output filter diff --git a/src/lib/synergy/CServerApp.h b/src/lib/synergy/CServerApp.h index 30c86287..0bf3e715 100644 --- a/src/lib/synergy/CServerApp.h +++ b/src/lib/synergy/CServerApp.h @@ -26,6 +26,7 @@ #include "IArchMultithread.h" #include "CArgsBase.h" #include +#include "CEventTypes.h" enum EServerState { kUninitialized, @@ -41,6 +42,7 @@ class CScreen; class CClientListener; class CEventQueueTimer; class ILogOutputter; +class IEventQueue; class CServerApp : public CApp { public: @@ -55,7 +57,7 @@ public: CConfig* m_config; }; - CServerApp(CreateTaskBarReceiverFunc createTaskBarReceiver); + CServerApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver); virtual ~CServerApp(); // Parse server specific command line arguments. @@ -72,15 +74,12 @@ public: // TODO: Document these functions. static void reloadSignalHandler(CArch::ESignal, void*); - static CEvent::Type getReloadConfigEvent(); void reloadConfig(const CEvent&, void*); void loadConfig(); bool loadConfig(const CString& pathname); void forceReconnect(const CEvent&, void*); - CEvent::Type getForceReconnectEvent(); void resetServer(const CEvent&, void*); - CEvent::Type getResetServerEvent(); void handleClientConnected(const CEvent&, void* vlistener); void handleClientsDisconnected(const CEvent&, void*); void closeServer(CServer* server); @@ -113,15 +112,14 @@ public: static CServerApp& instance() { return (CServerApp&)CApp::instance(); } // TODO: change s_ to m_ - CServer* s_server; - static CEvent::Type s_reloadConfigEvent; - CEvent::Type s_forceReconnectEvent; - CEvent::Type s_resetServerEvent; - EServerState s_serverState; - CScreen* s_serverScreen; - CPrimaryClient* s_primaryClient; - CClientListener* s_listener; - CEventQueueTimer* s_timer; + CServer* s_server; + EServerState s_serverState; + CScreen* s_serverScreen; + CPrimaryClient* s_primaryClient; + CClientListener* s_listener; + CEventQueueTimer* s_timer; + + IEventQueue* m_events; private: virtual bool parseArg(const int& argc, const char* const* argv, int& i); diff --git a/src/lib/synergy/CServerTaskBarReceiver.cpp b/src/lib/synergy/CServerTaskBarReceiver.cpp index ddf68219..87e91415 100644 --- a/src/lib/synergy/CServerTaskBarReceiver.cpp +++ b/src/lib/synergy/CServerTaskBarReceiver.cpp @@ -28,7 +28,8 @@ // CServerTaskBarReceiver // -CServerTaskBarReceiver::CServerTaskBarReceiver() : +CServerTaskBarReceiver::CServerTaskBarReceiver(IEventQueue* events) : + m_events(events), m_state(kNotRunning) { // do nothing @@ -93,7 +94,7 @@ CServerTaskBarReceiver::getClients() const void CServerTaskBarReceiver::quit() { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events->addEvent(CEvent(CEvent::kQuit)); } void @@ -135,21 +136,3 @@ CServerTaskBarReceiver::getToolTip() const return ""; } } - -CEvent::Type -CServerTaskBarReceiver::getReloadConfigEvent() -{ - return CServerApp::instance().getReloadConfigEvent(); -} - -CEvent::Type -CServerTaskBarReceiver::getForceReconnectEvent() -{ - return CServerApp::instance().getForceReconnectEvent(); -} - -CEvent::Type -CServerTaskBarReceiver::getResetServerEvent() -{ - return CServerApp::instance().getResetServerEvent(); -} diff --git a/src/lib/synergy/CServerTaskBarReceiver.h b/src/lib/synergy/CServerTaskBarReceiver.h index 6a1b1dc8..46af7c12 100644 --- a/src/lib/synergy/CServerTaskBarReceiver.h +++ b/src/lib/synergy/CServerTaskBarReceiver.h @@ -25,11 +25,14 @@ #include "CEvent.h" #include "CServerApp.h" #include "CServer.h" +#include "CEventTypes.h" + +class IEventQueue; //! Implementation of IArchTaskBarReceiver for the synergy server class CServerTaskBarReceiver : public IArchTaskBarReceiver { public: - CServerTaskBarReceiver(); + CServerTaskBarReceiver(IEventQueue* events); virtual ~CServerTaskBarReceiver(); //! @name manipulators @@ -86,17 +89,13 @@ protected: */ virtual void onStatusChanged(CServer* server); -protected: - CEvent::Type getReloadConfigEvent(); - CEvent::Type getForceReconnectEvent(); - CEvent::Type getResetServerEvent(); - private: EState m_state; CString m_errorMessage; CClients m_clients; + IEventQueue* m_events; }; -IArchTaskBarReceiver* createTaskBarReceiver(const CBufferedLogOutputter* logBuffer); +IArchTaskBarReceiver* createTaskBarReceiver(const CBufferedLogOutputter* logBuffer, IEventQueue* events); #endif diff --git a/src/lib/synergy/IApp.h b/src/lib/synergy/IApp.h index 88c0d96e..0879760d 100644 --- a/src/lib/synergy/IApp.h +++ b/src/lib/synergy/IApp.h @@ -26,6 +26,7 @@ class ILogOutputter; class CArgsBase; class IArchTaskBarReceiver; class CScreen; +class IEventQueue; class IApp : public IInterface { @@ -45,4 +46,5 @@ public: virtual const char* daemonName() const = 0; virtual int foregroundStartup(int argc, char** argv) = 0; virtual CScreen* createScreen() = 0; + virtual IEventQueue* events() const = 0; }; diff --git a/src/lib/synergy/IKeyState.cpp b/src/lib/synergy/IKeyState.cpp index 1cfde581..c650c5b9 100644 --- a/src/lib/synergy/IKeyState.cpp +++ b/src/lib/synergy/IKeyState.cpp @@ -25,41 +25,11 @@ // IKeyState // -CEvent::Type IKeyState::s_keyDownEvent = CEvent::kUnknown; -CEvent::Type IKeyState::s_keyUpEvent = CEvent::kUnknown; -CEvent::Type IKeyState::s_keyRepeatEvent = CEvent::kUnknown; - -IKeyState::IKeyState() : - m_eventQueue(*EVENTQUEUE) +IKeyState::IKeyState(IEventQueue* events) : + m_events(events) { } -IKeyState::IKeyState(IEventQueue& eventQueue) : - m_eventQueue(eventQueue) -{ -} - -CEvent::Type -IKeyState::getKeyDownEvent(IEventQueue& eventQueue) -{ - return eventQueue.registerTypeOnce(s_keyDownEvent, - "IKeyState::keyDown"); -} - -CEvent::Type -IKeyState::getKeyUpEvent(IEventQueue& eventQueue) -{ - return eventQueue.registerTypeOnce(s_keyUpEvent, - "IKeyState::keyUp"); -} - -CEvent::Type -IKeyState::getKeyRepeatEvent(IEventQueue& eventQueue) -{ - return eventQueue.registerTypeOnce(s_keyRepeatEvent, - "IKeyState::keyRepeat"); -} - // // IKeyState::CKeyInfo // diff --git a/src/lib/synergy/IKeyState.h b/src/lib/synergy/IKeyState.h index 904edbe8..408befd9 100644 --- a/src/lib/synergy/IKeyState.h +++ b/src/lib/synergy/IKeyState.h @@ -25,6 +25,7 @@ #include "CString.h" #include "stdset.h" #include "IEventQueue.h" +#include "CEventTypes.h" //! Key state interface /*! @@ -33,8 +34,7 @@ to synthesize key events. */ class IKeyState : public IInterface { public: - IKeyState(); - IKeyState(IEventQueue& eventQueue); + IKeyState(IEventQueue* events); enum { kNumButtons = 0x200 @@ -164,34 +164,10 @@ public: */ virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const = 0; - //! Get key down event type. Event data is CKeyInfo*, count == 1. - CEvent::Type getKeyDownEvent() { return getKeyDownEvent(m_eventQueue); } - - //! Get key up event type. Event data is CKeyInfo*, count == 1. - CEvent::Type getKeyUpEvent() { return getKeyUpEvent(m_eventQueue); } - - //! Get key repeat event type. Event data is CKeyInfo*. - CEvent::Type getKeyRepeatEvent() { return getKeyRepeatEvent(m_eventQueue); } - - //! Get key down event type. Event data is CKeyInfo*, count == 1. - static CEvent::Type getKeyDownEvent(IEventQueue& eventQueue); - - //! Get key up event type. Event data is CKeyInfo*, count == 1. - static CEvent::Type getKeyUpEvent(IEventQueue& eventQueue); - - //! Get key repeat event type. Event data is CKeyInfo*. - static CEvent::Type getKeyRepeatEvent(IEventQueue& eventQueue); - //@} -protected: - IEventQueue& getEventQueue() const { return m_eventQueue; } - private: - static CEvent::Type s_keyDownEvent; - static CEvent::Type s_keyUpEvent; - static CEvent::Type s_keyRepeatEvent; - IEventQueue& m_eventQueue; + IEventQueue* m_events; }; #endif diff --git a/src/lib/synergy/IPlatformScreen.h b/src/lib/synergy/IPlatformScreen.h index 55421126..7dab0632 100644 --- a/src/lib/synergy/IPlatformScreen.h +++ b/src/lib/synergy/IPlatformScreen.h @@ -41,8 +41,7 @@ public: //! @name manipulators //@{ - IPlatformScreen() { } - IPlatformScreen(IEventQueue& eventQueue) : IKeyState(eventQueue) { } + IPlatformScreen(IEventQueue* events) : IKeyState(events) { } //! Enable screen /*! @@ -198,8 +197,8 @@ protected: A platform screen is expected to install a handler for system events in its c'tor like so: \code - EVENTQUEUE->adoptHandler(CEvent::kSystem, - IEventQueue::getSystemTarget(), + m_events->adoptHandler(CEvent::kSystem, + m_events->getSystemTarget(), new TMethodEventJob(this, &CXXXPlatformScreen::handleSystemEvent)); \endcode diff --git a/src/lib/synergy/IPrimaryScreen.cpp b/src/lib/synergy/IPrimaryScreen.cpp index 70c16cb3..432f8f24 100644 --- a/src/lib/synergy/IPrimaryScreen.cpp +++ b/src/lib/synergy/IPrimaryScreen.cpp @@ -20,131 +20,6 @@ #include "CEventQueue.h" #include -// -// IPrimaryScreen -// - -CEvent::Type IPrimaryScreen::s_buttonDownEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_buttonUpEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_motionPrimaryEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_motionSecondaryEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_wheelEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_ssActivatedEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_ssDeactivatedEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_hotKeyDownEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_hotKeyUpEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_fakeInputBegin = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_fakeInputEnd = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_gameButtonsEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_gameSticksEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_gameTriggersEvent = CEvent::kUnknown; -CEvent::Type IPrimaryScreen::s_gameTimingReqEvent = CEvent::kUnknown; - -CEvent::Type -IPrimaryScreen::getButtonDownEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_buttonDownEvent, - "IPrimaryScreen::buttonDown"); -} - -CEvent::Type -IPrimaryScreen::getButtonUpEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_buttonUpEvent, - "IPrimaryScreen::buttonUp"); -} - -CEvent::Type -IPrimaryScreen::getMotionOnPrimaryEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_motionPrimaryEvent, - "IPrimaryScreen::motionPrimary"); -} - -CEvent::Type -IPrimaryScreen::getMotionOnSecondaryEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_motionSecondaryEvent, - "IPrimaryScreen::motionSecondary"); -} - -CEvent::Type -IPrimaryScreen::getWheelEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_wheelEvent, - "IPrimaryScreen::wheel"); -} - -CEvent::Type -IPrimaryScreen::getScreensaverActivatedEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_ssActivatedEvent, - "IPrimaryScreen::screensaverActivated"); -} - -CEvent::Type -IPrimaryScreen::getScreensaverDeactivatedEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_ssDeactivatedEvent, - "IPrimaryScreen::screensaverDeactivated"); -} - -CEvent::Type -IPrimaryScreen::getHotKeyDownEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_hotKeyDownEvent, - "IPrimaryScreen::hotKeyDown"); -} - -CEvent::Type -IPrimaryScreen::getHotKeyUpEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_hotKeyUpEvent, - "IPrimaryScreen::hotKeyUp"); -} - -CEvent::Type -IPrimaryScreen::getFakeInputBeginEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_fakeInputBegin, - "IPrimaryScreen::fakeInputBegin"); -} - -CEvent::Type -IPrimaryScreen::getFakeInputEndEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_fakeInputEnd, - "IPrimaryScreen::fakeInputEnd"); -} - -CEvent::Type -IPrimaryScreen::getGameDeviceButtonsEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_gameButtonsEvent, - "IPrimaryScreen::getGameDeviceButtonsEvent"); -} - -CEvent::Type -IPrimaryScreen::getGameDeviceSticksEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_gameSticksEvent, - "IPrimaryScreen::getGameDeviceSticksEvent"); -} - -CEvent::Type -IPrimaryScreen::getGameDeviceTriggersEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_gameTriggersEvent, - "IPrimaryScreen::getGameDeviceTriggersEvent"); -} - -CEvent::Type -IPrimaryScreen::getGameDeviceTimingReqEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_gameTimingReqEvent, - "IPrimaryScreen::getGameDeviceTimingReqEvent"); -} - // // IPrimaryScreen::CButtonInfo // diff --git a/src/lib/synergy/IPrimaryScreen.h b/src/lib/synergy/IPrimaryScreen.h index 5f85edab..586897ae 100644 --- a/src/lib/synergy/IPrimaryScreen.h +++ b/src/lib/synergy/IPrimaryScreen.h @@ -24,13 +24,14 @@ #include "MouseTypes.h" #include "CEvent.h" #include "GameDeviceTypes.h" +#include "CEventTypes.h" //! Primary screen interface /*! This interface defines the methods common to all platform dependent primary screen implementations. */ -class IPrimaryScreen : public IInterface { +class IPrimaryScreen : public IInterface { public: //! Button event data class CButtonInfo { @@ -217,64 +218,7 @@ public: //! Handle incoming game device feedback changes. virtual void gameDeviceFeedback(GameDeviceID id, UInt16 m1, UInt16 m2) = 0; - //! Get button down event type. Event data is CButtonInfo*. - static CEvent::Type getButtonDownEvent(); - //! Get button up event type. Event data is CButtonInfo*. - static CEvent::Type getButtonUpEvent(); - //! Get mouse motion on the primary screen event type - /*! - Event data is CMotionInfo* and the values are an absolute position. - */ - static CEvent::Type getMotionOnPrimaryEvent(); - //! Get mouse motion on a secondary screen event type - /*! - Event data is CMotionInfo* and the values are motion deltas not - absolute coordinates. - */ - static CEvent::Type getMotionOnSecondaryEvent(); - //! Get mouse wheel event type. Event data is CWheelInfo*. - static CEvent::Type getWheelEvent(); - //! Get screensaver activated event type - static CEvent::Type getScreensaverActivatedEvent(); - //! Get screensaver deactivated event type - static CEvent::Type getScreensaverDeactivatedEvent(); - //! Get hot key down event type. Event data is CHotKeyInfo*. - static CEvent::Type getHotKeyDownEvent(); - //! Get hot key up event type. Event data is CHotKeyInfo*. - static CEvent::Type getHotKeyUpEvent(); - //! Get start of fake input event type - static CEvent::Type getFakeInputBeginEvent(); - //! Get end of fake input event type - static CEvent::Type getFakeInputEndEvent(); -public: // HACK - //! Get game device buttons event type. - static CEvent::Type getGameDeviceButtonsEvent(); - //! Get game device sticks event type. - static CEvent::Type getGameDeviceSticksEvent(); - //! Get game device triggers event type. - static CEvent::Type getGameDeviceTriggersEvent(); - //! Get game device timing request event type. - static CEvent::Type getGameDeviceTimingReqEvent(); -private: // HACK - //@} - -private: - static CEvent::Type s_buttonDownEvent; - static CEvent::Type s_buttonUpEvent; - static CEvent::Type s_motionPrimaryEvent; - static CEvent::Type s_motionSecondaryEvent; - static CEvent::Type s_wheelEvent; - static CEvent::Type s_ssActivatedEvent; - static CEvent::Type s_ssDeactivatedEvent; - static CEvent::Type s_hotKeyDownEvent; - static CEvent::Type s_hotKeyUpEvent; - static CEvent::Type s_fakeInputBegin; - static CEvent::Type s_fakeInputEnd; - static CEvent::Type s_gameButtonsEvent; - static CEvent::Type s_gameSticksEvent; - static CEvent::Type s_gameTriggersEvent; - static CEvent::Type s_gameTimingReqEvent; }; #endif diff --git a/src/lib/synergy/IScreen.cpp b/src/lib/synergy/IScreen.cpp deleted file mode 100644 index 7f7f1217..00000000 --- a/src/lib/synergy/IScreen.cpp +++ /dev/null @@ -1,65 +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 . - */ - -#include "IScreen.h" -#include "CEventQueue.h" - -// -// IScreen -// - -CEvent::Type IScreen::s_errorEvent = CEvent::kUnknown; -CEvent::Type IScreen::s_shapeChangedEvent = CEvent::kUnknown; -CEvent::Type IScreen::s_clipboardGrabbedEvent = CEvent::kUnknown; -CEvent::Type IScreen::s_suspendEvent = CEvent::kUnknown; -CEvent::Type IScreen::s_resumeEvent = CEvent::kUnknown; - -CEvent::Type -IScreen::getErrorEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_errorEvent, - "IScreen::error"); -} - -CEvent::Type -IScreen::getShapeChangedEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_shapeChangedEvent, - "IScreen::shapeChanged"); -} - -CEvent::Type -IScreen::getClipboardGrabbedEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_clipboardGrabbedEvent, - "IScreen::clipboardGrabbed"); -} - -CEvent::Type -IScreen::getSuspendEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_suspendEvent, - "IScreen::suspend"); -} - -CEvent::Type -IScreen::getResumeEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_resumeEvent, - "IScreen::resume"); -} diff --git a/src/lib/synergy/IScreen.h b/src/lib/synergy/IScreen.h index b6a76288..361b3400 100644 --- a/src/lib/synergy/IScreen.h +++ b/src/lib/synergy/IScreen.h @@ -22,6 +22,7 @@ #include "IInterface.h" #include "ClipboardTypes.h" #include "CEvent.h" +#include "CEventTypes.h" class IClipboard; @@ -29,7 +30,7 @@ class IClipboard; /*! This interface defines the methods common to all screens. */ -class IScreen : public IInterface { +class IScreen : public IInterface { public: struct CClipboardInfo { public: @@ -66,51 +67,8 @@ public: Return the current position of the cursor in \c x and \c y. */ virtual void getCursorPos(SInt32& x, SInt32& y) const = 0; - - //! 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). - */ - static CEvent::Type getErrorEvent(); - - //! Get shape changed event type - /*! - Returns the shape changed event type. This is sent whenever the - screen's shape changes. - */ - static CEvent::Type getShapeChangedEvent(); - - //! 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. - */ - static CEvent::Type getClipboardGrabbedEvent(); - - //! 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). - */ - static CEvent::Type getSuspendEvent(); - - //! 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). - */ - static CEvent::Type getResumeEvent(); //@} - -private: - static CEvent::Type s_errorEvent; - static CEvent::Type s_shapeChangedEvent; - static CEvent::Type s_clipboardGrabbedEvent; - static CEvent::Type s_suspendEvent; - static CEvent::Type s_resumeEvent; }; #endif diff --git a/src/lib/synergy/ISecondaryScreen.cpp b/src/lib/synergy/ISecondaryScreen.cpp deleted file mode 100644 index 91079af7..00000000 --- a/src/lib/synergy/ISecondaryScreen.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012 Bolton Software Ltd. - * Copyright (C) 2011 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 . - */ - -#include "ISecondaryScreen.h" -#include "IEventQueue.h" - -CEvent::Type ISecondaryScreen::s_gameTimingRespEvent = CEvent::kUnknown; -CEvent::Type ISecondaryScreen::s_gameFeedbackEvent = CEvent::kUnknown; - -CEvent::Type -ISecondaryScreen::getGameDeviceTimingRespEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_gameTimingRespEvent, - "ISecondaryScreen::getGameDeviceTimingRespEvent"); -} - -CEvent::Type -ISecondaryScreen::getGameDeviceFeedbackEvent() -{ - return EVENTQUEUE->registerTypeOnce(s_gameFeedbackEvent, - "ISecondaryScreen::getGameDeviceFeedbackEvent"); -} diff --git a/src/lib/synergy/ISecondaryScreen.h b/src/lib/synergy/ISecondaryScreen.h index 6473daab..a8c68d74 100644 --- a/src/lib/synergy/ISecondaryScreen.h +++ b/src/lib/synergy/ISecondaryScreen.h @@ -23,6 +23,7 @@ #include "MouseTypes.h" #include "GameDeviceTypes.h" #include "CEvent.h" +#include "CEventTypes.h" //! Secondary screen interface /*! @@ -76,17 +77,7 @@ public: */ virtual void fakeGameDeviceTriggers(GameDeviceID id, UInt8 t1, UInt8 t2) const = 0; - //! Get game device timing response event type. - static CEvent::Type getGameDeviceTimingRespEvent(); - - //! Get game device feedback event type. - static CEvent::Type getGameDeviceFeedbackEvent(); - //@} - -private: - static CEvent::Type s_gameTimingRespEvent; - static CEvent::Type s_gameFeedbackEvent; }; #endif diff --git a/src/test/integtests/CIpcTests.cpp b/src/test/integtests/CIpcTests.cpp index 904a4017..0ab4f8b3 100644 --- a/src/test/integtests/CIpcTests.cpp +++ b/src/test/integtests/CIpcTests.cpp @@ -73,21 +73,21 @@ public: TEST_F(CIpcTests, connectToServer) { - CIpcServer server(TEST_IPC_PORT); + CIpcServer server(&m_events, TEST_IPC_PORT); server.listen(); m_connectToServer_server = &server; m_events.adoptHandler( - CIpcServer::getMessageReceivedEvent(), &server, + m_events.forCIpcServer().messageReceived(), &server, new TMethodEventJob( this, &CIpcTests::connectToServer_handleMessageReceived)); - CIpcClient client(TEST_IPC_PORT); + CIpcClient client(&m_events, TEST_IPC_PORT); client.connect(); initQuitTimeout(5); m_events.loop(); - m_events.removeHandler(CIpcServer::getMessageReceivedEvent(), &server); + m_events.removeHandler(m_events.forCIpcServer().messageReceived(), &server); cleanupQuitTimeout(); EXPECT_EQ(true, m_connectToServer_helloMessageReceived); @@ -96,22 +96,22 @@ TEST_F(CIpcTests, connectToServer) TEST_F(CIpcTests, sendMessageToServer) { - CIpcServer server(TEST_IPC_PORT); + CIpcServer server(&m_events, TEST_IPC_PORT); server.listen(); // event handler sends "test" command to server. m_events.adoptHandler( - CIpcServer::getMessageReceivedEvent(), &server, + m_events.forCIpcServer().messageReceived(), &server, new TMethodEventJob( this, &CIpcTests::sendMessageToServer_serverHandleMessageReceived)); - CIpcClient client(TEST_IPC_PORT); + CIpcClient client(&m_events, TEST_IPC_PORT); client.connect(); m_sendMessageToServer_client = &client; initQuitTimeout(5); m_events.loop(); - m_events.removeHandler(CIpcServer::getMessageReceivedEvent(), &server); + m_events.removeHandler(m_events.forCIpcServer().messageReceived(), &server); cleanupQuitTimeout(); EXPECT_EQ("test", m_sendMessageToServer_receivedString); @@ -119,28 +119,28 @@ TEST_F(CIpcTests, sendMessageToServer) TEST_F(CIpcTests, sendMessageToClient) { - CIpcServer server(TEST_IPC_PORT); + CIpcServer server(&m_events, TEST_IPC_PORT); server.listen(); m_sendMessageToClient_server = &server; // event handler sends "test" log line to client. m_events.adoptHandler( - CIpcServer::getMessageReceivedEvent(), &server, + m_events.forCIpcServer().messageReceived(), &server, new TMethodEventJob( this, &CIpcTests::sendMessageToClient_serverHandleClientConnected)); - CIpcClient client(TEST_IPC_PORT); + CIpcClient client(&m_events, TEST_IPC_PORT); client.connect(); m_events.adoptHandler( - CIpcClient::getMessageReceivedEvent(), &client, + m_events.forCIpcClient().messageReceived(), &client, new TMethodEventJob( this, &CIpcTests::sendMessageToClient_clientHandleMessageReceived)); initQuitTimeout(5); m_events.loop(); - m_events.removeHandler(CIpcServer::getMessageReceivedEvent(), &server); - m_events.removeHandler(CIpcClient::getMessageReceivedEvent(), &client); + m_events.removeHandler(m_events.forCIpcServer().messageReceived(), &server); + m_events.removeHandler(m_events.forCIpcClient().messageReceived(), &client); cleanupQuitTimeout(); EXPECT_EQ("test", m_sendMessageToClient_receivedString); @@ -215,15 +215,15 @@ CIpcTests::sendMessageToClient_clientHandleMessageReceived(const CEvent& e, void void CIpcTests::raiseQuitEvent() { - EVENTQUEUE->addEvent(CEvent(CEvent::kQuit)); + m_events.addEvent(CEvent(CEvent::kQuit)); } void CIpcTests::initQuitTimeout(double timeout) { assert(m_quitTimeoutTimer == nullptr); - m_quitTimeoutTimer = EVENTQUEUE->newOneShotTimer(timeout, NULL); - EVENTQUEUE->adoptHandler(CEvent::kTimer, m_quitTimeoutTimer, + m_quitTimeoutTimer = m_events.newOneShotTimer(timeout, NULL); + m_events.adoptHandler(CEvent::kTimer, m_quitTimeoutTimer, new TMethodEventJob( this, &CIpcTests::handleQuitTimeout)); } @@ -231,7 +231,7 @@ CIpcTests::initQuitTimeout(double timeout) void CIpcTests::cleanupQuitTimeout() { - EVENTQUEUE->removeHandler(CEvent::kTimer, m_quitTimeoutTimer); + m_events.removeHandler(CEvent::kTimer, m_quitTimeoutTimer); delete m_quitTimeoutTimer; m_quitTimeoutTimer = nullptr; } diff --git a/src/test/integtests/platform/CMSWindowsKeyStateTests.cpp b/src/test/integtests/platform/CMSWindowsKeyStateTests.cpp index 445099ea..322fd3ff 100644 --- a/src/test/integtests/platform/CMSWindowsKeyStateTests.cpp +++ b/src/test/integtests/platform/CMSWindowsKeyStateTests.cpp @@ -51,7 +51,7 @@ protected: delete m_screensaver; } - CMSWindowsDesks* newDesks(IEventQueue& eventQueue) + CMSWindowsDesks* newDesks(IEventQueue* eventQueue) { return new CMSWindowsDesks( true, false, m_hookLibrary, m_screensaver, eventQueue, @@ -74,9 +74,9 @@ private: TEST_F(CMSWindowsKeyStateTests, disable_nonWin95OS_eventQueueNotUsed) { NiceMock eventQueue; - CMSWindowsDesks* desks = newDesks(eventQueue); + CMSWindowsDesks* desks = newDesks(&eventQueue); CMockKeyMap keyMap; - CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap); + CMSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); // in anything above win95-family, event handler should not be called. EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(0); @@ -88,9 +88,9 @@ TEST_F(CMSWindowsKeyStateTests, disable_nonWin95OS_eventQueueNotUsed) TEST_F(CMSWindowsKeyStateTests, testAutoRepeat_noRepeatAndButtonIsZero_resultIsTrue) { NiceMock eventQueue; - CMSWindowsDesks* desks = newDesks(eventQueue); + CMSWindowsDesks* desks = newDesks(&eventQueue); CMockKeyMap keyMap; - CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap); + CMSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); keyState.setLastDown(1); bool actual = keyState.testAutoRepeat(true, false, 1); @@ -102,9 +102,9 @@ TEST_F(CMSWindowsKeyStateTests, testAutoRepeat_noRepeatAndButtonIsZero_resultIsT TEST_F(CMSWindowsKeyStateTests, testAutoRepeat_pressFalse_lastDownIsZero) { NiceMock eventQueue; - CMSWindowsDesks* desks = newDesks(eventQueue); + CMSWindowsDesks* desks = newDesks(&eventQueue); CMockKeyMap keyMap; - CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap); + CMSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); keyState.setLastDown(1); keyState.testAutoRepeat(false, false, 1); @@ -116,9 +116,9 @@ TEST_F(CMSWindowsKeyStateTests, testAutoRepeat_pressFalse_lastDownIsZero) TEST_F(CMSWindowsKeyStateTests, saveModifiers_noModifiers_savedModifiers0) { NiceMock eventQueue; - CMSWindowsDesks* desks = newDesks(eventQueue); + CMSWindowsDesks* desks = newDesks(&eventQueue); CMockKeyMap keyMap; - CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap); + CMSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); keyState.saveModifiers(); diff --git a/src/test/integtests/platform/COSXKeyStateTests.cpp b/src/test/integtests/platform/COSXKeyStateTests.cpp index f20e8344..f965142c 100644 --- a/src/test/integtests/platform/COSXKeyStateTests.cpp +++ b/src/test/integtests/platform/COSXKeyStateTests.cpp @@ -40,7 +40,7 @@ TEST_F(COSXKeyStateTests, fakeAndPoll_shift) { CKeyMap keyMap; CMockEventQueue eventQueue; - COSXKeyState keyState((IEventQueue&)eventQueue, keyMap); + COSXKeyState keyState((IEventQueue*)eventQueue, keyMap); keyState.updateKeyMap(); keyState.fakeKeyDown(SHIFT_ID_L, 0, 1); @@ -60,7 +60,7 @@ TEST_F(COSXKeyStateTests, fakeAndPoll_charKey) { CKeyMap keyMap; CMockEventQueue eventQueue; - COSXKeyState keyState((IEventQueue&)eventQueue, keyMap); + COSXKeyState keyState((IEventQueue*)eventQueue, keyMap); keyState.updateKeyMap(); keyState.fakeKeyDown(A_CHAR_ID, 0, 1); @@ -79,7 +79,7 @@ TEST_F(COSXKeyStateTests, fakeAndPoll_charKeyAndModifier) { CKeyMap keyMap; CMockEventQueue eventQueue; - COSXKeyState keyState((IEventQueue&)eventQueue, keyMap); + COSXKeyState keyState((IEventQueue*)eventQueue, keyMap); keyState.updateKeyMap(); keyState.fakeKeyDown(A_CHAR_ID, KeyModifierShift, 1); diff --git a/src/test/unittests/client/CMockClient.h b/src/test/unittests/client/CMockClient.h index ea73f423..0c7a6c99 100644 --- a/src/test/unittests/client/CMockClient.h +++ b/src/test/unittests/client/CMockClient.h @@ -28,7 +28,7 @@ class IEventQueue; class CMockClient : public CClient { public: - CMockClient() { m_mock = true; } + CMockClient() : CClient() { } MOCK_METHOD2(mouseMove, void(SInt32, SInt32)); MOCK_METHOD1(setOptions, void(const COptionsList&)); MOCK_METHOD0(handshakeComplete, void()); diff --git a/src/test/unittests/client/CServerProxyTests.cpp b/src/test/unittests/client/CServerProxyTests.cpp index 5217952b..09139131 100644 --- a/src/test/unittests/client/CServerProxyTests.cpp +++ b/src/test/unittests/client/CServerProxyTests.cpp @@ -29,6 +29,7 @@ using ::testing::_; using ::testing::Invoke; using ::testing::NiceMock; using ::testing::AnyNumber; +using ::testing::ReturnRef; const UInt8 g_mouseMove_bufferLen = 16; UInt8 g_mouseMove_buffer[g_mouseMove_bufferLen]; @@ -49,7 +50,10 @@ TEST(CServerProxyTests, mouseMove) NiceMock eventQueue; NiceMock client; NiceMock stream; - + IStreamEvents streamEvents; + streamEvents.setEvents(&eventQueue); + + ON_CALL(eventQueue, forIStream()).WillByDefault(ReturnRef(streamEvents)); ON_CALL(stream, read(_, _)).WillByDefault(Invoke(mouseMove_mockRead)); EXPECT_CALL(client, mouseMove(1, 2)).Times(1); @@ -68,7 +72,10 @@ TEST(CServerProxyTests, readCryptoIv) NiceMock eventQueue; NiceMock client; NiceMock stream; - + IStreamEvents streamEvents; + streamEvents.setEvents(&eventQueue); + + ON_CALL(eventQueue, forIStream()).WillByDefault(ReturnRef(streamEvents)); ON_CALL(stream, read(_, _)).WillByDefault(Invoke(readCryptoIv_mockRead)); ON_CALL(client, setDecryptIv(_)).WillByDefault(Invoke(readCryptoIv_setDecryptIv)); diff --git a/src/test/unittests/server/CClientProxyTests.cpp b/src/test/unittests/server/CClientProxyTests.cpp index e3f8b584..b44721df 100644 --- a/src/test/unittests/server/CClientProxyTests.cpp +++ b/src/test/unittests/server/CClientProxyTests.cpp @@ -25,6 +25,7 @@ using ::testing::_; using ::testing::NiceMock; using ::testing::Invoke; +using ::testing::ReturnRef; const UInt8 g_cryptoIvWrite_bufferLen = 200; UInt8 g_cryptoIvWrite_buffer[g_cryptoIvWrite_bufferLen]; @@ -43,6 +44,8 @@ TEST(CClientProxyTests, cryptoIvWrite) NiceMock innerStream; NiceMock server; CCryptoOptions options("ctr", "mock"); + IStreamEvents streamEvents; + streamEvents.setEvents(&eventQueue); CCryptoStream* serverStream = new CCryptoStream(&eventQueue, &innerStream, options, false); CCryptoStream* clientStream = new CCryptoStream(&eventQueue, &innerStream, options, false); @@ -52,6 +55,7 @@ TEST(CClientProxyTests, cryptoIvWrite) serverStream->setEncryptIv(iv); clientStream->setDecryptIv(iv); + ON_CALL(eventQueue, forIStream()).WillByDefault(ReturnRef(streamEvents)); ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(cryptoIv_mockWrite)); ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(cryptoIv_mockRead)); diff --git a/src/test/unittests/server/CMockServer.h b/src/test/unittests/server/CMockServer.h index 7623c240..ba8d5a6b 100644 --- a/src/test/unittests/server/CMockServer.h +++ b/src/test/unittests/server/CMockServer.h @@ -27,5 +27,5 @@ class IEventQueue; class CMockServer : public CServer { public: - CMockServer() : CServer() { m_mock = true; } + CMockServer() : CServer() { } }; diff --git a/src/test/unittests/synergy/CKeyStateTests.cpp b/src/test/unittests/synergy/CKeyStateTests.cpp index 1edd508e..71ec398b 100644 --- a/src/test/unittests/synergy/CKeyStateTests.cpp +++ b/src/test/unittests/synergy/CKeyStateTests.cpp @@ -26,6 +26,7 @@ using ::testing::_; using ::testing::NiceMock; using ::testing::Invoke; using ::testing::Return; +using ::testing::ReturnRef; using ::testing::SaveArg; TEST(CKeyStateTests, onKey_aKeyDown_keyStateOne) @@ -66,6 +67,7 @@ TEST(CKeyStateTests, sendKeyEvent_halfDuplexAndRepeat_addEventNotCalled) NiceMock keyMap; NiceMock eventQueue; CKeyStateImpl keyState(eventQueue, keyMap); + ON_CALL(keyMap, isHalfDuplex(_, _)).WillByDefault(Return(true)); EXPECT_CALL(eventQueue, addEvent(_)).Times(0); @@ -78,7 +80,11 @@ TEST(CKeyStateTests, sendKeyEvent_halfDuplex_addEventCalledTwice) NiceMock keyMap; NiceMock eventQueue; CKeyStateImpl keyState(eventQueue, keyMap); + IKeyStateEvents keyStateEvents; + keyStateEvents.setEvents(&eventQueue); + ON_CALL(keyMap, isHalfDuplex(_, _)).WillByDefault(Return(true)); + ON_CALL(eventQueue, forIKeyState()).WillByDefault(ReturnRef(keyStateEvents)); EXPECT_CALL(eventQueue, addEvent(_)).Times(2); @@ -90,6 +96,10 @@ TEST(CKeyStateTests, sendKeyEvent_keyRepeat_addEventCalledOnce) NiceMock keyMap; NiceMock eventQueue; CKeyStateImpl keyState(eventQueue, keyMap); + IKeyStateEvents keyStateEvents; + keyStateEvents.setEvents(&eventQueue); + + ON_CALL(eventQueue, forIKeyState()).WillByDefault(ReturnRef(keyStateEvents)); EXPECT_CALL(eventQueue, addEvent(_)).Times(1); @@ -101,6 +111,10 @@ TEST(CKeyStateTests, sendKeyEvent_keyDown_addEventCalledOnce) NiceMock keyMap; NiceMock eventQueue; CKeyStateImpl keyState(eventQueue, keyMap); + IKeyStateEvents keyStateEvents; + keyStateEvents.setEvents(&eventQueue); + + ON_CALL(eventQueue, forIKeyState()).WillByDefault(ReturnRef(keyStateEvents)); EXPECT_CALL(eventQueue, addEvent(_)).Times(1); @@ -112,6 +126,10 @@ TEST(CKeyStateTests, sendKeyEvent_keyUp_addEventCalledOnce) NiceMock keyMap; NiceMock eventQueue; CKeyStateImpl keyState(eventQueue, keyMap); + IKeyStateEvents keyStateEvents; + keyStateEvents.setEvents(&eventQueue); + + ON_CALL(eventQueue, forIKeyState()).WillByDefault(ReturnRef(keyStateEvents)); EXPECT_CALL(eventQueue, addEvent(_)).Times(1); diff --git a/src/test/unittests/synergy/CKeyStateTests.h b/src/test/unittests/synergy/CKeyStateTests.h index a4f9016f..601df40e 100644 --- a/src/test/unittests/synergy/CKeyStateTests.h +++ b/src/test/unittests/synergy/CKeyStateTests.h @@ -30,12 +30,13 @@ class CMockEventQueue; class CMockKeyState : public CKeyState { public: - CMockKeyState() : CKeyState() + CMockKeyState(const CMockEventQueue& eventQueue) : + CKeyState((IEventQueue*)&eventQueue) { } CMockKeyState(const CMockEventQueue& eventQueue, const CMockKeyMap& keyMap) : - CKeyState((IEventQueue&)eventQueue, (CKeyMap&)keyMap) + CKeyState((IEventQueue*)&eventQueue, (CKeyMap&)keyMap) { } diff --git a/src/test/unittests/synergy/CMockEventQueue.h b/src/test/unittests/synergy/CMockEventQueue.h index 67a985ee..034f4bf4 100644 --- a/src/test/unittests/synergy/CMockEventQueue.h +++ b/src/test/unittests/synergy/CMockEventQueue.h @@ -42,6 +42,26 @@ public: MOCK_CONST_METHOD2(getHandler, IEventJob*(CEvent::Type, void*)); MOCK_METHOD1(deleteTimer, void(CEventQueueTimer*)); MOCK_CONST_METHOD1(getRegisteredType, CEvent::Type(const CString&)); + MOCK_METHOD0(getSystemTarget, void*()); + MOCK_METHOD0(forCClient, CClientEvents&()); + MOCK_METHOD0(forIStream, IStreamEvents&()); + MOCK_METHOD0(forCIpcClient, CIpcClientEvents&()); + MOCK_METHOD0(forCIpcClientProxy, CIpcClientProxyEvents&()); + MOCK_METHOD0(forCIpcServer, CIpcServerEvents&()); + MOCK_METHOD0(forCIpcServerProxy, CIpcServerProxyEvents&()); + MOCK_METHOD0(forIDataSocket, IDataSocketEvents&()); + MOCK_METHOD0(forIListenSocket, IListenSocketEvents&()); + MOCK_METHOD0(forISocket, ISocketEvents&()); + MOCK_METHOD0(forCOSXScreen, COSXScreenEvents&()); + MOCK_METHOD0(forCClientListener, CClientListenerEvents&()); + MOCK_METHOD0(forCClientProxy, CClientProxyEvents&()); + MOCK_METHOD0(forCClientProxyUnknown, CClientProxyUnknownEvents&()); + MOCK_METHOD0(forCServer, CServerEvents&()); + MOCK_METHOD0(forCServerApp, CServerAppEvents&()); + MOCK_METHOD0(forIKeyState, IKeyStateEvents&()); + MOCK_METHOD0(forIPrimaryScreen, IPrimaryScreenEvents&()); + MOCK_METHOD0(forIScreen, IScreenEvents&()); + MOCK_METHOD0(forISecondaryScreen, ISecondaryScreenEvents&()); }; #endif