Send clipboard data in a thread #4601

This commit is contained in:
Jerry (Xinyu Hou) 2015-05-15 16:05:20 -07:00 committed by Xinyu Hou
parent 44089d55e8
commit 4c36c08099
4 changed files with 19 additions and 66 deletions

View File

@ -20,9 +20,7 @@
#include "server/Server.h"
#include "synergy/FileChunker.h"
#include "synergy/ProtocolUtil.h"
#include "mt/Thread.h"
#include "io/IStream.h"
#include "base/TMethodJob.h"
#include "base/Log.h"
#include <sstream>
@ -124,11 +122,6 @@ ClientProxy1_5::setClipboard(ClipboardID id, const IClipboard* clipboard)
// send last message
ProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, kDataEnd, "\0");
// m_sendFileThread = new Thread(
// new TMethodJob<ClientProxy1_5>(
// this, &ClientProxy1_5::sendClipboardThread,
// reinterpret_cast<void*>(id)));
}
}
@ -209,52 +202,3 @@ ClientProxy1_5::dragInfoReceived()
m_server->dragInfoReceived(fileNum, content);
}
void
ClientProxy1_5::sendClipboardThread(void* data)
{
//size_t id = reinterpret_cast<size_t>(data);
//String clipboardData = m_clipboardData.at(id);
//int size = clipboardData.size();
//LOG((CLOG_DEBUG "sending clipboard %d to \"%s\" size=%d", id, getName().c_str(), size));
////TODO: refactor FileChunker
//// send first message (file size)
//std::stringstream ss;
//ss << size;
//String dataSize = ss.str();
//ProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, kDataStart, &dataSize);
//// send chunk messages with a fixed chunk size
//size_t sentLength = 0;
//size_t chunkSize = 2048;
//Stopwatch stopwatch;
//stopwatch.start();
//while (true) {
// if (stopwatch.getTime() > 0.1f) {
// // make sure we don't read too much from the mock data.
// if (sentLength + chunkSize > size) {
// chunkSize = size - sentLength;
// }
// char* chunk = new char[chunkSize];
// memcpy(chunk, clipboardData.substr(sentLength, chunkSize).c_str(), chunkSize);
// //String chunk(clipboardData.substr(sentLength, chunkSize).c_str(), chunkSize);
// //int sizetest = chunk.size();
// //sizetest++;
// //sizetest--;
// ProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, kDataChunk, chunk);
// sentLength += chunkSize;
// if (sentLength == size) {
// break;
// }
// stopwatch.reset();
// }
//}
//// send last message
//ProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, kDataEnd, "\0");
}

View File

@ -23,7 +23,6 @@
class Server;
class IEventQueue;
class Thread;
//! Proxy for client implementing protocol version 1.5
class ClientProxy1_5 : public ClientProxy1_4 {
@ -38,10 +37,6 @@ public:
void fileChunkReceived();
void dragInfoReceived();
private:
// thread funciton for sending clipboard
void sendClipboardThread(void*);
private:
IEventQueue* m_events;
@ -49,5 +44,4 @@ private:
double m_elapsedTime;
size_t m_receivedDataSize;
static const UInt16 m_intervalThreshold;
//Thread* m_sendFileThread;
};

View File

@ -91,7 +91,8 @@ Server::Server(
m_ignoreFileTransfer(false),
m_enableDragDrop(enableDragDrop),
m_getDragInfoThread(NULL),
m_waitDragInfoThread(true)
m_waitDragInfoThread(true),
m_dataTransmissionThread(NULL)
{
// must have a primary client and it must have a canonical name
assert(m_primaryClient != NULL);
@ -505,9 +506,10 @@ Server::switchScreen(BaseClientProxy* dst,
forScreensaver);
// send the clipboard data to new active screen
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
m_active->setClipboard(id, &m_clipboards[id].m_clipboard);
}
m_dataTransmissionThread = new Thread(
new TMethodJob<Server>(
this, &Server::clipboardTransmissionThread,
NULL));
Server::SwitchToScreenInfo* info =
Server::SwitchToScreenInfo::alloc(m_active->getName());
@ -1849,6 +1851,14 @@ Server::sendDragInfo(BaseClientProxy* newScreen)
}
}
void
Server::clipboardTransmissionThread(void*)
{
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
m_active->setClipboard(id, &m_clipboards[id].m_clipboard);
}
}
void
Server::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
{

View File

@ -370,6 +370,9 @@ private:
// send drag info to new client screen
void sendDragInfo(BaseClientProxy* newScreen);
// thread funciton for sending clipboard
void clipboardTransmissionThread(void*);
public:
bool m_mock;
@ -480,4 +483,6 @@ private:
bool m_waitDragInfoThread;
ClientListener* m_clientListener;
Thread* m_dataTransmissionThread;
};