Diffstat (limited to 'noncore/comm/keypebble/krfbconnection.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/comm/keypebble/krfbconnection.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/noncore/comm/keypebble/krfbconnection.cpp b/noncore/comm/keypebble/krfbconnection.cpp index b447046..33e0563 100644 --- a/noncore/comm/keypebble/krfbconnection.cpp +++ b/noncore/comm/keypebble/krfbconnection.cpp | |||
@@ -1,18 +1,25 @@ | |||
1 | #include <assert.h> | ||
2 | #include <qsocket.h> | ||
3 | #include <qtimer.h> | ||
4 | #include <string.h> | ||
5 | |||
6 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
7 | #include "krfblogin.h" | 2 | #include "krfblogin.h" |
8 | #include "krfbdecoder.h" | 3 | #include "krfbdecoder.h" |
9 | #include "krfbbuffer.h" | 4 | #include "krfbbuffer.h" |
10 | 5 | ||
6 | /* OPIE */ | ||
7 | #include <opie2/odebug.h> | ||
8 | using namespace Opie::Core; | ||
9 | |||
10 | /* QT */ | ||
11 | #include <qsocket.h> | ||
12 | #include <qtimer.h> | ||
13 | |||
14 | /* STD */ | ||
15 | #include <assert.h> | ||
16 | #include <string.h> | ||
17 | |||
11 | KRFBConnection::KRFBConnection( QObject *parent ) | 18 | KRFBConnection::KRFBConnection( QObject *parent ) |
12 | : QObject( parent, "KRFBConnection" ) | 19 | : QObject( parent, "KRFBConnection" ) |
13 | { | 20 | { |
14 | portBase_ = 5900; | 21 | portBase_ = 5900; |
15 | currentState_ = Disconnected; | 22 | currentState_ = Disconnected; |
16 | sock = 0; | 23 | sock = 0; |
17 | minData_ = 0; | 24 | minData_ = 0; |
18 | options_ = new KRFBServer(); | 25 | options_ = new KRFBServer(); |
@@ -38,25 +45,25 @@ void KRFBConnection::connectTo( KRFBServer server) | |||
38 | 45 | ||
39 | sock = new QSocket( this, "rfbSocket" ); | 46 | sock = new QSocket( this, "rfbSocket" ); |
40 | CHECK_PTR( sock ); | 47 | CHECK_PTR( sock ); |
41 | 48 | ||
42 | // Connect to something to notice connection or error | 49 | // Connect to something to notice connection or error |
43 | connect( sock, SIGNAL( error(int) ), SLOT( gotSocketError(int) ) ); | 50 | connect( sock, SIGNAL( error(int) ), SLOT( gotSocketError(int) ) ); |
44 | connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) ); | 51 | connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) ); |
45 | 52 | ||
46 | qWarning( "Connecting..." ); | 53 | owarn << "Connecting..." << oendl; |
47 | 54 | ||
48 | currentState_ = Connecting; | 55 | currentState_ = Connecting; |
49 | sock->connectToHost( options_->hostname.latin1(), portBase_ + options_->display ); | 56 | sock->connectToHost( options_->hostname.latin1(), portBase_ + options_->display ); |
50 | } | 57 | } |
51 | 58 | ||
52 | void KRFBConnection::disconnect() | 59 | void KRFBConnection::disconnect() |
53 | { | 60 | { |
54 | qWarning( "Disconnecting from server" ); | 61 | owarn << "Disconnecting from server" << oendl; |
55 | 62 | ||
56 | if ( ( currentState_ != Disconnected ) | 63 | if ( ( currentState_ != Disconnected ) |
57 | && ( currentState_ != Disconnecting ) | 64 | && ( currentState_ != Disconnecting ) |
58 | && sock ) { | 65 | && sock ) { |
59 | currentState_ = Disconnecting; | 66 | currentState_ = Disconnecting; |
60 | 67 | ||
61 | connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); | 68 | connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); |
62 | sock->close(); | 69 | sock->close(); |
@@ -77,28 +84,28 @@ void KRFBConnection::disconnectDone() | |||
77 | delete buffer_; | 84 | delete buffer_; |
78 | emit disconnected(); | 85 | emit disconnected(); |
79 | } | 86 | } |
80 | 87 | ||
81 | void KRFBConnection::gotSocketConnection() | 88 | void KRFBConnection::gotSocketConnection() |
82 | { | 89 | { |
83 | currentState_ = LoggingIn; | 90 | currentState_ = LoggingIn; |
84 | 91 | ||
85 | qWarning( "Connected, logging in..." ); | 92 | owarn << "Connected, logging in..." << oendl; |
86 | 93 | ||
87 | static QString statusMsg = tr( "Connected" ); | 94 | static QString statusMsg = tr( "Connected" ); |
88 | emit statusChanged( statusMsg ); | 95 | emit statusChanged( statusMsg ); |
89 | 96 | ||
90 | // Do some login stuff | 97 | // Do some login stuff |
91 | login = new KRFBLogin( this ); | 98 | login = new KRFBLogin( this ); |
92 | } | 99 | } |
93 | 100 | ||
94 | void KRFBConnection::gotRFBConnection() | 101 | void KRFBConnection::gotRFBConnection() |
95 | { | 102 | { |
96 | qWarning( "Logged into server" ); | 103 | owarn << "Logged into server" << oendl; |
97 | 104 | ||
98 | currentState_ = Connected; | 105 | currentState_ = Connected; |
99 | emit connected(); | 106 | emit connected(); |
100 | 107 | ||
101 | // Create the decoder and start doing stuff | 108 | // Create the decoder and start doing stuff |
102 | decoder_ = new KRFBDecoder( this ); | 109 | decoder_ = new KRFBDecoder( this ); |
103 | CHECK_PTR( decoder_ ); | 110 | CHECK_PTR( decoder_ ); |
104 | 111 | ||
@@ -117,17 +124,17 @@ void KRFBConnection::gotRFBConnection() | |||
117 | updater->start( options_->updateRate ); | 124 | updater->start( options_->updateRate ); |
118 | } | 125 | } |
119 | 126 | ||
120 | void KRFBConnection::gotSocketError( int err ) | 127 | void KRFBConnection::gotSocketError( int err ) |
121 | { | 128 | { |
122 | currentState_ = Error; | 129 | currentState_ = Error; |
123 | 130 | ||
124 | // Do some error handling stuff | 131 | // Do some error handling stuff |
125 | qWarning( "KRFBConnection: Socket error %d", err ); | 132 | owarn << "KRFBConnection: Socket error " << err << "" << oendl; |
126 | 133 | ||
127 | static QString refused = tr( "Connection Refused" ); | 134 | static QString refused = tr( "Connection Refused" ); |
128 | static QString host = tr( "Host not found" ); | 135 | static QString host = tr( "Host not found" ); |
129 | static QString read = tr( "Read Error: QSocket reported an error reading\n" | 136 | static QString read = tr( "Read Error: QSocket reported an error reading\n" |
130 | "data, the remote host has probably dropped the\n" | 137 | "data, the remote host has probably dropped the\n" |
131 | "connection." ); | 138 | "connection." ); |
132 | static QString confused = tr( "QSocket reported an invalid error code" ); | 139 | static QString confused = tr( "QSocket reported an invalid error code" ); |
133 | 140 | ||
@@ -167,21 +174,21 @@ void KRFBConnection::gotMoreData() | |||
167 | 174 | ||
168 | void KRFBConnection::waitForData( unsigned int sz ) | 175 | void KRFBConnection::waitForData( unsigned int sz ) |
169 | { | 176 | { |
170 | assert( minData_ == 0 ); | 177 | assert( minData_ == 0 ); |
171 | assert( sz > 0 ); | 178 | assert( sz > 0 ); |
172 | assert( currentState_ != Error ); | 179 | assert( currentState_ != Error ); |
173 | 180 | ||
174 | if ( sock->size() >= sz ) { | 181 | if ( sock->size() >= sz ) { |
175 | // qWarning( "No need to wait for data" ); | 182 | // owarn << "No need to wait for data" << oendl; |
176 | emit gotEnoughData(); | 183 | emit gotEnoughData(); |
177 | } | 184 | } |
178 | else { | 185 | else { |
179 | // qWarning( "Waiting for %u bytes", sz ); | 186 | // owarn << "Waiting for " << sz << " bytes" << oendl; |
180 | minData_ = sz; | 187 | minData_ = sz; |
181 | connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); | 188 | connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); |
182 | } | 189 | } |
183 | } | 190 | } |
184 | 191 | ||
185 | int KRFBConnection::read( void *buf, int sz ) | 192 | int KRFBConnection::read( void *buf, int sz ) |
186 | { | 193 | { |
187 | return sock->readBlock( (char *) buf, sz ); | 194 | return sock->readBlock( (char *) buf, sz ); |