]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
- introduced chained list instead of fixed-length-array to hold parameters
authorsailer <sailer>
Wed, 23 Jul 2003 15:37:04 +0000 (15:37 +0000)
committersailer <sailer>
Wed, 23 Jul 2003 15:37:04 +0000 (15:37 +0000)
- added expiring of parameters
- removed scanTimer for records
-- Benjamin Sailer

allParam/ca/server/paramRecordSet.cc
allParam/ca/server/paramRecordSet.h
allParam/ca/server/paramServer.cc
allParam/ca/server/record.cc
allParam/ca/server/record.h

index 56d6c5f931ff3a9e6b5a21ba4f0cc78374e38749..b815e3000d2f7e59a7dc6859deb927dd9b351882 100644 (file)
@@ -1,4 +1,4 @@
-static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/ca/server/paramRecordSet.cc,v 1.11 2003-05-19 16:05:41 sailer Exp $";
+static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/ca/server/paramRecordSet.cc,v 1.12 2003-07-23 15:37:04 sailer Exp $";
 #define _POSIX_C_SOURCE 199509L
 
 #if HAVE_CONFIG_H
@@ -30,17 +30,22 @@ ParamRecordSet::ParamRecordSet(unsigned int pvCountEstimate) :
 {
        numParamSrc = 0;
        numPv = 0;
+       pv = NULL;
 }
 
 ParamRecordSet::~ParamRecordSet()
 {
+       Record *current;
+       Record *next;
+       for (current = pv; current != NULL; current = next) {
+               next = current->getNext();
+               delete current;
+       }
+
        for (int i = 0 ; i < numParamSrc ; i++) {
                desParam(param[i]);
                delete param[i];
        }
-       for (int i = 0 ; i < numPv ; i++) {
-               delete pvs[i];
-       }
 }
 
 Param *ParamRecordSet::pParam(const char *setup)
@@ -51,10 +56,6 @@ Param *ParamRecordSet::pParam(const char *setup)
                                if (strcmp(param[i]->setup, setup) == 0) {
                                        return param[i];
                                }
-                       } else {
-                               if (setup == NULL) {
-                                       return param[i];
-                               }
                        }
                }
        } else {
@@ -69,6 +70,7 @@ Param *ParamRecordSet::pParam(const char *setup)
 
 pvExistReturn ParamRecordSet::pvExistTest(const casCtx &ctx, const char *pPVName)
 {
+       Record *current;
        char *setup;
        char buf1[PARAM_MAX_NAME_LEN];
        char buf2[PARAM_MAX_NAME_LEN];
@@ -78,8 +80,8 @@ pvExistReturn ParamRecordSet::pvExistTest(const casCtx &ctx, const char *pPVName
        strcpy(buf2, "");
        strcpy(buf3, "");
 
-       for (int i = 0 ; i < numPv ; i++) {
-               if(strcmp(pPVName, pvs[i]->getPVName()) == 0) {
+       for (current = pv; current != NULL; current = current->getNext()) {
+               if(strcmp(pPVName, current->getPVName()) == 0) {
                        return pverExistsHere;
                }
        }
@@ -113,12 +115,48 @@ pvExistReturn ParamRecordSet::pvExistTest(const casCtx &ctx, const char *pPVName
        return pverDoesNotExistHere;
 }
 
+int ParamRecordSet::expireParams(int sec)
+{
+       int now;
+       int retVal = 0;
+       Record *previous = NULL;
+       Record *current = pv;
+       Record *next;
+
+       now = (int) time(NULL);
+
+       while (current != NULL) {
+               next = current->getNext();
+               if (now - sec > current->getLastAccessTime()) {
+                       syslog(LOG_DEBUG, "Removing param %s", current->getPVName());
+                       if (previous != NULL) {
+                               previous->setNext(current->getNext());
+                       } else {
+                               pv = current->getNext();
+                       }
+                       delete current;
+                       retVal++;
+                       numPv--;
+               } else {
+                       previous = current;
+               }
+               current = next;
+       }
+
+       if (retVal) {
+               syslog(LOG_INFO, "%d parameter removed, %d parameter left", retVal, numPv);
+       }
+       return retVal;
+}
+
 #if EPICS_RELEASE >= 314
 pvAttachReturn ParamRecordSet::pvAttach(const casCtx &ctx, const char *pPVName)
 #else
 pvCreateReturn ParamRecordSet::createPV(const casCtx &ctx, const char *pPVName)
 #endif
 {
+       Record *previous;
+       Record *current;
        char *setup;
        char type;
        char buf1[PARAM_MAX_NAME_LEN];
@@ -131,46 +169,59 @@ pvCreateReturn ParamRecordSet::createPV(const casCtx &ctx, const char *pPVName)
        pvCreateReturn retVal(S_casApp_pvNotFound);
 #endif
 
-       for (int i = 0 ; i < numPv ; i++) {
-               if(strcmp(pPVName, pvs[i]->getPVName()) == 0) {
-                       retVal = pvs[i];
-                       return retVal;
-               }
+       for (current = pv, previous = NULL;
+                current != NULL && (strcmp(pPVName, current->getPVName()) != 0);
+                previous = current, current = current->getNext()) {
        }
 
-       if(strncmp(pPVName, "HAD:P", strlen("HAD:P")) == 0) {
-               if(sscanf(pPVName, "HAD:P%c:%[^:]:%[^:]:%[^:]", &type, buf1, buf2, buf3) != 4) {
-                       setup = NULL;
-               } else {
-                       setup = buf1;
-                       for (unsigned int i = 0 ; i < strlen(setup) ; i++) {
-                               setup[i] = tolower(setup[i]);
+       if (current != NULL) {
+               retVal = current;
+               current->access();
+       } else {
+               if(strncmp(pPVName, "HAD:P", strlen("HAD:P")) == 0) {
+                       if(sscanf(pPVName, "HAD:P%c:%[^:]:%[^:]:%[^:]", &type, buf1, buf2, buf3) != 4) {
+                               setup = NULL;
+                       } else {
+                               setup = buf1;
+                               for (unsigned int i = 0 ; i < strlen(setup) ; i++) {
+                                       setup[i] = tolower(setup[i]);
+                               }
                        }
-               }
-               if(pParam(setup) != NULL) {
-                       switch (type) {
-                               case('I'):
-                                       retVal = (pvs[numPv++] = new ParamIntRecord(*this, pParam(setup), pPVName, "Integer"));
-                                       syslog(LOG_DEBUG, "Created Integer Record %s", pPVName);
-                                       break;
-                               case('S'):
-                                       retVal = (pvs[numPv++] = new ParamStringRecord(*this, pParam(setup), pPVName, "String"));
-                                       syslog(LOG_DEBUG, "Created String Record %s", pPVName);
-                                       break;
-                               case('F'):
-                                       retVal = (pvs[numPv++] = new ParamFilenameRecord(*this, pParam(setup), pPVName, "Filename"));
-                                       syslog(LOG_DEBUG, "Created Filename Record %s", pPVName);
-                                       break;
-                               case('B'):
-                                       retVal = (pvs[numPv++] = new ParamBlobRecord(*this, pParam(setup), pPVName, "Binary Large OBject"));
-                                       syslog(LOG_DEBUG, "Created Blob Record %s", pPVName);
-                                       break;
+                       if(pParam(setup) != NULL) {
+                               switch (type) {
+                                       case('I'):
+                                               current = new ParamIntRecord(*this, pParam(setup), pPVName, "Integer");
+                                               syslog(LOG_DEBUG, "Created Integer Record %s", pPVName);
+                                               break;
+                                       case('S'):
+                                               current = new ParamStringRecord(*this, pParam(setup), pPVName, "String");
+                                               syslog(LOG_DEBUG, "Created String Record %s", pPVName);
+                                               break;
+                                       case('F'):
+                                               current = new ParamFilenameRecord(*this, pParam(setup), pPVName, "Filename");
+                                               syslog(LOG_DEBUG, "Created Filename Record %s", pPVName);
+                                               break;
+                                       case('B'):
+                                               current = new ParamBlobRecord(*this, pParam(setup), pPVName, "Binary Large OBject");
+                                               syslog(LOG_DEBUG, "Created Blob Record %s", pPVName);
+                                               break;
+                                       default:
+                                               return S_casApp_pvNotFound;
+                                               break;
+                               }
+                               numPv++;
+                               if (previous != NULL) {
+                                       previous->setNext(current);
+                               } else {
+                                       pv = current;
+                               }
+                               current->access();
+                               retVal = current;
+                       } else {
+                               retVal = S_casApp_pvNotFound;
                        }
-                       return retVal;
-               } else {
-                       return S_casApp_pvNotFound;
                }
        }
-       return S_casApp_pvNotFound;
+       return retVal;
 }
 
index f8ffd15df7d6b997b205140ee6ad33dac1c3ed78..f2bcd67e5d0a887e760b95210e934e618d9ac11d 100644 (file)
@@ -10,12 +10,11 @@ extern "C" {
 #include "record.h"
 
 #define MAX_PARAM_SRC 128
-#define MAX_NUM_PV 1024
 
 class ParamRecordSet : public caServer {
   private:
     int numPv;
-    Record *pvs[MAX_NUM_PV];
+    Record *pv;
 
     int numParamSrc;
     Param *param[MAX_PARAM_SRC];
@@ -24,7 +23,8 @@ class ParamRecordSet : public caServer {
   public:
        ParamRecordSet(unsigned int);
        ~ParamRecordSet();
-       pvExistReturn pvExistTest(const casCtx &, const char *);
+       pvExistReturn pvExistTest(const casCtx &ctx, const char *pPVName);
+       int expireParams(int sec);
 #if EPICS_RELEASE >= 314
        pvAttachReturn pvAttach(const casCtx &ctx, const char *pPVName);
 #else
index 6f997e165263a4f7fe2d7cebea65bf1a6634b657..3556079fb89e22158264c3c7d459cf52d5031e2e 100644 (file)
@@ -1,5 +1,5 @@
 static const char rcsId[] =
-       "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/ca/server/paramServer.cc,v 1.10 2003-07-22 13:31:31 sailer Exp $";
+       "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/ca/server/paramServer.cc,v 1.11 2003-07-23 15:37:04 sailer Exp $";
 #define _POSIX_C_SOURCE 199506L
 #define SYSLOG_NAMES
 
@@ -23,6 +23,11 @@ extern int optind, opterr, optopt;
 
 #include "paramRecordSet.h"
 
+#define MAX_NUM_PV 1024
+
+#define SCAN_INTERVAL 100.0
+#define EXPIRE_INTERVAL 300
+
 #ifndef NDEBUG
 static void profSignalHandler(int sig)
 {
@@ -141,7 +146,8 @@ int main(int argc, char *argv[])
        cas->setDebugLevel(0u);
 
        while (aitTrue) {
-               fileDescriptorManager.process(1000.0);
+               fileDescriptorManager.process(SCAN_INTERVAL);
+               cas->expireParams(EXPIRE_INTERVAL);
        }
 
        delete cas;
index d7f096960f88709db98045243c8650c05afcfc83..59a916d1a5fb84fb754a0185c7f054c12eb882c4 100644 (file)
@@ -1,4 +1,4 @@
-static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/ca/server/record.cc,v 1.7 2003-07-09 11:34:34 sailer Exp $";
+static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/ca/server/record.cc,v 1.8 2003-07-23 15:37:04 sailer Exp $";
 #define _POSIX_C_SOURCE 199506L
 
 #if HAVE_CONFIG_H
@@ -25,6 +25,7 @@ Record::Record(caServer &cas, const Param *p, const char *n, const char *u, aitE
        char buf2[PARAM_MAX_NAME_LEN];
        char buf3[PARAM_MAX_NAME_LEN];
 
+       myPNext = NULL;
        strcpy (pPVName, n);
        interest = aitFalse;
 
@@ -47,10 +48,12 @@ Record::Record(caServer &cas, const Param *p, const char *n, const char *u, aitE
 
        interest = aitFalse;
 
+#if 0
        recordScanTimer = new scanTimer(*this);
 #if EPICS_RELEASE >= 314
        timer.start(*recordScanTimer, 100.0);
 #endif
+#endif
 }
 
 Record::~Record()
index 555654a80a687b5fb001dc90646a5d95b993fff5..49253383d9437d6556684bd1812ec29d78d4e537 100644 (file)
@@ -17,6 +17,8 @@
 #include <gddAppFuncTable.h>
 
 extern "C" {
+  #include <time.h>
+
   #include <allParam.h>
 }
 
@@ -33,10 +35,14 @@ class Record : public casPV {
 #if EPICS_RELEASE >= 314
        epicsTimer &timer;
 #endif
+#if 0
        scanTimer *recordScanTimer;
+#endif
        aitBool interest;
        epicsAlarmCondition alarmStatus;
        epicsAlarmSeverity alarmSeverity;
+       Record *myPNext;
+       int lastAccessTime;
 
        ArrayDestructor *pDest;
        char pPVName[PARAM_MAX_VALUE_LEN];
@@ -47,6 +53,11 @@ class Record : public casPV {
        Record(caServer &cas, const Param *p, const char *n, const char *u, aitEnum t);
        ~Record();
 
+       inline void setNext(Record *next) { myPNext = next; }
+       inline Record *getNext() { return myPNext; }
+       inline void access() { time_t t; t = time(NULL); lastAccessTime = (int) t; }
+       inline int getLastAccessTime() { return lastAccessTime; }
+
        void destroy();
        caStatus interestRegister();
        void interestDelete();