gmyth-stream/plugins/comm/xmlrpc.py
branchtrunk
changeset 464 5ef4452c42cc
child 470 57833200a415
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth-stream/plugins/comm/xmlrpc.py	Tue Mar 27 21:42:35 2007 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 + '''
     1.5 + # GMyth-Stream
     1.6 + #
     1.7 + # @file plugins/comm/xmlrpc.py
     1.8 + #
     1.9 + # @brief <p> Plugin for GMyth-Stream
    1.10 + #
    1.11 + # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
    1.12 + # @author Artur Duque de Souza <artur.souza@indt.org.br>
    1.13 + #
    1.14 + #
    1.15 + # This program is free software; you can redistribute it and/or modify
    1.16 + # it under the terms of the GNU Lesser General Public License as published by
    1.17 + # the Free Software Foundation; either version 2 of the License, or
    1.18 + # (at your option) any later version.
    1.19 + #
    1.20 + # This program is distributed in the hope that it will be useful,
    1.21 + # but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.22 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.23 + # GNU General Public License for more details.
    1.24 + #
    1.25 + # You should have received a copy of the GNU Lesser General Public License
    1.26 + # along with this program; if not, write to the Free Software
    1.27 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.28 + #
    1.29 + '''
    1.30 +
    1.31 +import SimpleXMLRPCServer
    1.32 +
    1.33 +
    1.34 +class Handler:
    1.35 +
    1.36 +    def __init__(self, pool):
    1.37 +        self.pool = pool
    1.38 +
    1.39 +    def _listMethods(self):
    1.40 +        return ['Setup', 'Play', 'Stop', 'Close']
    1.41 +
    1.42 +    def _methodHelp(self, method):
    1.43 +
    1.44 +        if method == 'Setup':
    1.45 +            return "Setup the Media: Setup(filename,codec,bitrate,widht,height,port)"
    1.46 +        elif method == 'Play':
    1.47 +            return "Play the Media: Play()"
    1.48 +        elif method == 'Stop':
    1.49 +            return "Stop the Media: Stop()"
    1.50 +        elif method == 'Close':
    1.51 +            return "Close the connection: Close()"
    1.52 +        else:
    1.53 +            # By convention, return empty
    1.54 +            # string if no help is available
    1.55 +            return ""
    1.56 +
    1.57 +
    1.58 +    def Setup(self, filename, codec, bitrate, width, height, port):
    1.59 +        self.pool.append("SETUP")
    1.60 +        self.pool.append("%s %s %s %s %s %s" % (filename, codec, bitrate,\
    1.61 +                                             width, height, port))
    1.62 +        return 0
    1.63 +
    1.64 +    def Play(self):
    1.65 +        self.pool.append("PLAY")
    1.66 +        return 0
    1.67 +
    1.68 +    def Stop(self):
    1.69 +        self.pool.append("STOP")
    1.70 +        return 0
    1.71 +
    1.72 +    def Close(self):
    1.73 +        self.pool.append("CLOSE")
    1.74 +        return 0
    1.75 +
    1.76 +
    1.77 +class Server:
    1.78 +
    1.79 +    def __init__(self, config):
    1.80 +        self.host = 'localhost'
    1.81 +        self.port = int(config.get("Comm", "port"))
    1.82 +        self.finish = 0
    1.83 +        self.pool = []
    1.84 +
    1.85 +        self.handler = Handler(self.pool)
    1.86 +
    1.87 +        self.xmlrpc = SimpleXMLRPCServer.SimpleXMLRPCServer((self.host, self.port))
    1.88 +        self.xmlrpc.register_instance(self.handler)
    1.89 +
    1.90 +
    1.91 +    def getMsg(self, size):
    1.92 +        try:
    1.93 +            return self.pool.pop(0)
    1.94 +        except IndexError:
    1.95 +            return ""
    1.96 +
    1.97 +    def getRequest(self):
    1.98 +        self.xmlrpc.handle_request()
    1.99 +        return (0, "RPC Client")
   1.100 +
   1.101 +    def disconnect_client(self, connection):
   1.102 +        connection = 0
   1.103 +
   1.104 +    def stop(self):
   1.105 +        self.xmlrpc.server_close()