diff --git a/src/lib/client/ServerProxy.cpp b/src/lib/client/ServerProxy.cpp index 0a995846..f970ad59 100644 --- a/src/lib/client/ServerProxy.cpp +++ b/src/lib/client/ServerProxy.cpp @@ -19,6 +19,8 @@ #include "client/ServerProxy.h" #include "client/Client.h" +#include "synergy/ClipboardChunk.h" +#include "synergy/StreamChunker.h" #include "synergy/Clipboard.h" #include "synergy/ProtocolUtil.h" #include "synergy/option_types.h" @@ -69,6 +71,11 @@ ServerProxy::ServerProxy(Client* client, synergy::IStream* stream, IEventQueue* new TMethodEventJob(this, &ServerProxy::handleData)); + m_events->adoptHandler(m_events->forClipboard().clipboardSending(), + this, + new TMethodEventJob(this, + &ServerProxy::handleClipboardSendingEvent)); + // send heartbeat setKeepAliveRate(kKeepAliveRate); } @@ -358,8 +365,11 @@ void ServerProxy::onClipboardChanged(ClipboardID id, const IClipboard* clipboard) { String data = IClipboard::marshall(clipboard); - LOG((CLOG_DEBUG1 "sending clipboard %d seqnum=%d, size=%d", id, m_seqNum, data.size())); - ProtocolUtil::writef(m_stream, kMsgDClipboard, id, m_seqNum, &data); + LOG((CLOG_DEBUG "sending clipboard %d seqnum=%d", id, m_seqNum)); + + StreamChunker::sendClipboard(data, data.size(), id, m_seqNum, m_events, this); + + LOG((CLOG_DEBUG "sent clipboard size=%d", data.size())); } void @@ -928,6 +938,38 @@ ServerProxy::dragInfoReceived() m_client->dragInfoReceived(fileNum, content); } +void +ServerProxy::handleClipboardSendingEvent(const Event& event, void*) +{ + void* data = event.getData(); + ClipboardChunk* clipboardData = reinterpret_cast(data); + + LOG((CLOG_DEBUG1 "sending clipboard chunk")); + + char* chunk = clipboardData->m_chunk; + ClipboardID id = chunk[0]; + UInt32* seq = reinterpret_cast(&chunk[1]); + UInt32 sequence = *seq; + UInt8 mark = chunk[5]; + String dataChunk(&chunk[6], clipboardData->m_dataSize); + + switch (mark) { + case kDataStart: + LOG((CLOG_DEBUG2 "file sending start: size=%s", dataChunk.c_str())); + break; + + case kDataChunk: + LOG((CLOG_DEBUG2 "file chunk sending: size=%i", dataChunk.size())); + break; + + case kDataEnd: + LOG((CLOG_DEBUG2 "file sending finished")); + break; + } + + ProtocolUtil::writef(m_stream, kMsgDClipboard, id, sequence, mark, &dataChunk); +} + void ServerProxy::fileChunkSending(UInt8 mark, char* data, size_t dataSize) { diff --git a/src/lib/client/ServerProxy.h b/src/lib/client/ServerProxy.h index 336c640b..7f498cef 100644 --- a/src/lib/client/ServerProxy.h +++ b/src/lib/client/ServerProxy.h @@ -106,6 +106,7 @@ private: void infoAcknowledgment(); void fileChunkReceived(); void dragInfoReceived(); + void handleClipboardSendingEvent(const Event&, void*); private: typedef EResult (ServerProxy::*MessageParser)(const UInt8*);