1/*
2 This file is part of the KDE project
3
4 SPDX-FileCopyrightText: 2004, 2005 Jakub Stachowski <qbast@go2.pl>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KDNSSDREMOTESERVICE_H
10#define KDNSSDREMOTESERVICE_H
11
12#include "servicebase.h"
13#include <QMetaType>
14#include <QObject>
15
16namespace KDNSSD
17{
18class RemoteServicePrivate;
19
20/*!
21 * \class KDNSSD::RemoteService
22 * \inmodule KDNSSD
23 * \inheaderfile KDNSSD/RemoteService
24 *
25 * \brief Describes a service published over DNS-SD,
26 * typically on a remote machine.
27 *
28 * This class allows delayed or asynchronous resolution of
29 * services. As the name suggests, the service is normally
30 * on a remote machine, but the service could just as easily
31 * be published on the local machine.
32 *
33 * RemoteService instances are normally provided by ServiceBrowser,
34 * but can be used to resolve any service if you know the name, type
35 * and domain for it.
36 *
37 * \sa ServiceBrowser
38 */
39class KDNSSD_EXPORT RemoteService : public QObject, public ServiceBase
40{
41 Q_OBJECT
42
43public:
44 typedef QExplicitlySharedDataPointer<RemoteService> Ptr;
45
46 /*!
47 * Creates an unresolved RemoteService representing the service with
48 * the given name, type and domain.
49 *
50 * \a name is the name of the service
51 *
52 * \a type is the type of the service (see ServiceBrowser::ServiceBrowser())
53 *
54 * \a domain is the domain of the service
55 *
56 * \sa ServiceBrowser::isAvailable()
57 */
58 RemoteService(const QString &name, const QString &type, const QString &domain);
59
60 ~RemoteService() override;
61
62 /*!
63 * Resolves the host name and port of service asynchronously.
64 *
65 * \note The host name is not resolved into an IP address - use KResolver
66 * for that.
67 *
68 * The resolved() signal will be emitted when the
69 * resolution is complete, or when it fails.
70 *
71 * \note resolved() may be emitted before this function
72 * returns in case of immediate failure.
73 *
74 * RemoteService will keep monitoring the service for
75 * changes in hostname and port, and re-emit resolved()
76 * when either changes.
77 *
78 * \sa resolve(), hostName(), port()
79 */
80 void resolveAsync();
81
82 /*!
83 * Resolves the host name and port of service synchronously.
84 *
85 * The host name is not resolved into an IP address - use KResolver
86 * for that.
87 *
88 * \note resolved() is emitted before this function is returned.
89 *
90 * resolve() will not cause RemoteService to monitor for changes
91 * in the hostname or port of the service.
92 *
93 * Returns \c true if successful, \c false on failure
94 *
95 * \sa resolveAsync(), hostName(), port()
96 */
97 bool resolve();
98
99 /*!
100 * Whether the service has been successfully resolved.
101 *
102 * Returns \c true if hostName() and port() will return
103 * valid values, \c false otherwise
104 */
105 bool isResolved() const;
106
107Q_SIGNALS:
108 /*!
109 * Emitted when resolving is complete
110 *
111 * If operating in asynchronous mode this signal can be
112 * emitted several times (when the hostName or port of
113 * the service changes).
114 *
115 * \a successful is \c true if the hostName and port were
116 * successfully resolved, \c false otherwise
117 *
118 */
119 void resolved(bool successful);
120
121protected:
122 void virtual_hook(int id, void *data) override;
123
124private:
125 friend class RemoteServicePrivate;
126};
127
128}
129
130Q_DECLARE_METATYPE(KDNSSD::RemoteService::Ptr)
131
132#endif
133

source code of kdnssd/src/remoteservice.h