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 #include "wsdiscoveryprobejob.h"
0006 
0007 #include "loggingcategory.h"
0008 #include "wsdiscoveryclient.h"
0009 #include "wsdiscoverytargetservice.h"
0010 #include <QDebug>
0011 #include <QSharedPointer>
0012 
0013 WSDiscoveryProbeJob::WSDiscoveryProbeJob(WSDiscoveryClient *parent)
0014     : QObject(parent)
0015     , m_client(parent)
0016 {
0017     connect(m_client, &WSDiscoveryClient::probeMatchReceived, this, &WSDiscoveryProbeJob::probeMatchReceived);
0018 
0019     m_timer.setInterval(30000);
0020     connect(&m_timer, &QTimer::timeout, this, &WSDiscoveryProbeJob::timeout);
0021 }
0022 
0023 QList<KDQName> WSDiscoveryProbeJob::typeList() const
0024 {
0025     return m_typeList;
0026 }
0027 
0028 void WSDiscoveryProbeJob::setTypeList(const QList<KDQName> &typeList)
0029 {
0030     m_typeList = typeList;
0031 }
0032 
0033 void WSDiscoveryProbeJob::addType(const KDQName &type)
0034 {
0035     m_typeList.append(type);
0036 }
0037 
0038 QList<QUrl> WSDiscoveryProbeJob::scopeList() const
0039 {
0040     return m_scopeList;
0041 }
0042 
0043 void WSDiscoveryProbeJob::setScopeList(const QList<QUrl> &scopeList)
0044 {
0045     m_scopeList = scopeList;
0046 }
0047 
0048 void WSDiscoveryProbeJob::addScope(const QUrl &scope)
0049 {
0050     m_scopeList.append(scope);
0051 }
0052 
0053 int WSDiscoveryProbeJob::interval() const
0054 {
0055     return m_timer.interval();
0056 }
0057 
0058 void WSDiscoveryProbeJob::setInterval(int interval)
0059 {
0060     m_timer.setInterval(interval);
0061 }
0062 
0063 void WSDiscoveryProbeJob::start()
0064 {
0065     timeout();
0066     m_timer.start();
0067 }
0068 
0069 void WSDiscoveryProbeJob::stop()
0070 {
0071     m_timer.stop();
0072 }
0073 
0074 void WSDiscoveryProbeJob::timeout()
0075 {
0076     m_client->sendProbe(m_typeList, m_scopeList);
0077 }
0078 
0079 void WSDiscoveryProbeJob::probeMatchReceived(const WSDiscoveryTargetService &probeMatchService)
0080 {
0081     bool isMatch = true;
0082     for (const KDQName &type : qAsConst(m_typeList)) {
0083         isMatch = probeMatchService.isMatchingType(type) && isMatch;
0084     }
0085     for (const QUrl &scope : qAsConst(m_scopeList)) {
0086         isMatch = probeMatchService.isMatchingScope(scope) && isMatch;
0087     }
0088     if (isMatch) {
0089         emit matchReceived(probeMatchService);
0090     } else {
0091         qCDebug(KDSoapWSDiscoveryClient) << "Received probe match that didn't match the probe job";
0092     }
0093 }