1999-08-03 07:41:27 +04:00
|
|
|
// nsWeakReference.cpp
|
|
|
|
|
|
|
|
#include "nsWeakReference.h"
|
1999-08-03 12:34:17 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-08-03 07:41:27 +04:00
|
|
|
|
1999-08-12 03:48:08 +04:00
|
|
|
NS_COM nsIWeakReference *
|
1999-08-03 07:41:27 +04:00
|
|
|
NS_GetWeakReference( nsISupports* aInstance, nsresult* aResult )
|
|
|
|
{
|
1999-08-03 08:59:47 +04:00
|
|
|
nsresult status;
|
|
|
|
if ( !aResult )
|
|
|
|
aResult = &status;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsWeakReference> factoryP = do_QueryInterface(aInstance, aResult);
|
1999-08-03 07:41:27 +04:00
|
|
|
|
1999-08-03 08:59:47 +04:00
|
|
|
nsIWeakReference* weakP = 0;
|
|
|
|
if ( factoryP )
|
|
|
|
status = factoryP->GetWeakReference(&weakP);
|
|
|
|
return weakP;
|
1999-08-03 07:41:27 +04:00
|
|
|
}
|
|
|
|
|
1999-08-12 03:48:08 +04:00
|
|
|
NS_IMETHODIMP
|
1999-08-03 07:41:27 +04:00
|
|
|
nsSupportsWeakReference::GetWeakReference( nsIWeakReference** aInstancePtr )
|
|
|
|
{
|
|
|
|
if ( !aInstancePtr )
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if ( !mProxy )
|
|
|
|
mProxy = new nsWeakReference(this);
|
|
|
|
*aInstancePtr = mProxy;
|
|
|
|
|
|
|
|
nsresult status;
|
|
|
|
if ( !*aInstancePtr )
|
|
|
|
status = NS_NOINTERFACE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_ADDREF(*aInstancePtr);
|
|
|
|
status = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-08-12 03:48:08 +04:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
1999-08-03 07:41:27 +04:00
|
|
|
nsWeakReference::AddRef()
|
|
|
|
{
|
1999-08-03 08:59:47 +04:00
|
|
|
return ++mRefCount;
|
1999-08-03 07:41:27 +04:00
|
|
|
}
|
|
|
|
|
1999-08-12 03:48:08 +04:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
1999-08-03 07:41:27 +04:00
|
|
|
nsWeakReference::Release()
|
|
|
|
{
|
|
|
|
nsrefcnt temp = --mRefCount;
|
|
|
|
if ( !mRefCount )
|
|
|
|
delete this;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
1999-08-12 03:48:08 +04:00
|
|
|
NS_IMETHODIMP
|
1999-08-03 07:41:27 +04:00
|
|
|
nsWeakReference::QueryInterface( const nsIID& aIID, void** aInstancePtr )
|
|
|
|
{
|
|
|
|
if ( !aInstancePtr )
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if ( aIID.Equals(nsCOMTypeInfo<nsIWeakReference>::GetIID()) )
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIWeakReference*, this);
|
|
|
|
else if ( aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()) )
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsISupports*, this);
|
|
|
|
else
|
|
|
|
*aInstancePtr = 0;
|
|
|
|
|
|
|
|
nsresult status;
|
|
|
|
if ( !*aInstancePtr )
|
|
|
|
status = NS_NOINTERFACE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_ADDREF( NS_REINTERPRET_CAST(nsISupports*, *aInstancePtr) );
|
|
|
|
status = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-08-12 03:48:08 +04:00
|
|
|
NS_IMETHODIMP
|
1999-08-14 03:00:58 +04:00
|
|
|
nsWeakReference::QueryReferent( const nsIID& aIID, void** aInstancePtr )
|
1999-08-03 07:41:27 +04:00
|
|
|
{
|
1999-08-03 08:59:47 +04:00
|
|
|
return mReferent ? mReferent->QueryInterface(aIID, aInstancePtr) : NS_ERROR_NULL_POINTER;
|
1999-08-03 07:41:27 +04:00
|
|
|
}
|