Fix service property monitoring handling
[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 property_changed(name, value, path):
17         service = path[path.rfind("/") + 1:]
18         if name in ["Profiles", "Services", "Providers", "Technologies",
19                                                 "Devices", "Networks"]:
20                 val = "["
21                 for i in value:
22                         val = val + " " + i[i.rfind("/") + 1:]
23                 val = val + " ]"
24         elif name in ["IPv4", "IPv4.Configuration", "Proxy", "Ethernet"]:
25                 val = extract_values(value)
26         elif name in ["Strength", "Priority"]:
27                 val = int(value)
28         else:
29                 val = str(value)
30         print "[%s] %s = %s" % (service, name, val)
31
32 if __name__ == '__main__':
33         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
34
35         bus = dbus.SystemBus()
36
37         bus.add_signal_receiver(property_changed,
38                                 bus_name="org.moblin.connman",
39                                 dbus_interface="org.moblin.connman.Service",
40                                 signal_name = "PropertyChanged",
41                                 path_keyword="path")
42
43         mainloop = gobject.MainLoop()
44         mainloop.run()