From f33ff4419a4730aef08a5632ee235eb58a908d19 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 14 Mar 2001 13:27:03 +0000 Subject: [PATCH] *** empty log message *** --- allParam/Makefile | 67 ++--- allParam/VERSION | 2 +- allParam/WARNING | 12 + allParam/ca/Makefile | 27 +- allParam/ca/caParam.c | 312 -------------------- allParam/ca/client/Makefile | 21 ++ allParam/ca/client/caParam.c | 535 +++++++++++++++++++++++++++++++++++ allParam/ca/server/Makefile | 81 ++++++ allParam/file/Makefile | 5 +- allParam/include/allParam.h | 9 + allParam/ora/Makefile | 5 +- allParam/psql/Makefile | 5 +- allParam/tcl/Makefile | 5 +- 13 files changed, 717 insertions(+), 369 deletions(-) create mode 100644 allParam/WARNING delete mode 100644 allParam/ca/caParam.c create mode 100644 allParam/ca/client/Makefile create mode 100644 allParam/ca/client/caParam.c create mode 100644 allParam/ca/server/Makefile diff --git a/allParam/Makefile b/allParam/Makefile index bc5010e..844e451 100644 --- a/allParam/Makefile +++ b/allParam/Makefile @@ -1,10 +1,10 @@ -#LIBDIR = /usr/local/lib #INCDIR = /usr/local/include +#LIBDIR = /usr/local/lib +#BINDIR = /usr/local/bin -LIBDIR = $(HOME)/lib/$(SYSTYPE) INCDIR = $(HOME)/include - -ARFLAGS = -rc +LIBDIR = $(HOME)/lib/$(SYSTYPE) +BINDIR = $(HOME)/bin/$(SYSTYPE) PARAMLIBES = ca file ora psql tcl INSTALLS = ca_install file_install ora_install psql_install tcl_install @@ -13,41 +13,34 @@ ALLS = ca_all file_all ora_all psql_all tcl_all VPATH = ca:file:ora:psql:tcl -all : $(ALLS) - -lib : $(PARAMLIBES) - -install : $(INSTALLS) - -test : $(TESTS) +warning : + @cat WARNING # Some subsets to make -hades05 : ca_all file_all tcl_all -lxi001 : ca_all file_all ora_all tcl_all - -ca_all : ca ca_install ca_test -file_all : file file_install file_test -ora_all : ora ora_install ora_test -psql_all : psql psql_install psql_test -tcl_all : tcl tcl_install tcl_test +ca_all : ca ca_test ca_install +file_all : file file_test file_install +ora_all : ora ora_test ora_install +psql_all : psql psql_test psql_install +tcl_all : tcl tcl_test tcl_install $(PARAMLIBES) : cd $@ ; $(MAKE) +$(TESTS) : + cd test ; $(MAKE) $@ + ca_install : - cd ca ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)" + cd ca ; $(MAKE) install "INCDIR=$(INCDIR)" "LIBDIR=$(LIBDIR)" \ + "BINDIR=$(BINDIR)" file_install : - cd file ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)" + cd file ; $(MAKE) install "INCDIR=$(INCDIR)" "LIBDIR=$(LIBDIR)" ora_install : - cd ora ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)" + cd ora ; $(MAKE) install "INCDIR=$(INCDIR)" "LIBDIR=$(LIBDIR)" psql_install : - cd psql ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)" + cd psql ; $(MAKE) install "INCDIR=$(INCDIR)" "LIBDIR=$(LIBDIR)" tcl_install : - cd tcl ; $(MAKE) install "LIBDIR=$(LIBDIR)" "INCDIR=$(INCDIR)" - -$(TESTS) : - cd test ; $(MAKE) $@ + cd tcl ; $(MAKE) install "INCDIR=$(INCDIR)" "LIBDIR=$(LIBDIR)" clean : cd ca ; $(MAKE) $@ @@ -65,15 +58,17 @@ lib_clean : cd tcl ; $(MAKE) $@ cd test ; $(MAKE) bin_clean -tar : lib_clean - rm -rf old_ca/ old_tcl/ param/ - ln -s caParam.h ca/allParam.h - ln -s fileParam.h file/allParam.h - ln -s oraParam.h ora/allParam.h - ln -s psqlParam.h psql/allParam.h - ln -s tclParam.h tcl/allParam.h - cd .. ; tar -cvZf allParam.0.1.tar.Z allParam/ - rm -f */allParam.h +dist : + $(MAKE) lib_clean + $(MAKE) tar "VERSION=`cat VERSION`" + +tar : + @echo making tar archive of current version $(VERSION) + cd .. ; tar -cvZf allParam-$(VERSION).tar.Z allParam/ + @echo made tar archive allParam-$(VERSION).tar.Z of current version + +# These "dummy" dependencies are because of $(PARAMLIBES) and test are also +# directories existing here. $(PARAMLIBES) test : dummy dummy : diff --git a/allParam/VERSION b/allParam/VERSION index 3b04cfb..c946ee6 100644 --- a/allParam/VERSION +++ b/allParam/VERSION @@ -1 +1 @@ -0.2 +0.1.6 diff --git a/allParam/WARNING b/allParam/WARNING new file mode 100644 index 0000000..1803d02 --- /dev/null +++ b/allParam/WARNING @@ -0,0 +1,12 @@ ++------------------------------------------------------------------------------+ +| Making all the libraries is probably not the thing You want to do (as some | +| of them have very special requirements). So please specify the ones You | +| really want to be made. Possible choices are: | +| - ca | +| - file | +| - ora | +| - psql | +| - tcl | +| For more detailed information please refer to the general README in this | +| directory and the special READMEs in the corresponding subdirectories. | ++------------------------------------------------------------------------------+ diff --git a/allParam/ca/Makefile b/allParam/ca/Makefile index 4f3aae4..ed945f6 100644 --- a/allParam/ca/Makefile +++ b/allParam/ca/Makefile @@ -1,20 +1,23 @@ -CFLAGS = -g -ansi -Wall -I$(EPICS_BASE)/include \ - -I$(EPICS_BASE)/include/os/$(HOST_ARCH) -I../include +SERVERS = daq_file_param_cas daq_ora_param_cas \ + daq_psql_param_cas daq_tcl_param_cas -libcaParam.a : caParam.o - $(AR) $(ARFLAGS) $@ $< +default : libcaParam.a daq_tcl_param_cas -caParam.o : caParam.c +libcaParam.a : + cd client ; $(MAKE) $@ -install : libcaParam.a - -mkdir -p $(LIBDIR) - install -m 644 $< $(LIBDIR) - -mkdir -p $(INCDIR) - install -m 644 ../include/allParam.h $(INCDIR) +$(SERVERS) : + cd server ; $(MAKE) $@ "SERVERS=$(SERVERS)" + +install : + cd client ; $(MAKE) $@ "INCDIR=$(INCDIR)" "LIBDIR=$(LIBDIR)" + cd server ; $(MAKE) $@ "INCDIR=$(INCDIR)" "BINDIR=$(BINDIR)" clean : - rm -f *.o + cd client ; $(MAKE) $@ + cd server ; $(MAKE) $@ lib_clean : - rm -f *.o *.a + cd client ; $(MAKE) $@ + cd server ; $(MAKE) bin_clean diff --git a/allParam/ca/caParam.c b/allParam/ca/caParam.c deleted file mode 100644 index 16ab63c..0000000 --- a/allParam/ca/caParam.c +++ /dev/null @@ -1,312 +0,0 @@ -#define _POSIX_C_SOURCE 199509L - -#include -#include -#include -#include - -#include - -#include - -#define TIMEOUT 0.2 - -static void Param_copyToAllocMem(struct event_handler_args args); -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) -{ - return Param_getIntArray(my, name, idx, 1, row, val); -} - -int Param_getString(const Param *my, const char *name, const char *idx, int *row, char *val) -{ - return Param_getStringArray(my, name, idx, 1, row, &val); -} - -int Param_getIntArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, unsigned long int *val) -{ - int retVal = 0; - int i; - char *endptr; - char *value[PARAM_MAX_ARRAY_LEN]; - - for (i = 0 ; i < PARAM_MAX_ARRAY_LEN ; i++) { - value[i] = malloc(PARAM_MAX_VALUE_LEN * sizeof(char)); - } - - if((retVal = Param_getStringArray(my, name, idx, maxrows, rows, value)) == 0) { - for (i = 0 ; i < *rows ; i++) { - val[i] = strtoul(value[i], &endptr, 0); - if(*endptr != '\0') { - Param_strerror((Param *) my, "Value seems not to be integer."); - retVal = -1; - } - } - } - if (retVal != 0) { - *rows = 0; - } - - for (i = 0 ; i < PARAM_MAX_ARRAY_LEN ; i++) { - free(value[i]); - } - return retVal; -} - -int Param_getStringArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val) -{ - int retVal = 0; - int status; - int found = 1; - chid chan; - char *pPVName; - - *rows = 0; - if((status = ca_task_initialize()) != ECA_NORMAL) { - Param_strerror((Param *) my, ca_message(status)); - retVal = -1; - } - - 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)); - 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) { - ParamResult resultS, *result = &resultS; - result->val = val; - result->rows = rows; - result->maxrows = maxrows; - result->my = my; - result->retVal = &retVal; - - 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((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; - } - } - - 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; -} - -const char *Param_getErrStr(const Param *my) -{ - return my->strerror; -} - -static void Param_copyToAllocMem(struct event_handler_args args) -{ - int i; - ParamResult *result = args.usr; - dbr_string_t *buffer = (dbr_string_t *) args.dbr; - - *(result->rows) = (args.count > result->maxrows) ? - result->maxrows : - args.count; - if(args.type == DBR_STRING && args.status == ECA_NORMAL) { - for(i = 0 ; i < *(result->rows) ; i++) { - strcpy((result->val)[i], buffer[i]); - } - } else { - Param_strerror((Param *) result->my, ca_message(args.status)); - *(result->rows) = 0; - *(result->retVal) = -1; - } -} - -static void Param_returnPVName(const Param *my, const char *get_store, const char *name, const char *idx, char *pPVName) -{ - int i; - - 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]); - } -} - -static void Param_strerror(Param *my, const char *strerror) -{ - my->strerror = realloc(my->strerror, strlen(strerror) + 1); - if(my->strerror != NULL) { - strcpy(my->strerror, strerror); - } -} - diff --git a/allParam/ca/client/Makefile b/allParam/ca/client/Makefile new file mode 100644 index 0000000..8b77380 --- /dev/null +++ b/allParam/ca/client/Makefile @@ -0,0 +1,21 @@ +CFLAGS = -g -ansi -Wall -I$(EPICS_BASE)/include \ + -I$(EPICS_BASE)/include/os/$(HOST_ARCH) -I../../include +ARFLAGS = -rc + +libcaParam.a : caParam.o + $(AR) $(ARFLAGS) $@ $< + +caParam.o : caParam.c + +install : libcaParam.a + -mkdir -p $(LIBDIR) + cp $< $(LIBDIR) + -mkdir -p $(INCDIR) + cp ../../include/allParam.h $(INCDIR) + +clean : + rm -f *.o + +lib_clean : + rm -f *.o *.a + diff --git a/allParam/ca/client/caParam.c b/allParam/ca/client/caParam.c new file mode 100644 index 0000000..3fc598f --- /dev/null +++ b/allParam/ca/client/caParam.c @@ -0,0 +1,535 @@ +#define _POSIX_C_SOURCE 199509L + +#include +#include +#include +#include +#include + +#include + +#include + +#define TIMEOUT 0.2 + +static void Param_copyStringsToAllocMem(struct event_handler_args args); +static void Param_copyIntsToAllocMem(struct event_handler_args args); +static void Param_copyBlobToAllocMem(struct event_handler_args args); +static void Param_returnPVName(const Param *my, const char *, const char *, const char *, char *); +static void Param_strerror(Param *, const char *); + +typedef struct ParamStringResultS { + char **val; + int *rows; + int maxrows; + const Param *my; + int *retVal; +} ParamStringResult; + +typedef struct ParamIntResultS { + unsigned long int *val; + int *rows; + int maxrows; + const Param *my; + int *retVal; +} ParamIntResult; + +typedef struct ParamBlobResultS { + FILE *val; + size_t *size; + size_t maxsize; + const Param *my; + int *retVal; +} ParamBlobResult; + +int conSetupParam(Param *my, const char *setup) +{ + my->strerror = NULL; + if(setup != NULL) { + my->setup = malloc(strlen(setup) + 1); + strcpy(my->setup, setup); + } else { + my->setup = NULL; + } + return 0; +} + +int conParam(Param *my) +{ + return conSetupParam(my, NULL); +} + +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) +{ + return Param_getIntArray(my, name, idx, 1, row, val); +} + +int Param_getString(const Param *my, const char *name, const char *idx, int *row, char *val) +{ + return Param_getStringArray(my, name, idx, 1, row, &val); +} + +int Param_getFilename(const Param *my, const char *name, const char *idx, int *row, char *val) +{ + return Param_getFilenameArray(my, name, idx, 1, row, &val); +} + +int Param_getIntArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, unsigned long int *val) +{ + int retVal = 0; + int status; + int found = 1; + chid chan; + char *pPVName; + + *rows = 0; + if((status = ca_task_initialize()) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + retVal = -1; + } + + pPVName = malloc((strlen("HAD:PI:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); + Param_returnPVName(my, "PI", 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) { + ParamIntResult resultS, *result = &resultS; + result->val = val; + result->rows = rows; + result->maxrows = maxrows; + result->my = my; + result->retVal = &retVal; + + status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyIntsToAllocMem, result); + 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_getStringArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val) +{ + int retVal = 0; + int status; + int found = 1; + chid chan; + char *pPVName; + + *rows = 0; + 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) { + ParamStringResult resultS, *result = &resultS; + result->val = val; + result->rows = rows; + result->maxrows = maxrows; + result->my = my; + result->retVal = &retVal; + + status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyStringsToAllocMem, result); + 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_getFilenameArray(const Param *my, const char *name, const char *idx, int maxrows, int *rows, char **val) +{ + int retVal = 0; + int status; + int found = 1; + chid chan; + char *pPVName; + + *rows = 0; + if((status = ca_task_initialize()) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + retVal = -1; + } + + pPVName = malloc((strlen("HAD:PF:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); + Param_returnPVName(my, "PF", 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) { + ParamStringResult resultS, *result = &resultS; + result->val = val; + result->rows = rows; + result->maxrows = maxrows; + result->my = my; + result->retVal = &retVal; + + status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyStringsToAllocMem, result); + 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_getBlob(const Param *my, const char *name, const char *idx, size_t maxsize, size_t *size, FILE *val) +{ + int retVal = 0; + int status; + int found = 1; + chid chan; + char *pPVName; + + *size = 0; + if((status = ca_task_initialize()) != ECA_NORMAL) { + Param_strerror((Param *) my, ca_message(status)); + retVal = -1; + } + + pPVName = malloc((strlen("HAD:PB:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); + Param_returnPVName(my, "PB", 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) { + ParamBlobResult resultS, *result = &resultS; + result->val = val; + result->size = size; + result->maxsize = maxsize; + result->my = my; + result->retVal = &retVal; + + status = ca_array_get_callback(ca_field_type(chan), ca_element_count(chan), chan, Param_copyBlobToAllocMem, result); + 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_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:PI:") + (my->setup == NULL ? 0 : strlen(my->setup) + 1) + strlen(name) + 1 + strlen(idx) + 1) * sizeof(char)); + Param_returnPVName(my, "PI", 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; + } + } + + 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; +} + +const char *Param_getErrStr(const Param *my) +{ + return my->strerror; +} + +static void Param_copyStringsToAllocMem(struct event_handler_args args) +{ + int i; + ParamStringResult *result = args.usr; + dbr_string_t *buffer = (dbr_string_t *) args.dbr; + + *(result->rows) = (args.count > result->maxrows) ? + result->maxrows : + args.count; + if(args.type == DBR_STRING && args.status == ECA_NORMAL) { + for(i = 0 ; i < *(result->rows) ; i++) { + strcpy((result->val)[i], buffer[i]); + } + } else { + Param_strerror((Param *) result->my, ca_message(args.status)); + *(result->rows) = 0; + *(result->retVal) = -1; + } +} + +static void Param_copyIntsToAllocMem(struct event_handler_args args) +{ + int i; + ParamIntResult *result = args.usr; + dbr_long_t *buffer = (dbr_long_t *) args.dbr; + + *(result->rows) = (args.count > result->maxrows) ? + result->maxrows : + args.count; + if(args.type == DBR_LONG && args.status == ECA_NORMAL) { + for(i = 0 ; i < *(result->rows) ; i++) { + (result->val)[i] = buffer[i]; + } + } else { + Param_strerror((Param *) result->my, ca_message(args.status)); + *(result->rows) = 0; + *(result->retVal) = -1; + } +} + +static void Param_copyBlobToAllocMem(struct event_handler_args args) +{ + ParamBlobResult *result = args.usr; + dbr_long_t *buffer = (dbr_long_t *) args.dbr; + + *(result->size) = (args.count > result->maxsize) ? + result->maxsize : + args.count; + if(args.type == DBR_LONG && args.status == ECA_NORMAL) { + fwrite(buffer, sizeof(dbr_long_t), *(result->size), result->val); + } else { + Param_strerror((Param *) result->my, ca_message(args.status)); + *(result->size) = 0; + *(result->retVal) = -1; + } +} + +static void Param_returnPVName(const Param *my, const char *type, const char *name, const char *idx, char *pPVName) +{ + int i; + + if (my->setup == NULL) { + sprintf(pPVName ,"HAD:%s:%s:%s", type, name, idx); + } else { + sprintf(pPVName ,"HAD:%s:%s:%s:%s", type, my->setup, name, idx); + } + for (i = 0 ; i < strlen(pPVName) ; i++) { + pPVName[i] = toupper(pPVName[i]); + } +} + +static void Param_strerror(Param *my, const char *strerror) +{ + my->strerror = realloc(my->strerror, strlen(strerror) + 1); + if(my->strerror != NULL) { + strcpy(my->strerror, strerror); + } +} + diff --git a/allParam/ca/server/Makefile b/allParam/ca/server/Makefile new file mode 100644 index 0000000..2bb7f1d --- /dev/null +++ b/allParam/ca/server/Makefile @@ -0,0 +1,81 @@ +########## +# Macros # +########## + +MV = mv + +CXXFLAGS = -g -ansi -Wall -I$(EPICS_BASE)/include \ + -I$(EPICS_BASE)/include/os/$(HOST_ARCH) -I../../include + +LOADLIBES = -L$(EPICS_BASE)/lib/$(HOST_ARCH) -lcas -lgdd -lca -lCom + +# Objects + +OBJS = record.o paramRecord.o paramGetRecord.o paramStoreRecord.o \ + paramRecordSet.o paramServer.o + +########### +# Targets # +########### + +daq_file_param_cas : ../../file/libfileParam.a + $(MAKE) daq_param_cas "LOADLIBES=-L../../file -lfileParam $(LOADLIBES)" + $(MV) daq_param_cas $@ + +daq_ora_param_cas : ../../ora/liboraParam.a + $(MAKE) daq_param_cas \ + "LOADLIBES=-L../../ora -loraParam -L$(ORACLE_HOME)/lib \ + -lsql -lclntsh -lcommon -lcore4 -lnlsrtl3 $(LOADLIBES)" + $(MV) daq_param_cas $@ + +daq_psql_param_cas : ../../psql/libpsqlParam.a + $(MAKE) daq_param_cas \ + "LOADLIBES=-L../../psql -lpsqlParam -lpq -lcrypt $(LOADLIBES)" + $(MV) daq_param_cas $@ + +daq_tcl_param_cas : ../../tcl/libtclParam.a + $(MAKE) daq_param_cas \ + "LOADLIBES=-L../../tcl -ltclParam -ltcl -lm -ldl $(LOADLIBES)" + $(MV) daq_param_cas $@ + +daq_param_cas : $(OBJS) + $(CXX) $(LDFLAGS) $^ $(LOADLIBES) -o $@ + +paramServer.o: paramServer.cc paramRecordSet.h \ + paramRecord.h record.h + +paramRecordSet.o: paramRecordSet.cc paramRecordSet.h paramGetRecord.h \ + paramStoreRecord.h paramRecord.h record.h + +record.o : record.cc record.h +paramRecord.o: paramRecord.cc paramRecord.h record.h +paramGetRecord.o: paramGetRecord.cc paramGetRecord.h paramRecord.h record.h +paramStoreRecord.o: paramStoreRecord.cc paramStoreRecord.h paramRecord.h \ + record.h + +# Libraries as sources for the server + +../../file/libfileParam.a : + cd ../../file ; $(MAKE) + +../../ora/liboraParam.a : + cd ../../ora ; $(MAKE) + +../../psql/libpsqlParam.a : + cd ../../psql ; $(MAKE) + +../../tcl/libtclParam.a : + cd ../../tcl ; $(MAKE) + +# Administrative + +install : + -mkdir -p $(BINDIR) + cp daq_*_param_cas $(BINDIR) + +clean : + rm -f *.o + +bin_clean : + rm -f *.o daq_*_param_cas + diff --git a/allParam/file/Makefile b/allParam/file/Makefile index 6d377ed..283351d 100644 --- a/allParam/file/Makefile +++ b/allParam/file/Makefile @@ -1,4 +1,5 @@ CFLAGS = -g -ansi -Wall -I../include +ARFLAGS = -rc libfileParam.a : fileParam.o $(AR) $(ARFLAGS) $@ $< @@ -7,9 +8,9 @@ fileParam.o : fileParam.c install : libfileParam.a -mkdir -p $(LIBDIR) - install -m 644 $< $(LIBDIR) + cp $< $(LIBDIR) -mkdir -p $(INCDIR) - install -m 644 ../include/allParam.h $(INCDIR) + cp ../include/allParam.h $(INCDIR) clean : rm -f *.o diff --git a/allParam/include/allParam.h b/allParam/include/allParam.h index f691ac9..538962f 100644 --- a/allParam/include/allParam.h +++ b/allParam/include/allParam.h @@ -1,6 +1,14 @@ #ifndef ALLPARAM_H #define ALLPARAM_H +#ifdef __cplusplus +extern "C" { +#include +#endif +#ifdef __cplusplus +} +#endif + #define PARAM_MAX_ARRAY_LEN 128 #define PARAM_MAX_VALUE_LEN 128 #define PARAM_MAX_NAME_LEN 128 @@ -21,6 +29,7 @@ int Param_getIntArray(const Param *, const char *, const char *, int, int *, uns 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_getBlob(const Param *my, const char *, const char *, size_t, size_t *, FILE *); int Param_storeInt(const Param *, const char *, const char *, unsigned long int); int Param_storeString(const Param *, const char *, const char *, const char *); diff --git a/allParam/ora/Makefile b/allParam/ora/Makefile index 5509062..26e8574 100644 --- a/allParam/ora/Makefile +++ b/allParam/ora/Makefile @@ -1,4 +1,5 @@ CFLAGS = -g -ansi -Wall -I../include -I$(ORACLE_HOME)/precomp/public/ +ARFLAGS = -rc ORA_USER = hades/hades@db-hades.gsi.de @@ -24,9 +25,9 @@ oraParam.c : oraParam.pc install : liboraParam.a -mkdir -p $(LIBDIR) - install -m 644 $< $(LIBDIR) + cp $< $(LIBDIR) -mkdir -p $(INCDIR) - install -m 644 ../include/allParam.h $(INCDIR) + cp ../include/allParam.h $(INCDIR) clean : rm -f *.o oraParam.c oraParam.lis diff --git a/allParam/psql/Makefile b/allParam/psql/Makefile index 48068df..27dec61 100644 --- a/allParam/psql/Makefile +++ b/allParam/psql/Makefile @@ -1,4 +1,5 @@ CFLAGS = -g -ansi -Wall -I/usr/include/pgsql -I../include +ARFLAGS = -rc libpsqlParam.a : psqlParam.o $(AR) $(ARFLAGS) $@ $< @@ -7,9 +8,9 @@ psqlParam.o : psqlParam.c install : libpsqlParam.a -mkdir -p $(LIBDIR) - install -m 644 $< $(LIBDIR) + cp $< $(LIBDIR) -mkdir -p $(INCDIR) - install -m 644 ../include/allParam.h $(INCDIR) + cp ../include/allParam.h $(INCDIR) clean : rm -f *.o diff --git a/allParam/tcl/Makefile b/allParam/tcl/Makefile index 6bb1ccd..fa92229 100644 --- a/allParam/tcl/Makefile +++ b/allParam/tcl/Makefile @@ -1,4 +1,5 @@ CFLAGS = -g -ansi -Wall -I../include +ARFLAGS = -rc libtclParam.a : tclParam.o $(AR) $(ARFLAGS) $@ $< @@ -7,9 +8,9 @@ tclParam.o : tclParam.c install : libtclParam.a -mkdir -p $(LIBDIR) - install -m 644 $< $(LIBDIR) + cp $< $(LIBDIR) -mkdir -p $(INCDIR) - install -m 644 ../include/allParam.h $(INCDIR) + cp ../include/allParam.h $(INCDIR) clean : rm -f *.o -- 2.43.0