diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2013-11-11 01:03:01 +0100 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-11-11 01:03:01 +0100 |
commit | 50d496726bf043a7993d7160e35b9fa9e54ad5e9 (patch) | |
tree | 36b76cbdb7891cd02949f131e34a1754e6e366c8 /test/bt-handover | |
parent | 072ce563e1f847dc27b255a36bcf232429c80825 (diff) | |
download | neard-50d496726bf043a7993d7160e35b9fa9e54ad5e9.tar.gz neard-50d496726bf043a7993d7160e35b9fa9e54ad5e9.tar.bz2 neard-50d496726bf043a7993d7160e35b9fa9e54ad5e9.zip |
test: Port bt-handover to the ObjectManager interface
Diffstat (limited to 'test/bt-handover')
-rwxr-xr-x | test/bt-handover | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/test/bt-handover b/test/bt-handover index 95b6dbf..980f812 100755 --- a/test/bt-handover +++ b/test/bt-handover @@ -6,23 +6,27 @@ import gobject import dbus import dbus.mainloop.glib +import neardutils 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: - 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"})) +def device_added(path, interfaces): + for iface, props in interfaces.iteritems(): + if "org.neard.Device" in interfaces: + print("Pairing with %s" % (path)) + device = dbus.Interface(bus.get_object("org.neard", path), + "org.neard.Device") + device.Push(({ "Type" : "Handover", "Carrier" : "bluetooth"})) + break + +def device_removed(path, interfaces): + for iface in interfaces: + if "org.neard.Device" in interfaces: + print("Lost device %s" % (path)) + mainloop.quit() + break if __name__ == '__main__': dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) @@ -41,29 +45,27 @@ if __name__ == '__main__': bluez_adapter.RemoveDevice(bluez_path) - manager = dbus.Interface(bus.get_object("org.neard", "/"), - "org.neard.Manager") - - properties = manager.GetProperties() - device_path = properties["Adapters"][0] - adapter = dbus.Interface(bus.get_object("org.neard", device_path), - "org.neard.Adapter") + adapter_path = neardutils.find_adapter().object_path + print("Adapter path %s" % (adapter_path)) + adapter = dbus.Interface(bus.get_object("org.neard", adapter_path), + "org.neard.Adapter") - adapter_properties = adapter.GetProperties() + adapter_props = dbus.Interface(bus.get_object("org.neard", adapter_path), + "org.freedesktop.DBus.Properties") + powered = adapter_props.Get("org.neard.Adapter", "Powered") + if (powered == dbus.Boolean(0)): + adapter_props.Set("org.neard.Adapter", "Powered", dbus.Boolean(1)) - for key in adapter_properties.keys(): - if key in ["Polling"]: - if adapter_properties[key] == dbus.Boolean(1): - print "Stoping poll on %s" % (device_path) - adapter.StopPollLoop() + polling = adapter_props.Get("org.neard.Adapter", "Polling") + if (polling == dbus.Boolean(0)): + adapter.StartPollLoop("Initiator") - print "Starting poll on %s" % (device_path) - adapter.StartPollLoop("Initiator") + bus.add_signal_receiver(device_added, bus_name="org.neard", + dbus_interface="org.freedesktop.DBus.ObjectManager", + signal_name="InterfacesAdded") - 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(device_removed, bus_name="org.neard", + dbus_interface="org.freedesktop.DBus.ObjectManager", + signal_name="InterfacesRemoved") mainloop.run() |