gmyth-stream/plugins/comm/xmlrpc.py
author renatofilho
Tue Mar 27 16:45:00 2007 +0100 (2007-03-27)
branchtrunk
changeset 461 0683ea324deb
child 470 57833200a415
permissions -rw-r--r--
[svn r466] fixed remote files read
     1  '''
     2  # GMyth-Stream
     3  #
     4  # @file plugins/comm/xmlrpc.py
     5  #
     6  # @brief <p> Plugin for GMyth-Stream
     7  #
     8  # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
     9  # @author Artur Duque de Souza <artur.souza@indt.org.br>
    10  #
    11  #
    12  # This program is free software; you can redistribute it and/or modify
    13  # it under the terms of the GNU Lesser General Public License as published by
    14  # the Free Software Foundation; either version 2 of the License, or
    15  # (at your option) any later version.
    16  #
    17  # This program is distributed in the hope that it will be useful,
    18  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  # GNU General Public License for more details.
    21  #
    22  # You should have received a copy of the GNU Lesser General Public License
    23  # along with this program; if not, write to the Free Software
    24  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    25  #
    26  '''
    27 
    28 import SimpleXMLRPCServer
    29 
    30 
    31 class Handler:
    32 
    33     def __init__(self, pool):
    34         self.pool = pool
    35 
    36     def _listMethods(self):
    37         return ['Setup', 'Play', 'Stop', 'Close']
    38 
    39     def _methodHelp(self, method):
    40 
    41         if method == 'Setup':
    42             return "Setup the Media: Setup(filename,codec,bitrate,widht,height,port)"
    43         elif method == 'Play':
    44             return "Play the Media: Play()"
    45         elif method == 'Stop':
    46             return "Stop the Media: Stop()"
    47         elif method == 'Close':
    48             return "Close the connection: Close()"
    49         else:
    50             # By convention, return empty
    51             # string if no help is available
    52             return ""
    53 
    54 
    55     def Setup(self, filename, codec, bitrate, width, height, port):
    56         self.pool.append("SETUP")
    57         self.pool.append("%s %s %s %s %s %s" % (filename, codec, bitrate,\
    58                                              width, height, port))
    59         return 0
    60 
    61     def Play(self):
    62         self.pool.append("PLAY")
    63         return 0
    64 
    65     def Stop(self):
    66         self.pool.append("STOP")
    67         return 0
    68 
    69     def Close(self):
    70         self.pool.append("CLOSE")
    71         return 0
    72 
    73 
    74 class Server:
    75 
    76     def __init__(self, config):
    77         self.host = 'localhost'
    78         self.port = int(config.get("Comm", "port"))
    79         self.finish = 0
    80         self.pool = []
    81 
    82         self.handler = Handler(self.pool)
    83 
    84         self.xmlrpc = SimpleXMLRPCServer.SimpleXMLRPCServer((self.host, self.port))
    85         self.xmlrpc.register_instance(self.handler)
    86 
    87 
    88     def getMsg(self, size):
    89         try:
    90             return self.pool.pop(0)
    91         except IndexError:
    92             return ""
    93 
    94     def getRequest(self):
    95         self.xmlrpc.handle_request()
    96         return (0, "RPC Client")
    97 
    98     def disconnect_client(self, connection):
    99         connection = 0
   100 
   101     def stop(self):
   102         self.xmlrpc.server_close()