gmyth-stream/plugins/comm/xmlrpc.py
branchtrunk
changeset 475 2521ec986005
parent 453 a806d8ad0ff0
     1.1 --- a/gmyth-stream/plugins/comm/xmlrpc.py	Tue Mar 27 00:13:27 2007 +0100
     1.2 +++ b/gmyth-stream/plugins/comm/xmlrpc.py	Sun Apr 01 03:11:01 2007 +0100
     1.3 @@ -1,74 +1,58 @@
     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 lib
    1.32  import SimpleXMLRPCServer
    1.33  
    1.34  
    1.35  class Handler:
    1.36  
    1.37 -    def __init__(self, pool):
    1.38 -        self.pool = pool
    1.39 +    def __init__(self, recv_pool, send_pool):
    1.40 +        self.recv_pool = recv_pool
    1.41 +        self.send_pool = send_pool
    1.42 +        self.getMsg = self.sendMsg
    1.43  
    1.44      def _listMethods(self):
    1.45 -        return ['Setup', 'Play', 'Stop', 'Close']
    1.46 +        return ['setup', 'play', 'stop', 'close', 'getMsg']
    1.47  
    1.48      def _methodHelp(self, method):
    1.49  
    1.50 -        if method == 'Setup':
    1.51 -            return "Setup the Media: Setup(filename,codec,bitrate,widht,height,port)"
    1.52 -        elif method == 'Play':
    1.53 -            return "Play the Media: Play()"
    1.54 -        elif method == 'Stop':
    1.55 -            return "Stop the Media: Stop()"
    1.56 -        elif method == 'Close':
    1.57 -            return "Close the connection: Close()"
    1.58 +        if method == 'setup':
    1.59 +            return "Setup the Media: setup( filename, mux, vcodec, vbitrate, fps, acodec, abitrate, width, height, port"
    1.60 +        elif method == 'play':
    1.61 +            return "Play the Media: play()"
    1.62 +        elif method == 'stop':
    1.63 +            return "Stop the Media: stop()"
    1.64 +        elif method == 'close':
    1.65 +            return "Close the connection: close()"
    1.66 +        elif method == 'getMsg':
    1.67 +            return "Return the first message in the pool: getMsg()"
    1.68          else:
    1.69              # By convention, return empty
    1.70              # string if no help is available
    1.71              return ""
    1.72  
    1.73 +    def setup(self, filename, mux, vcodec, vbitrate,\
    1.74 +            fps, acodec, abitrate, width, height, port):
    1.75 +        self.recv_pool.append("SETUP")
    1.76 +        self.recv_pool.append("%s %s %s %s %s %s %s" % (filename, mux, vcodec, vbitrate,\
    1.77 +                                                        fps, acodec, abitrate, width, height, port)
    1.78 +        return self.sendMsg()
    1.79  
    1.80 -    def Setup(self, filename, codec, bitrate, width, height, port):
    1.81 -        self.pool.append("SETUP")
    1.82 -        self.pool.append("%s %s %s %s %s %s" % (filename, codec, bitrate,\
    1.83 -                                             width, height, port))
    1.84 -        return 0
    1.85 +    def play(self):
    1.86 +        self.recv_pool.append("PLAY")
    1.87 +        return self.sendMsg()
    1.88  
    1.89 -    def Play(self):
    1.90 -        self.pool.append("PLAY")
    1.91 -        return 0
    1.92 +    def stop(self):
    1.93 +        self.recv_pool.append("STOP")
    1.94 +        return self.sendMsg()
    1.95  
    1.96 -    def Stop(self):
    1.97 -        self.pool.append("STOP")
    1.98 -        return 0
    1.99 +    def close(self):
   1.100 +        self.recv_pool.append("CLOSE")
   1.101 +        return self.sendMsg()
   1.102  
   1.103 -    def Close(self):
   1.104 -        self.pool.append("CLOSE")
   1.105 -        return 0
   1.106 +    def sendMsg(self):
   1.107 +        if self.send_pool != []:
   1.108 +            return self.send_pool.pop(0)
   1.109 +        else:
   1.110 +            return ""
   1.111  
   1.112  
   1.113  class Server:
   1.114 @@ -77,20 +61,28 @@
   1.115          self.host = 'localhost'
   1.116          self.port = int(config.get("Comm", "port"))
   1.117          self.finish = 0
   1.118 -        self.pool = []
   1.119 +        self.recv_pool = []
   1.120 +        self.send_pool = []
   1.121  
   1.122 -        self.handler = Handler(self.pool)
   1.123 +        self.handler = Handler(self.recv_pool, self.send_pool)
   1.124  
   1.125          self.xmlrpc = SimpleXMLRPCServer.SimpleXMLRPCServer((self.host, self.port))
   1.126          self.xmlrpc.register_instance(self.handler)
   1.127  
   1.128  
   1.129      def getMsg(self, size):
   1.130 -        try:
   1.131 -            return self.pool.pop(0)
   1.132 -        except IndexError:
   1.133 +        if self.recv_pool != []:
   1.134 +            return self.recv_pool.pop(0)
   1.135 +        else:
   1.136              return ""
   1.137  
   1.138 +    def sendMsg(self, msg):
   1.139 +        self.send_pool.append(msg)
   1.140 +
   1.141 +    def Ack(self, command):
   1.142 +        msg = "[%s] Command %s received" % (lib.now(), command)
   1.143 +        self.sendMsg(msg + "\n")
   1.144 +
   1.145      def getRequest(self):
   1.146          self.xmlrpc.handle_request()
   1.147          return (0, "RPC Client")