Deprecated and moved clipboard functionality into new protocol #4601

This commit is contained in:
Jerry (Xinyu Hou) 2015-05-21 15:34:28 -07:00
parent 8b49eb6595
commit 257c19ecc4
4 changed files with 55 additions and 58 deletions

View File

@ -275,17 +275,7 @@ ClientProxy1_0::leave()
void
ClientProxy1_0::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);
String data = m_clipboard[id].m_clipboard.marshall();
LOG((CLOG_DEBUG "send clipboard %d to \"%s\" size=%d", id, getName().c_str(), data.size()));
ProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, &data);
}
// ignore -- deprecated in protocol 1.0
}
void
@ -451,51 +441,8 @@ ClientProxy1_0::recvInfo()
bool
ClientProxy1_0::recvClipboard()
{
// parse message
static String dataCached;
static size_t expectedSize;
ClipboardID id;
UInt8 mark;
UInt32 seqNum;
String data;
if (!ProtocolUtil::readf(getStream(),
kMsgDClipboard + 4, &id, &seqNum, &mark, &data)) {
// deprecated in protocol 1.0
return false;
}
if (mark == kDataStart) {
expectedSize = synergy::string::stringToSizeType(data);
LOG((CLOG_DEBUG "start receiving clipboard data"));
dataCached.clear();
}
else if (mark == kDataChunk) {
dataCached.append(data);
}
else if (mark == kDataEnd) {
LOG((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seqNum, dataCached.size()));
// validate
if (id >= kClipboardEnd) {
return false;
}
else if (expectedSize != dataCached.size()) {
LOG((CLOG_ERR "corrupted clipboard data, expected size=%d actual size=%d", expectedSize, dataCached.size()));
return false;
}
// save clipboard
m_clipboard[id].m_clipboard.unmarshall(dataCached, 0);
m_clipboard[id].m_sequenceNumber = seqNum;
// notify
ClipboardInfo* info = new ClipboardInfo;
info->m_id = id;
info->m_sequenceNumber = seqNum;
m_events->addEvent(Event(m_events->forClipboard().clipboardChanged(),
getEventTarget(), info));
}
return true;
}
bool

View File

@ -70,7 +70,7 @@ protected:
virtual void resetHeartbeatTimer();
virtual void addHeartbeatTimer();
virtual void removeHeartbeatTimer();
virtual bool recvClipboard();
private:
void disconnect();
void removeHandlers();
@ -81,7 +81,6 @@ private:
void handleFlatline(const Event&, void*);
bool recvInfo();
bool recvClipboard();
bool recvGrabClipboard();
protected:

View File

@ -94,3 +94,53 @@ ClientProxy1_6::handleClipboardSendingEvent(const Event& event, void*)
ProtocolUtil::writef(getStream(), kMsgDClipboard, id, sequence, mark, &dataChunk);
}
bool
ClientProxy1_6::recvClipboard()
{
// parse message
static String dataCached;
static size_t expectedSize;
ClipboardID id;
UInt8 mark;
UInt32 seqNum;
String data;
if (!ProtocolUtil::readf(getStream(),
kMsgDClipboard + 4, &id, &seqNum, &mark, &data)) {
return false;
}
if (mark == kDataStart) {
expectedSize = synergy::string::stringToSizeType(data);
LOG((CLOG_DEBUG "start receiving clipboard data"));
dataCached.clear();
}
else if (mark == kDataChunk) {
dataCached.append(data);
}
else if (mark == kDataEnd) {
LOG((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seqNum, dataCached.size()));
// validate
if (id >= kClipboardEnd) {
return false;
}
else if (expectedSize != dataCached.size()) {
LOG((CLOG_ERR "corrupted clipboard data, expected size=%d actual size=%d", expectedSize, dataCached.size()));
return false;
}
// save clipboard
m_clipboard[id].m_clipboard.unmarshall(dataCached, 0);
m_clipboard[id].m_sequenceNumber = seqNum;
// notify
ClipboardInfo* info = new ClipboardInfo;
info->m_id = id;
info->m_sequenceNumber = seqNum;
m_events->addEvent(Event(m_events->forClipboard().clipboardChanged(),
getEventTarget(), info));
}
return true;
}

View File

@ -29,6 +29,7 @@ public:
~ClientProxy1_6();
virtual void setClipboard(ClipboardID id, const IClipboard* clipboard);
virtual bool recvClipboard();
private:
void handleClipboardSendingEvent(const Event&, void*);