gmyth-stream/main.py
author renatofilho
Tue Mar 27 15:35:49 2007 +0100 (2007-03-27)
branchtrunk
changeset 455 10c21aebb0ff
child 466 a7aba7d166fb
permissions -rwxr-xr-x
[svn r460] fixed file_transfer
morphbr@453
     1
 '''
morphbr@453
     2
 # GMyth-Stream
morphbr@453
     3
 #
morphbr@453
     4
 # @file main.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
#!/usr/bin/python
morphbr@453
    29
morphbr@453
    30
import sys
morphbr@453
    31
import os
morphbr@453
    32
import ConfigParser
morphbr@453
    33
morphbr@453
    34
def now():
morphbr@453
    35
    return time.strftime("%Y-%m-%d %H:%M:%S");
morphbr@453
    36
morphbr@453
    37
morphbr@453
    38
config = ConfigParser.ConfigParser()
morphbr@453
    39
config.read("stream.conf")
morphbr@453
    40
morphbr@453
    41
media_plugin = config.get("Media", "engine")
morphbr@453
    42
exec("from plugins.media.%s import *" % media_plugin)
morphbr@453
    43
morphbr@453
    44
media = Media(config)
morphbr@453
    45
morphbr@453
    46
comm_plugin = config.get("Comm", "engine")
morphbr@453
    47
exec("from plugins.comm.%s import *" % comm_plugin)
morphbr@453
    48
morphbr@453
    49
# Start Our Server:
morphbr@453
    50
server = Server(config)
morphbr@453
    51
morphbr@453
    52
print "--> Starting the server..."
morphbr@453
    53
morphbr@453
    54
while (server.finish == 0):
morphbr@453
    55
    con, client = server.getRequest()
morphbr@453
    56
morphbr@453
    57
    while True:
morphbr@453
    58
        msg = server.getMsg(1024).strip()
morphbr@453
    59
morphbr@453
    60
        if not msg: break
morphbr@453
    61
morphbr@453
    62
        elif (msg == "SETUP"):
morphbr@453
    63
            setup = server.getMsg(1024).strip().split(" ")
morphbr@453
    64
            media.setup(setup[0], setup[1], setup[2], \
morphbr@453
    65
                        setup[3], setup[4], setup[5])
morphbr@453
    66
morphbr@453
    67
        elif (msg == "PLAY"):
morphbr@453
    68
            media.play()
morphbr@453
    69
morphbr@453
    70
        elif (msg == "STOP"):
morphbr@453
    71
            media.stop()
morphbr@453
    72
morphbr@453
    73
        elif (msg == "CLOSE"):
morphbr@453
    74
            server.finish = 1
morphbr@453
    75
            media.stop()
morphbr@453
    76
            break
morphbr@453
    77
morphbr@453
    78
        print "[%s] %s: %s" % (now(), client, msg)
morphbr@453
    79
morphbr@453
    80
    print "[%s] Closing connection with %s" % (now(), client)
morphbr@453
    81
    server.disconnect_client(con)
morphbr@453
    82
morphbr@453
    83
server.stop()
morphbr@453
    84
morphbr@453
    85
print "--> Server stopped..."