Skip to content
Snippets Groups Projects
Commit 5c28ee5d authored by Marco De Marco's avatar Marco De Marco
Browse files

Script manager added

parent e005369f
No related branches found
No related tags found
No related merge requests found
...@@ -7,10 +7,7 @@ ...@@ -7,10 +7,7 @@
VERIFY_TOOL="/home/mdm/workspace/nexecs/test/tools/fitsverify" VERIFY_TOOL="/home/mdm/workspace/nexecs/test/tools/fitsverify"
CHECK_STRING="conform to the FITS format" CHECK_STRING="conform to the FITS format"
NO_FILE_ERROR="failed to find or open the following file"
FATAL_ERROR="Fatal" FATAL_ERROR="Fatal"
EOF_ERROR="End-of-file" EOF_ERROR="End-of-file"
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
......
...@@ -23,7 +23,7 @@ EventBuffer::~EventBuffer() ...@@ -23,7 +23,7 @@ EventBuffer::~EventBuffer()
} }
//============================================================================== //==============================================================================
// EventBuffer::insertNew() // EventBuffer::create()
//============================================================================== //==============================================================================
EventBuffer::SP EventBuffer::create(Tango::DeviceImpl* deviceImpl_p) EventBuffer::SP EventBuffer::create(Tango::DeviceImpl* deviceImpl_p)
{ {
......
...@@ -62,6 +62,8 @@ void EventThread::start() ...@@ -62,6 +62,8 @@ void EventThread::start()
try try
{ {
initScriptManager();
initEventBuffer(); initEventBuffer();
initINotify(); initINotify();
...@@ -149,6 +151,14 @@ void EventThread::writeStatus(std::string status) ...@@ -149,6 +151,14 @@ void EventThread::writeStatus(std::string status)
m_status = status; m_status = status;
} }
//==============================================================================
// EventThread::initScriptManager()
//==============================================================================
void EventThread::initScriptManager() throw(std::runtime_error)
{
DEBUG_STREAM << "EventThread::initScriptManager()" << endl;
}
//============================================================================== //==============================================================================
// EventThread::initEventBuffer() // EventThread::initEventBuffer()
//============================================================================== //==============================================================================
......
...@@ -70,14 +70,19 @@ protected: ...@@ -70,14 +70,19 @@ protected:
virtual void writeStatus(std::string); 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 initEventBuffer() throw(std::runtime_error);
virtual void initINotify() throw(std::runtime_error); virtual void initINotify() throw(std::runtime_error);
virtual void initThreadGroup() throw(std::runtime_error); virtual void initThreadGroup() throw(std::runtime_error);
//------------------------------------------------------------------------------
// [Protected] Event loop method
//------------------------------------------------------------------------------
virtual void eventLoop(); virtual void eventLoop();
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
#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;
}
}
#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 */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment