morphbr@453: ''' morphbr@453: # GMyth-Stream morphbr@453: # morphbr@453: # @file plugins/comm/xmlrpc.py morphbr@453: # morphbr@453: # @brief

Plugin for GMyth-Stream morphbr@453: # morphbr@453: # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia. morphbr@453: # @author Artur Duque de Souza morphbr@453: # morphbr@453: # morphbr@453: # This program is free software; you can redistribute it and/or modify morphbr@453: # it under the terms of the GNU Lesser General Public License as published by morphbr@453: # the Free Software Foundation; either version 2 of the License, or morphbr@453: # (at your option) any later version. morphbr@453: # morphbr@453: # This program is distributed in the hope that it will be useful, morphbr@453: # but WITHOUT ANY WARRANTY; without even the implied warranty of morphbr@453: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the morphbr@453: # GNU General Public License for more details. morphbr@453: # morphbr@453: # You should have received a copy of the GNU Lesser General Public License morphbr@453: # along with this program; if not, write to the Free Software morphbr@453: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA morphbr@453: # morphbr@453: ''' morphbr@453: morphbr@453: import SimpleXMLRPCServer morphbr@453: morphbr@453: morphbr@453: class Handler: morphbr@453: morphbr@453: def __init__(self, pool): morphbr@453: self.pool = pool morphbr@453: morphbr@453: def _listMethods(self): morphbr@453: return ['Setup', 'Play', 'Stop', 'Close'] morphbr@453: morphbr@453: def _methodHelp(self, method): morphbr@453: morphbr@453: if method == 'Setup': morphbr@453: return "Setup the Media: Setup(filename,codec,bitrate,widht,height,port)" morphbr@453: elif method == 'Play': morphbr@453: return "Play the Media: Play()" morphbr@453: elif method == 'Stop': morphbr@453: return "Stop the Media: Stop()" morphbr@453: elif method == 'Close': morphbr@453: return "Close the connection: Close()" morphbr@453: else: morphbr@453: # By convention, return empty morphbr@453: # string if no help is available morphbr@453: return "" morphbr@453: morphbr@453: morphbr@453: def Setup(self, filename, codec, bitrate, width, height, port): morphbr@453: self.pool.append("SETUP") morphbr@453: self.pool.append("%s %s %s %s %s %s" % (filename, codec, bitrate,\ morphbr@453: width, height, port)) morphbr@453: return 0 morphbr@453: morphbr@453: def Play(self): morphbr@453: self.pool.append("PLAY") morphbr@453: return 0 morphbr@453: morphbr@453: def Stop(self): morphbr@453: self.pool.append("STOP") morphbr@453: return 0 morphbr@453: morphbr@453: def Close(self): morphbr@453: self.pool.append("CLOSE") morphbr@453: return 0 morphbr@453: morphbr@453: morphbr@453: class Server: morphbr@453: morphbr@453: def __init__(self, config): morphbr@453: self.host = 'localhost' morphbr@453: self.port = int(config.get("Comm", "port")) morphbr@453: self.finish = 0 morphbr@453: self.pool = [] morphbr@453: morphbr@453: self.handler = Handler(self.pool) morphbr@453: morphbr@453: self.xmlrpc = SimpleXMLRPCServer.SimpleXMLRPCServer((self.host, self.port)) morphbr@453: self.xmlrpc.register_instance(self.handler) morphbr@453: morphbr@453: morphbr@453: def getMsg(self, size): morphbr@453: try: morphbr@453: return self.pool.pop(0) morphbr@453: except IndexError: morphbr@453: return "" morphbr@453: morphbr@453: def getRequest(self): morphbr@453: self.xmlrpc.handle_request() morphbr@453: return (0, "RPC Client") morphbr@453: morphbr@453: def disconnect_client(self, connection): morphbr@453: connection = 0 morphbr@453: morphbr@453: def stop(self): morphbr@453: self.xmlrpc.server_close()