From: leslie Date: Fri, 18 Jan 2008 18:21:59 +0000 (+0100) Subject: add dedicated housekeeping thread X-Git-Tag: 0.9.0~30 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=0343dad7ba837340e46467e95e62406ae38d3a35;p=sasc-ng.git add dedicated housekeeping thread --- diff --git a/sc.c b/sc.c index 815ccf0..7dc3182 100644 --- a/sc.c +++ b/sc.c @@ -1015,14 +1015,6 @@ bool cSoftCAM::Load(const char *cfgdir) return true; } -void cSoftCAM::HouseKeeping(void) -{ - if(Feature.KeyFile()) keys.HouseKeeping(); - if(!Active(false)) cStructLoaders::Purge(); - cStructLoaders::Load(true); - cStructLoaders::Save(); -} - void cSoftCAM::Shutdown(void) { cStructLoaders::Save(true); @@ -1069,6 +1061,48 @@ bool cSoftCAM::TriggerHook(int CardNum, int id) return dev && dev->Cam() && dev->Cam()->TriggerHook(id); } +// --- cScHousekeeper ---------------------------------------------------------- + +class cScHousekeeper : public cThread { +protected: + virtual void Action(void); +public: + cScHousekeeper(void); + ~cScHousekeeper(); + }; + +cScHousekeeper::cScHousekeeper(void) +:cThread("SC housekeeper") +{ + Start(); +} + +cScHousekeeper::~cScHousekeeper() +{ + Cancel(3); +} + +void cScHousekeeper::Action(void) +{ + int c=0; + while(Running()) { + if(++c==20) { + c=0; + for(int n=cDevice::NumDevices(); --n>=0;) { + cScDvbDevice *dev=dynamic_cast(cDevice::GetDevice(n)); + if(dev && dev->Cam()) dev->Cam()->HouseKeeping(); + } + } + + if(Feature.KeyFile()) keys.HouseKeeping(); + if(!cSoftCAM::Active(false)) cStructLoaders::Purge(); + cStructLoaders::Load(true); + cStructLoaders::Save(); + + cCondWait::SleepMs(987); + } +} + #ifndef STATICBUILD // --- cScDll ------------------------------------------------------------------ @@ -1183,6 +1217,7 @@ private: #ifndef STATICBUILD cScDlls dlls; #endif + cScHousekeeper *keeper; public: cScPlugin(void); virtual ~cScPlugin(); @@ -1193,7 +1228,6 @@ public: virtual bool Initialize(void); virtual bool Start(void); virtual void Stop(void); - virtual void Housekeeping(void); virtual void MainThreadHook(void); virtual cMenuSetupPage *SetupMenu(void); virtual bool SetupParse(const char *Name, const char *Value); @@ -1225,10 +1259,12 @@ cScPlugin::cScPlugin(void) dlls.Load(); #endif cScDvbDevice::Capture(); + keeper=0; } cScPlugin::~cScPlugin() { + delete keeper; delete ScOpts; delete LogOpts; } @@ -1271,11 +1307,13 @@ bool cScPlugin::Start(void) smartcards.LaunchWatcher(); } cScDvbDevice::Startup(); + keeper=new cScHousekeeper; return true; } void cScPlugin::Stop(void) { + delete keeper; keeper=0; cScDvbDevice::Shutdown(); LogStatsDown(); cSoftCAM::Shutdown(); @@ -1363,15 +1401,6 @@ bool cScPlugin::SetupParse(const char *Name, const char *Value) return true; } -void cScPlugin::Housekeeping(void) -{ - for(int n=cDevice::NumDevices(); --n>=0;) { - cScDvbDevice *dev=dynamic_cast(cDevice::GetDevice(n)); - if(dev && dev->Cam()) dev->Cam()->HouseKeeping(); - } - cSoftCAM::HouseKeeping(); -} - #ifndef SASC void cScPlugin::MainThreadHook(void) diff --git a/sc.h b/sc.h index da6f862..cb8f4fe 100644 --- a/sc.h +++ b/sc.h @@ -28,7 +28,6 @@ class cLogHook; class cSoftCAM { public: static bool Load(const char *cfgdir); - static void HouseKeeping(void); static void Shutdown(void); // static bool Active(bool log);