summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMikel Astiz <mikel.astiz@bmw-carit.de>2012-06-04 11:37:57 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2012-06-05 00:08:07 +0300
commite166ba52767cab0e2d1dcf54c5e472d3f5542084 (patch)
tree139a29e6f444332036b353d952ed85f3ff0b018b /test
parentc5c8053fae0d1a79ba6ff83830c997af8aa23523 (diff)
downloadobexd-e166ba52767cab0e2d1dcf54c5e472d3f5542084.tar.gz
client-test: Add opp-client
This new scripts replaces previous pull-business-card and send-files.
Diffstat (limited to 'test')
-rwxr-xr-xtest/opp-client96
-rwxr-xr-xtest/pull-business-card40
-rwxr-xr-xtest/send-files23
3 files changed, 96 insertions, 63 deletions
diff --git a/test/opp-client b/test/opp-client
new file mode 100755
index 0000000..ef76d18
--- /dev/null
+++ b/test/opp-client
@@ -0,0 +1,96 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+import gobject
+import dbus.mainloop.glib
+import os.path
+from optparse import OptionParser
+
+def parse_options():
+ parser.add_option("-d", "--device", dest="device",
+ help="Device to connect", metavar="DEVICE")
+ parser.add_option("-p", "--pull", dest="pull_to_file",
+ help="Pull vcard and store in FILE", metavar="FILE")
+ parser.add_option("-s", "--send", dest="send_file",
+ help="Send FILE", metavar="FILE")
+
+ return parser.parse_args()
+
+class OppClient:
+ def __init__(self, session_path):
+ self.transfer_path = None
+ bus = dbus.SessionBus()
+ obj = bus.get_object("org.openobex.client", session_path)
+ self.session = dbus.Interface(obj, "org.openobex.Session")
+ self.opp = dbus.Interface(obj, "org.openobex.ObjectPush")
+ bus.add_signal_receiver(self.transfer_complete,
+ dbus_interface="org.openobex.Transfer",
+ signal_name="Complete",
+ path_keyword="path")
+ bus.add_signal_receiver(self.transfer_error,
+ dbus_interface="org.openobex.Transfer",
+ signal_name="Error",
+ path_keyword="path")
+
+ def create_transfer_reply(self, reply):
+ (path, properties) = reply
+ self.transfer_path = path
+ print "Transfer created: %s" % path
+
+ def error(self, err):
+ print err
+ mainloop.quit()
+
+ def transfer_complete(self, path):
+ if path != self.transfer_path:
+ return
+ print "Transfer finished"
+ mainloop.quit()
+
+ def transfer_error(self, code, message, path):
+ if path != self.transfer_path:
+ return
+ print "Transfer finished with error %s: %s" % (code, message)
+ mainloop.quit()
+
+ def pull_business_card(self, filename):
+ self.opp.PullBusinessCard(os.path.abspath(filename),
+ reply_handler=self.create_transfer_reply,
+ error_handler=self.error)
+
+ def send_file(self, filename):
+ self.opp.SendFile(os.path.abspath(filename),
+ reply_handler=self.create_transfer_reply,
+ error_handler=self.error)
+
+if __name__ == '__main__':
+
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+ parser = OptionParser()
+
+ (options, args) = parse_options()
+
+ if not options.device:
+ parser.print_help()
+ sys.exit(0)
+
+ bus = dbus.SessionBus()
+ mainloop = gobject.MainLoop()
+
+ client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
+ "org.openobex.Client")
+
+ print "Creating Session"
+ session_path = client.CreateSession(options.device, { "Target": "OPP" })
+
+ opp_client = OppClient(session_path)
+
+ if options.pull_to_file:
+ opp_client.pull_business_card(options.pull_to_file)
+
+ if options.send_file:
+ opp_client.send_file(options.send_file)
+
+ mainloop.run()
diff --git a/test/pull-business-card b/test/pull-business-card
deleted file mode 100755
index 6f9267b..0000000
--- a/test/pull-business-card
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/python
-
-import sys
-import dbus
-import gobject
-import dbus.mainloop.glib
-
-def success():
- mainloop.quit()
- return
-
-def failure(error):
- print error
- mainloop.quit()
- return
-
-
-if __name__ == '__main__':
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-
- mainloop = gobject.MainLoop()
-
- bus = dbus.SessionBus()
- client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
- "org.openobex.Client")
-
- if (len(sys.argv) < 3):
- print "Usage: %s <device> <file>" % (sys.argv[0])
- sys.exit(1)
-
- print "Creating Session"
- session_path = client.CreateSession(sys.argv[1], { "Target": "OPP" })
- opp = dbus.Interface(bus.get_object("org.openobex.client",
- session_path),
- "org.openobex.ObjectPush")
-
- opp.PullBusinessCard(sys.argv[2],
- reply_handler=success, error_handler=failure)
-
- mainloop.run()
diff --git a/test/send-files b/test/send-files
deleted file mode 100755
index 5310c06..0000000
--- a/test/send-files
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/python
-
-import os
-import sys
-import dbus
-
-bus = dbus.SessionBus()
-client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
- "org.openobex.Client")
-
-if (len(sys.argv) < 3):
- print "Usage: %s <device> <file> [file*]" % (sys.argv[0])
- sys.exit(1)
-
-files = [os.path.realpath(f) for f in sys.argv[2:]]
-
-print "Creating Session"
-session_path = client.CreateSession(sys.argv[1], { "Target": "OPP" })
-opp = dbus.Interface(bus.get_object("org.openobex.client", session_path),
- "org.openobex.ObjectPush")
-
-for f in files:
- opp.SendFile(f)