From: Samuel Ortiz Date: Thu, 27 Jun 2013 10:30:54 +0000 (+0200) Subject: test: Add a device monitoring script X-Git-Tag: 0.13~72 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f6a995d9499f7c783a2f0e45cc0d9dc40c9685a;p=platform%2Fupstream%2Fneard.git test: Add a device monitoring script It displays the device detection event and the received NDEF record payloads if something is received from the device. --- diff --git a/test/monitor-device b/test/monitor-device new file mode 100755 index 0000000..24381e4 --- /dev/null +++ b/test/monitor-device @@ -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()