From 49ac320f97a6c9de4e8e98ab3c94d0d19d3cb53a Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 20 May 2015 19:09:54 +0100 Subject: [PATCH] Refactored clipboard event into ClipboardEvent #4601 --- src/lib/base/EventQueue.cpp | 2 + src/lib/base/EventQueue.h | 2 + src/lib/base/EventTypes.cpp | 11 ++-- src/lib/base/EventTypes.h | 72 +++++++++++++++----------- src/lib/base/IEventQueue.h | 2 + src/lib/client/Client.cpp | 4 +- src/lib/platform/MSWindowsScreen.cpp | 8 +-- src/lib/platform/OSXScreen.cpp | 4 +- src/lib/server/ClientProxy1_0.cpp | 4 +- src/lib/server/ClientProxy1_6.cpp | 2 +- src/lib/server/Server.cpp | 17 ++---- src/lib/synergy/StreamChunker.cpp | 6 +-- src/test/mock/synergy/MockEventQueue.h | 1 + 13 files changed, 76 insertions(+), 59 deletions(-) diff --git a/src/lib/base/EventQueue.cpp b/src/lib/base/EventQueue.cpp index 0aab4277..71208661 100644 --- a/src/lib/base/EventQueue.cpp +++ b/src/lib/base/EventQueue.cpp @@ -46,6 +46,7 @@ EVENT_TYPE_ACCESSOR(ServerApp) EVENT_TYPE_ACCESSOR(IKeyState) EVENT_TYPE_ACCESSOR(IPrimaryScreen) EVENT_TYPE_ACCESSOR(IScreen) +EVENT_TYPE_ACCESSOR(Clipboard) // interrupt handler. this just adds a quit event to the queue. static @@ -82,6 +83,7 @@ EventQueue::EventQueue() : m_typesForIKeyState(NULL), m_typesForIPrimaryScreen(NULL), m_typesForIScreen(NULL), + m_typesForClipboard(NULL), m_readyMutex(new Mutex), m_readyCondVar(new CondVar(m_readyMutex, false)) { diff --git a/src/lib/base/EventQueue.h b/src/lib/base/EventQueue.h index ed47c2b8..cf6dd01d 100644 --- a/src/lib/base/EventQueue.h +++ b/src/lib/base/EventQueue.h @@ -157,6 +157,7 @@ public: IKeyStateEvents& forIKeyState(); IPrimaryScreenEvents& forIPrimaryScreen(); IScreenEvents& forIScreen(); + ClipboardEvents& forClipboard(); private: ClientEvents* m_typesForClient; @@ -177,6 +178,7 @@ private: IKeyStateEvents* m_typesForIKeyState; IPrimaryScreenEvents* m_typesForIPrimaryScreen; IScreenEvents* m_typesForIScreen; + ClipboardEvents* m_typesForClipboard; Mutex* m_readyMutex; CondVar* m_readyCondVar; std::queue m_pending; diff --git a/src/lib/base/EventTypes.cpp b/src/lib/base/EventTypes.cpp index d1617d45..0fdb87d7 100644 --- a/src/lib/base/EventTypes.cpp +++ b/src/lib/base/EventTypes.cpp @@ -115,8 +115,6 @@ REGISTER_EVENT(ClientListener, connected) REGISTER_EVENT(ClientProxy, ready) REGISTER_EVENT(ClientProxy, disconnected) -REGISTER_EVENT(ClientProxy, clipboardChanged) -REGISTER_EVENT(ClientProxy, clipboardSending) // // ClientProxyUnknown @@ -176,7 +174,6 @@ REGISTER_EVENT(IPrimaryScreen, fakeInputEnd) REGISTER_EVENT(IScreen, error) REGISTER_EVENT(IScreen, shapeChanged) -REGISTER_EVENT(IScreen, clipboardGrabbed) REGISTER_EVENT(IScreen, suspend) REGISTER_EVENT(IScreen, resume) REGISTER_EVENT(IScreen, fileChunkSending) @@ -188,3 +185,11 @@ REGISTER_EVENT(IScreen, fileRecieveCompleted) REGISTER_EVENT(IpcServer, clientConnected) REGISTER_EVENT(IpcServer, messageReceived) + +// +// Clipboard +// + +REGISTER_EVENT(Clipboard, clipboardGrabbed) +REGISTER_EVENT(Clipboard, clipboardChanged) +REGISTER_EVENT(Clipboard, clipboardSending) \ No newline at end of file diff --git a/src/lib/base/EventTypes.h b/src/lib/base/EventTypes.h index 7eea4eea..33ee28cc 100644 --- a/src/lib/base/EventTypes.h +++ b/src/lib/base/EventTypes.h @@ -350,9 +350,7 @@ class ClientProxyEvents : public EventTypes { public: ClientProxyEvents() : m_ready(Event::kUnknown), - m_disconnected(Event::kUnknown), - m_clipboardChanged(Event::kUnknown), - m_clipboardSending(Event::kUnknown) { } + m_disconnected(Event::kUnknown) { } //! @name accessors //@{ @@ -372,28 +370,11 @@ public: */ Event::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::ClipboardInfo. - */ - Event::Type clipboardChanged(); - - //! Clipboard sending event type - /*! - Returns the clipboard sending event type. This is used to send - clipboard chunks. - */ - Event::Type clipboardSending(); - //@} private: Event::Type m_ready; Event::Type m_disconnected; - Event::Type m_clipboardChanged; - Event::Type m_clipboardSending; }; class ClientProxyUnknownEvents : public EventTypes { @@ -643,7 +624,6 @@ public: IScreenEvents() : m_error(Event::kUnknown), m_shapeChanged(Event::kUnknown), - m_clipboardGrabbed(Event::kUnknown), m_suspend(Event::kUnknown), m_resume(Event::kUnknown), m_fileChunkSending(Event::kUnknown), @@ -666,14 +646,6 @@ public: */ Event::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 ClipboardInfo. - */ - Event::Type clipboardGrabbed(); - //! Get suspend event type /*! Returns the suspend event type. This is sent whenever the system goes @@ -699,9 +671,49 @@ public: private: Event::Type m_error; Event::Type m_shapeChanged; - Event::Type m_clipboardGrabbed; Event::Type m_suspend; Event::Type m_resume; Event::Type m_fileChunkSending; Event::Type m_fileRecieveCompleted; }; + +class ClipboardEvents : public EventTypes { +public: + ClipboardEvents() : + m_clipboardGrabbed(Event::kUnknown), + m_clipboardChanged(Event::kUnknown), + m_clipboardSending(Event::kUnknown) { } + + //! @name accessors + //@{ + + //! 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 ClipboardInfo. + */ + Event::Type clipboardGrabbed(); + + //! 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::ClipboardInfo. + */ + Event::Type clipboardChanged(); + + //! Clipboard sending event type + /*! + Returns the clipboard sending event type. This is used to send + clipboard chunks. + */ + Event::Type clipboardSending(); + + //@} + +private: + Event::Type m_clipboardGrabbed; + Event::Type m_clipboardChanged; + Event::Type m_clipboardSending; +}; diff --git a/src/lib/base/IEventQueue.h b/src/lib/base/IEventQueue.h index 25c7bbd5..0dcc088a 100644 --- a/src/lib/base/IEventQueue.h +++ b/src/lib/base/IEventQueue.h @@ -48,6 +48,7 @@ class ServerAppEvents; class IKeyStateEvents; class IPrimaryScreenEvents; class IScreenEvents; +class ClipboardEvents; //! Event queue interface /*! @@ -244,4 +245,5 @@ public: virtual IKeyStateEvents& forIKeyState() = 0; virtual IPrimaryScreenEvents& forIPrimaryScreen() = 0; virtual IScreenEvents& forIScreen() = 0; + virtual ClipboardEvents& forClipboard() = 0; }; diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 06ea45d5..a309cf9e 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -488,7 +488,7 @@ Client::setupScreen() getEventTarget(), new TMethodEventJob(this, &Client::handleShapeChanged)); - m_events->adoptHandler(m_events->forIScreen().clipboardGrabbed(), + m_events->adoptHandler(m_events->forClipboard().clipboardGrabbed(), getEventTarget(), new TMethodEventJob(this, &Client::handleClipboardGrabbed)); @@ -546,7 +546,7 @@ Client::cleanupScreen() } m_events->removeHandler(m_events->forIScreen().shapeChanged(), getEventTarget()); - m_events->removeHandler(m_events->forIScreen().clipboardGrabbed(), + m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(), getEventTarget()); delete m_server; m_server = NULL; diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index 9252466c..efb92266 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -433,8 +433,8 @@ MSWindowsScreen::checkClipboards() if (m_ownClipboard && !MSWindowsClipboard::isOwnedBySynergy()) { LOG((CLOG_DEBUG "clipboard changed: lost ownership and no notification received")); m_ownClipboard = false; - sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard); - sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection); + sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardClipboard); + sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardSelection); } } @@ -1501,8 +1501,8 @@ MSWindowsScreen::onClipboardChange() if (m_ownClipboard) { LOG((CLOG_DEBUG "clipboard changed: lost ownership")); m_ownClipboard = false; - sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard); - sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection); + sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardClipboard); + sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardSelection); } } else if (!m_ownClipboard) { diff --git a/src/lib/platform/OSXScreen.cpp b/src/lib/platform/OSXScreen.cpp index 2a92d51f..acdeb4d5 100644 --- a/src/lib/platform/OSXScreen.cpp +++ b/src/lib/platform/OSXScreen.cpp @@ -954,8 +954,8 @@ OSXScreen::checkClipboards() LOG((CLOG_DEBUG2 "checking clipboard")); if (m_pasteboard.synchronize()) { LOG((CLOG_DEBUG "clipboard changed")); - sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard); - sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection); + sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardClipboard); + sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardSelection); } } diff --git a/src/lib/server/ClientProxy1_0.cpp b/src/lib/server/ClientProxy1_0.cpp index 6cc8057c..cb2f6307 100644 --- a/src/lib/server/ClientProxy1_0.cpp +++ b/src/lib/server/ClientProxy1_0.cpp @@ -474,7 +474,7 @@ ClientProxy1_0::recvClipboard() ClipboardInfo* info = new ClipboardInfo; info->m_id = id; info->m_sequenceNumber = seqNum; - m_events->addEvent(Event(m_events->forClientProxy().clipboardChanged(), + m_events->addEvent(Event(m_events->forClipboard().clipboardChanged(), getEventTarget(), info)); return true; @@ -500,7 +500,7 @@ ClientProxy1_0::recvGrabClipboard() ClipboardInfo* info = new ClipboardInfo; info->m_id = id; info->m_sequenceNumber = seqNum; - m_events->addEvent(Event(m_events->forIScreen().clipboardGrabbed(), + m_events->addEvent(Event(m_events->forClipboard().clipboardGrabbed(), getEventTarget(), info)); return true; diff --git a/src/lib/server/ClientProxy1_6.cpp b/src/lib/server/ClientProxy1_6.cpp index e1438aa4..3319866c 100644 --- a/src/lib/server/ClientProxy1_6.cpp +++ b/src/lib/server/ClientProxy1_6.cpp @@ -33,7 +33,7 @@ ClientProxy1_6::ClientProxy1_6(const String& name, synergy::IStream* stream, Ser ClientProxy1_5(name, stream, server, events), m_events(events) { - m_events->adoptHandler(m_events->forClientProxy().clipboardSending(), + m_events->adoptHandler(m_events->forClipboard().clipboardSending(), this, new TMethodEventJob(this, &ClientProxy1_6::handleClipboardSendingEvent)); diff --git a/src/lib/server/Server.cpp b/src/lib/server/Server.cpp index 607a0078..60f75e66 100644 --- a/src/lib/server/Server.cpp +++ b/src/lib/server/Server.cpp @@ -92,8 +92,7 @@ Server::Server( m_ignoreFileTransfer(false), m_enableDragDrop(enableDragDrop), m_getDragInfoThread(NULL), - m_waitDragInfoThread(true), - m_dataTransmissionThread(NULL) + m_waitDragInfoThread(true) { // must have a primary client and it must have a canonical name assert(m_primaryClient != NULL); @@ -506,12 +505,6 @@ Server::switchScreen(BaseClientProxy* dst, m_primaryClient->getToggleMask(), forScreensaver); - // send the clipboard data to new active screen - m_dataTransmissionThread = new Thread( - new TMethodJob( - this, &Server::sendClipboardThread, - NULL)); - Server::SwitchToScreenInfo* info = Server::SwitchToScreenInfo::alloc(m_active->getName()); m_events->addEvent(Event(m_events->forServer().screenSwitched(), this, info)); @@ -2079,11 +2072,11 @@ Server::addClient(BaseClientProxy* client) client->getEventTarget(), new TMethodEventJob(this, &Server::handleShapeChanged, client)); - m_events->adoptHandler(m_events->forIScreen().clipboardGrabbed(), + m_events->adoptHandler(m_events->forClipboard().clipboardGrabbed(), client->getEventTarget(), new TMethodEventJob(this, &Server::handleClipboardGrabbed, client)); - m_events->adoptHandler(m_events->forClientProxy().clipboardChanged(), + m_events->adoptHandler(m_events->forClipboard().clipboardChanged(), client->getEventTarget(), new TMethodEventJob(this, &Server::handleClipboardChanged, client)); @@ -2115,9 +2108,9 @@ Server::removeClient(BaseClientProxy* client) // remove event handlers m_events->removeHandler(m_events->forIScreen().shapeChanged(), client->getEventTarget()); - m_events->removeHandler(m_events->forIScreen().clipboardGrabbed(), + m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(), client->getEventTarget()); - m_events->removeHandler(m_events->forClientProxy().clipboardChanged(), + m_events->removeHandler(m_events->forClipboard().clipboardChanged(), client->getEventTarget()); // remove from list diff --git a/src/lib/synergy/StreamChunker.cpp b/src/lib/synergy/StreamChunker.cpp index b7393d94..60700407 100644 --- a/src/lib/synergy/StreamChunker.cpp +++ b/src/lib/synergy/StreamChunker.cpp @@ -112,7 +112,7 @@ StreamChunker::sendClipboard( String dataSize = synergy::string::sizeTypeToString(size); ClipboardChunk* sizeMessage = ClipboardChunk::start(id, sequence, dataSize); - events->addEvent(Event(events->forClientProxy().clipboardSending(), eventTarget, sizeMessage)); + events->addEvent(Event(events->forClipboard().clipboardSending(), eventTarget, sizeMessage)); // send clipboard chunk with a fixed size // TODO: 4096 fails and this shouldn't a magic number @@ -130,7 +130,7 @@ StreamChunker::sendClipboard( String chunk(data.substr(sentLength, chunkSize).c_str(), chunkSize); ClipboardChunk* dataChunk = ClipboardChunk::data(id, sequence, chunk); - events->addEvent(Event(events->forClientProxy().clipboardSending(), eventTarget, dataChunk)); + events->addEvent(Event(events->forClipboard().clipboardSending(), eventTarget, dataChunk)); sentLength += chunkSize; @@ -145,5 +145,5 @@ StreamChunker::sendClipboard( // send last message ClipboardChunk* end = ClipboardChunk::end(id, sequence); - events->addEvent(Event(events->forClientProxy().clipboardSending(), eventTarget, end)); + events->addEvent(Event(events->forClipboard().clipboardSending(), eventTarget, end)); } diff --git a/src/test/mock/synergy/MockEventQueue.h b/src/test/mock/synergy/MockEventQueue.h index 7977b41d..d6256790 100644 --- a/src/test/mock/synergy/MockEventQueue.h +++ b/src/test/mock/synergy/MockEventQueue.h @@ -61,5 +61,6 @@ public: MOCK_METHOD0(forIKeyState, IKeyStateEvents&()); MOCK_METHOD0(forIPrimaryScreen, IPrimaryScreenEvents&()); MOCK_METHOD0(forIScreen, IScreenEvents&()); + MOCK_METHOD0(forClipboard, ClipboardEvents&()); MOCK_CONST_METHOD0(waitForReady, void()); };