source: ntrip/trunk/BNC/bncnetqueryv0.cpp@ 1747

Last change on this file since 1747 was 1716, checked in by mervart, 16 years ago

* empty log message *

File size: 3.1 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncNetQueryV0
6 *
7 * Purpose: TCP/IP Network Requests, no NTRIP
8 *
9 * Author: G. Weber
10 *
11 * Created: 19-Feb-2009
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18#include <iomanip>
19
20#include "bncnetqueryv0.h"
21#include "bncsettings.h"
22
23using namespace std;
24
25#define BNCVERSION "1.7"
26
27// Constructor
28////////////////////////////////////////////////////////////////////////////
29bncNetQueryV0::bncNetQueryV0() {
30 _socket = 0;
31 _timeOut = 20000;
32}
33
34// Destructor
35////////////////////////////////////////////////////////////////////////////
36bncNetQueryV0::~bncNetQueryV0() {
37 delete _socket;
38}
39
40//
41////////////////////////////////////////////////////////////////////////////
42void bncNetQueryV0::stop() {
43#ifndef sparc
44 if (_socket) {
45 _socket->abort();
46 }
47#endif
48 _status = finished;
49}
50
51//
52////////////////////////////////////////////////////////////////////////////
53void bncNetQueryV0::waitForRequestResult(const QUrl&, QByteArray&) {
54}
55
56//
57////////////////////////////////////////////////////////////////////////////
58void bncNetQueryV0::waitForReadyRead(QByteArray& outData) {
59 if (_socket && _socket->state() == QAbstractSocket::ConnectedState) {
60 while (true) {
61 int nBytes = _socket->bytesAvailable();
62 if (nBytes > 0) {
63 outData = _socket->readAll();
64 return;
65 }
66 else if (!_socket->waitForReadyRead(_timeOut)) {
67 delete _socket;
68 _socket = 0;
69 _status = error;
70 emit newMessage(_url.path().toAscii() + " read timeout", true);
71 return;
72 }
73 }
74 }
75}
76
77// Connect to Caster, send the Request
78////////////////////////////////////////////////////////////////////////////
79void bncNetQueryV0::startRequest(const QUrl& url, const QByteArray& gga) {
80
81 _status = running;
82 QByteArray dummy = gga;
83
84 delete _socket;
85 _socket = new QTcpSocket();
86
87 // Default scheme and path
88 // -----------------------
89 _url = url;
90 if (_url.scheme().isEmpty()) {
91 _url.setScheme("http");
92 }
93 if (_url.path().isEmpty()) {
94 _url.setPath("/");
95 }
96
97 // Connect the Socket
98 // ------------------
99 bncSettings settings;
100
101 _socket->connectToHost(_url.host(), _url.port());
102 if (!_socket->waitForConnected(_timeOut)) {
103 delete _socket;
104 _socket = 0;
105 _status = error;
106 emit(newMessage(_url.path().toAscii().replace(0,1,"")
107 + ": Connect timeout, reconnecting", true));
108 return;
109 }
110
111 // Read Caster Response
112 // --------------------
113 QStringList response;
114 while (true) {
115 if (!_socket->waitForReadyRead(_timeOut)) {
116 delete _socket;
117 _socket = 0;
118 _status = error;
119 emit newMessage(_url.path().toAscii().replace(0,1,"")
120 + ": Read timeout", true);
121 return;
122 }
123 if (_socket->canReadLine()) {
124 QString line = _socket->readLine();
125 response.push_back(line);
126 response.clear();
127 break;
128 }
129 }
130}
131
Note: See TracBrowser for help on using the repository browser.