deskflow/src/lib/server/ClientProxy1_3.cpp

130 lines
3.2 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Bolton Software Ltd.
* Copyright (C) 2006 Chris Schoeneman
2012-06-10 16:50:54 +00:00
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "server/ClientProxy1_3.h"
#include "synergy/ProtocolUtil.h"
#include "base/Log.h"
#include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
2012-06-10 16:50:54 +00:00
#include <cstring>
#include <memory>
//
2014-11-11 13:51:47 +00:00
// ClientProxy1_3
2012-06-10 16:50:54 +00:00
//
2014-11-11 13:51:47 +00:00
ClientProxy1_3::ClientProxy1_3(const String& name, synergy::IStream* stream, IEventQueue* events) :
ClientProxy1_2(name, stream, events),
2012-06-10 16:50:54 +00:00
m_keepAliveRate(kKeepAliveRate),
2014-02-25 15:03:43 +00:00
m_keepAliveTimer(NULL),
m_events(events)
2012-06-10 16:50:54 +00:00
{
setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
}
2014-11-11 13:51:47 +00:00
ClientProxy1_3::~ClientProxy1_3()
2012-06-10 16:50:54 +00:00
{
// cannot do this in superclass or our override wouldn't get called
removeHeartbeatTimer();
}
void
2014-11-11 13:51:47 +00:00
ClientProxy1_3::mouseWheel(SInt32 xDelta, SInt32 yDelta)
2012-06-10 16:50:54 +00:00
{
LOG((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d,%+d", getName().c_str(), xDelta, yDelta));
2014-11-11 13:51:47 +00:00
ProtocolUtil::writef(getStream(), kMsgDMouseWheel, xDelta, yDelta);
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
ClientProxy1_3::parseMessage(const UInt8* code)
2012-06-10 16:50:54 +00:00
{
// process message
if (memcmp(code, kMsgCKeepAlive, 4) == 0) {
// reset alarm
resetHeartbeatTimer();
return true;
}
else {
2014-11-11 13:51:47 +00:00
return ClientProxy1_2::parseMessage(code);
2012-06-10 16:50:54 +00:00
}
}
void
2014-11-11 13:51:47 +00:00
ClientProxy1_3::resetHeartbeatRate()
2012-06-10 16:50:54 +00:00
{
setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
}
void
2014-11-11 13:51:47 +00:00
ClientProxy1_3::setHeartbeatRate(double rate, double)
2012-06-10 16:50:54 +00:00
{
m_keepAliveRate = rate;
2014-11-11 13:51:47 +00:00
ClientProxy1_2::setHeartbeatRate(rate, rate * kKeepAlivesUntilDeath);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
ClientProxy1_3::resetHeartbeatTimer()
2012-06-10 16:50:54 +00:00
{
// reset the alarm but not the keep alive timer
2014-11-11 13:51:47 +00:00
ClientProxy1_2::removeHeartbeatTimer();
ClientProxy1_2::addHeartbeatTimer();
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
ClientProxy1_3::addHeartbeatTimer()
2012-06-10 16:50:54 +00:00
{
// create and install a timer to periodically send keep alives
if (m_keepAliveRate > 0.0) {
m_keepAliveTimer = m_events->newTimer(m_keepAliveRate, NULL);
2014-11-11 13:51:47 +00:00
m_events->adoptHandler(Event::kTimer, m_keepAliveTimer,
new TMethodEventJob<ClientProxy1_3>(this,
&ClientProxy1_3::handleKeepAlive, NULL));
2012-06-10 16:50:54 +00:00
}
// superclass does the alarm
2014-11-11 13:51:47 +00:00
ClientProxy1_2::addHeartbeatTimer();
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
ClientProxy1_3::removeHeartbeatTimer()
2012-06-10 16:50:54 +00:00
{
// remove the timer that sends keep alives periodically
if (m_keepAliveTimer != NULL) {
2014-11-11 13:51:47 +00:00
m_events->removeHandler(Event::kTimer, m_keepAliveTimer);
m_events->deleteTimer(m_keepAliveTimer);
2012-06-10 16:50:54 +00:00
m_keepAliveTimer = NULL;
}
// superclass does the alarm
2014-11-11 13:51:47 +00:00
ClientProxy1_2::removeHeartbeatTimer();
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
ClientProxy1_3::handleKeepAlive(const Event&, void*)
{
keepAlive();
}
void
2014-11-11 13:51:47 +00:00
ClientProxy1_3::keepAlive()
2012-06-10 16:50:54 +00:00
{
2014-11-11 13:51:47 +00:00
ProtocolUtil::writef(getStream(), kMsgCKeepAlive);
2012-06-10 16:50:54 +00:00
}