Add decoding support for IPv6 properties
[platform/upstream/connman.git] / test / monitor-services
1 #!/usr/bin/python
2
3 import gobject
4
5 import dbus
6 import dbus.mainloop.glib
7
8 def extract_values(values):
9         val = "{"
10         for key in values.keys():
11                 val += " " + key + "="
12                 val += str(values[key])
13         val += " }"
14         return val
15
16 def extract_list(list):
17         val = "["
18         for i in list:
19                 val += " " + str(i)
20         val += " ]"
21         return val
22
23 def property_changed(name, value, path):
24         service = path[path.rfind("/") + 1:]
25         if name in ["Profiles", "Services", "Providers", "Technologies",
26                                                 "Devices", "Networks"]:
27                 val = "["
28                 for i in value:
29                         val = val + " " + i[i.rfind("/") + 1:]
30                 val = val + " ]"
31         elif name in ["IPv4", "IPv4.Configuration",
32                                 "IPv6", "IPv6.Configuration",
33                                                 "Proxy", "Ethernet"]:
34                 val = extract_values(value)
35         elif name in ["Nameservers", "Nameservers.Configuration",
36                                         "Domains", "Domains.Configuration"]:
37                 val = extract_list(value)
38         elif name in ["Strength", "Priority"]:
39                 val = int(value)
40         else:
41                 val = str(value)
42         print "[%s] %s = %s" % (service, name, val)
43
44 if __name__ == '__main__':
45         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
46
47         bus = dbus.SystemBus()
48
49         bus.add_signal_receiver(property_changed,
50                                 bus_name="org.moblin.connman",
51                                 dbus_interface="org.moblin.connman.Service",
52                                 signal_name = "PropertyChanged",
53                                 path_keyword="path")
54
55         mainloop = gobject.MainLoop()
56         mainloop.run()