From 13e70b6635f1cff822b2b4ed17229b1864e66af8 Mon Sep 17 00:00:00 2001
From: Marco De Marco <demarco@oats.inaf.it>
Date: Thu, 13 Nov 2014 11:24:22 +0100
Subject: [PATCH] Before ignore timeout property removed

---
 script/fits.sh                   | 104 -------------------
 script/script_template.sh        | 107 ++++++++++++++++++++
 src/Configuration.h              |  41 +++++---
 src/EventThread.cpp              |  14 ---
 src/PreProcessor.cpp             | 168 +++++++++++++++++++++++--------
 src/PreProcessor.h               |  27 ++++-
 src/PreProcessor.xmi             |  25 ++++-
 src/PreProcessorClass.cpp        | 100 ++++++++++++++----
 src/PreProcessorClass.h          |  13 +++
 src/PreProcessorStateMachine.cpp |  36 +++++--
 src/ScriptManager.cpp            | 101 ++++++++++++++++---
 src/ScriptManager.h              |  23 +++--
 src/WorkerThread.cpp             | 128 ++++++++++++++---------
 src/WorkerThread.h               |   8 +-
 14 files changed, 623 insertions(+), 272 deletions(-)
 delete mode 100755 script/fits.sh
 create mode 100755 script/script_template.sh

diff --git a/script/fits.sh b/script/fits.sh
deleted file mode 100755
index 0f8c354..0000000
--- a/script/fits.sh
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/bin/bash
-
-#: Title	: fits.sh
-#: Date		: 2014/03/03
-#: Author	: "Marco De Marco" <demarco@oats.inaf.it>
-#: Version	: 0.1
-#: Description	: Fits verification and preproccessing script
-#: Usage 	: 
-#: Response	: 
-
-
-if [ "$1" == "CHECK" ]; then
-
-	#: Section	: CHECK
-	#: Parameter	: none
-	#: Response	: CHECK OK
-	#: 		: CHECK FATAL
-
-	VERIFY_TOOL="/usr/local/bin/fitsverify"
-	CHECK_STRING="conform to the FITS format"
-
-	res=$($VERIFY_TOOL 2>&1)
-	check=$(echo $res | grep "$CHECK_STRING" | wc | awk '{print $1}')
-	if [ "$check" -ge "1" ]; then
-		echo "CHECK OK"
-	else
-		echo "CHECK FATAL"
-	fi
-	exit 0
-
-elif [ "$1" == "VERIFY" ]; then
-
-	#: Section	: VERIFY
-	#: Parameter	: file path 
-	#: Response	: VERIFY OK
-	#: 		: VERIFY WAIT
-	#: 		: VERIFY FATAL
-
-	VERIFY_TOOL="/usr/local/bin/fitsverify"
-	FATAL_ERROR="Fatal"
-	EOF_ERROR="End-of-file"
-
-	file=$2
-	file_name=${file##*/}
-
-	#Check regular expression -> fatal
-	if [[ ! "${file_name,,}" =~ ^[^\.].*\.(fits|fit|fts).*$ ]]; then
-		echo "VERIFY FATAL : error on regular expression"
-		exit 0
-	fi
-
-	#if fits verify tools exists -> fatal
-	if [ ! -x $VERIFY_TOOL ]; then
-		echo "VERIFY FATAL : verify tools not exists"
-		exit 0
-	fi
-
-	#if fits file not exists -> fatal
-	if [ ! -f $file ]; then
-		echo "VERIFY FATAL : file not exists"
-		exit 0
-	fi
-
-	#Check with fits verify
-	res=$($VERIFY_TOOL $file 2>&1)
-
-	#if fitsverify return fatal error -> wait
-	fatal=$(echo $res | grep "$FATAL_ERROR" | wc | awk '{print $1}')
-	if [ "$fatal" -ge "1" ]; then
-		echo "VERIFY WAIT"
-		exit 0
-	fi
-
-	#if fitsverify return end of file -> wait
-	eof=$(echo $res | grep "$EOF_ERROR" | wc | awk '{print $1}')
-	if [ "$eof" -ge "1" ]; then
-		echo "VERIFY WAIT"
-		exit 0
-	fi
-
-	#else -> ok
-	echo "VERIFY OK"
-	exit 0
-
-elif [ "$1" == "PROCESS" ]; then
-
-	#: Section	: PROCESS 
-	#: Parameter	: file path 
-	#: Response	: PROCESS OK
-	#: 		: PROCESS FATAL
-
-	echo "PROCESS OK"
-	exit 0
-
-else
-
-	#: Section	: DEFAULT
-	#: Parameter	: none
-	#: Response	: UNKNOWN
-
-	echo "UNKNOWN"
-	exit 0
-
-fi
diff --git a/script/script_template.sh b/script/script_template.sh
new file mode 100755
index 0000000..a042149
--- /dev/null
+++ b/script/script_template.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+
+#: Title	: checkfits.sh
+#: Date		: 2014/10/28
+#: Author	: "Marco De Marco" <demarco@oats.inaf.it>
+#: Version	: 1.0
+#: Description	: Fits verification and preproccessing script
+
+
+if [ "$1" == "CHECK" ]; then
+
+	#: Section	: CHECK
+	#: Parameter	: none
+	#: Response	: CHECK OK
+	#: 		: CHECK FATAL
+	#: Description	: Check availability of script tools
+
+	echo "CHECK OK"
+	exit 0
+
+elif [ "$1" == "VALID" ]; then
+
+	#: Section	: VALID
+	#: Parameter	: file path
+	#: Response	: VALID OK
+	#: 		: VALID IGNORE
+	#: Description	: Check file name compliance
+
+	echo "VALID OK"
+	exit 0
+
+elif [ "$1" == "VERIFY" ]; then
+
+	#: Section	: VERIFY
+	#: Parameter	: file path
+	#: Response	: VERIFY OK
+	#: 		: VERIFY WAIT
+	#: 		: VERIFY FATAL
+	#: Description	: Check file compliance to fits format
+
+	file=$2
+
+	echo "VERIFY OK"
+	exit 0
+
+elif [ "$1" == "PREPROCESS" ]; then
+
+	#: Section	: PREPROCESS
+	#: Parameter	: file path
+	#: 		: ingestion result [OK, WAIT, FATAL]
+	#: Response	: PREPROCESS OK
+	#: 		: PREPROCESS FATAL
+	#: Description	: Apply preprocessing before ingestion
+
+	file=$2
+	verified=$3
+
+	#Check verified parameter value
+	if [ "$verified" != "OK" -a "$verified" != "WAIT" -a "$verified" != "FATAL" ]; then
+		echo "PREPROCESS FATAL"
+		exit 0
+	fi
+
+	echo "PREPROCESS OK"
+	exit 0
+
+elif [ "$1" == "POSTPROCESS" ]; then
+
+	#: Section	: POSTPROCESS
+	#: Parameter	: file path
+	#: 		: ingestion result [OK, WAIT, FATAL]
+	#: Response	: POSTPROCESS OK
+	#: 		: POSTPROCESS FATAL
+	#: Description	: Apply postprocessing after ingestion
+
+	file=$2
+	verified=$3
+
+	#Check verified parameter value
+	if [ "$verified" != "OK" -a "$verified" != "WAIT" -a "$verified" != "FATAL" ]; then
+		echo "POSTPROCESS FATAL"
+		exit 0
+	fi
+
+	#Post process verified WAIT files
+	#if [ "$verified" == "WAIT" ]; then
+
+	#fi
+
+	#Post process verified FATAL files
+	#if [ "$verified" == "FATAL" ]; then
+
+	#fi
+
+	echo "POSTPROCESS OK"
+	exit 0
+
+else
+
+	#: Section	: DEFAULT
+	#: Parameter	: none
+	#: Response	: UNKNOWN
+
+	echo "UNKNOWN"
+	exit 0
+
+fi
diff --git a/src/Configuration.h b/src/Configuration.h
index 5d70bba..52f9cd1 100644
--- a/src/Configuration.h
+++ b/src/Configuration.h
@@ -21,12 +21,14 @@ private:
 //------------------------------------------------------------------------------
 //	[Private] Constructor destructor deleter
 //------------------------------------------------------------------------------
-	Configuration(std::string watchPath, std::string destPath,
-        std::string scriptPath, int workerNumber, int sleepTime, int waitTime,
-        uint32_t iNotifyMask) : m_watchPath(watchPath), m_destPath(destPath),
+	Configuration(std::string watchPath, std::string regularPath,
+		std::string warningPath, std::string errorPath, std::string scriptPath,
+		int workerNumber, int sleepTime, int waitTime, uint32_t iNotifyMask,
+        bool ignoreTimeout) : m_watchPath(watchPath), m_regularPath(regularPath),
+        m_warningPath(warningPath), m_errorPath(errorPath),
         m_scriptPath(scriptPath), m_workerNumber(workerNumber),
         m_sleepTime(sleepTime), m_waitTime(waitTime),
-        m_iNotifyMask(iNotifyMask) { }
+        m_iNotifyMask(iNotifyMask), m_ignoreTimeout(ignoreTimeout) { }
 
 	virtual ~Configuration() {}
 
@@ -42,24 +44,28 @@ public:
 //------------------------------------------------------------------------------
 //	[Public] User methods
 //------------------------------------------------------------------------------
-	static Configuration::SP create(std::string watchPath, std::string destPath,
+	static Configuration::SP create(std::string watchPath,
+		std::string regularPath, std::string warningPath, std::string errorPath,
         std::string scriptPath, int workerNumber, int sleepTime, int waitTime,
-        uint32_t iNotifyMask)
+        uint32_t iNotifyMask, bool ignoreTimeout)
 	{
-		Configuration::SP c_sp(new Configuration(watchPath, destPath, scriptPath,
-             workerNumber, sleepTime, waitTime, iNotifyMask),
-             Configuration::Deleter());
+		Configuration::SP c_sp(new Configuration(watchPath, regularPath,
+			warningPath, errorPath, scriptPath, workerNumber, sleepTime,
+			waitTime, iNotifyMask, ignoreTimeout), Configuration::Deleter());
 
 		return c_sp;
 	}
-    
+
 	std::string getWatchPath() const { return m_watchPath; }
-    std::string getDestPath() const { return m_destPath; }
+	std::string getRegularPath() const { return m_regularPath; }
+	std::string getWarningPath() const { return m_warningPath; }
+	std::string getErrorPath() const { return m_errorPath; }
     std::string getScriptPath() const { return m_scriptPath; }
 	unsigned int getWorkerNumber() const { return m_workerNumber; }
     unsigned int getSleepTime() const { return m_sleepTime; }
 	unsigned int getWaitTime() const { return m_waitTime; }
 	uint32_t getINotifyMask() const { return m_iNotifyMask; }
+	bool getIgnoreTimeout() const { return m_ignoreTimeout; }
 
 private:
 //------------------------------------------------------------------------------
@@ -68,8 +74,14 @@ private:
 	//INotify watch path
 	const std::string m_watchPath;
 
-    //File destination path
-    const std::string m_destPath;
+    //Regular file destination path
+    const std::string m_regularPath;
+
+	//Warning file destination path
+	const std::string m_warningPath;
+
+	//Error file destination path
+	const std::string m_errorPath;
 
     //Script path file
     const std::string m_scriptPath;
@@ -85,6 +97,9 @@ private:
 
 	//INotify mask
 	const uint32_t m_iNotifyMask;
+
+	//Ignore timeout
+	const bool m_ignoreTimeout;
 };
 
 }   //End of namespace
diff --git a/src/EventThread.cpp b/src/EventThread.cpp
index 7e3e653..b1f0d55 100644
--- a/src/EventThread.cpp
+++ b/src/EventThread.cpp
@@ -173,20 +173,6 @@ void EventThread::initEventBuffer() throw(std::runtime_error)
     if(!boost::filesystem::is_directory(path))
         throw std::runtime_error("Watch path \"" +
             watchPath + "\" is not a valid directory");
-
-    /*
-    //All files in watch path are inserted into event buffer
-    boost::filesystem::directory_iterator startIt(path);
-    boost::filesystem::directory_iterator endIt;
-
-    while(startIt != endIt)
-    {
-        if(boost::filesystem::is_regular_file(startIt->status()))
-            m_eventBuffer_sp->insertNew(startIt->path());
-
-        startIt++;
-    }
-    */
 }
 
 //==============================================================================
diff --git a/src/PreProcessor.cpp b/src/PreProcessor.cpp
index 6cfbe42..07fc4ea 100644
--- a/src/PreProcessor.cpp
+++ b/src/PreProcessor.cpp
@@ -65,6 +65,7 @@
 //================================================================
 //  Attributes managed are:
 //================================================================
+//  IgnoredFileCounter  |  Tango::DevULong	Scalar
 //  RegularFileCounter  |  Tango::DevULong	Scalar
 //  WarningFileCounter  |  Tango::DevULong	Scalar
 //  ErrorFileCounter    |  Tango::DevULong	Scalar
@@ -126,6 +127,7 @@ void PreProcessor::delete_device()
 	//	Delete device allocated objects
 
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::delete_device
+	delete[] attr_IgnoredFileCounter_read;
 	delete[] attr_RegularFileCounter_read;
 	delete[] attr_WarningFileCounter_read;
 	delete[] attr_ErrorFileCounter_read;
@@ -151,12 +153,16 @@ void PreProcessor::init_device()
 	//	Get the device properties from database
 	get_device_property();
 
+	attr_IgnoredFileCounter_read = new Tango::DevULong[1];
 	attr_RegularFileCounter_read = new Tango::DevULong[1];
 	attr_WarningFileCounter_read = new Tango::DevULong[1];
 	attr_ErrorFileCounter_read = new Tango::DevULong[1];
 
 	/*----- PROTECTED REGION ID(PreProcessor::init_device) ENABLED START -----*/
 
+	//Initialize ignored file counters to zero
+	*attr_IgnoredFileCounter_read = 0;
+
     //Initialize regular file counters to zero
 	*attr_RegularFileCounter_read = 0;
 
@@ -170,27 +176,27 @@ void PreProcessor::init_device()
     {
         try
         {
-                //Create event thread
-                m_eventThread_sp = EventThread::create(this, m_configuration_sp);
-
-                //Start device if auto start enabled
-                if(autoStart)
-                {
-                    INFO_STREAM << "PreProcessor::init_device() auto start enabled " << endl;
-                    on();
-                }
+			//Create event thread
+			m_eventThread_sp = EventThread::create(this, m_configuration_sp);
+
+			//Start device if auto start enabled
+			if(autoStart)
+			{
+				INFO_STREAM << "PreProcessor::init_device() auto start enabled " << endl;
+				on();
+			}
         }
         catch(std::exception& ex)
         {
-            set_state(Tango::FAULT);
-            std::stringstream error_stream;
-            error_stream << "PreProcessor::init_device() " << ex.what() << std::endl;
-            set_status(error_stream.str());
+			set_state(Tango::FAULT);
+			std::stringstream error_stream;
+			error_stream << "PreProcessor::init_device() " << ex.what() << std::endl;
+			set_status(error_stream.str());
         }
         catch(...)
         {
-            set_state(Tango::FAULT);
-            set_status("PreProcessor::init_device() unknown error");
+			set_state(Tango::FAULT);
+			set_status("PreProcessor::init_device() unknown error");
         }
     }
 
@@ -215,14 +221,18 @@ void PreProcessor::get_device_property()
 	//	Read device properties from database.
 	Tango::DbData	dev_prop;
 	dev_prop.push_back(Tango::DbDatum("WatchPath"));
-	dev_prop.push_back(Tango::DbDatum("DestPath"));
+	dev_prop.push_back(Tango::DbDatum("RegularPath"));
+	dev_prop.push_back(Tango::DbDatum("WarningPath"));
+	dev_prop.push_back(Tango::DbDatum("ErrorPath"));
 	dev_prop.push_back(Tango::DbDatum("ScriptPath"));
 	dev_prop.push_back(Tango::DbDatum("EventList"));
 	dev_prop.push_back(Tango::DbDatum("SleepTime"));
 	dev_prop.push_back(Tango::DbDatum("WaitTime"));
 	dev_prop.push_back(Tango::DbDatum("WorkerNumber"));
+	dev_prop.push_back(Tango::DbDatum("IgnoreTimeout"));
 	dev_prop.push_back(Tango::DbDatum("AutoStart"));
 
+
 	//	is there at least one property to be read ?
 	if (dev_prop.size()>0)
 	{
@@ -247,16 +257,38 @@ void PreProcessor::get_device_property()
 		//	And try to extract WatchPath value from database
 		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  watchPath;
 
-		//	Try to initialize DestPath from class property
+		//	Try to initialize RegularPath from class property
+		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
+		if (cl_prop.is_empty()==false)	cl_prop  >>  regularPath;
+		else {
+			//	Try to initialize RegularPath from default device value
+			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
+			if (def_prop.is_empty()==false)	def_prop  >>  regularPath;
+		}
+		//	And try to extract RegularPath value from database
+		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  regularPath;
+
+		//	Try to initialize WarningPath from class property
 		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
-		if (cl_prop.is_empty()==false)	cl_prop  >>  destPath;
+		if (cl_prop.is_empty()==false)	cl_prop  >>  warningPath;
 		else {
-			//	Try to initialize DestPath from default device value
+			//	Try to initialize WarningPath from default device value
 			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
-			if (def_prop.is_empty()==false)	def_prop  >>  destPath;
+			if (def_prop.is_empty()==false)	def_prop  >>  warningPath;
 		}
-		//	And try to extract DestPath value from database
-		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  destPath;
+		//	And try to extract WarningPath value from database
+		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  warningPath;
+
+		//	Try to initialize ErrorPath from class property
+		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
+		if (cl_prop.is_empty()==false)	cl_prop  >>  errorPath;
+		else {
+			//	Try to initialize ErrorPath from default device value
+			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
+			if (def_prop.is_empty()==false)	def_prop  >>  errorPath;
+		}
+		//	And try to extract ErrorPath value from database
+		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  errorPath;
 
 		//	Try to initialize ScriptPath from class property
 		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
@@ -313,6 +345,17 @@ void PreProcessor::get_device_property()
 		//	And try to extract WorkerNumber value from database
 		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  workerNumber;
 
+		//	Try to initialize IgnoreTimeout from class property
+		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
+		if (cl_prop.is_empty()==false)	cl_prop  >>  ignoreTimeout;
+		else {
+			//	Try to initialize IgnoreTimeout from default device value
+			def_prop = ds_class->get_default_device_property(dev_prop[i].name);
+			if (def_prop.is_empty()==false)	def_prop  >>  ignoreTimeout;
+		}
+		//	And try to extract IgnoreTimeout value from database
+		if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  ignoreTimeout;
+
 		//	Try to initialize AutoStart from class property
 		cl_prop = ds_class->get_class_property(dev_prop[++i].name);
 		if (cl_prop.is_empty()==false)	cl_prop  >>  autoStart;
@@ -335,10 +378,16 @@ void PreProcessor::get_device_property()
 
         checkIfDirectoryExists(watchPath);
 
-        if(destPath.empty())
-            throw(invalid_argument("DestPath property is empty or not defined"));
+		if(regularPath.empty())
+            throw(invalid_argument("Regular property is empty or not defined"));
+
+		checkIfDirectoryExists(regularPath);
+
+		if(!warningPath.empty())
+			checkIfDirectoryExists(warningPath);
 
-        checkIfDirectoryExists(destPath);
+		if(!errorPath.empty())
+			checkIfDirectoryExists(errorPath);
 
         if(scriptPath.empty())
             throw(invalid_argument("ScriptPath property is empty or not defined"));
@@ -368,8 +417,8 @@ void PreProcessor::get_device_property()
         if(workerNumber<1 || workerNumber>MAX_WORKER_NUMBER)
             throw(invalid_argument("WorkerNumber property out of range or not defined"));
 
-        m_configuration_sp = Configuration::create(watchPath, destPath, scriptPath,
-            workerNumber, sleepTime, waitTime, inotifyMask);
+        m_configuration_sp = Configuration::create(watchPath, regularPath, warningPath,
+			errorPath, scriptPath, workerNumber, sleepTime, waitTime, inotifyMask, ignoreTimeout);
     }
     catch(invalid_argument& ex)
     {
@@ -390,7 +439,7 @@ void PreProcessor::get_device_property()
 //--------------------------------------------------------
 void PreProcessor::always_executed_hook()
 {
-	DEBUG_STREAM << "PreProcessor::always_executed_hook()  " << device_name << endl;
+	INFO_STREAM << "PreProcessor::always_executed_hook()  " << device_name << endl;
 	/*----- PROTECTED REGION ID(PreProcessor::always_executed_hook) ENABLED START -----*/
 
 	if(get_state() != Tango::FAULT)
@@ -422,6 +471,26 @@ void PreProcessor::read_attr_hardware(TANGO_UNUSED(vector<long> &attr_list))
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::read_attr_hardware
 }
 
+//--------------------------------------------------------
+/**
+ *	Read attribute IgnoredFileCounter related method
+ *	Description:
+ *
+ *	Data type:	Tango::DevULong
+ *	Attr type:	Scalar
+ */
+//--------------------------------------------------------
+void PreProcessor::read_IgnoredFileCounter(Tango::Attribute &attr)
+{
+	DEBUG_STREAM << "PreProcessor::read_IgnoredFileCounter(Tango::Attribute &attr) entering... " << endl;
+	/*----- PROTECTED REGION ID(PreProcessor::read_IgnoredFileCounter) ENABLED START -----*/
+
+	boost::mutex::scoped_lock ignoredCounterLock(m_ignoredCounterMutex);
+
+	attr.set_value(attr_IgnoredFileCounter_read);
+
+	/*----- PROTECTED REGION END -----*/	//	PreProcessor::read_IgnoredFileCounter
+}
 //--------------------------------------------------------
 /**
  *	Read attribute RegularFileCounter related method
@@ -578,6 +647,11 @@ void PreProcessor::reset_counter()
 	DEBUG_STREAM << "PreProcessor::ResetCounter()  - " << device_name << endl;
 	/*----- PROTECTED REGION ID(PreProcessor::reset_counter) ENABLED START -----*/
 
+	//Reset ignored file counter
+	boost::mutex::scoped_lock ignoredCounterLock(m_ignoredCounterMutex);
+
+	*attr_IgnoredFileCounter_read = 0;
+
     //Reset regular file counter
     boost::mutex::scoped_lock regularCounterLock(m_regularCounterMutex);
 
@@ -596,44 +670,56 @@ void PreProcessor::reset_counter()
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::reset_counter
 }
 
+/*----- PROTECTED REGION ID(PreProcessor::namespace_ending) ENABLED START -----*/
+
+//==============================================================================
+//     PreProcessor::incrementRegularCounter()
+//==============================================================================
+void PreProcessor::incrementIgnoredCounter()
+{
+	DEBUG_STREAM << "PreProcessor::incrementIgnoredCounter()  - " << device_name << endl;
+
+	boost::mutex::scoped_lock ignoredCounterLock(m_ignoredCounterMutex);
+
+	++*attr_IgnoredFileCounter_read;
+}
+
 //==============================================================================
-//	PreProcessor::incrementRegularCounter()
+//     PreProcessor::incrementRegularCounter()
 //==============================================================================
 void PreProcessor::incrementRegularCounter()
 {
-    DEBUG_STREAM << "PreProcessor::incrementRegularCounter()  - " << device_name << endl;
+	DEBUG_STREAM << "PreProcessor::incrementRegularCounter()  - " << device_name << endl;
 
-    boost::mutex::scoped_lock regularCounterLock(m_regularCounterMutex);
+	boost::mutex::scoped_lock regularCounterLock(m_regularCounterMutex);
 
 	++*attr_RegularFileCounter_read;
 }
 
 //==============================================================================
-//	PreProcessor::incrementWarningCounter()
+//     PreProcessor::incrementWarningCounter()
 //==============================================================================
 void PreProcessor::incrementWarningCounter()
 {
-    DEBUG_STREAM << "PreProcessor::incrementWarningCounter()  - " << device_name << endl;
+		DEBUG_STREAM << "PreProcessor::incrementWarningCounter()  - " << device_name << endl;
 
-    boost::mutex::scoped_lock warningCounterLock(m_warningCounterMutex);
+		boost::mutex::scoped_lock warningCounterLock(m_warningCounterMutex);
 
-    ++*attr_WarningFileCounter_read;
+		++*attr_WarningFileCounter_read;
 }
 
 //==============================================================================
-//	PreProcessor::incrementErrorCounter()
+//     PreProcessor::incrementErrorCounter()
 //==============================================================================
 void PreProcessor::incrementErrorCounter()
 {
-    DEBUG_STREAM << "PreProcessor::incrementErrorCounter()  - " << device_name << endl;
+		DEBUG_STREAM << "PreProcessor::incrementErrorCounter()  - " << device_name << endl;
 
-    boost::mutex::scoped_lock errorCounterLock(m_errorCounterMutex);
+		boost::mutex::scoped_lock errorCounterLock(m_errorCounterMutex);
 
-    ++*attr_ErrorFileCounter_read;
+		++*attr_ErrorFileCounter_read;
 }
 
-/*----- PROTECTED REGION ID(PreProcessor::namespace_ending) ENABLED START -----*/
-
 //==============================================================================
 //	PreProcessor::create_inotify_mask()
 //==============================================================================
diff --git a/src/PreProcessor.h b/src/PreProcessor.h
index 573dde1..3cc9f13 100644
--- a/src/PreProcessor.h
+++ b/src/PreProcessor.h
@@ -74,6 +74,9 @@ class PreProcessor : public TANGO_BASE_CLASS
     //Thread shared pointer
     EventThread::SP m_eventThread_sp;
 
+	//Ignored file counter synchronization
+	boost::mutex m_ignoredCounterMutex;
+
     //Regular file counter synchronization
 	boost::mutex m_regularCounterMutex;
 
@@ -101,8 +104,12 @@ class PreProcessor : public TANGO_BASE_CLASS
 public:
 	//	WatchPath:
 	string	watchPath;
-	//	DestPath:
-	string	destPath;
+	//	RegularPath:	Regulars files destination path
+	string	regularPath;
+	//	WarningPath:	Warnings files destination path
+	string	warningPath;
+	//	ErrorPath:	Error files destination path
+	string	errorPath;
 	//	ScriptPath:
 	string	scriptPath;
 	//	EventList:
@@ -113,11 +120,16 @@ public:
 	Tango::DevUShort	waitTime;
 	//	WorkerNumber:
 	Tango::DevUShort	workerNumber;
+	//	IgnoreTimeout:	Behaviour for missing end of file after timeout case:
+	//  true = process those files like regulars files
+	//  false = process those files like erroneous files
+	Tango::DevBoolean	ignoreTimeout;
 	//	AutoStart:	Exec On command after init if state is not fault
 	Tango::DevBoolean	autoStart;
 
 //	Attribute data members
 public:
+	Tango::DevULong	*attr_IgnoredFileCounter_read;
 	Tango::DevULong	*attr_RegularFileCounter_read;
 	Tango::DevULong	*attr_WarningFileCounter_read;
 	Tango::DevULong	*attr_ErrorFileCounter_read;
@@ -182,6 +194,15 @@ public:
 	//--------------------------------------------------------
 	virtual void read_attr_hardware(vector<long> &attr_list);
 
+/**
+ *	Attribute IgnoredFileCounter related methods
+ *	Description:
+ *
+ *	Data type:	Tango::DevULong
+ *	Attr type:	Scalar
+ */
+	virtual void read_IgnoredFileCounter(Tango::Attribute &attr);
+	virtual bool is_IgnoredFileCounter_allowed(Tango::AttReqType type);
 /**
  *	Attribute RegularFileCounter related methods
  *	Description:
@@ -251,6 +272,8 @@ public:
 //------------------------------------------------------------------------------
 //  [Public] Users methods
 //------------------------------------------------------------------------------
+	virtual void incrementIgnoredCounter();
+
     virtual void incrementRegularCounter();
 
     virtual void incrementWarningCounter();
diff --git a/src/PreProcessor.xmi b/src/PreProcessor.xmi
index a754ed3..223886e 100644
--- a/src/PreProcessor.xmi
+++ b/src/PreProcessor.xmi
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="ASCII"?>
 <pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
   <classes name="PreProcessor" pogoRevision="8.1">
-    <description description="Pre proccesing generic server" title="PreProcessor" sourcePath="/home/mdm/workspace/nadir/pre_precessor/src" language="Cpp" filestogenerate="XMI   file,Code files" license="GPL" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
+    <description description="Pre proccesing generic server" title="PreProcessor" sourcePath="/home/marco/workspace/nadir/pre_precessor/src" language="Cpp" filestogenerate="XMI   file,Code files" license="GPL" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
       <inheritances classname="Device_Impl" sourcePath=""/>
       <identification contact="at oats.inaf.it - demarco" author="demarco" emailDomain="oats.inaf.it" classFamily="Acquisition" siteSpecific="" platform="Unix Like" bus="Not Applicable" manufacturer="none" reference=""/>
     </description>
@@ -9,10 +9,18 @@
       <type xsi:type="pogoDsl:StringType"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </deviceProperties>
-    <deviceProperties name="DestPath" description="">
+    <deviceProperties name="RegularPath" description="Regulars files destination path">
       <type xsi:type="pogoDsl:StringType"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </deviceProperties>
+	<deviceProperties name="WarningPath" description="Warnings files destination path">
+		<type xsi:type="pogoDsl:StringType"/>
+		<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+	</deviceProperties>
+	<deviceProperties name="ErrorPath" description="Error files destination path">
+		<type xsi:type="pogoDsl:StringType"/>
+		<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+	</deviceProperties>
     <deviceProperties name="ScriptPath" description="">
       <type xsi:type="pogoDsl:StringType"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
@@ -33,6 +41,11 @@
       <type xsi:type="pogoDsl:UShortType"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </deviceProperties>
+	<deviceProperties name="IgnoreTimeout" description="Behaviour for missing end of file after timeout case: &#xA;true = process those files like regulars files&#xA;false = process those files like erroneous files">
+		<type xsi:type="pogoDsl:BooleanType"/>
+		<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+		<DefaultPropValue>false</DefaultPropValue>
+	</deviceProperties>
     <deviceProperties name="AutoStart" description="Exec On command after init if state is not fault">
       <type xsi:type="pogoDsl:BooleanType"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
@@ -89,6 +102,14 @@
       </argout>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </commands>
+    <attributes name="IgnoredFileCounter" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
+      <dataType xsi:type="pogoDsl:UIntType"/>
+      <changeEvent fire="false" libCheckCriteria="false"/>
+      <archiveEvent fire="false" libCheckCriteria="false"/>
+      <dataReadyEvent fire="false" libCheckCriteria="true"/>
+      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+      <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
+    </attributes>
     <attributes name="RegularFileCounter" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
       <dataType xsi:type="pogoDsl:UIntType"/>
       <changeEvent fire="false" libCheckCriteria="false"/>
diff --git a/src/PreProcessorClass.cpp b/src/PreProcessorClass.cpp
index a6fa72b..8b9e200 100644
--- a/src/PreProcessorClass.cpp
+++ b/src/PreProcessorClass.cpp
@@ -130,8 +130,8 @@ PreProcessorClass *PreProcessorClass::init(const char *name)
 		catch (bad_alloc &)
 		{
 			throw;
-		}		
-	}		
+		}
+	}
 	return _instance;
 }
 
@@ -293,8 +293,34 @@ void PreProcessorClass::set_default_property()
 	}
 	else
 		add_wiz_dev_prop(prop_name, prop_desc);
-	prop_name = "DestPath";
-	prop_desc = "";
+	prop_name = "RegularPath";
+	prop_desc = "Regulars files destination path";
+	prop_def  = "";
+	vect_data.clear();
+	if (prop_def.length()>0)
+	{
+		Tango::DbDatum	data(prop_name);
+		data << vect_data ;
+		dev_def_prop.push_back(data);
+		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
+	}
+	else
+		add_wiz_dev_prop(prop_name, prop_desc);
+	prop_name = "WarningPath";
+	prop_desc = "Warnings files destination path";
+	prop_def  = "";
+	vect_data.clear();
+	if (prop_def.length()>0)
+	{
+		Tango::DbDatum	data(prop_name);
+		data << vect_data ;
+		dev_def_prop.push_back(data);
+		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
+	}
+	else
+		add_wiz_dev_prop(prop_name, prop_desc);
+	prop_name = "ErrorPath";
+	prop_desc = "Error files destination path";
 	prop_def  = "";
 	vect_data.clear();
 	if (prop_def.length()>0)
@@ -369,6 +395,20 @@ void PreProcessorClass::set_default_property()
 		dev_def_prop.push_back(data);
 		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
 	}
+	else
+		add_wiz_dev_prop(prop_name, prop_desc);
+	prop_name = "IgnoreTimeout";
+	prop_desc = "Behaviour for missing end of file after timeout case: \ntrue = process those files like regulars files\nfalse = process those files like erroneous files";
+	prop_def  = "false";
+	vect_data.clear();
+	vect_data.push_back("false");
+	if (prop_def.length()>0)
+	{
+		Tango::DbDatum	data(prop_name);
+		data << vect_data ;
+		dev_def_prop.push_back(data);
+		add_wiz_dev_prop(prop_name, prop_desc,  prop_def);
+	}
 	else
 		add_wiz_dev_prop(prop_name, prop_desc);
 	prop_name = "AutoStart";
@@ -457,7 +497,7 @@ void PreProcessorClass::write_class_property()
 				header = "$HeadURL: ";
 				start = header.length();
 				string	strloc = src_path.substr(start, (end-start));
-				
+
 				Tango::DbDatum	svn_loc("svn_location");
 				svn_loc << strloc;
 				data.push_back(svn_loc);
@@ -466,13 +506,13 @@ void PreProcessorClass::write_class_property()
 	}
 
 	//	Get CVS or SVN revision tag
-	
+
 	// CVS tag
 	string	tagname(TagName);
 	header = "$Name: ";
 	start = header.length();
 	string	endstr(" $");
-	
+
 	end   = tagname.find(endstr);
 	if (end!=string::npos && end>start)
 	{
@@ -481,17 +521,17 @@ void PreProcessorClass::write_class_property()
 		cvs_tag << strtag;
 		data.push_back(cvs_tag);
 	}
-	
+
 	// SVN tag
 	string	svnpath(SvnPath);
 	header = "$HeadURL: ";
 	start = header.length();
-	
+
 	end   = svnpath.find(endstr);
 	if (end!=string::npos && end>start)
 	{
 		string	strloc = svnpath.substr(start, end-start);
-		
+
 		string tagstr ("/tags/");
 		start = strloc.find(tagstr);
 		if ( start!=string::npos )
@@ -499,7 +539,7 @@ void PreProcessorClass::write_class_property()
 			start = start + tagstr.length();
 			end   = strloc.find(filename);
 			string	strtag = strloc.substr(start, end-start-1);
-			
+
 			Tango::DbDatum	svn_tag("svn_tag");
 			svn_tag << strtag;
 			data.push_back(svn_tag);
@@ -549,7 +589,7 @@ void PreProcessorClass::device_factory(const Tango::DevVarStringArray *devlist_p
 	for (unsigned long i=0 ; i<devlist_ptr->length() ; i++)
 	{
 		cout4 << "Device name : " << (*devlist_ptr)[i].in() << endl;
-		device_list.push_back(new PreProcessor(this, (*devlist_ptr)[i]));							 
+		device_list.push_back(new PreProcessor(this, (*devlist_ptr)[i]));
 	}
 
 	//	Manage dynamic attributes if any
@@ -589,6 +629,30 @@ void PreProcessorClass::attribute_factory(vector<Tango::Attr *> &att_list)
 	//	Add your own code
 
 	/*----- PROTECTED REGION END -----*/	//	PreProcessorClass::attribute_factory_before
+	//	Attribute : IgnoredFileCounter
+	IgnoredFileCounterAttrib	*ignoredfilecounter = new IgnoredFileCounterAttrib();
+	Tango::UserDefaultAttrProp	ignoredfilecounter_prop;
+	//	description	not set for IgnoredFileCounter
+	//	label	not set for IgnoredFileCounter
+	//	unit	not set for IgnoredFileCounter
+	//	standard_unit	not set for IgnoredFileCounter
+	//	display_unit	not set for IgnoredFileCounter
+	//	format	not set for IgnoredFileCounter
+	//	max_value	not set for IgnoredFileCounter
+	//	min_value	not set for IgnoredFileCounter
+	//	max_alarm	not set for IgnoredFileCounter
+	//	min_alarm	not set for IgnoredFileCounter
+	//	max_warning	not set for IgnoredFileCounter
+	//	min_warning	not set for IgnoredFileCounter
+	//	delta_t	not set for IgnoredFileCounter
+	//	delta_val	not set for IgnoredFileCounter
+
+	ignoredfilecounter->set_default_properties(ignoredfilecounter_prop);
+	//	Not Polled
+	ignoredfilecounter->set_disp_level(Tango::OPERATOR);
+	//	Not Memorized
+	att_list.push_back(ignoredfilecounter);
+
 	//	Attribute : RegularFileCounter
 	RegularFileCounterAttrib	*regularfilecounter = new RegularFileCounterAttrib();
 	Tango::UserDefaultAttrProp	regularfilecounter_prop;
@@ -606,7 +670,7 @@ void PreProcessorClass::attribute_factory(vector<Tango::Attr *> &att_list)
 	//	min_warning	not set for RegularFileCounter
 	//	delta_t	not set for RegularFileCounter
 	//	delta_val	not set for RegularFileCounter
-	
+
 	regularfilecounter->set_default_properties(regularfilecounter_prop);
 	//	Not Polled
 	regularfilecounter->set_disp_level(Tango::OPERATOR);
@@ -630,7 +694,7 @@ void PreProcessorClass::attribute_factory(vector<Tango::Attr *> &att_list)
 	//	min_warning	not set for WarningFileCounter
 	//	delta_t	not set for WarningFileCounter
 	//	delta_val	not set for WarningFileCounter
-	
+
 	warningfilecounter->set_default_properties(warningfilecounter_prop);
 	//	Not Polled
 	warningfilecounter->set_disp_level(Tango::OPERATOR);
@@ -654,7 +718,7 @@ void PreProcessorClass::attribute_factory(vector<Tango::Attr *> &att_list)
 	//	min_warning	not set for ErrorFileCounter
 	//	delta_t	not set for ErrorFileCounter
 	//	delta_val	not set for ErrorFileCounter
-	
+
 	errorfilecounter->set_default_properties(errorfilecounter_prop);
 	//	Not Polled
 	errorfilecounter->set_disp_level(Tango::OPERATOR);
@@ -728,7 +792,7 @@ void PreProcessorClass::command_factory()
  * method : 		PreProcessorClass::create_static_attribute_list
  * description : 	Create the a list of static attributes
  *
- * @param	att_list	the ceated attribute list 
+ * @param	att_list	the ceated attribute list
  */
 //--------------------------------------------------------
 void PreProcessorClass::create_static_attribute_list(vector<Tango::Attr *> &att_list)
@@ -762,10 +826,10 @@ void PreProcessorClass::erase_dynamic_attributes(const Tango::DevVarStringArray
 	Tango::Util *tg = Tango::Util::instance();
 
 	for (unsigned long i=0 ; i<devlist_ptr->length() ; i++)
-	{	
+	{
 		Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((string)(*devlist_ptr)[i]).c_str());
 		PreProcessor *dev = static_cast<PreProcessor *> (dev_impl);
-		
+
 		vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list();
 		vector<Tango::Attribute *>::iterator ite_att;
 		for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att)
diff --git a/src/PreProcessorClass.h b/src/PreProcessorClass.h
index 0041dd8..1bf6802 100644
--- a/src/PreProcessorClass.h
+++ b/src/PreProcessorClass.h
@@ -59,6 +59,19 @@ namespace PreProcessor_ns
 //=========================================
 //	Define classes for attributes
 //=========================================
+//	Attribute IgnoredFileCounter class definition
+class IgnoredFileCounterAttrib: public Tango::Attr
+{
+public:
+	IgnoredFileCounterAttrib():Attr("IgnoredFileCounter",
+			Tango::DEV_ULONG, Tango::READ) {};
+	~IgnoredFileCounterAttrib() {};
+	virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att)
+		{(static_cast<PreProcessor *>(dev))->read_IgnoredFileCounter(att);}
+	virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty)
+		{return (static_cast<PreProcessor *>(dev))->is_IgnoredFileCounter_allowed(ty);}
+};
+
 //	Attribute RegularFileCounter class definition
 class RegularFileCounterAttrib: public Tango::Attr
 {
diff --git a/src/PreProcessorStateMachine.cpp b/src/PreProcessorStateMachine.cpp
index 483f109..8078291 100644
--- a/src/PreProcessorStateMachine.cpp
+++ b/src/PreProcessorStateMachine.cpp
@@ -8,20 +8,20 @@
 // project :     PreProcessor
 //
 // This file is part of Tango device class.
-// 
+//
 // Tango 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 3 of the License, or
 // (at your option) any later version.
-// 
+//
 // Tango 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 Tango.  If not, see <http://www.gnu.org/licenses/>.
-// 
+//
 // $Author:  $
 //
 // $Revision:  $
@@ -53,6 +53,22 @@ namespace PreProcessor_ns
 //		Attributes Allowed Methods
 //=================================================
 
+//--------------------------------------------------------
+/**
+ *	Method      : PreProcessor::is_IgnoredFileCounter_allowed()
+ *	Description : Execution allowed for IgnoredFileCounter attribute
+ */
+//--------------------------------------------------------
+bool PreProcessor::is_IgnoredFileCounter_allowed(TANGO_UNUSED(Tango::AttReqType type))
+{
+
+	//	Not any excluded states for IgnoredFileCounter attribute in read access.
+	/*----- PROTECTED REGION ID(PreProcessor::IgnoredFileCounterStateAllowed_READ) ENABLED START -----*/
+
+	/*----- PROTECTED REGION END -----*/	//	PreProcessor::IgnoredFileCounterStateAllowed_READ
+	return true;
+}
+
 //--------------------------------------------------------
 /**
  *	Method      : PreProcessor::is_RegularFileCounter_allowed()
@@ -64,7 +80,7 @@ bool PreProcessor::is_RegularFileCounter_allowed(TANGO_UNUSED(Tango::AttReqType
 
 	//	Not any excluded states for RegularFileCounter attribute in read access.
 	/*----- PROTECTED REGION ID(PreProcessor::RegularFileCounterStateAllowed_READ) ENABLED START -----*/
-	
+
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::RegularFileCounterStateAllowed_READ
 	return true;
 }
@@ -80,7 +96,7 @@ bool PreProcessor::is_WarningFileCounter_allowed(TANGO_UNUSED(Tango::AttReqType
 
 	//	Not any excluded states for WarningFileCounter attribute in read access.
 	/*----- PROTECTED REGION ID(PreProcessor::WarningFileCounterStateAllowed_READ) ENABLED START -----*/
-	
+
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::WarningFileCounterStateAllowed_READ
 	return true;
 }
@@ -96,7 +112,7 @@ bool PreProcessor::is_ErrorFileCounter_allowed(TANGO_UNUSED(Tango::AttReqType ty
 
 	//	Not any excluded states for ErrorFileCounter attribute in read access.
 	/*----- PROTECTED REGION ID(PreProcessor::ErrorFileCounterStateAllowed_READ) ENABLED START -----*/
-	
+
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::ErrorFileCounterStateAllowed_READ
 	return true;
 }
@@ -119,7 +135,7 @@ bool PreProcessor::is_On_allowed(TANGO_UNUSED(const CORBA::Any &any))
 		get_state()==Tango::ALARM)
 	{
 	/*----- PROTECTED REGION ID(PreProcessor::OnStateAllowed) ENABLED START -----*/
-	
+
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::OnStateAllowed
 		return false;
 	}
@@ -140,7 +156,7 @@ bool PreProcessor::is_Off_allowed(TANGO_UNUSED(const CORBA::Any &any))
 		get_state()==Tango::ALARM)
 	{
 	/*----- PROTECTED REGION ID(PreProcessor::OffStateAllowed) ENABLED START -----*/
-	
+
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::OffStateAllowed
 		return false;
 	}
@@ -157,7 +173,7 @@ bool PreProcessor::is_ResetCounter_allowed(TANGO_UNUSED(const CORBA::Any &any))
 {
 	//	Not any excluded states for ResetCounter command.
 	/*----- PROTECTED REGION ID(PreProcessor::ResetCounterStateAllowed) ENABLED START -----*/
-	
+
 	/*----- PROTECTED REGION END -----*/	//	PreProcessor::ResetCounterStateAllowed
 	return true;
 }
diff --git a/src/ScriptManager.cpp b/src/ScriptManager.cpp
index 41450a4..1a09932 100644
--- a/src/ScriptManager.cpp
+++ b/src/ScriptManager.cpp
@@ -1,5 +1,7 @@
 #include <ScriptManager.h>
 
+#include <cstdio>
+
 namespace PreProcessor_ns
 {
 
@@ -34,7 +36,7 @@ ScriptManager::SP ScriptManager::create(Tango::DeviceImpl* deviceImpl_p,
 }
 
 //==============================================================================
-//	ScriptManager::isReadyToArchive()
+//	ScriptManager::checkScriptCompliance()
 //==============================================================================
 void ScriptManager::checkScriptCompliance()
     throw(std::runtime_error)
@@ -58,11 +60,41 @@ void ScriptManager::checkScriptCompliance()
         throw std::runtime_error("Invalid script");
 }
 
+//==============================================================================
+//	ScriptManager::isFileNameValid()
+//==============================================================================
+bool ScriptManager::isFileNameValid(boost::filesystem::path& filePath)
+	throw(std::runtime_error)
+{
+	DEBUG_STREAM << "ScriptManager::isFileNameValid()" << endl;
+
+	std::stringstream command;
+	command << m_configuration_sp->getScriptPath()
+	<< " VALID " << filePath.string();
+
+	std::string result = exec(command.str());
+
+	if(result.find("VALID OK") != std::string::npos)
+	{
+		return true;
+	}
+	else if(result.find("VALID FATAL") != std::string::npos)
+	{
+		return false;
+	}
+	else
+	{
+		std::stringstream errorStream;
+		errorStream << "Unknown validation error: " << result;
+		throw std::runtime_error(errorStream.str());
+	}
+}
+
 //==============================================================================
 //	ScriptManager::isFileVerified()
 //==============================================================================
-bool ScriptManager::isFileVerified(boost::filesystem::path& filePath)
-    throw(std::runtime_error)
+ScriptManager::Verified ScriptManager::isFileVerified(
+	boost::filesystem::path& filePath) throw(std::runtime_error)
 {
     DEBUG_STREAM << "ScriptManager::isFileVerified()" << endl;
 
@@ -74,17 +106,15 @@ bool ScriptManager::isFileVerified(boost::filesystem::path& filePath)
 
     if(result.find("VERIFY OK") != std::string::npos)
     {
-        return true;
+		return OK;
     }
     else if(result.find("VERIFY WAIT") != std::string::npos)
     {
-        return false;
+        return WAIT;
     }
     else if(result.find("VERIFY FATAL") != std::string::npos)
     {
-        std::stringstream errorStream;
-        errorStream << "Verification error: " << result;
-        throw std::runtime_error(errorStream.str());
+		return FATAL;
     }
     else
     {
@@ -97,20 +127,27 @@ bool ScriptManager::isFileVerified(boost::filesystem::path& filePath)
 //==============================================================================
 //	ScriptManager::preProcessFile()
 //==============================================================================
-void ScriptManager::preProcessFile(boost::filesystem::path& filePath)
-    throw(std::runtime_error)
+void ScriptManager::preProcessFile(boost::filesystem::path& filePath,
+	ScriptManager::Verified verified) throw(std::runtime_error)
 {
     DEBUG_STREAM << "ScriptManager::preProcessFile()" << endl;
 
     std::stringstream command;
     command << m_configuration_sp->getScriptPath()
-        << " PROCESS " << filePath.string();
+        << " PREPROCESS " << filePath.string();
+
+	if(verified == OK)
+		command << " OK";
+	else if(verified == WAIT)
+		command << " WAIT";
+	else if(verified == FATAL)
+		command << " FATAL";
 
     std::string result = exec(command.str());
 
-    if(result.find("PROCESS OK") == std::string::npos)
+    if(result.find("PREPROCESS OK") == std::string::npos)
     {
-        if(result.find("PROCESS FATAL") != std::string::npos)
+        if(result.find("PREPROCESS FATAL") != std::string::npos)
         {
             std::stringstream errorStream;
             errorStream << "Pre process error: " << result;
@@ -125,6 +162,44 @@ void ScriptManager::preProcessFile(boost::filesystem::path& filePath)
     }
 }
 
+//==============================================================================
+//	ScriptManager::postProcessFile()
+//==============================================================================
+void ScriptManager::postProcessFile(boost::filesystem::path& filePath,
+	ScriptManager::Verified verified) throw(std::runtime_error)
+{
+	DEBUG_STREAM << "ScriptManager::postProcessFile()" << endl;
+
+	std::stringstream command;
+	command << m_configuration_sp->getScriptPath()
+	<< " POSTPROCESS " << filePath.string();
+
+	if(verified == OK)
+		command << " OK";
+	else if(verified == WAIT)
+		command << " WAIT";
+	else if(verified == FATAL)
+		command << " FATAL";
+
+	std::string result = exec(command.str());
+
+	if(result.find("POSTPROCESS OK") == std::string::npos)
+	{
+		if(result.find("POSTPROCESS FATAL") != std::string::npos)
+		{
+			std::stringstream errorStream;
+			errorStream << "Post process error: " << result;
+			throw std::runtime_error(errorStream.str());
+		}
+		else
+		{
+			std::stringstream errorStream;
+			errorStream << "Unknown post process error: " << result;
+			throw std::runtime_error(errorStream.str());
+		}
+	}
+}
+
 //==============================================================================
 //	ScriptManager::exec()
 //==============================================================================
diff --git a/src/ScriptManager.h b/src/ScriptManager.h
index a0538e4..d128687 100644
--- a/src/ScriptManager.h
+++ b/src/ScriptManager.h
@@ -44,17 +44,28 @@ public:
 //------------------------------------------------------------------------------
 	static ScriptManager::SP create(Tango::DeviceImpl*, Configuration::SP);
 
+//------------------------------------------------------------------------------
+//  [Public] Verification results
+//------------------------------------------------------------------------------
+	enum Verified {OK, WAIT, FATAL};
+
 //------------------------------------------------------------------------------
 //  [Public] Script methods
 //------------------------------------------------------------------------------
-    virtual void checkScriptCompliance()
-        throw(std::runtime_error);
+	virtual void checkScriptCompliance()
+		throw(std::runtime_error);
+
+	virtual bool isFileNameValid(boost::filesystem::path&)
+		throw(std::runtime_error);
+
+	virtual Verified isFileVerified(boost::filesystem::path&)
+		throw(std::runtime_error);
 
-	virtual bool isFileVerified(boost::filesystem::path&)
-        throw(std::runtime_error);
+	virtual void preProcessFile(boost::filesystem::path&, Verified)
+		throw(std::runtime_error);
 
-    virtual void preProcessFile(boost::filesystem::path&)
-        throw(std::runtime_error);
+	virtual void postProcessFile(boost::filesystem::path&, Verified)
+		throw(std::runtime_error);
 
 protected:
 //------------------------------------------------------------------------------
diff --git a/src/WorkerThread.cpp b/src/WorkerThread.cpp
index a90a830..bde7326 100644
--- a/src/WorkerThread.cpp
+++ b/src/WorkerThread.cpp
@@ -42,6 +42,9 @@ void WorkerThread::workerLoop()
     boost::chrono::steady_clock::duration waitTime =
         boost::chrono::seconds(m_configuration_sp->getWaitTime());
 
+	//Process end of file after timeout like regualr files
+	bool ignoreTimeout = m_configuration_sp->getIgnoreTimeout();
+
     while(true)
     {
         try
@@ -59,45 +62,67 @@ void WorkerThread::workerLoop()
                 << fileName << "\"" << endl;
             try
             {
-                bool verified = false;
-
-                do
-                {
-                    if(m_fileManager_sp->isFileVerified(origPath))
-                    {
-                        verified = true;
-                        break;
-                    }
-                    else
-                    {
-                        boost::this_thread::sleep_for(sleepTime);
-                    }
-                }
-                while(boost::chrono::steady_clock::now()-start <= waitTime);
-
-                m_fileManager_sp->preProcessFile(origPath);
-
-                copyToDestination(origPath);
-
-                if(verified)
-                {
-                    INFO_STREAM << "WorkerThread::workerLoop() \"" << fileName
-                        << "\" ingested regularly" << endl;
-                    m_preProcessor_p->incrementRegularCounter();
-                }
-                else
-                {
-                    WARN_STREAM << "WorkerThread::workerLoop() \"" << fileName
-                        << "\" archived after timeout" << endl;
-                    m_preProcessor_p->incrementWarningCounter();
-                }
+				//Process only file that match valid regex
+				if(m_fileManager_sp->isFileNameValid(origPath))
+				{
+					ScriptManager::Verified verified;
+
+					do
+					{
+						verified = m_fileManager_sp->isFileVerified(origPath);
+
+						if(verified == ScriptManager::OK ||
+							verified == ScriptManager::FATAL)
+							break;
+
+						boost::this_thread::sleep_for(sleepTime);
+					}
+					while(boost::chrono::steady_clock::now()-start <= waitTime);
+
+					m_fileManager_sp->preProcessFile(origPath, verified);
+
+					copyToDestination(origPath, verified);
+
+					m_fileManager_sp->postProcessFile(origPath, verified);
+
+					if(verified == ScriptManager::Verified::OK)
+					{
+						INFO_STREAM << "WorkerThread::workerLoop() \"" << fileName
+						<< "\" ingested regularly" << endl;
+						m_preProcessor_p->incrementRegularCounter();
+					}
+					else if(verified == ScriptManager::Verified::WAIT)
+					{
+						WARN_STREAM << "WorkerThread::workerLoop() \"" << fileName
+						<< "\" archived after timeout" << endl;
+						m_preProcessor_p->incrementWarningCounter();
+					}
+					else if(verified == ScriptManager::Verified::FATAL)
+					{
+						WARN_STREAM << "WorkerThread::workerLoop() \"" << fileName
+						<< "\" not archived due to fits fatal error" << endl;
+						m_preProcessor_p->incrementErrorCounter();
+					}
+				}
+				else
+				{
+					INFO_STREAM << "WorkerThread::workerLoop() \"" << fileName
+					<< "\" ignored" << endl;
+					m_preProcessor_p->incrementIgnoredCounter();
+				}
             }
-            catch(std::runtime_error& ex)
+            catch(std::exception& ex)
             {
                 ERROR_STREAM << "WorkerThread::workerLoop() \"" << fileName
                     << "\" not archived due to " << ex.what() << endl;
                 m_preProcessor_p->incrementErrorCounter();
             }
+			catch(...)
+			{
+				ERROR_STREAM << "WorkerThread::workerLoop() \"" << fileName
+				<< "\" not archived due to unknown exception" << endl;
+				m_preProcessor_p->incrementErrorCounter();
+			}
 
             m_eventBuffer_sp->markAsProcessed(origPath);
         }
@@ -106,31 +131,44 @@ void WorkerThread::workerLoop()
             DEBUG_STREAM << "WorkerThread::workerLoop() interrupt" << endl;
 			break;
 		}
-        catch(std::exception& ex)
-        {
-            ERROR_STREAM << "WorkerThread::workerLoop() " << ex.what() << endl;
-        }
-		catch(...)
-		{
-            ERROR_STREAM << "WorkerThread::workerLoop() unknown exception" << endl;
-		}
     } //thread loop
 }
 
 //==============================================================================
 //	WorkerThread::moveFile()()
 //==============================================================================
-void WorkerThread::copyToDestination(boost::filesystem::path& origPath)
-    throw (std::runtime_error)
+void WorkerThread::copyToDestination(boost::filesystem::path& origPath,
+	ScriptManager::Verified verified) throw (std::runtime_error)
 {
     DEBUG_STREAM << "WorkerThread::moveFile()" << endl;
 
+	//Process end of file after timeout like regualr files
+	bool ignoreTimeout = m_configuration_sp->getIgnoreTimeout();
+
+	boost::filesystem::path destPath;
+
+	if(verified == ScriptManager::OK)
+	{
+		destPath /= m_configuration_sp->getRegularPath();
+	}
+	else if(verified == ScriptManager::WAIT)
+	{
+		if(ignoreTimeout)
+			destPath /= m_configuration_sp->getRegularPath();
+		else
+			destPath /= m_configuration_sp->getWarningPath();
+	}
+	else
+	{
+		destPath /= m_configuration_sp->getErrorPath();
+	}
+
+	//TODO: come fare per le destinazioni vuote?
+
 	if(!boost::filesystem::is_regular_file(origPath))
 		throw std::runtime_error( "Origin path \"" +
 			origPath.string() + "\" is not a regular file");
 
-    boost::filesystem::path destPath(m_configuration_sp->getDestPath());
-
 	if(!boost::filesystem::exists(destPath))
 		throw std::runtime_error( "Destination path \"" +
 			destPath.string() + "\" not exists");
diff --git a/src/WorkerThread.h b/src/WorkerThread.h
index e83e81c..8c23db8 100644
--- a/src/WorkerThread.h
+++ b/src/WorkerThread.h
@@ -35,8 +35,8 @@ protected:
 //------------------------------------------------------------------------------
 //	[Protected] Utilities methods
 //------------------------------------------------------------------------------
-    virtual void copyToDestination(boost::filesystem::path&)
-        throw (std::runtime_error);
+	virtual void copyToDestination(boost::filesystem::path&,
+		ScriptManager::Verified) throw (std::runtime_error);
 
 //------------------------------------------------------------------------------
 //	[Protected] Class variables
@@ -47,8 +47,8 @@ protected:
 	//Event buffer shared pointer
 	EventBuffer::SP m_eventBuffer_sp;
 
-    //File manager shared pointer
-    ScriptManager::SP m_fileManager_sp;
+	//File manager shared pointer
+	ScriptManager::SP m_fileManager_sp;
 
 	//Configuration shared pointer
 	Configuration::SP m_configuration_sp;
-- 
GitLab