Allows a QI from nsIServiceManager to nsIServiceManagerObsolete. b=105136, r=beard, sr=darin

This commit is contained in:
dougt%netscape.com 2001-10-16 23:39:20 +00:00
parent b70efcb81c
commit 004836dcaf
5 changed files with 107 additions and 148 deletions

View File

@ -524,6 +524,7 @@ nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr)
// libraries:
NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
NS_WARN_IF_FALSE(cnt == 0, "Component Manager being held past XPCOM shutdown.");
nsComponentManagerImpl::gComponentManager = nsnull;
#ifdef DEBUG
extern void _FreeAutoLockStatics();

View File

@ -602,11 +602,12 @@ nsComponentManagerImpl::~nsComponentManagerImpl()
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Destroyed."));
}
NS_IMPL_THREADSAFE_ISUPPORTS4(nsComponentManagerImpl,
NS_IMPL_THREADSAFE_ISUPPORTS5(nsComponentManagerImpl,
nsIComponentManager,
nsIServiceManager,
nsISupportsWeakReference,
nsIInterfaceRequestor)
nsIInterfaceRequestor,
nsIServiceManagerObsolete)
////////////////////////////////////////////////////////////////////////////////
// nsComponentManagerImpl: Platform methods
@ -1678,7 +1679,7 @@ nsComponentManagerImpl::UnregisterService(const nsCID& aClass)
}
NS_IMETHODIMP
nsComponentManagerImpl::RegisterServiceByContractID(const char* aContractID, nsISupports* aService)
nsComponentManagerImpl::RegisterService(const char* aContractID, nsISupports* aService)
{
nsAutoMonitor mon(mMon);
@ -1792,7 +1793,7 @@ NS_IMETHODIMP nsComponentManagerImpl::IsServiceInstantiatedByContractID(const ch
NS_IMETHODIMP
nsComponentManagerImpl::UnregisterServiceByContractID(const char* aContractID)
nsComponentManagerImpl::UnregisterService(const char* aContractID)
{
nsresult rv = NS_OK;
nsAutoMonitor mon(mMon);
@ -1880,6 +1881,38 @@ nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
return rv;
}
NS_IMETHODIMP
nsComponentManagerImpl::GetService(const nsCID& aClass, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener)
{
return GetService(aClass, aIID, (void**)result);
};
NS_IMETHODIMP
nsComponentManagerImpl::GetService(const char* aContractID, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener )
{
return GetServiceByContractID(aContractID, aIID, (void**)result);
};
NS_IMETHODIMP
nsComponentManagerImpl::ReleaseService(const nsCID& aClass, nsISupports* service,
nsIShutdownListener* shutdownListener )
{
NS_IF_RELEASE(service);
return NS_OK;
};
NS_IMETHODIMP
nsComponentManagerImpl::ReleaseService(const char* aContractID, nsISupports* service,
nsIShutdownListener* shutdownListener )
{
NS_IF_RELEASE(service);
return NS_OK;
};
/*
* I want an efficient way to allocate a buffer to the right size

View File

@ -83,18 +83,45 @@ class nsComponentManagerImpl
: public nsIComponentManager,
public nsIServiceManager,
public nsSupportsWeakReference,
public nsIInterfaceRequestor {
public nsIInterfaceRequestor,
public nsIServiceManagerObsolete
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICOMPONENTMANAGER
NS_DECL_NSISERVICEMANAGER
// to be moved when nsIComponentManager is frozen.
NS_IMETHOD RegisterService(const nsCID & aClass, nsISupports *aService);
NS_IMETHOD RegisterServiceByContractID(const char *aContractID, nsISupports *aService);
NS_IMETHOD UnregisterService(const nsCID & aClass);
NS_IMETHOD UnregisterServiceByContractID(const char *aContractID);
// nsIServiceManagerObsolete
NS_IMETHOD
RegisterService(const nsCID& aClass, nsISupports* aService);
NS_IMETHOD
UnregisterService(const nsCID& aClass);
NS_IMETHOD
GetService(const nsCID& aClass, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener);
NS_IMETHOD
ReleaseService(const nsCID& aClass, nsISupports* service,
nsIShutdownListener* shutdownListener);
NS_IMETHOD
RegisterService(const char* aContractID, nsISupports* aService);
NS_IMETHOD
UnregisterService(const char* aContractID);
NS_IMETHOD
GetService(const char* aContractID, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener);
NS_IMETHOD
ReleaseService(const char* aContractID, nsISupports* service,
nsIShutdownListener* shutdownListener);
// nsComponentManagerImpl methods:
nsComponentManagerImpl();

View File

@ -132,47 +132,6 @@ public:
};
class nsServiceManagerObsolete : public nsIServiceManagerObsolete {
public:
nsServiceManagerObsolete();
virtual ~nsServiceManagerObsolete();
NS_DECL_ISUPPORTS
NS_IMETHOD
RegisterService(const nsCID& aClass, nsISupports* aService);
NS_IMETHOD
UnregisterService(const nsCID& aClass);
NS_IMETHOD
GetService(const nsCID& aClass, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener = nsnull);
NS_IMETHOD
ReleaseService(const nsCID& aClass, nsISupports* service,
nsIShutdownListener* shutdownListener = nsnull);
NS_IMETHOD
RegisterService(const char* aContractID, nsISupports* aService);
NS_IMETHOD
UnregisterService(const char* aContractID);
NS_IMETHOD
GetService(const char* aContractID, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener = nsnull);
NS_IMETHOD
ReleaseService(const char* aContractID, nsISupports* service,
nsIShutdownListener* shutdownListener = nsnull);
};
// Interface to Global Services
class NS_COM nsServiceManager {
public:

View File

@ -1,7 +1,6 @@
#include "nsIServiceManager.h"
#include "nsIServiceManagerObsolete.h"
nsServiceManagerObsolete* gServiceManagerObsolete = nsnull;
#include "nsComponentManager.h"
extern PRBool gXPCOMShuttingDown;
@ -13,24 +12,19 @@ nsServiceManager::GetGlobalServiceManager(nsIServiceManager* *result)
if (gXPCOMShuttingDown)
return NS_ERROR_UNEXPECTED;
if (gServiceManagerObsolete) {
*result = (nsIServiceManager*)(void*)gServiceManagerObsolete;
return NS_OK;
}
if (nsComponentManagerImpl::gComponentManager == nsnull)
return NS_ERROR_UNEXPECTED;
gServiceManagerObsolete = new nsServiceManagerObsolete();
if (!gServiceManagerObsolete)
return NS_ERROR_OUT_OF_MEMORY;
*result = (nsIServiceManager*)(void*)gServiceManagerObsolete;
// this method does not addref for historical reasons.
// we return the nsIServiceManagerObsolete interface via a cast.
*result = (nsIServiceManager*) NS_STATIC_CAST(nsIServiceManagerObsolete*,
nsComponentManagerImpl::gComponentManager);
return NS_OK;
}
nsresult
nsServiceManager::ShutdownGlobalServiceManager(nsIServiceManager* *result)
{
delete gServiceManagerObsolete;
gServiceManagerObsolete = nsnull;
return NS_OK;
}
@ -39,10 +33,11 @@ nsServiceManager::GetService(const nsCID& aClass, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener)
{
nsCOMPtr<nsIServiceManager> mgr;
nsresult rv = NS_GetServiceManager(getter_AddRefs(mgr));
if (NS_FAILED(rv)) return rv;
return mgr->GetService(aClass, aIID, (void**)result);
if (nsComponentManagerImpl::gComponentManager == nsnull)
return NS_ERROR_UNEXPECTED;
return nsComponentManagerImpl::gComponentManager->GetService(aClass, aIID, (void**)result);
}
nsresult
@ -56,19 +51,21 @@ nsServiceManager::ReleaseService(const nsCID& aClass, nsISupports* service,
nsresult
nsServiceManager::RegisterService(const nsCID& aClass, nsISupports* aService)
{
nsCOMPtr<nsIServiceManager> mgr;
nsresult rv = NS_GetServiceManager(getter_AddRefs(mgr));
if (NS_FAILED(rv)) return rv;
return NS_ERROR_NOT_IMPLEMENTED;//mgr->RegisterService(aClass, aService);
if (nsComponentManagerImpl::gComponentManager == nsnull)
return NS_ERROR_UNEXPECTED;
return nsComponentManagerImpl::gComponentManager->RegisterService(aClass, aService);
}
nsresult
nsServiceManager::UnregisterService(const nsCID& aClass)
{
nsCOMPtr<nsIServiceManager> mgr;
nsresult rv = NS_GetServiceManager(getter_AddRefs(mgr));
if (NS_FAILED(rv)) return rv;
return NS_ERROR_NOT_IMPLEMENTED;//mgr->UnregisterService(aClass);
if (nsComponentManagerImpl::gComponentManager == nsnull)
return NS_ERROR_UNEXPECTED;
return nsComponentManagerImpl::gComponentManager->UnregisterService(aClass);
}
////////////////////////////////////////////////////////////////////////////////
@ -79,10 +76,11 @@ nsServiceManager::GetService(const char* aContractID, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener)
{
nsCOMPtr<nsIServiceManager> mgr;
nsresult rv = NS_GetServiceManager(getter_AddRefs(mgr));
if (NS_FAILED(rv)) return rv;
return mgr->GetServiceByContractID(aContractID, aIID, (void**)result);
if (nsComponentManagerImpl::gComponentManager == nsnull)
return NS_ERROR_UNEXPECTED;
return nsComponentManagerImpl::gComponentManager->GetServiceByContractID(aContractID, aIID, (void**)result);
}
nsresult
@ -96,10 +94,11 @@ nsServiceManager::ReleaseService(const char* aContractID, nsISupports* service,
nsresult
nsServiceManager::RegisterService(const char* aContractID, nsISupports* aService)
{
nsCOMPtr<nsIServiceManager> mgr;
nsresult rv = NS_GetServiceManager(getter_AddRefs(mgr));
if (NS_FAILED(rv)) return rv;
return NS_ERROR_NOT_IMPLEMENTED;//mgr->RegisterServiceByContractID(aContractID, aService);
if (nsComponentManagerImpl::gComponentManager == nsnull)
return NS_ERROR_UNEXPECTED;
return nsComponentManagerImpl::gComponentManager->RegisterService(aContractID, aService);
}
nsresult
@ -110,70 +109,10 @@ nsServiceManager::UnregisterService(const char* aContractID)
// destructor
if (gXPCOMShuttingDown)
return NS_OK;
nsCOMPtr<nsIServiceManager> mgr;
nsresult rv = NS_GetServiceManager(getter_AddRefs(mgr));
if (NS_FAILED(rv)) return rv;
return NS_ERROR_NOT_IMPLEMENTED;//mgr->UnregisterServiceByContractID(aContractID);
if (nsComponentManagerImpl::gComponentManager == nsnull)
return NS_ERROR_UNEXPECTED;
return nsComponentManagerImpl::gComponentManager->UnregisterService(aContractID);
}
////////////////////////////////////////////////////////////////////////////////
nsServiceManagerObsolete::nsServiceManagerObsolete() {
NS_INIT_ISUPPORTS();
}
nsServiceManagerObsolete::~nsServiceManagerObsolete() {
}
NS_IMPL_ISUPPORTS1(nsServiceManagerObsolete,
nsIServiceManagerObsolete);
NS_IMETHODIMP
nsServiceManagerObsolete::RegisterService(const nsCID& aClass, nsISupports* aService) {
return nsServiceManager::RegisterService(aClass, aService);
};
NS_IMETHODIMP
nsServiceManagerObsolete::UnregisterService(const nsCID& aClass){
return nsServiceManager::UnregisterService(aClass);
};
NS_IMETHODIMP
nsServiceManagerObsolete::GetService(const nsCID& aClass, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener){
return nsServiceManager::GetService(aClass, aIID, result, shutdownListener);
};
NS_IMETHODIMP
nsServiceManagerObsolete::ReleaseService(const nsCID& aClass, nsISupports* service,
nsIShutdownListener* shutdownListener ){
return nsServiceManager::ReleaseService(aClass, service, shutdownListener);
};
NS_IMETHODIMP
nsServiceManagerObsolete::RegisterService(const char* aContractID, nsISupports* aService){
return nsServiceManager::RegisterService(aContractID, aService);
};
NS_IMETHODIMP
nsServiceManagerObsolete::UnregisterService(const char* aContractID){
return nsServiceManager::UnregisterService(aContractID);
};
NS_IMETHODIMP
nsServiceManagerObsolete::GetService(const char* aContractID, const nsIID& aIID,
nsISupports* *result,
nsIShutdownListener* shutdownListener ){
return nsServiceManager::GetService(aContractID, aIID, result, shutdownListener);
};
NS_IMETHODIMP
nsServiceManagerObsolete::ReleaseService(const char* aContractID, nsISupports* service,
nsIShutdownListener* shutdownListener ){
return nsServiceManager::ReleaseService(aContractID, service, shutdownListener);
};