2016-08-06 17:49:21 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
from gi.repository import GLib
|
|
|
|
|
|
|
|
import dbus
|
|
|
|
import dbus.mainloop.glib
|
|
|
|
|
|
|
|
_dbus2py = {
|
2016-09-14 04:38:34 +02:00
|
|
|
dbus.String : str,
|
|
|
|
dbus.UInt32 : int,
|
|
|
|
dbus.Int32 : int,
|
|
|
|
dbus.Int16 : int,
|
|
|
|
dbus.UInt16 : int,
|
|
|
|
dbus.UInt64 : int,
|
|
|
|
dbus.Int64 : int,
|
|
|
|
dbus.Byte : int,
|
|
|
|
dbus.Boolean : bool,
|
|
|
|
dbus.ByteArray : str,
|
|
|
|
dbus.ObjectPath : str
|
|
|
|
}
|
2016-08-06 17:49:21 +02:00
|
|
|
|
|
|
|
def dbus2py(d):
|
2016-09-14 04:38:34 +02:00
|
|
|
t = type(d)
|
|
|
|
if t in _dbus2py:
|
|
|
|
return _dbus2py[t](d)
|
|
|
|
if t is dbus.Dictionary:
|
|
|
|
return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()])
|
|
|
|
if t is dbus.Array and d.signature == "y":
|
|
|
|
return "".join([chr(b) for b in d])
|
|
|
|
if t is dbus.Array or t is list:
|
|
|
|
return [dbus2py(v) for v in d]
|
|
|
|
if t is dbus.Struct or t is tuple:
|
|
|
|
return tuple([dbus2py(v) for v in d])
|
|
|
|
return d
|
2016-08-06 17:49:21 +02:00
|
|
|
|
|
|
|
def pretty(d):
|
2016-09-14 04:38:34 +02:00
|
|
|
d = dbus2py(d)
|
|
|
|
t = type(d)
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-14 04:38:34 +02:00
|
|
|
if t in (dict, tuple, list) and len(d) > 0:
|
|
|
|
if t is dict:
|
|
|
|
d = ", ".join(["%s = %s" % (k, pretty(v)) for k, v in d.items()])
|
|
|
|
return "{ %s }" % d
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-14 04:38:34 +02:00
|
|
|
d = " ".join([pretty(e) for e in d])
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-14 04:38:34 +02:00
|
|
|
if t is tuple:
|
|
|
|
return "( %s )" % d
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-14 04:38:34 +02:00
|
|
|
if t is str:
|
|
|
|
return "%s" % d
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-14 04:38:34 +02:00
|
|
|
return str(d)
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-21 18:51:56 +02:00
|
|
|
def properties_changed(interface, changed, invalidated, path):
|
2016-09-14 04:38:34 +02:00
|
|
|
iface = interface[interface.rfind(".") + 1:]
|
2016-09-21 18:51:56 +02:00
|
|
|
for name, value in changed.items():
|
|
|
|
print("{%s} [%s] %s = %s" % (iface, path, name, pretty(value)))
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-14 04:42:30 +02:00
|
|
|
relevant_ifaces = [ "net.connman.iwd.Device",
|
|
|
|
"net.connman.iwd.Adapter",
|
2019-10-24 17:43:08 +02:00
|
|
|
"net.connman.iwd.SimpleConfiguration",
|
2018-08-20 05:06:32 +02:00
|
|
|
"net.connman.iwd.AccessPoint",
|
|
|
|
"net.connman.iwd.AdHoc",
|
|
|
|
"net.connman.iwd.Network",
|
|
|
|
"net.connman.iwd.AgentManager",
|
2018-09-05 05:58:55 +02:00
|
|
|
"net.connman.iwd.KnownNetwork",
|
|
|
|
"net.connman.iwd.Station" ]
|
2016-09-14 04:42:30 +02:00
|
|
|
|
|
|
|
def interfaces_added(path, interfaces):
|
|
|
|
for iface, props in interfaces.items():
|
|
|
|
if not(iface in relevant_ifaces):
|
|
|
|
continue
|
|
|
|
|
|
|
|
print("{Added %s} [%s]" % (iface, path))
|
|
|
|
|
|
|
|
for name, value in props.items():
|
|
|
|
print(" %s = %s" % (name, pretty(value)))
|
|
|
|
|
|
|
|
def interfaces_removed(path, interfaces):
|
|
|
|
for iface in interfaces:
|
|
|
|
if not(iface in relevant_ifaces):
|
|
|
|
continue
|
|
|
|
|
|
|
|
print("{Removed %s} [%s]" % (iface, path))
|
|
|
|
|
2016-08-06 17:49:21 +02:00
|
|
|
if __name__ == '__main__':
|
2016-09-14 04:38:34 +02:00
|
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-14 04:38:34 +02:00
|
|
|
bus = dbus.SystemBus()
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-21 18:51:56 +02:00
|
|
|
bus.add_signal_receiver(properties_changed,
|
2016-09-14 04:38:34 +02:00
|
|
|
bus_name="net.connman.iwd",
|
2016-09-21 18:51:56 +02:00
|
|
|
dbus_interface="org.freedesktop.DBus.Properties",
|
|
|
|
signal_name="PropertiesChanged",
|
|
|
|
path_keyword="path")
|
2016-08-06 17:49:21 +02:00
|
|
|
|
2016-09-14 04:42:30 +02:00
|
|
|
bus.add_signal_receiver(interfaces_added, bus_name="net.connman.iwd",
|
|
|
|
dbus_interface="org.freedesktop.DBus.ObjectManager",
|
|
|
|
signal_name="InterfacesAdded")
|
|
|
|
|
|
|
|
bus.add_signal_receiver(interfaces_removed, bus_name="net.connman.iwd",
|
|
|
|
dbus_interface="org.freedesktop.DBus.ObjectManager",
|
|
|
|
signal_name="InterfacesRemoved")
|
|
|
|
|
2016-09-14 04:38:34 +02:00
|
|
|
mainloop = GLib.MainLoop()
|
|
|
|
mainloop.run()
|