QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NTRIPSourceTableController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QAbstractListModel>
4#include <QtCore/QLoggingCategory>
5#include <QtCore/QObject>
6#include <QtPositioning/QGeoCoordinate>
7#include <QtQmlIntegration/QtQmlIntegration>
8
10
11Q_DECLARE_LOGGING_CATEGORY(NTRIPSourceTableControllerLog)
12
14class NTRIPSourceTableControllerTest;
15class QNetworkAccessManager;
16class QNetworkReply;
17
18class NTRIPSourceTableController : public QObject
19{
20 Q_OBJECT
21 QML_ELEMENT
22 QML_UNCREATABLE("")
23 Q_MOC_INCLUDE("QtCore/QAbstractListModel")
25 Q_PROPERTY(QString fetchError READ fetchError NOTIFY fetchErrorChanged)
26 Q_PROPERTY(QAbstractListModel* mountpointModel READ mountpointModel NOTIFY mountpointModelChanged)
27
28public:
29 enum class FetchStatus
30 {
31 Idle,
33 Success,
34 Error
35 };
36 Q_ENUM(FetchStatus)
37
38 static constexpr int kCacheTtlMs = 60000;
39 static constexpr int kFetchTimeoutMs = 10000;
40 static constexpr qint64 kMaxSourceTableBytes = 8 * 1024 * 1024;
41
42 explicit NTRIPSourceTableController(QObject* parent = nullptr);
44
45 FetchStatus fetchStatus() const { return _fetchStatus; }
46
47 QString fetchError() const { return _fetchError; }
48
49 QAbstractListModel* mountpointModel() const;
50
51 void fetch(const NTRIPTransportConfig& config, const QGeoCoordinate& sortCoord = {});
52 Q_INVOKABLE void selectMountpoint(const QString& mountpoint);
53
54signals:
60 void mountpointSelected(const QString& mountpoint);
61
62private:
64
66 void injectSourceTableForTest(const QString& table);
67 void injectFetchErrorForTest(const QString& error);
68
69 void _onReplyFinished();
70 void _onSourceTableReceived(const QString& table);
71 void _onFetchError(const QString& error);
72 void _abortReply();
73
74 NTRIPSourceTableModel* _model = nullptr;
75 QNetworkAccessManager* _networkManager = nullptr;
76 QNetworkReply* _reply = nullptr;
77 bool _replyTooLarge = false;
78 QGeoCoordinate _sortCoord;
79 FetchStatus _fetchStatus = FetchStatus::Idle;
80 QString _fetchError;
81 qint64 _fetchedAtMs = 0;
82
83 // Cache key for the most recent fetch — NTRIPTransportConfig::casterIdentity()
84 // so it stays in lockstep with the config's own notion of "same caster".
85 QString _lastFetchKey;
86};
Config config
Error error
Q_INVOKABLE void selectMountpoint(const QString &mountpoint)
void fetch(const NTRIPTransportConfig &config, const QGeoCoordinate &sortCoord={})
void mountpointSelected(const QString &mountpoint)
QAbstractListModel * mountpointModel() const
static constexpr qint64 kMaxSourceTableBytes