]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
caching on client rpc side, first try, only ints cached
authormuench <muench>
Fri, 7 May 2004 11:55:29 +0000 (11:55 +0000)
committermuench <muench>
Fri, 7 May 2004 11:55:29 +0000 (11:55 +0000)
allParam/Makefile.am
allParam/Makefile.in
allParam/rpc/pcache.c [new file with mode: 0644]
allParam/rpc/pcache.h [new file with mode: 0644]
allParam/rpc/rpcParam.c
allParam/test/int/i_conparam.c

index bf5fa2e1fe831f625fb7308debefe56f9fd4b6c9..e81fdc20995ae051c7dc0a936c8a749438bf6239 100644 (file)
@@ -49,7 +49,7 @@ libfileParam_a_SOURCES = file/fileParam.c
 libfileParam_p_a_SOURCES = file/fileParam.c
 liboraParam_a_SOURCES = oraParam.c
 liboraParam_p_a_SOURCES = oraParam.c
-librpcParam_a_SOURCES = $(srcdir)/rpc/rpcParam.c $(srcdir)/rpc/rpcParam_clnt.c $(srcdir)/rpc/rpcParam_xdr.c
+librpcParam_a_SOURCES = $(srcdir)/rpc/rpcParam.c $(srcdir)/rpc/pcache.c $(srcdir)/rpc/rpcParam_clnt.c $(srcdir)/rpc/rpcParam_xdr.c
 librpcParam_p_a_SOURCES = $(srcdir)/rpc/rpcParam.c $(srcdir)/rpc/rpcParam_clnt.c $(srcdir)/rpc/rpcParam_xdr.c
 libtclParam_a_SOURCES = tcl/tclParam.c
 libtclParam_p_a_SOURCES = tcl/tclParam.c
index 6caee73a84e8d39dc7291a3ff2ec329b6c61030c..fa3cb3cd231136e717c5f784b9787e4c13700f26 100644 (file)
@@ -146,7 +146,7 @@ libfileParam_a_SOURCES = file/fileParam.c
 libfileParam_p_a_SOURCES = file/fileParam.c
 liboraParam_a_SOURCES = oraParam.c
 liboraParam_p_a_SOURCES = oraParam.c
-librpcParam_a_SOURCES = $(srcdir)/rpc/rpcParam.c $(srcdir)/rpc/rpcParam_clnt.c $(srcdir)/rpc/rpcParam_xdr.c
+librpcParam_a_SOURCES = $(srcdir)/rpc/rpcParam.c $(srcdir)/rpc/pcache.c $(srcdir)/rpc/rpcParam_clnt.c $(srcdir)/rpc/rpcParam_xdr.c
 librpcParam_p_a_SOURCES = $(srcdir)/rpc/rpcParam.c $(srcdir)/rpc/rpcParam_clnt.c $(srcdir)/rpc/rpcParam_xdr.c
 libtclParam_a_SOURCES = tcl/tclParam.c
 libtclParam_p_a_SOURCES = tcl/tclParam.c
@@ -201,6 +201,7 @@ liboraParam_p_a_OBJECTS = $(am_liboraParam_p_a_OBJECTS)
 librpcParam_a_AR = $(AR) cru
 librpcParam_a_LIBADD =
 am_librpcParam_a_OBJECTS = librpcParam_a-rpcParam.$(OBJEXT) \
+       librpcParam_a-pcache.$(OBJEXT) \
        librpcParam_a-rpcParam_clnt.$(OBJEXT) \
        librpcParam_a-rpcParam_xdr.$(OBJEXT)
 librpcParam_a_OBJECTS = $(am_librpcParam_a_OBJECTS)
@@ -247,6 +248,7 @@ am__depfiles_maybe = depfiles
 @AMDEP_TRUE@   ./$(DEPDIR)/libfileParam_p_a-fileParam.Po \
 @AMDEP_TRUE@   ./$(DEPDIR)/liboraParam_a-oraParam.Po \
 @AMDEP_TRUE@   ./$(DEPDIR)/liboraParam_p_a-oraParam.Po \
+@AMDEP_TRUE@   ./$(DEPDIR)/librpcParam_a-pcache.Po \
 @AMDEP_TRUE@   ./$(DEPDIR)/librpcParam_a-rpcParam.Po \
 @AMDEP_TRUE@   ./$(DEPDIR)/librpcParam_a-rpcParam_clnt.Po \
 @AMDEP_TRUE@   ./$(DEPDIR)/librpcParam_a-rpcParam_xdr.Po \
@@ -441,6 +443,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfileParam_p_a-fileParam.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liboraParam_a-oraParam.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liboraParam_p_a-oraParam.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/librpcParam_a-pcache.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/librpcParam_a-rpcParam.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/librpcParam_a-rpcParam_clnt.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/librpcParam_a-rpcParam_xdr.Po@am__quote@
@@ -636,6 +639,28 @@ librpcParam_a-rpcParam.obj: $(srcdir)/rpc/rpcParam.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(librpcParam_a_CFLAGS) $(CFLAGS) -c -o librpcParam_a-rpcParam.obj `if test -f '$(srcdir)/rpc/rpcParam.c'; then $(CYGPATH_W) '$(srcdir)/rpc/rpcParam.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/rpc/rpcParam.c'; fi`
 
+librpcParam_a-pcache.o: $(srcdir)/rpc/pcache.c
+@am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(librpcParam_a_CFLAGS) $(CFLAGS) -MT librpcParam_a-pcache.o -MD -MP -MF "$(DEPDIR)/librpcParam_a-pcache.Tpo" \
+@am__fastdepCC_TRUE@     -c -o librpcParam_a-pcache.o `test -f '$(srcdir)/rpc/pcache.c' || echo '$(srcdir)/'`$(srcdir)/rpc/pcache.c; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/librpcParam_a-pcache.Tpo" "$(DEPDIR)/librpcParam_a-pcache.Po"; \
+@am__fastdepCC_TRUE@   else rm -f "$(DEPDIR)/librpcParam_a-pcache.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@   fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$(srcdir)/rpc/pcache.c' object='librpcParam_a-pcache.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      depfile='$(DEPDIR)/librpcParam_a-pcache.Po' tmpdepfile='$(DEPDIR)/librpcParam_a-pcache.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(librpcParam_a_CFLAGS) $(CFLAGS) -c -o librpcParam_a-pcache.o `test -f '$(srcdir)/rpc/pcache.c' || echo '$(srcdir)/'`$(srcdir)/rpc/pcache.c
+
+librpcParam_a-pcache.obj: $(srcdir)/rpc/pcache.c
+@am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(librpcParam_a_CFLAGS) $(CFLAGS) -MT librpcParam_a-pcache.obj -MD -MP -MF "$(DEPDIR)/librpcParam_a-pcache.Tpo" \
+@am__fastdepCC_TRUE@     -c -o librpcParam_a-pcache.obj `if test -f '$(srcdir)/rpc/pcache.c'; then $(CYGPATH_W) '$(srcdir)/rpc/pcache.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/rpc/pcache.c'; fi`; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/librpcParam_a-pcache.Tpo" "$(DEPDIR)/librpcParam_a-pcache.Po"; \
+@am__fastdepCC_TRUE@   else rm -f "$(DEPDIR)/librpcParam_a-pcache.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@   fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$(srcdir)/rpc/pcache.c' object='librpcParam_a-pcache.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      depfile='$(DEPDIR)/librpcParam_a-pcache.Po' tmpdepfile='$(DEPDIR)/librpcParam_a-pcache.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(librpcParam_a_CFLAGS) $(CFLAGS) -c -o librpcParam_a-pcache.obj `if test -f '$(srcdir)/rpc/pcache.c'; then $(CYGPATH_W) '$(srcdir)/rpc/pcache.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/rpc/pcache.c'; fi`
+
 librpcParam_a-rpcParam_clnt.o: $(srcdir)/rpc/rpcParam_clnt.c
 @am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(librpcParam_a_CFLAGS) $(CFLAGS) -MT librpcParam_a-rpcParam_clnt.o -MD -MP -MF "$(DEPDIR)/librpcParam_a-rpcParam_clnt.Tpo" \
 @am__fastdepCC_TRUE@     -c -o librpcParam_a-rpcParam_clnt.o `test -f '$(srcdir)/rpc/rpcParam_clnt.c' || echo '$(srcdir)/'`$(srcdir)/rpc/rpcParam_clnt.c; \
diff --git a/allParam/rpc/pcache.c b/allParam/rpc/pcache.c
new file mode 100644 (file)
index 0000000..36ac7f4
--- /dev/null
@@ -0,0 +1,105 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcache.h"
+
+PData *newPInt(const char *name, const char *idx, unsigned long int value) {
+       PData *my = malloc(sizeof(PData));
+
+       my->name = malloc(strlen(name));
+       strcpy(my->name, name);
+
+       my->idx = malloc(strlen(idx));
+       strcpy(my->idx, idx);
+
+       my->type = PInt;
+       my->value.PInt = value;
+
+       return my;
+}
+
+void delPData(PData *my) {
+       if (my != NULL) {
+               switch (my->type) {
+               case PInt:
+                       break;
+               }
+               free(my->idx);
+               free(my->name);
+               free(my);
+       }
+}
+
+static int keyCompare(const PData *my, const PData *data) {
+       int retVal;
+
+       retVal = strcmp(my->name, data->name);
+       if (retVal == 0) {
+               retVal = strcmp(my->idx, data->idx);
+       }
+
+       return retVal;
+}
+
+PCache *insert(PCache *my, PData *data) {
+       if (my == NULL) {
+               my = malloc(sizeof(PCache));
+               my->r = NULL;
+               my->l = NULL;
+               my->data = data;
+       } else {
+               switch (keyCompare(my->data, data)) {
+                       case 0:
+                               delPData(my->data);
+                               my->data = data;
+                               break;
+                       case -1:
+                               my->l = insert(my->l, data);
+                               break;
+                       case 1:
+                               my->r = insert(my->r, data);
+                               break;
+               }
+       }
+       return my;
+}
+
+PData *find(const PCache *my, const PData *data) {
+       PData *retVal;
+
+       if (my == NULL) {
+               retVal = NULL;
+       } else {
+               switch (keyCompare(my->data, data)) {
+                       case 0:
+                               retVal = my->data;
+                               break;
+                       case -1:
+                               retVal = find(my->l, data);
+                               break;
+                       case 1:
+                               retVal = find(my->r, data);
+                               break;
+               }
+       }
+       return retVal;
+}
+
+int PCache_storeInt(PCache **my, const char *name, const char *idx, unsigned long int value) {
+       *my = insert(*my, newPInt(name, idx, value));                   
+}
+       
+int PCache_getInt(const PCache *my, const char *name, const char *idx, unsigned long int *value) {
+       int retVal;
+       const PData *data;
+
+       data = find(my, newPInt(name, idx, 0));
+       if (data == NULL) {
+               *value = 0;
+               retVal = -1;
+       } else {
+               *value = data->value.PInt;
+               retVal = 0;
+       }
+       return retVal;
+}
diff --git a/allParam/rpc/pcache.h b/allParam/rpc/pcache.h
new file mode 100644 (file)
index 0000000..3f87f5b
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef PCHE_H
+#define PCHE_H
+
+enum PType { PInt, PString, PIntArray, PStringArray };
+struct PDataS {
+       char *name;
+       char *idx;
+       enum PType type;
+       union {
+               unsigned long int PInt;
+               char *PString;
+               unsigned long int *PIntArray;
+               char **PStringArray;
+       } value;
+};
+typedef  struct PDataS PData;
+
+struct PCacheS {
+       struct PCacheS *r;
+       struct PCacheS *l;
+       PData *data;
+};
+typedef struct PCacheS PCache;
+
+int PCache_storeInt(PCache **my, const char *name, const char *idx, unsigned long int value);
+int PCache_getInt(const PCache *my, const char *name, const char *idx, unsigned long int *value);
+
+#endif
index 2267b721b114d8340ffc36e56608bf65c4cb73e9..c0dfbea47c3197a9cae12084fb490df7df1e3f76 100644 (file)
@@ -1,4 +1,4 @@
-static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/rpc/rpcParam.c,v 1.6 2004-04-19 12:58:54 muench Exp $";
+static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/allParam/rpc/rpcParam.c,v 1.7 2004-05-07 11:55:29 muench Exp $";
 #define _POSIX_C_SOURCE 199509L
 
 #if HAVE_CONFIG_H
@@ -18,6 +18,7 @@ static const char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuild
 
 #include "../include/allParam.h"
 
+#include "pcache.h"
 #include "rpcParam.h"
 
 static void Param_strerror(Param *, const char *);
@@ -25,6 +26,7 @@ static void Param_strerror(Param *, const char *);
 typedef struct RpcParamS {
        CLIENT *cl;
        unsigned long remParam;
+       PCache *cache;
 } RpcParam;
 
 int conSetupParam(Param * my, const char *setup)
@@ -60,6 +62,8 @@ int conSetupParam(Param * my, const char *setup)
                }
        }
 
+       rpcParam->cache = NULL;
+
        my->specParam = rpcParam;
 
        return retVal;
@@ -85,21 +89,30 @@ void desParam(Param * my)
 
 int Param_getInt(const Param * my, const char *name, const char *idx, int *row, unsigned long int *val)
 {
+       int retVal;
        RpcParam *rpcParam = my->specParam;
 
-       GetScalarArgs args;
-       GetIntRes res;
+       retVal = PCache_getInt(rpcParam->cache, name, idx, val);
+       if (retVal != 0) {
+               GetScalarArgs args;
+               GetIntRes res;
 
-       args.param = rpcParam->remParam;
-       args.name = name;
-       args.idx = idx;
+               args.param = rpcParam->remParam;
+               args.name = name;
+               args.idx = idx;
 
-       res = *getint_1(&args, rpcParam->cl);
+               res = *getint_1(&args, rpcParam->cl);
 
-       *row = res.rows;
-       *val = res.value;
+               *row = res.rows;
+               *val = res.value;
 
-       return res.ret;
+               retVal =  res.ret;
+               PCache_storeInt(&rpcParam->cache, name, idx, *val);
+               puts("no cache");
+       } else {
+               puts("cache");
+       }
+       return retVal;
 }
 
 int Param_getString(const Param * my, const char *name, const char *idx, int *row, char *val)
index ba787af80362a16f6bb2989df3033c8593f9d23c..17af17d05179a29390ab7abca8e666e1e7bc7310 100644 (file)
@@ -25,6 +25,8 @@ int i_conparam(const char *testid)
        param = malloc(sizeof(Param));
        conParam(param);
 
+       retVal = Param_getInt(param, name, idx, &rows, &result);
+       retVal = Param_getInt(param, name, idx, &rows, &result);
        retVal = Param_getInt(param, name, idx, &rows, &result);
        if ((rows == 1) && (result == 100) && (retVal == 0)) {
                myRetVal = 0;