From 5c28ee5d1daac519662dcde673119684ca6892d5 Mon Sep 17 00:00:00 2001 From: Marco De Marco <demarco@oats.inaf.it> Date: Thu, 6 Mar 2014 16:13:54 +0100 Subject: [PATCH] Script manager added --- script/script.sh | 3 -- src/EventBuffer.cpp | 4 +-- src/EventThread.cpp | 10 ++++++ src/EventThread.h | 7 +++- src/ScriptManager.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++ src/ScriptManager.h | 66 ++++++++++++++++++++++++++++++++++ 6 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 src/ScriptManager.cpp create mode 100644 src/ScriptManager.h diff --git a/script/script.sh b/script/script.sh index 02b1473..fb3caf5 100755 --- a/script/script.sh +++ b/script/script.sh @@ -7,10 +7,7 @@ VERIFY_TOOL="/home/mdm/workspace/nexecs/test/tools/fitsverify" CHECK_STRING="conform to the FITS format" -NO_FILE_ERROR="failed to find or open the following file" - FATAL_ERROR="Fatal" - EOF_ERROR="End-of-file" #----------------------------------------------------------------------- diff --git a/src/EventBuffer.cpp b/src/EventBuffer.cpp index 0499e6d..718001f 100644 --- a/src/EventBuffer.cpp +++ b/src/EventBuffer.cpp @@ -11,7 +11,7 @@ namespace PreProcessor_ns EventBuffer::EventBuffer(Tango::DeviceImpl* deviceImpl_p) : Tango::LogAdapter(deviceImpl_p) { - DEBUG_STREAM << "EventBuffer::EventBuffer()" << endl; + DEBUG_STREAM << "EventBuffer::EventBuffer()" << endl; } //============================================================================== @@ -23,7 +23,7 @@ EventBuffer::~EventBuffer() } //============================================================================== -// EventBuffer::insertNew() +// EventBuffer::create() //============================================================================== EventBuffer::SP EventBuffer::create(Tango::DeviceImpl* deviceImpl_p) { diff --git a/src/EventThread.cpp b/src/EventThread.cpp index ab73749..d308dc3 100644 --- a/src/EventThread.cpp +++ b/src/EventThread.cpp @@ -62,6 +62,8 @@ void EventThread::start() try { + initScriptManager(); + initEventBuffer(); initINotify(); @@ -149,6 +151,14 @@ void EventThread::writeStatus(std::string status) m_status = status; } +//============================================================================== +// EventThread::initScriptManager() +//============================================================================== +void EventThread::initScriptManager() throw(std::runtime_error) +{ + DEBUG_STREAM << "EventThread::initScriptManager()" << endl; +} + //============================================================================== // EventThread::initEventBuffer() //============================================================================== diff --git a/src/EventThread.h b/src/EventThread.h index 90e248f..b078a5d 100644 --- a/src/EventThread.h +++ b/src/EventThread.h @@ -70,14 +70,19 @@ protected: virtual void writeStatus(std::string); //------------------------------------------------------------------------------ -// [Protected] Utilities methods +// [Protected] Initialization methods //------------------------------------------------------------------------------ + virtual void initScriptManager() throw(std::runtime_error); + virtual void initEventBuffer() throw(std::runtime_error); virtual void initINotify() throw(std::runtime_error); virtual void initThreadGroup() throw(std::runtime_error); +//------------------------------------------------------------------------------ +// [Protected] Event loop method +//------------------------------------------------------------------------------ virtual void eventLoop(); //------------------------------------------------------------------------------ diff --git a/src/ScriptManager.cpp b/src/ScriptManager.cpp new file mode 100644 index 0000000..3d80b81 --- /dev/null +++ b/src/ScriptManager.cpp @@ -0,0 +1,83 @@ +#include <ScriptManager.h> + +#include <iostream> +#include <sstream> + +namespace PreProcessor_ns +{ + +//============================================================================= +// ScriptManager::ScriptManager() +//============================================================================= +ScriptManager::ScriptManager(Tango::DeviceImpl* deviceImpl_p, + Configuration::SP configuration_sp) : Tango::LogAdapter(deviceImpl_p), + m_configuration_sp(configuration_sp) +{ + DEBUG_STREAM << "ScriptManager::ScriptManager()" << endl; +} + +//============================================================================= +// ScriptManager::~ScriptManager() +//============================================================================= +ScriptManager::~ScriptManager() +{ + DEBUG_STREAM << "ScriptManager::~ScriptManager()" << endl; +} + +//============================================================================== +// EventBuffer::create() +//============================================================================== +ScriptManager::SP ScriptManager::create(Tango::DeviceImpl* deviceImpl_p, + Configuration::SP configuration_sp) +{ + ScriptManager::SP s_sp(new ScriptManager(deviceImpl_p, configuration_sp), + ScriptManager::Deleter()); + + return s_sp; +} + +//============================================================================= +// ScriptManager::isReadyToArchive() +//============================================================================= +bool ScriptManager::isReadyToArchive(std::string fileName) + throw(std::runtime_error) +{ + DEBUG_STREAM << "ScriptManager::isReadyToArchive()" << endl; + + return true; +} + +//============================================================================= +// ScriptManager::exec() +//============================================================================= +std::string ScriptManager::exec(std::string command) + throw(std::runtime_error) +{ + DEBUG_STREAM << "ScriptManager::exec()" << endl; + + const int BUFFSIZE = 1024; + + FILE* pipe = popen(command.c_str(), "r"); + + if (!pipe) + throw std::runtime_error("Error launching external script"); + + char buffer[BUFFSIZE]; + std::string result = ""; + + while(!feof(pipe)) + { + if(fgets(buffer, BUFFSIZE, pipe) != NULL) + result += buffer; + } + + pclose(pipe); + + DEBUG_STREAM << "ScriptManager::exec() " << result << endl; + + return result; +} + +} + + diff --git a/src/ScriptManager.h b/src/ScriptManager.h new file mode 100644 index 0000000..fd71def --- /dev/null +++ b/src/ScriptManager.h @@ -0,0 +1,66 @@ +#ifndef SCRIPT_MANAGER_H +#define SCRIPT_MANAGER_H + +#include <Configuration.h> + +#include <string> +#include <stdexcept> + +#include <tango.h> + +#include <boost/shared_ptr.hpp> + +namespace PreProcessor_ns +{ + +class ScriptManager : public Tango::LogAdapter +{ +public: +//------------------------------------------------------------------------------ +// [Public] Shared pointer typedef +//------------------------------------------------------------------------------ + typedef boost::shared_ptr<ScriptManager> SP; + +protected: +//------------------------------------------------------------------------------ +// [Protected] Constructor destructor deleter +//------------------------------------------------------------------------------ + ScriptManager(Tango::DeviceImpl* deviceImpl_p, Configuration::SP); + + virtual ~ScriptManager(); + + class Deleter; + friend class Deleter; + class Deleter + { + public: + void operator()(ScriptManager* f) { delete f; } + }; + +public: +//------------------------------------------------------------------------------ +// [Public] Class creation method +//------------------------------------------------------------------------------ + static ScriptManager::SP create(Tango::DeviceImpl*, Configuration::SP); + +//------------------------------------------------------------------------------ +// [Public] Script method +//------------------------------------------------------------------------------ + virtual bool isReadyToArchive(std::string) throw(std::runtime_error); + +protected: +//------------------------------------------------------------------------------ +// [Protected] Utilities methods +//------------------------------------------------------------------------------ + virtual std::string exec(std::string) throw(std::runtime_error); + +//------------------------------------------------------------------------------ +// [Protected] Class variables +//------------------------------------------------------------------------------ + //Configuration shared pointer + Configuration::SP m_configuration_sp; +}; + +} + +#endif /* SCRIPT_MANAGER_H */ -- GitLab