diff -r 000000000000 -r a4529d0f8ede gmyth-stream/server/0.1/plugins/comm/xmlrpc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/server/0.1/plugins/comm/xmlrpc.py Thu Jul 05 13:43:24 2007 +0100 @@ -0,0 +1,102 @@ +import lib +import SimpleXMLRPCServer + + +class Handler: + + def __init__(self, recv_pool, send_pool): + self.recv_pool = recv_pool + self.send_pool = send_pool + self.getMsg = self.sendMsg + + def _listMethods(self): + return ['setup', 'play', 'stop', 'close', 'getMsg'] + + def _methodHelp(self, method): + + if method == 'setup': + return "Setup the Media: setup( filename, mux, vcodec, vbitrate,"\ + " fps, acodec, abitrate, width, height, port, options" + elif method == 'play': + return "Play the Media: play()" + elif method == 'stop': + return "Stop the Media: stop()" + elif method == 'close': + return "Close the connection: close()" + elif method == 'getMsg': + return "Return the first message in the pool: getMsg()" + else: + # By convention, return empty + # string if no help is available + return "" + + def setup(self, filename, mux, vcodec, vbitrate,\ + fps, acodec, abitrate, width, height, port, options): + + msg = "%s %s %s %s %s %s %s" % (filename, mux, vcodec, vbitrate,\ + fps, acodec, abitrate, width, height, port) + + if len(options) > 0: + for opt in options: + msg += " %s" % opt + + self.recv_pool.append("SETUP") + self.recv_pool.append(msg) + return self.sendMsg() + + def play(self): + self.recv_pool.append("PLAY") + return self.sendMsg() + + def stop(self): + self.recv_pool.append("STOP") + return self.sendMsg() + + def close(self): + self.recv_pool.append("CLOSE") + return self.sendMsg() + + def sendMsg(self): + if self.send_pool != []: + return self.send_pool.pop(0) + else: + return "" + + +class Server: + + def __init__(self, config): + self.host = 'localhost' + self.port = int(config.get("Comm", "port")) + self.finish = 0 + self.recv_pool = [] + self.send_pool = [] + + self.handler = Handler(self.recv_pool, self.send_pool) + + self.xmlrpc = SimpleXMLRPCServer.SimpleXMLRPCServer((self.host, self.port)) + self.xmlrpc.register_instance(self.handler) + + + def getMsg(self, size): + if self.recv_pool != []: + return self.recv_pool.pop(0) + else: + return "" + + def sendMsg(self, msg): + self.send_pool.append(msg) + + def Ack(self, command): + msg = "[%s] Command %s received" % (lib.now(), command) + self.sendMsg(msg + "\n") + + def getRequest(self): + self.xmlrpc.handle_request() + return (0, "RPC Client") + + def disconnect_client(self, connection): + connection = 0 + + def stop(self): + self.xmlrpc.server_close()