summaryrefslogtreecommitdiff
path: root/noncore/comm/keypebble/krfbconnection.cpp
Unidiff
Diffstat (limited to 'noncore/comm/keypebble/krfbconnection.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/comm/keypebble/krfbconnection.cpp31
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,22 +1,29 @@
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>
8using 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
11KRFBConnection::KRFBConnection( QObject *parent ) 18KRFBConnection::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();
19 updater = 0; 26 updater = 0;
20 decoder_ = 0; 27 decoder_ = 0;
21 buffer_ = 0; 28 buffer_ = 0;
22} 29}
@@ -34,33 +41,33 @@ void KRFBConnection::connectTo( KRFBServer server)
34 if ( currentState_ != Disconnected ) 41 if ( currentState_ != Disconnected )
35 disconnect(); 42 disconnect();
36 43
37 (*options_)=server; 44 (*options_)=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
52void KRFBConnection::disconnect() 59void 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();
63 70
64 if ( sock->state() != QSocket::Closing ) 71 if ( sock->state() != QSocket::Closing )
65 disconnectDone(); 72 disconnectDone();
66 } 73 }
@@ -73,36 +80,36 @@ void KRFBConnection::disconnectDone()
73 sock = 0; 80 sock = 0;
74 minData_ = 0; 81 minData_ = 0;
75 delete updater; 82 delete updater;
76 delete decoder_; 83 delete decoder_;
77 delete buffer_; 84 delete buffer_;
78 emit disconnected(); 85 emit disconnected();
79} 86}
80 87
81void KRFBConnection::gotSocketConnection() 88void 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
94void KRFBConnection::gotRFBConnection() 101void 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
105 buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" ); 112 buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" );
106 CHECK_PTR( buffer_ ); 113 CHECK_PTR( buffer_ );
107 decoder_->setBuffer( buffer_ ); 114 decoder_->setBuffer( buffer_ );
108 115
@@ -113,25 +120,25 @@ void KRFBConnection::gotRFBConnection()
113 decoder_->start(); 120 decoder_->start();
114 121
115 updater = new QTimer; 122 updater = new QTimer;
116 connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) ); 123 connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) );
117 updater->start( options_->updateRate ); 124 updater->start( options_->updateRate );
118} 125}
119 126
120void KRFBConnection::gotSocketError( int err ) 127void 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
134 QString msg; 141 QString msg;
135 switch ( err ) { 142 switch ( err ) {
136 case QSocket::ErrConnectionRefused: 143 case QSocket::ErrConnectionRefused:
137 msg = refused; 144 msg = refused;
@@ -163,29 +170,29 @@ void KRFBConnection::gotMoreData()
163 QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); 170 QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) );
164 emit gotEnoughData(); 171 emit gotEnoughData();
165 } 172 }
166} 173}
167 174
168void KRFBConnection::waitForData( unsigned int sz ) 175void 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
185int KRFBConnection::read( void *buf, int sz ) 192int KRFBConnection::read( void *buf, int sz )
186{ 193{
187 return sock->readBlock( (char *) buf, sz ); 194 return sock->readBlock( (char *) buf, sz );
188} 195}
189 196
190int KRFBConnection::write( void *buf, int sz ) 197int KRFBConnection::write( void *buf, int sz )
191{ 198{