Changeset 1357 in ntrip
- Timestamp:
- Dec 27, 2008, 4:03:38 PM (16 years ago)
- Location:
- trunk/BNC
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bnc.pro
r1345 r1357 2 2 # Switch to debug configuration 3 3 # ----------------------------- 4 CONFIG += release5 ###CONFIG += debug4 CONFIG -= release 5 CONFIG += debug 6 6 7 7 DEFINES += NO_RTCM3_MAIN -
trunk/BNC/bncsocket.cpp
r1356 r1357 32 32 app, SLOT(slotMessage(const QByteArray,bool))); 33 33 _socket = 0; 34 #if QT_VERSION >= 0x040400 35 _manager = 0; 36 _reply = 0; 37 #endif 34 _http = 0; 38 35 } 39 36 … … 41 38 //////////////////////////////////////////////////////////////////////////// 42 39 bncSocket::~bncSocket() { 40 cout << "~bncSocket" << endl; 43 41 delete _socket; 44 #if QT_VERSION >= 0x040400 45 _reply->deleteLater(); 46 _manager->deleteLater(); 47 #endif 42 delete _http; 48 43 } 49 44 … … 52 47 void bncSocket::connectToHost(const QString &hostName, quint16 port, 53 48 QIODevice::OpenMode mode) { 54 #if QT_VERSION >= 0x04040055 if (_reply) {56 }57 else58 #endif59 49 if (_socket) { 60 50 _socket->connectToHost(hostName, port, mode); … … 65 55 //////////////////////////////////////////////////////////////////////////// 66 56 bool bncSocket::waitForConnected(int msecs) { 67 #if QT_VERSION >= 0x04040068 if (_reply) {69 return true;70 }71 else72 #endif73 57 if (_socket) { 74 58 return _socket->waitForConnected(msecs); … … 82 66 //////////////////////////////////////////////////////////////////////////// 83 67 QAbstractSocket::SocketState bncSocket::state() const { 84 #if QT_VERSION >= 0x04040085 if (_reply) {86 return QAbstractSocket::ConnectedState;87 }88 else89 #endif90 68 if (_socket) { 91 69 return _socket->state(); … … 99 77 //////////////////////////////////////////////////////////////////////////// 100 78 void bncSocket::close() { 101 #if QT_VERSION >= 0x040400102 if (_reply) {103 _reply->close();104 }105 else106 #endif107 79 if (_socket) { 108 80 _socket->close(); … … 113 85 //////////////////////////////////////////////////////////////////////////// 114 86 qint64 bncSocket::bytesAvailable() const { 115 #if QT_VERSION >= 0x040400116 if (_reply) {117 return _reply->bytesAvailable();118 }119 else120 #endif121 87 if (_socket) { 122 88 return _socket->bytesAvailable(); … … 130 96 //////////////////////////////////////////////////////////////////////////// 131 97 bool bncSocket::canReadLine() const { 132 #if QT_VERSION >= 0x040400133 if (_reply) {134 return _reply->canReadLine();135 }136 else137 #endif138 98 if (_socket) { 139 99 return _socket->canReadLine(); … … 147 107 //////////////////////////////////////////////////////////////////////////// 148 108 QByteArray bncSocket::readLine(qint64 maxlen) { 149 #if QT_VERSION >= 0x040400150 if (_reply) {151 return _reply->readLine(maxlen);152 }153 else154 #endif155 109 if (_socket) { 156 110 return _socket->readLine(maxlen); … … 164 118 //////////////////////////////////////////////////////////////////////////// 165 119 bool bncSocket::waitForReadyRead(int msecs) { 166 #if QT_VERSION >= 0x040400167 if (_reply) {168 return _reply->waitForReadyRead(msecs);169 }170 else171 #endif172 120 if (_socket) { 173 121 return _socket->waitForReadyRead(msecs); … … 181 129 //////////////////////////////////////////////////////////////////////////// 182 130 qint64 bncSocket::read(char* data, qint64 maxlen) { 183 #if QT_VERSION >= 0x040400184 if (_reply) {185 return _reply->read(data, maxlen);186 }187 else188 #endif189 131 if (_socket) { 190 132 return _socket->read(data, maxlen); … … 198 140 //////////////////////////////////////////////////////////////////////////// 199 141 qint64 bncSocket::write(const char* data, qint64 len) { 200 #if QT_VERSION >= 0x040400201 if (_reply) {202 return -1;203 }204 else205 #endif206 142 if (_socket) { 207 143 return _socket->write(data, len); … … 215 151 //////////////////////////////////////////////////////////////////////////// 216 152 bool bncSocket::waitForBytesWritten(int msecs) { 217 #if QT_VERSION >= 0x040400218 if (_reply) {219 return _reply->waitForBytesWritten(msecs);220 }221 else222 #endif223 153 if (_socket) { 224 154 return _socket->waitForBytesWritten(msecs); … … 361 291 // 362 292 //////////////////////////////////////////////////////////////////////////// 363 #if QT_VERSION >= 0x040400 364 void bncSocket::slotReplyFinished() { 365 cout << "slotReplyFinished" << endl; 293 void bncSocket::slotRequestFinished(int id, bool error) { 294 cout << "slotRequestFinished " << id << " " << error << endl; 366 295 this->deleteLater(); 367 296 } 368 #endif 369 370 // 371 //////////////////////////////////////////////////////////////////////////// 372 #if QT_VERSION >= 0x040400 373 void bncSocket::slotReadyRead() { 297 298 // 299 //////////////////////////////////////////////////////////////////////////// 300 void bncSocket::slotReadyRead(const QHttpResponseHeader&) { 374 301 cout << "slotReadyRead" << endl; 375 302 } 376 #endif 377 378 // 379 //////////////////////////////////////////////////////////////////////////// 380 #if QT_VERSION >= 0x040400 381 void bncSocket::slotError(QNetworkReply::NetworkError) { 382 cout << "slotError " << _reply->error() << endl 383 << _reply->errorString().toAscii().data() << endl; 384 } 385 #endif 386 387 // 388 //////////////////////////////////////////////////////////////////////////// 389 #if QT_VERSION >= 0x040400 303 304 // 305 //////////////////////////////////////////////////////////////////////////// 390 306 void bncSocket::slotSslErrors(const QList<QSslError>&) { 391 307 cout << "slotSslError" << endl; 392 308 } 393 #endif 309 310 // 311 //////////////////////////////////////////////////////////////////////////// 312 void bncSocket::slotDone(bool error) { 313 cout << "slotDone " << error << endl; 314 } 394 315 395 316 // Connect to Caster NTRIP Version 2 … … 398 319 const QByteArray& longitude, const QByteArray& nmea, 399 320 int timeOut, QString& msg) { 400 #if QT_VERSION < 0x040400 401 emit newMessage("NTRIP v2 requires Qt Version 4.4 or higher", "true"); 402 return failure; 403 #else 404 // Network Access Manager 405 // ---------------------- 406 if (_manager == 0) { 407 _manager = new QNetworkAccessManager(this); 408 } 409 else { 410 return failure; 411 } 321 322 delete _socket; 323 _socket = new QTcpSocket(); 324 325 delete _http; 326 _http = new QHttp(); 327 328 _http->setSocket(_socket); 412 329 413 330 // Network Request 414 331 // --------------- 415 QNetworkRequest request; 416 request.setUrl(url); 417 request.setRawHeader("Host" , url.host().toAscii()); 418 request.setRawHeader("Ntrip-Version", "NTRIP/2.0"); 419 request.setRawHeader("User-Agent" , "NTRIP BNC/1.7"); 332 QHttpRequestHeader request("GET", url.path()); 333 request.addValue("Host" , url.host().toAscii()); 334 request.addValue("Ntrip-Version", "NTRIP/2.0"); 335 request.addValue("User-Agent" , "NTRIP BNC/1.7"); 420 336 if (!url.userName().isEmpty()) { 421 request. setRawHeader("Authorization", "Basic " +337 request.addValue("Authorization", "Basic " + 422 338 (url.userName() + ":" + url.password()).toAscii().toBase64()); 423 339 } 424 request. setRawHeader("Connection" , "close");425 426 _reply = _manager->get(request); 427 428 connect(_ reply, SIGNAL(finished()), this, SLOT(slotReplyFinished()));429 connect(_reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));430 connect(_ reply, SIGNAL(error(QNetworkReply::NetworkError)),431 this, SLOT(slot Error(QNetworkReply::NetworkError)));432 connect(_ reply, SIGNAL(sslErrors(const QList<QSslError>&)),340 request.addValue("Connection" , "close"); 341 342 343 connect(_http, SIGNAL(done(bool)), this, SLOT(slotDone(bool))); 344 connect(_http, SIGNAL(requestFinished(int, bool)), 345 this, SLOT(slotRequestFinished(int, bool))); 346 connect(_http, SIGNAL(readyRead(const QHttpResponseHeader&)), 347 this, SLOT(slotReadyRead(const QHttpResponseHeader&))); 348 connect(_http, SIGNAL(sslErrors(const QList<QSslError>&)), 433 349 this, SLOT(slotSslErrors(const QList<QSslError>&))); 434 350 435 351 return success; 436 #endif 437 } 352 } -
trunk/BNC/bncsocket.h
r1356 r1357 5 5 #include "bncconst.h" 6 6 7 class bncSocket : public Q Object{7 class bncSocket : public QThread { 8 8 Q_OBJECT 9 9 … … 33 33 34 34 private slots: 35 #if QT_VERSION >= 0x040400 36 void slotReplyFinished(); 37 void slotReadyRead(); 38 void slotError(QNetworkReply::NetworkError); 35 void slotDone(bool); 36 void slotRequestFinished(int, bool); 37 void slotReadyRead(const QHttpResponseHeader&); 39 38 void slotSslErrors(const QList<QSslError>&); 40 #endif41 39 42 40 private: … … 45 43 int timeOut, QString& msg); 46 44 47 QTcpSocket* _socket; 48 #if QT_VERSION >= 0x040400 49 QNetworkAccessManager* _manager; 50 QNetworkReply* _reply; 51 #endif 45 QTcpSocket* _socket; 46 QHttp* _http; 52 47 }; 53 48
Note:
See TracChangeset
for help on using the changeset viewer.