KDNSSD::ServiceBrowser

#include <KDNSSD/ServiceBrowser>

Inheritance diagram for KDNSSD::ServiceBrowser:

Public Types

enum  State { Working, Stopped, Unsupported }
 

Signals

void finished ()
 
void serviceAdded (KDNSSD::RemoteService::Ptr service)
 
void serviceRemoved (KDNSSD::RemoteService::Ptr service)
 

Public Member Functions

 ServiceBrowser (const QString &type, bool autoResolve=false, const QString &domain=QString(), const QString &subtype=QString())
 
bool isAutoResolving () const
 
QList< RemoteService::Ptrservices () const
 
virtual void startBrowse ()
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static QString getLocalHostName ()
 
static State isAvailable ()
 
static QHostAddress resolveHostName (const QString &hostname)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

virtual void virtual_hook (int, void *)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

Browses for network services advertised over DNS-SD.

This is the central class in the KDNSSD library for applications that want to discover services on network.

Suppose that you need list of web servers running. Then you might do something like

KDNSSD::ServiceBrowser *browser = new KDNSSD::ServiceBrowser(QStringLiteral("_http._tcp"));
this, [](KDNSSD::RemoteService::Ptr service) {
});
this, [](KDNSSD::RemoteService::Ptr service) {
});
browser->startBrowse();

In above example addService() will be called for every web server already running and for every web service that subsequently appears on the network and delService() will be called when a server previously advertised is stopped.

Because no domain was passed to constructor, the default domain will be searched. To find other domains to browse for services on, use DomainBrowser.

Author
Jakub Stachowski

Definition at line 53 of file servicebrowser.h.

Member Enumeration Documentation

Availability of DNS-SD services.

Enumerator
Working 

the service is available

Stopped 

not available because mDnsd or Avahi daemon is not running

Unsupported 

not available because KDE was compiled without DNS-SD support

Definition at line 61 of file servicebrowser.h.

Constructor & Destructor Documentation

KDNSSD::ServiceBrowser::ServiceBrowser ( const QString type,
bool  autoResolve = false,
const QString domain = QString(),
const QString subtype = QString() 
)
explicit

Create a ServiceBrowser for a particular service type.

DomainBrowser can be used to find other domains to browse on. If no domain is given, the default domain is used.

The service type is the high-level protocol type, followed by a dot, followed by the transport protocol type (_tcp or _udp). The DNS-SD website maintains a full list of service types.

The subtype parameter allows you to do more fine-grained filtering on the services you are interested in. So you might request only FTP servers that allow anonymous access by passing "_ftp._tcp" as the type and "_anon" as the subtype. Subtypes are particularly important for types like _soap and _upnp, which are far too generic for most applications. In these cases, the subtype can be used to specify the particular SOAP or UPnP protocol they want.

Warning
Enabling autoResolve will increase network usage by resolving all services, so this feature should be used only when necessary.
Parameters
typeservice types to browse for (example: "_http._tcp")
autoResolvediscovered services will be resolved before being reported with the serviceAdded() signal
domaina domain to search on instead of the default one
subtypeonly browse for a specific subtype
See also
startBrowse() and isAvailable()

Definition at line 21 of file avahi-servicebrowser.cpp.

Member Function Documentation

void KDNSSD::ServiceBrowser::finished ( )
signal

Emitted when the list of published services has settled.

This signal is emitted once after startBrowse() is called when all the services of the requested type that are currently published have been reported (even if none are available or the DNS-SD service is not available). It is emitted again when a new batch of services become available or disappear.

For example, if a new host is connected to network and announces some services watched for by this ServiceBrowser, they will be reported by one or more serviceAdded() signals and the whole batch will be concluded by finished().

This signal can be used by applications that just want to get a list of the currently available services (similar to a directory listing) and do not care about adding or removing services that appear or disappear later.

Warning
There is no guarantee any RemoteService pointers received by serviceAdded() will be valid by the time this signal is emitted, so you should either do all your work involving them in the slot receiving the serviceAdded() signal, or you should listen to serviceRemoved() as well.
See also
serviceAdded() and serviceRemoved()
QString KDNSSD::ServiceBrowser::getLocalHostName ( )
static

The mDNS hostname of the local machine.

Usually this will return the same as QHostInfo::localHostName(), but it may be changed to something different in the Avahi configuration file (if using the Avahi backend).

Returns
the hostname, or an empty string on failure
Since
4.2

Definition at line 252 of file avahi-servicebrowser.cpp.

bool KDNSSD::ServiceBrowser::isAutoResolving ( ) const

Whether discovered services are resolved before being reported.

Returns
the value of the autoResolve parameter passed to the constructor
Since
4.1

Definition at line 42 of file avahi-servicebrowser.cpp.

ServiceBrowser::State KDNSSD::ServiceBrowser::isAvailable ( )
static

Checks availability of DNS-SD services.

Although this method is part of ServiceBrowser, none of the classes in this library will be able to perform their intended function if this method does not return Working.

If this method does not return Working, it is still safe to call any of the methods in this library. However, no services will be found or published and no domains will be found.

If you use this function to report an error to the user, below is a suggestion on how to word the errors when publishing a service. The first line of each error message can also be used for reporting errors when browsing for services.

return "";
return i18n("<p>The Zeroconf daemon is not running. See the Service"
" Discovery Handbook for more information.<br/>"
"Other users will not see the services provided by this
" system when browsing the network via zeroconf, but "
" normal access will still work.</p>");
case KDNSSD::ServiceBrowser::Unsupported:
return i18n("<p>Zeroconf support is not available in this version of KDE."
" See the Service Discovery Handbook for more information.<br/>"
"Other users will not see the services provided by this
" application when browsing the network via zeroconf, but "
" normal access will still work.</p>");
default:
return i18n("<p>Unknown error with Zeroconf.<br/>"
"Other users will not see the services provided by this
" application when browsing the network via zeroconf, but "
" normal access will still work.</p>");
}

Definition at line 31 of file avahi-servicebrowser.cpp.

QHostAddress KDNSSD::ServiceBrowser::resolveHostName ( const QString hostname)
static

Resolves an mDNS hostname into an IP address.

This function is very rarely useful, since a properly configured system is able to resolve an mDNS-based host name using the system resolver (ie: you can just pass the mDNS hostname to KIO or other library).

Parameters
hostnamethe hostname to be resolved
Returns
a QHostAddress containing the IP address, or QHostAddress() if resolution failed
Since
4.2

Definition at line 233 of file avahi-servicebrowser.cpp.

void KDNSSD::ServiceBrowser::serviceAdded ( KDNSSD::RemoteService::Ptr  service)
signal

Emitted when new service is discovered.

If isAutoResolving() returns true, this will not be emitted until the service has been resolved.

Parameters
servicea RemoteService object describing the service
See also
serviceRemoved() and finished()
void KDNSSD::ServiceBrowser::serviceRemoved ( KDNSSD::RemoteService::Ptr  service)
signal

Emitted when a service is no longer published over DNS-SD.

The RemoteService object is removed from the services() list and deleted immediately after this signal returns.

Warning
Do not use a delayed connection with this signal
Parameters
servicea RemoteService object describing the service
See also
serviceAdded() and finished()
QList< RemoteService::Ptr > KDNSSD::ServiceBrowser::services ( ) const

The currently known services of the specified type.

Returns
a list of RemoteService pointers
See also
serviceAdded() and serviceRemoved()

Definition at line 225 of file avahi-servicebrowser.cpp.

void KDNSSD::ServiceBrowser::startBrowse ( )
virtual

Starts browsing for services.

Only the first call to this function will have any effect.

Browsing stops when the ServiceBrowser object is destroyed.

Warning
The serviceAdded() signal may be emitted before this function returns.
See also
serviceAdded(), serviceRemoved() and finished()

Definition at line 47 of file avahi-servicebrowser.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 6 2020 22:39:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.