From 1df566d241e65d99ab7c73f5d2d51a61963ab438 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 21 May 2015 17:50:55 -0700 Subject: [PATCH] Refactored duplicated code #4601 --- src/lib/client/ServerProxy.cpp | 28 +-------------------------- src/lib/server/ClientProxy1_6.cpp | 28 +-------------------------- src/lib/synergy/ClipboardChunk.cpp | 31 ++++++++++++++++++++++++++++++ src/lib/synergy/ClipboardChunk.h | 2 ++ 4 files changed, 35 insertions(+), 54 deletions(-) diff --git a/src/lib/client/ServerProxy.cpp b/src/lib/client/ServerProxy.cpp index 1576ca8f..05b94fd9 100644 --- a/src/lib/client/ServerProxy.cpp +++ b/src/lib/client/ServerProxy.cpp @@ -921,33 +921,7 @@ ServerProxy::dragInfoReceived() 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); + ClipboardChunk::send(m_stream, event.getData()); } void diff --git a/src/lib/server/ClientProxy1_6.cpp b/src/lib/server/ClientProxy1_6.cpp index 2e359e8e..8b429cca 100644 --- a/src/lib/server/ClientProxy1_6.cpp +++ b/src/lib/server/ClientProxy1_6.cpp @@ -66,33 +66,7 @@ ClientProxy1_6::setClipboard(ClipboardID id, const IClipboard* clipboard) void ClientProxy1_6::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(getStream(), kMsgDClipboard, id, sequence, mark, &dataChunk); + ClipboardChunk::send(getStream(), event.getData()); } bool diff --git a/src/lib/synergy/ClipboardChunk.cpp b/src/lib/synergy/ClipboardChunk.cpp index 53b97203..0a0cc5c6 100644 --- a/src/lib/synergy/ClipboardChunk.cpp +++ b/src/lib/synergy/ClipboardChunk.cpp @@ -121,3 +121,34 @@ ClipboardChunk::assemble(synergy::IStream* stream, return kError; } + +void +ClipboardChunk::send(synergy::IStream* stream, void* data) +{ + 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 "sending clipboard chunk start: size=%s", dataChunk.c_str())); + break; + + case kDataChunk: + LOG((CLOG_DEBUG2 "sending clipboard chunk data: size=%i", dataChunk.size())); + break; + + case kDataEnd: + LOG((CLOG_DEBUG2 "sending clipboard finished")); + break; + } + + ProtocolUtil::writef(stream, kMsgDClipboard, id, sequence, mark, &dataChunk); +} diff --git a/src/lib/synergy/ClipboardChunk.h b/src/lib/synergy/ClipboardChunk.h index f534f4c6..c77ad781 100644 --- a/src/lib/synergy/ClipboardChunk.h +++ b/src/lib/synergy/ClipboardChunk.h @@ -56,4 +56,6 @@ public: String& dataCached, ClipboardID& id, UInt32& sequence); + + static void send(synergy::IStream* stream, void* data); };