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

Last change on this file since 1789 was 1788, checked in by mervart, 17 years ago

* empty log message *

File size: 2.5 KB
RevLine 
[1779]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
[1785]17#include <iostream>
18
[1779]19#include "bncnetqueryudp0.h"
20
21using namespace std;
22
23// Constructor
24////////////////////////////////////////////////////////////////////////////
25bncNetQueryUdp0::bncNetQueryUdp0() {
26 _udpSocket = 0;
[1785]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 }
[1779]34}
35
36// Destructor
37////////////////////////////////////////////////////////////////////////////
38bncNetQueryUdp0::~bncNetQueryUdp0() {
[1785]39 delete _eventLoop;
[1779]40 delete _udpSocket;
41}
42
43//
44////////////////////////////////////////////////////////////////////////////
45void bncNetQueryUdp0::stop() {
[1785]46 _eventLoop->quit();
[1783]47 _status = finished;
[1779]48}
49
50//
51////////////////////////////////////////////////////////////////////////////
52void bncNetQueryUdp0::waitForRequestResult(const QUrl&, QByteArray&) {
53}
54
55//
56////////////////////////////////////////////////////////////////////////////
57void bncNetQueryUdp0::waitForReadyRead(QByteArray& outData) {
[1785]58
59 // Wait Loop
60 // ---------
61 if (!_udpSocket->hasPendingDatagrams()) {
62 _eventLoop->exec();
[1779]63 }
[1785]64
65 // Append Data
66 // -----------
67 QByteArray datagram;
68 datagram.resize(_udpSocket->pendingDatagramSize());
69 _udpSocket->readDatagram(datagram.data(), datagram.size());
70
[1787]71 outData.append(datagram);
[1779]72}
73
74// Connect to Caster, send the Request
75////////////////////////////////////////////////////////////////////////////
[1783]76void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& /* gga */) {
[1779]77
78 _status = running;
79
80 // Default scheme and path
81 // -----------------------
82 _url = url;
83 if (_url.scheme().isEmpty()) {
84 _url.setScheme("http");
85 }
86 if (_url.path().isEmpty()) {
87 _url.setPath("/");
88 }
89
[1785]90 delete _udpSocket; _udpSocket = 0;
91
92 QHostInfo hInfo = QHostInfo::fromName(_url.host());
93 if (!hInfo.addresses().isEmpty()) {
94 _address = hInfo.addresses().first();
95 _udpSocket = new QUdpSocket();
[1786]96 _udpSocket->bind(_url.port());
[1785]97 connect(_udpSocket, SIGNAL(readyRead()), _eventLoop, SLOT(quit()));
98
99 _udpSocket->writeDatagram(_keepAlive, 12, _address, _url.port());
100 }
[1779]101}
102
Note: See TracBrowser for help on using the repository browser.