Converted dll to use nsIModule -bug 14034, r=jband

This commit is contained in:
neeti%netscape.com 1999-10-16 03:04:16 +00:00
Родитель 6c598ad724
Коммит cda59394de
1 изменённых файлов: 425 добавлений и 184 удалений

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

@ -35,213 +35,454 @@
/* module registration and factory code. */
#include "xpctest_private.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
// Module implementation
class nsXPCTestModule : public nsIModule
{
nsresult rv;
NS_ASSERTION(aFactory != nsnull, "bad factory pointer");
public:
nsXPCTestModule();
virtual ~nsXPCTestModule();
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
NS_DECL_ISUPPORTS
nsIGenericFactory* factory;
rv = compMgr->CreateInstance(kGenericFactoryCID, nsnull,
nsIGenericFactory::GetIID(),
(void**)&factory);
if (NS_FAILED(rv)) return rv;
NS_DECL_NSIMODULE
// add more factories as 'if else's below...
protected:
nsresult Initialize();
if(aClass.Equals(xpctest::GetEchoCID()))
rv = factory->SetConstructor(xpctest::ConstructEcho);
else if(aClass.Equals(xpctest::GetChildCID()))
rv = factory->SetConstructor(xpctest::ConstructChild);
else if(aClass.Equals(xpctest::GetNoisyCID()))
rv = factory->SetConstructor(xpctest::ConstructNoisy);
else if(aClass.Equals(xpctest::GetStringTestCID()))
rv = factory->SetConstructor(xpctest::ConstructStringTest);
else if(aClass.Equals(xpctest::GetOverloadedCID()))
rv = factory->SetConstructor(xpctest::ConstructOverloaded);
else if(aClass.Equals(xpctest::GetXPCTestObjectReadOnlyCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestObjectReadOnly);
else if(aClass.Equals(xpctest::GetXPCTestObjectReadWriteCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestObjectReadWrite);
else if(aClass.Equals(xpctest::GetXPCTestInCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestIn);
else if(aClass.Equals(xpctest::GetXPCTestOutCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestOut);
else if(aClass.Equals(xpctest::GetXPCTestInOutCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestInOut);
else if(aClass.Equals(xpctest::GetXPCTestCallJSCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestCallJS);
else if(aClass.Equals(xpctest::GetXPCTestConstCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestConst);
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mEchoFactory;
nsCOMPtr<nsIGenericFactory> mChildFactory;
nsCOMPtr<nsIGenericFactory> mNoisyFactory;
nsCOMPtr<nsIGenericFactory> mStringTestFactory;
nsCOMPtr<nsIGenericFactory> mOverloadedFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestObjectReadOnlyFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestObjectReadWriteFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestInFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestOutFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestInOutFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestCallJSFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestConstFactory;
#if (0)
else if(aClass.Equals(xpctest::GetXPCTestConstructWithArgsCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestConstructWithArgs);
else if(aClass.Equals(xpctest::GetXPCTestScriptableCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestScriptable);
nsCOMPtr<nsIGenericFactory> mXPCTestContructWithArgsFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestScriptableFactory;
#endif /* 0 */
else if(aClass.Equals(xpctest::GetXPCTestParentOneCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestParentOne);
else if(aClass.Equals(xpctest::GetXPCTestParentTwoCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestParentTwo);
else if(aClass.Equals(xpctest::GetXPCTestChild2CID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestChild2);
else if(aClass.Equals(xpctest::GetXPCTestChild3CID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestChild3);
else if(aClass.Equals(xpctest::GetXPCTestChild4CID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestChild4);
else if(aClass.Equals(xpctest::GetXPCTestChild5CID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestChild5);
else if(aClass.Equals(xpctest::GetArrayTestCID()))
rv = factory->SetConstructor(xpctest::ConstructArrayTest);
else
nsCOMPtr<nsIGenericFactory> mXPCTestParentOneFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestParentTwoFactory;
nsCOMPtr<nsIGenericFactory> mXPCTestChild2Factory;
nsCOMPtr<nsIGenericFactory> mXPCTestChild3Factory;
nsCOMPtr<nsIGenericFactory> mXPCTestChild4Factory;
nsCOMPtr<nsIGenericFactory> mXPCTestChild5Factory;
nsCOMPtr<nsIGenericFactory> mArrayTestFactory;
};
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
nsXPCTestModule::nsXPCTestModule()
: mInitialized(PR_FALSE)
{
NS_ASSERTION(0, "incorrectly registered");
rv = NS_ERROR_NO_INTERFACE;
NS_INIT_ISUPPORTS();
}
if (NS_FAILED(rv)) {
NS_RELEASE(factory);
return rv;
nsXPCTestModule::~nsXPCTestModule()
{
Shutdown();
}
*aFactory = factory;
NS_IMPL_ISUPPORTS(nsXPCTestModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsXPCTestModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
// Shutdown this module, releasing all of the module resources
void
nsXPCTestModule::Shutdown()
{
nsresult rv;
#ifdef DEBUG
printf("*** Register XPConnect test components\n");
#endif
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(xpctest::GetEchoCID(),
"nsEcho", "nsEcho", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetChildCID(),
"nsChild", "nsChild", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetNoisyCID(),
"nsNoisy", "nsNoisy", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetStringTestCID(),
"nsStringTest", "nsStringTest", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetOverloadedCID(),
"nsOverloaded", "nsOverloaded", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestObjectReadOnlyCID(),
"xpcTestObjectReadOnly", "xpcTestObjectReadOnly", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetArrayTestCID(),
"nsArrayTest", "nsArrayTest", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestObjectReadWriteCID(),
"xpcTestObjectReadWrite", "xpcTestObjectReadWrite", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestInCID(),
"xpcTestIn", "xpcTestIn", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestOutCID(),
"xpcTestOut", "xpcTestOut", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestInOutCID(),
"xpcTestOut", "xpcTestInOut", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestConstCID(),
"xpcTestConst", "xpcTestConst", aPath,
PR_TRUE, PR_TRUE);
#if 0
rv = compMgr->RegisterComponent(xpctest::GetXPCTestConstructWithArgsCID(),
"xpcTestConstructArgs", "xpcTestConstructArgs", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestScriptableCID(),
"xpcTestScriptable", "xpcTestScriptable", aPath,
PR_TRUE, PR_TRUE);
// Release the factory objects
mEchoFactory = nsnull;
mChildFactory = nsnull;
mNoisyFactory = nsnull;
mStringTestFactory = nsnull;
mOverloadedFactory = nsnull;
mXPCTestObjectReadOnlyFactory = nsnull;
mXPCTestObjectReadWriteFactory = nsnull;
mXPCTestInFactory = nsnull;
mXPCTestOutFactory = nsnull;
mXPCTestInOutFactory = nsnull;
mXPCTestCallJSFactory = nsnull;
mXPCTestConstFactory = nsnull;
#if (0)
mXPCTestContructWithArgsFactory = nsnull;
mXPCTestScriptableFactory = nsnull;
#endif /* 0 */
rv = compMgr->RegisterComponent(xpctest::GetXPCTestCallJSCID(),
"xpcTestCallJS", "xpcTestCallJS", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestParentOneCID(),
"xpcTestParentOne", "xpcTestParentOne", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestParentTwoCID(),
"xpcTestParentTwo", "xpcTestParentTwo", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestChild2CID(),
"xpcTestChild2", "xpcTestChild2", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestChild3CID(),
"xpcTestChild3", "xpcTestChild3", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestChild4CID(),
"xpcTestChild4", "xpcTestChild4", aPath,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(xpctest::GetXPCTestChild5CID(),
"xpcTestChild5", "xpcTestChild5", aPath,
PR_TRUE, PR_TRUE);
return rv;
mXPCTestParentOneFactory = nsnull;
mXPCTestParentTwoFactory = nsnull;
mXPCTestChild2Factory = nsnull;
mXPCTestChild3Factory = nsnull;
mXPCTestChild4Factory = nsnull;
mXPCTestChild5Factory = nsnull;
mArrayTestFactory = nsnull;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsXPCTestModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(xpctest::GetEchoCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetChildCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetNoisyCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetStringTestCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetOverloadedCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestObjectReadWriteCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestObjectReadOnlyCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestInCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestOutCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestInOutCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestConstCID(), aPath);
/*
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestConstructWithArgsCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestScriptableCID(), aPath);
*/
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestCallJSCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestParentOneCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestParentTwoCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestChild2CID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestChild3CID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestChild4CID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestChild5CID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetArrayTestCID(), aPath);
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(xpctest::GetEchoCID())) {
if (!mEchoFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mEchoFactory),
xpctest::ConstructEcho);
}
fact = mEchoFactory;
}
else if (aClass.Equals(xpctest::GetChildCID())) {
if (!mChildFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mChildFactory),
xpctest::ConstructChild);
}
fact = mChildFactory;
}
else if (aClass.Equals(xpctest::GetNoisyCID())) {
if (!mNoisyFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mNoisyFactory),
xpctest::ConstructNoisy);
}
fact = mNoisyFactory;
}
else if (aClass.Equals(xpctest::GetStringTestCID())) {
if (!mStringTestFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mStringTestFactory),
xpctest::ConstructStringTest);
}
fact = mStringTestFactory;
}
else if (aClass.Equals(xpctest::GetOverloadedCID())) {
if (!mOverloadedFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mOverloadedFactory),
xpctest::ConstructOverloaded);
}
fact = mOverloadedFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestObjectReadOnlyCID())) {
if (!mXPCTestObjectReadOnlyFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestObjectReadOnlyFactory),
xpctest::ConstructXPCTestObjectReadOnly);
}
fact = mXPCTestObjectReadOnlyFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestObjectReadWriteCID())) {
if (!mXPCTestObjectReadWriteFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestObjectReadWriteFactory),
xpctest::ConstructXPCTestObjectReadWrite);
}
fact = mXPCTestObjectReadWriteFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestInCID())) {
if (!mXPCTestInFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestInFactory),
xpctest::ConstructXPCTestIn);
}
fact = mXPCTestInFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestOutCID())) {
if (!mXPCTestOutFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestOutFactory),
xpctest::ConstructXPCTestOut);
}
fact = mXPCTestOutFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestInOutCID())) {
if (!mXPCTestInOutFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestInOutFactory),
xpctest::ConstructXPCTestInOut);
}
fact = mXPCTestInOutFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestCallJSCID())) {
if (!mXPCTestCallJSFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestCallJSFactory),
xpctest::ConstructXPCTestCallJS);
}
fact = mXPCTestCallJSFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestConstCID())) {
if (!mXPCTestConstFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestConstFactory),
xpctest::ConstructXPCTestConst);
}
fact = mXPCTestConstFactory;
}
#if (0)
else if (aClass.Equals(xpctest::GetXPCTestConstructWithArgsCID())) {
if (!mXPCTestConstructWithArgsFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestConstructWithArgsFactory),
xpctest::ConstructXPCTestConstructWithArgs);
}
fact = mXPCTestConstructWithArgsFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestScriptableCID())) {
if (!mXPCTestScriptableFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestScriptableFactory),
xpctest::ConstructXPCTestScriptable);
}
fact = mXPCTestScriptableFactory;
}
#endif /* 0 */
else if (aClass.Equals(xpctest::GetXPCTestParentOneCID())) {
if (!mXPCTestParentOneFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestParentOneFactory),
xpctest::ConstructXPCTestParentOne);
}
fact = mXPCTestParentOneFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestParentTwoCID())) {
if (!mXPCTestParentTwoFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestParentTwoFactory),
xpctest::ConstructXPCTestParentTwo);
}
fact = mXPCTestParentTwoFactory;
}
else if (aClass.Equals(xpctest::GetXPCTestChild2CID())) {
if (!mXPCTestChild2Factory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestChild2Factory),
xpctest::ConstructXPCTestChild2);
}
fact = mXPCTestChild2Factory;
}
else if (aClass.Equals(xpctest::GetXPCTestChild3CID())) {
if (!mXPCTestChild3Factory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestChild3Factory),
xpctest::ConstructXPCTestChild3);
}
fact = mXPCTestChild3Factory;
}
else if (aClass.Equals(xpctest::GetXPCTestChild4CID())) {
if (!mXPCTestChild4Factory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestChild4Factory),
xpctest::ConstructXPCTestChild4);
}
fact = mXPCTestChild4Factory;
}
else if (aClass.Equals(xpctest::GetXPCTestChild5CID())) {
if (!mXPCTestChild5Factory) {
rv = NS_NewGenericFactory(getter_AddRefs(mXPCTestChild5Factory),
xpctest::ConstructXPCTestChild5);
}
fact = mXPCTestChild5Factory;
}
else if (aClass.Equals(xpctest::GetArrayTestCID())) {
if (!mArrayTestFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mArrayTestFactory),
xpctest::ConstructArrayTest);
}
fact = mArrayTestFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsXPCTestModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "nsEcho", &xpctest::GetEchoCID(),
"nsEcho", },
{ "nsChild", &xpctest::GetChildCID(),
"nsChild", },
{ "nsNoisy", &xpctest::GetNoisyCID(),
"nsNoisy", },
{ "nsStringTest", &xpctest::GetStringTestCID(),
"nsStringTest", },
{ "nsOverloaded", &xpctest::GetOverloadedCID(),
"nsOverloaded", },
{ "xpcTestObjectReadOnly", &xpctest::GetXPCTestObjectReadOnlyCID(),
"xpcTestObjectReadOnly", },
{ "xpcTestObjectReadWrite", &xpctest::GetXPCTestObjectReadWriteCID(),
"xpcTestObjectReadWrite", },
{ "xpcTestIn", &xpctest::GetXPCTestInCID(),
"xpcTestIn", },
{ "xpcTestOut", &xpctest::GetXPCTestOutCID(),
"xpcTestOut", },
{ "xpcTestInOut", &xpctest::GetXPCTestInOutCID(),
"xpcTestInOut", },
{ "xpcTestCallJS", &xpctest::GetXPCTestCallJSCID(),
"xpcTestCallJS", },
{ "xpcTestConst", &xpctest::GetXPCTestConstCID(),
"xpcTestConst", },
#if 0
{ "xpcTestConstructArgs", &xpctest::GetXPCTestConstructWithArgsCID(),
"xpcTestConstructArgs", },
{ "xpcTestScriptable", &xpctest::GetXPCTestScriptableCID(),
"xpcTestScriptable", },
#endif /* 0 */
{ "xpcTestParentOne", &xpctest::GetXPCTestParentOneCID(),
"xpcTestParentOne", },
{ "xpcTestParentTwo", &xpctest::GetXPCTestParentTwoCID(),
"xpcTestParentTwo", },
{ "xpcTestChild2", &xpctest::GetXPCTestChild2CID(),
"xpcTestChild2", },
{ "xpcTestChild3", &xpctest::GetXPCTestChild3CID(),
"xpcTestChild3", },
{ "xpcTestChild4", &xpctest::GetXPCTestChild4CID(),
"xpcTestChild4", },
{ "xpcTestChild5", &xpctest::GetXPCTestChild5CID(),
"xpcTestChild5", },
{ "nsArrayTest", &xpctest::GetArrayTestCID(),
"nsArrayTest", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsXPCTestModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering XPCTest components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsXPCTestModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsXPCTestModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering XPCTest components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsXPCTestModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsXPCTestModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsXPCTestModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(return_cobj);
NS_ENSURE_NOT(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsXPCTestModule *m = new nsXPCTestModule();
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**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}