| 1 | /* |
| 2 | This file is part of the KDE project |
| 3 | |
| 4 | SPDX-FileCopyrightText: 2004 Jakub Stachowski <qbast@go2.pl> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef KDNSSDSERVICETYPEBROWSER_H |
| 10 | #define KDNSSDSERVICETYPEBROWSER_H |
| 11 | |
| 12 | #include "remoteservice.h" |
| 13 | #include <QObject> |
| 14 | #include <QtContainerFwd> |
| 15 | #include <memory> |
| 16 | |
| 17 | namespace KDNSSD |
| 18 | { |
| 19 | class ServiceTypeBrowserPrivate; |
| 20 | |
| 21 | /*! |
| 22 | * \class KDNSSD::ServiceTypeBrowser |
| 23 | * \inmodule KDNSSD |
| 24 | * \inheaderfile KDNSSD/ServiceTypeBrowser |
| 25 | * |
| 26 | * \brief Browses the service types being published on a domain. |
| 27 | * |
| 28 | * This class is mostly useful for generic utilities for |
| 29 | * browsing all the published service types on a local network. |
| 30 | * Applications that wish to find out about available services |
| 31 | * of a particular type (such as web servers) should use |
| 32 | * ServiceBrowser. |
| 33 | * |
| 34 | * ServiceTypeBrowser provides a list of all the service types |
| 35 | * published by at least one service on a given domain. |
| 36 | */ |
| 37 | class KDNSSD_EXPORT ServiceTypeBrowser : public QObject |
| 38 | { |
| 39 | Q_OBJECT |
| 40 | |
| 41 | public: |
| 42 | /*! |
| 43 | * Creates a ServiceTypeBrowser for a domain. |
| 44 | * |
| 45 | * The link-local domain (the LAN subnet for this computer) will |
| 46 | * be used if no \a domain is given. DomainBrowser can be used |
| 47 | * to get a list of browsing domains. |
| 48 | * |
| 49 | * Note that WAN domains may not support service type browsing. |
| 50 | * |
| 51 | * \a domain is a browsing domain to search |
| 52 | * |
| 53 | * \a parent is the parent object (see QObject documentation) |
| 54 | * |
| 55 | * \sa startBrowse() and ServiceBrowser::isAvailable() |
| 56 | */ |
| 57 | explicit ServiceTypeBrowser(const QString &domain = QString(), QObject *parent = nullptr); |
| 58 | |
| 59 | ~ServiceTypeBrowser() override; |
| 60 | |
| 61 | /*! |
| 62 | * All the service types currently being published. |
| 63 | * |
| 64 | * Returns a list of service types, in the form \c {_type._tcp} or \c {_type._udp} |
| 65 | */ |
| 66 | QStringList serviceTypes() const; |
| 67 | |
| 68 | /*! |
| 69 | * Starts browsing for published services. |
| 70 | * |
| 71 | * \note Only the first call to this function will have any effect. |
| 72 | * |
| 73 | * Browsing stops when the ServiceTypeBrowser object is destroyed. |
| 74 | * |
| 75 | * \warning The serviceTypeAdded() signal may be emitted before this |
| 76 | * function returns. |
| 77 | * |
| 78 | * \sa serviceTypeAdded(), serviceTypeRemoved() and finished() |
| 79 | */ |
| 80 | void startBrowse(); |
| 81 | |
| 82 | Q_SIGNALS: |
| 83 | /*! |
| 84 | * Emitted when there are no more services of this type. |
| 85 | * |
| 86 | * \warning |
| 87 | * This signal is not reliable: it is possible that it will not be |
| 88 | * emitted even after last service of this type disappeared |
| 89 | * |
| 90 | * \a type is the service type |
| 91 | * |
| 92 | * \sa serviceTypeAdded() and finished() |
| 93 | */ |
| 94 | void serviceTypeRemoved(const QString &type); |
| 95 | |
| 96 | /*! |
| 97 | * A new type of service has been found. |
| 98 | * |
| 99 | * \a type is the service type |
| 100 | * |
| 101 | * \sa serviceTypeAdded() and finished() |
| 102 | */ |
| 103 | void serviceTypeAdded(const QString &type); |
| 104 | |
| 105 | /*! |
| 106 | * Emitted when the list of published service types has settled. |
| 107 | * |
| 108 | * \note |
| 109 | * This signal is emitted once after startBrowse() is called |
| 110 | * when the types of all the services that are |
| 111 | * currently published have been reported (even if no services |
| 112 | * are available or the DNS-SD service is not available). |
| 113 | * It is emitted again when a new batch of service types become |
| 114 | * available or disappear. |
| 115 | * |
| 116 | * For example, if a new host is connected to network and |
| 117 | * announces services of several new types, |
| 118 | * they will be reported by several serviceTypeAdded() signals |
| 119 | * and the whole batch will be concluded by finished(). |
| 120 | * |
| 121 | * This signal can be used by applications that just want to |
| 122 | * get a list of the currently available service types |
| 123 | * (similar to a directory listing) and do not care about |
| 124 | * adding or removing service types that appear or disappear later. |
| 125 | * |
| 126 | * \sa serviceTypeAdded() and serviceTypeRemoved() |
| 127 | */ |
| 128 | void finished(); |
| 129 | |
| 130 | private: |
| 131 | friend class ServiceTypeBrowserPrivate; |
| 132 | std::unique_ptr<ServiceTypeBrowserPrivate> const d; |
| 133 | Q_DECLARE_PRIVATE_D(d, ServiceTypeBrowser) |
| 134 | }; |
| 135 | |
| 136 | } |
| 137 | |
| 138 | #endif |
| 139 | |