Commit bcc84950 authored by Alexis Girault's avatar Alexis Girault
Browse files

ENH: Implement imstkModule base functions

parent 5b3141a0
......@@ -20,6 +20,90 @@
#include "imstkModule.h"
#include <iostream>
namespace imstk {
void Module::exec()
{
m_status = ModuleStatus::RUNNING;
this->initModule();
while( m_status != ModuleStatus::TERMINATING )
{
if( m_status == ModuleStatus::RUNNING )
{
this->runModule();
}
}
this->cleanUpModule();
m_status = ModuleStatus::INACTIVE;
}
void Module::run()
{
switch(m_status)
{
case ModuleStatus::PAUSED :
m_status = ModuleStatus::RUNNING;
break;
case ModuleStatus::RUNNING :
std::cerr << "Can not run " << m_name <<std::endl
<< "Module already running." <<std::endl;
break;
default :
std::cerr << "Can not run " << m_name <<std::endl
<< "Module terminating or not active."
<< "Run `module::exec()` to launch your module." <<std::endl;
break;
}
}
void Module::pause()
{
switch(m_status)
{
case ModuleStatus::RUNNING :
m_status = ModuleStatus::PAUSED;
break;
case ModuleStatus::PAUSED :
std::cerr << "Can not pause " << m_name <<std::endl
<< "Module already running." <<std::endl;
break;
default :
std::cerr << "Can not pause " << m_name <<std::endl
<< "Module terminating or not active."
<< "Run `module::exec()` to launch your module." <<std::endl;
break;
}
}
void Module::terminate()
{
switch(m_status)
{
case ModuleStatus::TERMINATING :
std::cerr << "Can not terminate " << m_name <<std::endl
<< "Module already terminating." <<std::endl;
break;
case ModuleStatus::INACTIVE :
std::cerr << "Can not terminate " << m_name <<std::endl
<< "Module not active."
<< "Run `module::exec()` to launch your module." <<std::endl;
break;
default :
m_status = ModuleStatus::TERMINATING;
break;
}
}
const ModuleStatus& Module::getStatus() const
{
return m_status;
}
const std::string& Module::getName() const
{
return m_name;
}
}
......@@ -21,15 +21,40 @@
#ifndef imstkModule_h
#define imstkModule_h
#include <iostream>
namespace imstk {
enum class ModuleStatus
{
INACTIVE,
RUNNING,
PAUSED,
TERMINATING
};
class Module
{
public:
~Module() = default;
private:
Module() = default;
void exec();
void run();
void pause();
void terminate();
const ModuleStatus& getStatus() const;
const std::string& getName() const;
protected:
Module(std::string name) : m_name(name) {}
virtual void initModule() = 0;
virtual void runModule() = 0;
virtual void cleanUpModule() = 0;
ModuleStatus m_status = ModuleStatus::INACTIVE;
std::string m_name;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment