From 88b6acb6418a7b58b9afcd0d5e9e77ff8e220bb5 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Wed, 7 Mar 2012 20:58:25 +0400 Subject: [PATCH] introduce CEitManager class --- src/eitd/eitd.h | 6 ----- src/eitd/sectionsd.cpp | 52 +++++++++++++++++++++++++++++++++-- src/eitd/sectionsd.h | 61 ++++++++++++++++++++++++++++++++++++++++++ src/neutrino.cpp | 9 ++++--- 4 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 src/eitd/sectionsd.h diff --git a/src/eitd/eitd.h b/src/eitd/eitd.h index 016791f49..2b3349a99 100644 --- a/src/eitd/eitd.h +++ b/src/eitd/eitd.h @@ -299,10 +299,4 @@ class CTimeThread : public CSectionThread void setTimeSet(); }; -class CEitManager -{ - private: - public: -}; - #endif diff --git a/src/eitd/sectionsd.cpp b/src/eitd/sectionsd.cpp index a54afb498..535e443a8 100644 --- a/src/eitd/sectionsd.cpp +++ b/src/eitd/sectionsd.cpp @@ -60,6 +60,7 @@ #include #include "eitd.h" +#include "sectionsd.h" #include "edvbstring.h" #include "xmlutil.h" @@ -2009,7 +2010,48 @@ static void *houseKeepingThread(void *) pthread_exit(NULL); } -void sectionsd_main_thread(void * /*data*/) +CEitManager* CEitManager::manager = NULL; +OpenThreads::Mutex CEitManager::m; + +CEitManager::CEitManager() +{ + running = false; +} + +CEitManager::~CEitManager() +{ +} + +CEitManager * CEitManager::getInstance() +{ + m.lock(); + if(manager == NULL) + manager = new CEitManager(); + m.unlock(); + return manager; +} + +bool CEitManager::Start() +{ +xprintf("[sectionsd] start\n"); + if(running) + return false; + + running = true; + return (OpenThreads::Thread::start() == 0); + +} + +bool CEitManager::Stop() +{ + if(!running) + return false; + running = false; + int ret = (OpenThreads::Thread::join() == 0); + return ret; +} + +void CEitManager::run() { pthread_t /*threadTOT,*/ threadHouseKeeping; int rc; @@ -2093,7 +2135,7 @@ printf("SIevent size: %d\n", sizeof(SIevent)); sectionsd_ready = true; - while (!sectionsd_stop && sectionsd_server.run(sectionsd_parse_command, sectionsd::ACTVERSION, true)) { + while (running && sectionsd_server.run(sectionsd_parse_command, sectionsd::ACTVERSION, true)) { sched_yield(); if (threadCN.checkUpdate()) { sched_yield(); @@ -2113,6 +2155,12 @@ printf("SIevent size: %d\n", sizeof(SIevent)); threadEIT.StopRun(); threadCN.StopRun(); threadTIME.StopRun(); +#ifdef ENABLE_SDT + threadSDT.StopRun(); +#endif +#ifdef ENABLE_FREESATEPG + threadFSEIT.StopRun(); +#endif xprintf("broadcasting...\n"); diff --git a/src/eitd/sectionsd.h b/src/eitd/sectionsd.h new file mode 100644 index 000000000..b9fffbb0e --- /dev/null +++ b/src/eitd/sectionsd.h @@ -0,0 +1,61 @@ +/* + * sectionsd.h (network daemon for SI-sections) + * (dbox-II-project) + * + * (C) 2001 by fnbrd (fnbrd@gmx.de) + * + * Copyright (C) 2011-2012 CoolStream International Ltd + * + * License: GPLv2 + * + * 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; + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __sectionsd_h__ +#define __sectionsd_h__ + +#include + +#include +#include +#include "dmx.h" + +//#include "SIutils.hpp" +//#include "SIservices.hpp" +//#include "SIevents.hpp" +//#include "SIsections.hpp" +//#include "SIlanguage.hpp" + +class CEitManager : public OpenThreads::Thread, public OpenThreads::Mutex +{ + private: + bool running; + + static OpenThreads::Mutex m; + static CEitManager * manager; + + CEitManager(); + /* main thread function */ + void run(); + public: + ~CEitManager(); + + static CEitManager * getInstance(); + + bool Start(); + bool Stop(); +}; + +#endif diff --git a/src/neutrino.cpp b/src/neutrino.cpp index 802b9d1b2..662e84a28 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -111,6 +111,7 @@ #include "libdvbsub/dvbsub.h" #include "libtuxtxt/teletext.h" +#include int old_b_id = -1; CHintBox * reloadhintBox = 0; @@ -140,7 +141,7 @@ static pthread_t nhttpd_thread ; //#define DISABLE_SECTIONSD extern int sectionsd_stop; #ifndef DISABLE_SECTIONSD -static pthread_t sections_thread; +//static pthread_t sections_thread; #endif void * sectionsd_main_thread(void *data); extern bool timeset; // sectionsd @@ -1717,7 +1718,8 @@ int CNeutrinoApp::run(int argc, char **argv) hintBox->paint(); #ifndef DISABLE_SECTIONSD - pthread_create (§ions_thread, NULL, sectionsd_main_thread, (void *) NULL); + //pthread_create (§ions_thread, NULL, sectionsd_main_thread, (void *) NULL); + CEitManager::getInstance()->Start(); #endif g_Zapit = new CZapitClient; @@ -3697,7 +3699,8 @@ void stop_daemons(bool stopall) } #ifndef DISABLE_SECTIONSD printf("sectionsd shutdown\n"); - pthread_join(sections_thread, NULL); + //pthread_join(sections_thread, NULL); + CEitManager::getInstance()->Stop(); printf("sectionsd shutdown done\n"); #endif tuxtx_stop_subtitle();