Refactored clipboard event into ClipboardEvent #4601

This commit is contained in:
Xinyu Hou 2015-05-20 19:09:54 +01:00
parent a6dfbbe021
commit 49ac320f97
13 changed files with 76 additions and 59 deletions

View File

@ -46,6 +46,7 @@ EVENT_TYPE_ACCESSOR(ServerApp)
EVENT_TYPE_ACCESSOR(IKeyState) EVENT_TYPE_ACCESSOR(IKeyState)
EVENT_TYPE_ACCESSOR(IPrimaryScreen) EVENT_TYPE_ACCESSOR(IPrimaryScreen)
EVENT_TYPE_ACCESSOR(IScreen) EVENT_TYPE_ACCESSOR(IScreen)
EVENT_TYPE_ACCESSOR(Clipboard)
// interrupt handler. this just adds a quit event to the queue. // interrupt handler. this just adds a quit event to the queue.
static static
@ -82,6 +83,7 @@ EventQueue::EventQueue() :
m_typesForIKeyState(NULL), m_typesForIKeyState(NULL),
m_typesForIPrimaryScreen(NULL), m_typesForIPrimaryScreen(NULL),
m_typesForIScreen(NULL), m_typesForIScreen(NULL),
m_typesForClipboard(NULL),
m_readyMutex(new Mutex), m_readyMutex(new Mutex),
m_readyCondVar(new CondVar<bool>(m_readyMutex, false)) m_readyCondVar(new CondVar<bool>(m_readyMutex, false))
{ {

View File

@ -157,6 +157,7 @@ public:
IKeyStateEvents& forIKeyState(); IKeyStateEvents& forIKeyState();
IPrimaryScreenEvents& forIPrimaryScreen(); IPrimaryScreenEvents& forIPrimaryScreen();
IScreenEvents& forIScreen(); IScreenEvents& forIScreen();
ClipboardEvents& forClipboard();
private: private:
ClientEvents* m_typesForClient; ClientEvents* m_typesForClient;
@ -177,6 +178,7 @@ private:
IKeyStateEvents* m_typesForIKeyState; IKeyStateEvents* m_typesForIKeyState;
IPrimaryScreenEvents* m_typesForIPrimaryScreen; IPrimaryScreenEvents* m_typesForIPrimaryScreen;
IScreenEvents* m_typesForIScreen; IScreenEvents* m_typesForIScreen;
ClipboardEvents* m_typesForClipboard;
Mutex* m_readyMutex; Mutex* m_readyMutex;
CondVar<bool>* m_readyCondVar; CondVar<bool>* m_readyCondVar;
std::queue<Event> m_pending; std::queue<Event> m_pending;

View File

@ -115,8 +115,6 @@ REGISTER_EVENT(ClientListener, connected)
REGISTER_EVENT(ClientProxy, ready) REGISTER_EVENT(ClientProxy, ready)
REGISTER_EVENT(ClientProxy, disconnected) REGISTER_EVENT(ClientProxy, disconnected)
REGISTER_EVENT(ClientProxy, clipboardChanged)
REGISTER_EVENT(ClientProxy, clipboardSending)
// //
// ClientProxyUnknown // ClientProxyUnknown
@ -176,7 +174,6 @@ REGISTER_EVENT(IPrimaryScreen, fakeInputEnd)
REGISTER_EVENT(IScreen, error) REGISTER_EVENT(IScreen, error)
REGISTER_EVENT(IScreen, shapeChanged) REGISTER_EVENT(IScreen, shapeChanged)
REGISTER_EVENT(IScreen, clipboardGrabbed)
REGISTER_EVENT(IScreen, suspend) REGISTER_EVENT(IScreen, suspend)
REGISTER_EVENT(IScreen, resume) REGISTER_EVENT(IScreen, resume)
REGISTER_EVENT(IScreen, fileChunkSending) REGISTER_EVENT(IScreen, fileChunkSending)
@ -188,3 +185,11 @@ REGISTER_EVENT(IScreen, fileRecieveCompleted)
REGISTER_EVENT(IpcServer, clientConnected) REGISTER_EVENT(IpcServer, clientConnected)
REGISTER_EVENT(IpcServer, messageReceived) REGISTER_EVENT(IpcServer, messageReceived)
//
// Clipboard
//
REGISTER_EVENT(Clipboard, clipboardGrabbed)
REGISTER_EVENT(Clipboard, clipboardChanged)
REGISTER_EVENT(Clipboard, clipboardSending)

View File

@ -350,9 +350,7 @@ class ClientProxyEvents : public EventTypes {
public: public:
ClientProxyEvents() : ClientProxyEvents() :
m_ready(Event::kUnknown), m_ready(Event::kUnknown),
m_disconnected(Event::kUnknown), m_disconnected(Event::kUnknown) { }
m_clipboardChanged(Event::kUnknown),
m_clipboardSending(Event::kUnknown) { }
//! @name accessors //! @name accessors
//@{ //@{
@ -372,28 +370,11 @@ public:
*/ */
Event::Type disconnected(); 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: private:
Event::Type m_ready; Event::Type m_ready;
Event::Type m_disconnected; Event::Type m_disconnected;
Event::Type m_clipboardChanged;
Event::Type m_clipboardSending;
}; };
class ClientProxyUnknownEvents : public EventTypes { class ClientProxyUnknownEvents : public EventTypes {
@ -643,7 +624,6 @@ public:
IScreenEvents() : IScreenEvents() :
m_error(Event::kUnknown), m_error(Event::kUnknown),
m_shapeChanged(Event::kUnknown), m_shapeChanged(Event::kUnknown),
m_clipboardGrabbed(Event::kUnknown),
m_suspend(Event::kUnknown), m_suspend(Event::kUnknown),
m_resume(Event::kUnknown), m_resume(Event::kUnknown),
m_fileChunkSending(Event::kUnknown), m_fileChunkSending(Event::kUnknown),
@ -666,14 +646,6 @@ public:
*/ */
Event::Type shapeChanged(); 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 //! Get suspend event type
/*! /*!
Returns the suspend event type. This is sent whenever the system goes Returns the suspend event type. This is sent whenever the system goes
@ -699,9 +671,49 @@ public:
private: private:
Event::Type m_error; Event::Type m_error;
Event::Type m_shapeChanged; Event::Type m_shapeChanged;
Event::Type m_clipboardGrabbed;
Event::Type m_suspend; Event::Type m_suspend;
Event::Type m_resume; Event::Type m_resume;
Event::Type m_fileChunkSending; Event::Type m_fileChunkSending;
Event::Type m_fileRecieveCompleted; 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;
};

View File

@ -48,6 +48,7 @@ class ServerAppEvents;
class IKeyStateEvents; class IKeyStateEvents;
class IPrimaryScreenEvents; class IPrimaryScreenEvents;
class IScreenEvents; class IScreenEvents;
class ClipboardEvents;
//! Event queue interface //! Event queue interface
/*! /*!
@ -244,4 +245,5 @@ public:
virtual IKeyStateEvents& forIKeyState() = 0; virtual IKeyStateEvents& forIKeyState() = 0;
virtual IPrimaryScreenEvents& forIPrimaryScreen() = 0; virtual IPrimaryScreenEvents& forIPrimaryScreen() = 0;
virtual IScreenEvents& forIScreen() = 0; virtual IScreenEvents& forIScreen() = 0;
virtual ClipboardEvents& forClipboard() = 0;
}; };

View File

@ -488,7 +488,7 @@ Client::setupScreen()
getEventTarget(), getEventTarget(),
new TMethodEventJob<Client>(this, new TMethodEventJob<Client>(this,
&Client::handleShapeChanged)); &Client::handleShapeChanged));
m_events->adoptHandler(m_events->forIScreen().clipboardGrabbed(), m_events->adoptHandler(m_events->forClipboard().clipboardGrabbed(),
getEventTarget(), getEventTarget(),
new TMethodEventJob<Client>(this, new TMethodEventJob<Client>(this,
&Client::handleClipboardGrabbed)); &Client::handleClipboardGrabbed));
@ -546,7 +546,7 @@ Client::cleanupScreen()
} }
m_events->removeHandler(m_events->forIScreen().shapeChanged(), m_events->removeHandler(m_events->forIScreen().shapeChanged(),
getEventTarget()); getEventTarget());
m_events->removeHandler(m_events->forIScreen().clipboardGrabbed(), m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(),
getEventTarget()); getEventTarget());
delete m_server; delete m_server;
m_server = NULL; m_server = NULL;

View File

@ -433,8 +433,8 @@ MSWindowsScreen::checkClipboards()
if (m_ownClipboard && !MSWindowsClipboard::isOwnedBySynergy()) { if (m_ownClipboard && !MSWindowsClipboard::isOwnedBySynergy()) {
LOG((CLOG_DEBUG "clipboard changed: lost ownership and no notification received")); LOG((CLOG_DEBUG "clipboard changed: lost ownership and no notification received"));
m_ownClipboard = false; m_ownClipboard = false;
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard); sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardClipboard);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection); sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardSelection);
} }
} }
@ -1501,8 +1501,8 @@ MSWindowsScreen::onClipboardChange()
if (m_ownClipboard) { if (m_ownClipboard) {
LOG((CLOG_DEBUG "clipboard changed: lost ownership")); LOG((CLOG_DEBUG "clipboard changed: lost ownership"));
m_ownClipboard = false; m_ownClipboard = false;
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard); sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardClipboard);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection); sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardSelection);
} }
} }
else if (!m_ownClipboard) { else if (!m_ownClipboard) {

View File

@ -954,8 +954,8 @@ OSXScreen::checkClipboards()
LOG((CLOG_DEBUG2 "checking clipboard")); LOG((CLOG_DEBUG2 "checking clipboard"));
if (m_pasteboard.synchronize()) { if (m_pasteboard.synchronize()) {
LOG((CLOG_DEBUG "clipboard changed")); LOG((CLOG_DEBUG "clipboard changed"));
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardClipboard); sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardClipboard);
sendClipboardEvent(m_events->forIScreen().clipboardGrabbed(), kClipboardSelection); sendClipboardEvent(m_events->forClipboard().clipboardGrabbed(), kClipboardSelection);
} }
} }

View File

@ -474,7 +474,7 @@ ClientProxy1_0::recvClipboard()
ClipboardInfo* info = new ClipboardInfo; ClipboardInfo* info = new ClipboardInfo;
info->m_id = id; info->m_id = id;
info->m_sequenceNumber = seqNum; info->m_sequenceNumber = seqNum;
m_events->addEvent(Event(m_events->forClientProxy().clipboardChanged(), m_events->addEvent(Event(m_events->forClipboard().clipboardChanged(),
getEventTarget(), info)); getEventTarget(), info));
return true; return true;
@ -500,7 +500,7 @@ ClientProxy1_0::recvGrabClipboard()
ClipboardInfo* info = new ClipboardInfo; ClipboardInfo* info = new ClipboardInfo;
info->m_id = id; info->m_id = id;
info->m_sequenceNumber = seqNum; info->m_sequenceNumber = seqNum;
m_events->addEvent(Event(m_events->forIScreen().clipboardGrabbed(), m_events->addEvent(Event(m_events->forClipboard().clipboardGrabbed(),
getEventTarget(), info)); getEventTarget(), info));
return true; return true;

View File

@ -33,7 +33,7 @@ ClientProxy1_6::ClientProxy1_6(const String& name, synergy::IStream* stream, Ser
ClientProxy1_5(name, stream, server, events), ClientProxy1_5(name, stream, server, events),
m_events(events) m_events(events)
{ {
m_events->adoptHandler(m_events->forClientProxy().clipboardSending(), m_events->adoptHandler(m_events->forClipboard().clipboardSending(),
this, this,
new TMethodEventJob<ClientProxy1_6>(this, new TMethodEventJob<ClientProxy1_6>(this,
&ClientProxy1_6::handleClipboardSendingEvent)); &ClientProxy1_6::handleClipboardSendingEvent));

View File

@ -92,8 +92,7 @@ Server::Server(
m_ignoreFileTransfer(false), m_ignoreFileTransfer(false),
m_enableDragDrop(enableDragDrop), m_enableDragDrop(enableDragDrop),
m_getDragInfoThread(NULL), m_getDragInfoThread(NULL),
m_waitDragInfoThread(true), m_waitDragInfoThread(true)
m_dataTransmissionThread(NULL)
{ {
// must have a primary client and it must have a canonical name // must have a primary client and it must have a canonical name
assert(m_primaryClient != NULL); assert(m_primaryClient != NULL);
@ -506,12 +505,6 @@ Server::switchScreen(BaseClientProxy* dst,
m_primaryClient->getToggleMask(), m_primaryClient->getToggleMask(),
forScreensaver); forScreensaver);
// send the clipboard data to new active screen
m_dataTransmissionThread = new Thread(
new TMethodJob<Server>(
this, &Server::sendClipboardThread,
NULL));
Server::SwitchToScreenInfo* info = Server::SwitchToScreenInfo* info =
Server::SwitchToScreenInfo::alloc(m_active->getName()); Server::SwitchToScreenInfo::alloc(m_active->getName());
m_events->addEvent(Event(m_events->forServer().screenSwitched(), this, info)); m_events->addEvent(Event(m_events->forServer().screenSwitched(), this, info));
@ -2079,11 +2072,11 @@ Server::addClient(BaseClientProxy* client)
client->getEventTarget(), client->getEventTarget(),
new TMethodEventJob<Server>(this, new TMethodEventJob<Server>(this,
&Server::handleShapeChanged, client)); &Server::handleShapeChanged, client));
m_events->adoptHandler(m_events->forIScreen().clipboardGrabbed(), m_events->adoptHandler(m_events->forClipboard().clipboardGrabbed(),
client->getEventTarget(), client->getEventTarget(),
new TMethodEventJob<Server>(this, new TMethodEventJob<Server>(this,
&Server::handleClipboardGrabbed, client)); &Server::handleClipboardGrabbed, client));
m_events->adoptHandler(m_events->forClientProxy().clipboardChanged(), m_events->adoptHandler(m_events->forClipboard().clipboardChanged(),
client->getEventTarget(), client->getEventTarget(),
new TMethodEventJob<Server>(this, new TMethodEventJob<Server>(this,
&Server::handleClipboardChanged, client)); &Server::handleClipboardChanged, client));
@ -2115,9 +2108,9 @@ Server::removeClient(BaseClientProxy* client)
// remove event handlers // remove event handlers
m_events->removeHandler(m_events->forIScreen().shapeChanged(), m_events->removeHandler(m_events->forIScreen().shapeChanged(),
client->getEventTarget()); client->getEventTarget());
m_events->removeHandler(m_events->forIScreen().clipboardGrabbed(), m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(),
client->getEventTarget()); client->getEventTarget());
m_events->removeHandler(m_events->forClientProxy().clipboardChanged(), m_events->removeHandler(m_events->forClipboard().clipboardChanged(),
client->getEventTarget()); client->getEventTarget());
// remove from list // remove from list

View File

@ -112,7 +112,7 @@ StreamChunker::sendClipboard(
String dataSize = synergy::string::sizeTypeToString(size); String dataSize = synergy::string::sizeTypeToString(size);
ClipboardChunk* sizeMessage = ClipboardChunk::start(id, sequence, dataSize); 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 // send clipboard chunk with a fixed size
// TODO: 4096 fails and this shouldn't a magic number // 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); String chunk(data.substr(sentLength, chunkSize).c_str(), chunkSize);
ClipboardChunk* dataChunk = ClipboardChunk::data(id, sequence, chunk); 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; sentLength += chunkSize;
@ -145,5 +145,5 @@ StreamChunker::sendClipboard(
// send last message // send last message
ClipboardChunk* end = ClipboardChunk::end(id, sequence); ClipboardChunk* end = ClipboardChunk::end(id, sequence);
events->addEvent(Event(events->forClientProxy().clipboardSending(), eventTarget, end)); events->addEvent(Event(events->forClipboard().clipboardSending(), eventTarget, end));
} }

View File

@ -61,5 +61,6 @@ public:
MOCK_METHOD0(forIKeyState, IKeyStateEvents&()); MOCK_METHOD0(forIKeyState, IKeyStateEvents&());
MOCK_METHOD0(forIPrimaryScreen, IPrimaryScreenEvents&()); MOCK_METHOD0(forIPrimaryScreen, IPrimaryScreenEvents&());
MOCK_METHOD0(forIScreen, IScreenEvents&()); MOCK_METHOD0(forIScreen, IScreenEvents&());
MOCK_METHOD0(forClipboard, ClipboardEvents&());
MOCK_CONST_METHOD0(waitForReady, void()); MOCK_CONST_METHOD0(waitForReady, void());
}; };