KDNSSD

remoteservice.h
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 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 */
38class KDNSSD_EXPORT RemoteService : public QObject, public ServiceBase
39{
41
42public:
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
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
117protected:
118 void virtual_hook(int id, void *data) override;
119
120private:
121 friend class RemoteServicePrivate;
122};
123
124}
125
126Q_DECLARE_METATYPE(KDNSSD::RemoteService::Ptr)
127
128#endif
RemoteService(const QString &name, const QString &type, const QString &domain)
Creates an unresolved RemoteService representing the service with the given name, type and domain.
void resolveAsync()
Resolves the host name and port of service asynchronously.
bool isResolved() const
Whether the service has been successfully resolved.
void resolved(bool successful)
Emitted when resolving is complete.
bool resolve()
Resolves the host name and port of service synchronously.
ServiceBase(const QString &name=QString(), const QString &type=QString(), const QString &domain=QString(), const QString &host=QString(), unsigned short port=0)
Creates a ServiceBase object.
QString domain() const
The domain that the service belongs to.
QString type() const
The type of the service.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:52:52 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.