Debian Codegraph @

test/monitor-bluetooth

raw symbols SCIP
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 from __future__ import absolute_import, print_function, unicode_literals
5
6 import dbus
7 import dbus.mainloop.glib
8 try:
9 from gi.repository import GObject
10 except ImportError:
11 import gobject as GObject
12
13 relevant_ifaces = [ "org.bluez.Adapter1", "org.bluez.Device1" ]
14
15 def property_changed(interface, changed, invalidated, path):
16 iface = interface[interface.rfind(".") + 1:]
17 for name, value in changed.items():
18 val = str(value)
19 print("{%s.PropertyChanged} [%s] %s = %s" % (iface, path, name,
20 val))
21
22 def interfaces_added(path, interfaces):
23 for iface, props in interfaces.items():
24 if not(iface in relevant_ifaces):
25 continue
26 print("{Added %s} [%s]" % (iface, path))
27 for name, value in props.items():
28 print(" %s = %s" % (name, value))
29
30 def interfaces_removed(path, interfaces):
31 for iface in interfaces:
32 if not(iface in relevant_ifaces):
33 continue
34 print("{Removed %s} [%s]" % (iface, path))
35
36 if __name__ == '__main__':
37 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
38
39 bus = dbus.SystemBus()
40
41 bus.add_signal_receiver(property_changed, bus_name="org.bluez",
42 dbus_interface="org.freedesktop.DBus.Properties",
43 signal_name="PropertiesChanged",
44 path_keyword="path")
45
46 bus.add_signal_receiver(interfaces_added, bus_name="org.bluez",
47 dbus_interface="org.freedesktop.DBus.ObjectManager",
48 signal_name="InterfacesAdded")
49
50 bus.add_signal_receiver(interfaces_removed, bus_name="org.bluez",
51 dbus_interface="org.freedesktop.DBus.ObjectManager",
52 signal_name="InterfacesRemoved")
53
54 mainloop = GObject.MainLoop()
55 mainloop.run()