Added: Command tasks.

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 13 years ago
parent 10f7ac32be
commit e9ac3fbdd9

@ -33,11 +33,13 @@
// NeL includes
#include <nel/misc/class_registry.h>
#include <nel/misc/command.h>
// Project includes
namespace NLMISC {
class CConfigFile;
class IRunnable;
}
namespace PIPELINE {
@ -56,9 +58,18 @@ public:
static IPipelineInterface *getInstance();
/// Get the configuration file of the pipeline service. Must only be used for configuration values that may be different on different services, such as tool paths.
virtual NLMISC::CConfigFile &getConfigFile() = 0;
/// Register a process class with the pipeline service. You should use the PIPELINE_REGISTER_CLASS macro.
virtual void registerClass(const std::string &className, NLMISC::IClassable* (*creator)(), const std::string &typeidCheck) throw(NLMISC::ERegistry) = 0;
/// Runs a runnable task if STATE_IDLE. You must call endedRunnableTask when the task has ended.
virtual bool tryRunnableTask(std::string stateName, NLMISC::IRunnable *task) = 0;
/// Call when a runnable task has ended to reset to STATE_IDLE.
virtual void endedRunnableTask() = 0;
}; /* class IPipelineInterface */
#define PIPELINE_REGISTER_CLASS(_class_) PIPELINE::IPipelineInterface::getInstance()->registerClass(#_class_, _class_::creator, typeid(_class_).name());

@ -32,8 +32,11 @@
// NeL includes
// #include <nel/misc/debug.h>
#include <nel/misc/command.h>
#include <nel/misc/task_manager.h>
// Project includes
#include "../pipeline_library/pipeline_interface.h"
using namespace std;
// using namespace NLMISC;
@ -50,6 +53,35 @@ CProcessMaxShape::~CProcessMaxShape()
}
namespace {
class CMaxExportShapeCommand : public NLMISC::IRunnable
{
virtual void getName(std::string &result) const
{ result = "CMaxExportShapeCommand"; }
virtual void run()
{
// ...
PIPELINE::IPipelineInterface::getInstance()->endedRunnableTask();
}
};
CMaxExportShapeCommand s_MaxExportShapeCommand;
} /* anonymous namespace */
} /* namespace PIPELINE */
NLMISC_CATEGORISED_COMMAND(max, maxExportShape, "Export shapes from a .max file manually.", "<filePath> <outDirectory>")
{
if(args.size() != 2) return false;
if (!PIPELINE::IPipelineInterface::getInstance()->tryRunnableTask("COMMAND_MAX_EXPORT_SHAPE", &PIPELINE::s_MaxExportShapeCommand))
{
log.displayNL("Busy.");
return false;
}
return true;
}
/* end of file */

@ -37,6 +37,7 @@
#include <nel/misc/class_registry.h>
// Project includes
#include "pipeline_service.h"
using namespace std;
// using namespace NLMISC;
@ -66,6 +67,16 @@ void CPipelineInterfaceImpl::registerClass(const std::string &className, NLMISC:
nldebug("Registered class '%s'", className.c_str());
}
bool CPipelineInterfaceImpl::tryRunnableTask(std::string stateName, NLMISC::IRunnable *task)
{
return PIPELINE::tryRunnableTask(stateName, task);
}
void CPipelineInterfaceImpl::endedRunnableTask()
{
PIPELINE::endedRunnableTask();
}
} /* namespace PIPELINE */
/* end of file */

@ -62,6 +62,8 @@ public:
virtual NLMISC::CConfigFile &getConfigFile();
virtual void registerClass(const std::string &className, NLMISC::IClassable* (*creator)(), const std::string &typeidCheck) throw(NLMISC::ERegistry);
virtual bool tryRunnableTask(std::string stateName, NLMISC::IRunnable *task);
virtual void endedRunnableTask();
}; /* class CPipelineInterfaceImpl */
} /* namespace PIPELINE */

@ -102,6 +102,7 @@ enum EState
STATE_IDLE,
STATE_RELOAD_SHEETS,
STATE_DATABASE_STATUS,
STATE_RUNNABLE_TASK,
};
/// Data
@ -112,6 +113,7 @@ CDatabaseStatus *s_DatabaseStatus = NULL;
CPipelineInterfaceImpl *s_PipelineInterfaceImpl = NULL;
EState s_State = STATE_IDLE;
std::string s_StateRunnableTaskName = "";
CMutex s_StateMutex;
std::vector<NLMISC::CLibrary *> s_LoadedLibraries;
@ -141,14 +143,51 @@ bool tryStateTask(EState state, IRunnable *task)
}
s_StateMutex.leave();
if (!result) return false;
nlassert(s_State != STATE_IDLE);
s_TaskManager->addTask(task);
return true;
}
} /* anonymous namespace */
bool tryRunnableTask(std::string stateName, IRunnable *task)
{
// copy paste from above.
bool result = false;
s_StateMutex.enter();
result = (s_State == STATE_IDLE);
if (result)
{
s_State = STATE_RUNNABLE_TASK;
s_StateRunnableTaskName = stateName;
}
s_StateMutex.leave();
if (!result) return false;
nlassert(s_State != STATE_IDLE);
s_TaskManager->addTask(task);
return true;
}
void endedRunnableTask()
{
nlassert(s_State != STATE_IDLE);
s_StateMutex.enter();
s_State = STATE_IDLE;
s_StateMutex.leave();
}
// ******************************************************************
namespace {
void initSheets()
{
std::string leveldesignDfnDirectory = IService::getInstance()->ConfigFile.getVar("LeveldesignDfnDirectory").asString();
@ -186,9 +225,7 @@ class CReloadSheets : public IRunnable
releaseSheets();
initSheets();
s_StateMutex.enter();
s_State = STATE_IDLE;
s_StateMutex.leave();
endedRunnableTask();
}
};
CReloadSheets s_ReloadSheets;
@ -207,9 +244,7 @@ class CUpdateDatabaseStatus : public IRunnable
void databaseStatusUpdated()
{
s_StateMutex.enter();
s_State = STATE_IDLE;
s_StateMutex.leave();
endedRunnableTask();
}
virtual void run()
@ -349,6 +384,9 @@ NLMISC_DYNVARIABLE(std::string, pipelineServiceState, "State of the pipeline ser
case PIPELINE::STATE_DATABASE_STATUS:
*pointer = "DATABASE_STATUS";
break;
case PIPELINE::STATE_RUNNABLE_TASK:
*pointer = PIPELINE::s_StateRunnableTaskName;
break;
}
}
}

@ -36,6 +36,10 @@
// Project includes
namespace NLMISC {
class IRunnable;
}
namespace PIPELINE {
#if defined(PIPELINE_MASTER)
@ -59,6 +63,9 @@ std::string unMacroPath(const std::string &path);
/// Macros a path, and standardizes it in advance.
std::string macroPath(const std::string &path);
bool tryRunnableTask(std::string stateName, NLMISC::IRunnable *task);
void endedRunnableTask();
extern bool g_IsExiting;
} /* namespace PIPELINE */

Loading…
Cancel
Save