]> git.meshlink.io Git - catta/blob - avahi-daemon/dbus-test.py
Add init script support for fedora from Alexander Larsson
[catta] / avahi-daemon / dbus-test.py
1 #!/usr/bin/python2.4
2
3 import dbus, gobject
4 try:
5     import dbus.glib
6 except ImportError, e:
7     pass
8
9 bus = dbus.SystemBus()
10 server = dbus.Interface(bus.get_object("org.freedesktop.Avahi", '/'), 'org.freedesktop.Avahi.Server')
11
12 def server_state_changed_callback(t):
13     print "Server::StateChanged: ", t
14
15 server.connect_to_signal("StateChanged", server_state_changed_callback)
16
17 print "Version String: ", server.GetVersionString()
18
19 print server.ResolveHostName(0, 0, "ecstasy.local", 0)
20 print server.ResolveAddress(0, 0, "192.168.50.4")
21
22 print "Host name: %s" % server.GetHostName()
23 print "Domain name: %s" % server.GetDomainName()
24 print "FQDN: %s" % server.GetHostNameFqdn()
25 print "State: %i" % server.GetState()
26
27 n = server.GetNetworkInterfaceNameByIndex(2)
28 print "network: 2 -> %s -> %i" % (n, server.GetNetworkInterfaceIndexByName(n))
29
30 print server.GetAlternativeHostName("gurkiman10")
31 print server.GetAlternativeServiceName("Ahuga Service")
32
33 def entry_group_state_changed_callback(t):
34     print "EntryGroup::StateChanged: ", t
35
36     if t == 1:
37         print server.ResolveHostName(0, 0, "foo.local", 0)
38         
39 g = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.EntryGroupNew()), 'org.freedesktop.Avahi.EntryGroup')
40 g.connect_to_signal('StateChanged', entry_group_state_changed_callback)
41 g.AddService(0, 0, "Test Web Site", "_http._tcp", "", "", dbus.UInt16(4712), ["fuck=hallo", "gurke=mega"])
42 g.AddAddress(0, 0, "foo.local", "47.11.8.15")
43 g.Commit()
44
45 def domain_browser_callback(a, interface, protocol, domain):
46     print "DOMAIN_BROWSER: %s %i %i %s" % (a, interface, protocol, domain)
47
48 db = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.DomainBrowserNew(0, 0, "", 2)), 'org.freedesktop.Avahi.DomainBrowser')
49 db.connect_to_signal('ItemNew', lambda interface, protocol, domain: domain_browser_callback("NEW", interface, protocol, domain))
50 db.connect_to_signal('ItemRemove', lambda interface, protocol, domain: domain_browser_callback("REMOVE", interface, protocol, domain))
51
52 def service_type_browser_callback(a, interface, protocol, type, domain):
53     print "SERVICE_TYPE_BROWSER: %s %i %i %s %s" % (a, interface, protocol, type, domain)
54
55 stb = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.ServiceTypeBrowserNew(0, 0, "")), 'org.freedesktop.Avahi.ServiceTypeBrowser')
56 stb.connect_to_signal('ItemNew', lambda interface, protocol, type, domain: service_type_browser_callback("NEW", interface, protocol, type, domain))
57 stb.connect_to_signal('ItemRemove', lambda interface, protocol, type, domain: service_type_browser_callback("REMOVE", interface, protocol, type, domain))
58
59 def service_browser_callback(a, interface, protocol, name, type, domain):
60     print "SERVICE_BROWSER: %s %i %i %s %s %s" % (a, interface, protocol, name, type, domain)
61
62     if a == "NEW":
63         print server.ResolveService(interface, protocol, name, type, domain, 0)
64
65 sb = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.ServiceBrowserNew(0, 0, "_http._tcp", "")), 'org.freedesktop.Avahi.ServiceBrowser')
66 sb.connect_to_signal('ItemNew', lambda interface, protocol, name, type, domain: service_browser_callback("NEW", interface, protocol, name, type, domain))
67 sb.connect_to_signal('ItemRemove', lambda interface, protocol, name, type, domain: service_browser_callback("REMOVE", interface, protocol, name, type, domain))
68
69 try:
70     gobject.MainLoop().run()
71 except KeyboardInterrupt, k:
72     pass
73
74 g.Free()
75 db.Free()
76 stb.Free()
77
78 print "Quit"