Used a thread to send clipboard data #4601

This commit is contained in:
Jerry (Xinyu Hou) 2015-05-14 13:51:21 -07:00
parent 8c82996fc4
commit 220b6befab
5 changed files with 44 additions and 5 deletions

View File

@ -282,6 +282,7 @@ ClientProxy1_0::setClipboard(ClipboardID id, const IClipboard* clipboard)
Clipboard::copy(&m_clipboard[id].m_clipboard, clipboard); Clipboard::copy(&m_clipboard[id].m_clipboard, clipboard);
String data = m_clipboard[id].m_clipboard.marshall(); String data = m_clipboard[id].m_clipboard.marshall();
LOG((CLOG_DEBUG "send clipboard %d to \"%s\" size=%d", id, getName().c_str(), data.size())); LOG((CLOG_DEBUG "send clipboard %d to \"%s\" size=%d", id, getName().c_str(), data.size()));
ProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, &data); ProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, &data);
} }
@ -505,7 +506,6 @@ ClientProxy1_0::recvGrabClipboard()
return true; return true;
} }
// //
// ClientProxy1_0::ClientClipboard // ClientProxy1_0::ClientClipboard
// //

View File

@ -84,8 +84,7 @@ private:
bool recvClipboard(); bool recvClipboard();
bool recvGrabClipboard(); bool recvGrabClipboard();
private: protected:
typedef bool (ClientProxy1_0::*MessageParser)(const UInt8*);
struct ClientClipboard { struct ClientClipboard {
public: public:
ClientClipboard(); ClientClipboard();
@ -96,8 +95,12 @@ private:
bool m_dirty; bool m_dirty;
}; };
ClientInfo m_info;
ClientClipboard m_clipboard[kClipboardEnd]; ClientClipboard m_clipboard[kClipboardEnd];
private:
typedef bool (ClientProxy1_0::*MessageParser)(const UInt8*);
ClientInfo m_info;
double m_heartbeatAlarm; double m_heartbeatAlarm;
EventQueueTimer* m_heartbeatTimer; EventQueueTimer* m_heartbeatTimer;
MessageParser m_parser; MessageParser m_parser;

View File

@ -19,7 +19,9 @@
#include "server/Server.h" #include "server/Server.h"
#include "synergy/ProtocolUtil.h" #include "synergy/ProtocolUtil.h"
#include "mt/Thread.h"
#include "io/IStream.h" #include "io/IStream.h"
#include "base/TMethodJob.h"
#include "base/Log.h" #include "base/Log.h"
// //
@ -71,6 +73,24 @@ ClientProxy1_5::fileChunkSending(UInt8 mark, char* data, size_t dataSize)
ProtocolUtil::writef(getStream(), kMsgDFileTransfer, mark, &chunk); ProtocolUtil::writef(getStream(), kMsgDFileTransfer, mark, &chunk);
} }
void
ClientProxy1_5::setClipboard(ClipboardID id, const IClipboard* clipboard)
{
// ignore if this clipboard is already clean
if (m_clipboard[id].m_dirty) {
// this clipboard is now clean
m_clipboard[id].m_dirty = false;
Clipboard::copy(&m_clipboard[id].m_clipboard, clipboard);
m_clipboardData = m_clipboard[id].m_clipboard.marshall();
m_sendFileThread = new Thread(
new TMethodJob<ClientProxy1_5>(
this, &ClientProxy1_5::sendClipboardThread,
reinterpret_cast<void*>(id)));
}
}
bool bool
ClientProxy1_5::parseMessage(const UInt8* code) ClientProxy1_5::parseMessage(const UInt8* code)
{ {
@ -148,3 +168,11 @@ ClientProxy1_5::dragInfoReceived()
m_server->dragInfoReceived(fileNum, content); m_server->dragInfoReceived(fileNum, content);
} }
void
ClientProxy1_5::sendClipboardThread(void* data)
{
ClipboardID id = reinterpret_cast<ClipboardID>(data);\
LOG((CLOG_DEBUG "sending clipboard %d to \"%s\" size=%d", id, getName().c_str(), m_clipboardData.size()));
ProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, &m_clipboardData);
}

View File

@ -22,6 +22,7 @@
class Server; class Server;
class IEventQueue; class IEventQueue;
class Thread;
//! Proxy for client implementing protocol version 1.5 //! Proxy for client implementing protocol version 1.5
class ClientProxy1_5 : public ClientProxy1_4 { class ClientProxy1_5 : public ClientProxy1_4 {
@ -31,10 +32,15 @@ public:
virtual void sendDragInfo(UInt32 fileCount, const char* info, size_t size); virtual void sendDragInfo(UInt32 fileCount, const char* info, size_t size);
virtual void fileChunkSending(UInt8 mark, char* data, size_t dataSize); virtual void fileChunkSending(UInt8 mark, char* data, size_t dataSize);
virtual void setClipboard(ClipboardID id, const IClipboard* clipboard);
virtual bool parseMessage(const UInt8* code); virtual bool parseMessage(const UInt8* code);
void fileChunkReceived(); void fileChunkReceived();
void dragInfoReceived(); void dragInfoReceived();
private:
// thread funciton for sending clipboard
void sendClipboardThread(void*);
private: private:
IEventQueue* m_events; IEventQueue* m_events;
@ -42,4 +48,6 @@ private:
double m_elapsedTime; double m_elapsedTime;
size_t m_receivedDataSize; size_t m_receivedDataSize;
static const UInt16 m_intervalThreshold; static const UInt16 m_intervalThreshold;
Thread* m_sendFileThread;
String m_clipboardData;
}; };

View File

@ -27,7 +27,7 @@
// 1.3: adds keep alive and deprecates heartbeats, // 1.3: adds keep alive and deprecates heartbeats,
// adds horizontal mouse scrolling // adds horizontal mouse scrolling
// 1.4: adds crypto support // 1.4: adds crypto support
// 1.5: adds file transfer and removes home brew crypto // 1.5: adds file/clipboard transfer and removes home brew crypto
// NOTE: with new version, synergy minor version should increment // NOTE: with new version, synergy minor version should increment
static const SInt16 kProtocolMajorVersion = 1; static const SInt16 kProtocolMajorVersion = 1;
static const SInt16 kProtocolMinorVersion = 5; static const SInt16 kProtocolMinorVersion = 5;