Refactored duplicated code #4601

This commit is contained in:
Jerry (Xinyu Hou) 2015-05-21 17:50:55 -07:00
parent 1c28444cf6
commit 1df566d241
4 changed files with 35 additions and 54 deletions

View File

@ -921,33 +921,7 @@ ServerProxy::dragInfoReceived()
void
ServerProxy::handleClipboardSendingEvent(const Event& event, void*)
{
void* data = event.getData();
ClipboardChunk* clipboardData = reinterpret_cast<ClipboardChunk*>(data);
LOG((CLOG_DEBUG1 "sending clipboard chunk"));
char* chunk = clipboardData->m_chunk;
ClipboardID id = chunk[0];
UInt32* seq = reinterpret_cast<UInt32*>(&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

View File

@ -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<ClipboardChunk*>(data);
LOG((CLOG_DEBUG1 "sending clipboard chunk"));
char* chunk = clipboardData->m_chunk;
ClipboardID id = chunk[0];
UInt32* seq = reinterpret_cast<UInt32*>(&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

View File

@ -121,3 +121,34 @@ ClipboardChunk::assemble(synergy::IStream* stream,
return kError;
}
void
ClipboardChunk::send(synergy::IStream* stream, void* data)
{
ClipboardChunk* clipboardData = reinterpret_cast<ClipboardChunk*>(data);
LOG((CLOG_DEBUG1 "sending clipboard chunk"));
char* chunk = clipboardData->m_chunk;
ClipboardID id = chunk[0];
UInt32* seq = reinterpret_cast<UInt32*>(&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);
}

View File

@ -56,4 +56,6 @@ public:
String& dataCached,
ClipboardID& id,
UInt32& sequence);
static void send(synergy::IStream* stream, void* data);
};