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