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

0001 /* SPDX-FileCopyrightText: 2019 Casper Meijn <casper@meijn.net>
0002  * SPDX-License-Identifier: GPL-3.0-or-later
0003  *
0004  */
0005 #ifndef WSDISCOVERYPROBEJOB_H
0006 #define WSDISCOVERYPROBEJOB_H
0007 
0008 #include "wsdiscoveryclient_export.h"
0009 #include <KDSoapClient/KDQName>
0010 #include <QObject>
0011 #include <QTimer>
0012 #include <QUrl>
0013 
0014 class WSDiscoveryClient;
0015 class WSDiscoveryTargetService;
0016 
0017 /*!
0018  * \brief Periodically probe the network for WS-Discovery devices.
0019  *
0020  * You can set a filter for interested types and scopes, only devices that match
0021  * the filter will be reported. After starting it will probe the network and
0022  * report any matches.
0023  */
0024 class WSDISCOVERYCLIENT_EXPORT WSDiscoveryProbeJob : public QObject
0025 {
0026     Q_OBJECT
0027 public:
0028     /*!
0029      * Creates a WSDiscoveryProbeJob
0030      * \param parent is both the QObject parent as the WSDiscoveryClient
0031      *   used for sending and receiving messages
0032      */
0033     explicit WSDiscoveryProbeJob(WSDiscoveryClient *parent);
0034 
0035     /*!
0036      * \return List of types to filter devices with
0037      */
0038     QList<KDQName> typeList() const;
0039     /*!
0040      * \param typeList List of types to filter devices with
0041      */
0042     void setTypeList(const QList<KDQName> &typeList);
0043     /*!
0044      * \param type Adds a type to the list to filter devices with
0045      */
0046     void addType(const KDQName &type);
0047 
0048     /*!
0049      * \return List of scopes to filter devices with
0050      */
0051     QList<QUrl> scopeList() const;
0052     /*!
0053      * \param scopeList List of scopes to filter devices with
0054      */
0055     void setScopeList(const QList<QUrl> &scopeList);
0056     /*!
0057      * \param scope Adds a scopes to the list to filter devices with
0058      */
0059     void addScope(const QUrl &scope);
0060 
0061     /*!
0062      * \return The interval between probes
0063      */
0064     int interval() const;
0065     /*!
0066      * \param interval Sets the interval between probes
0067      */
0068     void setInterval(int interval);
0069 
0070 Q_SIGNALS:
0071     /*!
0072      * Emitted when a match is received
0073      * \param matchedService The service as described in the match
0074      */
0075     void matchReceived(const WSDiscoveryTargetService &matchedService);
0076 
0077 public Q_SLOTS:
0078     /*!
0079      * Start sending periodic probes
0080      */
0081     void start();
0082     /*!
0083      * Stop sending periodic probes
0084      */
0085     void stop();
0086 
0087     // TODO: Hide private interface
0088 private Q_SLOTS:
0089     void timeout();
0090     void probeMatchReceived(const WSDiscoveryTargetService &probeMatchService);
0091 
0092 private:
0093     WSDiscoveryClient *m_client;
0094     QList<KDQName> m_typeList;
0095     QList<QUrl> m_scopeList;
0096     QTimer m_timer;
0097 };
0098 
0099 #endif // WSDISCOVERYPROBEJOB_H