From aa4869baeb0aa2c897247eb871b009e62fcfa5ad Mon Sep 17 00:00:00 2001
From: Ruud Overeem <overeem@astron.nl>
Date: Fri, 14 Feb 2014 09:31:04 +0000
Subject: [PATCH] Task #4804: Added some functions to the PVSS classes that are
 neccesary for the PVSSGateway. Fixed memory leak in the DPservice class.

---
 .gitattributes                                |  1 +
 .../PVSS/include/GCF/PVSS/GCF_PVDateTime.h    |  3 +-
 MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDouble.h  |  2 +-
 MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDynArr.h  |  3 ++
 MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVTypes.h   | 19 +++++++
 MAC/GCF/PVSS/include/GCF/PVSS/GCF_PValue.h    |  3 +-
 MAC/GCF/PVSS/src/CMakeLists.txt               |  1 +
 MAC/GCF/PVSS/src/GCF_PVDateTime.cc            |  9 ++++
 MAC/GCF/PVSS/src/GCF_PVTypes.cc               | 53 +++++++++++++++++++
 MAC/GCF/RTDB/src/DPservice.cc                 |  5 +-
 10 files changed, 95 insertions(+), 4 deletions(-)
 create mode 100644 MAC/GCF/PVSS/src/GCF_PVTypes.cc

diff --git a/.gitattributes b/.gitattributes
index 6a1a66ca4f7..e44a1fb2038 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -3174,6 +3174,7 @@ MAC/GCF/LogSys/KVLogSys/src/KVL_Protocol.prot -text svneol=native#application/oc
 MAC/GCF/LogSys/KVLogSys/src/KeyValueLoggerSys.conf.in -text svneol=native#application/octet-stream
 MAC/GCF/LogSys/KVLogSys/src/KeyValueLoggerSys.log_prop.in -text svneol=native#application/octet-stream
 MAC/GCF/PVSS/src/GCF_DynTypes.h -text
+MAC/GCF/PVSS/src/GCF_PVTypes.cc -text
 MAC/GCF/PVSS/test/tPVSSservice.dpl -text
 MAC/GCF/README -text svneol=native#application/octet-stream
 MAC/GCF/RTDB/include/GCF/RTDB/GCF_RTDBPort.h -text
diff --git a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDateTime.h b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDateTime.h
index e073f96830b..30480dd19d9 100644
--- a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDateTime.h
+++ b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDateTime.h
@@ -45,6 +45,7 @@ public:
 
 	/** Changes the value of this object */
 	virtual TGCFResult setValue(double newVal);
+	void 			   setValue(time_t newVal, uint16 milliSec = 0);
 
 	/** 
 	* Changes the value of this object by means of a stringbuffer, 
@@ -92,7 +93,7 @@ inline bool GCFPVDateTime::operator==(const GCFPValue&	that) const {
 			(getValue() == ((GCFPVDateTime *) &that)->getValue()));
 }
 
-  } // namespace Common
+  } // namespace PVS
  } // namespace GCF
 } // namespace LOFAR
 #endif
diff --git a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDouble.h b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDouble.h
index a502d226e20..a4fe7d5e58e 100644
--- a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDouble.h
+++ b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDouble.h
@@ -45,7 +45,7 @@ class GCFPVDouble : public GCFPValue
   	virtual ~GCFPVDouble () {;}
     
     /** Changes the value of this object */
-    void setValue ( const double newVal) {_value = newVal;};
+    void setValue (const double newVal) {_value = newVal;};
 
     /** 
      * Changes the value of this object by means of a stringbuffer, 
diff --git a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDynArr.h b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDynArr.h
index 05fbade3583..ccb0c3e731d 100644
--- a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDynArr.h
+++ b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVDynArr.h
@@ -79,6 +79,9 @@ class GCFPVDynArr : public GCFPValue
 
 	// add value to the dynarray
 	void push_back(GCFPValue*	newElem) { _values.push_back(newElem); }
+
+	// return number of elements
+	size_t count() const { return(_values.size()); }
  
   private:
     /// @see GCFPValue::unpack()
diff --git a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVTypes.h b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVTypes.h
index a64ba5ce442..c4b6808b27e 100644
--- a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVTypes.h
+++ b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PVTypes.h
@@ -34,4 +34,23 @@
 #include <GCF/PVSS/GCF_PVString.h>
 #include <GCF/PVSS/GCF_PVUnsigned.h>
 
+namespace LOFAR {
+  namespace GCF {
+	namespace PVSS {
+
+GCFPValue*	createPValue(const bool		someVal);
+GCFPValue*	createPValue(const char		someVal);
+GCFPValue*	createPValue(const uint		someVal);
+GCFPValue*	createPValue(const int		someVal);
+GCFPValue*	createPValue(const float	someVal);
+GCFPValue*	createPValue(const double	someVal);
+GCFPValue*	createPValue(const char*	someVal);
+GCFPValue*	createPValue(const string&	someVal);
+GCFPValue*	createPValue(const time_t	someVal);
+
+  } // namespace PVS
+ } // namespace GCF
+} // namespace LOFAR
+
+
 #endif
diff --git a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PValue.h b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PValue.h
index e5ef3519463..955e73dc1c7 100644
--- a/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PValue.h
+++ b/MAC/GCF/PVSS/include/GCF/PVSS/GCF_PValue.h
@@ -171,7 +171,8 @@ inline ostream& operator<< (ostream& os, const GCFPValue& gv)
 	return (os);
 }
 
-  } // namespace Common
+
+  } // namespace PVSS
  } // namespace GCF
 } // namespace LOFAR
 
diff --git a/MAC/GCF/PVSS/src/CMakeLists.txt b/MAC/GCF/PVSS/src/CMakeLists.txt
index deafcfd65fe..36ddeab61b1 100644
--- a/MAC/GCF/PVSS/src/CMakeLists.txt
+++ b/MAC/GCF/PVSS/src/CMakeLists.txt
@@ -21,6 +21,7 @@ lofar_add_library(gcfpvss
   GCF_PVUnsigned.cc
   GCF_PVDynArr.cc
   GCF_PVBlob.cc
+  GCF_PVTypes.cc
   GSA_SCADAHandler.cc
   GSA_PvssApi.cc
   GSA_Resources.cc
diff --git a/MAC/GCF/PVSS/src/GCF_PVDateTime.cc b/MAC/GCF/PVSS/src/GCF_PVDateTime.cc
index e62d1054672..a286ead47bd 100644
--- a/MAC/GCF/PVSS/src/GCF_PVDateTime.cc
+++ b/MAC/GCF/PVSS/src/GCF_PVDateTime.cc
@@ -89,6 +89,15 @@ TGCFResult GCFPVDateTime::setValue(double	newVal)
 	return (GCF_NO_ERROR);
 }
 
+//
+// setValue(time_t)
+//
+void GCFPVDateTime::setValue(time_t	newVal, uint16	milliSec)
+{
+	itsSeconds = newVal;
+	itsMilli   = milliSec % 1000;
+}
+
 
 //
 // setValue(string)
diff --git a/MAC/GCF/PVSS/src/GCF_PVTypes.cc b/MAC/GCF/PVSS/src/GCF_PVTypes.cc
new file mode 100644
index 00000000000..97ba0606b0b
--- /dev/null
+++ b/MAC/GCF/PVSS/src/GCF_PVTypes.cc
@@ -0,0 +1,53 @@
+//#  GCF_PVTypes.cc: 
+//#
+//#  Copyright (C) 2014
+//#  ASTRON (Netherlands Foundation for Research in Astronomy)
+//#  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//#
+//#  This program is free software; you can redistribute it and/or modify
+//#  it under the terms of the GNU General Public License as published by
+//#  the Free Software Foundation; either version 2 of the License, or
+//#  (at your option) any later version.
+//#
+//#  This program is distributed in the hope that it will be useful,
+//#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//#  GNU General Public License for more details.
+//#
+//#  You should have received a copy of the GNU General Public License
+//#  along with this program; if not, write to the Free Software
+//#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//#
+//#  $Id: GCF_PVString.cc 22948 2012-11-23 08:54:47Z loose $
+
+
+#include <lofar_config.h>
+
+#include <GCF/PVSS/GCF_PVTypes.h>
+#include <GCF/PVSS/GCF_Defines.h>
+
+namespace LOFAR {
+ namespace GCF {
+  namespace PVSS {
+
+#define CREATE_AND_INIT_PVALUE(type, className, value) \
+{ \
+	GCFPValue* p = GCFPValue::createMACTypeObject(type); \
+	ASSERTSTR(p, "Creation of object of type " << type << " failed"); \
+	((className*)p)->setValue(value); \
+	return (p); \
+}
+		
+GCFPValue*	createPValue(const bool		someVal) CREATE_AND_INIT_PVALUE(LPT_BOOL, 	  GCFPVBool,	someVal)
+GCFPValue*	createPValue(const char		someVal) CREATE_AND_INIT_PVALUE(LPT_CHAR, 	  GCFPVChar,	someVal)
+GCFPValue*	createPValue(const uint		someVal) CREATE_AND_INIT_PVALUE(LPT_UNSIGNED, GCFPVUnsigned,someVal)
+GCFPValue*	createPValue(const int		someVal) CREATE_AND_INIT_PVALUE(LPT_INTEGER,  GCFPVInteger,	someVal)
+GCFPValue*	createPValue(const float	someVal) CREATE_AND_INIT_PVALUE(LPT_DOUBLE,	  GCFPVDouble,	someVal)
+GCFPValue*	createPValue(const double	someVal) CREATE_AND_INIT_PVALUE(LPT_DOUBLE,	  GCFPVDouble,	someVal)
+GCFPValue*	createPValue(const char*	someVal) CREATE_AND_INIT_PVALUE(LPT_STRING,	  GCFPVString,	someVal)
+GCFPValue*	createPValue(const string&	someVal) CREATE_AND_INIT_PVALUE(LPT_STRING,	  GCFPVString,	someVal)
+GCFPValue*	createPValue(const time_t	someVal) CREATE_AND_INIT_PVALUE(LPT_DATETIME, GCFPVDateTime,someVal)
+
+  } // namespace Common
+ } // namespace GCF
+} // namespace LOFAR
diff --git a/MAC/GCF/RTDB/src/DPservice.cc b/MAC/GCF/RTDB/src/DPservice.cc
index 224a5bee154..529b86739e7 100644
--- a/MAC/GCF/RTDB/src/DPservice.cc
+++ b/MAC/GCF/RTDB/src/DPservice.cc
@@ -94,6 +94,7 @@ PVSSresult DPservice::setValue (const string&		DPname,
 	// write value to it.
 	if (valueObj->setValue(value) != GCF_NO_ERROR) {
 		LOG_WARN_STR("Could not set value for DP " << DPname);
+		delete valueObj;
 		if (wantAnswer) {
 			itsExtResponse->dpeValueSet(DPname, SA_SETPROP_FAILED);
 		}
@@ -101,7 +102,9 @@ PVSSresult DPservice::setValue (const string&		DPname,
 	}
 
 	// finally write value to the database.
-	return (itsService->dpeSet(DPname, *valueObj, timestamp, wantAnswer));
+	PVSSresult	result = itsService->dpeSet(DPname, *valueObj, timestamp, wantAnswer);
+	delete valueObj;
+	return (result);
 }
 
 PVSSresult DPservice::setValue (const string&		DPname, 
-- 
GitLab