Bug 93100. Change NS_DECL_NSGETMODULE to be table driven so we can get at module ctor & dtor callbacks. Update meta-module and static-module stuff for this change, fix meta-module to not register stuff twice. r=cls,leaf

This commit is contained in:
waterson%netscape.com 2001-08-21 00:55:20 +00:00
Родитель f8d27dba10
Коммит b2442974aa
14 изменённых файлов: 290 добавлений и 612 удалений

Просмотреть файл

@ -1,6 +1,2 @@
nsMetaModule_mail.cpp.sed
nsMetaModule_mail.cpp
nsMetaModule_crypto.cpp.sed
nsMetaModule_crypto.cpp
nsMetaModule_gecko.cpp.sed
nsMetaModule_gecko.cpp
Makefile
nsMetaModule_*

Просмотреть файл

@ -92,17 +92,17 @@ list:
echo $(MOZ_STATIC_COMPONENTS)
ifdef MOZ_STATIC_COMPONENTS
nsStaticModule.cpp: nsStaticModule.cpp.in Makefile Makefile.in $(DEPTH)/config/autoconf.mk
rm -f $@
cat $< | sed -e "s|%COMPONENT_NS_GET_MODULE%|$(foreach m, $(MOZ_STATIC_COMPONENTS), REGISTER_MODULE_USING($(m)_NSGetModule);)|" | \
sed -e "s|%COMPONENT_LIST%|$(foreach m, $(MOZ_STATIC_COMPONENTS), { $(m)_NSGM_comps, $(m)_NSGM_comp_count }, )|" | \
sed -e "s|%DECLARE_COMPONENT_LIST%|$(foreach m,$(MOZ_STATIC_COMPONENTS), extern \"C\" nsresult $(m)_NSGetModule(nsIComponentManager *servMgr, nsIFile* aPath, nsIModule** return_cobj); extern nsModuleComponentInfo* $(m)_NSGM_comps; extern PRUint32 $(m)_NSGM_comp_count;)|" > $@
endif
nsMetaModule_%.cpp: nsMetaModule_%.cpp.in Makefile Makefile.in $(topsrcdir)/config/config.mk
nsStaticModule.cpp: nsMetaModule.cpp.in Makefile Makefile.in $(DEPTH)/config/autoconf.mk
rm -f $@
cat $< | \
sed -e "s|%COMPONENT_NS_GET_MODULE%|$(foreach m, $($(_META_COMPONENT_NAMES)), REGISTER_MODULE_USING($(m)_NSGetModule);)|" | \
sed -e "s|%COMPONENT_LIST%|$(foreach m, $($(_META_COMPONENT_NAMES)), { $(m)_NSGM_comps, $(m)_NSGM_comp_count }, )|" | \
sed -e "s|%DECLARE_COMPONENT_LIST%|$(foreach m,$($(_META_COMPONENT_NAMES)), extern \"C\" nsresult $(m)_NSGetModule(nsIComponentManager *servMgr, nsIFile* aPath, nsIModule** return_cobj); extern nsModuleComponentInfo* $(m)_NSGM_comps; extern PRUint32 $(m)_NSGM_comp_count;)|" > $@
sed -e "s|%DECLARE_SUBMODULE_INFOS%|$(foreach m, $(MOZ_STATIC_COMPONENTS), extern nsModuleInfo NSMODULEINFO($(m));)|" | \
sed -e "s|%SUBMODULE_INFOS%|$(foreach m, $(MOZ_STATIC_COMPONENTS), \\& NSMODULEINFO($(m)),)|" | \
> $@
endif
nsMetaModule_%.cpp: nsMetaModule.cpp.in Makefile Makefile.in $(topsrcdir)/config/config.mk
rm -f $@
cat $< | \
sed -e "s|%DECLARE_SUBMODULE_INFOS%|$(foreach m, $($(_META_COMPONENT_NAMES)), extern nsModuleInfo NSMODULEINFO($(m));)|" | \
sed -e "s|%SUBMODULE_INFOS%|$(foreach m, $($(_META_COMPONENT_NAMES)), \\& NSMODULEINFO($(m),)|" | \
> $@

Просмотреть файл

@ -37,6 +37,7 @@ EXTRA_LIBS_LIST_FILE = $(OBJDIR)\$(META_MODULE)-libs.txt
GARBAGE = $(GARBAGE) $(SEDCMDS) $(LIBFILE) nsMetaModule_$(META_MODULE).cpp
LCFLAGS = $(LCFLAGS) -DMETA_MODULE=\"$(META_MODULE)\"
CPP_OBJS = .\$(OBJDIR)\nsMetaModule_$(META_MODULE).obj
# XXX Lame! This is currently the superset of all static libraries not
@ -73,23 +74,20 @@ include <$(DEPTH)/config/rules.mak>
$(SEDCMDS): $(LINK_COMP_NAMES)
echo +++make: Creating $@
rm -f $@
echo s/%COMPONENT_NS_GET_MODULE%/\>> $@
sed -e "s/\(.*\)/REGISTER_MODULE_USING(\1_NSGetModule);\\\/" $(LINK_COMP_NAMES) >> $@
echo s/%DECLARE_SUBMODULE_INFOS%/\>> $@
sed -e "s/\(.*\)/extern nsModuleInfo NSMODULEINFO(\1);\\\/" $(LINK_COMP_NAMES) >> $@
echo />> $@
echo s/%COMPONENT_LIST%/\>> $@
sed -e "s/\(.*\)/{ \1_NSGM_comps, \1_NSGM_comp_count },\\\/" $(LINK_COMP_NAMES) >> $@
echo />> $@
echo s/%DECLARE_COMPONENT_LIST%/\>> $@
sed -e "s/\(.*\)/extern \"C\" nsresult \1_NSGetModule(nsIComponentManager*, nsIFile*, nsIModule**); extern nsModuleComponentInfo* \1_NSGM_comps; extern PRUint32 \1_NSGM_comp_count;\\\/" $(LINK_COMP_NAMES) >> $@
echo s/%SUBMODULE_INFOS%/\>> $@
sed -e "s/\(.*\)/\\\\\& NSMODULEINFO(\1),\\\/" $(LINK_COMP_NAMES) >> $@
echo />> $@
#
# Create nsMetaModule_(foo).cpp from nsMetaModule_(foo).cpp.in
# Create nsMetaModule_(foo).cpp from nsMetaModule.cpp.in
#
nsMetaModule_$(META_MODULE).cpp: nsMetaModule_$(META_MODULE).cpp.in $(SEDCMDS)
nsMetaModule_$(META_MODULE).cpp: nsMetaModule.cpp.in $(SEDCMDS)
echo +++make: Creating $@
rm -f $@
sed -f $(SEDCMDS) nsMetaModule_$(META_MODULE).cpp.in > $@
sed -f $(SEDCMDS) nsMetaModule.cpp.in > $@
#
# If no link components file has been created, make an empty one now.
@ -130,6 +128,7 @@ export::
copy $(FINAL_LINK_COMP_NAMES) $(DIST)\$(META_MODULE)-link-comp-names
!endif
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)/bin/components

Просмотреть файл

@ -0,0 +1,119 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Christopher Seawood <cls@seawood.org>
* Doug Turner <dougt@netscape.com>
* Chris Waterson <waterson@netscape.com>
*/
#line 27 "nsMetaModule.cpp.in"
#include "nsError.h"
#include "nsIModule.h"
#include "nsIFile.h"
#include "nsIGenericFactory.h"
#include "prmem.h"
%DECLARE_SUBMODULE_INFOS%
#line 35 "nsMetaModule.cpp.in"
static nsModuleInfo* gSubModules[] = {
%SUBMODULE_INFOS%
#line 39 "nsMetaModule.cpp.in"
};
#define NUM_SUB_MODULES (sizeof(gSubModules) / sizeof(gSubModules[0]))
static nsModuleComponentInfo* gComponentInfo;
static PRBool gInitialized = PR_FALSE;
PR_STATIC_CALLBACK(nsresult)
Initialize(nsIModule *self)
{
if (! gInitialized) {
// Run the ctor for each sub-module
gInitialized = PR_TRUE;
nsModuleInfo** module = gSubModules;
nsModuleInfo** limit = module + NUM_SUB_MODULES;
for ( ; module < limit; ++module) {
if ((*module)->mCtor)
((*module)->mCtor)(self);
}
}
return NS_OK;
}
PR_STATIC_CALLBACK(void)
Shutdown(nsIModule *self)
{
if (gInitialized) {
// Run the dtor for each sub-module
gInitialized = PR_FALSE;
nsModuleInfo** module = gSubModules;
nsModuleInfo** limit = module + NUM_SUB_MODULES;
for ( ; module < limit; ++module) {
if ((*module)->mDtor)
((*module)->mDtor)(self);
}
}
}
extern "C" NS_EXPORT nsresult
NSGetModule(nsIComponentManager *servMgr,
nsIFile *location,
nsIModule **result)
{
// Count the number of components contained in all of the
// sub-modules
nsModuleInfo** info = gSubModules;
nsModuleInfo** limit = info + NUM_SUB_MODULES;
PRUint32 count = 0;
for ( ; info < limit; ++info)
count += (*info)->mCount;
// Allocate an nsModuleComponentInfo array large enough to contain
// all of them. This will be permanently leaked.
gComponentInfo = new nsModuleComponentInfo[count];
if (! gComponentInfo)
return NS_ERROR_OUT_OF_MEMORY;
// Copy the module component info into the contiguous array
nsModuleComponentInfo *comps = gComponentInfo;
for (info = gSubModules; info < limit; ++info) {
PRUint32 n = (*info)->mCount;
::memcpy(comps, (*info)->mComponents, sizeof(nsModuleComponentInfo) * n);
comps += n;
}
// Dummy up an nsModuleInfo struct to register us as a generic
// module that contains all our sub-module's components.
nsModuleInfo metainfo;
metainfo.mVersion = NS_MODULEINFO_VERSION;
metainfo.mModuleName = META_MODULE " meta module";
metainfo.mComponents = gComponentInfo;
metainfo.mCount = count;
metainfo.mCtor = Initialize;
metainfo.mDtor = Shutdown;
return NS_NewGenericModule(&metainfo, result);
}

Просмотреть файл

@ -1,159 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Christopher Seawood <cls@seawood.org>
* Doug Turner <dougt@netscape.com>
*/
#include "nsError.h"
#include "nsIModule.h"
#include "nsIFile.h"
#include "nsIGenericFactory.h"
#include "prmem.h"
#define META_DESTRUCTOR_FUNC MetaModuleDestructorCrypto
#define NS_METAMODULE_NAME "nsMetaModuleCrypto"
#define NS_METAMODULE_DESC "Meta Component Crypto"
#define NS_METAMODULE_CID \
{ 0xcccc3240, 0x1dd1, 0x11b2, { 0xb2, 0x11, 0xc0, 0x85, 0x1f, 0xe2, 0xa6, 0xf6 } }
#define NS_METAMODULE_CONTRACTID "@mozilla.org/metamodule_crypto;1"
/*
* NO USER EDITABLE PORTIONS AFTER THIS POINT
*
*/
#define REGISTER_MODULE_USING(mod) { \
nsCOMPtr<nsIModule> module; \
mod##(aCompMgr, aPath, getter_AddRefs(module)); \
module->RegisterSelf(aCompMgr, aPath, aRegistryLocation, aComponentType); \
}
struct nsModuleComponentInfoContainer {
nsModuleComponentInfo *list;
PRUint32 count;
};
%DECLARE_COMPONENT_LIST%
static nsresult
NS_RegisterMetaModules(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *aRegistryLocation,
const char *aComponentType)
{
nsresult rv = NS_OK;
%COMPONENT_NS_GET_MODULE%
{};
return rv;
}
void META_DESTRUCTOR_FUNC(nsIModule *self, nsModuleComponentInfo *components)
{
PR_Free(components);
}
class nsMetaModuleImpl : public nsISupports
{
public:
nsMetaModuleImpl();
virtual ~nsMetaModuleImpl();
NS_DECL_ISUPPORTS
};
nsMetaModuleImpl::nsMetaModuleImpl()
{
NS_INIT_REFCNT();
}
nsMetaModuleImpl::~nsMetaModuleImpl()
{
}
NS_IMPL_ISUPPORTS1(nsMetaModuleImpl, nsISupports);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMetaModuleImpl)
static NS_METHOD nsMetaModuleRegistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
NS_RegisterMetaModules(aCompMgr, aPath, registryLocation, componentType);
return NS_OK;
}
static NS_METHOD nsMetaModuleUnregistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const nsModuleComponentInfo *info)
{
return NS_OK;
}
static nsModuleComponentInfo components[] =
{
{ NS_METAMODULE_DESC,
NS_METAMODULE_CID,
NS_METAMODULE_CONTRACTID,
nsMetaModuleImplConstructor,
nsMetaModuleRegistrationProc,
nsMetaModuleUnregistrationProc
},
};
static nsModuleComponentInfoContainer componentsList[] = {
{ components, sizeof(components)/sizeof(components[0]) },
%COMPONENT_LIST%
{ nsnull, 0 }
};
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFile* location,
nsIModule** result)
{
nsModuleComponentInfo *outList = nsnull;
nsModuleComponentInfoContainer *inList = componentsList;
PRUint32 count = 0, i = 0, k=0, msize = sizeof(nsModuleComponentInfo);
while (inList[i].list != nsnull) {
count += inList[i].count;
i++;
}
outList = (nsModuleComponentInfo *) PR_Calloc(count, sizeof(nsModuleComponentInfo));
i = 0; k =0;
while (inList[i].list != nsnull) {
memcpy(&outList[k], inList[i].list, msize * inList[i].count);
k+= inList[i].count;
i++;
}
return NS_NewGenericModule(NS_METAMODULE_NAME, count, outList, nsnull, nsnull, result);
}

Просмотреть файл

@ -1,162 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Christopher Seawood <cls@seawood.org>
* Doug Turner <dougt@netscape.com>
*/
#include "nsError.h"
#include "nsIModule.h"
#include "nsIFile.h"
#include "nsIGenericFactory.h"
#include "prmem.h"
#define META_DESTRUCTOR_FUNC MetaModuleDestructorMail
#define NS_METAMODULE_NAME "nsMetaModuleMail"
#define NS_METAMODULE_DESC "Meta Component Mail"
#define NS_METAMODULE_CID \
{ 0xda364d3c, 0x1dd1, 0x11b2, { 0xbd, 0xfd, 0x9d, 0x6f, 0xb7, 0x55, 0x30, 0x35 } }
#define NS_METAMODULE_CONTRACTID "@mozilla.org/metamodule_mail;1"
/*
* NO USER EDITABLE PORTIONS AFTER THIS POINT
*
*/
#define REGISTER_MODULE_USING(mod) { \
nsCOMPtr<nsIModule> module; \
mod##(aCompMgr, aPath, getter_AddRefs(module)); \
module->RegisterSelf(aCompMgr, aPath, aRegistryLocation, aComponentType); \
}
struct nsModuleComponentInfoContainer {
nsModuleComponentInfo *list;
PRUint32 count;
};
%DECLARE_COMPONENT_LIST%
static nsresult
NS_RegisterMetaModules(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *aRegistryLocation,
const char *aComponentType)
{
nsresult rv = NS_OK;
%COMPONENT_NS_GET_MODULE%
{};
return rv;
}
void META_DESTRUCTOR_FUNC(nsIModule *self, nsModuleComponentInfo *components)
{
PR_Free(components);
}
class nsMetaModuleImpl : public nsISupports
{
public:
nsMetaModuleImpl();
virtual ~nsMetaModuleImpl();
NS_DECL_ISUPPORTS
};
nsMetaModuleImpl::nsMetaModuleImpl()
{
NS_INIT_REFCNT();
}
nsMetaModuleImpl::~nsMetaModuleImpl()
{
}
NS_IMPL_ISUPPORTS1(nsMetaModuleImpl, nsISupports);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMetaModuleImpl)
static NS_METHOD nsMetaModuleRegistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
NS_RegisterMetaModules(aCompMgr, aPath, registryLocation, componentType);
return NS_OK;
}
static NS_METHOD nsMetaModuleUnregistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const nsModuleComponentInfo *info)
{
return NS_OK;
}
static nsModuleComponentInfo components[] =
{
{ NS_METAMODULE_DESC,
NS_METAMODULE_CID,
NS_METAMODULE_CONTRACTID,
nsMetaModuleImplConstructor,
nsMetaModuleRegistrationProc,
nsMetaModuleUnregistrationProc
},
};
static nsModuleComponentInfoContainer componentsList[] = {
{ components, sizeof(components)/sizeof(components[0]) },
%COMPONENT_LIST%
{ nsnull, 0 }
};
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFile* location,
nsIModule** result)
{
nsModuleComponentInfo *outList = nsnull;
nsModuleComponentInfoContainer *inList = componentsList;
PRUint32 count = 0, i = 0, k=0, msize = sizeof(nsModuleComponentInfo);
while (inList[i].list != nsnull) {
count += inList[i].count;
i++;
}
outList = (nsModuleComponentInfo *) PR_Calloc(count, sizeof(nsModuleComponentInfo));
i = 0; k =0;
while (inList[i].list != nsnull) {
memcpy(&outList[k], inList[i].list, msize * inList[i].count);
k+= inList[i].count;
i++;
}
return NS_NewGenericModule(NS_METAMODULE_NAME, count, outList, nsnull, nsnull, result);
}

Просмотреть файл

@ -1,158 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Christopher Seawood <cls@seawood.org>
* Doug Turner <dougt@netscape.com>
*/
#include "nsError.h"
#include "nsIModule.h"
#include "nsIFile.h"
#include "nsIGenericFactory.h"
#include "prmem.h"
#define REGISTER_MODULE_USING(mod) { \
nsCOMPtr<nsIModule> module; \
mod##(compMgr, aPath, getter_AddRefs(module)); \
module->RegisterSelf(compMgr, aPath, "", ""); \
}
struct nsModuleComponentInfoContainer {
nsModuleComponentInfo *list;
PRUint32 count;
};
%DECLARE_COMPONENT_LIST%
static nsresult
NS_RegisterStaticModules(nsIFile *aPath)
{
nsresult rv = PR_TRUE;
nsIComponentManager *compMgr = nsnull;
rv = NS_GetGlobalComponentManager(&compMgr);
NS_ASSERTION(NS_SUCCEEDED(rv), "Static mods cannot get global component manager.");
%COMPONENT_NS_GET_MODULE%
{};
return rv;
}
void StaticModuleDestructor(nsIModule *self, nsModuleComponentInfo *components)
{
PR_Free(components);
}
#define NS_STATICMODULE_CID \
{ 0x1926250e, 0xef22, 0x4c8d, { 0x94, 0x37, 0x86, 0xa8, 0x07, 0xeb, 0xe4, 0xca } }
#define NS_STATICMODULE_CONTRACTID "@mozilla.org/staticmodule;1"
class nsStaticModuleImpl : public nsISupports
{
public:
nsStaticModuleImpl();
virtual ~nsStaticModuleImpl();
NS_DECL_ISUPPORTS
};
nsStaticModuleImpl::nsStaticModuleImpl()
{
NS_INIT_REFCNT();
}
nsStaticModuleImpl::~nsStaticModuleImpl()
{
}
NS_IMPL_ISUPPORTS1(nsStaticModuleImpl, nsISupports);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsStaticModuleImpl)
static NS_METHOD nsStaticModuleRegistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
NS_RegisterStaticModules(aPath);
return NS_OK;
}
static NS_METHOD nsStaticModuleUnregistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const nsModuleComponentInfo *info)
{
return NS_OK;
}
static nsModuleComponentInfo components[] =
{
{ "Static Component",
NS_STATICMODULE_CID,
NS_STATICMODULE_CONTRACTID,
nsStaticModuleImplConstructor,
nsStaticModuleRegistrationProc,
nsStaticModuleUnregistrationProc
},
};
static nsModuleComponentInfoContainer componentsList[] = {
{ components, sizeof(components)/sizeof(components[0]) },
%COMPONENT_LIST%
{ nsnull, 0 }
};
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFile* location,
nsIModule** result)
{
nsModuleComponentInfo *outList = nsnull;
nsModuleComponentInfoContainer *inList = componentsList;
PRUint32 count = 0, i = 0, k=0, msize = sizeof(nsModuleComponentInfo);
while (inList[i].list != nsnull) {
count += inList[i].count;
i++;
}
outList = (nsModuleComponentInfo *) PR_Calloc(count, sizeof(nsModuleComponentInfo));
i = 0; k =0;
while (inList[i].list != nsnull) {
memcpy(&outList[k], inList[i].list, msize * inList[i].count);
k+= inList[i].count;
i++;
}
return NS_NewGenericModule("nsStaticModule", count, outList, nsnull, result);
}

Просмотреть файл

@ -262,8 +262,13 @@ nsGenericModule::Initialize()
void
nsGenericModule::Shutdown()
{
if (mDtor)
mDtor(this);
if (mInitialized) {
mInitialized = PR_FALSE;
if (mDtor)
mDtor(this);
}
// Release the factory objects
mFactories.Reset();
}
@ -410,23 +415,17 @@ nsGenericModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
}
NS_COM nsresult
NS_NewGenericModule(const char* moduleName,
PRUint32 componentCount,
nsModuleComponentInfo* components,
nsModuleConstructorProc ctor,
nsModuleDestructorProc dtor,
nsIModule* *result)
NS_NewGenericModule(nsModuleInfo* info, nsIModule* *result)
{
nsresult rv = NS_OK;
NS_ASSERTION(result, "Null argument");
// Create and initialize the module instance
nsGenericModule *m =
new nsGenericModule(moduleName, componentCount, components, ctor, dtor);
if (!m) {
new nsGenericModule(info->mModuleName, info->mCount, info->mComponents,
info->mCtor, info->mDtor);
if (!m)
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)result);

Просмотреть файл

@ -106,25 +106,46 @@ struct nsModuleComponentInfo {
PRUint32 mFlags;
};
typedef void (PR_CALLBACK *nsModuleDestructorProc) (nsIModule *self);
typedef nsresult (PR_CALLBACK *nsModuleConstructorProc) (nsIModule *self);
typedef void (PR_CALLBACK *nsModuleDestructorProc) (nsIModule *self);
/**
* 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.
*/
struct nsModuleInfo {
PRUint32 mVersion;
const char* mModuleName;
nsModuleComponentInfo* mComponents;
PRUint32 mCount;
nsModuleConstructorProc mCtor;
nsModuleDestructorProc mDtor;
};
/**
* Rev this if you change the nsModuleInfo, and are worried about
* binary compatibility. (Ostensibly fix NS_NewGenericModule() to deal
* with older rev's at the same time.)
*/
#define NS_MODULEINFO_VERSION 0x00010000UL // 1.0
extern NS_COM nsresult
NS_NewGenericModule(const char* moduleName,
PRUint32 componentCount,
nsModuleComponentInfo* components,
nsModuleConstructorProc ctor,
nsModuleDestructorProc dtor,
nsIModule* *result);
NS_NewGenericModule(nsModuleInfo *info, nsIModule* *result);
#if defined(XPCOM_TRANSLATE_NSGM_ENTRY_POINT)
# define NSGETMODULE_ENTRY_POINT(_name) _name##_NSGetModule
# define NSGETMODULE_COMPONENTS(_name) _name##_NSGM_comps
# define NSGETMODULE_COMPONENTS_COUNT(_name) _name##_NSGM_comp_count
# define NSMODULEINFO(_name) _name##_gModuleInfo
# define NSGETMODULE_ENTRY_POINT(_info)
#else
# define NSGETMODULE_ENTRY_POINT(_name) NSGetModule
# define NSGETMODULE_COMPONENTS(_name) NSGetModule_components
# define NSGETMODULE_COMPONENTS_COUNT(_name) NSGetModule_components_count
# define NSMODULEINFO(_name) gModuleInfo
# define NSGETMODULE_ENTRY_POINT(_info) \
extern "C" NS_EXPORT nsresult \
NSGetModule(nsIComponentManager *servMgr, \
nsIFile* location, \
nsIModule** result) \
{ \
return NS_NewGenericModule(&(_info), result); \
}
#endif
#define NS_IMPL_NSGETMODULE(_name, _components) \
@ -137,24 +158,15 @@ NS_NewGenericModule(const char* moduleName,
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, _dtor)
#define NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, _ctor, _dtor) \
\
PRUint32 \
NSGETMODULE_COMPONENTS_COUNT(_name) = \
sizeof(_components) / sizeof(_components[0]); \
\
\
nsModuleComponentInfo* NSGETMODULE_COMPONENTS(_name) = (_components); \
\
extern "C" NS_EXPORT nsresult \
NSGETMODULE_ENTRY_POINT(_name) (nsIComponentManager *servMgr, \
nsIFile* location, \
nsIModule** result) \
{ \
return NS_NewGenericModule((#_name), \
NSGETMODULE_COMPONENTS_COUNT(_name), \
NSGETMODULE_COMPONENTS(_name), \
_ctor, _dtor, result); \
}
nsModuleInfo NSMODULEINFO(_name) = { \
NS_MODULEINFO_VERSION, \
(#_name), \
(_components), \
(sizeof(_components) / sizeof(_components[0])), \
(_ctor), \
(_dtor) \
}; \
NSGETMODULE_ENTRY_POINT(NSMODULEINFO(_name))
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -262,8 +262,13 @@ nsGenericModule::Initialize()
void
nsGenericModule::Shutdown()
{
if (mDtor)
mDtor(this);
if (mInitialized) {
mInitialized = PR_FALSE;
if (mDtor)
mDtor(this);
}
// Release the factory objects
mFactories.Reset();
}
@ -410,23 +415,17 @@ nsGenericModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
}
NS_COM nsresult
NS_NewGenericModule(const char* moduleName,
PRUint32 componentCount,
nsModuleComponentInfo* components,
nsModuleConstructorProc ctor,
nsModuleDestructorProc dtor,
nsIModule* *result)
NS_NewGenericModule(nsModuleInfo* info, nsIModule* *result)
{
nsresult rv = NS_OK;
NS_ASSERTION(result, "Null argument");
// Create and initialize the module instance
nsGenericModule *m =
new nsGenericModule(moduleName, componentCount, components, ctor, dtor);
if (!m) {
new nsGenericModule(info->mModuleName, info->mCount, info->mComponents,
info->mCtor, info->mDtor);
if (!m)
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)result);

Просмотреть файл

@ -106,25 +106,46 @@ struct nsModuleComponentInfo {
PRUint32 mFlags;
};
typedef void (PR_CALLBACK *nsModuleDestructorProc) (nsIModule *self);
typedef nsresult (PR_CALLBACK *nsModuleConstructorProc) (nsIModule *self);
typedef void (PR_CALLBACK *nsModuleDestructorProc) (nsIModule *self);
/**
* 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.
*/
struct nsModuleInfo {
PRUint32 mVersion;
const char* mModuleName;
nsModuleComponentInfo* mComponents;
PRUint32 mCount;
nsModuleConstructorProc mCtor;
nsModuleDestructorProc mDtor;
};
/**
* Rev this if you change the nsModuleInfo, and are worried about
* binary compatibility. (Ostensibly fix NS_NewGenericModule() to deal
* with older rev's at the same time.)
*/
#define NS_MODULEINFO_VERSION 0x00010000UL // 1.0
extern NS_COM nsresult
NS_NewGenericModule(const char* moduleName,
PRUint32 componentCount,
nsModuleComponentInfo* components,
nsModuleConstructorProc ctor,
nsModuleDestructorProc dtor,
nsIModule* *result);
NS_NewGenericModule(nsModuleInfo *info, nsIModule* *result);
#if defined(XPCOM_TRANSLATE_NSGM_ENTRY_POINT)
# define NSGETMODULE_ENTRY_POINT(_name) _name##_NSGetModule
# define NSGETMODULE_COMPONENTS(_name) _name##_NSGM_comps
# define NSGETMODULE_COMPONENTS_COUNT(_name) _name##_NSGM_comp_count
# define NSMODULEINFO(_name) _name##_gModuleInfo
# define NSGETMODULE_ENTRY_POINT(_info)
#else
# define NSGETMODULE_ENTRY_POINT(_name) NSGetModule
# define NSGETMODULE_COMPONENTS(_name) NSGetModule_components
# define NSGETMODULE_COMPONENTS_COUNT(_name) NSGetModule_components_count
# define NSMODULEINFO(_name) gModuleInfo
# define NSGETMODULE_ENTRY_POINT(_info) \
extern "C" NS_EXPORT nsresult \
NSGetModule(nsIComponentManager *servMgr, \
nsIFile* location, \
nsIModule** result) \
{ \
return NS_NewGenericModule(&(_info), result); \
}
#endif
#define NS_IMPL_NSGETMODULE(_name, _components) \
@ -137,24 +158,15 @@ NS_NewGenericModule(const char* moduleName,
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, _dtor)
#define NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, _ctor, _dtor) \
\
PRUint32 \
NSGETMODULE_COMPONENTS_COUNT(_name) = \
sizeof(_components) / sizeof(_components[0]); \
\
\
nsModuleComponentInfo* NSGETMODULE_COMPONENTS(_name) = (_components); \
\
extern "C" NS_EXPORT nsresult \
NSGETMODULE_ENTRY_POINT(_name) (nsIComponentManager *servMgr, \
nsIFile* location, \
nsIModule** result) \
{ \
return NS_NewGenericModule((#_name), \
NSGETMODULE_COMPONENTS_COUNT(_name), \
NSGETMODULE_COMPONENTS(_name), \
_ctor, _dtor, result); \
}
nsModuleInfo NSMODULEINFO(_name) = { \
NS_MODULEINFO_VERSION, \
(#_name), \
(_components), \
(sizeof(_components) / sizeof(_components[0])), \
(_ctor), \
(_dtor) \
}; \
NSGETMODULE_ENTRY_POINT(NSMODULEINFO(_name))
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -266,7 +266,7 @@ endif
nsStaticComponents.cpp: nsStaticComponents.cpp.in Makefile Makefile.in $(FINAL_LINK_COMP_NAMES)
rm -f $@
cat $< | \
sed -e "s|%DECLARE_COMPONENTS%|$(foreach m,$(_COMPONENT_LIST),DECL_MODULE($(m));)|" | \
sed -e "s|%COMPONENT_LIST%|$(foreach m, $(_COMPONENT_LIST),MODULE($(m)),)|" \
sed -e "s|%DECL_NSGETMODULES%|$(foreach m,$(_COMPONENT_LIST),DECL_NSGETMODULE($(m)))|" | \
sed -e "s|%MODULE_LIST%|$(foreach m, $(_COMPONENT_LIST),MODULE($(m)),)|" \
> $@

Просмотреть файл

@ -144,10 +144,10 @@ include <$(DEPTH)\config\rules.mak>
$(SEDCMDS): $(FINAL_LINK_COMP_NAMES)
rm -f $@
echo s/%DECLARE_COMPONENTS%/\>> $@
sed -e "s/^/DECL_MODULE(/" -e "s/$$/);\\\/" $(FINAL_LINK_COMP_NAMES) >> $@
echo s/%DECL_NSGETMODULES%/\>> $@
sed -e "s/^/DECL_NSGETMODULE(/" -e "s/$$/)\\\/" $(FINAL_LINK_COMP_NAMES) >> $@
echo />> $@
echo s/%COMPONENT_LIST%/\>> $@
echo s/%MODULE_LIST%/\>> $@
sed -e "s/^/MODULE(/" -e "s/$$/),\\\/" $(FINAL_LINK_COMP_NAMES) >> $@
echo />> $@

Просмотреть файл

@ -19,33 +19,54 @@
*
* Contributor(s):
* Christopher Seawood <cls@seawood.org>
* Chris Waterson <waterson@netscape.com>
*/
#line 26 "nsStaticComponents.cpp.in"
#define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1
#include "nsIGenericFactory.h"
#include "nsStaticComponent.h"
/**
* Construct a unique NSGetModule entry point for a generic module.
*/
#define NSGETMODULE(_name) _name##_NSGetmodule
#define MODULE(name) { #name "_NSGetModule", NSGETMODULE_ENTRY_POINT(name) }
#define DECL_MODULE(name) \
extern "C" nsresult \
NSGETMODULE_ENTRY_POINT(name) (nsIComponentManager *aCompMgr, \
nsIFile *aLocation, \
nsIModule **aResult)
/**
* Declare an NSGetModule() routine for a generic module.
*/
#define DECL_NSGETMODULE(_name) \
extern nsModuleInfo NSMODULEINFO(_name); \
extern "C" NS_EXPORT nsresult \
NSGETMODULE(_name) (nsIComponentManager* aCompMgr, \
nsIFile* aLocation, \
nsIModule** aResult) \
{ \
return NS_NewGenericModule(&NSMODULEINFO(_name), aResult); \
}
%DECLARE_COMPONENTS%
// NSGetModule entry points
%DECL_NSGETMODULES%
#line 52 "nsStaticComponents.cpp.in"
static nsStaticModuleInfo StaticModuleInfo[] = {
%COMPONENT_LIST%
/**
* The nsStaticModuleInfo
*/
static nsStaticModuleInfo gStaticModuleInfo[] = {
#define MODULE(_name) { (#_name), NSGETMODULE(_name) }
%MODULE_LIST%
#line 60 "nsStaticComponents.cpp.in"
};
nsresult PR_CALLBACK
/**
* Our NSGetStaticModuleInfoFunc
*/
nsresult
apprunner_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count)
{
*info = StaticModuleInfo;
*count = sizeof(StaticModuleInfo) / sizeof(StaticModuleInfo[0]);
*info = gStaticModuleInfo;
*count = sizeof(gStaticModuleInfo) / sizeof(gStaticModuleInfo[0]);
return NS_OK;
}