# HG changeset patch # User Malte Bayer # Date 1351450882 -3600 # Node ID b0e4f424935109bc908e8ff1a2e735348bfa2e53 # Parent bb00e6994e5e7df82f9705b3784e1ae48d3f6453 added xmlrpc server to live viewer, cli functions communicate with server diff -r bb00e6994e5e -r b0e4f4249351 slotUI/SlotCli.py --- a/slotUI/SlotCli.py Sun Oct 28 18:53:03 2012 +0100 +++ b/slotUI/SlotCli.py Sun Oct 28 20:01:22 2012 +0100 @@ -13,6 +13,11 @@ import curses from time import sleep +import SimpleXMLRPCServer +import xmlrpclib +import threading + + VERSION = "1.7" MAXSLOTS = 6 TERM = { @@ -53,11 +58,27 @@ trigger_sound(what) Popen(["/bin/sh", os.path.abspath(EVENTPREFIX + what)]) +class SlotServer(threading.Thread): + def __init__(self, blackbox): + threading.Thread.__init__(self) + self.server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000)) + self.server.register_instance(blackbox) + #self.server.register_function(lambda astr: '_' + astr, '_string') + + def run(self): + self.server.serve_forever() + +class SlotClient(): + def __init__(self, url): + self.box = xmlrpclib.Server(url) + class SlotCli(): def __init__(self, test = None, dev=""): self.box = Blackbox() - if not test: + if (not test): self.box.connect(dev) + self.rpcserver = SlotServer(self.box) + self.rpcserver.start() self.slot_dummy = { "name": "Unnamed", "laps": 0, @@ -574,7 +595,11 @@ (options, args) = parser.parse_args() #if not options.dev: # options.dev = "/dev/ttyUSB0" - cli = SlotCli(options.test, options.dev) + + if options.live or options.learn or options.playback: + cli = SlotCli(options.test, options.dev) + else: + cli = SlotClient('http://localhost:8000') # should a CLI function be started? if options.live: