diff --git a/src/PreProcessor.cpp b/src/PreProcessor.cpp index 8c9542237e81536545296ebcc548f8fe0ce38f32..e39c73f264cfc9cac154a4ae2845803eed8edee8 100644 --- a/src/PreProcessor.cpp +++ b/src/PreProcessor.cpp @@ -298,12 +298,18 @@ void PreProcessor::get_device_property() if(watchPath.empty()) throw(invalid_argument("WatchPath property is empty or not defined")); + checkIfDirectoryExists(watchPath); + if(destPath.empty()) throw(invalid_argument("DestPath property is empty or not defined")); + checkIfDirectoryExists(destPath); + if(scriptPath.empty()) throw(invalid_argument("ScriptPath property is empty or not defined")); + checkIfFileExists(scriptPath); + if(eventList.empty()) throw(invalid_argument("EventList property is empty or not defined")); @@ -316,7 +322,6 @@ void PreProcessor::get_device_property() throw(invalid_argument(event_list_error.str())); } - //Create i-notify mask from event list property const uint32_t inotifyMask = create_inotify_mask(eventList); if(sleepTime<MIN_SLEEP_TIME || sleepTime>MAX_SLEEP_TIME) @@ -411,7 +416,23 @@ void PreProcessor::on() DEBUG_STREAM << "PreProcessor::On() - " << device_name << endl; /*----- PROTECTED REGION ID(PreProcessor::on) ENABLED START -----*/ - // Add your own code + try + { + if(m_eventThread_sp) + m_eventThread_sp->start(); + } + catch(std::exception& ex) + { + set_state(Tango::ALARM); + std::stringstream error_stream; + error_stream << "PreProcessor::On() " << ex.what() << std::endl; + set_status(error_stream.str()); + } + catch(...) + { + set_state(Tango::ALARM); + set_status("PreProcessor::On() unknown error"); + } /*----- PROTECTED REGION END -----*/ // PreProcessor::on } @@ -427,7 +448,23 @@ void PreProcessor::off() DEBUG_STREAM << "PreProcessor::Off() - " << device_name << endl; /*----- PROTECTED REGION ID(PreProcessor::off) ENABLED START -----*/ - // Add your own code + try + { + if(m_eventThread_sp) + m_eventThread_sp->stop(); + } + catch(std::exception& ex) + { + set_state(Tango::ALARM); + std::stringstream error_stream; + error_stream << "PreProcessor::Off() " << ex.what() << std::endl; + set_status(error_stream.str()); + } + catch(...) + { + set_state(Tango::ALARM); + set_status("PreProcessor::Off() unknown error"); + } /*----- PROTECTED REGION END -----*/ // PreProcessor::off } @@ -452,7 +489,7 @@ uint32_t PreProcessor::create_inotify_mask(const std::vector<std::string>& event for(it=event_list.begin(); it!=event_list.end(); it++) { std::stringstream event_stream; - event_stream << "FitsImporter::create_inotify_mask() "; + event_stream << "PreProcessor::create_inotify_mask() "; if(it->compare("IN_ACCESS")==0) { @@ -521,7 +558,7 @@ uint32_t PreProcessor::create_inotify_mask(const std::vector<std::string>& event iNotifyMask += IN_ALL_EVENTS; } else - throw std::invalid_argument("FitsImporter::create_inotify_mask() " + throw std::invalid_argument("PreProcessor::create_inotify_mask() " "string \"" + *it + " \" is invalid inotify event"); INFO_STREAM << event_stream.str() << endl; @@ -530,5 +567,53 @@ uint32_t PreProcessor::create_inotify_mask(const std::vector<std::string>& event return iNotifyMask; } +//============================================================================== +// PreProcessor::checkIfFileExists() +//============================================================================== +void PreProcessor::checkIfFileExists(std::string fileName) + throw(std::invalid_argument) +{ + DEBUG_STREAM << "PreProcessor::checkIfFileExists() - " << device_name << endl; + + boost::filesystem::path path(fileName); + + if(!boost::filesystem::exists(path)) + { + std::stringstream errorStream; + errorStream << "File " << fileName + << " not exists" << std::endl; + throw std::invalid_argument(errorStream.str()); + } + + INFO_STREAM << "PreProcessor::checkIfFileExists() " << fileName << endl; +} + +//============================================================================== +// PreProcessor::checkIfDirectoryExists() +//============================================================================== +void PreProcessor::checkIfDirectoryExists(std::string directoryName) + throw(std::invalid_argument) +{ + DEBUG_STREAM << "PreProcessor::checkIfFileExists() - " << device_name << endl; + + boost::filesystem::path path(directoryName); + + if(!boost::filesystem::exists(path)) + { + std::stringstream errorStream; + errorStream << "Directory " << directoryName << " not exists" << std::endl; + throw std::invalid_argument(errorStream.str()); + } + + if(!boost::filesystem::is_directory(path)) + { + std::stringstream errorStream; + errorStream << directoryName << " is not a directory" << std::endl; + throw std::invalid_argument(errorStream.str()); + } + + INFO_STREAM << "PreProcessor::checkIfDirectoryExists() " << directoryName << endl; +} + /*----- PROTECTED REGION END -----*/ // PreProcessor::namespace_ending } // namespace diff --git a/src/PreProcessor.h b/src/PreProcessor.h index e472238016640d22396b58b9c6f07a3148dc3c66..233e5ba5edd62c2859b1ef6ee570c178bf63d4bd 100644 --- a/src/PreProcessor.h +++ b/src/PreProcessor.h @@ -203,6 +203,12 @@ private: uint32_t create_inotify_mask(const std::vector<std::string>&) throw (std::invalid_argument); + virtual void checkIfFileExists(std::string) + throw(std::invalid_argument); + + virtual void checkIfDirectoryExists(std::string) + throw(std::invalid_argument); + /*----- PROTECTED REGION END -----*/ // PreProcessor::Additional Method prototypes };