This commit is contained in:
dougt%netscape.com 2000-02-03 02:29:57 +00:00
Родитель baac755daa
Коммит f603ef85b4
1 изменённых файлов: 54 добавлений и 291 удалений

Просмотреть файл

@ -23,6 +23,7 @@
#include "nscore.h"
#include "nsIGenericFactory.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIComponentManager.h"
@ -77,7 +78,6 @@ static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID)
static NS_DEFINE_IID(kIScriptExternalNameSetIID, NS_ISCRIPTEXTERNALNAMESET_IID);
static NS_DEFINE_IID(kISoftwareUpdate_IID, NS_ISOFTWAREUPDATE_IID);
static NS_DEFINE_IID(kSoftwareUpdate_CID, NS_SoftwareUpdate_CID);
static NS_DEFINE_IID(kIInstallTrigger_IID, NS_IDOMINSTALLTRIGGERGLOBAL_IID);
static NS_DEFINE_IID(kInstallTrigger_CID, NS_SoftwareUpdateInstallTrigger_CID);
@ -477,206 +477,20 @@ CreateNewSoftwareUpdate(nsISupports* aOuter, REFNSIID aIID, void **aResult)
return rv;
}
static NS_IMETHODIMP
CreateNewInstallTrigger(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_ERROR_NO_AGGREGATION;
}
nsInstallTrigger* inst = new nsInstallTrigger();
if (inst == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(inst);
nsresult rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst);
return rv;
}
static NS_IMETHODIMP
CreateNewInstallVersion(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_ERROR_NO_AGGREGATION;
}
nsInstallVersion* inst = new nsInstallVersion();
if (inst == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(inst);
nsresult rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); /* get rid of extra refcnt */
return rv;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsInstallTrigger);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsInstallVersion);
//----------------------------------------------------------------------
nsSoftwareUpdateModule::nsSoftwareUpdateModule()
: mInitialized(PR_FALSE)
nsresult RegisterSoftwareUpdate( nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
{
NS_INIT_ISUPPORTS();
}
nsSoftwareUpdateModule::~nsSoftwareUpdateModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsSoftwareUpdateModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsSoftwareUpdateModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsSoftwareUpdateModule::Shutdown()
{
// Release the factory objects
mSoftwareUpdateFactory = nsnull;
mInstallTriggerFactory = nsnull;
mInstallVersionFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsSoftwareUpdateModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kSoftwareUpdate_CID)) {
if (!mSoftwareUpdateFactory) {
// Create and save away the factory object for creating
// new instances of SoftwareUpdate. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mSoftwareUpdateFactory),
CreateNewSoftwareUpdate);
}
fact = mSoftwareUpdateFactory;
}
else if (aClass.Equals(kInstallTrigger_CID)) {
if (!mInstallTriggerFactory) {
// Create and save away the factory object for creating
// new instances of InstallTrigger. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mInstallTriggerFactory),
CreateNewInstallTrigger);
}
fact = mInstallTriggerFactory;
}
else if (aClass.Equals(kInstallVersion_CID)) {
if (!mInstallVersionFactory) {
// Create and save away the factory object for creating
// new instances of InstallVersion. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mInstallVersionFactory),
CreateNewInstallVersion);
}
fact = mInstallVersionFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsSoftwareUpdateModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "SoftwareUpdate Component", &kSoftwareUpdate_CID,
NS_IXPINSTALLCOMPONENT_PROGID, },
{ "InstallTrigger Component", &kInstallTrigger_CID,
NS_INSTALLTRIGGERCOMPONENT_PROGID, },
{ "InstallVersion Component", &kInstallVersion_CID,
NS_INSTALLVERSIONCOMPONENT_PROGID, },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsSoftwareUpdateModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering XPInstall\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if ( NS_SUCCEEDED( rv ) )
{
// get the registry
nsIRegistry* registry;
rv = nsServiceManager::GetService(NS_REGISTRY_PROGID,
nsresult rv = nsServiceManager::GetService(NS_REGISTRY_PROGID,
NS_GET_IID(nsIRegistry),
(nsISupports**)&registry);
if ( NS_SUCCEEDED( rv ) )
@ -697,86 +511,35 @@ nsSoftwareUpdateModule::RegisterSelf(nsIComponentManager *aCompMgr,
&key );
nsServiceManager::ReleaseService(NS_REGISTRY_PROGID, registry);
}
cp++;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsSoftwareUpdateModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
}
return rv;
}
NS_IMETHODIMP
nsSoftwareUpdateModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation)
// The list of components we register
static nsModuleComponentInfo components[] =
{
#ifdef DEBUG
printf("*** Unregistering SoftwareUpdate 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("nsSoftwareUpdateModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
{ "SoftwareUpdate Component",
NS_SoftwareUpdate_CID,
NS_IXPINSTALLCOMPONENT_PROGID,
CreateNewSoftwareUpdate,
(NSRegisterSelfProcPtr)RegisterSoftwareUpdate,
},
return NS_OK;
}
{ "InstallTrigger Component",
NS_SoftwareUpdateInstallTrigger_CID,
NS_INSTALLTRIGGERCOMPONENT_PROGID,
nsInstallTriggerConstructor,
},
NS_IMETHODIMP
nsSoftwareUpdateModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsSoftwareUpdateModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFile* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(return_cobj);
NS_ENSURE_FALSE(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsSoftwareUpdateModule *m = new nsSoftwareUpdateModule();
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;
}
{ "InstallVersion Component",
NS_SoftwareUpdateInstallVersion_CID,
NS_INSTALLVERSIONCOMPONENT_PROGID,
nsInstallVersionConstructor,
},
};
NS_IMPL_NSGETMODULE("nsSoftwareUpdate", components)