Removed nsIFactory.h (generated now).

Factored ComponentManager to support multiple ComponentLoaders.
Added support for relative paths in registry.
General cleanup.
(Broke detection of changed DLLs; dp is fixing -- thanks!)
This commit is contained in:
shaver@netscape.com
1999-08-31 21:40:21 +00:00
parent 89ff1f67b9
commit 1df39438da
11 changed files with 1840 additions and 1076 deletions

View File

@@ -0,0 +1,2 @@
nsIFactory.idl
nsIComponentLoader.idl

View File

@@ -28,6 +28,7 @@ LIBRARY_NAME = xpcomcomponents_s
CPPSRCS = \
nsComponentManager.cpp \
nsGenericFactory.cpp \
nsNativeComponentLoader.cpp \
nsRegistry.cpp \
nsRepository.cpp \
nsServiceManager.cpp \
@@ -35,12 +36,13 @@ CPPSRCS = \
$(NULL)
XPIDLSRCS = \
nsIFactory.idl \
nsIComponentLoader.idl \
nsIModule.idl \
$(NULL)
EXPORTS = \
nsIComponentManager.h \
nsIFactory.h \
nsIGenericFactory.h \
nsIRegistry.h \
nsIServiceManager.h \

View File

@@ -35,6 +35,7 @@ EXPORTS = \
$(NULL)
XPIDLSRCS = \
.\nsIComponentLoader.idl \
.\nsIModule.idl \
$(NULL)
@@ -55,6 +56,7 @@ LCFLAGS = -DUSE_NSREG -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN
CPP_OBJS = \
.\$(OBJDIR)\nsComponentManager.obj \
.\$(OBJDIR)\nsGenericFactory.obj \
.\$(OBJDIR)\nsNativeComponentLoader.obj \
.\$(OBJDIR)\nsRegistry.obj \
.\$(OBJDIR)\nsRepository.obj \
.\$(OBJDIR)\nsServiceManager.obj \

File diff suppressed because it is too large Load Diff

View File

@@ -19,11 +19,15 @@
#ifndef nsComponentManager_h__
#define nsComponentManager_h__
#include "nsIComponentLoader.h"
#include "nsNativeComponentLoader.h"
#include "nsIComponentManager.h"
#include "nsIFactory.h"
#include "nsIRegistry.h"
#include "nsHashtable.h"
#include "prtime.h"
#include "prmon.h"
#include "nsCOMPtr.h"
class nsFactoryEntry;
class nsDll;
@@ -36,6 +40,11 @@ class nsIServiceManager;
// here rather than in nsIRegistry.h
extern "C" NS_EXPORT nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
extern const char xpcomBaseName[];
extern const char xpcomKeyName[];
extern const char lastModValueName[];
extern const char fileSizeValueName[];
////////////////////////////////////////////////////////////////////////////////
class nsComponentManagerImpl : public nsIComponentManager {
@@ -161,6 +170,18 @@ public:
nsresult PlatformPrePopulateRegistry();
protected:
nsresult RegisterComponentCommon(const nsCID &aClass,
const char *aClassName,
const char *aProgID, char *aRegistryName,
PRBool aReplace, PRBool aPersist,
const char *aType);
nsresult AddComponentToRegistry(const nsCID &aCID, const char *aClassName,
const char *aProgID,
const char *aRegistryName,
const char *aType);
nsresult GetLoaderForType(const char *aType,
nsIComponentLoader **aLoader);
nsresult LoadFactory(nsFactoryEntry *aEntry, nsIFactory **aFactory);
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass, PRBool checkRegistry);
@@ -168,35 +189,29 @@ protected:
nsresult SelfRegisterDll(nsDll *dll);
nsresult SelfUnregisterDll(nsDll *dll);
nsresult HashProgID(const char *aprogID, const nsCID &aClass);
nsDll *CreateCachedDll(const char *persistentDescriptor, PRUint32 modDate, PRUint32 size);
nsDll *CreateCachedDll(nsIFileSpec *dllSpec);
nsDll *CreateCachedDllName(const char *dllName);
nsresult UnloadLibraries(nsIServiceManager *servmgr);
// The following functions are the only ones that operate on the persistent
// registry
nsresult PlatformInit(void);
nsresult PlatformVersionCheck();
nsresult PlatformCreateDll(const char *fullname, nsDll* *result);
nsresult PlatformMarkNoComponents(nsDll *dll);
nsresult PlatformRegister(const char *cidString, const char *className, const char *progID, nsDll *dll);
nsresult PlatformUnregister(const char *cidString, const char *aLibrary);
nsresult PlatformFind(const nsCID &aCID, nsDll* *aDll);
nsresult PlatformFind(const nsCID &aCID, nsFactoryEntry* *result);
nsresult PlatformProgIDToCLSID(const char *aProgID, nsCID *aClass);
nsresult PlatformCLSIDToProgID(nsCID *aClass, char* *aClassName, char* *aProgID);
void PlatformGetFileInfo(nsIRegistry::Key Key, PRUint32 *lastModifiedTime, PRUint32 *fileSize);
void PlatformSetFileInfo(nsIRegistry::Key Key, PRUint32 lastModifiedTime, PRUint32 fileSize);
protected:
nsObjectHashtable* mFactories;
nsObjectHashtable* mProgIDs;
nsSupportsHashtable* mLoaders;
PRMonitor* mMon;
nsObjectHashtable* mDllStore;
nsIRegistry* mRegistry;
nsIRegistry::Key mXPCOMKey;
nsIRegistry::Key mClassesKey;
nsIRegistry::Key mCLSIDKey;
PRBool mPrePopulationDone;
nsNativeComponentLoader *mNativeComponentLoader;
};
#define NS_MAX_FILENAME_LEN 1024
@@ -241,8 +256,9 @@ protected:
* alpha0.50 : using nsIRegistry
* alpha0.60 : xpcom 2.0 landing
* alpha0.70 : using nsIFileSpec. PRTime -> PRUint32
* alpha0.90 : using nsIComponentLoader, abs:/rel:/lib:, shaver-cleanup
*/
#define NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING "alpha0.70"
#define NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING "alpha0.90"
////////////////////////////////////////////////////////////////////////////////
/**
@@ -261,19 +277,33 @@ protected:
class nsFactoryEntry {
public:
nsFactoryEntry(const nsCID &aClass, nsDll *dll);
nsFactoryEntry(const nsCID &aClass, char *location, char *aType,
nsIComponentLoader *aLoader);
nsFactoryEntry(const nsCID &aClass, nsIFactory *aFactory);
~nsFactoryEntry();
nsresult GetFactory(nsIFactory **aFactory) {
if (factory) {
*aFactory = factory.get();
NS_ADDREF(*aFactory);
return NS_OK;
}
nsresult rv = loader->GetFactory(cid, location, type, aFactory);
if (NS_SUCCEEDED(rv))
factory = *aFactory;
return rv;
}
#if 0 /* unused? */
nsresult Init(nsHashtable* dllHashtable, const nsCID &aClass, const char *aLibrary,
PRTime lastModTime, PRUint32 fileSize);
#endif
nsCID cid;
nsIFactory *factory;
// DO NOT DELETE THIS. Many nsFactoryEntry(s) could be sharing the same Dll.
// This gets deleted from the dllStore going away.
nsDll *dll;
char *location;
nsCOMPtr<nsIFactory> factory;
char *type;
nsCOMPtr<nsIComponentLoader> loader;
};
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,76 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIFactory.idl"
#include "nsIFileSpec.idl"
[object, uuid(c073cfc0-567c-11d3-aec1-0000f8e25c06)]
interface nsIComponentLoader : nsISupports {
/**
* Get the factory for a given component.
*/
nsIFactory GetFactory(in nsIIDRef aCID, in string aLocation,
in string aType);
/**
* Initialize the loader.
*
* We use nsISupports here because nsIComponentManager and nsIRegistry
* aren't IDLized yet.
*/
void Init(in nsISupports aCompMgr, in nsISupports aRegistry);
/**
* Called when a component of the appropriate type is registered,
* to give the component loader an opportunity to do things like
* annotate the registry and such.
*/
void OnRegister(in nsIIDRef aCID, in string aType,
in string aClassName, in string aProgID,
in string aLocation, in boolean aReplace,
in boolean aPersist);
/**
* When is AutoRegistration occuring?
*/
const long Startup = 0;
const long Component = 1;
const long Timer = 2;
/**
* AutoRegister components in the given directory.
*/
void AutoRegisterComponents(in long aWhen, in nsIFileSpec aDirectory);
/**
* AutoRegister the given component.
*
* Returns true if the component was registered, false if it couldn't
* attempt to register the component (wrong type) and ``throws'' an
* NS_FAILED code if there was an error during registration.
*/
boolean AutoRegisterComponent(in long aWhen, in nsIFileSpec aComponent);
/**
* Unload all components that are willing.
*/
void UnloadAll(in long aWhen);
};

View File

@@ -1,39 +0,0 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsIFactory.idl
*/
#ifndef __gen_nsIFactory_h__
#define __gen_nsIFactory_h__
#include "nsISupports.h" /* interface nsISupports */
#include "nsrootidl.h" /* interface nsrootidl */
#ifdef XPIDL_JS_STUBS
#include "jsapi.h"
#endif
/* starting interface: nsIFactory */
/* {00000001-0000-0000-c000-000000000046} */
#define NS_IFACTORY_IID_STR "00000001-0000-0000-c000-000000000046"
#define NS_IFACTORY_IID \
{0x00000001, 0x0000, 0x0000, \
{ 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }}
class nsIFactory : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFACTORY_IID)
/* voidStar CreateInstance (in nsISupports aOuter, in nsIIDRef iid); */
NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID & iid, void * *_retval) = 0;
/* void LockFactory (in PRBool lock); */
NS_IMETHOD LockFactory(PRBool lock) = 0;
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIFactory *priv);
#endif
};
#endif /* __gen_nsIFactory_h__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.h"
#include "nsIRegistry.h"
#include "nsIComponentLoader.h"
#include "nsIComponentManager.h"
#include "nsIFileSpec.h"
#include "nsIRegistry.h"
#include "nsSpecialSystemDirectory.h"
#include "nsCOMPtr.h"
#include "nsHashtable.h"
#include "xcDll.h"
#ifndef nsNativeComponentLoader_h__
#define nsNativeComponentLoader_h__
class nsNativeComponentLoader : public nsIComponentLoader {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICOMPONENTLOADER
nsNativeComponentLoader();
virtual ~nsNativeComponentLoader();
PRBool IsRelativePath(nsIFileSpec *path);
nsresult RegistryNameForLib(const char *aLibName,
char **aRegistryName);
nsresult RegistryNameForSpec(nsIFileSpec *aSpec,
char **aRegistryName);
protected:
nsCOMPtr<nsIRegistry> mRegistry;
nsCOMPtr<nsIComponentManager> mCompMgr;
nsObjectHashtable* mDllStore;
NS_IMETHOD RegisterComponentsInDir(PRInt32 when, nsIFileSpec *dir);
nsIRegistry::Key mXPCOMKey;
nsSpecialSystemDirectory *mComponentsDir;
PRUint32 mComponentsDirLen;
private:
nsresult CreateDll(nsIFileSpec *spec, const char *aLocation, nsDll **aDll);
nsresult SelfRegisterDll(nsDll *dll, const char *registryLocation);
nsresult SelfUnregisterDll(nsDll *dll);
void GetRegistryDllInfo(const char *aLocation, PRUint32 *lastModifiedTime,
PRUint32 *fileSize);
nsresult GetFactoryFromModule(nsDll *aDll, const nsCID &aCID,
nsIFactory **aFactory);
/* obsolete! already! */
nsresult GetFactoryFromNSGetFactory(nsDll *aDlll, const nsCID &aCID,
nsIServiceManager *aServMgr,
nsIFactory **aFactory);
};
#endif /* nsNativeComponentLoader_h__ */

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
@@ -31,7 +31,6 @@
#include "nsIFileSpec.h"
#include "nsCOMPtr.h"
// MAC ONLY
nsDll::nsDll(const char *codeDllName, int type)
: m_dllName(NULL), m_dllSpec(NULL), m_modDate(0), m_size(0),
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
@@ -50,12 +49,13 @@ nsDll::nsDll(const char *codeDllName, int type)
}
}
nsDll::nsDll(nsIFileSpec *dllSpec)
nsDll::nsDll(nsIFileSpec *dllSpec, const char *registryLocation)
: m_dllName(NULL), m_dllSpec(dllSpec), m_modDate(0), m_size(0),
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE)
{
m_registryLocation = nsCRT::strdup(registryLocation);
Init(dllSpec);
}
@@ -96,6 +96,26 @@ nsDll::Init(nsIFileSpec *dllSpec)
m_status = DLL_INVALID_PARAM;
return;
}
#ifdef XP_UNIX
/* on Unix, symlinks are fair game too; XXX move to nsFileSpec? */
if (!isFile) {
#ifdef DEBUG_shaver
char *pathName;
m_dllSpec->GetNativePath(&pathName);
fprintf(stderr, "%s is not a file ", pathName);
nsAllocator::Free(pathName);
#endif
if (NS_FAILED(m_dllSpec->IsSymlink(&isFile))) {
m_status = DLL_INVALID_PARAM;
return;
}
#ifdef DEBUG_shaver
fputs(isFile ? "but it's a symlink\n" : "and it's not a symlink\n",
stderr);
#endif
}
#endif /* XP_UNIX */
if (isFile == PR_FALSE)
{
// Not a file. Cant work with it.
@@ -159,6 +179,8 @@ nsDll::~nsDll(void)
nsCRT::free(m_persistentDescriptor);
if (m_nativePath)
nsCRT::free(m_nativePath);
if (m_registryLocation)
nsCRT::free(m_registryLocation);
}
@@ -202,6 +224,10 @@ nsDll::HasChanged()
if (NS_FAILED(rv) || aSize != m_size)
return PR_TRUE;
#ifdef DEBUG_shaver
fprintf(stderr, "%s not changed (%d/%d\n)",
GetNativePath(), m_modDate, m_size);
#endif
return PR_FALSE;
}
@@ -288,7 +314,7 @@ void * nsDll::FindSymbol(const char *symbol)
if (Load() != PR_TRUE)
return (NULL);
return (PR_FindSymbol(m_instance, symbol));
return(PR_FindSymbol(m_instance, symbol));
}
@@ -332,7 +358,8 @@ nsresult nsDll::GetModule(nsISupports *servMgr, nsIModule **cobj)
nsGetModuleProc proc =
(nsGetModuleProc) FindSymbol(NS_GET_MODULE_SYMBOL);
if (proc == NULL) return NS_ERROR_FAILURE;
if (proc == NULL)
return NS_ERROR_FACTORY_NOT_LOADED;
rv = (*proc) (compMgr, m_dllSpec, &m_moduleObject);
if (NS_SUCCEEDED(rv))

View File

@@ -28,6 +28,9 @@
#include "prlink.h"
#include "nsISupports.h"
#ifndef xcDll_h__
#define xcDll_h__
class nsIFileSpec;
class nsIModule;
class nsIServiceManager;
@@ -59,13 +62,14 @@ private:
char *m_nativePath;
PRBool m_markForUnload;
char *m_registryLocation;
void Init(nsIFileSpec *dllSpec);
void Init(const char *persistentDescriptor);
public:
nsDll(nsIFileSpec *dllSpec);
nsDll(nsIFileSpec *dllSpec, const char *registryLocation);
nsDll(const char *persistentDescriptor);
nsDll(const char *persistentDescriptor, PRUint32 modDate, PRUint32 fileSize);
nsDll(const char *dll, int type /* dummy */);
@@ -101,3 +105,5 @@ public:
nsresult GetDllSpec(nsIFileSpec **dllSpec);
nsresult GetModule(nsISupports *servMgr, nsIModule **mobj);
};
#endif /* xcDll_h__ */