CClientProxy1_3.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2006 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "CClientProxy1_3.h"
00016 #include "CProtocolUtil.h"
00017 #include "CLog.h"
00018 #include "IEventQueue.h"
00019 #include "TMethodEventJob.h"
00020 #include <cstring>
00021 #include <memory>
00022 
00023 //
00024 // CClientProxy1_3
00025 //
00026 
00027 CClientProxy1_3::CClientProxy1_3(const CString& name, IStream* stream) :
00028     CClientProxy1_2(name, stream),
00029     m_keepAliveRate(kKeepAliveRate),
00030     m_keepAliveTimer(NULL)
00031 {
00032     setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
00033 }
00034 
00035 CClientProxy1_3::~CClientProxy1_3()
00036 {
00037     // cannot do this in superclass or our override wouldn't get called
00038     removeHeartbeatTimer();
00039 }
00040 
00041 void
00042 CClientProxy1_3::mouseWheel(SInt32 xDelta, SInt32 yDelta)
00043 {
00044     LOG((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d,%+d", getName().c_str(), xDelta, yDelta));
00045     CProtocolUtil::writef(getStream(), kMsgDMouseWheel, xDelta, yDelta);
00046 }
00047 
00048 bool
00049 CClientProxy1_3::parseMessage(const UInt8* code)
00050 {
00051     // process message
00052     if (memcmp(code, kMsgCKeepAlive, 4) == 0) {
00053         // reset alarm
00054         resetHeartbeatTimer();
00055         return true;
00056     }
00057     else {
00058         return CClientProxy1_2::parseMessage(code);
00059     }
00060 }
00061 
00062 void
00063 CClientProxy1_3::resetHeartbeatRate()
00064 {
00065     setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
00066 }
00067 
00068 void
00069 CClientProxy1_3::setHeartbeatRate(double rate, double)
00070 {
00071     m_keepAliveRate = rate;
00072     CClientProxy1_2::setHeartbeatRate(rate, rate * kKeepAlivesUntilDeath);
00073 }
00074 
00075 void
00076 CClientProxy1_3::resetHeartbeatTimer()
00077 {
00078     // reset the alarm but not the keep alive timer
00079     CClientProxy1_2::removeHeartbeatTimer();
00080     CClientProxy1_2::addHeartbeatTimer();
00081 }
00082 
00083 void
00084 CClientProxy1_3::addHeartbeatTimer()
00085 {
00086     // create and install a timer to periodically send keep alives
00087     if (m_keepAliveRate > 0.0) {
00088         m_keepAliveTimer = EVENTQUEUE->newTimer(m_keepAliveRate, NULL);
00089         EVENTQUEUE->adoptHandler(CEvent::kTimer, m_keepAliveTimer,
00090                             new TMethodEventJob<CClientProxy1_3>(this,
00091                                 &CClientProxy1_3::handleKeepAlive, NULL));
00092     }
00093 
00094     // superclass does the alarm
00095     CClientProxy1_2::addHeartbeatTimer();
00096 }
00097 
00098 void
00099 CClientProxy1_3::removeHeartbeatTimer()
00100 {
00101     // remove the timer that sends keep alives periodically
00102     if (m_keepAliveTimer != NULL) {
00103         EVENTQUEUE->removeHandler(CEvent::kTimer, m_keepAliveTimer);
00104         EVENTQUEUE->deleteTimer(m_keepAliveTimer);
00105         m_keepAliveTimer = NULL;
00106     }
00107 
00108     // superclass does the alarm
00109     CClientProxy1_2::removeHeartbeatTimer();
00110 }
00111 
00112 void
00113 CClientProxy1_3::handleKeepAlive(const CEvent&, void*)
00114 {
00115     CProtocolUtil::writef(getStream(), kMsgCKeepAlive);
00116 }

Generated on Fri Nov 6 00:18:44 2009 for synergy-plus by  doxygen 1.4.7