logplus/Workflow/WFEngine/Module/include/ModuleManager.h
2026-01-16 17:18:41 +08:00

155 lines
4.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file ModuleManager.h
* @brief 文件主要定义了与模块的创建和加载相关的类和接口
* @author dev
* @date 2011-8-29
*/
#ifndef PAI_FRAME_MODULEAPI_MODULEMANAGER_H
#define PAI_FRAME_MODULEAPI_MODULEMANAGER_H
#include "ModuleMetaData.h"
#include <string>
#include <vector>
#include <map>
#include "Turtle.h"
namespace Json {
class Value;
}
namespace pai {
namespace module {
class CModuleParameter;
class CCompositeParameterItem;
class CModule;
/**
* @class CModuleManager
* @brief 定义了与模块的创建和加载相关的接口
*/
class PAI_MODULE_EXPORT CModuleManager
{
public:
/**
* @brief 构造函数
*/
CModuleManager();
/**
* @brief 虚析构函数
*/
virtual ~CModuleManager();
/**
* @brief 根据指定的模块类名创建该模块类的实例
* @param[in] strModuleClassName 模块类名
* @return 模块<code>CModule</code>指针
*/
CModule* CreateModuleByClassName(const std::string& strModuleClassName);
/**
* @brief 获取所有的模块此接口目前由GUI调用
* @param[out] vecModules 包含所有的模块的容器
*/
void ListAllModules(std::vector<CModule*>& vecModules) const;
/**
* @brief 查找指定模块ID的模块句柄
* @param[in] id 待查找模块ID
* @return 具有指定模块ID模块句柄如果没找到返回值为NULL
*/
CModule* FindModule(const std::string& id) const;
/**
* @deprecated 与@see #FindModule(const std::string&)功能相同,考虑去除
* @brief 查找指定模块ID的模块元数据
* @param[in] id 待查找模块IDCModuleMetaData
* @return 具有指定模块ID模块元数据如果没找到返回值为NULL
*/
CModuleMetaData* FindModuleMetaData(const std::string& id) const;
/**
* @brief 获取指定类型的所有模块信息
* @param[in] strCategory 模块类型
* @param[out] vecModules 返回所有属于strCategory对应参数所指定类型的模块
*/
void GetModulesByCategory(const std::string& strCategory, std::vector<CModule*>& vecModules);
/**
* @brief 获取模块树中的所有类型名字
* @param[out] vecCategoryNames 所有类型名字的集合
*/
void GetCategoryNames(std::vector<std::string>& vecCategoryNames);
/**
* @brief 获取模块动态库的存放路径
* @return 模块动态库的存放路径
*/
std::string GetLibDeployPath() const;
/**
* @brief 加载所有的模块
*/
void LoadAllModules();
/**
* @brief 重新加载所有的模块
*/
void ReLoadAllModules();
//some special module should be added in WellLog
//only use by WellLog
void AddModule(std::string modulefileFullPathName,CModule* aModule,void* modulehandle);
private:
/**
* @brief 将所有的模块信息从PAI_HOME/module目录下读取.json文件获取元数据信息到内存
* @param[in] moduleDir 模块json文件所在目录
*
*/
void Initialize(std::string moduleDir);
/**
* @brief parse module metadata json data
* @param[in] metaDataFilePath: module json file path
* @param[out] root: the parsed json data
* @return return ture if the file is parsed success, if not return false
*/
bool ParseMetaData(const std::string metaDataFilePath,Json::Value& root);
/**
* @brief load module by the module class name
* @param[in] moduleClassName: the name of the module to be loaded
* @return return true if load the module success ,if not return false
*/
bool LoadModuleByClassName(const std::string moduleClassName);
/**
* @brief load module and add the module json value to the module
* @param[in] root:the parsed module json data
* @return return true if load the module success ,if not return false
*/
// bool LoadModule(const Json::Value& root);
/**
* @brief 解析指定Json节点的模块参数信息
* @param[in] paramJsonNode 参数项对应Json节点
* @param[in] pParentItem 父参数项
*/
void _ParseParameterInfo(const Json::Value& paramJsonNode, CCompositeParameterItem* pParentItem);
/**
* @brief 仅创建实例,不组装参数和元数据
* @param[in] strModuleClassName:the name of the module to be created
* @return return the module that was created
*/
CModule* CreateModuleByClassNameInternal(const std::string& strModuleClassName);
private:
std::map<std::string,CModule*> m_moduleContainer;//模块的容器
std::map<std::string,std::string> m_modulePaths;
std::vector<void*> m_moduleHandles;
bool m_isLoadAllModules; //是否已加载所有模块
};
/**
* @brief 返回全局唯一的模块管理器句柄
*/
extern PAI_MODULE_EXPORT CModuleManager* GetModuleManager();
}
}
#endif