📄 manager.cpp
字号:
/******************************************************************************** manager.cpp: Vls manager*-------------------------------------------------------------------------------* (c)1999-2001 VideoLAN* $Id: manager.cpp,v 1.20 2002/09/30 15:17:53 jpsaman Exp $** Authors: Benoit Steiner <benny@via.ecp.fr>* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>** This program is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License* as published by the Free Software Foundation; either version 2* of the License, or (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.**-------------------------------------------------------------------------------********************************************************************************///------------------------------------------------------------------------------// Preamble//------------------------------------------------------------------------------#include "../core/defs.h"#include "config.h"#include "../core/core.h"#include "../mpeg/mpeg.h"#include "../mpeg/ts.h"#include "../mpeg/rtp.h"#include "program.h"#include "request.h"#include "admin.h"#include "buffer.h"#include "output.h"#include "channel.h"#include "broadcast.h"#include "input.h"#include "repository.h"#include "directory.h"#include "tsstreamer.h"#include "manager.h"#ifndef _WIN32 #include "daemon.h"#endif#include "vls.h"#include "repository.cpp"/******************************************************************************** C_Manager****************************************************************************************************************************************************************///------------------------------------------------------------------------------// Constructor//------------------------------------------------------------------------------C_Manager::C_Manager(handle hLog, C_EventHub* pHub) : m_cEventQueued(0){ ASSERT(hLog); m_hLog = hLog; m_pEventHub = pHub; m_bStop = false;}//------------------------------------------------------------------------------// Destructor//------------------------------------------------------------------------------C_Manager::~C_Manager(){}//------------------------------------------------------------------------------// Initialization//------------------------------------------------------------------------------int C_Manager::Init(){ int iRc = NO_ERR; try { InitChannels(); InitInputs(); InitPgrmTable(); Create(); } catch(E_Exception e) { Log(m_hLog, LOG_ERROR, "Unable to init manager: " + e.Dump()); iRc = GEN_ERR; } return iRc;}//------------------------------------------------------------------------------// Execution//------------------------------------------------------------------------------int C_Manager::Run(){ int iRc = NO_ERR; // Nothing to do yet return iRc;}//------------------------------------------------------------------------------// Stop the execution//------------------------------------------------------------------------------int C_Manager::Stop(){ Log(m_hLog, LOG_NOTE, "Stopping the manager"); int iRc = NO_ERR; try { StopPrograms(); C_Thread::Stop(); Log(m_hLog, LOG_NOTE, "Manager stopped"); } catch(E_Exception e) { Log(m_hLog, LOG_ERROR, "Unable to stop the manager:\n" + e.Dump()); iRc = GEN_ERR; } return iRc;}//------------------------------------------------------------------------------// Destruction//------------------------------------------------------------------------------int C_Manager::Destroy(){ int iRc = NO_ERR; Log(m_hLog, LOG_NOTE, "Destroying the manager"); try { DestroyPgrmTable(); DestroyInputs(); DestroyChannels(); } catch(E_Exception e) { Log(m_hLog, LOG_ERROR, "Unable to destroy manager: " + e.Dump()); iRc = e.GetCode(); } if(!iRc) Log(m_hLog, LOG_NOTE, "Manager destroyed"); return iRc;}//------------------------------------------------------------------------------////------------------------------------------------------------------------------void C_Manager::InitPgrmTable(){ // Lock the input repository and the program list m_cInputList.Lock(); m_cProgramList.Lock(); // Get the input lists of programs and merge them with the manager one C_RepositoryBrowser<C_String, C_Input> cIterator = m_cInputList.CreateBrowser(); while(cIterator.HasNextItem()) { C_Input* pInput = cIterator.GetNextItem(); C_List<C_Program> cInputPgrms = pInput->GetAvailablePgrms(); unsigned int iPgrmNumber = cInputPgrms.Size(); for(unsigned int j = 0; j < iPgrmNumber; j++) { m_cProgramList.Add(cInputPgrms[j], pInput); } } // Unlock the input repository and the program list m_cInputList.UnLock(); m_cProgramList.UnLock();}//------------------------------------------------------------------------------////------------------------------------------------------------------------------void C_Manager::DestroyPgrmTable(){ // Nothing to do yet}//------------------------------------------------------------------------------// Inputs initialization//------------------------------------------------------------------------------void C_Manager::InitInputs(){ // Get the names of all the sources C_Application* pApp = C_Application::GetApp(); ASSERT(pApp); C_Vector<C_Setting> vInputs = pApp->GetSettings("Inputs"); // Lock the input repository m_cInputList.Lock(); // Create the corresponding inputs for(unsigned int i = 0; i < vInputs.Size(); i++) { // Current input C_Input* pInput = NULL; // Get input name and type C_Setting cCurrentInput = vInputs[i]; C_String strInputName = cCurrentInput.GetName(); C_String strInputType = cCurrentInput.GetValue(); // Create the input for the given source C_InputModule* pModule = (C_InputModule*) C_Application::GetModuleManager() ->GetModule("input", strInputType); if(pModule) { pInput = pModule->NewInput(strInputName); ASSERT(pInput); pInput->SetEventHandler(this); Log(m_hLog, LOG_NOTE, "Starting input '"+strInputName+"'"); try { // Initialize the input pInput->Init(); // And register it m_cInputList.Add(strInputName, pInput); Log(m_hLog, LOG_NOTE, "Input '" + strInputName + "' sucessfully initialised"); } catch(E_Exception e) { Log(m_hLog, LOG_ERROR, "Unable to start input '" + strInputName + "': " + e.Dump()); delete pInput; } } else { Log(m_hLog, LOG_ERROR, "Input type \"" + strInputType + "\" invalid"); } } // Unlock the input repository m_cInputList.UnLock();}//------------------------------------------------------------------------------// Inputs destruction//------------------------------------------------------------------------------void C_Manager::DestroyInputs(){ // Lock the input repository m_cInputList.Lock(); C_RepositoryBrowser<C_String, C_Input> cIterator = m_cInputList.CreateBrowser(); while(cIterator.HasNextItem()) { C_Input* pInput = cIterator.GetNextItem(); try { pInput->Destroy(); Log(m_hLog, LOG_NOTE, "Input "+pInput->GetName()+" correctly stopped"); } catch(E_Exception e) { // Just log the pb and go on with inputs destruction C_String strInputName = pInput->GetName(); Log(m_hLog, LOG_ERROR, "Unable to stop input "+strInputName+": "+e.Dump()); } } // Unlock the input repository m_cInputList.UnLock();}//------------------------------------------------------------------------------// Channels initialization//------------------------------------------------------------------------------void C_Manager::InitChannels(){ // Lock the channel repository m_cChannelList.Lock(); // Get the names of all the channels C_Application* pApp = C_Application::GetApp(); ASSERT(pApp); C_Vector<C_Setting> vChannels = pApp->GetSettings("Channels"); // Create the corresponding channels for(unsigned int i = 0; i < vChannels.Size(); i++) { // Current channel C_Channel* pChannel = NULL; // Get channel name and type C_Setting cCurrentChannel = vChannels[i]; C_String strChannelName = cCurrentChannel.GetName(); C_String strChannelType = cCurrentChannel.GetValue(); C_ChannelModule* pModule = (C_ChannelModule*) C_Application::GetModuleManager() ->GetModule("channel", strChannelType); if(pModule) { pChannel = pModule->NewChannel(strChannelName); ASSERT(pChannel); m_cChannelList.Add(strChannelName, pChannel); Log(m_hLog, LOG_NOTE, "Channel '"+strChannelName+"' created"); } else { Log(m_hLog, LOG_ERROR, "Channel type \"" + strChannelType + "\" invalid"); } } // Unlock the channel repository m_cChannelList.UnLock();}//------------------------------------------------------------------------------// Channels destruction//------------------------------------------------------------------------------void C_Manager::DestroyChannels(){ // Just make sure that the channel is free // to do}//------------------------------------------------------------------------------////------------------------------------------------------------------------------void C_Manager::StopPrograms(){ // Stop all th programs so that the inputs could be destroyed m_cBroadcasts.Lock(); C_Vector<C_Request> cRequests; C_RepositoryBrowser<C_String, C_Broadcast> cIterator1 = m_cBroadcasts.CreateBrowser(); while(cIterator1.HasNextItem()) { C_Broadcast* pBroadcast = cIterator1.GetNextItem(); C_Request* pRequest = new C_Request("stop"); pRequest->SetArg("channel", pBroadcast->GetChannel()->GetName()); cRequests.Add(pRequest); } m_cBroadcasts.UnLock(); unsigned int iCount = cRequests.Size(); for(unsigned int i = 0; i < iCount; i++) { C_Request& cRequest = cRequests[i]; HandleRequest(cRequest); LogDbg(m_hLog, "Remove the broadcast"); m_cBroadcasts.Lock(); int iRc = m_cBroadcasts.Remove(cRequest.GetArg("program") + ":" + cRequest.GetArg("input")); m_cBroadcasts.UnLock(); LogDbg(m_hLog, C_String("Broadcast removed with status ") + iRc); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -