| 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 "bncnetqueryudp0.h"
|
|---|
| 18 |
|
|---|
| 19 | using namespace std;
|
|---|
| 20 |
|
|---|
| 21 | // Constructor
|
|---|
| 22 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 23 | bncNetQueryUdp0::bncNetQueryUdp0() {
|
|---|
| 24 | _udpSocket = 0;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | // Destructor
|
|---|
| 28 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 29 | bncNetQueryUdp0::~bncNetQueryUdp0() {
|
|---|
| 30 | delete _udpSocket;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | //
|
|---|
| 34 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 35 | void bncNetQueryUdp0::stop() {
|
|---|
| 36 | #ifndef sparc
|
|---|
| 37 | if (_udpSocket) {
|
|---|
| 38 | _udpSocket->abort();
|
|---|
| 39 | }
|
|---|
| 40 | #endif
|
|---|
| 41 | _status = finished;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | //
|
|---|
| 45 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 46 | void bncNetQueryUdp0::waitForRequestResult(const QUrl&, QByteArray&) {
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | //
|
|---|
| 50 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 51 | void bncNetQueryUdp0::waitForReadyRead(QByteArray& outData) {
|
|---|
| 52 | if (_udpSocket) {
|
|---|
| 53 | while (true) {
|
|---|
| 54 | int nBytes = _udpSocket->bytesAvailable();
|
|---|
| 55 | if (nBytes > 0) {
|
|---|
| 56 | outData = _udpSocket->readAll();
|
|---|
| 57 | return;
|
|---|
| 58 | }
|
|---|
| 59 | else if (!_udpSocket->waitForReadyRead(_timeOut)) {
|
|---|
| 60 | delete _udpSocket;
|
|---|
| 61 | _udpSocket = 0;
|
|---|
| 62 | _status = error;
|
|---|
| 63 | emit newMessage(_url.path().toAscii() + " read timeout", true);
|
|---|
| 64 | return;
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | // Connect to Caster, send the Request
|
|---|
| 71 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 72 | void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& /* gga */) {
|
|---|
| 73 |
|
|---|
| 74 | _status = running;
|
|---|
| 75 |
|
|---|
| 76 | // Default scheme and path
|
|---|
| 77 | // -----------------------
|
|---|
| 78 | _url = url;
|
|---|
| 79 | if (_url.scheme().isEmpty()) {
|
|---|
| 80 | _url.setScheme("http");
|
|---|
| 81 | }
|
|---|
| 82 | if (_url.path().isEmpty()) {
|
|---|
| 83 | _url.setPath("/");
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | delete _udpSocket;
|
|---|
| 87 | _udpSocket = new QUdpSocket();
|
|---|
| 88 | _udpSocket->connectToHost(_url.host(), _url.port());
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|