cleanup NS_IMPL_MODULE and friends

- define new nsModuleComponentInfo and use it instead of components_t
- use size_t instead of unsigned int
- add some docs
- allow user to define own module name


git-svn-id: svn://10.0.0.236/trunk@52452 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
alecf%netscape.com 1999-11-02 01:12:32 +00:00
parent 44d6b4c7e5
commit 54bfc70eea
11 changed files with 111 additions and 255 deletions

View File

@ -26,162 +26,11 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextPS)
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
static components_t components[] =
static nsModuleComponentInfo components[] =
{
{ NS_DEVICECONTEXTPS_CID, &nsDeviceContextPSConstructor, "component://netscape/gfx/decidecontext/ps", "GFX Postscript Device Context", },
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsGfxPSModule, components)
NS_IMPL_NSGETMODULE(nsGfxPSModule)
#if 0
static NS_DEFINE_CID(kCDeviceContextPS, NS_DEVICECONTEXTPS_CID);
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
class nsGfxFactoryPS : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
nsGfxFactoryPS(const nsCID &aClass);
virtual ~nsGfxFactoryPS();
private:
nsCID mClassID;
};
nsGfxFactoryPS::nsGfxFactoryPS(const nsCID &aClass) :
mRefCnt(0),
mClassID(aClass)
{
}
nsGfxFactoryPS::~nsGfxFactoryPS()
{
}
NS_IMPL_ISUPPORTS(nsGfxFactoryPS, nsIFactory::GetIID())
NS_IMETHODIMP
nsGfxFactoryPS::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (aResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
*aResult = nsnull;
nsISupports *inst = nsnull;
if (mClassID.Equals(kCDeviceContextPS)) {
inst = (nsISupports *)(nsIDeviceContextPS*)new nsDeviceContextPS();
}
if (inst == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = inst->QueryInterface(aIID, aResult);
if (rv != NS_OK) {
delete inst;
}
return rv;
}
nsresult nsGfxFactoryPS::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
nsresult
NSGetFactory(nsISupports* servMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if (nsnull == aFactory) {
return NS_ERROR_NULL_POINTER;
}
*aFactory = new nsGfxFactoryPS(aClass);
if (nsnull == aFactory) {
return NS_ERROR_OUT_OF_MEMORY;
}
return (*aFactory)->QueryInterface(nsIFactory::GetIID(), (void**)aFactory);
}
PRBool
NSCanUnload(nsISupports* aServMgr)
{
return PR_TRUE;
}
nsresult
NSRegisterSelf(nsISupports* aServMgr, const char *fullpath)
{
nsresult rv;
#ifdef NS_DEBUG
printf("*** Registering GFX Postscript\n");
#endif
nsCOMPtr<nsIServiceManager>
serviceManager(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kCDeviceContextPS,
"GFX Postscript Device Context",
"component://netscape/gfx/devicecontext/ps",
fullpath,
PR_TRUE, PR_TRUE);
return rv;
}
nsresult
NSUnregisterSelf(nsISupports* aServMgr, const char *fullpath)
{
nsresult rv;
nsCOMPtr<nsIServiceManager>
serviceManager(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
compMgr->UnregisterComponent(kCDeviceContextPS, fullpath);
return NS_OK;
}
#endif /* 0 */

View File

@ -67,14 +67,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSmtpUrl);
static PRInt32 g_InstanceCount = 0;
static PRInt32 g_LockCount = 0;
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
static components_t components[] =
static nsModuleComponentInfo components[] =
{
{ NS_MSGCOMPOSE_CID, &nsMsgComposeConstructor, NS_MSGCOMPOSE_PROGID, },
{ NS_MSGCOMPOSESERVICE_CID, &nsMsgComposeServiceConstructor, NS_MSGCOMPOSESERVICE_PROGID, },
@ -91,5 +84,5 @@ static components_t components[] =
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsMsgComposeModule, components)
NS_IMPL_NSGETMODULE(nsMsgComposeModule)

View File

@ -44,14 +44,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMimeRawEmitter);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMimeXmlEmitter);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMimeXULEmitter);
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
static components_t components[] =
static nsModuleComponentInfo components[] =
{
{ NS_HTML_MIME_EMITTER_CID, &nsMimeHtmlEmitterConstructor, NS_HTML_MIME_EMITTER_PROGID, },
{ NS_XML_MIME_EMITTER_CID, &nsMimeXmlEmitterConstructor, NS_XML_MIME_EMITTER_PROGID, },
@ -59,5 +53,5 @@ static components_t components[] =
{ NS_XUL_MIME_EMITTER_CID, &nsMimeXULEmitterConstructor, NS_XUL_MIME_EMITTER_PROGID, },
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsMimeEmitterModule, components)
NS_IMPL_NSGETMODULE(nsMimeEmitterModule)

View File

@ -54,14 +54,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsNNTPNewsgroupList)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNewsMessage)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgNewsFolder)
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
static components_t components[] =
static nsModuleComponentInfo components[] =
{
{ NS_NNTPURL_CID, &nsNntpUrlConstructor, NS_NNTPURL_PROGID, },
{ NS_NNTPSERVICE_CID, &nsNntpServiceConstructor, NS_NNTPSERVICE_PROGID, },
@ -79,7 +72,7 @@ static components_t components[] =
{ NS_NNTPHOST_CID, &nsNNTPHostConstructor, NS_NNTPHOST_PROGID, },
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsMsgNewsModule, components)
NS_IMPL_NSGETMODULE(nsMsgNewsModule)

View File

@ -35,18 +35,11 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRDFDOMDataSource);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRDFDOMViewerElement);
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
static components_t components[] =
static nsModuleComponentInfo components[] =
{
{ NS_RDF_DOMDATASOURCE_CID, &nsRDFDOMDataSourceConstructor, NS_RDF_DATASOURCE_PROGID_PREFIX "domds", },
{ NS_RDF_DOMRESOURCEFACTORY_CID, &nsRDFDOMViewerElementConstructor, NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "dom", },
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsRDFDOMViewerModule, components)
NS_IMPL_NSGETMODULE(nsRDFDOMViewerModule)

View File

@ -25,18 +25,11 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnixToolkitService)
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
static components_t components[] =
static nsModuleComponentInfo components[] =
{
{ NS_UNIX_TOOLKIT_SERVICE_CID, &nsUnixToolkitServiceConstructor,
NS_UNIX_TOOLKIT_SERVICE_PROGID, "Unix WIndow Service", },
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsToolkitModule, components)
NS_IMPL_NSGETMODULE(nsToolkitModule)

View File

@ -25,18 +25,11 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerGtk)
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
static components_t components[] =
static nsModuleComponentInfo components[] =
{
{ NS_TIMER_GTK_CID, &nsTimerGtkConstructor, "component://netscape/timer/unix/gtk", "GTK timer", },
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsGtkTimerModule, components)
NS_IMPL_NSGETMODULE(nsGtkTimerModule)

View File

@ -128,6 +128,15 @@ _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
} \
// if you add entries to this structure, add them at the
// END so you don't break declarations like
// { NS_MY_CID, &nsMyObjectConstructor, etc.... }
struct nsModuleComponentInfo {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
#define NS_DECL_MODULE(_class) \
class _class : public nsIModule { \
@ -180,7 +189,8 @@ _class::RegisterSelf(nsIComponentManager *aCompMgr, \
const char* componentType) \
{ \
nsresult rv = NS_OK; \
for (unsigned int i=0; i<(sizeof(_table) / sizeof(_table[0])); i++) { \
size_t i; \
for (i=0; i<(sizeof(_table) / sizeof(_table[0])); i++) { \
rv = aCompMgr->RegisterComponentSpec(_table[i].cid, \
_table[i].description, \
_table[i].progid, \
@ -197,7 +207,8 @@ _class::UnregisterSelf(nsIComponentManager *aCompMgr, \
const char* registryLocation) \
{ \
nsresult rv = NS_OK; \
for (unsigned int i=0; i<(sizeof(_table) / sizeof(_table[0])); i++) { \
size_t i; \
for (i=0; i<(sizeof(_table) / sizeof(_table[0])); i++) { \
rv = aCompMgr->UnregisterComponentSpec(_table[i].cid, aPath); \
} \
return rv; \
@ -238,13 +249,34 @@ NSGetModule(nsIComponentManager *servMgr, \
}
#define NS_IMPL_MODULE(_table) \
NS_DECL_MODULE(nsModule) \
NS_IMPL_MODULE_CORE(nsModule) \
NS_IMPL_ISUPPORTS1(nsModule, nsIModule) \
NS_IMPL_MODULE_GETCLASSOBJECT(nsModule, _table) \
NS_IMPL_MODULE_REGISTERSELF(nsModule, _table) \
NS_IMPL_MODULE_UNREGISTERSELF(nsModule, _table) \
NS_IMPL_MODULE_CANUNLOAD(nsModule)
#define NS_IMPL_MODULE(_module, _table) \
NS_DECL_MODULE(_module) \
NS_IMPL_MODULE_CORE(_module) \
NS_IMPL_ISUPPORTS1(_module, nsIModule) \
NS_IMPL_MODULE_GETCLASSOBJECT(_module, _table) \
NS_IMPL_MODULE_REGISTERSELF(_module, _table) \
NS_IMPL_MODULE_UNREGISTERSELF(_module, _table) \
NS_IMPL_MODULE_CANUNLOAD(_module)
// how to use the NS_IMPL_MODULE:
// define your static constructors:
//
// NS_GENERIC_FACTORY_CONSTRUCTOR(nsMyObject1)
// NS_GENERIC_FACTORY_CONSTRUCTOR(nsMyObject2)
//
// define your array of component information:
// static nsModuleComponentInfo components[] =
// {
// { NS_MYOBJECT1_CID, &nsMyObject1Constructor, NS_MYOBJECT1_PROGID, },
// { NS_MYOBJECT2_CID, &nsMyObject2Constructor, NS_MYOBJECT2_PROGID, },
// { NS_MYOBJECT2_CID, &nsMyObject2Constructor, NS_MYoBJECT2_PROGID2, },
// };
//
// NS_IMPL_MODULE(nsMyModule, components)
// NS_IMPL_NSGETMODULE(nsMyModule)
#endif /* nsIGenericFactory_h___ */

View File

@ -128,6 +128,15 @@ _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
} \
// if you add entries to this structure, add them at the
// END so you don't break declarations like
// { NS_MY_CID, &nsMyObjectConstructor, etc.... }
struct nsModuleComponentInfo {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
#define NS_DECL_MODULE(_class) \
class _class : public nsIModule { \
@ -180,7 +189,8 @@ _class::RegisterSelf(nsIComponentManager *aCompMgr, \
const char* componentType) \
{ \
nsresult rv = NS_OK; \
for (unsigned int i=0; i<(sizeof(_table) / sizeof(_table[0])); i++) { \
size_t i; \
for (i=0; i<(sizeof(_table) / sizeof(_table[0])); i++) { \
rv = aCompMgr->RegisterComponentSpec(_table[i].cid, \
_table[i].description, \
_table[i].progid, \
@ -197,7 +207,8 @@ _class::UnregisterSelf(nsIComponentManager *aCompMgr, \
const char* registryLocation) \
{ \
nsresult rv = NS_OK; \
for (unsigned int i=0; i<(sizeof(_table) / sizeof(_table[0])); i++) { \
size_t i; \
for (i=0; i<(sizeof(_table) / sizeof(_table[0])); i++) { \
rv = aCompMgr->UnregisterComponentSpec(_table[i].cid, aPath); \
} \
return rv; \
@ -238,13 +249,34 @@ NSGetModule(nsIComponentManager *servMgr, \
}
#define NS_IMPL_MODULE(_table) \
NS_DECL_MODULE(nsModule) \
NS_IMPL_MODULE_CORE(nsModule) \
NS_IMPL_ISUPPORTS1(nsModule, nsIModule) \
NS_IMPL_MODULE_GETCLASSOBJECT(nsModule, _table) \
NS_IMPL_MODULE_REGISTERSELF(nsModule, _table) \
NS_IMPL_MODULE_UNREGISTERSELF(nsModule, _table) \
NS_IMPL_MODULE_CANUNLOAD(nsModule)
#define NS_IMPL_MODULE(_module, _table) \
NS_DECL_MODULE(_module) \
NS_IMPL_MODULE_CORE(_module) \
NS_IMPL_ISUPPORTS1(_module, nsIModule) \
NS_IMPL_MODULE_GETCLASSOBJECT(_module, _table) \
NS_IMPL_MODULE_REGISTERSELF(_module, _table) \
NS_IMPL_MODULE_UNREGISTERSELF(_module, _table) \
NS_IMPL_MODULE_CANUNLOAD(_module)
// how to use the NS_IMPL_MODULE:
// define your static constructors:
//
// NS_GENERIC_FACTORY_CONSTRUCTOR(nsMyObject1)
// NS_GENERIC_FACTORY_CONSTRUCTOR(nsMyObject2)
//
// define your array of component information:
// static nsModuleComponentInfo components[] =
// {
// { NS_MYOBJECT1_CID, &nsMyObject1Constructor, NS_MYOBJECT1_PROGID, },
// { NS_MYOBJECT2_CID, &nsMyObject2Constructor, NS_MYOBJECT2_PROGID, },
// { NS_MYOBJECT2_CID, &nsMyObject2Constructor, NS_MYoBJECT2_PROGID2, },
// };
//
// NS_IMPL_MODULE(nsMyModule, components)
// NS_IMPL_NSGETMODULE(nsMyModule)
#endif /* nsIGenericFactory_h___ */

View File

@ -2307,18 +2307,9 @@ NS_DEFINE_MODULE_INSTANCE_COUNTER()
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsBrowserInstance, Init)
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
components_t components[] = {
static nsModuleComponentInfo components[] = {
{ NS_BROWSERINSTANCE_CID, &nsBrowserInstanceConstructor, NS_IBROWSERINSTANCE_PROGID, "nsBrowserInstance", },
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsBrowserModule,components)
NS_IMPL_NSGETMODULE(nsBrowserModule)

View File

@ -29,16 +29,9 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrefWindow)
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
components_t components[] = {
static nsModuleComponentInfo components[] = {
{ NS_PREFWINDOW_CID, &nsPrefWindowConstructor, NS_PREFWINDOW_PROGID, "Preferences window helper object", },
};
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)
NS_IMPL_MODULE(nsPrefWindowModule, components)
NS_IMPL_NSGETMODULE(nsPrefWindowModule)