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, 2005 Jakub Stachowski <qbast@go2.pl> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KDNSSDREMOTESERVICE_H 0010 #define KDNSSDREMOTESERVICE_H 0011 0012 #include "servicebase.h" 0013 #include <QMetaType> 0014 #include <QObject> 0015 0016 namespace KDNSSD 0017 { 0018 class RemoteServicePrivate; 0019 0020 /** 0021 * @class RemoteService remoteservice.h KDNSSD/RemoteService 0022 * @short Describes a service published over DNS-SD, 0023 * typically on a remote machine 0024 * 0025 * This class allows delayed or asynchronous resolution of 0026 * services. As the name suggests, the service is normally 0027 * on a remote machine, but the service could just as easily 0028 * be published on the local machine. 0029 * 0030 * RemoteService instances are normally provided by ServiceBrowser, 0031 * but can be used to resolve any service if you know the name, type 0032 * and domain for it. 0033 * 0034 * @author Jakub Stachowski 0035 * 0036 * @see ServiceBrowser 0037 */ 0038 class KDNSSD_EXPORT RemoteService : public QObject, public ServiceBase 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 typedef QExplicitlySharedDataPointer<RemoteService> Ptr; 0044 0045 /** 0046 * Creates an unresolved RemoteService representing the service with 0047 * the given name, type and domain 0048 * 0049 * @param name the name of the service 0050 * @param type the type of the service (see ServiceBrowser::ServiceBrowser()) 0051 * @param domain the domain of the service 0052 * 0053 * @see ServiceBrowser::isAvailable() 0054 */ 0055 RemoteService(const QString &name, const QString &type, const QString &domain); 0056 0057 ~RemoteService() override; 0058 0059 /** 0060 * Resolves the host name and port of service asynchronously 0061 * 0062 * The host name is not resolved into an IP address - use KResolver 0063 * for that. 0064 * 0065 * The resolved(bool) signal will be emitted when the 0066 * resolution is complete, or when it fails. 0067 * 0068 * Note that resolved(bool) may be emitted before this function 0069 * returns in case of immediate failure. 0070 * 0071 * RemoteService will keep monitoring the service for 0072 * changes in hostname and port, and re-emit resolved(bool) 0073 * when either changes. 0074 * 0075 * @see resolve(), hostName(), port() 0076 */ 0077 void resolveAsync(); 0078 0079 /** 0080 * Resolves the host name and port of service synchronously 0081 * 0082 * The host name is not resolved into an IP address - use KResolver 0083 * for that. 0084 * 0085 * resolved(bool) is emitted before this function is returned. 0086 * 0087 * resolve() will not cause RemoteService to monitor for changes 0088 * in the hostname or port of the service. 0089 * 0090 * @return @c true if successful, @c false on failure 0091 * 0092 * @see resolveAsync(), hostName(), port() 0093 */ 0094 bool resolve(); 0095 0096 /** 0097 * Whether the service has been successfully resolved 0098 * 0099 * @return @c true if hostName() and port() will return 0100 * valid values, @c false otherwise 0101 */ 0102 bool isResolved() const; 0103 0104 Q_SIGNALS: 0105 /** 0106 * Emitted when resolving is complete 0107 * 0108 * If operating in asynchronous mode this signal can be 0109 * emitted several times (when the hostName or port of 0110 * the service changes). 0111 * 0112 * @param successful @c true if the hostName and port were 0113 * successfully resolved, @c false otherwise 0114 */ 0115 void resolved(bool successful); 0116 0117 protected: 0118 void virtual_hook(int id, void *data) override; 0119 0120 private: 0121 friend class RemoteServicePrivate; 0122 }; 0123 0124 } 0125 0126 Q_DECLARE_METATYPE(KDNSSD::RemoteService::Ptr) 0127 0128 #endif