# class ServiceBrowser

###

Module | dnssd
Namespace | DNSSD
Class | ServiceBrowser
Inherits | QObject

\class ServiceBrowser servicebrowser.h DNSSD/ServiceBrowser

Most important class for applications that want to discover specific services on network. Suppose that you need list of web servers running. Example:

    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 or just appearing on network and delService will be called when server is stopped. Because no domain was passed to constructor, default domain will be searched.

Author Jakub Stachowski Browsing for specific type of services or all available service types

### enums

- State { Working, Stopped, Unsupported }

enum details

### methods

- ServiceBrowser (type, autoResolve, domain, subtype)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  type | QString |
  autoResolve | bool | 0
  domain | QString | QString()
  subtype | QString | QString()

  ServiceBrowser constructor.

  type - Service types to browse for (example: "_http._tcp").

  autoResolve - - after disovering new service it will be resolved and then reported with serviceAdded() signal. It raises network usage by resolving all services, so use it only when necessary.

  domain - Domain name. Can be left as null string to use default domain

  subtypes - Set it to browse only for specific subtype

- finished ( )

  returns Nothing
  SIGNAL ("finished ()")

  Emitted when all services has been reported. This signal can be used by application that just want to get list of currently available services (similar to directory listing) and do not care about dynamic adding/removing services later. This signal can be emitted many time: for example if new host has been connected to network and is announcing some services interesting to this ServiceBrowser, they will be reported by several serviceAdded() signals and whole batch will be concluded by finished().

- isAutoResolving ( )

  returns bool

  Returns true if newly discovered services are resolved before being reported with serviceAdded() \since 4.1

- isAvailable ( )

  returns DNSSD::ServiceBrowser.State
  static

  Checks availability of DNS-SD services (this also covers publishing).

  If you use this function to report an error to the user, below is a suggestion on how to word the errors:

      switch(DNSSD.ServiceBrowser.isAvailable()) {
      case DNSSD.ServiceBrowser.Working:
      return "";
      case DNSSD.ServiceBrowser.Stopped:
      return i18n("The Zeroconf daemon is not running. See the Service Discovery Handbook"
      " for more information.
      "
      "Other users will not see this system when browsing"
      " the network via zeroconf, but normal access will still work.");
      case DNSSD.ServiceBrowser.Unsupported:
      return i18n("Zeroconf support is not available in this version of KDE."
      " See the Service Discovery Handbook for more information.
      "
      "Other users will not see this system when browsing"
      " the network via zeroconf, but normal access will still work.");
      default:
      return i18n("Unknown error with Zeroconf.
      "
      "Other users will not see this system when browsing"
      " the network via zeroconf, but normal access will still work.");
      }

- serviceAdded (a0)

  returns Nothing
  SIGNAL ("serviceAdded (Ptr)")

  Argument | Type | Default
  --- | --- | ---
  a0 | DNSSD::RemoteService.Ptr |

  Emitted when new service is discovered (or resolved if autoresolve is set

- serviceRemoved (a0)

  returns Nothing
  SIGNAL ("serviceRemoved (Ptr)")

  Argument | Type | Default
  --- | --- | ---
  a0 | DNSSD::RemoteService.Ptr |

  Emitted when service is no longer announced. RemoteService object is deleted from services list and destroyed immediately after this signal returns.

- services ( )

  returns QList<DNSSD::RemoteService::Ptr>

  Returns list of services

- startBrowse ( )

  returns Nothing

  Starts browsing for services. To stop it just destroy the object.

- virtual_hook (a0, a1)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  a0 | int |
  a1 | void |

### enums - detail

- State { Working, Stopped, Unsupported }

  Availability of DNS-SD services.

- Working - available
- Stopped - not available because mdnsd daemon is not running. This flag is currently unused
- Unsupported - not available because KDE was compiled without DNS-SD support

| Working | - | - |
| Stopped | - | - |
| Unsupported | - | - |