diff options
| author | 2010-12-27 16:07:43 +0100 | |
|---|---|---|
| committer | 2010-12-27 16:07:43 +0100 | |
| commit | eb9d750f59161f2bf0a55b4e75b56e65e6f7b432 (patch) | |
| tree | 975a0e589eb2a1e2e1bcc7b253ffaa115b193ae3 /ZeroconfService.py | |
| download | totem-plugin-airplay-eb9d750f59161f2bf0a55b4e75b56e65e6f7b432.tar.gz totem-plugin-airplay-eb9d750f59161f2bf0a55b4e75b56e65e6f7b432.tar.bz2 | |
Initial commit of the sources
Diffstat (limited to 'ZeroconfService.py')
| -rw-r--r-- | ZeroconfService.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ZeroconfService.py b/ZeroconfService.py new file mode 100644 index 0000000..7b3257b --- /dev/null +++ b/ZeroconfService.py | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | import avahi | ||
| 2 | import dbus | ||
| 3 | |||
| 4 | __all__ = ["ZeroconfService"] | ||
| 5 | |||
| 6 | class ZeroconfService(object): | ||
| 7 | def __init__(self, name, port, stype="_http._tcp", domain="", host="", text=""): | ||
| 8 | self.name = name | ||
| 9 | self.stype = stype | ||
| 10 | self.domain = domain | ||
| 11 | self.host = host | ||
| 12 | self.port = port | ||
| 13 | self.text = text | ||
| 14 | |||
| 15 | def publish(self): | ||
| 16 | bus = dbus.SystemBus() | ||
| 17 | server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER) | ||
| 18 | |||
| 19 | g = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP) | ||
| 20 | g.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), self.name, self.stype, self.domain, self.host, dbus.UInt16(self.port), self.text) | ||
| 21 | |||
| 22 | g.Commit() | ||
| 23 | self.group = g | ||
| 24 | |||
| 25 | def unpublish(self): | ||
| 26 | if self.group is not None: | ||
| 27 | self.group.Reset() | ||
| 28 | |||
