From 951990e55667391c21c340c5b131d12bd6dee213 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Mon, 3 Jan 2000 23:45:32 +0000 Subject: [PATCH] Converting to use nsIModule macro. git-svn-id: svn://10.0.0.236/trunk@56695 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpinstall/notifier/nsXPIFlash.cpp | 225 +--------------------- 1 file changed, 7 insertions(+), 218 deletions(-) diff --git a/mozilla/xpinstall/notifier/nsXPIFlash.cpp b/mozilla/xpinstall/notifier/nsXPIFlash.cpp index aac32da22d5..366a8885c1c 100644 --- a/mozilla/xpinstall/notifier/nsXPIFlash.cpp +++ b/mozilla/xpinstall/notifier/nsXPIFlash.cpp @@ -694,224 +694,13 @@ nsXPINotifierImpl::QueryInterface(REFNSIID aIID, void** aResult) #define NS_XPIUPDATENOTIFIER_CID \ { 0x69fdc800, 0x4050, 0x11d3, { 0xbe, 0x2f, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } -static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); -static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID); -static NS_DEFINE_CID(kXPIUpdateNotifierCID, NS_XPIUPDATENOTIFIER_CID); - -// Module implementation -class nsXPINotifierModule : public nsIModule +static nsModuleComponentInfo components[] = { -public: - nsXPINotifierModule(); - virtual ~nsXPINotifierModule(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIMODULE - -protected: - nsresult Initialize(); - - void Shutdown(); - - PRBool mInitialized; - nsCOMPtr mFactory; + { "XPInstall Update Notifier", + NS_XPIUPDATENOTIFIER_CID, + "component://netscape/rdf/datasource?name=xpinstall-update-notifier", + nsXPINotifierImpl::New + } }; - -//---------------------------------------------------------------------- - -nsXPINotifierModule::nsXPINotifierModule() - : mInitialized(PR_FALSE) -{ - NS_INIT_ISUPPORTS(); -} - -nsXPINotifierModule::~nsXPINotifierModule() -{ - Shutdown(); -} - -NS_IMPL_ISUPPORTS(nsXPINotifierModule, NS_GET_IID(nsIModule)) - -// Perform our one-time intialization for this module -nsresult -nsXPINotifierModule::Initialize() -{ - if (mInitialized) { - return NS_OK; - } - mInitialized = PR_TRUE; - return NS_OK; -} - -// Shutdown this module, releasing all of the module resources -void -nsXPINotifierModule::Shutdown() -{ - // Release the factory object - mFactory = nsnull; -} - -// Create a factory object for creating instances of aClass. -NS_IMETHODIMP -nsXPINotifierModule::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 fact; - if (aClass.Equals(kXPIUpdateNotifierCID)) { - if (!mFactory) { - // Create and save away the factory object for creating - // new instances of XPINotifier. This way if we are called - // again for the factory, we won't need to create a new - // one. - rv = NS_NewGenericFactory(getter_AddRefs(mFactory), - nsXPINotifierImpl::New); - } - fact = mFactory; - } - else { - rv = NS_ERROR_FACTORY_NOT_REGISTERED; -#ifdef DEBUG - char* cs = aClass.ToString(); - printf("+++ nsXPINotifierModule: 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[] = { - { "XPInstall Update Notifier", &kXPIUpdateNotifierCID, - "component://netscape/rdf/datasource?name=xpinstall-update-notifier", }, -}; -#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) - -NS_IMETHODIMP -nsXPINotifierModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) -{ - nsresult rv = NS_OK; - -#ifdef DEBUG - printf("*** Registering XPINotifier components\n"); -#endif - - Components* cp = gComponents; - Components* end = cp + NUM_COMPONENTS; - while (cp < end) { - rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, - cp->mProgID, aPath, PR_TRUE, - PR_TRUE); - if (NS_FAILED(rv)) { -#ifdef DEBUG - printf("nsXPINotifierModule: unable to register %s component => %x\n", - cp->mDescription, rv); -#endif - break; - } - cp++; - } - - return rv; -} - -NS_IMETHODIMP -nsXPINotifierModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) -{ -#ifdef DEBUG - printf("*** Unregistering XPINotifier 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("nsXPINotifierModule: unable to unregister %s component => %x\n", - cp->mDescription, rv); -#endif - } - cp++; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsXPINotifierModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) -{ - if (!okToUnload) { - return NS_ERROR_INVALID_POINTER; - } - *okToUnload = PR_FALSE; - return NS_ERROR_FAILURE; -} - -//---------------------------------------------------------------------- - -static nsXPINotifierModule *gModule = NULL; - -extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, - nsIFileSpec* 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 - nsXPINotifierModule *m = new nsXPINotifierModule(); - 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; -} +NS_IMPL_NSGETMODULE("XPInstallUpdateNotifierModule", components);