]> www.vanbest.org Git - sasc-ng.git/commitdiff
add dedicated housekeeping thread
authorleslie <unknown>
Fri, 18 Jan 2008 18:21:59 +0000 (19:21 +0100)
committerleslie <unknown>
Fri, 18 Jan 2008 18:21:59 +0000 (19:21 +0100)
sc.c
sc.h

diff --git a/sc.c b/sc.c
index 815ccf041eb0c9a5104bdcb435b2341a77fbc888..7dc318247cfafcf8b01d5e728e722b685d6ede7a 100644 (file)
--- 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<cScDvbDevice *>(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<cScDvbDevice *>(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 da6f86283cf4f685743f89603e24c8e57b4761a8..cb8f4feec0fe9e802bbefc857b84888304292bf1 100644 (file)
--- 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);