convert nsPrefWindow to a module

prefwindow was doing it's own singleton management, so changed it to use getService()


git-svn-id: svn://10.0.0.236/trunk@51560 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
alecf%netscape.com
1999-10-22 21:05:31 +00:00
parent 16ace9def7
commit 450ceda4e0
4 changed files with 17 additions and 150 deletions

View File

@@ -50,7 +50,7 @@
if (prefwindow == null)
{
dump("Creating prefwindow object...");
prefwindow = Components.classes['component://netscape/prefwindow'].createInstance(Components.interfaces.nsIPrefWindow);
prefwindow = Components.classes['component://netscape/prefwindow'].getService(Components.interfaces.nsIPrefWindow);
dump("...created\n");
}
else

View File

@@ -29,7 +29,7 @@ function StartUp(windowName)
if (prefwindow == null)
{
dump("Creating prefwindow object...\n");
prefwindow = Components.classes['component://netscape/prefwindow'].createInstance(Components.interfaces.nsIPrefWindow);
prefwindow = Components.classes['component://netscape/prefwindow'].getService(Components.interfaces.nsIPrefWindow);
}
else
{

View File

@@ -50,7 +50,7 @@
if (prefwindow == null)
{
dump("Creating prefwindow object...");
prefwindow = Components.classes['component://netscape/prefwindow'].createInstance(Components.interfaces.nsIPrefWindow);
prefwindow = Components.classes['component://netscape/prefwindow'].getService(Components.interfaces.nsIPrefWindow);
dump("...created\n");
}
else

View File

@@ -24,154 +24,21 @@
// include files for components this factory creates...
#include "nsPrefWindow.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
//static NS_DEFINE_CID(kPrefWindowCID, NS_PREFWINDOW_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrefWindow)
static PRInt32 gLockCount = 0;
struct components_t {
nsCID cid;
nsIGenericFactory::ConstructorProcPtr constructor;
const char *progid;
const char *description;
};
//========================================================================================
class nsPrefWindowFactory : public nsIFactory
//========================================================================================
{
public:
// nsISupports methods
NS_DECL_ISUPPORTS
components_t components[] = {
{ NS_PREFWINDOW_CID, &nsPrefWindowConstructor, NS_PREFWINDOW_PROGID, "Preferences window helper object", },
};
nsPrefWindowFactory(/*const nsCID &aClass, const char* aClassName, const char* aProgID*/);
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~nsPrefWindowFactory();
// DATA
protected:
// nsCID mClassID;
// char* mClassName;
// char* mProgID;
};
//----------------------------------------------------------------------------------------
nsPrefWindowFactory::nsPrefWindowFactory(
/*const nsCID &aClass,
const char* aClassName,
const char* aProgID*/)
//----------------------------------------------------------------------------------------
// : mClassID(aClass)
// , mClassName(nsCRT::strdup(aClassName))
// , mProgID(nsCRT::strdup(aProgID))
{
NS_INIT_REFCNT();
}
//----------------------------------------------------------------------------------------
nsPrefWindowFactory::~nsPrefWindowFactory()
//----------------------------------------------------------------------------------------
{
// nsCRT::free(mClassName);
// nsCRT::free(mProgID);
}
NS_IMPL_ISUPPORTS(nsPrefWindowFactory, nsIFactory::GetIID());
//----------------------------------------------------------------------------------------
nsresult nsPrefWindowFactory::CreateInstance(
nsISupports* /* aOuter */,
const nsIID &aIID,
void** aResult)
//----------------------------------------------------------------------------------------
{
if (aResult == nsnull)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
// if (!mClassID.Equals(nsPrefWindow::GetCID()))
// return NS_NOINTERFACE;
*aResult = nsPrefWindow::Get();
return NS_OK;
} // nsPrefWindowFactory::CreateInstanc
//----------------------------------------------------------------------------------------
nsresult nsPrefWindowFactory::LockFactory(PRBool aLock)
//----------------------------------------------------------------------------------------
{
if (aLock)
PR_AtomicIncrement(&gLockCount);
else
PR_AtomicDecrement(&gLockCount);
return NS_OK;
} // nsPrefWindowFactory::LockFactory
//----------------------------------------------------------------------------------------
extern "C" NS_EXPORT nsresult NSGetFactory(
nsISupports* /* aServMgr */,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
//----------------------------------------------------------------------------------------
{
if (nsnull == aFactory)
return NS_ERROR_NULL_POINTER;
// If we decide to implement multiple factories, then we need to
// check the class type here and create the appropriate factory.
*aFactory = new nsPrefWindowFactory(/*aClass, aClassName, aProgID*/);
if (!aFactory)
return NS_ERROR_OUT_OF_MEMORY;
return (*aFactory)->QueryInterface(nsIFactory::GetIID(), (void**)aFactory);
// they want a Factory Interface so give it to them
} // NSGetFactory
//----------------------------------------------------------------------------------------
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* /* aServMgr */)
//----------------------------------------------------------------------------------------
{
return PRBool(!nsPrefWindow::InstanceExists() && gLockCount == 0);
} // NSCanUnload
//----------------------------------------------------------------------------------------
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* /*aServMgr*/, const char* path)
//----------------------------------------------------------------------------------------
{
nsresult rv;
// nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
// if (NS_FAILED(rv))
// return rv;
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv))
return rv;
#ifdef NS_DEBUG
printf("Registering the PrefsWindow\n");
#endif
rv = compMgr->RegisterComponent(
nsPrefWindow::GetCID(),
"nsPrefWindow", // classname
NS_PREFWINDOW_PROGID, // progid
path,
PR_TRUE, // replace
PR_TRUE // persist
);
return rv;
} // NSRegisterSelf
//----------------------------------------------------------------------------------------
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* /*aServMgr*/, const char* path)
//----------------------------------------------------------------------------------------
{
nsresult rv;
// nsCOMPtr<nsIServiceManager> servMgr(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->UnregisterComponent(nsPrefWindow::GetCID(), path);
return rv;
} // NSUnregisterSelf
NS_IMPL_MODULE(components)
NS_IMPL_NSGETMODULE(nsModule)