chore: Adjust Clang-format linter rules
120 Column Lines Block Indent for Bracket Align Custom Line Break Rules No Single Line Functions
This commit is contained in:
@ -54,9 +54,9 @@
|
||||
//
|
||||
|
||||
Client::Client(
|
||||
IEventQueue *events, const String &name, const NetworkAddress &address,
|
||||
ISocketFactory *socketFactory, deskflow::Screen *screen,
|
||||
deskflow::ClientArgs const &args)
|
||||
IEventQueue *events, const String &name, const NetworkAddress &address, ISocketFactory *socketFactory,
|
||||
deskflow::Screen *screen, deskflow::ClientArgs const &args
|
||||
)
|
||||
: m_mock(false),
|
||||
m_name(name),
|
||||
m_serverAddress(address),
|
||||
@ -75,29 +75,32 @@ Client::Client(
|
||||
m_useSecureNetwork(args.m_enableCrypto),
|
||||
m_args(args),
|
||||
m_enableClipboard(true),
|
||||
m_maximumClipboardSize(INT_MAX) {
|
||||
m_maximumClipboardSize(INT_MAX)
|
||||
{
|
||||
assert(m_socketFactory != NULL);
|
||||
assert(m_screen != NULL);
|
||||
|
||||
// register suspend/resume event handlers
|
||||
m_events->adoptHandler(
|
||||
m_events->forIScreen().suspend(), getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleSuspend));
|
||||
m_events->forIScreen().suspend(), getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleSuspend)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
m_events->forIScreen().resume(), getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleResume));
|
||||
m_events->forIScreen().resume(), getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleResume)
|
||||
);
|
||||
|
||||
if (m_args.m_enableDragDrop) {
|
||||
m_events->adoptHandler(
|
||||
m_events->forFile().fileChunkSending(), this,
|
||||
new TMethodEventJob<Client>(this, &Client::handleFileChunkSending));
|
||||
m_events->forFile().fileChunkSending(), this, new TMethodEventJob<Client>(this, &Client::handleFileChunkSending)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
m_events->forFile().fileRecieveCompleted(), this,
|
||||
new TMethodEventJob<Client>(this, &Client::handleFileRecieveCompleted));
|
||||
new TMethodEventJob<Client>(this, &Client::handleFileRecieveCompleted)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Client::~Client() {
|
||||
Client::~Client()
|
||||
{
|
||||
if (m_mock) {
|
||||
return;
|
||||
}
|
||||
@ -112,7 +115,8 @@ Client::~Client() {
|
||||
delete m_socketFactory;
|
||||
}
|
||||
|
||||
void Client::connect(size_t addressIndex) {
|
||||
void Client::connect(size_t addressIndex)
|
||||
{
|
||||
if (m_stream != NULL) {
|
||||
return;
|
||||
}
|
||||
@ -123,9 +127,7 @@ void Client::connect(size_t addressIndex) {
|
||||
|
||||
try {
|
||||
if (m_args.m_hostMode) {
|
||||
LOG(
|
||||
(CLOG_NOTE "waiting for server connection on %i port",
|
||||
m_serverAddress.getPort()));
|
||||
LOG((CLOG_NOTE "waiting for server connection on %i port", m_serverAddress.getPort()));
|
||||
} else {
|
||||
// resolve the server hostname. do this every time we connect
|
||||
// in case we couldn't resolve the address earlier or the address
|
||||
@ -138,16 +140,15 @@ void Client::connect(size_t addressIndex) {
|
||||
if (m_serverAddress.getAddress() != nullptr) {
|
||||
// to help users troubleshoot, show server host name (issue: 60)
|
||||
LOG(
|
||||
(CLOG_NOTE "connecting to '%s': %s:%i",
|
||||
m_serverAddress.getHostname().c_str(),
|
||||
ARCH->addrToString(m_serverAddress.getAddress()).c_str(),
|
||||
m_serverAddress.getPort()));
|
||||
(CLOG_NOTE "connecting to '%s': %s:%i", m_serverAddress.getHostname().c_str(),
|
||||
ARCH->addrToString(m_serverAddress.getAddress()).c_str(), m_serverAddress.getPort())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// create the socket
|
||||
IDataSocket *socket = m_socketFactory->create(
|
||||
m_useSecureNetwork, ARCH->getAddrFamily(m_serverAddress.getAddress()));
|
||||
IDataSocket *socket =
|
||||
m_socketFactory->create(m_useSecureNetwork, ARCH->getAddrFamily(m_serverAddress.getAddress()));
|
||||
bindNetworkInterface(socket);
|
||||
|
||||
// filter socket messages, including a packetizing filter
|
||||
@ -168,7 +169,8 @@ void Client::connect(size_t addressIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::disconnect(const char *msg) {
|
||||
void Client::disconnect(const char *msg)
|
||||
{
|
||||
cleanup();
|
||||
|
||||
if (msg) {
|
||||
@ -178,47 +180,62 @@ void Client::disconnect(const char *msg) {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::refuseConnection(const char *msg) {
|
||||
void Client::refuseConnection(const char *msg)
|
||||
{
|
||||
cleanup();
|
||||
|
||||
if (msg) {
|
||||
auto info = new FailInfo(msg);
|
||||
info->m_retry = true;
|
||||
Event event(
|
||||
m_events->forClient().connectionRefused(), getEventTarget(), info,
|
||||
Event::kDontFreeData);
|
||||
Event event(m_events->forClient().connectionRefused(), getEventTarget(), info, Event::kDontFreeData);
|
||||
m_events->addEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handshakeComplete() {
|
||||
void Client::handshakeComplete()
|
||||
{
|
||||
m_ready = true;
|
||||
m_screen->enable();
|
||||
sendEvent(m_events->forClient().connected(), NULL);
|
||||
}
|
||||
|
||||
bool Client::isConnected() const { return (m_server != NULL); }
|
||||
bool Client::isConnected() const
|
||||
{
|
||||
return (m_server != NULL);
|
||||
}
|
||||
|
||||
bool Client::isConnecting() const { return (m_timer != NULL); }
|
||||
bool Client::isConnecting() const
|
||||
{
|
||||
return (m_timer != NULL);
|
||||
}
|
||||
|
||||
NetworkAddress Client::getServerAddress() const { return m_serverAddress; }
|
||||
NetworkAddress Client::getServerAddress() const
|
||||
{
|
||||
return m_serverAddress;
|
||||
}
|
||||
|
||||
void *Client::getEventTarget() const { return m_screen->getEventTarget(); }
|
||||
void *Client::getEventTarget() const
|
||||
{
|
||||
return m_screen->getEventTarget();
|
||||
}
|
||||
|
||||
bool Client::getClipboard(ClipboardID id, IClipboard *clipboard) const {
|
||||
bool Client::getClipboard(ClipboardID id, IClipboard *clipboard) const
|
||||
{
|
||||
return m_screen->getClipboard(id, clipboard);
|
||||
}
|
||||
|
||||
void Client::getShape(SInt32 &x, SInt32 &y, SInt32 &w, SInt32 &h) const {
|
||||
void Client::getShape(SInt32 &x, SInt32 &y, SInt32 &w, SInt32 &h) const
|
||||
{
|
||||
m_screen->getShape(x, y, w, h);
|
||||
}
|
||||
|
||||
void Client::getCursorPos(SInt32 &x, SInt32 &y) const {
|
||||
void Client::getCursorPos(SInt32 &x, SInt32 &y) const
|
||||
{
|
||||
m_screen->getCursorPos(x, y);
|
||||
}
|
||||
|
||||
void Client::enter(
|
||||
SInt32 xAbs, SInt32 yAbs, UInt32, KeyModifierMask mask, bool) {
|
||||
void Client::enter(SInt32 xAbs, SInt32 yAbs, UInt32, KeyModifierMask mask, bool)
|
||||
{
|
||||
m_active = true;
|
||||
m_screen->mouseMove(xAbs, yAbs);
|
||||
m_screen->enter(mask);
|
||||
@ -229,7 +246,8 @@ void Client::enter(
|
||||
}
|
||||
}
|
||||
|
||||
bool Client::leave() {
|
||||
bool Client::leave()
|
||||
{
|
||||
m_active = false;
|
||||
|
||||
m_screen->leave();
|
||||
@ -246,58 +264,78 @@ bool Client::leave() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Client::setClipboard(ClipboardID id, const IClipboard *clipboard) {
|
||||
void Client::setClipboard(ClipboardID id, const IClipboard *clipboard)
|
||||
{
|
||||
m_screen->setClipboard(id, clipboard);
|
||||
m_ownClipboard[id] = false;
|
||||
m_sentClipboard[id] = false;
|
||||
}
|
||||
|
||||
void Client::grabClipboard(ClipboardID id) {
|
||||
void Client::grabClipboard(ClipboardID id)
|
||||
{
|
||||
m_screen->grabClipboard(id);
|
||||
m_ownClipboard[id] = false;
|
||||
m_sentClipboard[id] = false;
|
||||
}
|
||||
|
||||
void Client::setClipboardDirty(ClipboardID, bool) {
|
||||
void Client::setClipboardDirty(ClipboardID, bool)
|
||||
{
|
||||
assert(0 && "shouldn't be called");
|
||||
}
|
||||
|
||||
void Client::keyDown(
|
||||
KeyID id, KeyModifierMask mask, KeyButton button, const String &lang) {
|
||||
void Client::keyDown(KeyID id, KeyModifierMask mask, KeyButton button, const String &lang)
|
||||
{
|
||||
m_screen->keyDown(id, mask, button, lang);
|
||||
}
|
||||
|
||||
void Client::keyRepeat(
|
||||
KeyID id, KeyModifierMask mask, SInt32 count, KeyButton button,
|
||||
const String &lang) {
|
||||
void Client::keyRepeat(KeyID id, KeyModifierMask mask, SInt32 count, KeyButton button, const String &lang)
|
||||
{
|
||||
m_screen->keyRepeat(id, mask, count, button, lang);
|
||||
}
|
||||
|
||||
void Client::keyUp(KeyID id, KeyModifierMask mask, KeyButton button) {
|
||||
void Client::keyUp(KeyID id, KeyModifierMask mask, KeyButton button)
|
||||
{
|
||||
m_screen->keyUp(id, mask, button);
|
||||
}
|
||||
|
||||
void Client::mouseDown(ButtonID id) { m_screen->mouseDown(id); }
|
||||
void Client::mouseDown(ButtonID id)
|
||||
{
|
||||
m_screen->mouseDown(id);
|
||||
}
|
||||
|
||||
void Client::mouseUp(ButtonID id) { m_screen->mouseUp(id); }
|
||||
void Client::mouseUp(ButtonID id)
|
||||
{
|
||||
m_screen->mouseUp(id);
|
||||
}
|
||||
|
||||
void Client::mouseMove(SInt32 x, SInt32 y) { m_screen->mouseMove(x, y); }
|
||||
void Client::mouseMove(SInt32 x, SInt32 y)
|
||||
{
|
||||
m_screen->mouseMove(x, y);
|
||||
}
|
||||
|
||||
void Client::mouseRelativeMove(SInt32 dx, SInt32 dy) {
|
||||
void Client::mouseRelativeMove(SInt32 dx, SInt32 dy)
|
||||
{
|
||||
m_screen->mouseRelativeMove(dx, dy);
|
||||
}
|
||||
|
||||
void Client::mouseWheel(SInt32 xDelta, SInt32 yDelta) {
|
||||
void Client::mouseWheel(SInt32 xDelta, SInt32 yDelta)
|
||||
{
|
||||
m_screen->mouseWheel(xDelta, yDelta);
|
||||
}
|
||||
|
||||
void Client::screensaver(bool activate) { m_screen->screensaver(activate); }
|
||||
void Client::screensaver(bool activate)
|
||||
{
|
||||
m_screen->screensaver(activate);
|
||||
}
|
||||
|
||||
void Client::resetOptions() { m_screen->resetOptions(); }
|
||||
void Client::resetOptions()
|
||||
{
|
||||
m_screen->resetOptions();
|
||||
}
|
||||
|
||||
void Client::setOptions(const OptionsList &options) {
|
||||
for (OptionsList::const_iterator index = options.begin();
|
||||
index != options.end(); ++index) {
|
||||
void Client::setOptions(const OptionsList &options)
|
||||
{
|
||||
for (OptionsList::const_iterator index = options.begin(); index != options.end(); ++index) {
|
||||
const OptionID id = *index;
|
||||
if (id == kOptionClipboardSharing) {
|
||||
index++;
|
||||
@ -324,9 +362,13 @@ void Client::setOptions(const OptionsList &options) {
|
||||
m_screen->setOptions(options);
|
||||
}
|
||||
|
||||
String Client::getName() const { return m_name; }
|
||||
String Client::getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void Client::sendClipboard(ClipboardID id) {
|
||||
void Client::sendClipboard(ClipboardID id)
|
||||
{
|
||||
// note -- m_mutex must be locked on entry
|
||||
assert(m_screen != NULL);
|
||||
assert(m_server != NULL);
|
||||
@ -349,7 +391,8 @@ void Client::sendClipboard(ClipboardID id) {
|
||||
LOG(
|
||||
(CLOG_NOTE "skipping clipboard transfer because the clipboard"
|
||||
" contents exceeds the %i MB size limit set by the server",
|
||||
m_maximumClipboardSize / 1024));
|
||||
m_maximumClipboardSize / 1024)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -364,97 +407,110 @@ void Client::sendClipboard(ClipboardID id) {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::sendEvent(Event::Type type, void *data) {
|
||||
void Client::sendEvent(Event::Type type, void *data)
|
||||
{
|
||||
m_events->addEvent(Event(type, getEventTarget(), data));
|
||||
}
|
||||
|
||||
void Client::sendConnectionFailedEvent(const char *msg) {
|
||||
void Client::sendConnectionFailedEvent(const char *msg)
|
||||
{
|
||||
FailInfo *info = new FailInfo(msg);
|
||||
info->m_retry = true;
|
||||
Event event(
|
||||
m_events->forClient().connectionFailed(), getEventTarget(), info,
|
||||
Event::kDontFreeData);
|
||||
Event event(m_events->forClient().connectionFailed(), getEventTarget(), info, Event::kDontFreeData);
|
||||
m_events->addEvent(event);
|
||||
}
|
||||
|
||||
void Client::sendFileChunk(const void *data) {
|
||||
void Client::sendFileChunk(const void *data)
|
||||
{
|
||||
FileChunk *chunk = static_cast<FileChunk *>(const_cast<void *>(data));
|
||||
LOG((CLOG_DEBUG1 "send file chunk"));
|
||||
assert(m_server != NULL);
|
||||
|
||||
// relay
|
||||
m_server->fileChunkSending(
|
||||
chunk->m_chunk[0], &chunk->m_chunk[1], chunk->m_dataSize);
|
||||
m_server->fileChunkSending(chunk->m_chunk[0], &chunk->m_chunk[1], chunk->m_dataSize);
|
||||
}
|
||||
|
||||
void Client::setupConnecting() {
|
||||
void Client::setupConnecting()
|
||||
{
|
||||
assert(m_stream != NULL);
|
||||
|
||||
if (m_args.m_enableCrypto) {
|
||||
m_events->adoptHandler(
|
||||
m_events->forIDataSocket().secureConnected(),
|
||||
m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnected));
|
||||
m_events->forIDataSocket().secureConnected(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnected)
|
||||
);
|
||||
} else {
|
||||
m_events->adoptHandler(
|
||||
m_events->forIDataSocket().connected(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnected));
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnected)
|
||||
);
|
||||
}
|
||||
|
||||
m_events->adoptHandler(
|
||||
m_events->forIDataSocket().connectionFailed(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnectionFailed));
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnectionFailed)
|
||||
);
|
||||
}
|
||||
|
||||
void Client::setupConnection() {
|
||||
void Client::setupConnection()
|
||||
{
|
||||
assert(m_stream != NULL);
|
||||
|
||||
m_events->adoptHandler(
|
||||
m_events->forISocket().disconnected(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected));
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
m_events->forIStream().inputReady(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleHello));
|
||||
new TMethodEventJob<Client>(this, &Client::handleHello)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
m_events->forIStream().outputError(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleOutputError));
|
||||
new TMethodEventJob<Client>(this, &Client::handleOutputError)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
m_events->forIStream().inputShutdown(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected));
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
m_events->forIStream().outputShutdown(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected));
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
||||
);
|
||||
|
||||
m_events->adoptHandler(
|
||||
m_events->forISocket().stopRetry(), m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleStopRetry));
|
||||
new TMethodEventJob<Client>(this, &Client::handleStopRetry)
|
||||
);
|
||||
}
|
||||
|
||||
void Client::setupScreen() {
|
||||
void Client::setupScreen()
|
||||
{
|
||||
assert(m_server == NULL);
|
||||
|
||||
m_ready = false;
|
||||
m_server = new ServerProxy(this, m_stream, m_events);
|
||||
m_events->adoptHandler(
|
||||
m_events->forIScreen().shapeChanged(), getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleShapeChanged));
|
||||
new TMethodEventJob<Client>(this, &Client::handleShapeChanged)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
m_events->forClipboard().clipboardGrabbed(), getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleClipboardGrabbed));
|
||||
new TMethodEventJob<Client>(this, &Client::handleClipboardGrabbed)
|
||||
);
|
||||
}
|
||||
|
||||
void Client::setupTimer() {
|
||||
void Client::setupTimer()
|
||||
{
|
||||
assert(m_timer == NULL);
|
||||
|
||||
if (!m_args.m_hostMode) {
|
||||
m_timer = m_events->newOneShotTimer(2.0, NULL);
|
||||
m_events->adoptHandler(
|
||||
Event::kTimer, m_timer,
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnectTimeout));
|
||||
m_events->adoptHandler(Event::kTimer, m_timer, new TMethodEventJob<Client>(this, &Client::handleConnectTimeout));
|
||||
}
|
||||
}
|
||||
|
||||
void Client::cleanup() {
|
||||
void Client::cleanup()
|
||||
{
|
||||
m_connectOnResume = false;
|
||||
cleanupTimer();
|
||||
cleanupScreen();
|
||||
@ -462,50 +518,43 @@ void Client::cleanup() {
|
||||
cleanupConnection();
|
||||
}
|
||||
|
||||
void Client::cleanupConnecting() {
|
||||
void Client::cleanupConnecting()
|
||||
{
|
||||
if (m_stream != NULL) {
|
||||
m_events->removeHandler(
|
||||
m_events->forIDataSocket().connected(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(
|
||||
m_events->forIDataSocket().connectionFailed(),
|
||||
m_stream->getEventTarget());
|
||||
m_events->removeHandler(m_events->forIDataSocket().connected(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(m_events->forIDataSocket().connectionFailed(), m_stream->getEventTarget());
|
||||
}
|
||||
}
|
||||
|
||||
void Client::cleanupConnection() {
|
||||
void Client::cleanupConnection()
|
||||
{
|
||||
if (m_stream != NULL) {
|
||||
m_events->removeHandler(
|
||||
m_events->forIStream().inputReady(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(
|
||||
m_events->forIStream().outputError(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(
|
||||
m_events->forIStream().inputShutdown(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(
|
||||
m_events->forIStream().outputShutdown(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(
|
||||
m_events->forISocket().disconnected(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(
|
||||
m_events->forISocket().stopRetry(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(m_events->forIStream().inputReady(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(m_events->forIStream().outputError(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(m_events->forIStream().inputShutdown(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(m_events->forIStream().outputShutdown(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(m_events->forISocket().disconnected(), m_stream->getEventTarget());
|
||||
m_events->removeHandler(m_events->forISocket().stopRetry(), m_stream->getEventTarget());
|
||||
cleanupStream();
|
||||
}
|
||||
}
|
||||
|
||||
void Client::cleanupScreen() {
|
||||
void Client::cleanupScreen()
|
||||
{
|
||||
if (m_server != NULL) {
|
||||
if (m_ready) {
|
||||
m_screen->disable();
|
||||
m_ready = false;
|
||||
}
|
||||
m_events->removeHandler(
|
||||
m_events->forIScreen().shapeChanged(), getEventTarget());
|
||||
m_events->removeHandler(
|
||||
m_events->forClipboard().clipboardGrabbed(), getEventTarget());
|
||||
m_events->removeHandler(m_events->forIScreen().shapeChanged(), getEventTarget());
|
||||
m_events->removeHandler(m_events->forClipboard().clipboardGrabbed(), getEventTarget());
|
||||
delete m_server;
|
||||
m_server = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Client::cleanupTimer() {
|
||||
void Client::cleanupTimer()
|
||||
{
|
||||
if (m_timer != NULL) {
|
||||
m_events->removeHandler(Event::kTimer, m_timer);
|
||||
m_events->deleteTimer(m_timer);
|
||||
@ -513,12 +562,14 @@ void Client::cleanupTimer() {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::cleanupStream() {
|
||||
void Client::cleanupStream()
|
||||
{
|
||||
delete m_stream;
|
||||
m_stream = NULL;
|
||||
}
|
||||
|
||||
void Client::handleConnected(const Event &, void *) {
|
||||
void Client::handleConnected(const Event &, void *)
|
||||
{
|
||||
LOG((CLOG_DEBUG1 "connected; wait for hello"));
|
||||
cleanupConnecting();
|
||||
setupConnection();
|
||||
@ -531,9 +582,9 @@ void Client::handleConnected(const Event &, void *) {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleConnectionFailed(const Event &event, void *) {
|
||||
IDataSocket::ConnectionFailedInfo *info =
|
||||
static_cast<IDataSocket::ConnectionFailedInfo *>(event.getData());
|
||||
void Client::handleConnectionFailed(const Event &event, void *)
|
||||
{
|
||||
IDataSocket::ConnectionFailedInfo *info = static_cast<IDataSocket::ConnectionFailedInfo *>(event.getData());
|
||||
|
||||
cleanupTimer();
|
||||
cleanupConnecting();
|
||||
@ -543,7 +594,8 @@ void Client::handleConnectionFailed(const Event &event, void *) {
|
||||
delete info;
|
||||
}
|
||||
|
||||
void Client::handleConnectTimeout(const Event &, void *) {
|
||||
void Client::handleConnectTimeout(const Event &, void *)
|
||||
{
|
||||
cleanupTimer();
|
||||
cleanupConnecting();
|
||||
cleanupConnection();
|
||||
@ -552,7 +604,8 @@ void Client::handleConnectTimeout(const Event &, void *) {
|
||||
sendConnectionFailedEvent("Timed out");
|
||||
}
|
||||
|
||||
void Client::handleOutputError(const Event &, void *) {
|
||||
void Client::handleOutputError(const Event &, void *)
|
||||
{
|
||||
cleanupTimer();
|
||||
cleanupScreen();
|
||||
cleanupConnection();
|
||||
@ -560,7 +613,8 @@ void Client::handleOutputError(const Event &, void *) {
|
||||
sendEvent(m_events->forClient().disconnected(), NULL);
|
||||
}
|
||||
|
||||
void Client::handleDisconnected(const Event &, void *) {
|
||||
void Client::handleDisconnected(const Event &, void *)
|
||||
{
|
||||
cleanupTimer();
|
||||
cleanupScreen();
|
||||
cleanupConnection();
|
||||
@ -568,18 +622,19 @@ void Client::handleDisconnected(const Event &, void *) {
|
||||
sendEvent(m_events->forClient().disconnected(), NULL);
|
||||
}
|
||||
|
||||
void Client::handleShapeChanged(const Event &, void *) {
|
||||
void Client::handleShapeChanged(const Event &, void *)
|
||||
{
|
||||
LOG((CLOG_DEBUG "resolution changed"));
|
||||
m_server->onInfoChanged();
|
||||
}
|
||||
|
||||
void Client::handleClipboardGrabbed(const Event &event, void *) {
|
||||
void Client::handleClipboardGrabbed(const Event &event, void *)
|
||||
{
|
||||
if (!m_enableClipboard || (m_maximumClipboardSize == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const IScreen::ClipboardInfo *info =
|
||||
static_cast<const IScreen::ClipboardInfo *>(event.getData());
|
||||
const IScreen::ClipboardInfo *info = static_cast<const IScreen::ClipboardInfo *>(event.getData());
|
||||
|
||||
// grab ownership
|
||||
m_server->onGrabClipboard(info->m_id);
|
||||
@ -596,7 +651,8 @@ void Client::handleClipboardGrabbed(const Event &event, void *) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Client::isCompatible(int major, int minor) const {
|
||||
bool Client::isCompatible(int major, int minor) const
|
||||
{
|
||||
const std::map<int, std::set<int>> compatibleTable{
|
||||
{6, {7, 8}}, // 1.6 is compatible with 1.7 and 1.8
|
||||
{7, {8}} // 1.7 is compatible with 1.8
|
||||
@ -608,19 +664,18 @@ bool Client::isCompatible(int major, int minor) const {
|
||||
auto versions = compatibleTable.find(minor);
|
||||
if (versions != compatibleTable.end()) {
|
||||
auto compatibleVersions = versions->second;
|
||||
isCompatible = compatibleVersions.find(kProtocolMinorVersion) !=
|
||||
compatibleVersions.end();
|
||||
isCompatible = compatibleVersions.find(kProtocolMinorVersion) != compatibleVersions.end();
|
||||
}
|
||||
}
|
||||
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
void Client::handleHello(const Event &, void *) {
|
||||
void Client::handleHello(const Event &, void *)
|
||||
{
|
||||
SInt16 major, minor;
|
||||
if (!ProtocolUtil::readf(m_stream, kMsgHello, &major, &minor)) {
|
||||
sendConnectionFailedEvent(
|
||||
"Protocol error from server, check encryption settings");
|
||||
sendConnectionFailedEvent("Protocol error from server, check encryption settings");
|
||||
cleanupTimer();
|
||||
cleanupConnection();
|
||||
return;
|
||||
@ -636,9 +691,7 @@ void Client::handleHello(const Event &, void *) {
|
||||
// server
|
||||
LOG((CLOG_NOTE "downgrading protocol version for server"));
|
||||
helloBackMinor = minor;
|
||||
} else if (
|
||||
major < kProtocolMajorVersion ||
|
||||
(major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) {
|
||||
} else if (major < kProtocolMajorVersion || (major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) {
|
||||
sendConnectionFailedEvent(XIncompatibleClient(major, minor).what());
|
||||
cleanupTimer();
|
||||
cleanupConnection();
|
||||
@ -647,8 +700,7 @@ void Client::handleHello(const Event &, void *) {
|
||||
|
||||
// say hello back
|
||||
LOG((CLOG_DEBUG1 "say hello version %d.%d", helloBackMajor, helloBackMinor));
|
||||
ProtocolUtil::writef(
|
||||
m_stream, kMsgHelloBack, helloBackMajor, helloBackMinor, &m_name);
|
||||
ProtocolUtil::writef(m_stream, kMsgHelloBack, helloBackMajor, helloBackMinor, &m_name);
|
||||
|
||||
// now connected but waiting to complete handshake
|
||||
setupScreen();
|
||||
@ -658,12 +710,12 @@ void Client::handleHello(const Event &, void *) {
|
||||
// receive another event for already pending messages so we fake
|
||||
// one.
|
||||
if (m_stream->isReady()) {
|
||||
m_events->addEvent(
|
||||
Event(m_events->forIStream().inputReady(), m_stream->getEventTarget()));
|
||||
m_events->addEvent(Event(m_events->forIStream().inputReady(), m_stream->getEventTarget()));
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleSuspend(const Event &, void *) {
|
||||
void Client::handleSuspend(const Event &, void *)
|
||||
{
|
||||
if (!m_suspended) {
|
||||
LOG((CLOG_INFO "suspend"));
|
||||
m_suspended = true;
|
||||
@ -673,7 +725,8 @@ void Client::handleSuspend(const Event &, void *) {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleResume(const Event &, void *) {
|
||||
void Client::handleResume(const Event &, void *)
|
||||
{
|
||||
if (m_suspended) {
|
||||
LOG((CLOG_INFO "resume"));
|
||||
m_suspended = false;
|
||||
@ -684,27 +737,29 @@ void Client::handleResume(const Event &, void *) {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleFileChunkSending(const Event &event, void *) {
|
||||
void Client::handleFileChunkSending(const Event &event, void *)
|
||||
{
|
||||
sendFileChunk(event.getDataObject());
|
||||
}
|
||||
|
||||
void Client::handleFileRecieveCompleted(const Event &event, void *) {
|
||||
void Client::handleFileRecieveCompleted(const Event &event, void *)
|
||||
{
|
||||
onFileRecieveCompleted();
|
||||
}
|
||||
|
||||
void Client::onFileRecieveCompleted() {
|
||||
void Client::onFileRecieveCompleted()
|
||||
{
|
||||
if (isReceivedFileSizeValid()) {
|
||||
auto method = new TMethodJob<Client>(this, &Client::writeToDropDirThread);
|
||||
m_writeToDropDirThread.reset(new Thread(method));
|
||||
}
|
||||
}
|
||||
|
||||
void Client::bindNetworkInterface(IDataSocket *socket) const {
|
||||
void Client::bindNetworkInterface(IDataSocket *socket) const
|
||||
{
|
||||
try {
|
||||
if (!m_args.m_deskflowAddress.empty()) {
|
||||
LOG(
|
||||
(CLOG_DEBUG1 "bind to network interface: %s",
|
||||
m_args.m_deskflowAddress.c_str()));
|
||||
LOG((CLOG_DEBUG1 "bind to network interface: %s", m_args.m_deskflowAddress.c_str()));
|
||||
|
||||
NetworkAddress bindAddress(m_args.m_deskflowAddress);
|
||||
bindAddress.resolve();
|
||||
@ -713,27 +768,28 @@ void Client::bindNetworkInterface(IDataSocket *socket) const {
|
||||
}
|
||||
} catch (XBase &e) {
|
||||
LOG((CLOG_WARN "%s", e.what()));
|
||||
LOG((CLOG_WARN
|
||||
"operating system will select network interface automatically"));
|
||||
LOG((CLOG_WARN "operating system will select network interface automatically"));
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleStopRetry(const Event &, void *) {
|
||||
void Client::handleStopRetry(const Event &, void *)
|
||||
{
|
||||
m_args.m_restartable = false;
|
||||
}
|
||||
|
||||
void Client::writeToDropDirThread(void *) {
|
||||
void Client::writeToDropDirThread(void *)
|
||||
{
|
||||
LOG((CLOG_DEBUG "starting write to drop dir thread"));
|
||||
|
||||
while (m_screen->isFakeDraggingStarted()) {
|
||||
ARCH->sleep(.1f);
|
||||
}
|
||||
|
||||
DropHelper::writeToDir(
|
||||
m_screen->getDropTarget(), m_dragFileList, m_receivedFileData);
|
||||
DropHelper::writeToDir(m_screen->getDropTarget(), m_dragFileList, m_receivedFileData);
|
||||
}
|
||||
|
||||
void Client::dragInfoReceived(UInt32 fileNum, String data) {
|
||||
void Client::dragInfoReceived(UInt32 fileNum, String data)
|
||||
{
|
||||
// TODO: fix duplicate function from CServer
|
||||
if (!m_args.m_enableDragDrop) {
|
||||
LOG((CLOG_DEBUG "drag drop not enabled, ignoring drag info."));
|
||||
@ -745,11 +801,13 @@ void Client::dragInfoReceived(UInt32 fileNum, String data) {
|
||||
m_screen->startDraggingFiles(m_dragFileList);
|
||||
}
|
||||
|
||||
bool Client::isReceivedFileSizeValid() {
|
||||
bool Client::isReceivedFileSizeValid()
|
||||
{
|
||||
return m_expectedFileSize == m_receivedFileData.size();
|
||||
}
|
||||
|
||||
void Client::sendFileToServer(const char *filename) {
|
||||
void Client::sendFileToServer(const char *filename)
|
||||
{
|
||||
if (m_sendFileThread) {
|
||||
StreamChunker::interruptFile();
|
||||
}
|
||||
@ -759,7 +817,8 @@ void Client::sendFileToServer(const char *filename) {
|
||||
m_sendFileThread.reset(new Thread(method));
|
||||
}
|
||||
|
||||
void Client::sendFileThread(void *filename) {
|
||||
void Client::sendFileThread(void *filename)
|
||||
{
|
||||
try {
|
||||
char *name = static_cast<char *>(filename);
|
||||
StreamChunker::sendFile(name, m_events, this);
|
||||
@ -770,6 +829,7 @@ void Client::sendFileThread(void *filename) {
|
||||
m_sendFileThread.reset(nullptr);
|
||||
}
|
||||
|
||||
void Client::sendDragInfo(UInt32 fileCount, String &info, size_t size) {
|
||||
void Client::sendDragInfo(UInt32 fileCount, String &info, size_t size)
|
||||
{
|
||||
m_server->sendDragInfo(fileCount, info.c_str(), size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user