Sun, 28 Oct 2012 20:01:22 +0100
added xmlrpc server to live viewer, cli functions communicate with server
slotUI/SlotCli.py | file | annotate | diff | comparison | revisions |
--- 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: