]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
*** empty log message ***
authorhades <hades>
Wed, 7 Mar 2001 10:21:09 +0000 (10:21 +0000)
committerhades <hades>
Wed, 7 Mar 2001 10:21:09 +0000 (10:21 +0000)
19 files changed:
allParam/Makefile
allParam/README
allParam/VERSION
allParam/ca/Makefile
allParam/ca/caParam.c
allParam/ca/caParam.h [deleted file]
allParam/file/Makefile
allParam/file/fileParam.c
allParam/file/fileParam.h [deleted file]
allParam/include/allParam.h
allParam/ora/Makefile
allParam/ora/oraParam.h [deleted file]
allParam/ora/oraParam.pc
allParam/psql/Makefile
allParam/psql/psqlParam.c
allParam/psql/psqlParam.h [deleted file]
allParam/tcl/Makefile
allParam/tcl/tclParam.c
allParam/tcl/tclParam.h [deleted file]

index 55cdb1cd53950779be3814a06b29947d2971112c..bc5010e683594d0d8c15640fffc31269ccb95c4c 100644 (file)
@@ -36,15 +36,15 @@ $(PARAMLIBES) :
        cd $@ ; $(MAKE)
 
 ca_install :
-       cd ca ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)/ca"
+       cd ca ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)"
 file_install :
-       cd file ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)/file"
+       cd file ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)"
 ora_install :
-       cd ora ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)/ora"
+       cd ora ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)"
 psql_install :
-       cd psql ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)/psql"
+       cd psql ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)"
 tcl_install :
-       cd tcl ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)/tcl"
+       cd tcl ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)"
 
 $(TESTS) :
        cd test ; $(MAKE) $@
index 288bf67c5b6be9ed66f871157177caa53913705f..5f460b63fae7fb4df509fe84ecefaabaa320f11b 100644 (file)
@@ -1,18 +1,18 @@
 Author:  Benjamin Sailer
          TUM/E12
          Benjamin.Sailer@ph.tum.de
-Version: 0.1
-Date:    2000-09-10
+Version: 0.2
+Date:    2001-02-19
 
-Param libraries
-===============
+allParam libraries
+==================
 
 Content
 -------
 
 1. The scope of the README files
-2. How to install the param libraries
-3. How to use the param libraries
+2. How to install the allParam libraries
+3. How to use the allParam libraries
 4. Known bugs and further developement perspectives
 
 1. The scope of the README files
@@ -23,36 +23,39 @@ the special param library build there. The test directory contains a litte test
 suite to check if the explicit defined behaviour of the libraries is fulfilled
 within the concrete enviroment. Unfortunately this testing suite cannot check
 if the parameter sources needed for a correct work are available. In case of
-files this is not that big problem because if you set the enviroment variable
-DAQSLOW_PARAM_FILE to the file param.tcl in the test directory, it should
-work out fine. If the parameter source is a database, of course the situation
-is bad because you need connection to the explicit database containing exactly
-the data tested within the test suite (for liboraParam.a you even need
-connection to the database at compiletime). With libcaParam.a there can only
-be tested a complete setup of a EPICS parameter server, which is contained in
-the HADES DAQ runctrl package, together with the param library.
-
-2. How to install the param libraries
--------------------------------------
+files this is not that big problem because if you unset the enviroment
+variables DAQSLOW_PARAM_FILE and SETUP, it should work out fine. If the
+parameter source is a database, of course the situation is bad because you need
+connection to the explicit database containing exactly the data tested within
+the test suite (for liboraParam.a you even need connection to the database at
+compiletime). With libcaParam.a only a complete setup of a EPICS parameter
+server, which is contained in the HADES DAQ runctrl package, together with the
+param library can be tested.
+
+2. How to install the allParam libraries
+----------------------------------------
 
   Retrieve the libraries via ftp from
-ftp://ftp.e12.physik.tu-muenchen.de/pub/bsailer/param/param.0.1.tar.Z
+ftp://ftp.e12.physik.tu-muenchen.de/pub/hadsoft/allParam.0.2.tar.Z
 and extract them to a directory of your own choice (which is only needed for
-building, testing and installing the libraries).
-  Go into the extracted directory param and type
+building, testing and installing the libraries). Although the sources are also
+available via CVS, it is recommended to use only the tar archives, while CVS
+is reserved for the developers of the libraries (as the checkouts are logged
+by CVS).
+  Go into the extracted directory allParam and type
 $ make <lib>_all
 where <lib> is one of 'ca', 'file', 'ora', 'psql' or 'tcl', or simply 
 $ make
 if you want to make them all. '_all' includes installation to your home
-directory respectively the subdirectories lib/$SYSTYPE and include/<lib> as
-well as compiling and running a test suite in the subdirectory param/test.
-protocol named <lib>_test_protocol.txt is created there but take care of the
+directory respectively the subdirectories lib/$SYSTYPE and include as well as
+compiling and running a test suite in the subdirectory allParam/test. A
+protocol named <lib>_test_protocol.txt is created there but take care of the
 fact, that failures may come due to missing parameter sources - as mentioned
 above.
   The usage of the enviroment variable $SYSTYPE applies to the fact that your
 home directory may be available from different os' with different binary file
 formats, which you should be able to use simultaneously. If you don't have this
-envviroment variable available, you can make good this placing the lines
+envviroment variable available, you can correct this placing the lines
 SYSTYPE=$(echo "$(uname -m)_$(uname -s)_$(uname -r)" |
     tr -d [:cntrl:] |
     tr [:lower:] [:upper:] |
@@ -63,18 +66,27 @@ into your ~/.profile.
 foreseen, if you want to make the libraries available systemwide as root),
 the change of LIBPATH and INCPATH in the Makefiles is straight forward.
 
-3. How to use the param libraries
----------------------------------
+3. How to use the allParam libraries
+------------------------------------
 
   The param libraries provide four functions to access parmeters from different
 sources:
+
 - Param_getStringArray() retrieves an array of strings,
 - Param_getIntArray() makes a conversion to unsigned long integers (if all
   elements of the retrieved array can be converted properly; to decide this,
-  the c-function strtoul(3) is used)
+  the C-function strtoul(3) is used)
 - Param_getString() and
 - Param_getInt() are aliases that retrieve only a scalar value (the first
   element of an array)
+
+  Additionally, there are two functions that allow to store scalar values of
+unsigned integers respectively strings to the parameter source. These functions
+are called
+
+- Param_storeString() and
+- Param_storeInt().
+
 All functions have a return value that indicates the success (0) or failure
 of the action, all functions need to get a pointer to user-supplied space
 for the result and all funtions put the number of elements returned into a
@@ -85,7 +97,7 @@ be returned.
 parameter source when looking into Param_getErrStr().
   At first you have to invoke a new Param structure and call the constructor
 of it via
-#include <param.h>
+#include <allParam.h>
 ...
 {
        Param *param;
@@ -100,18 +112,34 @@ of it via
                exit(-1);
        }
 }
+... respectively ...
+{
+       Param *param;
+       const char *setup = "setup";
+       param = malloc(sizeof(Param));
+       if(param != 0) {
+               if(conSetupParam(param, setup) != 0) {
+                       sprintf(stderr, "conSetupParam() for param failed.\n"); 
+                       exit(-1);
+               }
+       } else {
+               sprintf(stderr, "malloc() for param failed.\n"); 
+               exit(-1);
+       }
+}
 ...
 {
        desParam(param);
        free param;
 }
-Here also shown is the deletion of the Param structure. Then you can
-immediately start retieving values. Note, that a not found parameter does not
-result in an -1 return value but only in the number 0 of returned rows. So
-check the returned rows all the time before you use the result. The content of
-the reserved space is not defined beyond the retrieved values. Note that
-returned strings may have a length of PARAM_MAX_VALUE_LEN and prepare enought
-space for them. Here some examples (one for each function):
+Here you also can see the deletion of the Param structure.
+After calling one of the two constructors, you can immediately start retieving
+values. Note, that a not found parameter does not result in an -1 return value
+but only in the number 0 of returned rows. So check the returned rows all the
+time before you use the result. The content of the reserved space is not
+defined beyond the retrieved values. Note that returned strings may have a
+length of PARAM_MAX_VALUE_LEN and prepare enought space for them. Here some
+examples (one for each function):
 
 /* Param_getString */
        const char *name = "tname";
@@ -121,7 +149,7 @@ space for them. Here some examples (one for each function):
        if(Param_getString(param, name, idx1, &row, values) != 0) {
                sprintf(stderr, "%s : Param_getString() failed: %s",
                        argv[0], Param_getErrStr(param));
-                       exit (-1);
+               exit (-1);
        } else if(row == 0) {
                sprintf(stderr, "%s(%s) not found.\n", name, idx1);
        } else {
@@ -134,7 +162,7 @@ space for them. Here some examples (one for each function):
        if(Param_getInt(param, name, idx2, &row, &valuei) != 0) {
                sprintf(stderr, "%s : Param_getInt() failed: %s",
                        argv[0], Param_getErrStr(param));
-                       exit (-1);
+               exit (-1);
        } else if(row == 0) {
                sprintf(stderr, "%s(%s) not found.\n", name, idx2);
                exit (-1);
@@ -158,7 +186,7 @@ space for them. Here some examples (one for each function):
        if(Param_getStringArray(param, name, idx3, maxrows, &rows, valuesa) != 0) {
                sprintf(stderr, "%s : Param_getStringArray() failed: %s",
                        argv[0], Param_getErrStr(param));
-                       exit (-1);
+               exit (-1);
        } else if(row == 0) {
                sprintf(stderr, "%s(%s) not found.\n", name, idx3);
                exit (-1);
@@ -175,7 +203,7 @@ space for them. Here some examples (one for each function):
        if(Param_getIntArray(param, name, idx4, maxrows, &rows, valueia) != 0) {
                sprintf(stderr, "%s : Param_getIntArray() failed: %s",
                        argv[0], Param_getErrStr(param));
-                       exit (-1);
+               exit (-1);
        } else if(rows == 0) {
                sprintf(stderr, "%s(%s) not found.\n", name, idx4);
                exit (-1);
index 49d59571fbf6e077eece30f8c418b6aad15e20b0..3b04cfb60da13a716867848ebeb2191a164887d9 100644 (file)
@@ -1 +1 @@
-0.1
+0.2
index f5246f50961ff0437a486705f3f017c75c047c78..4f3aae4e5f3b65558f9107a157b6dc99671e4df0 100644 (file)
@@ -1,16 +1,16 @@
 CFLAGS = -g -ansi -Wall -I$(EPICS_BASE)/include \
-  -I$(EPICS_BASE)/include/os/$(HOST_ARCH)
+  -I$(EPICS_BASE)/include/os/$(HOST_ARCH) -I../include
 
 libcaParam.a : caParam.o
        $(AR) $(ARFLAGS) $@ $<
 
-caParam.o : caParam.c caParam.h
+caParam.o : caParam.c
 
 install : libcaParam.a
        -mkdir -p $(LIBDIR)
        install -m 644 $< $(LIBDIR)
        -mkdir -p $(INCDIR)
-       install -m 644 caParam.h $(INCDIR)/allParam.h
+       install -m 644 ../include/allParam.h $(INCDIR)
 
 clean :
        rm -f *.o
index 1ba0efc51f644f4e8d28a9a9dce11c2c304a5d4d..16ab63ce890114a450359e82a7a6c05fdefe4d3f 100644 (file)
@@ -7,20 +7,44 @@
 
 #include <cadef.h>
 
-#include "caParam.h"
+#include <allParam.h>
+
+#define TIMEOUT 0.2
 
 static void Param_copyToAllocMem(struct event_handler_args args);
-static void Param_returnPVName(const char *, const char *, char *);
+static void Param_returnPVName(const Param *my, const char *, const char *, const char *, char *);
 static void Param_strerror(Param *, const char *);
 
+typedef struct ParamResultS {
+       char **val;
+       int *rows;
+       int maxrows;
+       const Param *my;
+       int *retVal;
+} ParamResult;
+
+int conSetupParam(Param *my, const char *setup)
+{
+       my->strerror = NULL;
+       if(setup != NULL) {
+               my->setup = malloc(strlen(setup) + 1);
+               strcpy(my->setup, setup);
+       }
+       return 0;
+}
+
 int conParam(Param *my)
 {
        my->strerror = NULL;
+       my->setup = NULL;
        return 0;
 }
 
 void desParam(Param *my)
 {
+       if(my->setup != NULL) {
+               free(my->setup);
+       }
 }
 
 int Param_getInt(const Param *my, const char *name, const char *idx, int *row, unsigned long int *val)
@@ -77,8 +101,8 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
                retVal = -1;
        }
 
-       pPVName = malloc((strlen("HAD:PARAM:") + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char));
-       Param_returnPVName(name, idx, pPVName);
+       pPVName = malloc((strlen("HAD:PG:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char));
+       Param_returnPVName(my, "PG", name, idx, pPVName);
 
        if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) {
                Param_strerror((Param *) my, ca_message(status));
@@ -87,8 +111,6 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
                Param_strerror((Param *) my, ca_message(status));
                retVal = -1;
                found = -1;
-       } else {
-               found = 1;
        }
 
        if((status = ca_pend_io(TIMEOUT)) != ECA_NORMAL) {
@@ -107,25 +129,124 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
                status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyToAllocMem, result);
                Param_strerror((Param *) my, ca_message(status));
 
-#if 0
-               if(ca_test_io() == ECA_IOINPROGRESS) {
-#endif
-                       if((status = ca_pend_event(TIMEOUT)) == ECA_TIMEOUT) {
-                               Param_strerror((Param *) my, ca_message(status));
-                       } else if (status != ECA_NORMAL) {
-                               Param_strerror((Param *) my, ca_message(status));
-                               retVal = -1;
-                       }
-#if 0
-               } else {
-                       if((status = ca_poll()) == ECA_TIMEOUT) {
-                               Param_strerror((Param *) my, ca_message(status));
-                       } else if (status != ECA_NORMAL) {
-                               Param_strerror((Param *) my, ca_message(status));
-                               retVal = -1;
-                       }
+               if((status = ca_pend_event(TIMEOUT)) == ECA_TIMEOUT) {
+                       Param_strerror((Param *) my, ca_message(status));
+               } else if (status != ECA_NORMAL) {
+                       Param_strerror((Param *) my, ca_message(status));
+                       retVal = -1;
+               }
+       }
+
+       if((status = ca_clear_channel(chan)) != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+               retVal = -1;
+       }
+
+       free(pPVName);
+
+       if((status = ca_task_exit()) != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+       }
+
+       return retVal;
+}
+
+int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned long int value)
+{
+       int retVal = 0;
+       int status;
+       int found = 1;
+       chid chan;
+       char *pPVName;
+
+       if((status = ca_task_initialize()) != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+               retVal = -1;
+       }
+
+       pPVName = malloc((strlen("HAD:PS:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char));
+       Param_returnPVName(my, "PS", name, idx, pPVName);
+
+       if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) {
+               Param_strerror((Param *) my, ca_message(status));
+               found = 0;
+       } else if (status != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+               retVal = -1;
+               found = -1;
+       }
+
+       if((status = ca_pend_io(TIMEOUT)) != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+               found = 0;
+               retVal = 0;
+       }
+       if(found == 1) {
+               status = ca_put(DBR_LONG, chan, &value);
+               Param_strerror((Param *) my, ca_message(status));
+
+               if((status = ca_pend_event(TIMEOUT)) == ECA_TIMEOUT) {
+                       Param_strerror((Param *) my, ca_message(status));
+               } else if (status != ECA_NORMAL) {
+                       Param_strerror((Param *) my, ca_message(status));
+                       retVal = -1;
+               }
+       }
+
+       if((status = ca_clear_channel(chan)) != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+               retVal = -1;
+       }
+
+       free(pPVName);
+
+       if((status = ca_task_exit()) != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+       }
+
+       return retVal;
+}
+
+int Param_storeString(const Param *my, const char *name, const char *idx, const char *value)
+{
+       int retVal = 0;
+       int status;
+       int found = 1;
+       chid chan;
+       char *pPVName;
+
+       if((status = ca_task_initialize()) != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+               retVal = -1;
+       }
+
+       pPVName = malloc((strlen("HAD:PS:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char));
+       Param_returnPVName(my, "PS", name, idx, pPVName);
+
+       if((status = ca_search(pPVName, &chan)) == ECA_GETFAIL) {
+               Param_strerror((Param *) my, ca_message(status));
+               found = 0;
+       } else if (status != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+               retVal = -1;
+               found = -1;
+       }
+
+       if((status = ca_pend_io(TIMEOUT)) != ECA_NORMAL) {
+               Param_strerror((Param *) my, ca_message(status));
+               found = 0;
+               retVal = 0;
+       }
+       if(found == 1) {
+               status = ca_put(DBR_STRING, chan, value);
+               Param_strerror((Param *) my, ca_message(status));
+
+               if((status = ca_pend_event(TIMEOUT)) == ECA_TIMEOUT) {
+                       Param_strerror((Param *) my, ca_message(status));
+               } else if (status != ECA_NORMAL) {
+                       Param_strerror((Param *) my, ca_message(status));
+                       retVal = -1;
                }
-#endif
        }
 
        if((status = ca_clear_channel(chan)) != ECA_NORMAL) {
@@ -167,11 +288,15 @@ static void Param_copyToAllocMem(struct event_handler_args args)
        }
 }
 
-static void Param_returnPVName(const char *name, const char *idx, char *pPVName)
+static void Param_returnPVName(const Param *my, const char *get_store, const char *name, const char *idx, char *pPVName)
 {
        int i;
 
-       sprintf(pPVName ,"HAD:PARAM:%s:%s", name, idx);
+       if (my->setup == NULL) {
+               sprintf(pPVName ,"HAD:%s:%s:%s", get_store, name, idx);
+       } else {
+               sprintf(pPVName ,"HAD:%s:%s:%s:%s", get_store, my->setup, name, idx);
+       }
        for (i = 0 ; i < strlen(pPVName) ; i++) {
                pPVName[i] = toupper(pPVName[i]);
        }
diff --git a/allParam/ca/caParam.h b/allParam/ca/caParam.h
deleted file mode 100644 (file)
index 503696d..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef CAPARAM_H
-#define CAPARAM_H
-
-#define PARAM_MAX_ARRAY_LEN 128
-#define PARAM_MAX_VALUE_LEN 128
-#define PARAM_MAX_NAME_LEN 128
-
-/*****************************************************************************
- * Section containing struct Param (different in the different xxxParam.h's) *
- *****************************************************************************/
-
-#define TIMEOUT 0.2
-
-#ifndef STATESET_ST
-
-typedef struct ParamS {
-       char *strerror;
-} Param;
-
-typedef struct ParamResultS {
-       char **val;
-       int *rows;
-       int maxrows;
-       const Param *my;
-       int *retVal;
-} ParamResult;
-
-/*********************************************************************
- * Section containing the API for param (common to all allParam.h's) *
- *********************************************************************/
-
-int conParam(Param *);
-void desParam(Param *);
-
-int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *);
-int Param_getString(const Param *, const char *, const char *, int *, char *);
-int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *);
-int Param_getStringArray(const Param *, const char *, const char *, int, int *, char **);
-
-const char *Param_getErrStr(const Param *);
-
-#endif
-
-#endif
-
index 42f5845e68d707274be2b10ada6d8fed2e730162..6d377edf385363bac90584a7c7eca4e2c86cec11 100644 (file)
@@ -1,15 +1,15 @@
-CFLAGS = -g -ansi -Wall
+CFLAGS = -g -ansi -Wall -I../include
 
 libfileParam.a : fileParam.o
        $(AR) $(ARFLAGS) $@ $<
 
-fileParam.o : fileParam.c fileParam.h
+fileParam.o : fileParam.c
 
 install : libfileParam.a
        -mkdir -p $(LIBDIR)
        install -m 644 $< $(LIBDIR)
        -mkdir -p $(INCDIR)
-       install -m 644 fileParam.h $(INCDIR)/allParam.h
+       install -m 644 ../include/allParam.h $(INCDIR)
 
 clean :
        rm -f *.o
index 4b4597c269a5512328bf51ab173723883fead60e..3cf1b8a8fb5d3cbc26e297527152d18111d07ec0 100644 (file)
 #include <stdlib.h>
 #include <ctype.h>
 
-#include "fileParam.h"
-
-#define BUFFERSIZE 130
+#include <allParam.h>
 
 static int Param_getParamNumber(const Param *, const char *, const char *);
 static void Param_strerror(Param *, const char *);
 
+typedef struct FileParamS {
+       int nVals;
+       char **pname;
+       char **value;
+       FILE *store;
+} FileParam;
+
+int conSetupParam(Param *my, const char *setup)
+{
+       int retVal = 0;
+       char *paramFile;
+       char *storageFile;
+       FILE *f;
+       char buf[2 * (PARAM_MAX_NAME_LEN + 1)];
+
+       my->strerror = NULL;
+       my->specParam = malloc(sizeof(FileParam));
+       ((FileParam *) (my->specParam))->pname = 0;
+       ((FileParam *) (my->specParam))->value = 0;
+       ((FileParam *) (my->specParam))->nVals = 0;
+
+       if (setup != NULL) {
+               my->setup = malloc(strlen(setup) + 1);
+               strcpy(my->setup, setup);
+       } else if (getenv("SETUP") != NULL) {
+               my->setup = malloc(strlen(getenv("SETUP")) + 1);
+               strcpy(my->setup, getenv("SETUP"));
+       } else {
+               my->setup = NULL;
+       }
+
+       paramFile = malloc(((my->setup == NULL) ? strlen("default") : strlen(setup)) + strlen("_p.tcl") + 1);
+       storageFile = malloc(((my->setup == NULL) ? strlen("default") : strlen(setup)) + strlen("_s.tcl") + 1);
+       sprintf(paramFile, "%s_p.tcl", (setup == NULL) ? "default" : setup);
+       sprintf(storageFile, "%s_s.tcl", (setup == NULL) ? "default" : setup);
+
+       if (NULL == (f = fopen(paramFile, "r"))) {
+               return -1;
+       } else {
+               while(fgets(buf, 2 * (PARAM_MAX_NAME_LEN + 1), f) != NULL) {
+                       if (buf[0] != '#') {
+                               ((FileParam *) (my->specParam))->nVals++;
+                               ((FileParam *) (my->specParam))->pname = realloc(((FileParam *) (my->specParam))->pname, ((FileParam *) (my->specParam))->nVals * sizeof(char *));
+                               ((FileParam *) (my->specParam))->value = realloc(((FileParam *) (my->specParam))->value, ((FileParam *) (my->specParam))->nVals * sizeof(char *));
+                               ((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1] = malloc(2 * (PARAM_MAX_NAME_LEN + 1) * sizeof(char));
+                               ((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char));
+                               sscanf(buf, "set%s\"%[^\"]\"",
+                                       ((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1],
+                                       ((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1]
+                               );
+                               if(strcmp(((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1],"") == 0) {
+                                       sscanf(buf, "set%s%s",
+                                               ((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1],
+                                               ((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1]
+                                       );
+                               }
+                       }
+               } 
+               fclose(f);
+       }
+
+       if (NULL == (((FileParam *) (my->specParam))->store = fopen(storageFile, "a+"))) {
+               return -1;
+       }
+
+       free(paramFile);
+       free(storageFile);
+
+       return retVal;
+}
+
 int conParam(Param *my)
 {
        int retVal = 0;
-       int i = 0;
-       char *fileName;
+       char *paramFile;
+       char *storageFile;
        FILE *f;
-       char buf[BUFFERSIZE];
+       char buf[2 * (PARAM_MAX_NAME_LEN + 1)];
 
        my->strerror = NULL;
+       my->setup = NULL;
+       my->specParam = malloc(sizeof(FileParam));
+       ((FileParam *) (my->specParam))->pname = 0;
+       ((FileParam *) (my->specParam))->value = 0;
+       ((FileParam *) (my->specParam))->nVals = 0;
+
+       paramFile = getenv("DAQSLOW_PARAM_FILE");
+       if (paramFile == NULL) {
+               paramFile = "param.tcl";
+       }
 
-       fileName = getenv("DAQSLOW_PARAM_FILE");
-       if (fileName == NULL) {
-               fileName = "param.tcl";
+       storageFile = getenv("DAQSLOW_STORAGE_FILE");
+       if (storageFile == NULL) {
+               storageFile = "storage.tcl";
        }
-       if (NULL == (f = fopen(fileName, "r"))) {
+
+       if (NULL == (f = fopen(paramFile, "r"))) {
                return -1;
        } else {
-               int oneMore = 1;
-               my->overFullParamFile = 0;
-               while (oneMore) {
-                       oneMore = 0;
-                       if (i < PARAM_MAX_NVALS) {
-                               if (fgets(buf, BUFFERSIZE, f) != NULL) {
-                                       oneMore = 1;
+               while(fgets(buf, 2 * (PARAM_MAX_NAME_LEN + 1), f) != NULL) {
+                       if (buf[0] != '#') {
+                               ((FileParam *) (my->specParam))->nVals++;
+                               ((FileParam *) (my->specParam))->pname = realloc(((FileParam *) (my->specParam))->pname, ((FileParam *) (my->specParam))->nVals * sizeof(char *));
+                               ((FileParam *) (my->specParam))->value = realloc(((FileParam *) (my->specParam))->value, ((FileParam *) (my->specParam))->nVals * sizeof(char *));
+                               ((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1] = malloc(2 * (PARAM_MAX_NAME_LEN + 1) * sizeof(char));
+                               ((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char));
+                               sscanf(buf, "set%s\"%[\"]\"",
+                                       ((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1],
+                                       ((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1]
+                               );
+                               if(strcmp(((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1],"") == 0) {
+                                       sscanf(buf, "set%s%s",
+                                               ((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1],
+                                               ((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1]
+                                       );
                                }
-                               if (oneMore && (buf[0] != '#')) {
-                                       sscanf(buf, "set%s%s", my->pname[i], my->value[i]);
-                                       i++;
-                               } 
-                       } else {
-                               oneMore = 0;
-                               my->overFullParamFile = 1;
-                               retVal = -1;
                        }
-               }
-               my->nVals = i;
+               } 
                fclose(f);
        }
+
+       if (NULL == (((FileParam *) (my->specParam))->store = fopen(storageFile, "a+"))) {
+               return -1;
+       }
+
        return retVal;
 }
 
 void desParam(Param *my)
 {
+       int i;
+
+       for (i = 0 ; i < ((FileParam *) (my->specParam))->nVals ; i++) {
+               free(((FileParam *) (my->specParam))->pname[i]);
+               free(((FileParam *) (my->specParam))->value[i]);
+       }
+       free(((FileParam *) (my->specParam))->pname);
+       free(((FileParam *) (my->specParam))->value);
+       free((FileParam *) (my->specParam));
+
+       fclose(((FileParam *) (my->specParam))->store);
+       if(my->setup != NULL) {
+               free(my->setup);
+       }
 }
 
 int Param_getInt(const Param *my, const char *name, const char *idx, int *row, unsigned long int *val)
@@ -98,7 +197,6 @@ int Param_getIntArray(const Param *my, const char *name, const char *idx, int ma
 
 int Param_getStringArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val)
 {
-       int retVal = 0;
        int i;
        int n;
        char lname[PARAM_MAX_NAME_LEN];
@@ -113,23 +211,114 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
 
        *rows = 0;
        if((n = Param_getParamNumber(my, lname, lidx)) != -1) {
-               strcpy(val[0], my->value[n]);
+               strcpy(val[0], ((FileParam *) (my->specParam))->value[n]);
                *rows = 1;
        } else {
                char index[PARAM_MAX_NAME_LEN];
                for (i = 0 ; i < maxrows ; i++) {
                        sprintf(index,"%s%d", lidx, i);
                        if((n = Param_getParamNumber(my, lname, index)) != -1) {
-                               strcpy(val[i], my->value[n]);
+                               strcpy(val[i], ((FileParam *) (my->specParam))->value[n]);
                                (*rows)++;
                        } else {
                                i = maxrows;
                        }
                }
        }
+       return 0;
+}
+
+int Param_getFilename(const Param *my, const char *name, const char *idx, int *row, char *val)
+{
+       int retVal = 0;
+       int rows = 0;
+       char value[PARAM_MAX_VALUE_LEN];
+
+       if (((retVal = Param_getString(my, name, idx, &rows, value)) == 0) && (rows == 1)) {
+               if (value[0] == '/') {
+                       strcpy(val, value);
+                       *row = 1;
+               } else {
+                       if ((Param_getString(my, "glob", "basedir", &rows, val) == 0) && (rows == 1)) {
+                               strcat(val, "/");
+                               strcat(val, value);
+                               *row = 1;
+                       } else {
+                               strcpy(val, value);
+                               *row = 1;
+                       }
+               }
+       } else {
+               *row = 0;
+       }
+       return retVal;
+}
+
+int Param_getFilenameArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val)
+{
+       int retVal = 0;
+       int row = 0;
+       int i;
+       char *value[PARAM_MAX_ARRAY_LEN];
+
+       for (i = 0 ; i < maxrows ; i++) {
+               value[i] = malloc(PARAM_MAX_VALUE_LEN);
+       }
+
+       if (((retVal = Param_getStringArray(my, name, idx, maxrows, rows, value)) == 0) && (*rows > 0)) {
+               char basedir[PARAM_MAX_VALUE_LEN];
+
+               if ((Param_getString(my, "glob", "basedir", &row, basedir) == 0) && (row == 1)) {
+                       strcat(basedir, "/");
+               } else {
+                       strcpy(basedir, "");
+               }
+               for (i = 0 ; i < *rows ; i++) {
+                       if (value[i][0] != '/') {
+                               strcpy(val[i], basedir);
+                       } else {
+                               strcpy(val[i], "");
+                       }
+                       strcat(val[i], value[i]);
+               }
+       } else {
+               *rows = 0;
+       }
+
+       for (i = 0 ; i < maxrows ; i++) {
+               free(value[i]);
+       }
+
        return retVal;
 }
 
+int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned long int value)
+{
+       fprintf(((FileParam *) (my->specParam))->store, "set %s(%s)\t%lu\n", name, idx, value);
+       ((FileParam *) (my->specParam))->nVals++;
+       ((FileParam *) (my->specParam))->pname = realloc(((FileParam *) (my->specParam))->pname, ((FileParam *) (my->specParam))->nVals * sizeof(char *));
+       ((FileParam *) (my->specParam))->value = realloc(((FileParam *) (my->specParam))->value, ((FileParam *) (my->specParam))->nVals * sizeof(char *));
+       ((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1] = malloc(2 * (PARAM_MAX_NAME_LEN + 1) * sizeof(char));
+       ((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char));
+       sprintf(((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1], "%s(%s)", name, idx);
+       sprintf(((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1], "%lu", value);
+       return 0;
+}
+
+int Param_storeString(const Param *my, const char *name, const char *idx, const char *value)
+{
+       fprintf(((FileParam *) (my->specParam))->store, "set %s(%s)\t\"%s\"\n", name, idx, value);
+       fflush(((FileParam *) (my->specParam))->store);
+       ((FileParam *) (my->specParam))->nVals++;
+       ((FileParam *) (my->specParam))->pname = realloc(((FileParam *) (my->specParam))->pname, ((FileParam *) (my->specParam))->nVals * sizeof(char *));
+       ((FileParam *) (my->specParam))->value = realloc(((FileParam *) (my->specParam))->value, ((FileParam *) (my->specParam))->nVals * sizeof(char *));
+       ((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1] = malloc(2 * (PARAM_MAX_NAME_LEN + 1) * sizeof(char));
+       ((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char));
+       sprintf(((FileParam *) (my->specParam))->pname[((FileParam *) (my->specParam))->nVals - 1], "%s(%s)", name, idx);
+       sprintf(((FileParam *) (my->specParam))->value[((FileParam *) (my->specParam))->nVals - 1], "%s", value);
+       return 0;
+}
+
 const char *Param_getErrStr(const Param *my)
 {
        return my->strerror;
@@ -139,11 +328,11 @@ static int Param_getParamNumber(const Param *my, const char *name, const char *i
 {
        int retVal = -1;
        int i;
-       char fullName[PARAM_MAX_NAME_LEN];
+       char fullName[2 * (PARAM_MAX_NAME_LEN + 1)];
 
        sprintf(fullName, "%s(%s)", name, idx);
-       for (i = 0; i < my->nVals; i++) {
-               if (strcmp(my->pname[i], fullName) == 0) {
+       for (i = 0; i < ((FileParam *) (my->specParam))->nVals; i++) {
+               if (strcmp(((FileParam *) (my->specParam))->pname[i], fullName) == 0) {
                        retVal = i;
                }
        }
diff --git a/allParam/file/fileParam.h b/allParam/file/fileParam.h
deleted file mode 100644 (file)
index 10de076..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef FILEPARAM_H
-#define FILEPARAM_H
-
-#define PARAM_MAX_ARRAY_LEN 128
-#define PARAM_MAX_VALUE_LEN 128
-#define PARAM_MAX_NAME_LEN 128
-
-/*****************************************************************************
- * Section containing struct Param (different in the different xxxParam.h's) *
- *****************************************************************************/
-
-#define PARAM_MAX_NVALS 1024
-
-#ifndef STATESET_ST
-
-typedef struct ParamS {
-       char *strerror;
-       int nVals;
-       int overFullParamFile;
-       char pname[PARAM_MAX_NVALS][PARAM_MAX_NAME_LEN];
-       char value[PARAM_MAX_NVALS][PARAM_MAX_NAME_LEN];
-} Param;
-
-/*********************************************************************
- * Section containing the API for param (common to all allParam.h's) *
- *********************************************************************/
-
-int conParam(Param *);
-void desParam(Param *);
-
-int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *);
-int Param_getString(const Param *, const char *, const char *, int *, char *);
-int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *);
-int Param_getStringArray(const Param *, const char *, const char *, int, int *, char **);
-
-const char *Param_getErrStr(const Param *);
-
-#endif
-
-#endif
-
index f03ce8ecb74553447528e0bd8c90375a1d0cf291..f691ac9d581647dc51538be9b1cd987cc40775fd 100644 (file)
@@ -5,15 +5,13 @@
 #define PARAM_MAX_VALUE_LEN 128
 #define PARAM_MAX_NAME_LEN 128
 
-/*********************************************************************
- * Section containing the API for param (common to all allParam.h's) *
- *********************************************************************/
-
 typedef struct ParamS {
        char *strerror;
-       void *interp;
+       char *setup;
+       void *specParam;
 } Param;
 
+int conSetupParam(Param *, const char *);
 int conParam(Param *);
 void desParam(Param *);
 
@@ -21,6 +19,11 @@ int Param_getInt(const Param *, const char *, const char *, int *, unsigned long
 int Param_getString(const Param *, const char *, const char *, int *, char *);
 int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *);
 int Param_getStringArray(const Param *, const char *, const char *, int, int *, char **);
+int Param_getFilename(const Param *, const char *, const char *, int *, char *);
+int Param_getFilenameArray(const Param *, const char *, const char *, int, int *, char **);
+
+int Param_storeInt(const Param *, const char *, const char *, unsigned long int);
+int Param_storeString(const Param *, const char *, const char *, const char *);
 
 const char *Param_getErrStr(const Param *);
 
index 8519f60ddc6e5cd6c5c5357ad876571cccbd8dc2..5509062a2c07fab7e5944c7ce67e1349b6e2c7c2 100644 (file)
@@ -1,4 +1,4 @@
-CFLAGS = -g -ansi -Wall -I$(ORACLE_HOME)/precomp/public/
+CFLAGS = -g -ansi -Wall -I../include -I$(ORACLE_HOME)/precomp/public/
 
 ORA_USER = hades/hades@db-hades.gsi.de
 
@@ -12,12 +12,12 @@ PROC_INCLUDES = include=/usr/include include=/usr/include/g++-2 \
   include=$(ORACLE_HOME)/rdbms/demo \
   include=$(ORACLE_HOME)/plsql/public \
   include=$(ORACLE_HOME)/network/public \
-  include=../param
+  include=../include
 
 liboraParam.a : oraParam.o
        $(AR) $(ARFLAGS) $@ $<
 
-oraParam.o : oraParam.c oraParam.h
+oraParam.o : oraParam.c
 
 oraParam.c : oraParam.pc
        $(PROC) $(PROCFLAGS) $(PROC_INCLUDES) iname=$< oname=$@
@@ -26,7 +26,7 @@ install : liboraParam.a
        -mkdir -p $(LIBDIR)
        install -m 644 $< $(LIBDIR)
        -mkdir -p $(INCDIR)
-       install -m 644 oraParam.h $(INCDIR)/allParam.h
+       install -m 644 ../include/allParam.h $(INCDIR)
 
 clean :
        rm -f *.o oraParam.c oraParam.lis
diff --git a/allParam/ora/oraParam.h b/allParam/ora/oraParam.h
deleted file mode 100644 (file)
index 316954a..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef ORAPARAM_H
-#define ORAPARAM_H
-
-#define PARAM_MAX_ARRAY_LEN 128
-#define PARAM_MAX_VALUE_LEN 128
-#define PARAM_MAX_NAME_LEN 128
-
-/*****************************************************************************
- * Section containing struct Param (different in the different xxxParam.h's) *
- *****************************************************************************/
-
-#ifndef STATESET_ST
-
-typedef struct ParamS {
-       const char *user;
-       const char *passwd;
-       char *strerror;
-} Param;
-
-/*********************************************************************
- * Section containing the API for param (common to all allParam.h's) *
- *********************************************************************/
-
-int conParam(Param *);
-void desParam(Param *);
-
-int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *);
-int Param_getString(const Param *, const char *, const char *, int *, char *);
-int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *);
-int Param_getStringArray(const Param *, const char *, const char *, int, int *, char **);
-
-const char *Param_getErrStr(const Param *);
-
-#endif
-
-#endif
-
index 7d05f1aa48317ead87374dad521305fa63bbb20b..c8d2af2a9a8d3e12c6921f6c59ccbd0a593c0102 100644 (file)
@@ -8,22 +8,46 @@
 #include <oraca.h>
 #include <sqlca.h>
 
-#include "oraParam.h"
+#include <allParam.h>
 
 static void Param_rollback();
 
 static void Param_strerror(const Param *, const char *);
 
+typedef struct OraParamS {
+       const char *user;
+       const char *passwd;
+} OraParam;
+
+int conSetupParam(Param *my, const char *setup)
+{
+       my->strerror = NULL;
+       if(setup != NULL) {
+               my->setup = malloc(strlen(setup) + 1);
+               strcpy(my->setup, setup);
+       }
+       my->specParam = malloc(sizeof(OraParam));
+       ((OraParam *) (my->specParam))->user = "daq@db-hades.gsi.de";
+       ((OraParam *) (my->specParam))->passwd = "daqall";
+       return 0;
+}
+
 int conParam(Param *my)
 {
        my->strerror = NULL;
-       my->user = "hades@db-hades.gsi.de";
-       my->passwd = "hades";
+       my->setup = NULL;
+       my->specParam = malloc(sizeof(OraParam));
+       ((OraParam *) (my->specParam))->user = "daq@db-hades.gsi.de";
+       ((OraParam *) (my->specParam))->passwd = "daqall";
        return 0;
 }
 
 void desParam(Param *my)
 {
+       free(my->specParam);
+       if(my->setup != NULL) {
+               free(my->setup);
+       }
 }
 
 int Param_getInt(const Param *my, const char *name, const char *idx, int *row, unsigned long int *val)
@@ -59,8 +83,8 @@ int Param_getIntArray(const Param *my, const char *name, const char *idx, int ma
        for(i = 0 ; i <= strlen(idx) ; i++) {
                sqlidx[i] = tolower(idx[i]);
        }
-       un = my->user;
-       pw = my->passwd;
+       un = ((OraParam *) (my->specParam))->user;
+       pw = ((OraParam *) (my->specParam))->passwd;
 
        EXEC SQL CONNECT :un IDENTIFIED BY :pw;
        EXEC SQL SELECT VALUE INTO :value FROM DAQ.PARAMS WHERE NAME = :sqlname AND IDX = :sqlidx ORDER BY SEQ_NUM;
@@ -73,7 +97,7 @@ int Param_getIntArray(const Param *my, const char *name, const char *idx, int ma
                int j = PARAM_MAX_VALUE_LEN - 1;
                while(value[i][--j] == ' ');
                value[i][j + 1] = '\0';
-               val[i] = strtoul(value[i], &endptr, NULL);
+               val[i] = strtoul(value[i], &endptr, 0);
                if(*endptr != '\0') {
                        Param_strerror(my, "Value seems to be no integer.");
                        *rows = 0;
@@ -99,6 +123,7 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
        EXEC SQL BEGIN DECLARE SECTION;
        const char* un;
        const char* pw;
+       char setup[PARAM_MAX_NAME_LEN];
        char sqlname[PARAM_MAX_NAME_LEN];
        char sqlidx[PARAM_MAX_NAME_LEN];
        char value[PARAM_MAX_ARRAY_LEN][PARAM_MAX_VALUE_LEN];
@@ -110,12 +135,19 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
        for(i = 0 ; i <= strlen(idx) ; i++) {
                sqlidx[i] = tolower(idx[i]);
        }
-       un = my->user;
-       pw = my->passwd;
+       un = ((OraParam *) (my->specParam))->user;
+       pw = ((OraParam *) (my->specParam))->passwd;
 
        EXEC SQL CONNECT :un IDENTIFIED BY :pw;
 
-       EXEC SQL SELECT VALUE INTO :value FROM DAQ.PARAMS WHERE NAME = :sqlname AND IDX = :sqlidx ORDER BY SEQ_NUM;
+       if(my->setup == NULL) {
+               EXEC SQL SELECT VALUE INTO :value FROM DAQ.PARAMS WHERE NAME = :sqlname AND IDX = :sqlidx ORDER BY SEQ_NUM;
+       } else {
+               for(i = 0 ; i <= strlen(my->setup) ; i++) {
+                       setup[i] = tolower((my->setup)[i]);
+               }
+               EXEC SQL SELECT VALUE INTO :value FROM DAQ.SETUP_PARAMS WHERE SETUP = :setup AND NAME = :sqlname AND IDX = :sqlidx ORDER BY SEQ_NUM;
+       }
        *rows = sqlca.sqlerrd[2];
 
        if (*rows > maxrows) {
@@ -135,6 +167,90 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
        return retVal;
 }
 
+int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned long int val)
+{
+       int i;
+
+       EXEC SQL WHENEVER SQLERROR DO Param_strerror(my, sqlca.sqlerrm.sqlerrmc);
+       EXEC SQL WHENEVER SQLERROR DO Param_rollback();
+
+       EXEC SQL BEGIN DECLARE SECTION;
+       const char* un;
+       const char* pw;
+       char setup[PARAM_MAX_NAME_LEN];
+       char sqlname[PARAM_MAX_NAME_LEN];
+       char sqlidx[PARAM_MAX_NAME_LEN];
+       unsigned long int value;
+       EXEC SQL END DECLARE SECTION;
+
+       for(i = 0 ; i <= strlen(name) ; i++) {
+               sqlname[i] = tolower(name[i]);
+       }
+       for(i = 0 ; i <= strlen(idx) ; i++) {
+               sqlidx[i] = tolower(idx[i]);
+       }
+       value = val;
+
+       un = ((OraParam *) (my->specParam))->user;
+       pw = ((OraParam *) (my->specParam))->passwd;
+
+       EXEC SQL CONNECT :un IDENTIFIED BY :pw;
+
+       if(my->setup == NULL) {
+               EXEC SQL INSERT INTO DAQ.STORE_INT VALUES (:sqlname, :sqlidx, :value);
+       } else {
+               for(i = 0 ; i <= strlen(my->setup) ; i++) {
+                       setup[i] = tolower((my->setup)[i]);
+               }
+               EXEC SQL INSERT INTO DAQ.SETUP_STORE_INT VALUES (:setup, :sqlname, :sqlidx, :value);
+       }
+
+       EXEC SQL COMMIT RELEASE;
+       return 0;
+}
+
+int Param_storeString(const Param *my, const char *name, const char *idx, const char *val)
+{
+       int i;
+
+       EXEC SQL WHENEVER SQLERROR DO Param_strerror(my, sqlca.sqlerrm.sqlerrmc);
+       EXEC SQL WHENEVER SQLERROR DO Param_rollback();
+
+       EXEC SQL BEGIN DECLARE SECTION;
+       const char* un;
+       const char* pw;
+       char setup[PARAM_MAX_NAME_LEN];
+       char sqlname[PARAM_MAX_NAME_LEN];
+       char sqlidx[PARAM_MAX_NAME_LEN];
+       char value[PARAM_MAX_VALUE_LEN];
+       EXEC SQL END DECLARE SECTION;
+
+       for(i = 0 ; i <= strlen(name) ; i++) {
+               sqlname[i] = tolower(name[i]);
+       }
+       for(i = 0 ; i <= strlen(idx) ; i++) {
+               sqlidx[i] = tolower(idx[i]);
+       }
+       strcpy(value, val);
+
+       un = ((OraParam *) (my->specParam))->user;
+       pw = ((OraParam *) (my->specParam))->passwd;
+
+       EXEC SQL CONNECT :un IDENTIFIED BY :pw;
+
+       if(my->setup == NULL) {
+               EXEC SQL INSERT INTO DAQ.STORE_STRING VALUES (:sqlname, :sqlidx, :value);
+       } else {
+               for(i = 0 ; i <= strlen(my->setup) ; i++) {
+                       setup[i] = tolower((my->setup)[i]);
+               }
+               EXEC SQL INSERT INTO DAQ.SETUP_STORE_STRING VALUES (:setup, :sqlname, :sqlidx, :value);
+       }
+
+       EXEC SQL COMMIT RELEASE;
+       return 0;
+}
+
 const char *Param_getErrStr(const Param *my)
 {
        return my->strerror;
@@ -142,10 +258,9 @@ const char *Param_getErrStr(const Param *my)
 
 static void Param_strerror(const Param *my, const char *strerror)
 {
-       (Param *) my;
-       my->strerror = realloc(my->strerror, strlen(strerror) + 1);
-       if(my->strerror != NULL) {
-               strcpy(my->strerror, strerror);
+       ((Param *) my)->strerror = realloc(my->strerror, strlen(strerror) + 1);
+       if(((Param *) my)->strerror != NULL) {
+               strcpy(((Param *) my)->strerror, strerror);
        }
 }
 
index 4b9d0de050201f0f6067f66bbbbc4d87e947c14d..48068df9644d65182b12a87a52f05dbba999f906 100644 (file)
@@ -1,15 +1,15 @@
-CFLAGS = -g -ansi -Wall -I/usr/include/pgsql
+CFLAGS = -g -ansi -Wall -I/usr/include/pgsql -I../include
 
 libpsqlParam.a : psqlParam.o
        $(AR) $(ARFLAGS) $@ $<
 
-psqlParam.o : psqlParam.c psqlParam.h
+psqlParam.o : psqlParam.c
 
 install : libpsqlParam.a
        -mkdir -p $(LIBDIR)
        install -m 644 $< $(LIBDIR)
        -mkdir -p $(INCDIR)
-       install -m 644 psqlParam.h $(INCDIR)/allParam.h
+       install -m 644 ../include/allParam.h $(INCDIR)
 
 clean :
        rm -f *.o
index afcb1a926019863e47bbe830ee027f852488a07b..3c0a525f24e18c12d81f3c133e968ba371e765fc 100644 (file)
@@ -7,18 +7,35 @@
 
 #include <libpq-fe.h>
 
-#include "psqlParam.h"
+#include <allParam.h>
+
+#define PG_MAX_QUERY_LEN 1024
+#define PG_MAX_CLAUSE_LEN 256
 
 static void Param_strerror(Param *, const char *);
 
+int conSetupParam(Param *my, const char *setup)
+{
+       my->strerror = NULL;
+       if(setup != NULL) {
+               my->setup = malloc(strlen(setup) + 1);
+               strcpy(my->setup, setup);
+       }
+       return 0;
+}
+
 int conParam(Param *my)
 {
        my->strerror = NULL;
+       my->setup = NULL;
        return 0;
 }
 
 void desParam(Param *my)
 {
+       if(my->setup != NULL) {
+               free(my->setup);
+       }
 }
 
 int Param_getInt(const Param *my, const char *name, const char *idx, int *row, unsigned long int *val)
@@ -52,8 +69,13 @@ int Param_getIntArray(const Param *my, const char *name, const char *idx, int ma
 
        *rows = 0;
        conn = PQconnectdb("host=casino.e12.physik.tu-muenchen.de dbname=hadaq user=bsailer");
-       sprintf(whereClause, "WHERE name = '%s' AND idx = '%s' ", lname, lidx);
-       sprintf(query, "SELECT * FROM card_params %s UNION SELECT * FROM cpus %s UNION SELECT * FROM crate_params %s UNION SELECT * FROM crate_setup %s ORDER BY seq_num;", whereClause, whereClause, whereClause, whereClause);
+       if (my->setup == NULL) {
+               sprintf(whereClause, "WHERE name = '%s' AND idx = '%s' ", lname, lidx);
+               sprintf(query, "SELECT * FROM card_params %s UNION SELECT * FROM cpus %s UNION SELECT * FROM crate_params %s UNION SELECT * FROM crate_setup %s ORDER BY seq_num;", whereClause, whereClause, whereClause, whereClause);
+       } else {
+               sprintf(whereClause, "WHERE setup = '%s' AND name = '%s' AND idx = '%s' ", my->setup, lname, lidx);
+               sprintf(query, "SELECT * FROM setup_card_params %s UNION SELECT * FROM setup_cpus %s UNION SELECT * FROM setup_crate_params %s UNION SELECT * FROM setup_crate_setup %s ORDER BY seq_num;", whereClause, whereClause, whereClause, whereClause);
+       }
 
        result = PQexec(conn, query);
        if(PQresultStatus(result) != PGRES_TUPLES_OK) {
@@ -101,8 +123,13 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
 
        *rows = 0;
        conn = PQconnectdb("host=casino.e12.physik.tu-muenchen.de dbname=hadaq user=bsailer");
-       sprintf(whereClause, "WHERE name = '%s' AND idx = '%s' ", lname, lidx);
-       sprintf(query, "SELECT * FROM card_params %s UNION SELECT * FROM cpus %s UNION SELECT * FROM crate_params %s UNION SELECT * FROM crate_setup %s ORDER BY seq_num;", whereClause, whereClause, whereClause, whereClause);
+       if (my->setup == NULL) {
+               sprintf(whereClause, "WHERE name = '%s' AND idx = '%s' ", lname, lidx);
+               sprintf(query, "SELECT * FROM card_params %s UNION SELECT * FROM cpus %s UNION SELECT * FROM crate_params %s UNION SELECT * FROM crate_setup %s ORDER BY seq_num;", whereClause, whereClause, whereClause, whereClause);
+       } else {
+               sprintf(whereClause, "WHERE setup = '%s' AND name = '%s' AND idx = '%s' ", my->setup, lname, lidx);
+               sprintf(query, "SELECT * FROM setup_card_params %s UNION SELECT * FROM setup_cpus %s UNION SELECT * FROM setup_crate_params %s UNION SELECT * FROM setup_crate_setup %s ORDER BY seq_num;", whereClause, whereClause, whereClause, whereClause);
+       }
 
        result = PQexec(conn, query);
        if(PQresultStatus(result) != PGRES_TUPLES_OK) {
@@ -125,6 +152,82 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
        return 0;
 }
 
+int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned long int val)
+{
+       int i;
+       PGresult *result;
+       PGconn *conn;
+       char query[PG_MAX_QUERY_LEN];
+       char lsetup[PARAM_MAX_NAME_LEN];
+       char lname[PARAM_MAX_NAME_LEN];
+       char lidx[PARAM_MAX_NAME_LEN];
+
+       for(i = 0 ; i <=strlen(name) ; i++) {
+               lname[i] = tolower(name[i]);
+       }
+       for(i = 0 ; i <=strlen(idx) ; i++) {
+               lidx[i] = tolower(idx[i]);
+       }
+
+       conn = PQconnectdb("host=casino.e12.physik.tu-muenchen.de dbname=hadaq user=bsailer");
+       if (my->setup == NULL) {
+               sprintf(query, "INSERT INTO store_int VALUES ('%s', '%s', %lu)", lname, lidx, val);
+       } else {
+               for(i = 0 ; i <=strlen(my->setup) ; i++) {
+                       lsetup[i] = tolower(my->setup[i]);
+               }
+               sprintf(query, "INSERT INTO setup_store_int VALUES ('%s', '%s', '%s', %lu)", lsetup, lname, lidx, val);
+       }
+
+       result = PQexec(conn, query);
+       if(PQresultStatus(result) != PGRES_TUPLES_OK) {
+               Param_strerror((Param *) my, "The PostgreSQL query result is not correct.");
+               return -1;
+       }
+
+       PQfinish(conn);
+
+       return 0;
+}
+
+int Param_storeString(const Param *my, const char *name, const char *idx, const char *val)
+{
+       int i;
+       PGresult *result;
+       PGconn *conn;
+       char query[PG_MAX_QUERY_LEN];
+       char lsetup[PARAM_MAX_NAME_LEN];
+       char lname[PARAM_MAX_NAME_LEN];
+       char lidx[PARAM_MAX_NAME_LEN];
+
+       for(i = 0 ; i <=strlen(name) ; i++) {
+               lname[i] = tolower(name[i]);
+       }
+       for(i = 0 ; i <=strlen(idx) ; i++) {
+               lidx[i] = tolower(idx[i]);
+       }
+
+       conn = PQconnectdb("host=casino.e12.physik.tu-muenchen.de dbname=hadaq user=bsailer");
+       if (my->setup == NULL) {
+               sprintf(query, "INSERT INTO store_string VALUES ('%s', '%s', '%s')", lname, lidx, val);
+       } else {
+               for(i = 0 ; i <=strlen(my->setup) ; i++) {
+                       lsetup[i] = tolower(my->setup[i]);
+               }
+               sprintf(query, "INSERT INTO setup_store_string VALUES ('%s', '%s', '%s', '%s')", lsetup, lname, lidx, val);
+       }
+
+       result = PQexec(conn, query);
+       if(PQresultStatus(result) != PGRES_TUPLES_OK) {
+               Param_strerror((Param *) my, "The PostgreSQL query result is not correct.");
+               return -1;
+       }
+
+       PQfinish(conn);
+
+       return 0;
+}
+
 const char *Param_getErrStr(const Param *my)
 {
        return my->strerror;
diff --git a/allParam/psql/psqlParam.h b/allParam/psql/psqlParam.h
deleted file mode 100644 (file)
index 137f497..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef PSQLPARAM_H
-#define PSQLPARAM_H
-
-#define PARAM_MAX_ARRAY_LEN 128
-#define PARAM_MAX_VALUE_LEN 128
-#define PARAM_MAX_NAME_LEN 128
-
-/*****************************************************************************
- * Section containing struct Param (different in the different xxxParam.h's) *
- *****************************************************************************/
-
-#ifndef STATESET_ST
-
-#define PG_MAX_QUERY_LEN 1024
-#define PG_MAX_CLAUSE_LEN 256
-
-typedef struct ParamS {
-       char *strerror;
-} Param;
-
-/*********************************************************************
- * Section containing the API for param (common to all allParam.h's) *
- *********************************************************************/
-
-int conParam(Param *);
-void desParam(Param *);
-
-int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *);
-int Param_getString(const Param *, const char *, const char *, int *, char *);
-int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *);
-int Param_getStringArray(const Param *, const char *, const char *, int, int *, char **);
-
-const char *Param_getErrStr(const Param *);
-
-#endif
-
-#endif
-
index e8e798d3308e1b761bc7b2e212c2243b53697aca..6bb1ccd5be6914276004219bccbeec76499a8abc 100644 (file)
@@ -1,15 +1,15 @@
-CFLAGS = -g -ansi -Wall
+CFLAGS = -g -ansi -Wall -I../include
 
 libtclParam.a : tclParam.o
        $(AR) $(ARFLAGS) $@ $<
 
-tclParam.o : tclParam.c tclParam.h
+tclParam.o : tclParam.c
 
 install : libtclParam.a
        -mkdir -p $(LIBDIR)
        install -m 644 $< $(LIBDIR)
        -mkdir -p $(INCDIR)
-       install -m 644 tclParam.h $(INCDIR)/allParam.h
+       install -m 644 ../include/allParam.h $(INCDIR)
 
 clean :
        rm -f *.o
index 751ef3d9e028b5f54140e6cc3703f9da069874e7..0c6c3499f6a1ab61629dfd5df71fa88553a8b62a 100644 (file)
 #include <stdlib.h>
 #include <ctype.h>
 
-#include "tclParam.h"
+#include <tcl.h>
+
+#include <allParam.h>
 
 static void Param_strerror(Param *, const char *);
 
+typedef struct TclParamS {
+       Tcl_Interp *interp;
+       FILE *store;
+} TclParam;
+
+int conSetupParam(Param *my, const char *setup)
+{
+       int retVal = 0;
+       char *paramFile;
+       char *storageFile;
+       int code;
+
+       my->strerror = NULL;
+       my->specParam = malloc(sizeof(TclParam));
+
+       if (setup != NULL) {
+               my->setup = malloc(strlen(setup) + 1);
+               strcpy(my->setup, setup);
+       } else if (getenv("SETUP") != NULL) {
+               my->setup = malloc(strlen(getenv("SETUP")) + 1);
+               strcpy(my->setup, getenv("SETUP"));
+       } else {
+               my->setup = NULL;
+       }
+
+       paramFile = malloc(((my->setup == NULL) ? strlen("default") : strlen(setup)) + strlen("_p.tcl") + 1);
+       storageFile = malloc(((my->setup == NULL) ? strlen("default") : strlen(setup)) + strlen("_s.tcl") + 1);
+       sprintf(paramFile, "%s_p.tcl", (my->setup == NULL) ? "default" : setup);
+       sprintf(storageFile, "%s_s.tcl", (my->setup == NULL) ? "default" : setup);
+
+       ((TclParam *) (my->specParam))->interp = Tcl_CreateInterp();
+       code = Tcl_EvalFile(((TclParam *) (my->specParam))->interp, paramFile);
+       if (code != TCL_OK) {
+               if (* ((TclParam *) (my->specParam))->interp->result != 0) {
+                       Param_strerror(my, ((TclParam *) (my->specParam))->interp->result);
+               } else {
+                       Param_strerror((Param *) my, "Tcl interpreter cannot read file correctly and does not deliver an error string.");
+               }
+               retVal = -1;
+       }
+
+       if (NULL == (((TclParam *) (my->specParam))->store = fopen(storageFile, "a+"))) {
+               retVal = -1;
+       }
+
+       free(paramFile);
+       free(storageFile);
+
+       return retVal;
+}
+
 int conParam(Param *my)
 {
-       int retVal;
-       char *fileName;
+       int retVal = 0;
+       char *paramFile;
+       char *storageFile;
        int code;
 
        my->strerror = NULL;
-       fileName = getenv("DAQSLOW_PARAM_FILE");
-       if (fileName == NULL) {
-               fileName = "param.tcl";
+       my->setup = NULL;
+       my->specParam = malloc(sizeof(TclParam));
+
+       paramFile = getenv("DAQSLOW_PARAM_FILE");
+       if (paramFile == NULL) {
+               paramFile = "param.tcl";
        }
-       my->interp = Tcl_CreateInterp();
-       code = Tcl_EvalFile(my->interp, fileName);
+       storageFile = getenv("DAQSLOW_STORAGE_FILE");
+       if (storageFile == NULL) {
+               storageFile = "storage.tcl";
+       }
+
+       ((TclParam *) (my->specParam))->interp = Tcl_CreateInterp();
+       code = Tcl_EvalFile(((TclParam *) (my->specParam))->interp, paramFile);
        if (code != TCL_OK) {
-               if (*my->interp->result != 0) {
-                       Param_strerror(my, my->interp->result);
+               if (* ((TclParam *) (my->specParam))->interp->result != 0) {
+                       Param_strerror(my, ((TclParam *) (my->specParam))->interp->result);
                } else {
                        Param_strerror((Param *) my, "Tcl interpreter cannot read file correctly and does not deliver an error string.");
                }
                retVal = -1;
-       } else {
-               retVal = 0;
        }
+
+       if (NULL == (((TclParam *) (my->specParam))->store = fopen(storageFile, "a+"))) {
+               return -1;
+       }
+
        return retVal;
 }
 
 void desParam(Param *my)
 {
-       Tcl_DeleteInterp(my->interp);
+       Tcl_DeleteInterp(((TclParam *) (my->specParam))->interp);
+       fclose(((TclParam *) (my->specParam))->store);
+
+       free((TclParam *) (my->specParam));
+       if(my->setup != NULL) {
+               free(my->setup);
+       }
 }
 
 int Param_getInt(const Param *my, const char *name, const char *idx, int *row, unsigned long int *val)
@@ -94,15 +165,15 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
        }
 
        *rows = 0;
-       if(Tcl_GetVar2(my->interp, lname, lidx, 0) != 0) {
-               strcpy(val[0], Tcl_GetVar2(my->interp, lname, lidx, 0));
+       if(Tcl_GetVar2(((TclParam *) (my->specParam))->interp, lname, lidx, 0) != 0) {
+               strcpy(val[0], Tcl_GetVar2(((TclParam *) (my->specParam))->interp, lname, lidx, 0));
                *rows = 1;
        } else {
                char index[PARAM_MAX_NAME_LEN];
                for (i = 0 ; i < maxrows ; i++) {
                        sprintf(index,"%s%d", lidx, i);
-                       if(Tcl_GetVar2(my->interp, lname, index, 0) != 0) {
-                               strcpy(val[i], Tcl_GetVar2(my->interp, lname, index, 0));
+                       if(Tcl_GetVar2(((TclParam *) (my->specParam))->interp, lname, index, 0) != 0) {
+                               strcpy(val[i], Tcl_GetVar2(((TclParam *) (my->specParam))->interp, lname, index, 0));
                                (*rows)++;
                        } else {
                                i = maxrows;
@@ -112,6 +183,88 @@ int Param_getStringArray(const Param *my, const char *name, const char *idx, int
        return retVal;
 }
 
+int Param_getFilename(const Param *my, const char *name, const char *idx, int *row, char *val)
+{
+       int retVal = 0;
+       int rows = 0;
+       char value[PARAM_MAX_VALUE_LEN];
+
+       if (((retVal = Param_getString(my, name, idx, &rows, value)) == 0) && (rows == 1)) {
+               if (value[0] == '/') {
+                       strcpy(val, value);
+                       *row = 1;
+               } else {
+                       if ((Param_getString(my, "glob", "basedir", &rows, val) == 0) && (rows == 1)) {
+                               strcat(val, "/");
+                               strcat(val, value);
+                               *row = 1;
+                       } else {
+                               strcpy(val, value);
+                               *row = 1;
+                       }
+               }
+       } else {
+               *row = 0;
+       }
+       return retVal;
+}
+
+int Param_getFilenameArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val)
+{
+       int retVal = 0;
+       int row = 0;
+       int i;
+       char *value[PARAM_MAX_ARRAY_LEN];
+
+       for (i = 0 ; i < maxrows ; i++) {
+               value[i] = malloc(PARAM_MAX_VALUE_LEN);
+       }
+
+       if (((retVal = Param_getStringArray(my, name, idx, maxrows, rows, value)) == 0) && (*rows > 0)) {
+               char basedir[PARAM_MAX_VALUE_LEN];
+
+               if ((Param_getString(my, "glob", "basedir", &row, basedir) == 0) && (row == 1)) {
+                       strcat(basedir, "/");
+               } else {
+                       strcpy(basedir, "");
+               }
+               for (i = 0 ; i < *rows ; i++) {
+                       if (value[i][0] != '/') {
+                               strcpy(val[i], basedir);
+                       } else {
+                               strcpy(val[i], "");
+                       }
+                       strcat(val[i], value[i]);
+               }
+       } else {
+               *rows = 0;
+       }
+
+       for (i = 0 ; i < maxrows ; i++) {
+               free(value[i]);
+       }
+
+       return retVal;
+}
+
+int Param_storeInt(const Param *my, const char *name, const char *idx, unsigned long int value)
+{
+       char buf[strlen("set ()\t\n") + 2 * PARAM_MAX_NAME_LEN + PARAM_MAX_VALUE_LEN];
+       sprintf(buf, "set %s(%s)\t%lu\n", name, idx, value);
+       fprintf(((TclParam *) (my->specParam))->store, buf);
+       Tcl_Eval(((TclParam *) (my->specParam))->interp, buf);
+       return 0;
+}
+
+int Param_storeString(const Param *my, const char *name, const char *idx, const char *value)
+{
+       char buf[strlen("set ()\t\n") + 2 * PARAM_MAX_NAME_LEN + PARAM_MAX_VALUE_LEN];
+       sprintf(buf, "set %s(%s)\t\"%s\"\n", name, idx, value);
+       fprintf(((TclParam *) (my->specParam))->store, buf);
+       Tcl_Eval(((TclParam *) (my->specParam))->interp, buf);
+       return 0;
+}
+
 const char *Param_getErrStr(const Param *my)
 {
        return my->strerror;
diff --git a/allParam/tcl/tclParam.h b/allParam/tcl/tclParam.h
deleted file mode 100644 (file)
index af2345f..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef TCLPARAM_H
-#define TCLPARAM_H
-
-#define PARAM_MAX_ARRAY_LEN 128
-#define PARAM_MAX_VALUE_LEN 128
-#define PARAM_MAX_NAME_LEN 128
-
-/*****************************************************************************
- * Section containing struct Param (different in the different xxxParam.h's) *
- *****************************************************************************/
-
-#ifndef STATESET_ST
-
-#include <tcl.h>
-
-typedef struct ParamS {
-       char *strerror;
-       Tcl_Interp *interp;
-} Param;
-
-/*********************************************************************
- * Section containing the API for param (common to all allParam.h's) *
- *********************************************************************/
-
-int conParam(Param *);
-void desParam(Param *);
-
-int Param_getInt(const Param *, const char *, const char *, int *, unsigned long int *);
-int Param_getString(const Param *, const char *, const char *, int *, char *);
-int Param_getIntArray(const Param *, const char *, const char *, int, int *, unsigned long int *);
-int Param_getStringArray(const Param *, const char *, const char *, int, int *, char **);
-
-const char *Param_getErrStr(const Param *);
-
-#endif
-
-#endif
-