mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-08 22:52:13 +08:00
Checkpoint. Conversion to event driven system complete for Unix.
Still need to convert win32 platform specific files.
This commit is contained in:
@@ -13,15 +13,15 @@
|
||||
*/
|
||||
|
||||
#include "CServerProxy.h"
|
||||
#include "CClient.h"
|
||||
#include "CClipboard.h"
|
||||
#include "CProtocolUtil.h"
|
||||
#include "IClient.h"
|
||||
#include "OptionTypes.h"
|
||||
#include "ProtocolTypes.h"
|
||||
#include "IInputStream.h"
|
||||
#include "IOutputStream.h"
|
||||
#include "CLock.h"
|
||||
#include "IStream.h"
|
||||
#include "CLog.h"
|
||||
#include "CStopwatch.h"
|
||||
#include "IEventQueue.h"
|
||||
#include "TMethodEventJob.h"
|
||||
#include "XBase.h"
|
||||
#include <memory>
|
||||
|
||||
@@ -29,293 +29,243 @@
|
||||
// CServerProxy
|
||||
//
|
||||
|
||||
CServerProxy::CServerProxy(IClient* client,
|
||||
IInputStream* adoptedInput, IOutputStream* adoptedOutput) :
|
||||
CEvent::Type CServerProxy::s_handshakeCompleteEvent =
|
||||
CEvent::kUnknown;
|
||||
|
||||
CServerProxy::CServerProxy(CClient* client, IStream* stream) :
|
||||
m_client(client),
|
||||
m_input(adoptedInput),
|
||||
m_output(adoptedOutput),
|
||||
m_stream(stream),
|
||||
m_timer(NULL),
|
||||
m_seqNum(0),
|
||||
m_heartRate(kHeartRate)
|
||||
m_compressMouse(false),
|
||||
m_ignoreMouse(false),
|
||||
m_heartRate(0.0)
|
||||
{
|
||||
assert(m_client != NULL);
|
||||
assert(m_input != NULL);
|
||||
assert(m_output != NULL);
|
||||
assert(m_stream != NULL);
|
||||
|
||||
// initialize modifier translation table
|
||||
for (KeyModifierID id = 0; id < kKeyModifierIDLast; ++id)
|
||||
m_modifierTranslationTable[id] = id;
|
||||
|
||||
// handle data on stream
|
||||
EVENTQUEUE->adoptHandler(IStream::getInputReadyEvent(),
|
||||
m_stream->getEventTarget(),
|
||||
new TMethodEventJob<CServerProxy>(this,
|
||||
&CServerProxy::handleMessage));
|
||||
|
||||
// send heartbeat
|
||||
installHeartBeat(kHeartRate);
|
||||
}
|
||||
|
||||
CServerProxy::~CServerProxy()
|
||||
{
|
||||
delete m_input;
|
||||
delete m_output;
|
||||
installHeartBeat(-1.0);
|
||||
}
|
||||
|
||||
bool
|
||||
CServerProxy::mainLoop()
|
||||
CEvent::Type
|
||||
CServerProxy::getHandshakeCompleteEvent()
|
||||
{
|
||||
bool failedToConnect = false;
|
||||
try {
|
||||
// no compressed mouse motion yet
|
||||
m_compressMouse = false;
|
||||
return CEvent::registerTypeOnce(s_handshakeCompleteEvent,
|
||||
"CServerProxy::handshakeComplete");
|
||||
}
|
||||
|
||||
// not ignoring mouse motions
|
||||
m_ignoreMouse = false;
|
||||
void
|
||||
CServerProxy::installHeartBeat(double heartRate)
|
||||
{
|
||||
if (m_timer != NULL) {
|
||||
EVENTQUEUE->removeHandler(CEvent::kTimer, m_timer);
|
||||
EVENTQUEUE->deleteTimer(m_timer);
|
||||
}
|
||||
m_heartRate = heartRate;
|
||||
if (m_heartRate > 0.0) {
|
||||
m_timer = EVENTQUEUE->newTimer(m_heartRate, NULL);
|
||||
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_timer,
|
||||
new TMethodEventJob<CServerProxy>(this,
|
||||
&CServerProxy::handleHeartBeat));
|
||||
}
|
||||
}
|
||||
|
||||
// reset sequence number
|
||||
m_seqNum = 0;
|
||||
void
|
||||
CServerProxy::handleMessage(const CEvent&, void*)
|
||||
{
|
||||
while (m_stream->isReady()) {
|
||||
// read next code
|
||||
UInt8 code[4];
|
||||
UInt32 n = m_stream->read(code, sizeof(code));
|
||||
if (n == 0) {
|
||||
break;
|
||||
}
|
||||
if (n != 4) {
|
||||
// client sent an incomplete message
|
||||
LOG((CLOG_ERR "incomplete message from server"));
|
||||
m_client->disconnect("incomplete message from server");
|
||||
return;
|
||||
}
|
||||
|
||||
// handle messages from server
|
||||
CStopwatch heartbeat;
|
||||
for (;;) {
|
||||
// if no input is pending then flush compressed mouse motion
|
||||
if (getInputStream()->getSize() == 0) {
|
||||
flushCompressedMouse();
|
||||
}
|
||||
// parse message
|
||||
LOG((CLOG_DEBUG2 "msg from server: %c%c%c%c", code[0], code[1], code[2], code[3]));
|
||||
if (memcmp(code, kMsgDMouseMove, 4) == 0) {
|
||||
mouseMove();
|
||||
}
|
||||
|
||||
// wait for a message
|
||||
LOG((CLOG_DEBUG2 "waiting for message"));
|
||||
UInt8 code[4];
|
||||
UInt32 n = getInputStream()->read(code, 4, m_heartRate);
|
||||
else if (memcmp(code, kMsgDMouseWheel, 4) == 0) {
|
||||
mouseWheel();
|
||||
}
|
||||
|
||||
// check if server hungup
|
||||
if (n == 0) {
|
||||
LOG((CLOG_NOTE "server disconnected"));
|
||||
break;
|
||||
}
|
||||
else if (memcmp(code, kMsgDKeyDown, 4) == 0) {
|
||||
keyDown();
|
||||
}
|
||||
|
||||
// check for time out
|
||||
if (n == (UInt32)-1 ||
|
||||
(m_heartRate >= 0.0 && heartbeat.getTime() > m_heartRate)) {
|
||||
// send heartbeat
|
||||
CLock lock(&m_mutex);
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCNoop);
|
||||
heartbeat.reset();
|
||||
if (n == (UInt32)-1) {
|
||||
// no message to process
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (memcmp(code, kMsgDKeyUp, 4) == 0) {
|
||||
keyUp();
|
||||
}
|
||||
|
||||
// verify we got an entire code
|
||||
if (n != 4) {
|
||||
// client sent an incomplete message
|
||||
LOG((CLOG_ERR "incomplete message from server"));
|
||||
break;
|
||||
}
|
||||
else if (memcmp(code, kMsgDMouseDown, 4) == 0) {
|
||||
mouseDown();
|
||||
}
|
||||
|
||||
// parse message
|
||||
LOG((CLOG_DEBUG2 "msg from server: %c%c%c%c", code[0], code[1], code[2], code[3]));
|
||||
if (memcmp(code, kMsgDMouseMove, 4) == 0) {
|
||||
mouseMove();
|
||||
}
|
||||
else if (memcmp(code, kMsgDMouseUp, 4) == 0) {
|
||||
mouseUp();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgDMouseWheel, 4) == 0) {
|
||||
mouseWheel();
|
||||
}
|
||||
else if (memcmp(code, kMsgDKeyRepeat, 4) == 0) {
|
||||
keyRepeat();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgDKeyDown, 4) == 0) {
|
||||
keyDown();
|
||||
}
|
||||
else if (memcmp(code, kMsgCNoop, 4) == 0) {
|
||||
// accept and discard no-op
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgDKeyUp, 4) == 0) {
|
||||
keyUp();
|
||||
}
|
||||
else if (memcmp(code, kMsgCEnter, 4) == 0) {
|
||||
enter();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgDMouseDown, 4) == 0) {
|
||||
mouseDown();
|
||||
}
|
||||
else if (memcmp(code, kMsgCLeave, 4) == 0) {
|
||||
leave();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgDMouseUp, 4) == 0) {
|
||||
mouseUp();
|
||||
}
|
||||
else if (memcmp(code, kMsgCClipboard, 4) == 0) {
|
||||
grabClipboard();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgDKeyRepeat, 4) == 0) {
|
||||
keyRepeat();
|
||||
}
|
||||
else if (memcmp(code, kMsgCScreenSaver, 4) == 0) {
|
||||
screensaver();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgCNoop, 4) == 0) {
|
||||
// accept and discard no-op
|
||||
}
|
||||
else if (memcmp(code, kMsgQInfo, 4) == 0) {
|
||||
queryInfo();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgCEnter, 4) == 0) {
|
||||
enter();
|
||||
}
|
||||
else if (memcmp(code, kMsgCInfoAck, 4) == 0) {
|
||||
infoAcknowledgment();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgCLeave, 4) == 0) {
|
||||
leave();
|
||||
}
|
||||
else if (memcmp(code, kMsgDClipboard, 4) == 0) {
|
||||
setClipboard();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgCClipboard, 4) == 0) {
|
||||
grabClipboard();
|
||||
}
|
||||
else if (memcmp(code, kMsgCResetOptions, 4) == 0) {
|
||||
resetOptions();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgCScreenSaver, 4) == 0) {
|
||||
screensaver();
|
||||
}
|
||||
else if (memcmp(code, kMsgDSetOptions, 4) == 0) {
|
||||
setOptions();
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgQInfo, 4) == 0) {
|
||||
queryInfo();
|
||||
}
|
||||
else if (memcmp(code, kMsgCClose, 4) == 0) {
|
||||
// server wants us to hangup
|
||||
LOG((CLOG_DEBUG1 "recv close"));
|
||||
m_client->disconnect(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgCInfoAck, 4) == 0) {
|
||||
infoAcknowledgment();
|
||||
}
|
||||
else if (memcmp(code, kMsgEIncompatible, 4) == 0) {
|
||||
SInt32 major, minor;
|
||||
CProtocolUtil::readf(m_stream,
|
||||
kMsgEIncompatible + 4, &major, &minor);
|
||||
LOG((CLOG_ERR "server has incompatible version %d.%d", major, minor));
|
||||
m_client->disconnect("server has incompatible version");
|
||||
return;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgDClipboard, 4) == 0) {
|
||||
setClipboard();
|
||||
}
|
||||
else if (memcmp(code, kMsgEBusy, 4) == 0) {
|
||||
LOG((CLOG_ERR "server already has a connected client with name \"%s\"", m_client->getName().c_str()));
|
||||
m_client->disconnect("server already has a connected client with our name");
|
||||
return;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgCResetOptions, 4) == 0) {
|
||||
resetOptions();
|
||||
}
|
||||
else if (memcmp(code, kMsgEUnknown, 4) == 0) {
|
||||
LOG((CLOG_ERR "server refused client with name \"%s\"", m_client->getName().c_str()));
|
||||
m_client->disconnect("server refused client with our name");
|
||||
return;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgDSetOptions, 4) == 0) {
|
||||
setOptions();
|
||||
}
|
||||
else if (memcmp(code, kMsgEBad, 4) == 0) {
|
||||
LOG((CLOG_ERR "server disconnected due to a protocol error"));
|
||||
m_client->disconnect("server reported a protocol error");
|
||||
return;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgCClose, 4) == 0) {
|
||||
// server wants us to hangup
|
||||
LOG((CLOG_DEBUG1 "recv close"));
|
||||
break;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgEIncompatible, 4) == 0) {
|
||||
SInt32 major, minor;
|
||||
CProtocolUtil::readf(getInputStream(),
|
||||
kMsgEIncompatible + 4, &major, &minor);
|
||||
LOG((CLOG_ERR "server has incompatible version %d.%d", major, minor));
|
||||
failedToConnect = true;
|
||||
break;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgEBusy, 4) == 0) {
|
||||
LOG((CLOG_ERR "server already has a connected client with name \"%s\"", getName().c_str()));
|
||||
failedToConnect = true;
|
||||
break;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgEUnknown, 4) == 0) {
|
||||
LOG((CLOG_ERR "server refused client with name \"%s\"", getName().c_str()));
|
||||
failedToConnect = true;
|
||||
break;
|
||||
}
|
||||
|
||||
else if (memcmp(code, kMsgEBad, 4) == 0) {
|
||||
LOG((CLOG_ERR "server disconnected due to a protocol error"));
|
||||
failedToConnect = true;
|
||||
break;
|
||||
}
|
||||
|
||||
else {
|
||||
// unknown message
|
||||
LOG((CLOG_ERR "unknown message from server"));
|
||||
LOG((CLOG_ERR "unknown message: %d %d %d %d [%c%c%c%c]", code[0], code[1], code[2], code[3], code[0], code[1], code[2], code[3]));
|
||||
failedToConnect = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// unknown message
|
||||
LOG((CLOG_ERR "unknown message: %d %d %d %d [%c%c%c%c]", code[0], code[1], code[2], code[3], code[0], code[1], code[2], code[3]));
|
||||
m_client->disconnect("unknown message from server");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (XBase& e) {
|
||||
LOG((CLOG_ERR "error: %s", e.what()));
|
||||
}
|
||||
catch (...) {
|
||||
throw;
|
||||
}
|
||||
|
||||
return !failedToConnect;
|
||||
}
|
||||
|
||||
IClient*
|
||||
CServerProxy::getClient() const
|
||||
{
|
||||
return m_client;
|
||||
}
|
||||
|
||||
CString
|
||||
CServerProxy::getName() const
|
||||
{
|
||||
return m_client->getName();
|
||||
}
|
||||
|
||||
IInputStream*
|
||||
CServerProxy::getInputStream() const
|
||||
{
|
||||
return m_input;
|
||||
}
|
||||
|
||||
IOutputStream*
|
||||
CServerProxy::getOutputStream() const
|
||||
{
|
||||
return m_output;
|
||||
flushCompressedMouse();
|
||||
}
|
||||
|
||||
void
|
||||
CServerProxy::onError()
|
||||
CServerProxy::handleHeartBeat(const CEvent&, void*)
|
||||
{
|
||||
// ignore
|
||||
CProtocolUtil::writef(m_stream, kMsgCNoop);
|
||||
}
|
||||
|
||||
void
|
||||
CServerProxy::onInfoChanged(const CClientInfo& info)
|
||||
CServerProxy::onInfoChanged()
|
||||
{
|
||||
// ignore mouse motion until we receive acknowledgment of our info
|
||||
// change message.
|
||||
CLock lock(&m_mutex);
|
||||
m_ignoreMouse = true;
|
||||
|
||||
// send info update
|
||||
sendInfo(info);
|
||||
queryInfo();
|
||||
}
|
||||
|
||||
bool
|
||||
CServerProxy::onGrabClipboard(ClipboardID id)
|
||||
{
|
||||
LOG((CLOG_DEBUG1 "sending clipboard %d changed", id));
|
||||
CLock lock(&m_mutex);
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCClipboard, id, m_seqNum);
|
||||
CProtocolUtil::writef(m_stream, kMsgCClipboard, id, m_seqNum);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
CServerProxy::onClipboardChanged(ClipboardID id, const CString& data)
|
||||
CServerProxy::onClipboardChanged(ClipboardID id, const IClipboard* clipboard)
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
CString data = IClipboard::marshall(clipboard);
|
||||
LOG((CLOG_DEBUG1 "sending clipboard %d seqnum=%d, size=%d", id, m_seqNum, data.size()));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDClipboard, id, m_seqNum, &data);
|
||||
CProtocolUtil::writef(m_stream, kMsgDClipboard, id, m_seqNum, &data);
|
||||
}
|
||||
|
||||
void
|
||||
CServerProxy::flushCompressedMouse()
|
||||
{
|
||||
bool send = false;
|
||||
SInt32 x = 0, y = 0;
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
if (m_compressMouse) {
|
||||
m_compressMouse = false;
|
||||
x = m_xMouse;
|
||||
y = m_yMouse;
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (send) {
|
||||
getClient()->mouseMove(x, y);
|
||||
if (m_compressMouse) {
|
||||
m_compressMouse = false;
|
||||
m_client->mouseMove(m_xMouse, m_yMouse);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CServerProxy::sendInfo(const CClientInfo& info)
|
||||
{
|
||||
// note -- m_mutex should be locked on entry
|
||||
LOG((CLOG_DEBUG1 "sending info shape=%d,%d %dx%d zone=%d pos=%d,%d", info.m_x, info.m_y, info.m_w, info.m_h, info.m_zoneSize, info.m_mx, info.m_my));
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgDInfo,
|
||||
LOG((CLOG_DEBUG1 "sending info shape=%d,%d %dx%d", info.m_x, info.m_y, info.m_w, info.m_h));
|
||||
CProtocolUtil::writef(m_stream, kMsgDInfo,
|
||||
info.m_x, info.m_y,
|
||||
info.m_w, info.m_h,
|
||||
info.m_zoneSize,
|
||||
info.m_mx, info.m_my);
|
||||
info.m_w, info.m_h, 0, 0, 0);
|
||||
}
|
||||
|
||||
KeyID
|
||||
@@ -434,19 +384,15 @@ CServerProxy::enter()
|
||||
SInt16 x, y;
|
||||
UInt16 mask;
|
||||
UInt32 seqNum;
|
||||
CProtocolUtil::readf(getInputStream(),
|
||||
kMsgCEnter + 4, &x, &y, &seqNum, &mask);
|
||||
CProtocolUtil::readf(m_stream, kMsgCEnter + 4, &x, &y, &seqNum, &mask);
|
||||
LOG((CLOG_DEBUG1 "recv enter, %d,%d %d %04x", x, y, seqNum, mask));
|
||||
|
||||
// discard old compressed mouse motion, if any
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
m_compressMouse = false;
|
||||
m_seqNum = seqNum;
|
||||
}
|
||||
m_compressMouse = false;
|
||||
m_seqNum = seqNum;
|
||||
|
||||
// forward
|
||||
getClient()->enter(x, y, seqNum, static_cast<KeyModifierMask>(mask), false);
|
||||
m_client->enter(x, y, seqNum, static_cast<KeyModifierMask>(mask), false);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -459,7 +405,7 @@ CServerProxy::leave()
|
||||
flushCompressedMouse();
|
||||
|
||||
// forward
|
||||
getClient()->leave();
|
||||
m_client->leave();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -469,8 +415,7 @@ CServerProxy::setClipboard()
|
||||
ClipboardID id;
|
||||
UInt32 seqNum;
|
||||
CString data;
|
||||
CProtocolUtil::readf(getInputStream(),
|
||||
kMsgDClipboard + 4, &id, &seqNum, &data);
|
||||
CProtocolUtil::readf(m_stream, kMsgDClipboard + 4, &id, &seqNum, &data);
|
||||
LOG((CLOG_DEBUG "recv clipboard %d size=%d", id, data.size()));
|
||||
|
||||
// validate
|
||||
@@ -479,7 +424,9 @@ CServerProxy::setClipboard()
|
||||
}
|
||||
|
||||
// forward
|
||||
getClient()->setClipboard(id, data);
|
||||
CClipboard clipboard;
|
||||
clipboard.unmarshall(data, 0);
|
||||
m_client->setClipboard(id, &clipboard);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -488,7 +435,7 @@ CServerProxy::grabClipboard()
|
||||
// parse
|
||||
ClipboardID id;
|
||||
UInt32 seqNum;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgCClipboard + 4, &id, &seqNum);
|
||||
CProtocolUtil::readf(m_stream, kMsgCClipboard + 4, &id, &seqNum);
|
||||
LOG((CLOG_DEBUG "recv grab clipboard %d", id));
|
||||
|
||||
// validate
|
||||
@@ -497,7 +444,7 @@ CServerProxy::grabClipboard()
|
||||
}
|
||||
|
||||
// forward
|
||||
getClient()->grabClipboard(id);
|
||||
m_client->grabClipboard(id);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -508,8 +455,7 @@ CServerProxy::keyDown()
|
||||
|
||||
// parse
|
||||
UInt16 id, mask, button;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDKeyDown + 4,
|
||||
&id, &mask, &button);
|
||||
CProtocolUtil::readf(m_stream, kMsgDKeyDown + 4, &id, &mask, &button);
|
||||
LOG((CLOG_DEBUG1 "recv key down id=%d, mask=0x%04x, button=0x%04x", id, mask, button));
|
||||
|
||||
// translate
|
||||
@@ -521,7 +467,7 @@ CServerProxy::keyDown()
|
||||
LOG((CLOG_DEBUG1 "key down translated to id=%d, mask=0x%04x", id2, mask2));
|
||||
|
||||
// forward
|
||||
getClient()->keyDown(id2, mask2, button);
|
||||
m_client->keyDown(id2, mask2, button);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -532,7 +478,7 @@ CServerProxy::keyRepeat()
|
||||
|
||||
// parse
|
||||
UInt16 id, mask, count, button;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDKeyRepeat + 4,
|
||||
CProtocolUtil::readf(m_stream, kMsgDKeyRepeat + 4,
|
||||
&id, &mask, &count, &button);
|
||||
LOG((CLOG_DEBUG1 "recv key repeat id=%d, mask=0x%04x, count=%d, button=0x%04x", id, mask, count, button));
|
||||
|
||||
@@ -545,7 +491,7 @@ CServerProxy::keyRepeat()
|
||||
LOG((CLOG_DEBUG1 "key repeat translated to id=%d, mask=0x%04x", id2, mask2));
|
||||
|
||||
// forward
|
||||
getClient()->keyRepeat(id2, mask2, count, button);
|
||||
m_client->keyRepeat(id2, mask2, count, button);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -556,7 +502,7 @@ CServerProxy::keyUp()
|
||||
|
||||
// parse
|
||||
UInt16 id, mask, button;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDKeyUp + 4, &id, &mask, &button);
|
||||
CProtocolUtil::readf(m_stream, kMsgDKeyUp + 4, &id, &mask, &button);
|
||||
LOG((CLOG_DEBUG1 "recv key up id=%d, mask=0x%04x, button=0x%04x", id, mask, button));
|
||||
|
||||
// translate
|
||||
@@ -568,7 +514,7 @@ CServerProxy::keyUp()
|
||||
LOG((CLOG_DEBUG1 "key up translated to id=%d, mask=0x%04x", id2, mask2));
|
||||
|
||||
// forward
|
||||
getClient()->keyUp(id2, mask2, button);
|
||||
m_client->keyUp(id2, mask2, button);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -579,11 +525,11 @@ CServerProxy::mouseDown()
|
||||
|
||||
// parse
|
||||
SInt8 id;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDMouseDown + 4, &id);
|
||||
CProtocolUtil::readf(m_stream, kMsgDMouseDown + 4, &id);
|
||||
LOG((CLOG_DEBUG1 "recv mouse down id=%d", id));
|
||||
|
||||
// forward
|
||||
getClient()->mouseDown(static_cast<ButtonID>(id));
|
||||
m_client->mouseDown(static_cast<ButtonID>(id));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -594,11 +540,11 @@ CServerProxy::mouseUp()
|
||||
|
||||
// parse
|
||||
SInt8 id;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDMouseUp + 4, &id);
|
||||
CProtocolUtil::readf(m_stream, kMsgDMouseUp + 4, &id);
|
||||
LOG((CLOG_DEBUG1 "recv mouse up id=%d", id));
|
||||
|
||||
// forward
|
||||
getClient()->mouseUp(static_cast<ButtonID>(id));
|
||||
m_client->mouseUp(static_cast<ButtonID>(id));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -607,30 +553,27 @@ CServerProxy::mouseMove()
|
||||
// parse
|
||||
bool ignore;
|
||||
SInt16 x, y;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDMouseMove + 4, &x, &y);
|
||||
CProtocolUtil::readf(m_stream, kMsgDMouseMove + 4, &x, &y);
|
||||
|
||||
{
|
||||
// note if we should ignore the move
|
||||
CLock lock(&m_mutex);
|
||||
ignore = m_ignoreMouse;
|
||||
// note if we should ignore the move
|
||||
ignore = m_ignoreMouse;
|
||||
|
||||
// compress mouse motion events if more input follows
|
||||
if (!ignore && !m_compressMouse && getInputStream()->getSize() > 0) {
|
||||
m_compressMouse = true;
|
||||
}
|
||||
// compress mouse motion events if more input follows
|
||||
if (!ignore && !m_compressMouse && m_stream->isReady()) {
|
||||
m_compressMouse = true;
|
||||
}
|
||||
|
||||
// if compressing then ignore the motion but record it
|
||||
if (m_compressMouse) {
|
||||
ignore = true;
|
||||
m_xMouse = x;
|
||||
m_yMouse = y;
|
||||
}
|
||||
// if compressing then ignore the motion but record it
|
||||
if (m_compressMouse) {
|
||||
ignore = true;
|
||||
m_xMouse = x;
|
||||
m_yMouse = y;
|
||||
}
|
||||
LOG((CLOG_DEBUG2 "recv mouse move %d,%d", x, y));
|
||||
|
||||
// forward
|
||||
if (!ignore) {
|
||||
getClient()->mouseMove(x, y);
|
||||
m_client->mouseMove(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,11 +585,11 @@ CServerProxy::mouseWheel()
|
||||
|
||||
// parse
|
||||
SInt16 delta;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDMouseWheel + 4, &delta);
|
||||
CProtocolUtil::readf(m_stream, kMsgDMouseWheel + 4, &delta);
|
||||
LOG((CLOG_DEBUG2 "recv mouse wheel %+d", delta));
|
||||
|
||||
// forward
|
||||
getClient()->mouseWheel(delta);
|
||||
m_client->mouseWheel(delta);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -654,11 +597,11 @@ CServerProxy::screensaver()
|
||||
{
|
||||
// parse
|
||||
SInt8 on;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgCScreenSaver + 4, &on);
|
||||
CProtocolUtil::readf(m_stream, kMsgCScreenSaver + 4, &on);
|
||||
LOG((CLOG_DEBUG1 "recv screen saver on=%d", on));
|
||||
|
||||
// forward
|
||||
getClient()->screensaver(on != 0);
|
||||
m_client->screensaver(on != 0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -668,22 +611,18 @@ CServerProxy::resetOptions()
|
||||
LOG((CLOG_DEBUG1 "recv reset options"));
|
||||
|
||||
// forward
|
||||
getClient()->resetOptions();
|
||||
m_client->resetOptions();
|
||||
|
||||
CLock lock(&m_mutex);
|
||||
|
||||
// reset heart rate
|
||||
m_heartRate = kHeartRate;
|
||||
// reset heart rate and send heartbeat if necessary
|
||||
installHeartBeat(kHeartRate);
|
||||
if (m_heartRate >= 0.0) {
|
||||
CProtocolUtil::writef(m_stream, kMsgCNoop);
|
||||
}
|
||||
|
||||
// reset modifier translation table
|
||||
for (KeyModifierID id = 0; id < kKeyModifierIDLast; ++id) {
|
||||
m_modifierTranslationTable[id] = id;
|
||||
}
|
||||
|
||||
// send heartbeat if necessary
|
||||
if (m_heartRate >= 0.0) {
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCNoop);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -691,13 +630,11 @@ CServerProxy::setOptions()
|
||||
{
|
||||
// parse
|
||||
COptionsList options;
|
||||
CProtocolUtil::readf(getInputStream(), kMsgDSetOptions + 4, &options);
|
||||
CProtocolUtil::readf(m_stream, kMsgDSetOptions + 4, &options);
|
||||
LOG((CLOG_DEBUG1 "recv set options size=%d", options.size()));
|
||||
|
||||
// forward
|
||||
getClient()->setOptions(options);
|
||||
|
||||
CLock lock(&m_mutex);
|
||||
m_client->setOptions(options);
|
||||
|
||||
// update modifier table
|
||||
for (UInt32 i = 0, n = options.size(); i < n; i += 2) {
|
||||
@@ -718,12 +655,10 @@ CServerProxy::setOptions()
|
||||
id = kKeyModifierIDSuper;
|
||||
}
|
||||
else if (options[i] == kOptionHeartbeat) {
|
||||
// update heart rate
|
||||
m_heartRate = 1.0e-3 * static_cast<double>(options[i + 1]);
|
||||
|
||||
// send heartbeat if necessary
|
||||
// update heart rate and send heartbeat if necessary
|
||||
installHeartBeat(1.0e-3 * static_cast<double>(options[i + 1]));
|
||||
if (m_heartRate >= 0.0) {
|
||||
CProtocolUtil::writef(getOutputStream(), kMsgCNoop);
|
||||
CProtocolUtil::writef(m_stream, kMsgCNoop);
|
||||
}
|
||||
}
|
||||
if (id != kKeyModifierIDNull) {
|
||||
@@ -737,24 +672,14 @@ CServerProxy::setOptions()
|
||||
void
|
||||
CServerProxy::queryInfo()
|
||||
{
|
||||
// get current info
|
||||
CClientInfo info;
|
||||
getClient()->getShape(info.m_x, info.m_y, info.m_w, info.m_h);
|
||||
getClient()->getCursorPos(info.m_mx, info.m_my);
|
||||
info.m_zoneSize = getClient()->getJumpZoneSize();
|
||||
|
||||
// send it
|
||||
CLock lock(&m_mutex);
|
||||
m_client->getShape(info.m_x, info.m_y, info.m_w, info.m_h);
|
||||
sendInfo(info);
|
||||
}
|
||||
|
||||
void
|
||||
CServerProxy::infoAcknowledgment()
|
||||
{
|
||||
// parse
|
||||
LOG((CLOG_DEBUG1 "recv info acknowledgment"));
|
||||
|
||||
// now allow mouse motion
|
||||
CLock lock(&m_mutex);
|
||||
m_ignoreMouse = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user