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) $@
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
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.
-A 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:] |
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
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;
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";
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 {
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);
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);
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);
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
#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)
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));
Param_strerror((Param *) my, ca_message(status));
retVal = -1;
found = -1;
- } else {
- found = 1;
}
if((status = ca_pend_io(TIMEOUT)) != ECA_NORMAL) {
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) {
}
}
-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]);
}
+++ /dev/null
-#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
-
-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
#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)
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];
*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;
{
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;
}
}
+++ /dev/null
-#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
-
#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 *);
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 *);
-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
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=$@
-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
+++ /dev/null
-#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
-
#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)
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;
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;
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];
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) {
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;
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);
}
}
-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
#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)
*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) {
*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) {
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;
+++ /dev/null
-#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
-
-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
#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)
}
*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;
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;
+++ /dev/null
-#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
-