QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NTRIPHttpSession.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4
5#include <QtCore/QByteArray>
6#include <QtCore/QByteArrayView>
7#include <QtCore/QDateTime>
8#include <QtCore/QList>
9#include <QtCore/QObject>
10#include <QtCore/QString>
11
12#include "NTRIPError.h"
13#include "NTRIPHttpCodec.h"
14#include "ScheduledTask.h"
15
17class QSslError;
18class QSslSocket;
19class QTcpSocket;
21
31class NTRIPHttpSession : public QObject
32{
33 Q_OBJECT
36
37public:
38 static constexpr qint64 READ_BUFFER_BYTES = 64 * 1024;
39 static constexpr qint64 READ_CHUNK_BYTES = 16 * 1024;
40 static constexpr std::chrono::milliseconds ERROR_BODY_TIMEOUT{250};
41
42 explicit NTRIPHttpSession(QObject* parent = nullptr, RuntimeScheduler* scheduler = nullptr,
44
47 QString open(const NTRIPConnectionConfig& config);
49 bool write(const QByteArray& bytes);
50 bool isConnected() const;
51
53 bool awaitingErrorBody() const { return _decoder.awaitingErrorBody(); }
54
56 void abort();
59 void retire();
60
61signals:
63 void certificatePinned(const QString& pin);
67 void bodyReceived(const QByteArray& body, qint64 receivedAtMs);
69 void failed(const NTRIPFailure& failure);
71 void finished();
72
73private:
75 void _attach(QTcpSocket* socket);
76 void _verifyCertificate(QSslSocket* socket, const QList<QSslError>& errors);
77 void _establish();
78 void _read();
80 void _receive(QByteArrayView bytes, qint64 receivedAtMs, const QDateTime& utcNow = QDateTime::currentDateTimeUtc());
82 void _publish(const NTRIPHttpDecoder::Result& result, qint64 receivedAtMs);
84 void _finishResponse();
85 void _fail(NTRIPError code, const QString& message);
86 void _end();
87
88 RuntimeScheduler* const _scheduler;
89 const NTRIPHttpPurpose _purpose;
90 ScheduledTask _errorBodyTask;
91 NTRIPHttpDecoder _decoder;
92 QByteArray _request;
93 QTcpSocket* _socket = nullptr;
94 QString _endpoint;
95 QString _pinnedCertificate;
96 QString _newPin;
97 bool _allowSelfSignedCerts = false;
98 bool _reading = false;
99 bool _ended = false;
100};
Config config
NTRIPHttpPurpose
Private transport parser; buffers framing, never correction payloads.
bool awaitingErrorBody() const
static constexpr qint64 READ_CHUNK_BYTES
void certificatePinned(const QString &pin)
A newly trusted self-signed certificate, as NTRIPConnectionConfig::pinnedCertificate; precedes the re...
static constexpr qint64 READ_BUFFER_BYTES
QString open(const NTRIPConnectionConfig &config)
bool awaitingErrorBody() const
An error status arrived and its body is still being read.
friend class NTRIPHttpTransportTest
static constexpr std::chrono::milliseconds ERROR_BODY_TIMEOUT
bool write(const QByteArray &bytes)
False unless the socket accepted every byte; the owner decides how to report it.
void finished()
The response ended where its HTTP framing allows.
void bodyReceived(const QByteArray &body, qint64 receivedAtMs)
Body bytes, with the scheduler time at which the bytes carrying them arrived.
void responseStarted()
The caster accepted the request; its body follows.
void abort()
Ends the connection without further signals.
friend class NTRIPHttpSessionTest
bool isConnected() const
void failed(const NTRIPFailure &failure)
A socket, TLS or HTTP failure, including an error status with the caster's explanation.