From eb9d750f59161f2bf0a55b4e75b56e65e6f7b432 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Mon, 27 Dec 2010 16:07:43 +0100 Subject: Initial commit of the sources --- ZeroconfService.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ZeroconfService.py (limited to 'ZeroconfService.py') diff --git a/ZeroconfService.py b/ZeroconfService.py new file mode 100644 index 0000000..7b3257b --- /dev/null +++ b/ZeroconfService.py @@ -0,0 +1,28 @@ +import avahi +import dbus + +__all__ = ["ZeroconfService"] + +class ZeroconfService(object): + def __init__(self, name, port, stype="_http._tcp", domain="", host="", text=""): + self.name = name + self.stype = stype + self.domain = domain + self.host = host + self.port = port + self.text = text + + def publish(self): + bus = dbus.SystemBus() + server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER) + + g = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP) + 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) + + g.Commit() + self.group = g + + def unpublish(self): + if self.group is not None: + self.group.Reset() + -- cgit v1.1-32-gdbae