File indexing completed on 2024-04-28 03:54:04

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 Q_SIGNALS:
0081     /**
0082      * Emitted when there are no more services of this type
0083      *
0084      * @warning
0085      * This signal is not reliable: it is possible that it will not be
0086      * emitted even after last service of this type disappeared
0087      *
0088      * @param type the service type
0089      *
0090      * @see serviceTypeAdded() and finished()
0091      */
0092     void serviceTypeRemoved(const QString &type);
0093 
0094     /**
0095      * A new type of service has been found
0096      *
0097      * @param type the service type
0098      *
0099      * @see serviceTypeAdded() and finished()
0100      */
0101     void serviceTypeAdded(const QString &type);
0102 
0103     /**
0104      * Emitted when the list of published service types has settled
0105      *
0106      * This signal is emitted once after startBrowse() is called
0107      * when the types of all the services that are
0108      * currently published have been reported (even if no services
0109      * are available or the DNS-SD service is not available).
0110      * It is emitted again when a new batch of service types become
0111      * available or disappear.
0112      *
0113      * For example, if a new host is connected to network and
0114      * announces services of several new types,
0115      * they will be reported by several serviceTypeAdded() signals
0116      * and the whole batch will be concluded by finished().
0117      *
0118      * This signal can be used by applications that just want to
0119      * get a list of the currently available service types
0120      * (similar to a directory listing) and do not care about
0121      * adding or removing service types that appear or disappear later.
0122      *
0123      * @see serviceTypeAdded() and serviceTypeRemoved()
0124      */
0125     void finished();
0126 
0127 private:
0128     friend class ServiceTypeBrowserPrivate;
0129     std::unique_ptr<ServiceTypeBrowserPrivate> const d;
0130     Q_DECLARE_PRIVATE_D(d, ServiceTypeBrowser)
0131 };
0132 
0133 }
0134 
0135 #endif