morphbr@453: ''' morphbr@453: # GMyth-Stream morphbr@453: # morphbr@453: # @file main.py morphbr@453: # morphbr@453: # @brief

Plugin for GMyth-Stream morphbr@453: # morphbr@453: # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia. morphbr@453: # @author Artur Duque de Souza morphbr@453: # morphbr@453: # morphbr@453: # This program is free software; you can redistribute it and/or modify morphbr@453: # it under the terms of the GNU Lesser General Public License as published by morphbr@453: # the Free Software Foundation; either version 2 of the License, or morphbr@453: # (at your option) any later version. morphbr@453: # morphbr@453: # This program is distributed in the hope that it will be useful, morphbr@453: # but WITHOUT ANY WARRANTY; without even the implied warranty of morphbr@453: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the morphbr@453: # GNU General Public License for more details. morphbr@453: # morphbr@453: # You should have received a copy of the GNU Lesser General Public License morphbr@453: # along with this program; if not, write to the Free Software morphbr@453: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA morphbr@453: # morphbr@453: ''' morphbr@453: morphbr@453: #!/usr/bin/python morphbr@453: morphbr@453: import sys morphbr@453: import os morphbr@453: import ConfigParser morphbr@453: morphbr@453: def now(): morphbr@453: return time.strftime("%Y-%m-%d %H:%M:%S"); morphbr@453: morphbr@453: morphbr@453: config = ConfigParser.ConfigParser() morphbr@453: config.read("stream.conf") morphbr@453: morphbr@453: media_plugin = config.get("Media", "engine") morphbr@453: exec("from plugins.media.%s import *" % media_plugin) morphbr@453: morphbr@453: media = Media(config) morphbr@453: morphbr@453: comm_plugin = config.get("Comm", "engine") morphbr@453: exec("from plugins.comm.%s import *" % comm_plugin) morphbr@453: morphbr@453: # Start Our Server: morphbr@453: server = Server(config) morphbr@453: morphbr@453: print "--> Starting the server..." morphbr@453: morphbr@453: while (server.finish == 0): morphbr@453: con, client = server.getRequest() morphbr@453: morphbr@453: while True: morphbr@453: msg = server.getMsg(1024).strip() morphbr@453: morphbr@453: if not msg: break morphbr@453: morphbr@453: elif (msg == "SETUP"): morphbr@453: setup = server.getMsg(1024).strip().split(" ") morphbr@453: media.setup(setup[0], setup[1], setup[2], \ morphbr@453: setup[3], setup[4], setup[5]) morphbr@453: morphbr@453: elif (msg == "PLAY"): morphbr@453: media.play() morphbr@453: morphbr@453: elif (msg == "STOP"): morphbr@453: media.stop() morphbr@453: morphbr@453: elif (msg == "CLOSE"): morphbr@453: server.finish = 1 morphbr@453: media.stop() morphbr@453: break morphbr@453: morphbr@453: print "[%s] %s: %s" % (now(), client, msg) morphbr@453: morphbr@453: print "[%s] Closing connection with %s" % (now(), client) morphbr@453: server.disconnect_client(con) morphbr@453: morphbr@453: server.stop() morphbr@453: morphbr@453: print "--> Server stopped..."