File indexing completed on 2024-04-28 15:22:07

0001 /*
0002     This file is part of the KDE project
0003 
0004     SPDX-FileCopyrightText: 2004 Jakub Stachowski <qbast@go2.pl>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KDNSSDSERVICETYPEBROWSER_H
0010 #define KDNSSDSERVICETYPEBROWSER_H
0011 
0012 #include "remoteservice.h"
0013 #include <QObject>
0014 #include <QtContainerFwd>
0015 #include <memory>
0016 
0017 namespace KDNSSD
0018 {
0019 class ServiceTypeBrowserPrivate;
0020 
0021 /**
0022  * @class ServiceTypeBrowser servicetypebrowser.h KDNSSD/ServiceTypeBrowser
0023  * @short Browses the service types being published on a domain
0024  *
0025  * This class is mostly useful for generic utilities for
0026  * browsing all the published service types on a local network.
0027  * Applications that wish to find out about available services
0028  * of a particular type (such as web servers) should use
0029  * ServiceBrowser.
0030  *
0031  * ServiceTypeBrowser provides a list of all the service types
0032  * published by at least one service on a given domain.
0033  *
0034  * @author Jakub Stachowski
0035  */
0036 class KDNSSD_EXPORT ServiceTypeBrowser : public QObject
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     /**
0042      * Create a ServiceTypeBrowser for a domain
0043      *
0044      * The link-local domain (the LAN subnet for this computer) will
0045      * be used if no @p domain is given.  DomainBrowser can be used
0046      * to get a list of browsing domains.
0047      *
0048      * Note that WAN domains may not support service type browsing.
0049      *
0050      * @param domain a browsing domain to search
0051      * @param parent the parent object (see QObject documentation)
0052      *
0053      * @see startBrowse() and ServiceBrowser::isAvailable()
0054      */
0055     explicit ServiceTypeBrowser(const QString &domain = QString(), QObject *parent = nullptr);
0056 
0057     ~ServiceTypeBrowser() override;
0058 
0059     /**
0060      * All the service types currently being published
0061      *
0062      * @return a list of service types, in the form _type._tcp or _type._udp
0063      */
0064     QStringList serviceTypes() const;
0065 
0066     /**
0067      * Starts browsing
0068      *
0069      * Only the first call to this function will have any effect.
0070      *
0071      * Browsing stops when the ServiceTypeBrowser object is destroyed.
0072      *
0073      * @warning The serviceTypeAdded() signal may be emitted before this
0074      *          function returns.
0075      *
0076      * @see serviceTypeAdded(), serviceTypeRemoved() and finished()
0077      */
0078     void startBrowse();
0079 
0080 #if KDNSSD_ENABLE_DEPRECATED_SINCE(4, 0)
0081     /**
0082      * This method is unnecessary, since it is safe to call startBrowse()
0083      * multiple times.
0084      * @deprecated since 4.0, just call startBrowse() again.
0085      */
0086     KDNSSD_DEPRECATED_VERSION(4, 0, "Just call ServiceTypeBrowser::startBrowse() again")
0087     bool isRunning() const
0088     {
0089         return false;
0090     }
0091 #endif
0092 
0093 Q_SIGNALS:
0094     /**
0095      * Emitted when there are no more services of this type
0096      *
0097      * @warning
0098      * This signal is not reliable: it is possible that it will not be
0099      * emitted even after last service of this type disappeared
0100      *
0101      * @param type the service type
0102      *
0103      * @see serviceTypeAdded() and finished()
0104      */
0105     void serviceTypeRemoved(const QString &type);
0106 
0107     /**
0108      * A new type of service has been found
0109      *
0110      * @param type the service type
0111      *
0112      * @see serviceTypeAdded() and finished()
0113      */
0114     void serviceTypeAdded(const QString &type);
0115 
0116     /**
0117      * Emitted when the list of published service types has settled
0118      *
0119      * This signal is emitted once after startBrowse() is called
0120      * when the types of all the services that are
0121      * currently published have been reported (even if no services
0122      * are available or the DNS-SD service is not available).
0123      * It is emitted again when a new batch of service types become
0124      * available or disappear.
0125      *
0126      * For example, if a new host is connected to network and
0127      * announces services of several new types,
0128      * they will be reported by several serviceTypeAdded() signals
0129      * and the whole batch will be concluded by finished().
0130      *
0131      * This signal can be used by applications that just want to
0132      * get a list of the currently available service types
0133      * (similar to a directory listing) and do not care about
0134      * adding or removing service types that appear or disappear later.
0135      *
0136      * @see serviceTypeAdded() and serviceTypeRemoved()
0137      */
0138     void finished();
0139 
0140 private:
0141     friend class ServiceTypeBrowserPrivate;
0142     std::unique_ptr<ServiceTypeBrowserPrivate> const d;
0143     Q_DECLARE_PRIVATE_D(d, ServiceTypeBrowser)
0144 };
0145 
0146 }
0147 
0148 #endif