XPCOM Cleanup: Fixed Aggregation macros in nsAgg.h to do aggregation correctly. Fixed usages and implementation of aggregation using these macros through out the tree.

This commit is contained in:
tbogard%aol.net 1999-08-19 05:36:30 +00:00
parent ada1396491
commit 57feff30c2
15 changed files with 255 additions and 227 deletions

View File

@ -51,9 +51,6 @@ PR_END_EXTERN_C
#include "nsCLiveconnect.h"
static NS_DEFINE_IID(kILiveconnectIID, NS_ILIVECONNECT_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////
// from nsISupports and AggregatedQueryInterface:
@ -65,18 +62,21 @@ NS_IMPL_AGGREGATED(nsCLiveconnect);
NS_METHOD
nsCLiveconnect::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (aIID.Equals(kISupportsIID)) {
if (!*aInstancePtr)
return NS_ERROR_INVALID_POINTER;
if (aIID.Equals(NS_GET_IID(nsISupports))) {
*aInstancePtr = GetInner();
AddRef();
return NS_OK;
}
if (aIID.Equals(kILiveconnectIID))
{
*aInstancePtr = (nsILiveconnect *)this;
AddRef();
return NS_OK;
else if (aIID.Equals(NS_GET_IID(nsILiveconnect))) {
*aInstancePtr = NS_STATIC_CAST(nsILiveconnect*, this);
}
return NS_NOINTERFACE;
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF((nsISupports*) *aInstancePtr);
return NS_OK;
}

View File

@ -94,17 +94,20 @@ NS_IMPL_RELEASE(nsCLiveconnectFactory)
NS_METHOD
nsCLiveconnectFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult)
return NS_ERROR_INVALID_POINTER;
*aResult = NULL;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
return NS_ERROR_INVALID_ARG;
nsILiveconnect* liveconnect = new nsCLiveconnect(aOuter);
nsCLiveconnect* liveconnect = new nsCLiveconnect(aOuter);
if (liveconnect == NULL)
return NS_ERROR_FAILURE;
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = liveconnect->QueryInterface(aIID, aResult);
if (result != NS_OK)
nsresult result = liveconnect->AggregatedQueryInterface(aIID, aResult);
if (NS_FAILED(result))
delete liveconnect;
return result;

View File

@ -168,19 +168,7 @@ NS_IMPL_ISUPPORTS(nsCJVMManagerFactory, kIFactoryIID)
NS_METHOD
nsCJVMManagerFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
*aResult = NULL;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
nsresult res = NS_ERROR_OUT_OF_MEMORY;
nsJVMManager *manager = new nsJVMManager(aOuter);
if (manager != NULL) {
res = manager->QueryInterface(aIID, (void**)aResult);
if (res != NS_OK)
delete manager;
}
return res;
return nsJVMManager::Create(aOuter, aIID, aResult);
}
NS_METHOD

View File

@ -267,14 +267,21 @@ nsJVMManager::PostEvent(PRUint32 threadID, nsIRunnable* runnable, PRBool async)
NS_METHOD
nsJVMManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
if (!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
*aInstancePtr = nsnull;
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
return NS_ERROR_INVALID_ARG;
nsJVMManager* jvmmgr = new nsJVMManager(outer);
if (jvmmgr == NULL)
return NS_ERROR_OUT_OF_MEMORY;
jvmmgr->AddRef();
*aInstancePtr = (outer != NULL ? (void*) jvmmgr->GetInner() : (void*) jvmmgr);
return NS_OK;
nsresult rv = jvmmgr->AggregatedQueryInterface(aIID, aInstancePtr);
if(NS_FAILED(rv))
delete jvmmgr;
return rv;
}
nsJVMManager::nsJVMManager(nsISupports* outer)

View File

@ -26,7 +26,6 @@
#include "xp.h"
#include "xp_str.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
@ -54,13 +53,20 @@ NS_IMPL_AGGREGATED(nsJVMPluginTagInfo);
NS_METHOD
nsJVMPluginTagInfo::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (aIID.Equals(kIJVMPluginTagInfoIID) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
if(!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
if (aIID.Equals(kIJVMPluginTagInfoIID))
*aInstancePtr = NS_STATIC_CAST(nsIJVMPluginTagInfo*, this);
else if (aIID.Equals(NS_GET_IID(nsISupports)))
*aInstancePtr = GetInner();
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF((nsISupports*)aInstancePtr);
return NS_OK;
}
@ -194,19 +200,22 @@ NS_METHOD
nsJVMPluginTagInfo::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
nsIPluginTagInfo2* info)
{
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
if(!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
if (outer && !aIID.Equals(NS_GET_IID(nsISupports)))
return NS_ERROR_INVALID_ARG;
nsJVMPluginTagInfo* jvmTagInfo = new nsJVMPluginTagInfo(outer, info);
if (jvmTagInfo == NULL)
return NS_ERROR_OUT_OF_MEMORY;
jvmTagInfo->AddRef();
*aInstancePtr = jvmTagInfo->GetInner();
nsresult result = outer->QueryInterface(kIPluginTagInfo2IID,
nsresult result = jvmTagInfo->AggregatedQueryInterface(aIID, aInstancePtr);
if (NS_FAILED(result)) goto error;
result = jvmTagInfo->QueryInterface(kIPluginTagInfo2IID,
(void**)&jvmTagInfo->fPluginTagInfo);
if (result != NS_OK) goto error;
outer->Release(); // no need to AddRef outer
if (NS_FAILED(result)) goto error;
return result;
error:

View File

@ -40,26 +40,40 @@ nsSymantecDebugManager::~nsSymantecDebugManager()
NS_METHOD
nsSymantecDebugManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (aIID.Equals(kISymantecDebugManagerIID)) {
*aInstancePtr = this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
if (!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
if (aIID.Equals(NS_GET_IID(nsISupports)))
*aInstancePtr = GetInner();
else if (aIID.Equals(kISymantecDebugManagerIID))
*aInstancePtr = NS_STATIC_CAST(nsISymantecDebugManager*, this);
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
NS_METHOD
nsSymantecDebugManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
nsJVMManager* jvmMgr)
{
if (!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
return NS_ERROR_INVALID_ARG;
nsSymantecDebugManager* dbgr = new nsSymantecDebugManager(outer, jvmMgr);
if (dbgr == NULL)
return NS_ERROR_OUT_OF_MEMORY;
dbgr->AddRef();
*aInstancePtr = dbgr->GetInner();
return NS_OK;
nsresult rv = dbgr->AggregatedQueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv)) {
delete dbgr;
return rv;
}
return rv;
}
#if defined(XP_PC) && defined(_WIN32)

View File

@ -22,7 +22,6 @@
#include "nsMalloc.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID);
nsMalloc::nsMalloc(nsISupports* outer)
@ -41,30 +40,37 @@ nsMalloc::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIMallocIID) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
if (aIID.Equals(NS_GET_IID(nsISupports)))
*aInstancePtr = GetInner();
else if (aIID.Equals(kIMallocIID))
*aInstancePtr = NS_STATIC_CAST(nsIMalloc*, this);
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
NS_METHOD
nsMalloc::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
if (!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
return NS_ERROR_INVALID_ARG;
nsMalloc* mm = new nsMalloc(outer);
if (mm == NULL)
return NS_ERROR_OUT_OF_MEMORY;
mm->AddRef();
if (aIID.Equals(kISupportsIID))
*aInstancePtr = mm->GetInner();
else
*aInstancePtr = mm;
return NS_OK;
nsresult rv = mm->AggregatedQueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv)) {
delete mm;
return rv;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -22,7 +22,6 @@
#include "nsMalloc.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID);
nsMalloc::nsMalloc(nsISupports* outer)
@ -41,30 +40,37 @@ nsMalloc::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIMallocIID) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
if (aIID.Equals(NS_GET_IID(nsISupports)))
*aInstancePtr = GetInner();
else if (aIID.Equals(kIMallocIID))
*aInstancePtr = NS_STATIC_CAST(nsIMalloc*, this);
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
NS_METHOD
nsMalloc::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
if (!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
if (outer && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE; // XXX right error?
return NS_ERROR_INVALID_ARG;
nsMalloc* mm = new nsMalloc(outer);
if (mm == NULL)
return NS_ERROR_OUT_OF_MEMORY;
mm->AddRef();
if (aIID.Equals(kISupportsIID))
*aInstancePtr = mm->GetInner();
else
*aInstancePtr = mm;
return NS_OK;
nsresult rv = mm->AggregatedQueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv)) {
delete mm;
return rv;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -85,12 +85,18 @@ nsLoadGroup::~nsLoadGroup()
NS_METHOD
nsLoadGroup::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
NS_ENSURE_PROPER_AGGREGATION(aOuter, aIID);
nsLoadGroup* group = new nsLoadGroup(aOuter);
if (group == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(group);
nsresult rv = group->QueryInterface(aIID, aResult);
NS_RELEASE(group);
nsresult rv = group->AggregatedQueryInterface(aIID, aResult);
if (NS_FAILED(rv))
delete group;
return rv;
}
@ -99,16 +105,22 @@ NS_IMPL_AGGREGATED(nsLoadGroup);
NS_IMETHODIMP
nsLoadGroup::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(kLoadGroupCID) || // for internal use only (to set parent)
NS_ENSURE_ARG_POINTER(aInstancePtr);
if (aIID.Equals(NS_GET_IID(nsISupports)))
*aInstancePtr = GetInner();
else if (aIID.Equals(kLoadGroupCID) || // for internal use only (to set parent)
aIID.Equals(nsCOMTypeInfo<nsILoadGroup>::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsIRequest>::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsILoadGroup*, this);
NS_ADDREF_THIS();
return NS_OK;
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
return NS_NOINTERFACE;
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -50,15 +50,19 @@ NS_IMPL_AGGREGATED(nsSimpleURI);
NS_IMETHODIMP
nsSimpleURI::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(kThisSimpleURIImplementationCID) || // used by Equals
aIID.Equals(nsIURI::GetIID()) ||
aIID.Equals(kISupportsIID)) {
NS_ENSURE_ARG_POINTER(aInstancePtr);
if (aIID.Equals(kISupportsIID))
*aInstancePtr = GetInner();
else if (aIID.Equals(kThisSimpleURIImplementationCID) || // used by Equals
aIID.Equals(nsIURI::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIURI*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
@ -217,12 +221,17 @@ nsSimpleURI::Clone(nsIURI* *result)
NS_METHOD
nsSimpleURI::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
NS_ENSURE_PROPER_AGGREGATION(aOuter, aIID);
nsSimpleURI* url = new nsSimpleURI(aOuter);
if (url == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(url);
nsresult rv = url->QueryInterface(aIID, aResult);
NS_RELEASE(url);
nsresult rv = url->AggregatedQueryInterface(aIID, aResult);
if (NS_FAILED(rv))
delete url;
return rv;
}

View File

@ -128,15 +128,21 @@ NS_IMETHODIMP
nsStdURL::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(kThisStdURLImplementationCID) || // used by Equals
if(!aInstancePtr)
return NS_ERROR_INVALID_POINTER;
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aInstancePtr = GetInner();
else if (aIID.Equals(kThisStdURLImplementationCID) || // used by Equals
aIID.Equals(nsCOMTypeInfo<nsIURL>::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsIURI>::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
aIID.Equals(nsCOMTypeInfo<nsIURI>::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIURL*, this);
NS_ADDREF_THIS();
return NS_OK;
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
return NS_NOINTERFACE;
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
NS_IMETHODIMP
@ -619,10 +625,22 @@ nsStdURL::Create(nsISupports *aOuter,
REFNSIID aIID,
void **aResult)
{
if (!aResult)
return NS_ERROR_INVALID_POINTER;
if (aOuter && !aIID.Equals(NS_GET_IID(nsISupports)))
return NS_ERROR_INVALID_ARG;
nsStdURL* url = new nsStdURL(nsnull, aOuter);
if (url == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = url->QueryInterface(aIID, aResult);
nsresult rv = url->AggregatedQueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
delete url;
return rv;
}
return rv;
}

View File

@ -21,34 +21,6 @@
#include "nsISupports.h"
/**
* Outer objects can implement nsIOuter if they choose, allowing them to
* get notification if their inner objects (children) are effectively freed.
* This allows them to reset any state associated with the inner object and
* potentially unload it.
*/
class nsIOuter : public nsISupports {
public:
/**
* This method is called whenever an inner object's refcount is about to
* become zero and the inner object should be released by the outer. This
* allows the outer to clean up any state associated with the inner and
* potentially unload the inner object. This method should call
* inner->Release().
*/
NS_IMETHOD
ReleaseInner(nsISupports* inner) = 0;
};
#define NS_IOUTER_IID \
{ /* ea0bf9f0-3d67-11d2-8163-006008119d7a */ \
0xea0bf9f0, \
0x3d67, \
0x11d2, \
{0x81, 0x63, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
}
////////////////////////////////////////////////////////////////////////////////
@ -56,13 +28,15 @@ public:
#define NS_DECL_AGGREGATED \
NS_DECL_ISUPPORTS \
\
protected: \
public: \
\
/* You must implement this operation instead of the nsISupports */ \
/* methods if you inherit from nsAggregated. */ \
NS_IMETHOD \
AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr); \
\
protected: \
\
class Internal : public nsISupports { \
public: \
\
@ -89,7 +63,7 @@ public: \
#define NS_INIT_AGGREGATED(outer) \
PR_BEGIN_MACRO \
NS_INIT_REFCNT(); \
fOuter = outer; \
fOuter = outer ? outer : &fAggregated; \
PR_END_MACRO
@ -98,48 +72,19 @@ public: \
NS_IMETHODIMP \
_class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
{ \
/* try our own interfaces first before delegating to outer */ \
nsresult rslt = AggregatedQueryInterface(aIID, aInstancePtr); \
if (rslt != NS_OK && fOuter) \
return fOuter->QueryInterface(aIID, aInstancePtr); \
else \
return rslt; \
return fOuter->QueryInterface(aIID, aInstancePtr); \
} \
\
NS_IMETHODIMP_(nsrefcnt) \
_class::AddRef(void) \
{ \
++mRefCnt; /* keep track of our refcount as well as outer's */ \
if (fOuter) \
return NS_ADDREF(fOuter); \
else \
return mRefCnt; \
return fOuter->AddRef(); \
} \
\
NS_IMETHODIMP_(nsrefcnt) \
_class::Release(void) \
{ \
if (fOuter) { \
nsISupports* outer = fOuter; /* in case we release ourself */ \
nsIOuter* outerIntf; \
static NS_DEFINE_IID(kIOuterIID, NS_IOUTER_IID); \
if (mRefCnt == 1 && \
outer->QueryInterface(kIOuterIID, \
(void**)&outerIntf) == NS_OK) { \
outerIntf->ReleaseInner(GetInner()); \
outerIntf->Release(); \
} \
else \
--mRefCnt; /* keep track of our refcount as well as outer's */ \
return outer->Release(); \
} \
else { \
if (--mRefCnt == 0) { \
delete this; \
return 0; \
} \
return mRefCnt; \
} \
return fOuter->Release(); \
} \
\
NS_IMETHODIMP \

View File

@ -37,32 +37,36 @@ NS_IMPL_AGGREGATED(nsAllocatorImpl);
NS_METHOD
nsAllocatorImpl::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsIAllocator::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
*aInstancePtr = (void*) this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
NS_ENSURE_ARG_POINTER(aInstancePtr);
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aInstancePtr = GetInner();
else if (aIID.Equals(nsIAllocator::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIAllocator*, this);
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
NS_METHOD
nsAllocatorImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
if (outer && !aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
return NS_NOINTERFACE; // XXX right error?
NS_ENSURE_ARG_POINTER(aInstancePtr);
NS_ENSURE_PROPER_AGGREGATION(outer, aIID);
nsAllocatorImpl* mm = new nsAllocatorImpl(outer);
if (mm == NULL)
return NS_ERROR_OUT_OF_MEMORY;
mm->AddRef();
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aInstancePtr = mm->GetInner();
else
*aInstancePtr = mm;
return NS_OK;
nsresult rv = mm->AggregatedQueryInterface(aIID, aInstancePtr);
if (NS_FAILED(rv))
delete mm;
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -42,16 +42,14 @@ NS_COM nsresult NS_NewObserver(nsIObserver** anObserver, nsISupports* outer)
NS_METHOD
nsObserver::Create(nsISupports* outer, const nsIID& aIID, void* *anObserver)
{
if (anObserver == NULL)
return NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG_POINTER(anObserver);
NS_ENSURE_PROPER_AGGREGATION(outer, aIID);
nsObserver* it = new nsObserver(outer);
if (it == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsISupports* inner = outer ? it->GetInner() : it;
nsresult rv = inner->QueryInterface(aIID, anObserver);
nsresult rv = it->AggregatedQueryInterface(aIID, anObserver);
if (NS_FAILED(rv)) {
delete it;
return rv;
@ -71,15 +69,19 @@ nsObserver::~nsObserver(void)
NS_IMETHODIMP
nsObserver::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (aInstancePtr == nsnull)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIObserver::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
*aInstancePtr = (nsIObserver*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
NS_ENSURE_ARG_POINTER(aInstancePtr);
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aInstancePtr = GetInner();
else if(aIID.Equals(nsIObserver::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIObserver*, this);
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
NS_IMETHODIMP

View File

@ -32,15 +32,17 @@ nsProperties::nsProperties(nsISupports* outer)
NS_METHOD
nsProperties::Create(nsISupports *outer, REFNSIID aIID, void **aResult)
{
if (outer && !aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
return NS_NOINTERFACE; // XXX right error?
NS_ENSURE_ARG_POINTER(aResult);
NS_ENSURE_PROPER_AGGREGATION(outer, aIID);
nsProperties* props = new nsProperties(outer);
if (props == NULL)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(props);
nsresult rv = props->QueryInterface(aIID, aResult);
NS_RELEASE(props);
return NS_OK;
nsresult rv = props->AggregatedQueryInterface(aIID, aResult);
if (NS_FAILED(rv))
delete props;
return rv;
}
PRBool
@ -61,16 +63,19 @@ NS_IMPL_AGGREGATED(nsProperties);
NS_METHOD
nsProperties::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsIProperties::GetIID()) ||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
*aInstancePtr = (void*) this;
NS_ADDREF_THIS();
return NS_OK;
NS_ENSURE_ARG_POINTER(aInstancePtr);
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
*aInstancePtr = GetInner();
else if (aIID.Equals(nsIProperties::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIProperties*, this);
else {
*aInstancePtr = nsnull;
return NS_NOINTERFACE;
}
return NS_NOINTERFACE;
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
NS_IMETHODIMP