This commit is contained in:
dp%netscape.com 1999-04-03 01:05:56 +00:00
Родитель 2139f85e5b
Коммит 2fed4f56bc
1 изменённых файлов: 59 добавлений и 14 удалений

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

@ -16,15 +16,17 @@
* Reserved.
*/
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIWalletService.h"
//#include "nsIServiceManager.h"
//#include "nsRepository.h"
#include "nsIServiceManager.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kWalletServiceCID, NS_WALLETSERVICE_CID);
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
//#if defined(HAS_C_PLUS_PLUS_CASTS)
//#define NS_STATIC_CAST(__type, __ptr) static_cast<__type>(__ptr)
@ -85,9 +87,9 @@ WalletFactoryImpl::QueryInterface(const nsIID &aIID,
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
@ -109,26 +111,21 @@ WalletFactoryImpl::CreateInstance(nsISupports *aOuter,
*aResult = nsnull;
nsresult rv;
PRBool wasRefCounted = PR_TRUE;
nsISupports *inst = nsnull;
if (mClassID.Equals(kWalletServiceCID)) {
if (NS_FAILED(rv = NS_NewWalletService((nsIWalletService**) &inst)))
return rv;
}
else {
return NS_ERROR_NO_INTERFACE;
return NS_ERROR_NO_INTERFACE;
}
if (! inst)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult))) {
// We didn't get the right interface, so clean up
delete inst;
delete inst;
}
if (wasRefCounted)
NS_IF_RELEASE(inst);
return rv;
}
@ -161,3 +158,51 @@ NSGetFactory(nsISupports* serviceMgr,
*aFactory = factory;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
// register wallet service
rv = compMgr->RegisterComponent(kWalletServiceCID,
NS_WALLETSERVICE_CLASSNAME,
NS_WALLETSERVICE_PROGID,
aPath, PR_TRUE, PR_TRUE);
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(nsISupports* aServMgr , const char* aPath)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
// unregister wallet component
rv = compMgr->UnregisterComponent(kWalletServiceCID, aPath);
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}