diff options
author | Bruno Dilly <bdilly@profusion.mobi> | 2011-08-30 10:04:23 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2011-09-13 10:42:39 +0300 |
commit | a48d5487c7fad16a9c5d1ef00270c57b40bd74ae (patch) | |
tree | 4b57531f2a57d0a43088e8be2e6a77e0df2f5fd5 /test | |
parent | e327f964cec1972bbbfc8517c64243f0b7a5c1b3 (diff) |
Add test for serial proxy and serial proxy manager
Diffstat (limited to 'test')
-rwxr-xr-x | test/test-serial-proxy | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/test-serial-proxy b/test/test-serial-proxy new file mode 100755 index 00000000..f6dbd6c1 --- /dev/null +++ b/test/test-serial-proxy @@ -0,0 +1,64 @@ +#!/usr/bin/python + +import sys +import time +import dbus +import socket +from optparse import OptionParser, make_option + +bus = dbus.SystemBus() + +manager = dbus.Interface(bus.get_object("org.bluez", "/"), + "org.bluez.Manager") +option_list = [ + make_option("-i", "--device", action="store", + type="string", dest="dev_id"), + ] +parser = OptionParser(option_list=option_list) + +(options, args) = parser.parse_args() + +if options.dev_id: + adapter_path = manager.FindAdapter(options.dev_id) +else: + adapter_path = manager.DefaultAdapter() + +adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path), + "org.bluez.Adapter") + +if (len(args) < 1): + print "Usage: %s <socket_name> [service]" % (sys.argv[0]) + sys.exit(1) + +socket_name = args[0] + +if (len(args) < 2): + service = "spp" +else: + service = args[1] + +sk = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +sk.bind(socket_name) +sk.listen(1) + +proxy_manager = dbus.Interface(bus.get_object("org.bluez", adapter_path), + "org.bluez.SerialProxyManager") +proxy_path = proxy_manager.CreateProxy(service, socket_name) + +proxy = dbus.Interface(bus.get_object("org.bluez", proxy_path), + "org.bluez.SerialProxy") +proxy.Enable() + +conn, addr = sk.accept() + +print "Waiting for message" + +while 1: + data = conn.recv(1024) + if data: + print(data) + break + +proxy.Disable() +proxy_manager.RemoveProxy(proxy_path) +conn.close() |