summaryrefslogtreecommitdiffstats
path: root/avahi-daemon/dbus-test.py
blob: a5adc0f7af8d8a23a07af71cb641c6aa015aea3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python2.4

import dbus, gobject
try:
    import dbus.glib
except ImportError, e:
    pass

bus = dbus.SystemBus()
server = dbus.Interface(bus.get_object("org.freedesktop.Avahi", '/'), 'org.freedesktop.Avahi.Server')

def server_state_changed_callback(t):
    print "Server::StateChanged: ", t

server.connect_to_signal("StateChanged", server_state_changed_callback)

print "Version String: ", server.GetVersionString()

print server.ResolveHostName(0, 0, "ecstasy.local", 0)
print server.ResolveAddress(0, 0, "192.168.50.4")

print "Host name: %s" % server.GetHostName()
print "Domain name: %s" % server.GetDomainName()
print "FQDN: %s" % server.GetHostNameFqdn()
print "State: %i" % server.GetState()

n = server.GetNetworkInterfaceNameByIndex(2)
print "network: 2 -> %s -> %i" % (n, server.GetNetworkInterfaceIndexByName(n))

print server.GetAlternativeHostName("gurkiman10")
print server.GetAlternativeServiceName("Ahuga Service")

def entry_group_state_changed_callback(t):
    print "EntryGroup::StateChanged: ", t

    if t == 1:
        print server.ResolveHostName(0, 0, "foo.local", 0)
        
g = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.EntryGroupNew()), 'org.freedesktop.Avahi.EntryGroup')
g.connect_to_signal('StateChanged', entry_group_state_changed_callback)
g.AddService(0, 0, "Test Web Site", "_http._tcp", "", "", dbus.UInt16(4712), ["fuck=hallo", "gurke=mega"])
g.AddAddress(0, 0, "foo.local", "47.11.8.15")
g.Commit()

def domain_browser_callback(a, interface, protocol, domain):
    print "DOMAIN_BROWSER: %s %i %i %s" % (a, interface, protocol, domain)

db = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.DomainBrowserNew(0, 0, "", 2)), 'org.freedesktop.Avahi.DomainBrowser')
db.connect_to_signal('ItemNew', lambda interface, protocol, domain: domain_browser_callback("NEW", interface, protocol, domain))
db.connect_to_signal('ItemRemove', lambda interface, protocol, domain: domain_browser_callback("REMOVE", interface, protocol, domain))

def service_type_browser_callback(a, interface, protocol, type, domain):
    print "SERVICE_TYPE_BROWSER: %s %i %i %s %s" % (a, interface, protocol, type, domain)

stb = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.ServiceTypeBrowserNew(0, 0, "")), 'org.freedesktop.Avahi.ServiceTypeBrowser')
stb.connect_to_signal('ItemNew', lambda interface, protocol, type, domain: service_type_browser_callback("NEW", interface, protocol, type, domain))
stb.connect_to_signal('ItemRemove', lambda interface, protocol, type, domain: service_type_browser_callback("REMOVE", interface, protocol, type, domain))

def service_browser_callback(a, interface, protocol, name, type, domain):
    print "SERVICE_BROWSER: %s %i %i %s %s %s" % (a, interface, protocol, name, type, domain)

    if a == "NEW":
        print server.ResolveService(interface, protocol, name, type, domain, 0)

sb = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.ServiceBrowserNew(0, 0, "_http._tcp", "")), 'org.freedesktop.Avahi.ServiceBrowser')
sb.connect_to_signal('ItemNew', lambda interface, protocol, name, type, domain: service_browser_callback("NEW", interface, protocol, name, type, domain))
sb.connect_to_signal('ItemRemove', lambda interface, protocol, name, type, domain: service_browser_callback("REMOVE", interface, protocol, name, type, domain))

try:
    gobject.MainLoop().run()
except KeyboardInterrupt, k:
    pass

g.Free()
db.Free()
stb.Free()

print "Quit"