source: ntrip/trunk/BNC/bncnetrequest.cpp@ 1343

Last change on this file since 1343 was 1343, checked in by mervart, 15 years ago

* empty log message *

File size: 3.5 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncNetRequest
6 *
7 * Purpose: Prepare and submit network request
8 *
9 * Author: L. Mervart
10 *
11 * Created: 09-Dec-2008
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18#include <iomanip>
19
20#include "bncnetrequest.h"
21#include "RTCM3/RTCM3Decoder.h"
22
23using namespace std;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27bncNetRequest::bncNetRequest() {
28 _manager = 0;
29 _reply = 0;
30 _decoder = new RTCM3Decoder("TEST1");
31 connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
32 this, SIGNAL(slotNewMessage(QByteArray,bool)));
33}
34
35// Destructor
36////////////////////////////////////////////////////////////////////////////
37bncNetRequest::~bncNetRequest() {
38 cout << "~bncNetRequest" << endl;
39 delete _reply;
40 delete _manager;
41}
42
43// Network Request
44////////////////////////////////////////////////////////////////////////////
45t_irc bncNetRequest::request(const QUrl& url) {
46
47 // Network Access Manager
48 // ----------------------
49 if (_manager == 0) {
50 _manager = new QNetworkAccessManager(this);
51 }
52 else {
53 return failure;
54 }
55
56 // Network Request
57 // ---------------
58 QNetworkRequest request;
59 request.setUrl(url);
60 request.setRawHeader("Host" , url.host().toAscii());
61 request.setRawHeader("Ntrip-Version", "NTRIP/2.0");
62 request.setRawHeader("User-Agent" , "NTRIP BNC/1.7");
63 if (!url.userName().isEmpty()) {
64 request.setRawHeader("Authorization", "Basic " +
65 (url.userName() + ":" + url.password()).toAscii().toBase64());
66 }
67 request.setRawHeader("Connection" , "close");
68
69 _reply = _manager->get(request);
70
71 connect(_reply, SIGNAL(finished()), this, SLOT(slotReplyFinished()));
72 connect(_reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
73 connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)),
74 this, SLOT(slotError(QNetworkReply::NetworkError)));
75 connect(_reply, SIGNAL(sslErrors(const QList<QSslError>&)),
76 this, SLOT(slotSslErrors(const QList<QSslError>&)));
77
78
79 return success;
80}
81
82//
83////////////////////////////////////////////////////////////////////////////
84void bncNetRequest::slotReplyFinished() {
85 cout << "slotReplyFinished" << endl;
86 this->deleteLater();
87}
88
89//
90////////////////////////////////////////////////////////////////////////////
91void bncNetRequest::slotReadyRead() {
92 cout << "slotReadyRead" << endl;
93 QByteArray buffer = _reply->readAll();
94
95 vector<string> errmsg;
96 _decoder->Decode(buffer.data(), buffer.length(), errmsg);
97
98 QListIterator<p_obs> it(_decoder->_obsList);
99 while (it.hasNext()) {
100 p_obs obs = it.next();
101 cout << obs->_o.satNum << endl;
102 delete obs;
103 }
104 _decoder->_obsList.clear();
105}
106
107//
108////////////////////////////////////////////////////////////////////////////
109void bncNetRequest::slotError(QNetworkReply::NetworkError) {
110 cout << "slotError " << _reply->error() << endl
111 << _reply->errorString().toAscii().data() << endl;
112}
113
114//
115////////////////////////////////////////////////////////////////////////////
116void bncNetRequest::slotSslErrors(const QList<QSslError>&) {
117 cout << "slotSslError" << endl;
118}
119
120//
121////////////////////////////////////////////////////////////////////////////
122void bncNetRequest::slotNewMessage(QByteArray msg, bool) {
123 cout << "Message: " << msg.data() << endl;
124}
Note: See TracBrowser for help on using the repository browser.