6#include <QtCore/QByteArray>
8#include <QtCore/QLoggingCategory>
9#include <QtCore/QMutex>
10#include <QtCore/QString>
11#include <QtNetwork/QHostAddress>
15#ifdef QGC_ZEROCONF_ENABLED
17#define WIN32_LEAN_AND_MEAN
31 UDPClient(
const QHostAddress &addr, quint16 portNum)
37 : address(other->address)
43 return ((address == other.
address) && (port == other.
port));
65 Q_PROPERTY(quint16 localPort READ localPort WRITE setLocalPort NOTIFY
localPortChanged)
72 Q_INVOKABLE
void addHost(
const QString &host);
73 Q_INVOKABLE
void addHost(
const QString &host, quint16 port);
74 Q_INVOKABLE
void removeHost(
const QString &host);
75 Q_INVOKABLE
void removeHost(
const QString &host, quint16 port);
77 LinkType type()
const override {
return LinkConfiguration::TypeUdp; }
78 void setAutoConnect(
bool autoc =
true)
override;
80 void loadSettings(QSettings &settings,
const QString &root)
override;
81 void saveSettings(QSettings &settings,
const QString &root)
const override;
82 QString settingsURL()
const override {
return QStringLiteral(
"UdpSettings.qml"); }
83 QString settingsTitle()
const override {
return tr(
"UDP Link Settings"); }
85 QStringList hostList()
const {
return _hostList; }
86 QList<std::shared_ptr<UDPClient>> targetHosts()
const {
return _targetHosts; }
87 quint16 localPort()
const {
return _localPort; }
88 void setLocalPort(quint16 port) {
if (port != _localPort) { _localPort = port; emit
localPortChanged(); } }
95 void _updateHostList();
97 static QString _getIpAddress(
const QString &address);
99 QStringList _hostList;
100 QList<std::shared_ptr<UDPClient>> _targetHosts;
101 quint16 _localPort = 0;
130 void _onSocketConnected();
131 void _onSocketDisconnected();
132 void _onSocketReadyRead();
133 void _onSocketBytesWritten(qint64 bytes);
134 void _onSocketErrorOccurred(QAbstractSocket::SocketError socketError);
138 QUdpSocket *_socket =
nullptr;
139 QMutex _sessionTargetsMutex;
140 QList<std::shared_ptr<UDPClient>> _sessionTargets;
141 bool _isConnected =
false;
142 bool _errorEmitted =
false;
143 QSet<QHostAddress> _localAddresses;
145 static const QHostAddress _multicastGroup;
147#ifdef QGC_ZEROCONF_ENABLED
148 void _registerZeroconf(uint16_t port);
149 void _deregisterZeroconf();
150 static void _zeroconfRegisterCallback(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErrorType errorCode,
const char *name,
const char *regtype,
const char *domain,
void *context);
152 DNSServiceRef _dnssServiceRef =
nullptr;
174 void _writeBytes(
const QByteArray &data)
override;
176 void _onDisconnected();
178 void _onDataReceived(
const QByteArray &data);
179 void _onDataSent(
const QByteArray &data);
184 QThread *_workerThread =
nullptr;
185 std::atomic<bool> _disconnectedEmitted{
false};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
std::shared_ptr< LinkConfiguration > SharedLinkConfigurationPtr
Interface holding link specific settings.
The link interface defines the interface for all links used to communicate with the ground station ap...
bool isSecureConnection() const override
Returns true if the connection is secure (e.g. USB, wired ethernet)
bool isConnected() const override
bool _connect() override
connect is private since all links should be created through LinkManager::createConnectedLink calls
void disconnect() override
void dataReceived(const QByteArray &data)
void dataSent(const QByteArray &data)
void errorOccurred(const QString &errorString)
void writeData(const QByteArray &data)
UDPClient(const QHostAddress &addr, quint16 portNum)
UDPClient(const UDPClient *other)
bool operator==(const UDPClient &other) const
UDPClient & operator=(const UDPClient &other)