~vorlon/ubuntu/saucy/gourmet/trunk

« back to all changes in this revision

Viewing changes to src/lib/avahi_interface.py

  • Committer: Bazaar Package Importer
  • Author(s): Rolf Leggewie
  • Date: 2008-07-26 13:29:41 UTC
  • Revision ID: james.westby@ubuntu.com-20080726132941-6ldd73qmacrzz0bn
Tags: upstream-0.14.0
ImportĀ upstreamĀ versionĀ 0.14.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import dbus
 
2
import avahi
 
3
import gobject
 
4
import dbus.glib
 
5
 
 
6
bus = dbus.SystemBus()
 
7
server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
 
8
 
 
9
def new_service(interface, protocol, name, type, domain, flags):
 
10
    interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags = server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0))
 
11
    print "Found service '%s' of type '%s' in domain '%s' at address '%s:%s'" % (name, type, domain, address, port)
 
12
 
 
13
def remove_service(interface, protocol, name, type, domain):
 
14
    print "Service '%s' of type '%s' in domain '%s' disappeared." % (name, type, domain)
 
15
 
 
16
stype = '_daap._tcp'
 
17
domain = 'local'
 
18
browser = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype, domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
 
19
 
 
20
browser.connect_to_signal('ItemNew', new_service)
 
21
browser.connect_to_signal('ItemRemove', remove_service)
 
22
gobject.MainLoop().run()
 
23