Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017 
<== Date ==> <== Thread ==>

Subject: [Merge] lp:~info-martin-konrad/epics-gateway/putlog into lp:epics-gateway
From: Martin Konrad <info@martin-konrad.net>
To: mp+213921@code.launchpad.net
Date: Wed, 02 Apr 2014 20:00:34 -0000
Martin Konrad has proposed merging lp:~info-martin-konrad/epics-gateway/putlog into lp:epics-gateway.

Requested reviews:
  EPICS Core Developers (epics-core)

For more details, see:
https://code.launchpad.net/~info-martin-konrad/epics-gateway/putlog/+merge/213921

Add option to compile in and use caPutLog
-- 
https://code.launchpad.net/~info-martin-konrad/epics-gateway/putlog/+merge/213921
Your team EPICS Core Developers is requested to review the proposed merge of lp:~info-martin-konrad/epics-gateway/putlog into lp:epics-gateway.
=== modified file 'Makefile'
--- Makefile	2009-09-17 15:45:45 +0000
+++ Makefile	2014-04-02 20:00:01 +0000
@@ -144,6 +144,14 @@
 # need access to casCtx.h
 USR_INCLUDES += -I$(EPICS_BASE)/src/cas/generic
 
+# To compile in caPutLog functionality, define the location of the caPutLog
+# module as 'CAPUTLOG' in the appropriate extensions configure/RELEASE* file
+ifdef CAPUTLOG
+  USR_LIBS_DEFAULT += caPutLog dbIoc
+  USR_CXXFLAGS_DEFAULT += -DALLOW_CAPUTLOG
+  USR_CFLAGS_DEFAULT += -DALLOW_CAPUTLOG
+endif
+
 PROD_HOST = gateway
 
 

=== modified file 'gateResources.cc'
--- gateResources.cc	2011-04-05 21:28:22 +0000
+++ gateResources.cc	2014-04-02 20:00:01 +0000
@@ -41,6 +41,12 @@
 #include <gddAppTable.h>
 #include <dbMapper.h>
 
+#ifdef ALLOW_CAPUTLOG
+  #include <caPutLog.h>
+  #include <caPutLogTask.h>
+  #include <caPutLogAs.h>
+#endif
+
 // Global variables
 gateResources* global_resources;
 
@@ -108,6 +114,159 @@
 	return name;
 }
 
+#ifdef ALLOW_CAPUTLOG
+/*
+  We need to define these here, as caPutLog is using dbFldTypes.h defs for
+  DBR_xxx and our code is loading db_access.h defs elsewhere, and thse ARE
+  DIFFERENT.
+
+  DBR_FLOAT in db_access.h is 6, for example but in dbFldTypes.h that means a
+  DBR_ULONG.
+*/
+#define OUR_DBR_STRING   0
+#define OUR_DBR_CHAR     1
+#define OUR_DBR_UCHAR    2
+#define OUR_DBR_SHORT    3
+#define OUR_DBR_USHORT   4
+#define OUR_DBR_LONG     5
+#define OUR_DBR_ULONG    6
+#define OUR_DBR_FLOAT    7
+#define OUR_DBR_DOUBLE   8
+
+static int gddGetOurType(const gdd *gddVal)
+{
+  switch ( gddVal->primitiveType() ) {
+    case aitEnumInt8    : return(OUR_DBR_CHAR);
+    case aitEnumUint8   : return(OUR_DBR_UCHAR);
+    case aitEnumInt16   : return(OUR_DBR_SHORT);
+    case aitEnumEnum16  : return(OUR_DBR_USHORT);
+    case aitEnumUint16  : return(OUR_DBR_USHORT);
+    case aitEnumInt32   : return(OUR_DBR_LONG);
+    case aitEnumUint32  : return(OUR_DBR_ULONG);
+    case aitEnumFloat32 : return(OUR_DBR_FLOAT);
+    case aitEnumFloat64 : return(OUR_DBR_DOUBLE);
+    case aitEnumFixedString:
+    case aitEnumString:
+    default:
+      return(OUR_DBR_STRING);
+  }
+}
+
+static int gddToVALUE(const gdd *gddVal, short ourdbrtype, VALUE *valueStruct)
+{
+  memset(valueStruct,0,sizeof(VALUE));
+  switch (ourdbrtype) {
+    case OUR_DBR_CHAR: {
+          aitInt8 x;
+          gddVal->get(x);
+          valueStruct->v_char = x;
+        }
+        return(0);
+
+    case OUR_DBR_UCHAR: {
+          aitUint8 x;
+          gddVal->get(x);
+          valueStruct->v_uchar = x;
+        }
+        return(0);
+
+    case OUR_DBR_SHORT: {
+          aitInt16 x;
+          gddVal->get(x);
+          valueStruct->v_short = x;
+        }
+        return(0);
+
+    case OUR_DBR_USHORT: {
+          aitUint16 x;
+          gddVal->get(x);
+          valueStruct->v_ushort = x;
+        }
+        return(0);
+
+    case OUR_DBR_LONG: {
+          aitInt32 x;
+          gddVal->get(x);
+          valueStruct->v_long = x;
+        }
+        return(0);
+
+    case OUR_DBR_ULONG: {
+          aitUint32 x;
+          gddVal->get(x);
+          valueStruct->v_ulong = x;
+        }
+        return(0);
+
+    case OUR_DBR_FLOAT: {
+          aitFloat32 x;
+          gddVal->get(x);
+          valueStruct->v_float = x;
+        }
+        return(0);
+
+    case OUR_DBR_DOUBLE: {
+          aitFloat64 x;
+          gddVal->get(x);
+          valueStruct->v_double = x;
+        }
+        return(0);
+
+    case OUR_DBR_STRING:
+    default: {
+          aitString x;
+          gddVal->get(x);
+          int len = strlen(x);
+          int siz = sizeof(valueStruct->v_string);
+          if (len >= siz) {
+            strncpy(valueStruct->v_string,x,siz-1);
+            valueStruct->v_string[siz-1] = 0;
+          } else {
+            strcpy(valueStruct->v_string,x);
+          }
+          return(0);
+        }
+  }
+}
+
+static char *debugVALUEString(VALUE *v, int ourdbrtype, char *buffer)
+{
+  switch (ourdbrtype) {
+    case OUR_DBR_CHAR:
+      sprintf(buffer,"v_char %d",v->v_char);
+      break;
+    case OUR_DBR_UCHAR:
+      sprintf(buffer,"v_uchar %d",v->v_uchar);
+      break;
+    case OUR_DBR_SHORT:
+      sprintf(buffer,"v_short %hd",v->v_short);
+      break;
+    case OUR_DBR_USHORT:
+      sprintf(buffer,"v_ushort %hu",v->v_ushort);
+      break;
+    case OUR_DBR_LONG:
+      sprintf(buffer,"v_long %ld",v->v_long);
+      break;
+    case OUR_DBR_ULONG:
+      sprintf(buffer,"v_ulong %lu",v->v_ulong);
+      break;
+    case OUR_DBR_FLOAT:
+      sprintf(buffer,"v_float %g",v->v_float);
+      break;
+    case OUR_DBR_DOUBLE:
+      sprintf(buffer,"v_double %g",v->v_double);
+      break;
+    case OUR_DBR_STRING:
+      sprintf(buffer,"v_string '%s'",v->v_string);
+      break;
+    default:
+      sprintf(buffer,"unknown type %d",ourdbrtype);
+  }
+  return(buffer);
+}
+
+#endif // ALLOW_CAPUTLOG
+
 gateResources::gateResources(void)
 {
 	as = NULL;
@@ -130,6 +289,9 @@
     
 	// Miscellaneous initializations
 	putlog_file=NULL;
+#ifdef ALLOW_CAPUTLOG
+    caputlog_address=NULL;
+#endif
 	putlogFp=NULL;
 	report_file=strDup(GATE_REPORT_FILE);
     debug_level=0;
@@ -168,6 +330,10 @@
 	if(command_file) delete [] command_file;
 	if(putlog_file) delete [] putlog_file;
 	if(report_file) delete [] report_file;
+#ifdef ALLOW_CAPUTLOG
+    caPutLog_Term();
+	if (caputlog_address) delete [] caputlog_address;
+#endif
 }
 
 int gateResources::appValue=0;
@@ -207,6 +373,62 @@
 	return 0;
 }
 
+#ifdef ALLOW_CAPUTLOG
+int gateResources::setCaPutlogAddress(const char* address)
+{
+	if (caputlog_address) {
+      delete [] caputlog_address;
+    }
+	caputlog_address = strDup(address);
+    return 0;
+}
+
+int gateResources::caPutLog_Init(void)
+{
+  if (caputlog_address) {
+    return caPutLogInit(caputlog_address,caPutLogAll);
+  }
+  return 1;
+}
+
+void gateResources::caPutLog_Term(void)
+{
+  caPutLogTaskStop();
+}
+
+void gateResources::caPutLog_Send
+     (const char *user,
+      const char *host,
+      const char *pvname,
+      const gdd *old_value,
+      const gdd *new_value)
+{
+  if ((! new_value) || (new_value->primitiveType() == aitEnumInvalid)) return;
+
+  // get memory for a LOGDATA item from caPutLog's free list
+  LOGDATA *pdata = caPutLogDataCalloc();
+  if (pdata == NULL) {
+    errlogPrintf("gateResources::caPutLogSend: memory allocation failed\n");
+    return;
+  }
+  strcpy(pdata->userid,user);
+  strcpy(pdata->hostid,host);
+  strcpy(pdata->pv_name,pvname);
+  pdata->pfield = (void *) pvname;
+  pdata->type = gddGetOurType(new_value);
+  gddToVALUE(new_value,pdata->type,&pdata->new_value.value);
+  new_value->getTimeStamp(&pdata->new_value.time);
+  if ((old_value) && (old_value->primitiveType() != aitEnumInvalid) && (gddGetOurType(old_value) == pdata->type)) {
+    gddToVALUE(old_value,pdata->type,&pdata->old_value);
+  } else {
+    // if no usable old_value provided, fill in data.old_value with copy of new value
+    // as there's no way to flag a VALUE struct as invalid
+    memcpy(&pdata->old_value,&pdata->new_value.value,sizeof(VALUE));
+  }
+  caPutLogTaskSend(pdata);
+}
+#endif // ALLOW_CAPUTLOG
+
 int gateResources::setReportFile(const char* file)
 {
 	if(report_file) delete [] report_file;

=== modified file 'gateResources.h'
--- gateResources.h	2007-07-10 20:08:21 +0000
+++ gateResources.h	2014-04-02 20:00:01 +0000
@@ -49,6 +49,7 @@
 #endif
 
 #include "cadef.h"
+#include "gdd.h"
 
 #include "gateVersion.h"
 
@@ -132,6 +133,19 @@
 	gateAs* getAs(void);
 	bool isAsSetUp(void) const { return as?true:false; }
 
+#ifdef ALLOW_CAPUTLOG
+	int setCaPutlogAddress(const char* address);
+	const char* caputlogAddress(void) const	{ return caputlog_address?caputlog_address:"NULL"; }
+    int hasCaPutlogAddress(void) const { return caputlog_address?1:0; }
+	int caPutLog_Init(void);
+    void caPutLog_Send(const char *user,
+                       const char *host,
+                       const char *pvname,
+                       const gdd *old_value,
+                       const gdd *new_value);
+	void caPutLog_Term(void);
+#endif
+
 	// here for convenience
 	static int appValue;
 	static int appEnum;
@@ -144,6 +158,9 @@
 
 private:
 	char *access_file, *pvlist_file, *command_file, *putlog_file, *report_file;
+#ifdef ALLOW_CAPUTLOG
+    char *caputlog_address;
+#endif
 	int debug_level, ro;
 	bool serverMode;
 	bool cacheMode;

=== modified file 'gateStat.cc'
--- gateStat.cc	2005-02-11 22:55:10 +0000
+++ gateStat.cc	2014-04-02 20:00:01 +0000
@@ -92,6 +92,15 @@
 			  pStat && pStat->getName()?pStat->getName():"Unknown");
 			fflush(fp);
 		}
+#ifdef ALLOW_CAPUTLOG
+        if (global_resources->hasCaPutlogAddress()) {
+          global_resources->caPutLog_Send(asclient->user() ? asclient->user() : "Unknown",
+                                          asclient->host() ? asclient->host() : "Unknown",
+                                          (pStat && pStat->getName()) ? pStat->getName() : "Unknown",
+                                          (pStat) ? pStat->pvData() : NULL,
+                                          &value);
+        }
+#endif
 	}
 	
 	// Call the non-virtual-function write() in the gateStat

=== modified file 'gateStat.h'
--- gateStat.h	2004-06-11 15:29:57 +0000
+++ gateStat.h	2014-04-02 20:00:01 +0000
@@ -78,6 +78,8 @@
 	
 	void report(FILE *fp);
 
+    gdd* pvData(void) const { return value; }
+
 protected:
 	gdd *value;
 	gdd *attr;

=== modified file 'gateVc.cc'
--- gateVc.cc	2009-08-31 19:57:25 +0000
+++ gateVc.cc	2014-04-02 20:00:01 +0000
@@ -244,6 +244,15 @@
 			  vc && vc->getName()?vc->getName():"Unknown");
 			fflush(fp);
 		}
+#ifdef ALLOW_CAPUTLOG
+        if (global_resources->hasCaPutlogAddress()) {
+          global_resources->caPutLog_Send(user ? user : "Unknown",
+                                          host ? host : "Unknown",
+                                          (vc && vc->getName()) ? vc->getName() : "Unknown",
+                                          (vc) ? vc->eventData() : NULL,
+                                          &value);
+        }
+#endif
 	}
 	
 	// Call the non-virtual-function write() in the gateVcData
@@ -271,6 +280,15 @@
 			  vc && vc->getName()?vc->getName():"Unknown");
 			fflush(fp);
 		}
+#ifdef ALLOW_CAPUTLOG
+        if (global_resources->hasCaPutlogAddress()) {
+          global_resources->caPutLog_Send(user ? user : "Unknown",
+                                          host ? host : "Unknown",
+                                          (vc && vc->getName()) ? vc->getName() : "Unknown",
+                                          (vc) ? vc->eventData() : NULL,
+                                          &value);
+        }
+#endif
 	}
 	
 	// Call the non-virtual-function write() in the gateVcData

=== modified file 'gateway.cc'
--- gateway.cc	2007-07-10 20:08:21 +0000
+++ gateway.cc	2014-04-02 20:00:01 +0000
@@ -102,6 +102,7 @@
 //	-access file_name = access security file
 //	-command file_name = USR1 command list file
 //	-putlog file_name = putlog file
+//  -caputlog = address (IP:port) for caPutLog server
 //	-report file_name = report file
 //	-home directory = the program's home directory
 //	-connect_timeout number = clear PV connect requests every number seconds
@@ -123,6 +124,7 @@
 //	process variable list file = gateway.pvlist
 //	USR1 command list file = gateway.command
 //	putlog file = gateway.putlog
+//  caputlog address = none, not used
 //	report file = gateway.report
 //	log file = gateway.log
 //	debug level = 0 (none)
@@ -166,7 +168,9 @@
 #define PARM_SERVER_IGNORE_IP 25
 #define PARM_CACHE 			  26
 #define PARM_ARCHIVE		  27
-
+#ifdef ALLOW_CAPUTLOG
+  #define PARM_CAPUTLOG       28
+#endif
 
 #define HOME_DIR_SIZE    300
 
@@ -184,6 +188,9 @@
 static const char *log_file=NULL;
 static const char *putlog_file=NULL;
 static const char *report_file=NULL;
+#ifdef ALLOW_CAPUTLOG
+static const char *caputlog_address=NULL;
+#endif
 #ifndef WIN32
 static pid_t parent_pid;
 #endif
@@ -205,6 +212,9 @@
     { "-access",              7, PARM_ACCESS,      "file_name" },
     { "-command",             8, PARM_COMMAND,     "file_name" },
     { "-putlog",              7, PARM_PUTLOG,      "file_name" },
+#ifdef ALLOW_CAPUTLOG
+    { "-caputlog",            9, PARM_CAPUTLOG,    "address (ip:port)" },
+#endif
     { "-report",              7, PARM_REPORT,      "file_name" },
     { "-home",                5, PARM_HOME,        "directory" },
     { "-sip",                 4, PARM_SERVER_IP,   "IP_address" },
@@ -423,6 +433,9 @@
 	fprintf(fp,"# pvlist file=<%s>\n",global_resources->listFile());
 	fprintf(fp,"# command file=<%s>\n",global_resources->commandFile());
 	fprintf(fp,"# putlog file=<%s>\n",global_resources->putlogFile());
+#ifdef ALLOW_CAPUTLOG
+	fprintf(fp,"# caputlog address=<%s>\n",global_resources->caputlogAddress());
+#endif
 	fprintf(fp,"# report file=<%s>\n",global_resources->reportFile());
 	fprintf(fp,"# debug level=%d\n",global_resources->debugLevel());
 	fprintf(fp,"# dead timeout=%ld\n",global_resources->deadTimeout());
@@ -622,6 +635,22 @@
 	system("printenv | grep EPICS");
 	fflush(stdout); fflush(stderr);
 #endif
+    // start caPutLog in global_resources, if user defined a caPutLog ip:port address
+#ifdef ALLOW_CAPUTLOG
+    if (global_resources->hasCaPutlogAddress()) {
+  	  int caputlog_status = global_resources->caPutLog_Init();
+      if (caputlog_status != 0) {
+        fprintf(stderr,"%s global_resources caPutLogInit failed, aborting\n",timeStamp());
+        fflush(stdout);
+        fflush(stderr);
+        if (server) {
+          delete server;
+          server = NULL;
+        }
+        return 1;
+      }
+    }
+#endif
 
 	// Start the gateServer
 	try {
@@ -834,6 +863,18 @@
 						}
 					}
 					break;
+#ifdef ALLOW_CAPUTLOG
+				case PARM_CAPUTLOG:
+					if(++i>=argc) no_error=0;
+					else {
+						if(argv[i][0]=='-') no_error=0;
+						else {
+							caputlog_address=argv[i];
+							not_done=0;
+						}
+					}
+					break;
+#endif
 				case PARM_REPORT:
 					if(++i>=argc) no_error=0;
 					else {
@@ -1062,6 +1103,9 @@
 		fprintf(stderr,"\tpvlist=%s\n",gr->listFile());
 		fprintf(stderr,"\tcommand=%s\n",gr->commandFile());
 		fprintf(stderr,"\tputlog=%s\n",gr->putlogFile());
+#ifdef ALLOW_CAPUTLOG
+		fprintf(stderr,"\tcaputlog=%s\n",gr->caputlogAddress());
+#endif
 		fprintf(stderr,"\treport=%s\n",gr->reportFile());
 		fprintf(stderr,"\tdead=%ld\n",gr->deadTimeout());
 		fprintf(stderr,"\tconnect=%ld\n",gr->connectTimeout());
@@ -1113,6 +1157,9 @@
 	if(pvlist_file)			gr->setListFile(pvlist_file);
 	if(command_file)		gr->setCommandFile(command_file);
 	if(putlog_file)	    	gr->setPutlogFile(putlog_file);
+#ifdef ALLOW_CAPUTLOG
+	if(caputlog_address)  	gr->setCaPutlogAddress(caputlog_address);
+#endif
 	if(report_file)	    	gr->setReportFile(report_file);
 	
 	//set caching and archive mode 
@@ -1263,6 +1310,9 @@
 		fprintf(stderr," list file = <%s>\n",gr->listFile());
 		fprintf(stderr," command file = <%s>\n",gr->commandFile());
 		fprintf(stderr," putlog file = <%s>\n",gr->putlogFile());
+#ifdef ALLOW_CAPUTLOG
+		fprintf(stderr," caputlog address = <%s>\n",gr->caputlogAddress());
+#endif
 		fprintf(stderr," report file = <%s>\n",gr->reportFile());
 		fprintf(stderr," debug level = %d\n",gr->debugLevel());
 		fprintf(stderr," connect timeout = %ld\n",gr->connectTimeout());


Replies:
Re: [Merge] lp:~info-martin-konrad/epics-gateway/putlog into lp:epics-gateway Ralph Lange
Re: [Merge] lp:~info-martin-konrad/epics-gateway/putlog into lp:epics-gateway Martin Konrad

Navigate by Date:
Prev: Re: caPutLog support for gateway Andrew Johnson
Next: Build failed in Jenkins: epics-base-3.14-rtems #10 APS Jenkins
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017 
Navigate by Thread:
Prev: Jenkins build is back to normal : epics-base-3.15-win32s #4 APS Jenkins
Next: Re: [Merge] lp:~info-martin-konrad/epics-gateway/putlog into lp:epics-gateway Ralph Lange
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017 
ANJ, 19 May 2014 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·