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. */ /* module registration and factory code. */
#include "xpctest_private.h" #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(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID); static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
extern "C" PR_IMPLEMENT(nsresult) // Module implementation
NSGetFactory(nsISupports* aServMgr, class nsXPCTestModule : public nsIModule
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{ {
nsresult rv; public:
NS_ASSERTION(aFactory != nsnull, "bad factory pointer"); nsXPCTestModule();
virtual ~nsXPCTestModule();
NS_WITH_SERVICE1(nsIComponentManager, compMgr, NS_DECL_ISUPPORTS
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
nsIGenericFactory* factory; NS_DECL_NSIMODULE
rv = compMgr->CreateInstance(kGenericFactoryCID, nsnull,
nsIGenericFactory::GetIID(),
(void**)&factory);
if (NS_FAILED(rv)) return rv;
// add more factories as 'if else's below... protected:
nsresult Initialize();
if(aClass.Equals(xpctest::GetEchoCID())) void Shutdown();
rv = factory->SetConstructor(xpctest::ConstructEcho);
else if(aClass.Equals(xpctest::GetChildCID())) PRBool mInitialized;
rv = factory->SetConstructor(xpctest::ConstructChild); nsCOMPtr<nsIGenericFactory> mEchoFactory;
else if(aClass.Equals(xpctest::GetNoisyCID())) nsCOMPtr<nsIGenericFactory> mChildFactory;
rv = factory->SetConstructor(xpctest::ConstructNoisy); nsCOMPtr<nsIGenericFactory> mNoisyFactory;
else if(aClass.Equals(xpctest::GetStringTestCID())) nsCOMPtr<nsIGenericFactory> mStringTestFactory;
rv = factory->SetConstructor(xpctest::ConstructStringTest); nsCOMPtr<nsIGenericFactory> mOverloadedFactory;
else if(aClass.Equals(xpctest::GetOverloadedCID())) nsCOMPtr<nsIGenericFactory> mXPCTestObjectReadOnlyFactory;
rv = factory->SetConstructor(xpctest::ConstructOverloaded); nsCOMPtr<nsIGenericFactory> mXPCTestObjectReadWriteFactory;
else if(aClass.Equals(xpctest::GetXPCTestObjectReadOnlyCID())) nsCOMPtr<nsIGenericFactory> mXPCTestInFactory;
rv = factory->SetConstructor(xpctest::ConstructXPCTestObjectReadOnly); nsCOMPtr<nsIGenericFactory> mXPCTestOutFactory;
else if(aClass.Equals(xpctest::GetXPCTestObjectReadWriteCID())) nsCOMPtr<nsIGenericFactory> mXPCTestInOutFactory;
rv = factory->SetConstructor(xpctest::ConstructXPCTestObjectReadWrite); nsCOMPtr<nsIGenericFactory> mXPCTestCallJSFactory;
else if(aClass.Equals(xpctest::GetXPCTestInCID())) nsCOMPtr<nsIGenericFactory> mXPCTestConstFactory;
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);
#if (0) #if (0)
else if(aClass.Equals(xpctest::GetXPCTestConstructWithArgsCID())) nsCOMPtr<nsIGenericFactory> mXPCTestContructWithArgsFactory;
rv = factory->SetConstructor(xpctest::ConstructXPCTestConstructWithArgs); nsCOMPtr<nsIGenericFactory> mXPCTestScriptableFactory;
else if(aClass.Equals(xpctest::GetXPCTestScriptableCID()))
rv = factory->SetConstructor(xpctest::ConstructXPCTestScriptable);
#endif /* 0 */ #endif /* 0 */
else if(aClass.Equals(xpctest::GetXPCTestParentOneCID())) nsCOMPtr<nsIGenericFactory> mXPCTestParentOneFactory;
rv = factory->SetConstructor(xpctest::ConstructXPCTestParentOne); nsCOMPtr<nsIGenericFactory> mXPCTestParentTwoFactory;
else if(aClass.Equals(xpctest::GetXPCTestParentTwoCID())) nsCOMPtr<nsIGenericFactory> mXPCTestChild2Factory;
rv = factory->SetConstructor(xpctest::ConstructXPCTestParentTwo); nsCOMPtr<nsIGenericFactory> mXPCTestChild3Factory;
else if(aClass.Equals(xpctest::GetXPCTestChild2CID())) nsCOMPtr<nsIGenericFactory> mXPCTestChild4Factory;
rv = factory->SetConstructor(xpctest::ConstructXPCTestChild2); nsCOMPtr<nsIGenericFactory> mXPCTestChild5Factory;
else if(aClass.Equals(xpctest::GetXPCTestChild3CID())) nsCOMPtr<nsIGenericFactory> mArrayTestFactory;
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); // Functions used to create new instances of a given object by the
else if(aClass.Equals(xpctest::GetArrayTestCID())) // generic factory.
rv = factory->SetConstructor(xpctest::ConstructArrayTest);
else
nsXPCTestModule::nsXPCTestModule()
: mInitialized(PR_FALSE)
{ {
NS_ASSERTION(0, "incorrectly registered"); NS_INIT_ISUPPORTS();
rv = NS_ERROR_NO_INTERFACE;
} }
if (NS_FAILED(rv)) { nsXPCTestModule::~nsXPCTestModule()
NS_RELEASE(factory); {
return rv; 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; return NS_OK;
} }
extern "C" PR_IMPLEMENT(nsresult) // Shutdown this module, releasing all of the module resources
NSRegisterSelf(nsISupports* aServMgr , const char* aPath) void
nsXPCTestModule::Shutdown()
{ {
nsresult rv; // Release the factory objects
#ifdef DEBUG mEchoFactory = nsnull;
printf("*** Register XPConnect test components\n"); mChildFactory = nsnull;
#endif mNoisyFactory = nsnull;
NS_WITH_SERVICE1(nsIComponentManager, compMgr, mStringTestFactory = nsnull;
aServMgr, kComponentManagerCID, &rv); mOverloadedFactory = nsnull;
if (NS_FAILED(rv)) return rv; mXPCTestObjectReadOnlyFactory = nsnull;
mXPCTestObjectReadWriteFactory = nsnull;
rv = compMgr->RegisterComponent(xpctest::GetEchoCID(), mXPCTestInFactory = nsnull;
"nsEcho", "nsEcho", aPath, mXPCTestOutFactory = nsnull;
PR_TRUE, PR_TRUE); mXPCTestInOutFactory = nsnull;
mXPCTestCallJSFactory = nsnull;
rv = compMgr->RegisterComponent(xpctest::GetChildCID(), mXPCTestConstFactory = nsnull;
"nsChild", "nsChild", aPath, #if (0)
PR_TRUE, PR_TRUE); mXPCTestContructWithArgsFactory = nsnull;
mXPCTestScriptableFactory = nsnull;
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);
#endif /* 0 */ #endif /* 0 */
rv = compMgr->RegisterComponent(xpctest::GetXPCTestCallJSCID(), mXPCTestParentOneFactory = nsnull;
"xpcTestCallJS", "xpcTestCallJS", aPath, mXPCTestParentTwoFactory = nsnull;
PR_TRUE, PR_TRUE); mXPCTestChild2Factory = nsnull;
mXPCTestChild3Factory = nsnull;
rv = compMgr->RegisterComponent(xpctest::GetXPCTestParentOneCID(), mXPCTestChild4Factory = nsnull;
"xpcTestParentOne", "xpcTestParentOne", aPath, mXPCTestChild5Factory = nsnull;
PR_TRUE, PR_TRUE); mArrayTestFactory = nsnull;
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;
} }
extern "C" PR_IMPLEMENT(nsresult) // Create a factory object for creating instances of aClass.
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath) NS_IMETHODIMP
nsXPCTestModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{ {
nsresult rv; nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(xpctest::GetEchoCID(), aPath); // Defensive programming: Initialize *r_classObj in case of error below
rv = compMgr->UnregisterComponent(xpctest::GetChildCID(), aPath); if (!r_classObj) {
rv = compMgr->UnregisterComponent(xpctest::GetNoisyCID(), aPath); return NS_ERROR_INVALID_POINTER;
rv = compMgr->UnregisterComponent(xpctest::GetStringTestCID(), aPath); }
rv = compMgr->UnregisterComponent(xpctest::GetOverloadedCID(), aPath); *r_classObj = NULL;
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestObjectReadWriteCID(), aPath);
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestObjectReadOnlyCID(), aPath); // Do one-time-only initialization if necessary
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestInCID(), aPath); if (!mInitialized) {
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestOutCID(), aPath); rv = Initialize();
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestInOutCID(), aPath); if (NS_FAILED(rv)) {
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestConstCID(), aPath); // Initialization failed! yikes!
/* return rv;
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestConstructWithArgsCID(), aPath); }
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestScriptableCID(), aPath); }
*/
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestCallJSCID(), aPath); // Choose the appropriate factory, based on the desired instance
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestParentOneCID(), aPath); // class type (aClass).
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestParentTwoCID(), aPath); nsCOMPtr<nsIGenericFactory> fact;
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestChild2CID(), aPath); if (aClass.Equals(xpctest::GetEchoCID())) {
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestChild3CID(), aPath); if (!mEchoFactory) {
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestChild4CID(), aPath); rv = NS_NewGenericFactory(getter_AddRefs(mEchoFactory),
rv = compMgr->UnregisterComponent(xpctest::GetXPCTestChild5CID(), aPath); xpctest::ConstructEcho);
rv = compMgr->UnregisterComponent(xpctest::GetArrayTestCID(), aPath); }
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; 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;
}