source: trunk/synergy/lib/server/CClientProxy1_3.cpp

Last change on this file was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 2.9 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2006 Chris Schoeneman
4 *
5 * This package is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include "CClientProxy1_3.h"
16#include "CProtocolUtil.h"
17#include "CLog.h"
18#include "IEventQueue.h"
19#include "TMethodEventJob.h"
20
21//
22// CClientProxy1_3
23//
24
25CClientProxy1_3::CClientProxy1_3(const CString& name, IStream* stream) :
26 CClientProxy1_2(name, stream),
27 m_keepAliveRate(kKeepAliveRate),
28 m_keepAliveTimer(NULL)
29{
30 setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
31}
32
33CClientProxy1_3::~CClientProxy1_3()
34{
35 // cannot do this in superclass or our override wouldn't get called
36 removeHeartbeatTimer();
37}
38
39void
40CClientProxy1_3::mouseWheel(SInt32 xDelta, SInt32 yDelta)
41{
42 LOG((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d,%+d", getName().c_str(), xDelta, yDelta));
43 CProtocolUtil::writef(getStream(), kMsgDMouseWheel, xDelta, yDelta);
44}
45
46bool
47CClientProxy1_3::parseMessage(const UInt8* code)
48{
49 // process message
50 if (memcmp(code, kMsgCKeepAlive, 4) == 0) {
51 // reset alarm
52 resetHeartbeatTimer();
53 return true;
54 }
55 else {
56 return CClientProxy1_2::parseMessage(code);
57 }
58}
59
60void
61CClientProxy1_3::resetHeartbeatRate()
62{
63 setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
64}
65
66void
67CClientProxy1_3::setHeartbeatRate(double rate, double)
68{
69 m_keepAliveRate = rate;
70 CClientProxy1_2::setHeartbeatRate(rate, rate * kKeepAlivesUntilDeath);
71}
72
73void
74CClientProxy1_3::resetHeartbeatTimer()
75{
76 // reset the alarm but not the keep alive timer
77 CClientProxy1_2::removeHeartbeatTimer();
78 CClientProxy1_2::addHeartbeatTimer();
79}
80
81void
82CClientProxy1_3::addHeartbeatTimer()
83{
84 // create and install a timer to periodically send keep alives
85 if (m_keepAliveRate > 0.0) {
86 m_keepAliveTimer = EVENTQUEUE->newTimer(m_keepAliveRate, NULL);
87 EVENTQUEUE->adoptHandler(CEvent::kTimer, m_keepAliveTimer,
88 new TMethodEventJob<CClientProxy1_3>(this,
89 &CClientProxy1_3::handleKeepAlive, NULL));
90 }
91
92 // superclass does the alarm
93 CClientProxy1_2::addHeartbeatTimer();
94}
95
96void
97CClientProxy1_3::removeHeartbeatTimer()
98{
99 // remove the timer that sends keep alives periodically
100 if (m_keepAliveTimer != NULL) {
101 EVENTQUEUE->removeHandler(CEvent::kTimer, m_keepAliveTimer);
102 EVENTQUEUE->deleteTimer(m_keepAliveTimer);
103 m_keepAliveTimer = NULL;
104 }
105
106 // superclass does the alarm
107 CClientProxy1_2::removeHeartbeatTimer();
108}
109
110void
111CClientProxy1_3::handleKeepAlive(const CEvent&, void*)
112{
113 CProtocolUtil::writef(getStream(), kMsgCKeepAlive);
114}
Note: See TracBrowser for help on using the repository browser.