6 import dbus.mainloop.glib
8 from dbus.lowlevel import MethodCallMessage, HANDLER_RESULT_NOT_YET_HANDLED
10 def extract_list(list):
13 if type(i).__name__ == 'Dictionary':
14 val += extract_values(i)
15 elif type(i).__name__ == 'Struct':
16 val += extract_list(i)
22 def extract_values(values):
24 for key in values.keys():
25 val += " " + key + "="
26 if key in ["ProtocolFamily"]:
27 val += "%s" % (int(values[key]))
28 elif key in ["IPv4", "IPv6"]:
29 val += extract_values(values[key])
31 val += str(values[key])
35 def extract(name, value):
40 elif name in ["IPv4", "IPv6" ]:
41 val = extract_values(value)
42 elif name in ["UserRoutes", "ServerRoutes", "Nameservers"]:
43 val = extract_list(value)
49 def property_changed(name, value, path, interface):
50 iface = interface[interface.rfind(".") + 1:]
51 val = extract(name, value)
53 print "{%s} [%s] %s = %s" % (iface, path, name, val)
55 def message_filter(connection, message):
56 if not isinstance(message, MethodCallMessage):
57 return HANDLER_RESULT_NOT_YET_HANDLED
59 interface = message.get_interface()
60 path = message.get_path()
61 name = message.get_member()
62 args = message.get_args_list()
64 property_changed(name, args, path, interface)
66 if __name__ == '__main__':
67 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
69 bus = dbus.SystemBus()
71 bus.add_signal_receiver(property_changed,
72 bus_name="net.connman.vpn",
73 signal_name = "PropertyChanged",
75 interface_keyword="interface")
77 bus.add_message_filter(message_filter)
79 mainloop = gobject.MainLoop()