📄 nsigenericfactory.h
字号:
PRUint32 mFlags;
};
/** Module Callbacks **/
/**
* nsModuleConstructorProc
*
* This function is called when the module is first being constructed.
* @param self module which is being constructed.
*
* @return NS_OK Construction successful.
* NS_ERROR* Method failure which will result in module not being
* loaded.
**/
typedef nsresult (PR_CALLBACK *nsModuleConstructorProc) (nsIModule *self);
/**
* nsModuleDestructorProc
*
* This function is called when the module is being destroyed.
* @param self module which is being destroyed.
*
**/
typedef void (PR_CALLBACK *nsModuleDestructorProc) (nsIModule *self);
/**
* nsModuleInfo
*
* Use this structure to define meta-information about the module
* itself, including the name, its components, and an optional
* module-level initialization or shutdown routine.
*
* @param mVersion : Module Info Version
* @param mModuleName : Module Name
* @param mComponents : Array of Components
* @param mCount : Count of mComponents
* @param mCtor : Module user defined constructor
* @param mDtor : Module user defined destructor
* @param mLibraryDependencies : array of library which this module is
* dependent on.
*
**/
struct nsModuleInfo {
PRUint32 mVersion;
const char* mModuleName;
const nsModuleComponentInfo* mComponents;
PRUint32 mCount;
nsModuleConstructorProc mCtor;
nsModuleDestructorProc mDtor;
const char** mLibraryDependencies;
};
/**
* Rev this if you change the nsModuleInfo, and are worried about
* binary compatibility. (Ostensibly fix NS_NewGenericModule2() to deal
* with older rev's at the same time.)
*/
#define NS_MODULEINFO_VERSION 0x00015000UL // 1.5
/**
* Create a new generic module. Use the NS_IMPL_NSGETMODULE macro, or
* one of its relatives, rather than using this directly.
*/
NS_COM nsresult
NS_NewGenericModule2(nsModuleInfo *info, nsIModule* *result);
/**
* Obsolete. Use NS_NewGenericModule2() instead.
*/
NS_COM nsresult
NS_NewGenericModule(const char* moduleName,
PRUint32 componentCount,
nsModuleComponentInfo* components,
nsModuleDestructorProc dtor,
nsIModule* *result);
#if defined(XPCOM_TRANSLATE_NSGM_ENTRY_POINT)
# define NS_MODULEINFO nsModuleInfo
# define NSMODULEINFO(_name) _name##_gModuleInfo
# define NSGETMODULE_ENTRY_POINT(_info)
# define NSDEPENDENT_LIBS(_name) const char* _name##_gDependlibs[]={DEPENDENT_LIBS "\0"};
# define NSDEPENDENT_LIBS_NAME(_name) _name##_gDependlibs
#else
# define NS_MODULEINFO static nsModuleInfo
# define NSMODULEINFO(_name) gModuleInfo
# define NSDEPENDENT_LIBS(_name) static const char* gDependlibs[]={DEPENDENT_LIBS "\0"};
# define NSDEPENDENT_LIBS_NAME(_name) gDependlibs
# define NSGETMODULE_ENTRY_POINT(_info) \
extern "C" NS_EXPORT nsresult \
NSGetModule(nsIComponentManager *servMgr, \
nsIFile* location, \
nsIModule** result) \
{ \
return NS_NewGenericModule2(&(_info), result); \
}
#endif
/**
* Ease of use Macros which define NSGetModule for your component.
* See xpcom/sample/nsSampleModule.cpp for more info.
*
**/
#define NS_IMPL_NSGETMODULE(_name, _components) \
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, nsnull)
#define NS_IMPL_NSGETMODULE_WITH_CTOR(_name, _components, _ctor) \
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, _ctor, nsnull)
#define NS_IMPL_NSGETMODULE_WITH_DTOR(_name, _components, _dtor) \
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, _dtor)
#ifndef DEPENDENT_LIBS
#define NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, _ctor, _dtor) \
NS_MODULEINFO NSMODULEINFO(_name) = { \
NS_MODULEINFO_VERSION, \
(#_name), \
(_components), \
(sizeof(_components) / sizeof(_components[0])), \
(_ctor), \
(_dtor), \
(nsnull) \
}; \
NSGETMODULE_ENTRY_POINT(NSMODULEINFO(_name))
#else // DEPENDENT_LIBS
#define NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, _ctor, _dtor) \
NSDEPENDENT_LIBS(_name) \
NS_MODULEINFO NSMODULEINFO(_name) = { \
NS_MODULEINFO_VERSION, \
(#_name), \
(_components), \
(sizeof(_components) / sizeof(_components[0])), \
(_ctor), \
(_dtor), \
(NSDEPENDENT_LIBS_NAME(_name)) \
}; \
NSGETMODULE_ENTRY_POINT(NSMODULEINFO(_name))
#endif
////////////////////////////////////////////////////////////////////////////////
#define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass) \
static NS_IMETHODIMP \
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
void **aResult) \
{ \
nsresult rv; \
\
_InstanceClass * inst; \
\
*aResult = NULL; \
if (NULL != aOuter) { \
rv = NS_ERROR_NO_AGGREGATION; \
return rv; \
} \
\
NS_NEWXPCOM(inst, _InstanceClass); \
if (NULL == inst) { \
rv = NS_ERROR_OUT_OF_MEMORY; \
return rv; \
} \
NS_ADDREF(inst); \
rv = inst->QueryInterface(aIID, aResult); \
NS_RELEASE(inst); \
\
return rv; \
} \
#define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
static NS_IMETHODIMP \
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
void **aResult) \
{ \
nsresult rv; \
\
_InstanceClass * inst; \
\
*aResult = NULL; \
if (NULL != aOuter) { \
rv = NS_ERROR_NO_AGGREGATION; \
return rv; \
} \
\
NS_NEWXPCOM(inst, _InstanceClass); \
if (NULL == inst) { \
rv = NS_ERROR_OUT_OF_MEMORY; \
return rv; \
} \
NS_ADDREF(inst); \
rv = inst->_InitMethod(); \
if(NS_SUCCEEDED(rv)) { \
rv = inst->QueryInterface(aIID, aResult); \
} \
NS_RELEASE(inst); \
\
return rv; \
} \
// 'Constructor' that uses an existing getter function that gets a singleton.
// NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
#define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc) \
static NS_IMETHODIMP \
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
void **aResult) \
{ \
nsresult rv; \
\
_InstanceClass * inst; \
\
*aResult = NULL; \
if (NULL != aOuter) { \
rv = NS_ERROR_NO_AGGREGATION; \
return rv; \
} \
\
inst = _GetterProc(); \
if (NULL == inst) { \
rv = NS_ERROR_OUT_OF_MEMORY; \
return rv; \
} \
/* NS_ADDREF(inst); */ \
rv = inst->QueryInterface(aIID, aResult); \
NS_RELEASE(inst); \
\
return rv; \
} \
#endif /* nsIGenericFactory_h___ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -