diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2008-03-14 21:46:19 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2008-03-14 21:46:19 +0000 |
commit | 9bafbc5c70f6dde0f9219aea446d21f653826888 (patch) | |
tree | eee1e8abcaeaa1c39dec76bb4b72840f1afec4dc | |
parent | 5946ab97f600372b44cb1681c3a26a863032261d (diff) |
Add example script for testing discovery procedure
-rw-r--r-- | hcid/Makefile.am | 3 | ||||
-rwxr-xr-x | hcid/test-discovery | 42 |
2 files changed, 44 insertions, 1 deletions
diff --git a/hcid/Makefile.am b/hcid/Makefile.am index 638a7524..9c3ee058 100644 --- a/hcid/Makefile.am +++ b/hcid/Makefile.am @@ -58,7 +58,8 @@ AM_YFLAGS = -d CLEANFILES = lexer.c parser.c parser.h EXTRA_DIST = hcid.8 hcid.conf.5 hcid.conf dbus-api.txt \ - list-devices test-device simple-agent service-record.dtd \ + list-devices test-discovery test-device simple-agent \ + service-record.dtd \ service-did.xml service-spp.xml service-opp.xml service-ftp.xml MAINTAINERCLEANFILES = Makefile.in diff --git a/hcid/test-discovery b/hcid/test-discovery new file mode 100755 index 00000000..6605d6a4 --- /dev/null +++ b/hcid/test-discovery @@ -0,0 +1,42 @@ +#!/usr/bin/python + +import gobject + +import dbus +import dbus.mainloop.glib + +def device_found(address, properties): + print '[ ' + address + ' ]' + + for key in properties.keys(): + value = properties[key] + if (key == "Class"): + print ' %s = 0x%06x' % (key, value) + else: + print ' %s = %s' % (key, value) + +def discovery_completed(): + mainloop.quit() + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + bus = dbus.SystemBus() + manager = dbus.Interface(bus.get_object('org.bluez', '/'), + 'org.bluez.Manager') + path = manager.DefaultAdapter() + adapter = dbus.Interface(bus.get_object('org.bluez', path), + 'org.bluez.Adapter') + + bus.add_signal_receiver(device_found, + dbus_interface = 'org.bluez.Adapter', + signal_name = 'DeviceFound') + + bus.add_signal_receiver(discovery_completed, + dbus_interface = 'org.bluez.Adapter', + signal_name = 'DiscoveryCompleted') + + adapter.DiscoverDevices() + + mainloop = gobject.MainLoop() + mainloop.run() |