- Adding nsComponentMangager::GetClassObject()

- Adding a nsIID parameter to the nsIModule:GetClassObject()
This commit is contained in:
dp%netscape.com 1999-08-19 14:54:12 +00:00
parent d7fc6e2d31
commit d42f5605f4
5 changed files with 81 additions and 21 deletions

View File

@ -1084,29 +1084,25 @@ nsComponentManagerImpl::LoadFactory(nsFactoryEntry *aEntry,
// new library can be traced.
nsTraceRefcnt::LoadLibrarySymbols(aEntry->dll->GetNativePath(), aEntry->dll->GetInstance());
#endif
nsIServiceManager* serviceMgr = NULL;
nsresult rv = nsServiceManager::GetGlobalServiceManager(&serviceMgr);
if (NS_FAILED(rv)) return rv;
// Create the module object and get the factory
nsCOMPtr<nsIModule> mobj;
rv = aEntry->dll->GetModule(gComponentManager, getter_AddRefs(mobj));
nsresult rv = aEntry->dll->GetModule(gComponentManager, getter_AddRefs(mobj));
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsISupports> classObject;
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
("nsComponentManager: %s using nsIModule to get factory.",
aEntry->dll->GetNativePath()));
rv = mobj->GetClassObject(gComponentManager, aEntry->cid, getter_AddRefs(classObject));
if (NS_SUCCEEDED(rv))
{
rv = classObject->QueryInterface(nsIFactory::GetIID(), (void **)aFactory);
}
rv = mobj->GetClassObject(gComponentManager, aEntry->cid,
NS_GET_IID(nsIFactory), (void **)aFactory);
return rv;
}
#ifndef OBSOLETE_MODULE_LOADING
// Try the older OBSOLETE method
nsIServiceManager* serviceMgr = NULL;
rv = nsServiceManager::GetGlobalServiceManager(&serviceMgr);
if (NS_FAILED(rv)) return rv;
nsFactoryProc proc = (nsFactoryProc) aEntry->dll->FindSymbol("NSGetFactory");
if (proc != NULL)
{
@ -1203,6 +1199,14 @@ nsComponentManagerImpl::FindFactory(const nsCID &aClass,
// XXX Cache factory that we created for performance.
// XXX Need a way to release this factory else dlls will never
// XXX get unloaded
// XXX
// XXX With the new module notion, we dont need to cache the
// XXX factory anylonger. The module would do that and manage
// XXX it. This is simpler for making decisions of unloading.
// XXX
// XXX The other option we got is to make UnloadLibraries()
// XXX release any cached factory before asking if a dll can
// XXX be unloaded. This we can do to improve performance.
if (NS_SUCCEEDED(res))
{
entry->factory = *aFactory;
@ -1223,6 +1227,40 @@ nsComponentManagerImpl::FindFactory(const nsCID &aClass,
return res;
}
/**
* GetClassObject()
*
* Given a classID, this finds the singleton ClassObject that implements the CID.
* Returns an interface of type aIID off the singleton classobject.
*/
nsresult
nsComponentManagerImpl::GetClassObject(const nsCID &aClass, const nsIID &aIID,
void **aResult)
{
nsresult rv;
nsCOMPtr<nsIFactory> factory;
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
{
char *buf = aClass.ToString();
PR_LogPrint("nsComponentManager: GetClassObject(%s)", buf);
delete [] buf;
}
PR_ASSERT(aResult != NULL);
rv = FindFactory(aClass, getter_AddRefs(factory));
if (NS_FAILED(rv)) return rv;
rv = factory->QueryInterface(aIID, aResult);
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
return rv;
}
/**
* ProgIDToCLSID()
*
@ -1406,11 +1444,6 @@ nsComponentManagerImpl::CreateInstance(const char *aProgID,
* Once registration is complete, we add the class to the factories cache
* that we maintain. The factories cache is the ONLY place where these
* registrations are ever kept.
*
* XXX This uses FindFactory() to test if a factory already exists. This
* XXX has the bad side effect of loading the factory if the previous
* XXX registration was a dll for this class. We might be able to do away
* XXX with such a load.
*/
nsresult
nsComponentManagerImpl::RegisterFactory(const nsCID &aClass,

View File

@ -46,6 +46,10 @@ public:
NS_IMETHOD FindFactory(const nsCID &aClass,
nsIFactory **aFactory);
// nsIComponentManager methods:
NS_IMETHOD GetClassObject(const nsCID &aClass, const nsIID &aIID,
void **aResult);
// Finds a class ID for a specific Program ID
NS_IMETHOD ProgIDToCLSID(const char *aProgID,
nsCID *aClass);

View File

@ -25,6 +25,9 @@
#include "nsError.h"
#include "nsISupports.h"
#include "nsIFactory.h"
// XXX Need to substitute these includes with
// XXX equivalent forward declarations.
#include "nsIFileSpec.h"
#include "nsIEnumerator.h"
@ -80,9 +83,14 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOMPONENTMANAGER_IID)
// Get the factory for creation of the CID
NS_IMETHOD FindFactory(const nsCID &aClass,
nsIFactory **aFactory) = 0;
// Get the singleton class object that implements the CID aClass
NS_IMETHOD GetClassObject(const nsCID &aClass, const nsIID &aIID,
void **aResult) = 0;
// Finds a class ID for a specific Program ID
NS_IMETHOD ProgIDToCLSID(const char *aProgID,
nsCID *aClass) = 0;
@ -92,7 +100,7 @@ public:
NS_IMETHOD CLSIDToProgID(nsCID *aClass,
char* *aClassName,
char* *aProgID) = 0;
// Creates a class instance for a specific class ID
NS_IMETHOD CreateInstance(const nsCID &aClass,
nsISupports *aDelegate,
@ -218,6 +226,10 @@ public:
static nsresult FindFactory(const nsCID &aClass,
nsIFactory **aFactory);
// Get the singleton class object that implements the CID aClass
static nsresult GetClassObject(const nsCID &aClass, const nsIID &aIID,
void **aResult);
// Finds a class ID for a specific Program ID
static nsresult ProgIDToCLSID(const char *aProgID,
nsCID *aClass);

View File

@ -27,15 +27,16 @@
// Once we idl component manager, this can be removed
[ptr] native nsIComponentManager(nsIComponentManager);
[uuid(00000000-0000-0000-0000-000000000005)]
[uuid(7392D032-5371-11d3-994E-00805FD26FEE)]
interface nsIModule : nsISupports
{
// Object Instance Creation.
// Factory can be queried off the Class Object. Factory will be used to
// create new objects.
// Services can be queried off the Class Object.
// SingletonFactory can be queried off the Class Object. Services can be created
// using the singletonfactory.
void GetClassObject(in nsIComponentManager aCompMgr, in nsCIDRef aClass,
out nsISupports return_ClassObject);
in nsIIDRef aIID, out voidStar return_ClassObject);
// Component registration
void RegisterSelf(in nsIComponentManager aCompMgr, in nsIFileSpec location);

View File

@ -34,6 +34,16 @@ nsComponentManager::FindFactory(const nsCID &aClass,
return cm->FindFactory(aClass, aFactory);
}
nsresult
nsComponentManager::GetClassObject(const nsCID &aClass, const nsIID &aIID,
void **aResult)
{
nsIComponentManager* cm;
nsresult rv = NS_GetGlobalComponentManager(&cm);
if (NS_FAILED(rv)) return rv;
return cm->GetClassObject(aClass, aIID, aResult);
}
nsresult
nsComponentManager::ProgIDToCLSID(const char *aProgID,
nsCID *aClass)