• Main Page
  • Classes
  • Files
  • File List

CClientProxy1_3.cpp

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

Generated on Fri May 24 2013 00:00:03 for Synergy by  doxygen 1.7.1