test: Add a device monitoring script
authorSamuel Ortiz <sameo@linux.intel.com>
Thu, 27 Jun 2013 10:30:54 +0000 (12:30 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 27 Jun 2013 10:30:54 +0000 (12:30 +0200)
It displays the device detection event and the received NDEF record
payloads if something is received from the device.

test/monitor-device [new file with mode: 0755]

diff --git a/test/monitor-device b/test/monitor-device
new file mode 100755 (executable)
index 0000000..24381e4
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.mainloop.glib
+
+from dbus.lowlevel import MethodCallMessage, HANDLER_RESULT_NOT_YET_HANDLED
+
+def extract_record(key, list):
+       j = 0
+       for i in list:
+               record = dbus.Interface(bus.get_object("org.neard", i),
+                                               "org.neard.Record")
+
+               properties = record.GetProperties()
+               print "        Record #%d" % (j)
+               j += 1
+
+               for key in properties.keys():
+                       val = str(properties[key])
+                       print "              %s = %s" % (key, val)
+
+def property_changed_device(name, value, path):
+    device = path[path.rfind("/") + 1:]
+    if name in ["Records"]:
+       extract_record(name, value)
+
+def property_changed_adapter(name, value, path):
+    adapter = path[path.rfind("/") + 1:]
+    if name in ["Devices"]:
+       for i in value:
+                  print "New Device detected [%s]" % (i)
+
+
+if __name__ == '__main__':
+       dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+       bus = dbus.SystemBus()
+
+       bus.add_signal_receiver(property_changed_adapter,
+                               bus_name="org.neard",
+                               dbus_interface="org.neard.Adapter",
+                               signal_name = "PropertyChanged",
+                               path_keyword="path")
+
+       bus.add_signal_receiver(property_changed_device,
+                               bus_name="org.neard",
+                               dbus_interface="org.neard.Device",
+                               signal_name = "PropertyChanged",
+                               path_keyword="path")
+
+
+       mainloop = gobject.MainLoop()
+       mainloop.run()