]> www.vanbest.org Git - sasc-ng.git/commitdiff
switch ECM cache to new loading code (now ecm.cache)
authormirv <unknown>
Thu, 3 Jan 2008 19:43:49 +0000 (20:43 +0100)
committermirv <unknown>
Thu, 3 Jan 2008 19:43:49 +0000 (20:43 +0100)
cam.c
cam.h
data.c
data.h
sc.c

diff --git a/cam.c b/cam.c
index 047460382fe605a32fc5ef23d9d8b76399fd360b..bd5e17858eef0c70cbd02cf8732281887ba14cdc 100644 (file)
--- a/cam.c
+++ b/cam.c
@@ -61,6 +61,8 @@
 #define MAX_ECM_HOLD    15000 // delay before an idle handler stops processing
 #define CAID_TIME      300000 // time between caid scans
 
+#define ECMCACHE_FILE "ecm.cache"
+
 #define L_HEX       2
 #define L_HEX_ECM   LCLASS(L_HEX,2)
 #define L_HEX_EMM   LCLASS(L_HEX,4)
@@ -570,29 +572,13 @@ void cLogger::Process(cPidFilter *filter, unsigned char *data, int len)
 // -- cEcmData -----------------------------------------------------------------
 
 class cEcmData : public cEcmInfo {
-private:
-  bool del;
 public:
-  cEcmData(void);
-  cEcmData(cEcmInfo *e);
-  bool Save(FILE *f);
+  cEcmData(void):cEcmInfo() {}
+  cEcmData(cEcmInfo *e):cEcmInfo(e) {}
+  virtual cString ToString(bool hide=false);
   bool Parse(const char *buf);
-  void Delete(void) { del=true; }
-  bool IsDeleted(void) const { return del; }
   };
 
-cEcmData::cEcmData(void)
-:cEcmInfo()
-{
-  del=false;
-}
-
-cEcmData::cEcmData(cEcmInfo *e)
-:cEcmInfo(e)
-{
-  del=false;
-}
-
 bool cEcmData::Parse(const char *buf)
 {
   char Name[64];
@@ -610,16 +596,21 @@ bool cEcmData::Parse(const char *buf)
   return false;
 }
 
-bool cEcmData::Save(FILE *f)
+cString cEcmData::ToString(bool hide)
 {
-  fprintf(f,"%d:%x:%x:%s:%x/%x:%x:%x/%x",prgId,source,transponder,name,caId,emmCaId,provId,ecm_pid,ecm_table);
+  char *str;
   if(data) {
-    char *str=AUTOARRAY(char,dataLen*2+2);
-    fprintf(f,":%d:%s\n",dataLen,HexStr(str,data,dataLen));
+    str=AUTOARRAY(char,dataLen*2+2);
+    sprintf(str,":%d:%s",dataLen,HexStr(str,data,dataLen));
+    }
+  else {
+    str=AUTOARRAY(char,4);
+    strcpy(str,":0");
     }
-  else
-    fprintf(f,":0\n");
-  return ferror(f)==0;
+  return cString::sprintf("%d:%x:%x:%s:%x/%x:%x:%x/%x%s",
+                            prgId,source,transponder,name,
+                            caId,emmCaId,provId,ecm_pid,ecm_table,
+                            str);
 }
 
 // -- cEcmCache ----------------------------------------------------------------
@@ -627,17 +618,18 @@ bool cEcmData::Save(FILE *f)
 cEcmCache ecmcache;
 
 cEcmCache::cEcmCache(void)
-:cLoader("ECM")
+:cStructList<cEcmData>("ecm cache",ECMCACHE_FILE,true,true,false,false)
 {}
 
 void cEcmCache::New(cEcmInfo *e)
 {
-  Lock();
+  ListLock(true);
   cEcmData *dat;
   if(!(dat=Exists(e))) {
+    ListUnlock();
+    AutoGenWarn();
     dat=new cEcmData(e);
-    Add(dat);
-    Modified();
+    AddItem(dat,0,0);
     PRINTF(L_CORE_ECM,"cache add prgId=%d source=%x transponder=%x ecm=%x/%x",e->prgId,e->source,e->transponder,e->ecm_pid,e->ecm_table);
     }
   else {
@@ -647,25 +639,26 @@ void cEcmCache::New(cEcmInfo *e)
       }
     if(dat->Update(e))
       Modified();
+    ListUnlock();
     }
   e->SetCached();
-  Unlock();
 }
 
 cEcmData *cEcmCache::Exists(cEcmInfo *e)
 {
-  for(cEcmData *dat=First(); dat; dat=Next(dat))
-    if(!dat->IsDeleted() && dat->Compare(e)) return dat;
-  return 0;
+  cEcmData *dat;
+  for(dat=First(); dat; dat=Next(dat))
+    if(dat->Valid() && dat->Compare(e)) break;
+  return dat;
 }
 
 int cEcmCache::GetCached(cSimpleList<cEcmInfo> *list, int sid, int Source, int Transponder)
 {
   int n=0;
   list->Clear();
-  Lock();
+  ListLock(false);
   for(cEcmData *dat=First(); dat; dat=Next(dat)) {
-    if(!dat->IsDeleted() && dat->prgId==sid && dat->source==Source && dat->transponder==Transponder) {
+    if(dat->Valid() && dat->prgId==sid && dat->source==Source && dat->transponder==Transponder) {
       cEcmInfo *e=new cEcmInfo(dat);
       if(e) {
         PRINTF(L_CORE_ECM,"from cache: system %s (%04x) id %04x with ecm %x/%x",e->name,e->caId,e->provId,e->ecm_pid,e->ecm_table);
@@ -675,68 +668,36 @@ int cEcmCache::GetCached(cSimpleList<cEcmInfo> *list, int sid, int Source, int T
         }
       }
     }
-  Unlock();
+  ListUnlock();
   return n;
 }
 
 void cEcmCache::Delete(cEcmInfo *e)
 {
-  Lock();
+  ListLock(false);
   cEcmData *dat=Exists(e);
+  ListUnlock();
   if(dat) {
-    dat->Delete();
-    Modified();
+    DelItem(dat);
     PRINTF(L_CORE_ECM,"invalidated cached prgId=%d source=%x transponder=%x ecm=%x/%x",dat->prgId,dat->source,dat->transponder,dat->ecm_pid,dat->ecm_table);
     }
-  Unlock();
 }
 
 void cEcmCache::Flush(void)
 {
-  Lock();
+  ListLock(true);
   Clear();
   Modified();
   PRINTF(L_CORE_ECM,"cache flushed");
-  Unlock();    
+  ListUnlock();
 }
 
-void cEcmCache::Load(void)
+cStructItem *cEcmCache::ParseLine(char *line)
 {
-  Lock();
-  Clear();
-  Unlock();
-}
-
-bool cEcmCache::Save(FILE *f)
-{
-  bool res=true;
-  Lock();
-  for(cEcmData *dat=First(); dat;) {
-    if(!dat->IsDeleted()) {
-      if(!dat->Save(f)) { res=false; break; }
-      dat=Next(dat);
-      }
-    else {
-      cEcmData *n=Next(dat);
-      Del(dat);
-      dat=n;
-      }
-    }
-  Modified(!res);
-  Unlock();
-  return res;
-}
-
-bool cEcmCache::ParseLine(const char *line, bool fromCache)
-{
-  bool res=false;
   cEcmData *dat=new cEcmData;
-  if(dat && dat->Parse(line)) {
-    if(!Exists(dat)) { Add(dat); dat=0; }
-    res=true;
-    }
+  if(dat && dat->Parse(line) && !Exists(dat)) return dat;
   delete dat;
-  return res;
+  return 0;
 }
 
 // -- cEcmSys ------------------------------------------------------------------
diff --git a/cam.h b/cam.h
index 18e6b88ac4e1dabd8df40c8acba5a3b91e9683d7..697823caadac78319cd9bce16b9475d3db06a6ad 100644 (file)
--- a/cam.h
+++ b/cam.h
@@ -41,18 +41,16 @@ class cPrg;
 
 // ----------------------------------------------------------------
 
-class cEcmCache : public cLoader, cMutex, cSimpleList<cEcmData> {
+class cEcmCache : public cStructList<cEcmData> {
 private:
   cEcmData *Exists(cEcmInfo *e);
 public:
   cEcmCache(void);
-  void Load(void);
   void New(cEcmInfo *e);
   int GetCached(cSimpleList<cEcmInfo> *list, int sid, int Source, int Transponder);
   void Delete(cEcmInfo *e);
   void Flush(void);
-  virtual bool Save(FILE *f);
-  virtual bool ParseLine(const char *line, bool fromCache);
+  virtual cStructItem *ParseLine(char *line);
   };
 
 extern cEcmCache ecmcache;
diff --git a/data.c b/data.c
index 2b6a7771431ddfa303ef21463b8dc13513026417..85af8f6b349b7938146d2ebdcb7dc6c4a9a0c3b3 100644 (file)
--- a/data.c
+++ b/data.c
@@ -156,7 +156,7 @@ cStructItem::~cStructItem()
 void cStructItem::SetComment(const char *com)
 {
   free(comment);
-  comment=strdup(com);
+  comment=com ? strdup(com):0;
 }
 
 bool cStructItem::Save(FILE *f)
@@ -222,12 +222,28 @@ void cStructLoader::DelItem(cStructItem *d, bool keep)
     if(keep) {
       cStructItem *n=new cCommentItem;
       n->SetComment(cString::sprintf(";%s%s",*d->ToString(false),d->Comment()?d->Comment():""));
+      ListLock(true);
       Add(n,d);
+      ListUnlock();
       }
     Modified();
     }
 }
 
+void cStructLoader::AutoGenWarn(void)
+{
+  if(Count()==0) {
+    cStructItem *n=new cCommentItem;
+    n->SetComment("## This is a generated file. DO NOT EDIT!!");
+    cStructItem *n2=new cCommentItem;
+    n2->SetComment("## This file will be OVERWRITTEN WITHOUT WARNING!!");
+    ListLock(true);
+    Add(n);
+    Add(n2);
+    ListUnlock();
+    }
+}
+
 void cStructLoader::SetCfgDir(const char *cfgdir)
 {
   free(path);
diff --git a/data.h b/data.h
index 1dbaadb81fd8b3d05bb332eb54a6ed5a98a26b3b..ca6c5cde2b2cf4c338cb86f64285ec6029dd76bb 100644 (file)
--- a/data.h
+++ b/data.h
@@ -109,6 +109,7 @@ protected:
   bool IsModified(void) const { return modified; }
   void ListLock(bool rw) { lock.Lock(rw); }
   void ListUnlock(void) { lock.Unlock(); }
+  void AutoGenWarn(void);
   virtual void PostLoad(void) {}
 public:
   cStructLoader(const char *Type, const char *Filename, bool rw, bool miok, bool wat, bool verb);
@@ -214,7 +215,7 @@ public:
 
 // ----------------------------------------------------------------
 
-class cEcmInfo : public cSimpleItem {
+class cEcmInfo : public cStructItem {
 private:
   bool cached, failed;
   //
@@ -234,6 +235,7 @@ public:
   cEcmInfo(const cEcmInfo *e);
   cEcmInfo(const char *Name, int Pid, int CaId, int ProvId);
   ~cEcmInfo();
+  virtual cString ToString(bool hide=false) { return ""; }
   bool Compare(const cEcmInfo *e);
   bool Update(const cEcmInfo *e);
   void SetSource(int PrgId, int Source, int Transponder);
diff --git a/sc.c b/sc.c
index d2c0a07da93e6f82daa6be6376743eaa9de2efe3..ddf1eb435672e648700f0d228b8bfe9a3eddcf7c 100644 (file)
--- a/sc.c
+++ b/sc.c
@@ -1006,7 +1006,6 @@ bool cScSetup::Ignore(unsigned short caid)
 
 bool cSoftCAM::Load(const char *cfgdir)
 {
-  ecmcache.Load();
   if(!Feature.KeyFile()) keys.Disable();
   cStructLoaders::Load(false);
   if(Feature.KeyFile() && keys.Count()<1)