diff -r a806d8ad0ff0 -r 2eef40885322 gmyth-stream/plugins/comm/xmlrpc.py --- a/gmyth-stream/plugins/comm/xmlrpc.py Tue Mar 27 00:13:27 2007 +0100 +++ b/gmyth-stream/plugins/comm/xmlrpc.py Fri Mar 30 23:07:54 2007 +0100 @@ -1,74 +1,58 @@ - ''' - # GMyth-Stream - # - # @file plugins/comm/xmlrpc.py - # - # @brief

Plugin for GMyth-Stream - # - # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia. - # @author Artur Duque de Souza - # - # - # This program is free software; you can redistribute it and/or modify - # it under the terms of the GNU Lesser General Public License as published by - # the Free Software Foundation; either version 2 of the License, or - # (at your option) any later version. - # - # This program is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - # GNU General Public License for more details. - # - # You should have received a copy of the GNU Lesser General Public License - # along with this program; if not, write to the Free Software - # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - # - ''' - +import lib import SimpleXMLRPCServer class Handler: - def __init__(self, pool): - self.pool = pool + 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'] + return ['setup', 'play', 'stop', 'close', 'getMsg'] def _methodHelp(self, method): - if method == 'Setup': - return "Setup the Media: Setup(filename,codec,bitrate,widht,height,port)" - elif method == 'Play': - return "Play the Media: Play()" - elif method == 'Stop': - return "Stop the Media: Stop()" - elif method == 'Close': - return "Close the connection: Close()" + if method == 'setup': + return "Setup the Media: setup( filename, mux, vcodec, vbitrate, fps, acodec, abitrate, width, height, port" + 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): + self.recv_pool.append("SETUP") + self.recv_pool.append("%s %s %s %s %s %s %s" % (filename, mux, vcodec, vbitrate,\ + fps, acodec, abitrate, width, height, port) + return self.sendMsg() - def Setup(self, filename, codec, bitrate, width, height, port): - self.pool.append("SETUP") - self.pool.append("%s %s %s %s %s %s" % (filename, codec, bitrate,\ - width, height, port)) - return 0 + def play(self): + self.recv_pool.append("PLAY") + return self.sendMsg() - def Play(self): - self.pool.append("PLAY") - return 0 + def stop(self): + self.recv_pool.append("STOP") + return self.sendMsg() - def Stop(self): - self.pool.append("STOP") - return 0 + def close(self): + self.recv_pool.append("CLOSE") + return self.sendMsg() - def Close(self): - self.pool.append("CLOSE") - return 0 + def sendMsg(self): + if self.send_pool != []: + return self.send_pool.pop(0) + else: + return "" class Server: @@ -77,20 +61,28 @@ self.host = 'localhost' self.port = int(config.get("Comm", "port")) self.finish = 0 - self.pool = [] + self.recv_pool = [] + self.send_pool = [] - self.handler = Handler(self.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): - try: - return self.pool.pop(0) - except IndexError: + 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")