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