插件引擎改进(未完成)
This commit is contained in:
parent
fb81037fa3
commit
6d58e8e90b
@ -37,7 +37,7 @@ namespace hgl
|
|||||||
virtual ~ExternalPlugIn();
|
virtual ~ExternalPlugIn();
|
||||||
|
|
||||||
void Free(); ///<释放插件文件
|
void Free(); ///<释放插件文件
|
||||||
bool Load(const UTF16String &,const OSString &); ///<加载插件
|
bool Load(const OSString &,const OSString &); ///<加载插件
|
||||||
};//class ExternalPlugIn:public PlugIn
|
};//class ExternalPlugIn:public PlugIn
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_EXTERNAL_PLUG_IN_INCLUDE
|
#endif//HGL_EXTERNAL_PLUG_IN_INCLUDE
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#define HGL_PLUGIN_INCLUDE
|
#define HGL_PLUGIN_INCLUDE
|
||||||
|
|
||||||
#include<hgl/type/BaseString.h>
|
#include<hgl/type/BaseString.h>
|
||||||
#include<hgl/plugin/PlugInInterface.h>
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -15,18 +14,16 @@ namespace hgl
|
|||||||
uint ref_count;
|
uint ref_count;
|
||||||
|
|
||||||
uint ver;
|
uint ver;
|
||||||
UTF16String name;
|
OSString name;
|
||||||
UTF16String intro;
|
UTF16String intro;
|
||||||
|
|
||||||
OSString filename; ///<插件文件名
|
OSString filename; ///<插件文件名
|
||||||
|
|
||||||
PlugInInterface *plugin_interface;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const uint GetVersion ()const{return ver;} ///<取得插件版本
|
const uint GetVersion ()const{return ver;} ///<取得插件版本
|
||||||
|
const OSString & GetName ()const{return name;} ///<取得插件名称
|
||||||
const UTF16String & GetIntro ()const{return intro;} ///<取得插件介绍
|
const UTF16String & GetIntro ()const{return intro;} ///<取得插件介绍
|
||||||
const UTF16String & GetName ()const{return name;} ///<取得插件名称
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -34,13 +31,14 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
ref_count=0;
|
ref_count=0;
|
||||||
ver=0;
|
ver=0;
|
||||||
plugin_interface=nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~PlugIn();
|
virtual ~PlugIn();
|
||||||
|
|
||||||
uint add_ref(){return ++ref_count;}
|
uint add_ref(){return ++ref_count;}
|
||||||
uint release_ref(){return --ref_count;}
|
uint release_ref(){return --ref_count;}
|
||||||
|
|
||||||
|
virtual bool GetInterface(uint,void *)=0;
|
||||||
};//class PlugIn
|
};//class PlugIn
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_PLUGIN_INCLUDE
|
#endif//HGL_PLUGIN_INCLUDE
|
||||||
|
@ -12,7 +12,7 @@ namespace hgl
|
|||||||
typedef bool (*GetPlugInInterfacePROC)(uint32,void *); ///<取得插件接口
|
typedef bool (*GetPlugInInterfacePROC)(uint32,void *); ///<取得插件接口
|
||||||
typedef void (*SetPlugInInterfacePROC)(void *,void *); ///<设置插件接口
|
typedef void (*SetPlugInInterfacePROC)(void *,void *); ///<设置插件接口
|
||||||
|
|
||||||
typedef bool (*LoadInterfaceByNamePROC)(const u16char *,uint32,void *); ///<取得接口
|
typedef bool (*LoadInterfaceByNamePROC)(const char *,uint32,void *); ///<取得接口
|
||||||
typedef bool (*LoadInterfaceByIndexPROC)(uint32,uint32,void *); ///<取得接口
|
typedef bool (*LoadInterfaceByIndexPROC)(uint32,uint32,void *); ///<取得接口
|
||||||
|
|
||||||
struct PlugInInterface
|
struct PlugInInterface
|
||||||
|
@ -9,15 +9,15 @@ namespace hgl
|
|||||||
/**
|
/**
|
||||||
* 插件管理
|
* 插件管理
|
||||||
*/
|
*/
|
||||||
class PlugInManage:public ResManage<UTF16String,PlugIn>
|
class PlugInManage:public ResManage<OSString,PlugIn>
|
||||||
{
|
{
|
||||||
UTF16String name; ///<插件类目名称(必须符合代码名称规则)
|
OSString name; ///<插件类目名称(必须符合代码名称规则)
|
||||||
|
|
||||||
OSStringList findpath; ///<插件查找目录
|
OSStringList findpath; ///<插件查找目录
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PlugInManage(const UTF16String &n)
|
PlugInManage(const OSString &n)
|
||||||
{
|
{
|
||||||
name=n;
|
name=n;
|
||||||
}
|
}
|
||||||
@ -25,13 +25,13 @@ namespace hgl
|
|||||||
virtual ~PlugInManage();
|
virtual ~PlugInManage();
|
||||||
|
|
||||||
bool RegistryPlugin(PlugIn *); ///<注册一个内置插件
|
bool RegistryPlugin(PlugIn *); ///<注册一个内置插件
|
||||||
uint UnregistryPlugin(const UTF16String &); ///<释放一个内置插件
|
uint UnregistryPlugin(const OSString &); ///<释放一个内置插件
|
||||||
|
|
||||||
bool AddFindPath (const OSString &path); ///<添加一个插件查找目录
|
bool AddFindPath (const OSString &path); ///<添加一个插件查找目录
|
||||||
|
|
||||||
PlugIn *LoadPlugin (const UTF16String &,const OSString &); ///<加载一个外部插件,明确指定全路径文件名
|
PlugIn *LoadPlugin (const OSString &,const OSString &); ///<加载一个外部插件,明确指定全路径文件名
|
||||||
PlugIn *LoadPlugin (const UTF16String &); ///<加载一个外部插件,自行查找
|
PlugIn *LoadPlugin (const OSString &); ///<加载一个外部插件,自行查找
|
||||||
bool UnloadPlugin(const UTF16String &); ///<释放一个外部插件
|
bool UnloadPlugin(const OSString &); ///<释放一个外部插件
|
||||||
};//class PlugInManage:public ResManage<UTF16String,PlugIn>
|
};//class PlugInManage:public ResManage<UTF16String,PlugIn>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include<hgl/type/Set.h>
|
#include<hgl/type/Set.h>
|
||||||
#include<hgl/type/BaseString.h>
|
#include<hgl/type/BaseString.h>
|
||||||
#include<hgl/thread/ThreadMutex.h>
|
#include<hgl/thread/ThreadMutex.h>
|
||||||
#include<hgl/LogInfo.h>
|
#include<hgl/log/LogInfo.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef HGL_TYPE_LRU_CACHE_CPP
|
#ifndef HGL_TYPE_LRU_CACHE_CPP
|
||||||
#define HGL_TYPE_LRU_CACHE_CPP
|
#define HGL_TYPE_LRU_CACHE_CPP
|
||||||
|
|
||||||
#include<hgl/LogInfo.h>
|
#include<hgl/log/LogInfo.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef HGL_STACK_CPP
|
#ifndef HGL_STACK_CPP
|
||||||
#define HGL_STACK_CPP
|
#define HGL_STACK_CPP
|
||||||
|
|
||||||
#include<hgl/LogInfo.h>
|
#include<hgl/log/LogInfo.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include <hgl/filesystem/FileSystem.h>
|
#include <hgl/filesystem/FileSystem.h>
|
||||||
#include <hgl/LogInfo.h>
|
#include <hgl/log/LogInfo.h>
|
||||||
#include <hgl/io/FileInputStream.h>
|
#include <hgl/io/FileInputStream.h>
|
||||||
#include <hgl/io/FileOutputStream.h>
|
#include <hgl/io/FileOutputStream.h>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include<hgl/platform/Platform.h>
|
#include<hgl/platform/Platform.h>
|
||||||
#include<hgl/io/FileAccess.h>
|
#include<hgl/io/FileAccess.h>
|
||||||
#include<hgl/LogInfo.h>
|
#include<hgl/log/LogInfo.h>
|
||||||
|
|
||||||
#if HGL_OS != HGL_OS_Windows
|
#if HGL_OS != HGL_OS_Windows
|
||||||
#include<unistd.h>
|
#include<unistd.h>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include<hgl/Logger.h>
|
#include<hgl/log/Logger.h>
|
||||||
#include<hgl/io/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
#include<hgl/thread/ThreadMutex.h>
|
#include<hgl/thread/ThreadMutex.h>
|
||||||
#include<hgl/io/FileOutputStream.h>
|
#include<hgl/io/FileOutputStream.h>
|
||||||
#include<hgl/io/DataOutputStream.h>
|
#include<hgl/io/DataOutputStream.h>
|
||||||
|
@ -54,8 +54,7 @@ namespace hgl
|
|||||||
Date d;
|
Date d;
|
||||||
Time t;
|
Time t;
|
||||||
|
|
||||||
d.Sync();
|
ToDateTime(d,t);
|
||||||
t.Sync();
|
|
||||||
|
|
||||||
const OSString str= OS_TEXT("Create Log Date/Time: ")+
|
const OSString str= OS_TEXT("Create Log Date/Time: ")+
|
||||||
OSString(d.GetYear ())+OS_TEXT("-")+
|
OSString(d.GetYear ())+OS_TEXT("-")+
|
||||||
@ -119,17 +118,8 @@ namespace hgl
|
|||||||
WriteLog<char>
|
WriteLog<char>
|
||||||
};
|
};
|
||||||
|
|
||||||
bool GetLogInterface(uint32 ver,void *data)
|
|
||||||
{
|
|
||||||
if(ver!=3)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
memcpy(data,&LogInterface3,sizeof(LogInterface));
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志插件,一个模拟的接口
|
* 日志插件
|
||||||
*/
|
*/
|
||||||
class LogPlugIn:public PlugIn ///日志插件
|
class LogPlugIn:public PlugIn ///日志插件
|
||||||
{
|
{
|
||||||
@ -137,12 +127,20 @@ namespace hgl
|
|||||||
|
|
||||||
LogPlugIn()
|
LogPlugIn()
|
||||||
{
|
{
|
||||||
type=pitLog;
|
ver=1;
|
||||||
|
name=OS_TEXT("Log");
|
||||||
|
intro=U16_TEXT("unicode text log module.");
|
||||||
|
|
||||||
name=OS_TEXT("unicode text log module.");
|
filename=OS_TEXT("Loginfo.cpp");
|
||||||
filename=OS_TEXT("LogInfo.cpp");
|
}
|
||||||
|
|
||||||
GetInterface=GetLogInterface;
|
bool GetInterface(uint ver,void *data) override
|
||||||
|
{
|
||||||
|
if(ver!=3||!data)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
memcpy(data,&LogInterface3,sizeof(LogInterface));
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
};//class LogPlugIn
|
};//class LogPlugIn
|
||||||
}//namespace logger
|
}//namespace logger
|
||||||
@ -164,8 +162,6 @@ namespace hgl
|
|||||||
delete li;
|
delete li;
|
||||||
li=nullptr;
|
li=nullptr;
|
||||||
|
|
||||||
UnloadPlugIn(pi);
|
|
||||||
|
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include<hgl/platform/ExternalModule.h>
|
#include<hgl/platform/ExternalModule.h>
|
||||||
#include<hgl/LogInfo.h>
|
#include<hgl/log/LogInfo.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ namespace hgl
|
|||||||
status=PlugInStatus::NO_LOAD;
|
status=PlugInStatus::NO_LOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExternalPlugIn::Load(const UTF16String &pn,const OSString &fn)
|
bool ExternalPlugIn::Load(const OSString &pn,const OSString &fn)
|
||||||
{
|
{
|
||||||
if(pi_module)
|
if(pi_module)
|
||||||
return(true);
|
return(true);
|
||||||
|
@ -9,7 +9,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
if(!pi)return(false);
|
if(!pi)return(false);
|
||||||
|
|
||||||
const UTF16String &pi_name=pi->GetName();
|
const OSString &pi_name=pi->GetName();
|
||||||
|
|
||||||
if(this->Find(pi_name))
|
if(this->Find(pi_name))
|
||||||
return(false);
|
return(false);
|
||||||
@ -17,7 +17,7 @@ namespace hgl
|
|||||||
return this->Add(pi_name,pi);
|
return this->Add(pi_name,pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint PlugInManage::UnregistryPlugin(const UTF16String &pi_name)
|
uint PlugInManage::UnregistryPlugin(const OSString &pi_name)
|
||||||
{
|
{
|
||||||
PlugIn *pi=this->Find(pi_name);
|
PlugIn *pi=this->Find(pi_name);
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ namespace hgl
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlugIn *PlugInManage::LoadPlugin(const UTF16String &pi_name,const OSString &filename)
|
PlugIn *PlugInManage::LoadPlugin(const OSString &pi_name,const OSString &filename)
|
||||||
{
|
{
|
||||||
if(pi_name.IsEmpty())return(nullptr);
|
if(pi_name.IsEmpty())return(nullptr);
|
||||||
if(filename.IsEmpty())return(nullptr);
|
if(filename.IsEmpty())return(nullptr);
|
||||||
@ -64,7 +64,7 @@ namespace hgl
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlugIn *PlugInManage::LoadPlugin(const UTF16String &pi_name)
|
PlugIn *PlugInManage::LoadPlugin(const OSString &pi_name)
|
||||||
{
|
{
|
||||||
if(pi_name.IsEmpty())return(nullptr);
|
if(pi_name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
@ -99,5 +99,16 @@ namespace hgl
|
|||||||
|
|
||||||
epi->Free();
|
epi->Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete epi;
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlugInManage::UnloadPlugin(const OSString &pi_name)
|
||||||
|
{
|
||||||
|
if(pi_name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
|
this->Release(pi_name);
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user