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