KDE 4.4 PyKDE API Reference
  • KDE's Python API
  • Overview
  • PyKDE Home
  • Sitemap
  • Contact Us
 

ServiceBrowser Class Reference

from PyKDE4.dnssd import *

Inherits: QObject
Namespace: DNSSD.ServiceBrowser

Detailed Description

ServiceBrowser servicebrowser.h DNSSD/ServiceBrowser Browses for network services advertised over DNS-SD

This is the central class in the DNSSD 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

 DNSSD.ServiceBrowser* browser = new DNSSD.ServiceBrowser("_http._tcp");
 connect(browser, SIGNAL(serviceAdded(RemoteService.Ptr)),
         this,    SLOT(addService(RemoteService.Ptr)));
 connect(browser, SIGNAL(serviceRemoved(RemoteService.Ptr)),
         this,    SLOT(delService(RemoteService.Ptr)));
 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


Enumerations

State { Working, Stopped, Unsupported }

Signals

 finished ()
 serviceAdded (DNSSD.RemoteService.Ptr service)
 serviceRemoved (DNSSD.RemoteService.Ptr service)

Methods

 __init__ (self, QString type, bool autoResolve=0, QString domain=QString(), QString subtype=QString())
 finished (self)
QString getLocalHostName (self)
bool isAutoResolving (self)
DNSSD.ServiceBrowser.State isAvailable (self)
QHostAddress resolveHostName (self, QString hostname)
 serviceAdded (self, DNSSD.RemoteService.Ptr service)
 serviceRemoved (self, DNSSD.RemoteService.Ptr service)
[DNSSD.RemoteService.Ptr] services (self)
 startBrowse (self)
 virtual_hook (self, int a0, void a1)

Method Documentation

__init__ (  self,
QString  type,
bool  autoResolve=0,
QString  domain=QString(),
QString  subtype=QString()
)
finished (   self )

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()

Signal syntax:
QObject.connect(source, SIGNAL("finished()"), target_slot)
QString getLocalHostName (   self )

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

bool isAutoResolving (   self )

Whether discovered services are resolved before being reported

Returns:
the value of the autoResolve parameter passed to the constructor

Since:
4.1

DNSSD.ServiceBrowser.State isAvailable (   self )

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.

 switch(DNSSD.ServiceBrowser.isAvailable()) {
 case DNSSD.ServiceBrowser.Working:
     return "";
 case DNSSD.ServiceBrowser.Stopped:
     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 DNSSD.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>");
 }

QHostAddress resolveHostName (  self,
QString  hostname
)

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:
hostname  the hostname to be resolved

Returns:
a QHostAddress containing the IP address, or QHostAddress() if resolution failed
Since:
4.2

serviceAdded (  self,
DNSSD.RemoteService.Ptr  service
)

Emitted when new service is discovered

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

Parameters:
service  a RemoteService object describing the service

See also:
serviceRemoved() and finished()

Signal syntax:
QObject.connect(source, SIGNAL("serviceAdded(DNSSD::RemoteService::Ptr)"), target_slot)
serviceRemoved (  self,
DNSSD.RemoteService.Ptr  service
)

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:
service  a RemoteService object describing the service

See also:
serviceAdded() and finished()

Signal syntax:
QObject.connect(source, SIGNAL("serviceRemoved(DNSSD::RemoteService::Ptr)"), target_slot)
[DNSSD.RemoteService.Ptr] services (   self )

The currently known services of the specified type

Returns:
a list of RemoteService pointers

See also:
serviceAdded() and serviceRemoved()

startBrowse (   self )

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()

virtual_hook (  self,
int  a0,
void  a1
)

Enumeration Documentation

State
Enumerator:

  • Full Index

Modules

  • akonadi
  • dnssd
  • kdecore
  • kdeui
  • khtml
  • kio
  • knewstuff
  • kparts
  • kutils
  • nepomuk
  • phonon
  • plasma
  • polkitqt
  • solid
  • soprano
This documentation is maintained by Simon Edwards.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal