310 lines
9.0 KiB
C++
310 lines
9.0 KiB
C++
|
|
/**
|
|||
|
|
* @file ModuleInfomation.cpp
|
|||
|
|
*
|
|||
|
|
* @author 黄军
|
|||
|
|
* @date 2011-7-27
|
|||
|
|
*/
|
|||
|
|
#include "ModuleManager.h"
|
|||
|
|
#include "ModuleInformation.h"
|
|||
|
|
// #include "Utils.h"
|
|||
|
|
// #include "Log.h"
|
|||
|
|
#include <string>
|
|||
|
|
#include <iostream>
|
|||
|
|
#include <vector>
|
|||
|
|
#include <map>
|
|||
|
|
#include <cstdlib>
|
|||
|
|
#include <fstream>
|
|||
|
|
// #include "Utils.h"
|
|||
|
|
namespace pai {
|
|||
|
|
namespace workflow {
|
|||
|
|
|
|||
|
|
CModuleInformation::CModuleInformation():m_oModule(NULL), m_iStepId(0), m_iId(0), m_strNamespace(), m_strName(),\
|
|||
|
|
m_strVersion(), m_bQC(false), m_bBreakpoint(false), m_strComments(),\
|
|||
|
|
m_bEnabled(true), m_ModParam(NULL), inModules(), outModules(), m_bBlankModule(false)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
CModuleInformation::CModuleInformation(const std::string& moduleClass):m_oModule(NULL), m_iStepId(0), m_iId(0), m_strNamespace(), m_strName(),\
|
|||
|
|
m_strVersion(), m_bQC(false), m_bBreakpoint(false), m_strComments(),\
|
|||
|
|
m_bEnabled(true), m_ModParam(NULL), inModules(), outModules(), m_bBlankModule(false)
|
|||
|
|
{
|
|||
|
|
if (moduleClass.empty())
|
|||
|
|
{
|
|||
|
|
m_bBlankModule = true;
|
|||
|
|
m_ModParam = NULL;
|
|||
|
|
m_oModule = NULL;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_bBlankModule = false;
|
|||
|
|
m_oModule = GetModuleManager()->CreateModuleByClassName(moduleClass);
|
|||
|
|
if (!m_oModule)
|
|||
|
|
{
|
|||
|
|
// exception
|
|||
|
|
//pai::log::Error(pai::utils::CUtils::GetFormatStr("Failed to create moduel for %s", moduleClass.c_str()));
|
|||
|
|
// throw pai::error::runtime_error("Failed to create module for " + moduleClass + ",please check this module library!");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_strVersion = GetModuleMetaData()->GetVersion();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
CModuleInformation::CModuleInformation(const CModuleInformation & modInfo):m_oModule(NULL), m_iStepId(modInfo.GetStepID()), m_iId(modInfo.GetId()), m_strNamespace(modInfo.GetNamespace()), m_strName(modInfo.GetName()),\
|
|||
|
|
m_strVersion(modInfo.m_strVersion), m_bQC(modInfo.GetQC()), m_bBreakpoint(modInfo.GetBreakpoint()), m_strComments(modInfo.GetComments()),\
|
|||
|
|
m_bEnabled(modInfo.GetEnabled()), m_ModParam(NULL), inModules(), outModules(), m_bBlankModule(modInfo.IsBlankModule())
|
|||
|
|
{
|
|||
|
|
Clone(modInfo);
|
|||
|
|
}
|
|||
|
|
void CModuleInformation::Clone(const workflow::CModuleInformation& modInfo)
|
|||
|
|
{
|
|||
|
|
if(this == &modInfo){
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
m_iStepId = modInfo.GetStepID();
|
|||
|
|
m_iId = modInfo.GetId();
|
|||
|
|
m_strNamespace = modInfo.GetNamespace();
|
|||
|
|
m_strName == modInfo.GetName();
|
|||
|
|
m_bBlankModule = modInfo.IsBlankModule();
|
|||
|
|
m_strVersion = modInfo.GetVersion();
|
|||
|
|
if (!m_bBlankModule)
|
|||
|
|
{
|
|||
|
|
if(m_ModParam != NULL){
|
|||
|
|
delete m_ModParam;
|
|||
|
|
}
|
|||
|
|
m_ModParam = NULL; //是否以后要删除
|
|||
|
|
if(m_oModule != NULL){
|
|||
|
|
delete m_oModule;
|
|||
|
|
}
|
|||
|
|
m_oModule = GetModuleManager()->CreateModuleByClassName(modInfo.GetClassName());
|
|||
|
|
if(m_oModule)
|
|||
|
|
{
|
|||
|
|
m_oModule->GetModuleParameter()->Clone(*(modInfo.GetModule()->GetModuleParameter()));
|
|||
|
|
*(m_oModule->GetMetaData()) = *(modInfo.GetModule()->GetMetaData());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
if(m_ModParam != NULL){
|
|||
|
|
delete m_ModParam;
|
|||
|
|
}
|
|||
|
|
if(m_oModule != NULL){
|
|||
|
|
delete m_oModule;
|
|||
|
|
}
|
|||
|
|
m_ModParam = NULL;
|
|||
|
|
m_oModule = NULL;
|
|||
|
|
}
|
|||
|
|
m_bQC = modInfo.GetQC();
|
|||
|
|
m_bBreakpoint = modInfo.GetBreakpoint();
|
|||
|
|
m_strComments = modInfo.GetComments();
|
|||
|
|
m_bEnabled = modInfo.GetEnabled();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::string CModuleInformation::GetComments2() const
|
|||
|
|
{
|
|||
|
|
return m_strComments;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
CModuleInformation::~CModuleInformation()
|
|||
|
|
{
|
|||
|
|
if (m_ModParam != NULL)
|
|||
|
|
{
|
|||
|
|
delete m_ModParam;
|
|||
|
|
m_ModParam = NULL;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (m_oModule)
|
|||
|
|
{
|
|||
|
|
delete m_oModule;
|
|||
|
|
m_oModule = NULL;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// // START 为检查工作流崩溃问题,暂时记录相关类析构时的堆栈信息,以便崩溃后跟踪。
|
|||
|
|
// std::string logPath;
|
|||
|
|
// std::ostringstream log;
|
|||
|
|
// log << "workflow_coredump_debug_log_pid" << getpid() << ".log";
|
|||
|
|
// std::string logName = log.str();
|
|||
|
|
// char *pEnv = (char*)pai::utils::CUtils::GetPaiHome().c_str();//getenv("PAI_HOME");
|
|||
|
|
|
|||
|
|
// if(pEnv == NULL)
|
|||
|
|
// {
|
|||
|
|
// logPath = std::string("/home/") + logName;
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// logPath = std::string(pEnv) + "/log/" + logName;
|
|||
|
|
// }
|
|||
|
|
/*
|
|||
|
|
std::ofstream fcout(logPath.c_str(), std::ofstream::app);
|
|||
|
|
if(fcout)
|
|||
|
|
{
|
|||
|
|
fcout << "#####start_CModuleInformation#####" << std::endl;
|
|||
|
|
std::vector<std::string> stack_trace = GetStackTrace();
|
|||
|
|
for (size_t i = 0; i < stack_trace.size(); ++i)
|
|||
|
|
{
|
|||
|
|
fcout << stack_trace[i] << std::endl;
|
|||
|
|
}
|
|||
|
|
fcout << "#####end_CModuleInformation#####" << std::endl;
|
|||
|
|
fcout.close();
|
|||
|
|
}
|
|||
|
|
*/
|
|||
|
|
// END
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
const CModuleMetaData* CModuleInformation::GetModuleMetaData() const
|
|||
|
|
{
|
|||
|
|
if (m_oModule)
|
|||
|
|
{
|
|||
|
|
return m_oModule->GetMetaData();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return NULL;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::string CModuleInformation::GetName() const
|
|||
|
|
{
|
|||
|
|
if (m_oModule)
|
|||
|
|
{
|
|||
|
|
return m_oModule->GetMetaData()->GetID();
|
|||
|
|
}
|
|||
|
|
// pai::log::Error(pai::utils::CUtils::GetFormatStr("module is NULL"));
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool CModuleInformation::IsBlankModule() const
|
|||
|
|
{
|
|||
|
|
return m_bBlankModule;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CModuleInformation::SetBlankModule(bool bBlankModule)
|
|||
|
|
{
|
|||
|
|
m_bBlankModule = bBlankModule;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
CModuleParameter* CModuleInformation::GetModuleParameter() const
|
|||
|
|
{
|
|||
|
|
if (m_oModule)
|
|||
|
|
{
|
|||
|
|
return m_oModule->GetModuleParameter();
|
|||
|
|
}
|
|||
|
|
// pai::log::Error(pai::utils::CUtils::GetFormatStr("%s : module is NULL", __func__));
|
|||
|
|
return NULL;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CModuleInformation::Print()
|
|||
|
|
{
|
|||
|
|
CModuleInformation* modInfo = this;
|
|||
|
|
CModule* module = modInfo->GetModule();
|
|||
|
|
std::cout << "\t\t\tid=" << modInfo->GetStepID() << std::endl;
|
|||
|
|
// std::cout << "\t\t\tsortId=" << module->GetModuleContext().module_sort_id << std::endl;
|
|||
|
|
// std::cout << "\t\t\tindegree=" << module->GetModuleContext().module_indegree << std::endl;
|
|||
|
|
// std::cout << "\t\t\toutdegree=" << module->GetModuleContext().module_outdegree << std::endl;
|
|||
|
|
std::cout << "\t\t\tnamespace=" << modInfo->GetNamespace() << std::endl;
|
|||
|
|
std::cout << "\t\t\tname=" << module->GetClassName() << std::endl;
|
|||
|
|
std::cout << "\t\t\tqc=" << modInfo->GetQC() << std::endl;
|
|||
|
|
std::cout << "\t\t\tbreakpoint=" << modInfo->GetBreakpoint() << std::endl;
|
|||
|
|
std::cout << "\t\t\tcomments=" << modInfo->GetComments() << std::endl;
|
|||
|
|
std::cout << "\t\t\tenabled=" << modInfo->GetEnabled() << std::endl;
|
|||
|
|
std::cout << "\t\t\tparametervalues:" << std::endl;
|
|||
|
|
std::cout << "\t\t\t{" << std::endl;
|
|||
|
|
int i = 0;
|
|||
|
|
std::vector < CParameterItem > paramItems = module->GetModuleParameter()->GetParameterItems();
|
|||
|
|
for (std::vector<CParameterItem>::iterator it = paramItems.begin(); it != paramItems.end(); ++it)
|
|||
|
|
{
|
|||
|
|
std::cout << "\t\t\t\tParameterValue[" << i << "]" << std::endl;
|
|||
|
|
std::cout << "\t\t\t\t{" << std::endl;
|
|||
|
|
CParameterItem item = *it;
|
|||
|
|
std::cout << "\t\t\t\t\tname=" << item.GetName().toStdString() << std::endl;
|
|||
|
|
std::cout << "\t\t\t\t\ttype=" << ParamItemTypeToString(item.GetType()) << std::endl;
|
|||
|
|
std::cout << "\t\t\t\t\tvalue=" << item.ValueToString() << std::endl;
|
|||
|
|
std::cout << "\t\t\t\t\tdefault=" << item.GetDefault() << std::endl;
|
|||
|
|
std::cout << "\t\t\t\t\tmax=" << item.GetMax() << std::endl;
|
|||
|
|
std::cout << "\t\t\t\t\tmin=" << item.GetMin() << std::endl;
|
|||
|
|
std::cout << "\t\t\t\t}" << std::endl;
|
|||
|
|
i++;
|
|||
|
|
}
|
|||
|
|
std::cout << "\t\t\t}" << std::endl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::string CModuleInformation::ParamItemTypeToString(ParameterType type)
|
|||
|
|
{
|
|||
|
|
std::string strIntType = "int";
|
|||
|
|
std::string strFloatType = "float";
|
|||
|
|
std::string strDoubleType = "double";
|
|||
|
|
std::string strStringType = "string";
|
|||
|
|
|
|||
|
|
std::string strType = "";
|
|||
|
|
switch (type)
|
|||
|
|
{
|
|||
|
|
case pai::module::ParmType_INT:
|
|||
|
|
strType = strIntType;
|
|||
|
|
break;
|
|||
|
|
case pai::module::ParmType_FLOAT:
|
|||
|
|
strType = strFloatType;
|
|||
|
|
break;
|
|||
|
|
case pai::module::ParmType_DOUBLE:
|
|||
|
|
strType = strDoubleType;
|
|||
|
|
break;
|
|||
|
|
case pai::module::ParmType_STRING:
|
|||
|
|
strType = strStringType;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
strType = strStringType;
|
|||
|
|
}
|
|||
|
|
return strType;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
unsigned long CModuleInformation::GetMemorySize()
|
|||
|
|
{
|
|||
|
|
unsigned long total = 0;
|
|||
|
|
total = sizeof(*this);
|
|||
|
|
if(!inModules.empty())
|
|||
|
|
{
|
|||
|
|
std::vector<CModuleInformation*>::iterator it = inModules.begin();
|
|||
|
|
while(it !=inModules.end())
|
|||
|
|
{
|
|||
|
|
total += (*it)->GetMemorySize();
|
|||
|
|
++it;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(!outModules.empty())
|
|||
|
|
{
|
|||
|
|
std::vector<CModuleInformation*>::iterator it = outModules.begin();
|
|||
|
|
while(it !=outModules.end())
|
|||
|
|
{
|
|||
|
|
total += (*it)->GetMemorySize();
|
|||
|
|
++it;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if(m_oModule)
|
|||
|
|
{
|
|||
|
|
total += m_oModule->GetMemorySize();
|
|||
|
|
}
|
|||
|
|
return total;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool operator ==(CModuleInformation &info, CModuleInformation &info2)
|
|||
|
|
{
|
|||
|
|
std::string moduleId = info.GetModuleID();
|
|||
|
|
std::string moduleId2 = info2.GetModuleID();
|
|||
|
|
if (moduleId != moduleId2)
|
|||
|
|
{
|
|||
|
|
// pai::log::Error( "两模块的ModuleId不等,分别为:" + moduleId + ";" + moduleId2 );
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
CModuleParameter*parm = info.GetModuleParameter();
|
|||
|
|
CModuleParameter* parm2 = info2.GetModuleParameter();
|
|||
|
|
if (!((*parm) == (*parm2)))
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|