source: ntrip/trunk/BNC/bncnetqueryudp0.cpp@ 1785

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

* empty log message *

File size: 2.5 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncNetQueryUdp0
6 *
7 * Purpose: Blocking Network Requests (plain UDP, no NTRIP)
8 *
9 * Author: L. Mervart
10 *
11 * Created: 04-Feb-2009
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18
19#include "bncnetqueryudp0.h"
20
21using namespace std;
22
23// Constructor
24////////////////////////////////////////////////////////////////////////////
25bncNetQueryUdp0::bncNetQueryUdp0() {
26 _udpSocket = 0;
27 _eventLoop = new QEventLoop(this);
28
29 _keepAlive[ 0] = 128;
30 _keepAlive[ 1] = 96;
31 for (int ii = 2; ii <=11; ii++) {
32 _keepAlive[ii] = 0;
33 }
34}
35
36// Destructor
37////////////////////////////////////////////////////////////////////////////
38bncNetQueryUdp0::~bncNetQueryUdp0() {
39 delete _eventLoop;
40 delete _udpSocket;
41}
42
43//
44////////////////////////////////////////////////////////////////////////////
45void bncNetQueryUdp0::stop() {
46 _eventLoop->quit();
47 _status = finished;
48}
49
50//
51////////////////////////////////////////////////////////////////////////////
52void bncNetQueryUdp0::waitForRequestResult(const QUrl&, QByteArray&) {
53}
54
55//
56////////////////////////////////////////////////////////////////////////////
57void bncNetQueryUdp0::waitForReadyRead(QByteArray& outData) {
58
59 // Wait Loop
60 // ---------
61 if (!_udpSocket->hasPendingDatagrams()) {
62 _eventLoop->exec();
63 }
64
65 // Append Data
66 // -----------
67 QByteArray datagram;
68 datagram.resize(_udpSocket->pendingDatagramSize());
69 _udpSocket->readDatagram(datagram.data(), datagram.size());
70
71 if (datagram.size() > 0) {
72 outData.append(datagram);
73 }
74}
75
76// Connect to Caster, send the Request
77////////////////////////////////////////////////////////////////////////////
78void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& /* gga */) {
79
80 _status = running;
81
82 // Default scheme and path
83 // -----------------------
84 _url = url;
85 if (_url.scheme().isEmpty()) {
86 _url.setScheme("http");
87 }
88 if (_url.path().isEmpty()) {
89 _url.setPath("/");
90 }
91
92 delete _udpSocket; _udpSocket = 0;
93
94 QHostInfo hInfo = QHostInfo::fromName(_url.host());
95 if (!hInfo.addresses().isEmpty()) {
96 _address = hInfo.addresses().first();
97 _udpSocket = new QUdpSocket();
98 _udpSocket->bind(0);
99 connect(_udpSocket, SIGNAL(readyRead()), _eventLoop, SLOT(quit()));
100
101 _udpSocket->writeDatagram(_keepAlive, 12, _address, _url.port());
102 }
103}
104
Note: See TracBrowser for help on using the repository browser.