File indexing completed on 2024-04-28 04:40:42

0001 // SPDX-License-Identifier: GPL-3.0-or-later
0002 // SPDX-FileCopyrightText: 2019 Casper Meijn <casper@meijn.net>
0003 // SPDX-FileCopyrightText: 2023 Harald Sitter <sitter@kde.org>
0004 
0005 #ifndef WSDISCOVERYCLIENT_H
0006 #define WSDISCOVERYCLIENT_H
0007 
0008 #include "wsdiscoveryclient_export.h"
0009 #include <QHash>
0010 #include <QObject>
0011 #include <QUrl>
0012 
0013 #include <KDSoapClient/KDQName>
0014 
0015 #include "KDSoapClient/kdsoap_version.h"
0016 
0017 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) && (KDSOAP_VERSION <= KDSOAP_VERSION_CHECK(2, 1, 1))
0018 WSDISCOVERYCLIENT_EXPORT QDebug operator<<(QDebug dbg, const KDQName &qn);
0019 #endif
0020 
0021 class KDSoapHeaders;
0022 class KDSoapMessage;
0023 class KDSoapUdpClient;
0024 class QHostAddress;
0025 class WSDiscoveryTargetService;
0026 
0027 /*!
0028  * \brief WSDiscoveryClient is a low-level helper for sending and receiving WS-Discovery messages.
0029  *
0030  * start() will bind to the network and start receveing messages.
0031  * When a message is received, it will trigger the signals probeMatchReceived() and
0032  * resolveMatchReceived(). You can send messages using sendProbe() and sendResolve().
0033  *
0034  * \see WSDiscoveryProbeJob for a more high level interface
0035  */
0036 class WSDISCOVERYCLIENT_EXPORT WSDiscoveryClient : public QObject
0037 {
0038     Q_OBJECT
0039 public:
0040     /*!
0041      * Create a WSDiscoveryClient
0042      * \param parent The QObject parent
0043      */
0044     explicit WSDiscoveryClient(QObject *parent = nullptr);
0045     ~WSDiscoveryClient();
0046 
0047 Q_SIGNALS:
0048     /*!
0049      * Emitted when a WS-Discovery probe match message is received. When a single message is reveived
0050      * with multiple matches, then multiple signals are emitted.
0051      * \param probeMatchService The service as described in the match
0052      */
0053     void probeMatchReceived(const WSDiscoveryTargetService &probeMatchService);
0054 
0055     /*!
0056      * Emitted when a WS-Discovery resolve match message is received.
0057      * \param probeMatchService The service as described in the match
0058      */
0059     // TODO: Rename parameter
0060     void resolveMatchReceived(const WSDiscoveryTargetService &probeMatchService);
0061 
0062 public Q_SLOTS:
0063     /*!
0064      * Bind to the WS-Discovery network ports. After binding messages will be
0065      * received. It binds on both IPv4 and IPv6.
0066      * @param port the port to bind or 0 to pick a random port
0067      */
0068     // TODO: Rename to bind()
0069     void start(quint16 port = 0);
0070 
0071     /*!
0072      * Send a WS-Discovery probe message. This will cause all devices in the network
0073      * that match to \p typeList and \p scopeList to send a probeMatch back.
0074      * \param  typeList List of types that a device should match
0075      * \param  scopeList List of scoped that a device should match
0076      */
0077     void sendProbe(const QList<KDQName> &typeList, const QList<QUrl> &scopeList);
0078 
0079     /*!
0080      * Send a WS-Discovery resolve message. This will cause a specific device
0081      * in the network to send a resolveMatch back.
0082      * \param endpointReference The identifier of the device of interest
0083      */
0084     void sendResolve(const QString &endpointReference);
0085 
0086 private Q_SLOTS:
0087     // TODO: Make implementation private
0088     void receivedMessage(const KDSoapMessage &replyMessage, const KDSoapHeaders &replyHeaders, const QHostAddress &senderAddress, quint16 senderPort);
0089 
0090 private:
0091     KDSoapUdpClient *m_soapUdpClient;
0092 };
0093 
0094 #endif // WSDISCOVERYCLIENT_H