KDE 4.2 PyKDE API Reference

- KDE's Python API

# PublicService Class Reference

`from PyKDE4.dnssd import *`

Inherits: QObject,DNSSD.ServiceBase → QSharedData
Namespace: DNSSD

## Detailed Description

PublicService publicservice.h DNSSD/PublicService Represents a service to be published

This class allows you to publish the existance of a network service provided by your application.

If you are providing a web server and want to advertise it on the local network, you might do

     DNSSD.PublicService *service = new DNSSD.PublicService("My files", "_http._tcp", 80);
     bool isOK = service->publish();

In this example publish() is synchronous: it will not return until publishing is complete. This is usually not too long but it can freeze an application's GUI for a moment. To publish asynchronously instead, do:

     DNSSD.PublicService *service = new DNSSD.PublicService("My files", "_http._tcp", 80);
     connect(service, SIGNAL(published(bool)), this, SLOT(wasPublished(bool)));
     service->publishAsync();

Author:
  Jakub Stachowski

## Signals

| published (bool successful)

## Methods

| __init__ (self, QString name=QString(), QString type=QString(), long port=0, QString domain=QString(), QStringList subtypes=QStringList())
bool | isPublished (self)
bool | publish (self)
| publishAsync (self)
| published (self, bool successful)
| setDomain (self, QString domain)
| setPort (self, long port)
| setServiceName (self, QString serviceName)
| setSubTypes (self, QStringList subtypes)
| setTextData (self, QMap<QString,QByteArray> textData)
| setType (self, QString type)
| stop (self)
QStringList | subtypes (self)
| virtual_hook (self, int a0, void a1)

## Method Documentation

__init__ | ( | self, |
|  | QString | name=QString(),
|  | QString | type=QString(),
|  | long | port=0,
|  | QString | domain=QString(),
|  | QStringList | subtypes=QStringList()
| ) |  |  |

Creates a service description that can be published

If no name is given, the computer name is used instead. If there is already a service with the same name, type and domain a number will be appended to the name to make it unique.

If no domain is specified, the service is published on the link-local domain (.local).

The subtypes can be used to specify server attributes, such as "_anon" for anonymous FTP servers, or can specify a specific protocol (such as a web service interface) on top of a generic protocol like SOAP.

There is a comprehensive list of possible types available, but you are largely on your own for subtypes.

Parameters:

  | name | a service name to use instead of the computer name
  | type | service type, in the form _sometype._udp or _sometype._tcp
  | port | port number, or 0 to "reserve" the service name
  | domain | the domain to publish the service on (see DomainBrowser)
  | subtypes | optional list of subtypes, each with a leading underscore

See also:
  ServiceBrowser.ServiceBrowser()

bool isPublished | ( |  | self ) |

Whether the service is currently published

Returns:
  true if the service is being published to the domain,

false otherwise

bool publish | ( |  | self ) |

Publish the service synchronously

The method will not return (and hence the application interface will freeze, since KDElibs code should be executed in the main thread) until either the service is published or publishing fails.

published(bool) is emitted before this method returns.

Returns:
  true if the service was successfully published, false otherwise

publishAsync | ( |  | self ) |

Publish the service asynchronously

Returns immediately and emits published(bool) when completed. Note that published(bool) may be emitted before this method returns when an error is detected immediately.

published | ( | self, |
|  | bool | successful
| ) |  |  |

Emitted when publishing is complete

It will also emitted when an already-published service is republished after a property of the service (such as the name or port) is changed.

Signal syntax:
  `QObject.connect(source, SIGNAL("published(bool)"), target_slot)`

setDomain | ( | self, |
|  | QString | domain
| ) |  |  |

Sets the domain where the service is published

"local." means link-local, ie: the IP subnet on the LAN containing this computer.

If service is already published, it will be removed from the current domain and published on domain instead.

Parameters:

  | domain | the new domain to publish the service on

setPort | ( | self, |
|  | long | port
| ) |  |  |

Sets the port

If the service is already published, it will be re-announced with the new port.

Parameters:

  | port | the port of the service, or 0 to simply "reserve" the name

setServiceName | ( | self, |
|  | QString | serviceName
| ) |  |  |

Sets the name of the service

If the service is already published, it will be re-announced with the new name.

Parameters:

  | serviceName | the new name of the service

setSubTypes | ( | self, |
|  | QStringList | subtypes
| ) |  |  |

Sets the subtypetypes of the service

If the service is already published, it will be re-announced with the new subtypes.

The existing list of substypes is replaced, so an empty list will cause all existing subtypes to be removed.

Parameters:

  | subtypes | the new list of subtypes

setTextData | ( | self, |
|  | QMap<QString,QByteArray> | textData
| ) |  |  |

Sets new text properties

If the service is already published, it will be re-announced with the new data.

Parameters:

  | textData | the new text properties for the service

See also:
  ServiceBase.textData()

setType | ( | self, |
|  | QString | type
| ) |  |  |

Sets the service type

If the service is already published, it will be re-announced with the new type.

Parameters:

  | type | the new type of the service

See PublicService() for details on the format of type

stop | ( |  | self ) |

Stops publishing or aborts an incomplete publish request.

Useful when you want to disable the service for some time.

Note that if you stop providing a service (without exiting the application), you should stop publishing it.

QStringList subtypes | ( |  | self ) |

The subtypes of service.

See also:
  setSubTypes()

virtual_hook | ( | self, |
|  | int | a0,
|  | void | a1
| ) |  |  |