diff options
author | Sebastian Chlad <sebastian.chlad@tieto.com> | 2014-03-10 12:27:34 +0100 |
---|---|---|
committer | Sebastian Chlad <sebastian.chlad@tieto.com> | 2014-03-10 12:47:02 +0100 |
commit | 8658f962aed81a52cde9e522758bb496922f48bb (patch) | |
tree | 156458b06c4220baaa37c34e5efc6b5210f89cef | |
parent | 66b602ca469cccea316b94ba1e7030998f9d847c (diff) | |
download | neard-8658f962aed81a52cde9e522758bb496922f48bb.tar.gz neard-8658f962aed81a52cde9e522758bb496922f48bb.tar.bz2 neard-8658f962aed81a52cde9e522758bb496922f48bb.zip |
bluez: Adjust BT handover script
Since blueZ 5.X switched to the ObjectManager API bt-handover
cannot be used with the bt-handover test script provided by neard
lower than 0.14.
Patch adds bt-interim-handover script which uses ObjectManager
and therefore allows bt-handover testing with neard 0-12 and BlueZ
5.X.
Change-Id: I83e4dc8c44d8dac50ad2866f7482fffd750b8e9e
Signed-off-by: Sebastian Chlad <sebastianx.chlad@intel.com>
-rw-r--r-- | Makefile.am | 3 | ||||
-rwxr-xr-x | test/bt-interim-handover | 91 |
2 files changed, 93 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index fd2bb90..e3e4f93 100644 --- a/Makefile.am +++ b/Makefile.am @@ -81,7 +81,8 @@ dist_man_MANS = doc/neard.8 doc/neard.conf.5 doc/nfctool.1 test_scripts = test/disable-adapter test/enable-adapter test/list-adapters \ test/dump-device test/dump-tag test/dump-record \ test/monitor-near test/start-poll test/stop-poll test/write-tag \ - test/push-device test/bt-handover test/handover-agent test/wifi-handover + test/push-device test/bt-handover test/handover-agent test/wifi-handover \ + test/bt-interim-handover if TEST testdir = $(pkglibdir)/test diff --git a/test/bt-interim-handover b/test/bt-interim-handover new file mode 100755 index 0000000..215e3ba --- /dev/null +++ b/test/bt-interim-handover @@ -0,0 +1,91 @@ +#!/usr/bin/python + +# +# This is just interim bt-handover script which enable handover while bluez uses +# ObjectManager +# + +import os +import sys +import gobject + +import dbus +import dbus.mainloop.glib + +from dbus.lowlevel import MethodCallMessage, HANDLER_RESULT_NOT_YET_HANDLED + +mainloop = gobject.MainLoop() + +def property_changed_adapter(name, value, path): + if name in ["Devices"]: + if (len(value) == 0): + print "Lost device, exiting" + mainloop.quit() + else: + print "Tutaj" + device_path = value[0] + + print "Pairing with %s" % (device_path) + + device = dbus.Interface(bus.get_object("org.neard", device_path), "org.neard.Device") + device.Push(({ "Type" : "Handover", "Carrier" : "bluetooth"})) + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + bus = dbus.SystemBus() + + manager = dbus.Interface(bus.get_object("org.bluez", "/"), + "org.freedesktop.DBus.ObjectManager") + + objects = manager.GetManagedObjects() + + all_adapters = (path for path, interfaces in objects.iteritems() if + "org.bluez.Adapter1" in interfaces.keys() + and path.endswith(bt_adapter)) + + bluez_adapter = None + + for adapter in sorted(objects): + bluez_adapter = dbus.Interface(bus.get_object("org.bluez", + adapter), + "org.bluez.Adapter1") + break + + if(bluez_adapter is None): + print("Bluetooth adapter %s could not be found" % bluez_adapter) + exit() + + adapter_path = bluez_adapter.object_path + print("Using %s" % adapter_path) + + adapter_props = dbus.Interface(bus.get_object("org.bluez", + adapter_path), + "org.freedesktop.DBus.Properties") + + manager_neard = dbus.Interface(bus.get_object("org.neard", "/"), + "org.neard.Manager") + + properties_neard = manager_neard.GetProperties() + neard_device_path = properties_neard["Adapters"][0] + adapter_neard = dbus.Interface(bus.get_object("org.neard", neard_device_path), + "org.neard.Adapter") + + adapter_properties = adapter_neard.GetProperties() + + for key in adapter_properties.keys(): + if key in ["Polling"]: + if adapter_properties[key] == dbus.Boolean(1): + print "Stoping poll on %s" % (neard_device_path) + adapter_neard.StopPollLoop() + + print "Starting poll on %s" % (neard_device_path) + adapter_neard.StartPollLoop("Initiator") + + bus.add_signal_receiver(property_changed_adapter, + bus_name="org.neard", + dbus_interface="org.neard.Adapter", + signal_name = "PropertyChanged", + path_keyword="path") + + mainloop.run() |