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 |
|
---|
25 | CClientProxy1_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 |
|
---|
33 | CClientProxy1_3::~CClientProxy1_3()
|
---|
34 | {
|
---|
35 | // cannot do this in superclass or our override wouldn't get called
|
---|
36 | removeHeartbeatTimer();
|
---|
37 | }
|
---|
38 |
|
---|
39 | void
|
---|
40 | CClientProxy1_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 |
|
---|
46 | bool
|
---|
47 | CClientProxy1_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 |
|
---|
60 | void
|
---|
61 | CClientProxy1_3::resetHeartbeatRate()
|
---|
62 | {
|
---|
63 | setHeartbeatRate(kKeepAliveRate, kKeepAliveRate * kKeepAlivesUntilDeath);
|
---|
64 | }
|
---|
65 |
|
---|
66 | void
|
---|
67 | CClientProxy1_3::setHeartbeatRate(double rate, double)
|
---|
68 | {
|
---|
69 | m_keepAliveRate = rate;
|
---|
70 | CClientProxy1_2::setHeartbeatRate(rate, rate * kKeepAlivesUntilDeath);
|
---|
71 | }
|
---|
72 |
|
---|
73 | void
|
---|
74 | CClientProxy1_3::resetHeartbeatTimer()
|
---|
75 | {
|
---|
76 | // reset the alarm but not the keep alive timer
|
---|
77 | CClientProxy1_2::removeHeartbeatTimer();
|
---|
78 | CClientProxy1_2::addHeartbeatTimer();
|
---|
79 | }
|
---|
80 |
|
---|
81 | void
|
---|
82 | CClientProxy1_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 |
|
---|
96 | void
|
---|
97 | CClientProxy1_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 |
|
---|
110 | void
|
---|
111 | CClientProxy1_3::handleKeepAlive(const CEvent&, void*)
|
---|
112 | {
|
---|
113 | CProtocolUtil::writef(getStream(), kMsgCKeepAlive);
|
---|
114 | }
|
---|