From 9b076da055b044a4aadec53fda66c877db6172cb Mon Sep 17 00:00:00 2001
From: Ruud Overeem <overeem@astron.nl>
Date: Mon, 4 Jun 2007 10:00:39 +0000
Subject: [PATCH] BugID: 1000 Added optional third argument to init function of
 GCFTask allowing us to pass the name of the log file we want to use.

---
 MAC/GCF/TM/include/GCF/TM/GCF_Fsm.h       |  2 +-
 MAC/GCF/TM/include/GCF/TM/GCF_Task.h      |  5 ++--
 MAC/GCF/TM/src/GCF_Task.cc                | 29 ++++++++++-------------
 MAC/GCF/TM/src/Port/GCF_RawPort.cc        |  4 ++--
 MAC/GCF/TM/src/PortImpl/GCF_DevicePort.cc |  2 +-
 MAC/GCF/TM/src/PortImpl/GCF_ETHRawPort.cc |  2 +-
 MAC/GCF/TM/src/PortImpl/GCF_TCPPort.cc    |  2 +-
 7 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/MAC/GCF/TM/include/GCF/TM/GCF_Fsm.h b/MAC/GCF/TM/include/GCF/TM/GCF_Fsm.h
index 8fb956b3353..cda6f7792c5 100644
--- a/MAC/GCF/TM/include/GCF/TM/GCF_Fsm.h
+++ b/MAC/GCF/TM/include/GCF/TM/GCF_Fsm.h
@@ -85,7 +85,7 @@ class GCFDummyPort : public GCFPortInterface
     int cancelAllTimers ()
     {	return (0);	}
 
-	double timeLeft(long	timerID)
+	double timeLeft(long	/*timerID*/)
     {	return (0);	}
   
   private:
diff --git a/MAC/GCF/TM/include/GCF/TM/GCF_Task.h b/MAC/GCF/TM/include/GCF/TM/GCF_Task.h
index 58c3b790fc1..f50f39f997f 100644
--- a/MAC/GCF/TM/include/GCF/TM/GCF_Task.h
+++ b/MAC/GCF/TM/include/GCF/TM/GCF_Task.h
@@ -68,7 +68,7 @@ class GCFTask : public GCFFsm
      * - lofar logger("mac.log_prop")
      * - parameterset(argv[0] + ".conf")
      */     
-    static void init (int argc, char** argv);
+    static void init (int argc, char** argv, const string&	logfile = "");
     
     /**
     * The static run method. This starts the event processing loop.
@@ -112,8 +112,7 @@ class GCFTask : public GCFFsm
     void setName (string& name) {_name = name;}
 
     /// returns the "define" of a signal ID as a string    
-    const char* evtstr(const GCFEvent& e) const;
-    string eventstr(const GCFEvent& e) const;
+    string evtstr(const GCFEvent& e) const;
 
   protected:
     /**
diff --git a/MAC/GCF/TM/src/GCF_Task.cc b/MAC/GCF/TM/src/GCF_Task.cc
index 0d2dd4a78fb..aea43a683d1 100644
--- a/MAC/GCF/TM/src/GCF_Task.cc
+++ b/MAC/GCF/TM/src/GCF_Task.cc
@@ -72,7 +72,7 @@ GCFTask::~GCFTask()
 {
 }
 
-void GCFTask::init(int argc, char** argv)
+void GCFTask::init(int argc, char** argv, const string&	logfile)
 {
 	_argc = argc;
 	_argv = argv;
@@ -87,8 +87,15 @@ void GCFTask::init(int argc, char** argv)
 		// locator could not find it try defaultname
 		logPropFile = "mac.log_prop";
 	}
-	INIT_LOGGER(aCL.locate(logPropFile).c_str());   
-	LOG_DEBUG_STR ("Initialized logsystem with: " << aCL.locate(logPropFile));
+	if (logfile.empty()) {
+		INIT_LOGGER(aCL.locate(logPropFile).c_str());   
+		LOG_DEBUG_STR ("Initialized logsystem with: " << aCL.locate(logPropFile));
+	}
+	else {
+		INIT_VAR_LOGGER(aCL.locate(logPropFile).c_str(), logfile);   
+		LOG_DEBUG_STR ("Initialized logsystem with: " << aCL.locate(logPropFile) <<
+						"," << logfile);
+	}
 
 	// Read in the ParameterSet of the task (<task>.conf)
 	ParameterSet*	pParamSet = ACC::APS::globalParameterSet();
@@ -194,22 +201,10 @@ void GCFTask::registerProtocol(unsigned short protocolID,
   _protocols[protocolID] = signal_names;
 }
 
-const char* GCFTask::evtstr(const GCFEvent& e)  const
-{
-  static const char* unknown = "unknown signal";
-  const char* signame(0);
-  TProtocols::const_iterator iter = _protocols.find(F_EVT_PROTOCOL(e));
-  if (iter != _protocols.end())
-  {
-    signame = (iter->second)[F_EVT_SIGNAL(e)];
-  }
-  return (signame?signame:unknown);
-}
-
 //
-// eventstr(event&)
+// evtstr(event&)
 //
-string GCFTask::eventstr(const GCFEvent& e)  const
+string GCFTask::evtstr(const GCFEvent& e)  const
 {
 	TProtocols::const_iterator iter = _protocols.find(F_EVT_PROTOCOL(e));
 	if (iter != _protocols.end()) {
diff --git a/MAC/GCF/TM/src/Port/GCF_RawPort.cc b/MAC/GCF/TM/src/Port/GCF_RawPort.cc
index dbcaf656d7b..5ac56f8bc71 100644
--- a/MAC/GCF/TM/src/Port/GCF_RawPort.cc
+++ b/MAC/GCF/TM/src/Port/GCF_RawPort.cc
@@ -105,7 +105,7 @@ GCFEvent::TResult GCFRawPort::dispatch(GCFEvent& event)
 						  (F_EVT_PROTOCOL(event) != F_PORT_PROTOCOL)) {
 		// Inform about the fact of an incomming message
 		LOG_DEBUG(formatString ("%s was received on port '%s' in task '%s'",
-								_pTask->evtstr(event), 
+								_pTask->evtstr(event).c_str(), 
 								getRealName().c_str(), 
 								_pTask->getName().c_str())); 
 	}
@@ -347,7 +347,7 @@ GCFEvent::TResult GCFRawPort::recvEvent()
 		ASSERT(getTask());
 		LOG_DEBUG(formatString (
 			"'%s' for port '%s' in task '%s' not handled or an error occured",
-			getTask()->evtstr(e), getRealName().c_str(),
+			getTask()->evtstr(e).c_str(), getRealName().c_str(),
 			getTask()->getName().c_str()));
 	}
 
diff --git a/MAC/GCF/TM/src/PortImpl/GCF_DevicePort.cc b/MAC/GCF/TM/src/PortImpl/GCF_DevicePort.cc
index 8ebd38adc16..70e53d8044c 100644
--- a/MAC/GCF/TM/src/PortImpl/GCF_DevicePort.cc
+++ b/MAC/GCF/TM/src/PortImpl/GCF_DevicePort.cc
@@ -163,7 +163,7 @@ ssize_t GCFDevicePort::send(GCFEvent& e)
 
   LOG_DEBUG(formatString (
       "Sending event '%s' for task '%s' on port '%s'",
-      getTask()->evtstr(e),
+      getTask()->evtstr(e).c_str(),
       getTask()->getName().c_str(), 
       getRealName().c_str()));
 
diff --git a/MAC/GCF/TM/src/PortImpl/GCF_ETHRawPort.cc b/MAC/GCF/TM/src/PortImpl/GCF_ETHRawPort.cc
index 75f123443fa..cadb2c8cef0 100644
--- a/MAC/GCF/TM/src/PortImpl/GCF_ETHRawPort.cc
+++ b/MAC/GCF/TM/src/PortImpl/GCF_ETHRawPort.cc
@@ -193,7 +193,7 @@ ssize_t GCFETHRawPort::send(GCFEvent& e)
 
   LOG_DEBUG(formatString (
       "Sending event '%s' for task '%s' on port '%s'",
-      getTask()->evtstr(e),
+      getTask()->evtstr(e).c_str(),
       getTask()->getName().c_str(), 
       getRealName().c_str()));
 
diff --git a/MAC/GCF/TM/src/PortImpl/GCF_TCPPort.cc b/MAC/GCF/TM/src/PortImpl/GCF_TCPPort.cc
index 7e6d5be5af4..8247b790030 100644
--- a/MAC/GCF/TM/src/PortImpl/GCF_TCPPort.cc
+++ b/MAC/GCF/TM/src/PortImpl/GCF_TCPPort.cc
@@ -316,7 +316,7 @@ ssize_t GCFTCPPort::send(GCFEvent& e)
 
 	LOG_TRACE_STAT(formatString (
 						"Sending event '%s' for task '%s' on port '%s'",
-						getTask()->evtstr(e), getTask()->getName().c_str(), 
+						getTask()->evtstr(e).c_str(), getTask()->getName().c_str(), 
 						getRealName().c_str()));
 
 	if ((written = _pSocket->send(buf, packsize)) != (ssize_t) packsize) {  
-- 
GitLab