通过将系统集成所需要的服务从主执行程序转移到dstPlatform.dll模块中,便于其他模块或者脚本调用。本模块主要提供日志管理、对象生命期管理、插件管理、服务管理、线程/任务管理、脚本管理、应用程序管理、服务包装宏等。接口定义如下:
//**********************************************************************
// Copyright (c) 2012
// 迪斯特软件开发小组.
// 文件: dstPlatform.h
// 内容:
// 历史:
// 序号 修改时间 修改人 修改内容
// 1 2012-8-2 胡乐秋 首次生成
//*********************************************************************
//声明本头文件宏
#ifndef _DSTPLATFORM_H
#define _DSTPLATFORM_H
//输出宏定义
#ifdef DSTPLATFORM_EXPORTS
#define PLATFORM_API extern "C" __declspec(dllexport)
#else
#define PLATFORM_API extern "C"
#endif
//包含头文件
#include <sstream>
////////////////////////////////////////// 日志管理 /////////////////////////////////////////////////////////
//日志严重度
enum{ LOG_VERBOSE = -1,LOG_INFO,LOG_WARNING,LOG_ERROR,LOG_ERROR_REPORT,LOG_FATAL,LOG_NUM_SEVERITIES };
typedef void (* log_handle_type)(int nSeverityLevel,const char* szMessage,unsigned int nMessageStartOffset,void* pUserData);
typedef void (* status_message_handle_type)(const char* szMessage,void* pUserData);
//外部函数声明(要求模块实现)
extern const char* GetCurrentModuleName(void);
//打印日志(线程安全,任意线程调用)
PLATFORM_API void dstPrintLog(int nSeverityLevel,const char* szMessage,unsigned int nMessageStartOffset);
//得到最小日志级别(可通过应用程序配置文件中命令行command-line="... -log_level=1 ..."开关予以改变)
PLATFORM_API int dstGetMinLogLevel(void);
//得到指定模块的详细日志级别(可通过应用程序配置文件中命令行command-line="... --vmodule=dstPlatform=3,dstXUL=2 ..."开关予以改变)
PLATFORM_API int dstGetVlogLevel(const char* szModuleName);
//注册日志观察者(线程安全,任意线程调用)
PLATFORM_API void dstRegisterLogHandle(unsigned int nThreadID,log_handle_type pLogHandle,void* pUserData,bool bConsumeLog);
//注销日志观察者(线程安全,任意线程调用)
PLATFORM_API void dstUnregisterLogHandle(log_handle_type pLogHandle,void* pUserData);
//打印状态信息(线程安全,任意线程调用)
PLATFORM_API void dstPrintStatusMessage(const char* szMsg);
//注册状态信息处理器(NULL参数可注销,线程安全,任意线程调用)
PLATFORM_API void dstRegisterStatusMessageHandle(unsigned int nThreadID,status_message_handle_type pStatusMessageHandler,void* pUserData);
//日志宏定义
#define COMPACT_LOG_EX_INFO(ClassName, ...) ClassName(GetCurrentModuleName(),__FILE__, __LINE__, LOG_INFO , ##__VA_ARGS__)
#define COMPACT_LOG_EX_WARNING(ClassName, ...) ClassName(GetCurrentModuleName(),__FILE__, __LINE__, LOG_WARNING , ##__VA_ARGS__)
#define COMPACT_LOG_EX_ERROR(ClassName, ...) ClassName(GetCurrentModuleName(),__FILE__, __LINE__, LOG_ERROR , ##__VA_ARGS__)
#define COMPACT_LOG_EX_ERROR_REPORT(ClassName, ...) ClassName(GetCurrentModuleName(),__FILE__, __LINE__, LOG_ERROR_REPORT , ##__VA_ARGS__)
#define COMPACT_LOG_EX_FATAL(ClassName, ...) ClassName(GetCurrentModuleName(),__FILE__, __LINE__, LOG_FATAL , ##__VA_ARGS__)
#define COMPACT_LOG_EX_DFATAL(ClassName, ...) ClassName(GetCurrentModuleName(),__FILE__, __LINE__, LOG_DFATAL , ##__VA_ARGS__)
#define COMPACT_LOG_INFO COMPACT_LOG_EX_INFO(CLogMessage)
#define COMPACT_LOG_WARNING COMPACT_LOG_EX_WARNING(CLogMessage)
#define COMPACT_LOG_ERROR COMPACT_LOG_EX_ERROR(CLogMessage)
#define COMPACT_LOG_ERROR_REPORT COMPACT_LOG_EX_ERROR_REPORT(CLogMessage)
#define COMPACT_LOG_FATAL COMPACT_LOG_EX_FATAL(CLogMessage)
#define COMPACT_LOG_DFATAL COMPACT_LOG_EX_DFATAL(CLogMessage)
#ifndef ERROR
#define ERROR 0
#endif
#define COMPACT_LOG_EX_0(ClassName, ...) COMPACT_LOG_EX_ERROR(ClassName , ##__VA_ARGS__)
#define COMPACT_LOG_0 COMPACT_LOG_ERROR
enum{ LOG_0 = LOG_ERROR};
#define LOG_IS_ON(severity) ((LOG_ ## severity) >= dstGetMinLogLevel())
#define VLOG_IS_ON(verboselevel) ((verboselevel) <= dstGetVlogLevel(GetCurrentModuleName()))
#define LAZY_STREAM(stream, condition) !(condition) ? (void) 0 : CLogMessageVoidify() & (stream)
#define LOG_STREAM(severity) COMPACT_LOG_ ## severity.stream()
#define LOG(severity) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity))
#define LOG_IF(severity, condition) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
#define VLOG_STREAM(verbose_level) CLogMessage(GetCurrentModuleName(),__FILE__, __LINE__, -verbose_level).stream()
#define VLOG(verbose_level) LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
#define VLOG_IF(verbose_level, condition) LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level) && (condition))
#define STATUS_MESSAGE CStatusMessage().stream()
////////////////////////////////////////// 对象生命期管理 /////////////////////////////////////////////////////////
//类型声明
typedef void (* object_release_type)(void*);
//注册对象(线程安全)
PLATFORM_API void dstRegisterObject(int hObject,const char* szObjectType,const char* szCreateFile,int nCreateLine,object_release_type pRelease = 0);
//注销对象(线程安全)
PLATFORM_API void dstUnregisterObject(int hObject);
//对象句柄是否有效(线程安全)
PLATFORM_API bool dstIsValidHandle(int hObject);
//得到对象类型(线程安全)
PLATFORM_API const char* dstGetObjectHandleType(int hObject);
//是否为有效对象句柄(线程安全)
PLATFORM_API bool dstIsValidObjectHandle(int hObject,const char* szObjectType);
//验证对象类型有效(线程安全
template<typename T> inline bool dstVerifyValidObjectHandle(void* pHandle) { return dstIsValidObjectHandle(reinterpret_cast<int>(pHandle),typeid(T*).name()) != 0;}
//得到对象指针(线程安全
template<typename T> inline T* dstGetObjectFromHandle(void* pObject) { return dstVerifyValidObjectHandle<T>(pObject) ? reinterpret_cast<T*>(pObject) : 0; }
//对象注册宏
#define REGISTER_OBJECT(x) dstRegisterObject(reinterpret_cast<int>((x)),typeid((x)).name(),__FILE__,__LINE__)
#define REGISTER_OBJECT_EX(x,pRelease) dstRegisterObject(reinterpret_cast<int>((x)),typeid((x)).name(),__FILE__,__LINE__,pRelease)
#define UNREGISTER_OBJECT(x) dstUnregisterObject(reinterpret_cast<int>((x)))
#define VERIFY_REGISTER_OBJECT(x) if(!dstIsValidHandle(reinterpret_cast<int>((x)))) REGISTER_OBJECT(x)
#define VERIFY_UNREGISTER_OBJECT(x) if(dstIsValidHandle(reinterpret_cast<int>((x)))) UNREGISTER_OBJECT(x)
////////////////////////////////////////// 插件管理 /////////////////////////////////////////////////////////
//判断插件是否存在(线程安全)
PLATFORM_API bool dstHasPlugin(const char* szPluginName);
//根据插件描叙内容载入插件(线程安全)
PLATFORM_API void dstLoadPlugin(const char* szPluginDirectory,const char* szPluginDescriptionXmlContent);
//根据插件描叙文件载入插件(线程安全)
PLATFORM_API void dstLoadPluginFromFile(const char* szPluginDescriptionPathName);
//卸载插件(线程安全)
PLATFORM_API void dstUnloadPlugin(const char* szPluginName);
////////////////////////////////////////// 服务管理 /////////////////////////////////////////////////////////
//类型声明
typedef void (* service_changed_cb_type)(const char* szServiceName,bool bRegistered,void* pUserData);
//得到服务数量(线程安全)
PLATFORM_API unsigned int dstGetServicesCount(void);
//是否已经注册服务(线程安全)
PLATFORM_API bool dstHasService(const char* szServiceName);
//得到服务名(线程安全)
PLATFORM_API const char* dstGetServiceName(unsigned int nIndex);
//得到服务运行的线程(线程安全)
PLATFORM_API int dstGetServiceThreadID(const char* szServiceName);
//得到服务地址(线程安全)
PLATFORM_API void* dstGetServiceAddress(const char* szServiceName);
//得到服务
template<typename ServiceType> void dstGetService(const char* szServiceName,ServiceType& pService);
//得到服务原型字符串(线程安全)
PLATFORM_API const char* dstGetServicePrototype(const char* szServiceName);
//得到服务帮助(线程安全)
PLATFORM_API const char* dstGetServiceHelp(const char* szServiceName);
//得到服务模块名(线程安全)
PLATFORM_API const char* dstGetServicePluginName(const char* szServiceName);
//注册服务(线程安全)
PLATFORM_API void dstRegisterService(int nThreadID,const char* szServiceName,void* pServiceAddress,const char* szPrototype,const char* szHelp,const char* szPluginName);
//注销服务(线程安全)
PLATFORM_API void dstUnregisterService(const char* szServiceName);
//注册观察者(线程安全,但pServiceChangedCB将在主线程调用)
PLATFORM_API void dstRegisterServiceObserver(service_changed_cb_type pServiceChangedCB,void* pUserData);
//注销观察者(线程安全,但pServiceChangedCB将在主线程调用)
PLATFORM_API void dstUnregisterServiceObserver(service_changed_cb_type pServiceChangedCB,void* pUserData);
//显示插件服务UI(线程安全)
PLATFORM_API void dstShowServicesUI(void);
////////////////////////////////////////// 线程、任务管理 /////////////////////////////////////////////////////////
//类型声明
typedef void (* task_callback_type)(void*); //任务回调函数
enum { prpUIThread,prpMainThread = prpUIThread,prpWorkThread0,prpWorkThread1,prpWorkThread2,prpWorkThread3,prpWorkThread4,prpWorkThread6,prpWorkThread7,prpWorkThread8,prpWorkThread9 }; //命名线程ID
//得到线程数量(线程安全,任意线程调用)
PLATFORM_API unsigned int dstGetThreadCount(void);
//得到当前线程ID(线程安全,可在任意线程调用)
PLATFORM_API unsigned int dstGetCurrentThreadID(void);
//查找空闲线程ID(线程安全,可在任意线程调用,无空闲线程时返回-1)
PLATFORM_API int dstFindIdleThread(void);
//运行等待派发的任务(在进入window模式对话框后,将运行window自定义的消息循环,所以在窗口流程中需循环调用本方法处理任务)
PLATFORM_API void dstDispatchPendingTasks(void);
//发布任务(线程安全,任意线程调用)
PLATFORM_API void dstPostTask(unsigned int nThreadID,task_callback_type pTaskCB,void* pTaskParameter,long long nDelayedMilliseconds = 0,bool bNestable = true);
//发送任务,等待任务返回(线程安全,任意线程调用)
PLATFORM_API void dstSendTask(unsigned int nThreadID,task_callback_type pTaskCB,void* pTaskParameter,long long nDelayedMilliseconds = 0,bool bNestable = true);
//发布任务(不等待任务完成,线程安全,任意线程调用)
template<typename FunctorType> void dstPostTask(unsigned int nThreadID,FunctorType& aFunctor,long long nDelayMilliseconds = 0,bool bNestable = true);
//发送任务(等待任务完成,线程安全,任意线程调用)
template<typename FunctorType> void dstSendTask(unsigned int nThreadID,FunctorType& aFunctor,long long nDelayMilliseconds = 0,bool bNestable = true);
//调用任务(等待任务返回结果,线程安全,任意线程调用)
template<typename FunctorType> typename FunctorType::result_type dstInvokeTask(unsigned int nThreadID,FunctorType& aFunctor,long long nDelayMilliseconds = 0,bool bNestable = true);
//在指定线程立刻生成对象(等待任务完成,线程安全,任意线程调用)
template<typename T> T* dstCreateImmediately(unsigned int nThreadID,long long nDelayMilliseconds = 0,bool bNestable = false);
//在指定线程删除对象(不等待任务完成,线程安全,任意线程调用)
template<typename T> void dstDeleteSoon(unsigned int nThreadID,T* pObject,long long nDelayMilliseconds = 0,bool bNestable = false);
////////////////////////////////////////// 脚本管理 /////////////////////////////////////////////////////////
//运行脚本(线程安全)
PLATFORM_API void dstRunScript(unsigned int nThreadID,const char* szScriptContent);
////////////////////////////////////////// 应用程序管理 /////////////////////////////////////////////////////////
//类型声明
typedef void (*application_callback_type)(void* pUserData);
enum ApplicationEventType //应用程序事件类型
{
prpApplicationObjectsWillCreate = 0,
prpApplicationObjectsCreated,
prpApplicationObjectsWillInit,
prpApplicationObjectsInited,
prpApplicationWillStart,
prpApplicationStarted,
prpApplicationUIWillStart,
prpApplicationUIStarted,
prpApplicationUIWillClose,
prpApplicationUIClosed,
prpApplicationShutdown,
prpApplicationEventCount
};
//焕发应用程序事件(线程安全,任意线程调用)
PLATFORM_API void dstFireApplicationEvent(unsigned int nEventType);
//注册应用程序事件观察者(线程安全,任意线程调用)
PLATFORM_API void dstRegisterApplicationEventObserver(unsigned int nEventType,application_callback_type pCallback,void* pUserData,unsigned int nInvokeThreadID,int nPriorityLevel = 0);
//注销应用程序观察者(线程安全,任意线程调用)
PLATFORM_API void dstUnreigsterApplicationEventObserver(unsigned int nEventType,application_callback_type pCallback,void* pUserData);
//得到应用程序选项xml元素(线程安全,返回实际类型为rapidxml::xml_node<char>,对返回对象的操作可读但不可修改(由于不同dll静态链接运行库时内存分配模型不同),非线程安全,需要在主线程调用)
PLATFORM_API void* dstApplicationOptions_GetXmlElement(void);
//是否有配置信息(线程安全)
PLATFORM_API bool dstApplicationOptions_HasAttribute(const char* szAttributeName,bool bCaseSensitive = false);
//得到配置属性(线程安全)
PLATFORM_API const char* dstApplicationOptions_GetAttribute(const char* szAttributeName,const char* szDefaultValue,bool bCaseSensitive = false);
//设置配置属性(线程安全)
PLATFORM_API void dstApplicationOptions_SetAttribute(const char* szAttributeName,const char* szValue,bool bCaseSensitive = false);
////////////////////////////////////////// 其它 /////////////////////////////////////////////////////////
//得到平台版本(线程安全)
PLATFORM_API const char* dstGetPlatformVersion(void);
//注册应用程序退出时处理函数(线程安全,但回调函数将在主线程调用)
typedef void (* exit_callback_type)(void*);
PLATFORM_API void dstRegisterExitCallback(exit_callback_type pCallback,void* pUserData);
//注册应用程序退出时处理函数
template<typename FunctorType> void dstRegisterExitCallback(FunctorType aFunctor);
////////////////////////////////////////// 日志管理实现 /////////////////////////////////////////////////////////
//**********************************************************************
// 类名: CLogMessage
// 目的: 日志信息类
//*********************************************************************
class CLogMessage
{
////类型声明
public:
typedef CLogMessage my_type;
////构造、析构函数
public:
//构造函数
CLogMessage(const char* szModuleName,const char* szFileName,int nLineNumber,int nSeverityLevel) : m_nSeverityLevel(nSeverityLevel)
{
//输出前缀
m_aStream << '[';
//输出模块
if(szModuleName && (*szModuleName != '\0'))
m_aStream << szModuleName;
//输出日志严重度
const char* const s_szLogSeverityNames[LOG_NUM_SEVERITIES] = {"信息", "警告", "错误", "错误记录", "致命错误" };
if(nSeverityLevel >= 0)
m_aStream << ':' << s_szLogSeverityNames[nSeverityLevel];
else
m_aStream << ":详细日志" << -nSeverityLevel;
//输出文件信息
if(szFileName && (*szFileName != '\0'))
{
const char* psz1 = strrchr(szFileName,'\\');
const char* psz2 = strrchr(szFileName,'/');
const char* psz = psz1 < psz2 ? psz2 : psz1;
m_aStream << ':' << (psz ? psz + 1 : szFileName) << '(' << nLineNumber << ')';
}
//输出后缀
m_aStream << "] ";
m_nMessageStartOffset = m_aStream.tellp();
}
//析构函数
~CLogMessage(void) { dstPrintLog(m_nSeverityLevel,m_aStream.str().c_str(),m_nMessageStartOffset);}
private:
//拷贝构造函数(声明未实现,禁止value语义)
CLogMessage(const my_type&);
//赋值操作符重载(声明未实现,禁止value语义)
my_type& operator=(const my_type&);
////基本查询
public:
//得到输出流
std::ostream& stream(void) { return m_aStream; }
////数据成员
private:
int m_nSeverityLevel; //日志严重级别
std::ostringstream m_aStream; //日志流
unsigned int m_nMessageStartOffset; //日志消息开始偏移值(可用于忽略前缀附加信息,如文件名等)
};
//**********************************************************************
// 类名: CLogMessageVoidify
// 目的: dummy日志消息类(用户不满足条件下
//*********************************************************************
class CLogMessageVoidify
{
public:
CLogMessageVoidify(void) {}
void operator&(std::ostream&) {}
};
//**********************************************************************
// 类名: CStatusMessage
// 目的: 状态信息类
//*********************************************************************
class CStatusMessage
{
////构造、析构函数
public:
//构造函数
CStatusMessage(void) {}
//析构函数
~CStatusMessage(void)
{
std::string szMsg = m_aStream.str();
dstPrintStatusMessage(szMsg.c_str());
}
////基本查询
public:
std::ostream& stream(void) { return m_aStream; }
////数据成员
private:
std::ostringstream m_aStream;
};
////////////////////////////////////////// 任务管理模板函数 /////////////////////////////////////////////////////////
//**********************************************************************
// 函数: dstPostTask
// 功能: 发布任务(不等待任务完成)
//*********************************************************************
template<typename FunctorType>
inline void dstPostTask(unsigned int nThreadID,FunctorType& aFunctor,long long nDelayMilliseconds,bool bNestable)
{
struct CInvokeAndDeleteFunctor
{
static void Execute(void* pUserData)
{
FunctorType* pFunctor = reinterpret_cast<FunctorType*>(pUserData);
if(pFunctor)
{
(*pFunctor)();
delete pFunctor;
}
}
};
dstPostTask(nThreadID,&CInvokeAndDeleteFunctor::Execute,new FunctorType(aFunctor),nDelayMilliseconds,bNestable);
}
//**********************************************************************
// 函数: dstSendTask
// 功能: 发送任务(等待任务完成)
//*********************************************************************
template<typename FunctorType>
inline void dstSendTask(unsigned int nThreadID,FunctorType& aFunctor,long long nDelayMilliseconds,bool bNestable)
{
struct CInvokeFunctor
{
static void Execute(void* pUserData)
{
FunctorType* pFunctor = reinterpret_cast<FunctorType*>(pUserData);
if(pFunctor)
(*pFunctor)();
}
};
dstSendTask(nThreadID,&CInvokeFunctor::Execute,&aFunctor,nDelayMilliseconds,bNestable);
}
//**********************************************************************
// 函数: dstInvokeTask
// 功能: 同步调用任务(等待任务返回结果)
//*********************************************************************
template<typename FunctorType>
inline typename FunctorType::result_type dstInvokeTask(unsigned int nThreadID,FunctorType& aFunctor,long long nDelayMilliseconds,bool bNestable)
{
typedef typename FunctorType::result_type result_type;
struct CInvokeTaskFunctor
{
CInvokeTaskFunctor(FunctorType& aFunctor,result_type& aResult) : m_aFunctor(aFunctor),m_aResult(aResult) {}
static void ExecuteEntry(void* pUserData)
{
reinterpret_cast<CInvokeTaskFunctor*>(pUserData)->Execute();
}
void Execute(void)
{
m_aResult = m_aFunctor();
}
FunctorType& m_aFunctor;
result_type& m_aResult; //调用结果
};
result_type aResult;
CInvokeTaskFunctor aInvokeTaskFunctor(aFunctor,aResult);
dstSendTask(nThreadID,&CInvokeTaskFunctor::ExecuteEntry,&aInvokeTaskFunctor,nDelayMilliseconds,bNestable);
return aResult;
}
//**********************************************************************
// 函数: dstCreateImmediately
// 功能: 在指定线程立刻生成对象(等待任务完成,线程安全,任意线程调用)
//*********************************************************************
template<typename T>
inline T* dstCreateImmediately(unsigned int nThreadID,long long nDelayMilliseconds,bool bNestable)
{
struct CCreateFunctor
{
static void Execute(void* pUserData)
{
*(reinterpret_cast<T**>(pUserData)) = new T();
}
};
T* pObject = 0;
dstSendTask(nThreadID,&CCreateFunctor::Execute,&pObject,nDelayMilliseconds,bNestable);
return pObject;
}
//**********************************************************************
// 函数: dstDeleteSoon
// 功能: 删除对象(不久后)
//*********************************************************************
template<typename T>
inline void dstDeleteSoon(unsigned int nThreadID,T* pObject,long long nDelayMilliseconds,bool bNestable)
{
struct CDeleteObject
{
static void Execute(void* pUserData)
{
delete reinterpret_cast<T*>(pUserData);
}
};
dstPostTask(nThreadID,CDeleteObject::Execute,pObject,nDelayMilliseconds,bNestable);
}
////////////////////////////////////////// 其它模板函数实现 /////////////////////////////////////////////////////////
//**********************************************************************
// 函数: dstRegisterExitCallback
// 功能: 注册应用程序退出时处理函数
//*********************************************************************
template<typename FunctorType>
inline void dstRegisterExitCallback(FunctorType aFunctor)
{
struct CInvokeAndDeleteFunctor
{
static void Execute(void* pUserData)
{
FunctorType* pFunctor = reinterpret_cast<FunctorType*>(pUserData);
if(pFunctor)
{
(*pFunctor)();
delete pFunctor;
}
}
};
dstRegisterExitCallback(&CInvokeAndDeleteFunctor::Execute,new FunctorType(aFunctor));
}
////////////////////////////////////////// 服务管理模板函数、服务封装宏 /////////////////////////////////////////////////////////
//**********************************************************************
// 函数: dstGetService
// 功能: 得到服务
//*********************************************************************
template<typename ServiceType>
inline void dstGetService(const char* szServiceName,ServiceType& pService)
{
if(!pService)
{
//检查服务是否存在
void* pServiceAddress = dstGetServiceAddress(szServiceName);
if(pServiceAddress)
{
//检查服务原型是否匹配
const char* szPrototype = dstGetServicePrototype(szServiceName);
if(_stricmp(szPrototype,typeid(ServiceType).name()) != 0)
{
std::stringstream ss;
ss << "服务(" << szServiceName << ")原型不匹配!\r\n\r\n\t注册原型为: " << szPrototype << "\r\n\t期望原型为: " << typeid(pService).name();
dstPrintLog(LOG_ERROR_REPORT,ss.str().c_str(),0);
return;
}
else
pService = reinterpret_cast<ServiceType>(pServiceAddress);
}
else
{
std::stringstream ss;
ss << "找不到插件期望的服务(" << szServiceName << ")!";
dstPrintLog(LOG_ERROR_REPORT,ss.str().c_str(),0);
}
}
}
#define SERVICE_WRAPPER_0(FuncName) \
void FuncName(void) \
{ \
void (* pService)(void) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(); \
}
#define SERVICE_WRAPPER_R0(ReturnType,FuncName) \
ReturnType FuncName(void) \
{ \
ReturnType (* pService)(void) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService() : 0; \
}
#define SERVICE_WRAPPER_1(FuncName,P0) \
void FuncName(P0 p0) \
{ \
void (* pService)(P0) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0); \
}
#define SERVICE_WRAPPER_R1(ReturnType,FuncName,P0) \
ReturnType FuncName(P0 p0) \
{ \
ReturnType (* pService)(P0) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0) : 0; \
}
#define SERVICE_WRAPPER_2(FuncName,P0,P1) \
void FuncName(P0 p0,P1 p1) \
{ \
void (* pService)(P0,P1) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1); \
}
#define SERVICE_WRAPPER_R2(ReturnType,FuncName,P0,P1) \
ReturnType FuncName(P0 p0,P1 p1) \
{ \
ReturnType (* pService)(P0,P1) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1) : 0; \
}
#define SERVICE_WRAPPER_3(FuncName,P0,P1,P2) \
void FuncName(P0 p0,P1 p1,P2 p2) \
{ \
void (* pService)(P0,P1,P2) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2); \
}
#define SERVICE_WRAPPER_R3(ReturnType,FuncName,P0,P1,P2) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2) \
{ \
ReturnType (* pService)(P0,P1,P2) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2) : 0; \
}
#define SERVICE_WRAPPER_4(FuncName,P0,P1,P2,P3) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3) \
{ \
void (* pService)(P0,P1,P2,P3) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3); \
}
#define SERVICE_WRAPPER_R4(ReturnType,FuncName,P0,P1,P2,P3) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3) \
{ \
ReturnType (* pService)(P0,P1,P2,P3) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3) : 0; \
}
#define SERVICE_WRAPPER_5(FuncName,P0,P1,P2,P3,P4) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4) \
{ \
void (* pService)(P0,P1,P2,P3,P4) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4); \
}
#define SERVICE_WRAPPER_R5(ReturnType,FuncName,P0,P1,P2,P3,P4) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4) : 0; \
}
#define SERVICE_WRAPPER_6(FuncName,P0,P1,P2,P3,P4,P5) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5); \
}
#define SERVICE_WRAPPER_R6(ReturnType,FuncName,P0,P1,P2,P3,P4,P5) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5) : 0; \
}
#define SERVICE_WRAPPER_7(FuncName,P0,P1,P2,P3,P4,P5,P6) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6); \
}
#define SERVICE_WRAPPER_R7(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6) : 0; \
}
#define SERVICE_WRAPPER_8(FuncName,P0,P1,P2,P3,P4,P5,P6,P7) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6,P7) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6,p7); \
}
#define SERVICE_WRAPPER_R8(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6,P7) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6,P7) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6,p7) : 0; \
}
#define SERVICE_WRAPPER_9(FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6,p7,p8); \
}
#define SERVICE_WRAPPER_R9(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6,p7,p8) : 0; \
}
#define SERVICE_WRAPPER_10(FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9); \
}
#define SERVICE_WRAPPER_R10(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9) : 0; \
}
#define SERVICE_WRAPPER_11(FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10); \
}
#define SERVICE_WRAPPER_R11(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) : 0; \
}
#define SERVICE_WRAPPER_12(FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10,P11 p11) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11); \
}
#define SERVICE_WRAPPER_R12(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10,P11 p11) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11) : 0; \
}
#define SERVICE_WRAPPER_13(FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10,P11 p11,P12 p12) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12); \
}
#define SERVICE_WRAPPER_R13(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10,P11 p11,P12 p12) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12) : 0; \
}
#define SERVICE_WRAPPER_14(FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10,P11 p11,P12 p12,P13 p13) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13); \
}
#define SERVICE_WRAPPER_R14(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10,P11 p11,P12 p12,P13 p13) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13) : 0; \
}
#define SERVICE_WRAPPER_15(FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14) \
void FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10,P11 p11,P12 p12,P13 p13,P14 p14) \
{ \
void (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14) = 0; \
dstGetService(__FUNCTION__,pService); \
if(pService) \
pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14); \
}
#define SERVICE_WRAPPER_R15(ReturnType,FuncName,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14) \
ReturnType FuncName(P0 p0,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5,P6 p6,P7 p7,P8 p8,P9 p9,P10 p10,P11 p11,P12 p12,P13 p13,P14 p14) \
{ \
ReturnType (* pService)(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14) = 0; \
dstGetService(__FUNCTION__,pService); \
return pService ? pService(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14) : 0; \
}
#endif //假如未定义_DSTPLATFORM_H宏