зеркало из https://github.com/mozilla/gecko-dev.git
Backing out changes due to nsCOMPtr build problems.
This commit is contained in:
Родитель
fd87026ad8
Коммит
4ccf22afa1
|
@ -72,21 +72,18 @@ class nsProxyObject : public nsISupports
|
|||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsCOMTypeInfo<nsISupports>::GetIID())
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsCOMTypeInfo<nsISupports>::GetIID())
|
||||
nsProxyObject();
|
||||
nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject);
|
||||
nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID);
|
||||
|
||||
virtual ~nsProxyObject();
|
||||
|
||||
nsresult Post( PRUint32 methodIndex,
|
||||
nsXPTMethodInfo * info,
|
||||
nsXPTCMiniVariant * params,
|
||||
nsIInterfaceInfo * interfaceInfo);
|
||||
nsresult Post(PRUint32 methodIndex, nsXPTMethodInfo *info,
|
||||
nsXPTCMiniVariant *params, nsIInterfaceInfo *interfaceInfo);
|
||||
|
||||
nsresult PostAndWait(nsProxyObjectCallInfo *proxyInfo);
|
||||
nsISupports* GetRealObject();
|
||||
nsresult NestedEventLoop(nsProxyObjectCallInfo *proxyInfo);
|
||||
nsISupports* GetRealObject() const { return mRealObject; }
|
||||
nsIEventQueue* GetQueue();
|
||||
PRInt32 GetProxyType() const { return mProxyType; }
|
||||
|
||||
|
@ -94,20 +91,6 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
|
||||
PRInt32 mProxyType;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> mDestQueue; /* destination queue */
|
||||
|
||||
nsCOMPtr<nsISupports> mRealObject; /* the non-proxy object that this event is referring to.
|
||||
This is a strong ref. */
|
||||
|
||||
|
||||
nsresult convertMiniVariantToVariant(nsXPTMethodInfo * methodInfo,
|
||||
nsXPTCMiniVariant * params,
|
||||
nsXPTCVariant **fullParam,
|
||||
uint8 *paramCount);
|
||||
|
||||
#ifdef AUTOPROXIFICATION
|
||||
typedef enum
|
||||
{
|
||||
|
@ -121,7 +104,19 @@ private:
|
|||
nsresult AutoProxyParameterList(PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMiniVariant * params,
|
||||
nsIInterfaceInfo *interfaceInfo, AutoProxyConvertTypes convertType);
|
||||
#endif
|
||||
};
|
||||
|
||||
nsIEventQueue *mDestQueue; /* destination queue */
|
||||
nsISupports *mRealObject; /* the non-proxy object that this event is referring to.
|
||||
This is a strong ref. */
|
||||
|
||||
PRBool mRealObjectOwned;
|
||||
PRInt32 mProxyType;
|
||||
|
||||
nsresult convertMiniVariantToVariant(nsXPTMethodInfo *methodInfo, nsXPTCMiniVariant * params,
|
||||
nsXPTCVariant **fullParam, uint8 *paramCount);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class NS_EXPORT nsProxyObjectCallInfo
|
||||
|
@ -129,7 +124,6 @@ class NS_EXPORT nsProxyObjectCallInfo
|
|||
public:
|
||||
|
||||
nsProxyObjectCallInfo(nsProxyObject* owner,
|
||||
nsXPTMethodInfo *methodInfo,
|
||||
PRUint32 methodIndex,
|
||||
nsXPTCVariant* parameterList,
|
||||
PRUint32 parameterCount,
|
||||
|
@ -143,35 +137,23 @@ public:
|
|||
PLEvent* GetPLEvent() const { return mEvent; }
|
||||
nsresult GetResult() const { return mResult; }
|
||||
nsProxyObject* GetProxyObject() const { return mOwner; }
|
||||
|
||||
PRBool GetCompleted();
|
||||
void SetCompleted();
|
||||
void PostCompleted();
|
||||
|
||||
void SetResult(nsresult rv) {mResult = rv; }
|
||||
|
||||
nsIEventQueue* GetCallersQueue();
|
||||
void SetCallersQueue(nsIEventQueue* queue);
|
||||
void SetCompleted();
|
||||
|
||||
private:
|
||||
|
||||
nsresult mResult; /* this is the return result of the called function */
|
||||
nsXPTMethodInfo *mMethodInfo;
|
||||
PRUint32 mMethodIndex; /* which method to be called? */
|
||||
nsXPTCVariant *mParameterList; /* marshalled in parameter buffer */
|
||||
PRUint32 mParameterCount; /* number of params */
|
||||
PLEvent *mEvent; /* the current plevent */
|
||||
PRInt32 mCompleted; /* is true when the method has been called. */
|
||||
|
||||
nsIEventQueue* mCallersEventQ; /* this is the eventQ that we must post a message back to
|
||||
when we are done invoking the method (only PROXY_SYNC).
|
||||
this does not need to be a comptr because it will be
|
||||
released by the created in PostAndWait()
|
||||
*/
|
||||
|
||||
|
||||
nsCOMPtr<nsProxyObject> mOwner; /* this is the strong referenced nsProxyObject */
|
||||
|
||||
void RefCountInInterfacePointers(PRBool addRef);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "nsProxyObjectManager.h"
|
||||
|
||||
#include "pratom.h"
|
||||
#include "prmem.h"
|
||||
#include "prmem.h" // for PR_NEW
|
||||
#include "xptcall.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
|
@ -37,11 +37,8 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
|||
|
||||
static void* EventHandler(PLEvent *self);
|
||||
static void DestroyHandler(PLEvent *self);
|
||||
static void* CompletedEventHandler(PLEvent *self);
|
||||
static void CompletedDestroyHandler(PLEvent *self) ;
|
||||
|
||||
nsProxyObjectCallInfo::nsProxyObjectCallInfo( nsProxyObject* owner,
|
||||
nsXPTMethodInfo *methodInfo,
|
||||
nsProxyObjectCallInfo::nsProxyObjectCallInfo(nsProxyObject* owner,
|
||||
PRUint32 methodIndex,
|
||||
nsXPTCVariant* parameterList,
|
||||
PRUint32 parameterCount,
|
||||
|
@ -53,102 +50,33 @@ nsProxyObjectCallInfo::nsProxyObjectCallInfo( nsProxyObject* owner,
|
|||
mParameterList = parameterList;
|
||||
mParameterCount = parameterCount;
|
||||
mEvent = event;
|
||||
mMethodInfo = methodInfo;
|
||||
mCallersEventQ = 0;
|
||||
|
||||
RefCountInInterfacePointers(PR_TRUE);
|
||||
}
|
||||
|
||||
|
||||
nsProxyObjectCallInfo::~nsProxyObjectCallInfo()
|
||||
{
|
||||
RefCountInInterfacePointers(PR_FALSE);
|
||||
|
||||
// I am worried about order of destruction here.
|
||||
// do not remove assignments.
|
||||
|
||||
mOwner = 0;
|
||||
mCallersEventQ = 0;
|
||||
|
||||
PR_FREEIF(mEvent);
|
||||
|
||||
if (mParameterList)
|
||||
free( (void*) mParameterList);
|
||||
}
|
||||
|
||||
void
|
||||
nsProxyObjectCallInfo::RefCountInInterfacePointers(PRBool addRef)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mParameterCount; i++)
|
||||
{
|
||||
nsXPTParamInfo paramInfo = mMethodInfo->GetParam(i);
|
||||
|
||||
if (paramInfo.GetType().IsInterfacePointer() )
|
||||
{
|
||||
nsISupports* anInterface = nsnull;
|
||||
|
||||
if (paramInfo.IsIn())
|
||||
{
|
||||
anInterface = ((nsISupports*)mParameterList[i].val.p);
|
||||
|
||||
if (anInterface)
|
||||
{
|
||||
if(addRef)
|
||||
anInterface->AddRef();
|
||||
else
|
||||
anInterface->Release();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
PRBool
|
||||
nsProxyObjectCallInfo::GetCompleted()
|
||||
{
|
||||
return (PRBool)mCompleted;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
nsProxyObjectCallInfo::SetCompleted()
|
||||
{
|
||||
PR_AtomicSet(&mCompleted, 1);
|
||||
}
|
||||
|
||||
void
|
||||
nsProxyObjectCallInfo::PostCompleted()
|
||||
{
|
||||
if (mCallersEventQ)
|
||||
{
|
||||
PLEvent *event = PR_NEW(PLEvent);
|
||||
|
||||
PL_InitEvent(event,
|
||||
this,
|
||||
CompletedEventHandler,
|
||||
CompletedDestroyHandler);
|
||||
|
||||
mCallersEventQ->PostSynchronousEvent(event, nsnull);
|
||||
PR_FREEIF(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
// caller does not have an eventQ? This is an error!
|
||||
SetCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
nsIEventQueue*
|
||||
nsProxyObjectCallInfo::GetCallersQueue()
|
||||
{
|
||||
return mCallersEventQ;
|
||||
}
|
||||
void
|
||||
nsProxyObjectCallInfo::SetCallersQueue(nsIEventQueue* queue)
|
||||
{
|
||||
mCallersEventQ = queue;
|
||||
}
|
||||
|
||||
#ifdef debug_DOUGT
|
||||
static PRUint32 totalProxyObjects = 0;
|
||||
static PRUint32 outstandingProxyObjects = 0;
|
||||
#endif
|
||||
|
||||
NS_IMPL_ISUPPORTS0(nsProxyObject)
|
||||
|
||||
|
@ -158,66 +86,71 @@ nsProxyObject::nsProxyObject()
|
|||
}
|
||||
nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject)
|
||||
{
|
||||
#ifdef debug_DOUGT
|
||||
totalProxyObjects++;
|
||||
outstandingProxyObjects++;
|
||||
#endif
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
mRealObject = realObject;
|
||||
mDestQueue = do_QueryInterface(destQueue);
|
||||
mProxyType = proxyType;
|
||||
mDestQueue = destQueue;
|
||||
}
|
||||
|
||||
|
||||
nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID)
|
||||
{
|
||||
#ifdef debug_DOUGT
|
||||
totalProxyObjects++;
|
||||
outstandingProxyObjects++;
|
||||
#endif
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
nsComponentManager::CreateInstance(aClass,
|
||||
aDelegate,
|
||||
aIID,
|
||||
getter_AddRefs(mRealObject));
|
||||
(void**) &mRealObject);
|
||||
|
||||
mDestQueue = do_QueryInterface(destQueue);
|
||||
mProxyType = proxyType;
|
||||
mDestQueue = destQueue;
|
||||
}
|
||||
|
||||
nsProxyObject::~nsProxyObject()
|
||||
{
|
||||
// I am worried about order of destruction here.
|
||||
// do not remove assignments.
|
||||
|
||||
mRealObject = 0;
|
||||
mDestQueue = 0;
|
||||
#ifdef debug_DOUGT
|
||||
outstandingProxyObjects--;
|
||||
printf("[proxyobjects] %d total used in system, %d outstading\n", totalProxyObjects, outstandingProxyObjects);
|
||||
#endif
|
||||
}
|
||||
|
||||
// GetRealObject
|
||||
// This function must return the real pointer to the object to be proxied.
|
||||
// It must not be a comptr or be addreffed.
|
||||
nsISupports*
|
||||
nsProxyObject::GetRealObject()
|
||||
{
|
||||
return mRealObject.get();
|
||||
}
|
||||
|
||||
nsIEventQueue*
|
||||
nsProxyObject::GetQueue()
|
||||
{
|
||||
if (mDestQueue)
|
||||
NS_ADDREF(mDestQueue);
|
||||
return mDestQueue;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsProxyObject::PostAndWait(nsProxyObjectCallInfo *proxyInfo)
|
||||
nsProxyObject::NestedEventLoop(nsProxyObjectCallInfo *proxyInfo)
|
||||
{
|
||||
if (proxyInfo == nsnull) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PLEvent* event = proxyInfo->GetPLEvent();
|
||||
PRBool eventLoopCreated = PR_FALSE;
|
||||
nsresult rv;
|
||||
//---------------------
|
||||
//This block of code should be a function of the EventQueueServices
|
||||
|
||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> eventQ;
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), getter_AddRefs(eventQ));
|
||||
nsIEventQueue *eventQ;
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
|
@ -225,50 +158,36 @@ nsProxyObject::PostAndWait(nsProxyObjectCallInfo *proxyInfo)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), getter_AddRefs(eventQ));
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventQ = 0;
|
||||
rv = eventQService->PushThreadEventQueue(getter_AddRefs(eventQ));
|
||||
NS_RELEASE(eventQ);
|
||||
rv = eventQService->PushThreadEventQueue(&eventQ);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
//---------------------
|
||||
|
||||
proxyInfo->SetCallersQueue(eventQ);
|
||||
|
||||
PLEvent* event = proxyInfo->GetPLEvent();
|
||||
if (!event)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mDestQueue->PostEvent(event);
|
||||
|
||||
while (! proxyInfo->GetCompleted())
|
||||
{
|
||||
//rv = eventQ->WaitForEvent();
|
||||
//if (NS_FAILED(rv)) break;
|
||||
|
||||
rv = eventQ->GetEvent(&event);
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
eventQ->HandleEvent(event);
|
||||
|
||||
PR_Sleep(PR_MillisecondsToInterval(100));
|
||||
|
||||
PR_Sleep( PR_MillisecondsToInterval(5) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (eventLoopCreated)
|
||||
{
|
||||
NS_RELEASE(eventQ);
|
||||
eventQService->DestroyThreadEventQueue();
|
||||
eventQ = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
nsIEventQueue *dumbAddref = eventQ;
|
||||
NS_ADDREF(dumbAddref); // PopThreadEventQueue released the nsCOMPtr,
|
||||
// then we crash while leaving this functions.
|
||||
eventQService->PopThreadEventQueue(dumbAddref); // this is totally evil
|
||||
eventQService->PopThreadEventQueue(eventQ);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -298,7 +217,10 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi
|
|||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (! mDestQueue || ! mRealObject)
|
||||
if (mDestQueue == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (mRealObject == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (methodInfo->IsNotXPCOM())
|
||||
|
@ -309,38 +231,28 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi
|
|||
if (event == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
#ifdef AUTOPROXIFICATION
|
||||
// this should move into the nsProxyObjectCallInfo.
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Auto-proxification
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
#ifdef AUTOPROXIFICATION
|
||||
rv = AutoProxyParameterList(methodIndex, methodInfo, params, interfaceInfo, convertInParameters);
|
||||
#endif
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
delete event;
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
nsXPTCVariant *fullParam;
|
||||
uint8 paramCount;
|
||||
rv = convertMiniVariantToVariant(methodInfo, params, &fullParam, ¶mCount);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
delete event;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsProxyObjectCallInfo *proxyInfo = new nsProxyObjectCallInfo(this,
|
||||
methodInfo,
|
||||
methodIndex,
|
||||
fullParam, // will be deleted by ~()
|
||||
paramCount,
|
||||
event); // will be deleted by ~()
|
||||
nsProxyObjectCallInfo *proxyInfo = new nsProxyObjectCallInfo(this, methodIndex, fullParam, paramCount, event);
|
||||
|
||||
if (proxyInfo == nsnull)
|
||||
{
|
||||
delete event;
|
||||
free(fullParam); // allocated with malloc
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -357,13 +269,12 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi
|
|||
if (callDirectly)
|
||||
{
|
||||
EventHandler(event);
|
||||
// there is no need to call the DestroyHandler() because
|
||||
// there is no need to wake up the nested event loop.
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = PostAndWait(proxyInfo);
|
||||
|
||||
mDestQueue->PostEvent(event);
|
||||
rv = NestedEventLoop(proxyInfo);
|
||||
//mDestQueue->PostSynchronousEvent(event, nsnull);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
@ -371,9 +282,14 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi
|
|||
rv = proxyInfo->GetResult();
|
||||
delete proxyInfo;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Auto-proxification
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
#ifdef AUTOPROXIFICATION
|
||||
rv = AutoProxyParameterList(methodIndex, methodInfo, params, interfaceInfo, convertOutParameters);
|
||||
#endif
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -382,70 +298,16 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi
|
|||
mDestQueue->PostEvent(event);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DestroyHandler(PLEvent *self)
|
||||
{
|
||||
nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
|
||||
nsProxyObject* proxyObject = owner->GetProxyObject();
|
||||
|
||||
if (proxyObject == nsnull)
|
||||
return;
|
||||
|
||||
if (proxyObject->GetProxyType() & PROXY_ASYNC)
|
||||
{
|
||||
delete owner;
|
||||
}
|
||||
else
|
||||
{
|
||||
owner->PostCompleted();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void* EventHandler(PLEvent *self)
|
||||
{
|
||||
nsProxyObjectCallInfo *info = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
|
||||
NS_ASSERTION(info, "No nsProxyObjectCallInfo!");
|
||||
|
||||
nsProxyObject *proxyObject = info->GetProxyObject();
|
||||
|
||||
if (proxyObject)
|
||||
{
|
||||
// invoke the magic of xptc...
|
||||
nsresult rv = XPTC_InvokeByIndex( proxyObject->GetRealObject(),
|
||||
info->GetMethodIndex(),
|
||||
info->GetParameterCount(),
|
||||
info->GetParameterList());
|
||||
info->SetResult(rv);
|
||||
}
|
||||
else
|
||||
{
|
||||
info->SetResult(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
return NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
}
|
||||
|
||||
void CompletedDestroyHandler(PLEvent *self)
|
||||
{
|
||||
}
|
||||
|
||||
void* CompletedEventHandler(PLEvent *self)
|
||||
{
|
||||
nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
|
||||
owner->SetCompleted();
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
#ifdef AUTOPROXIFICATION
|
||||
// ssc@netscape.com wishes he could get rid of this instance of |NS_DEFINE_IID|, but |ProxyEventClassIdentity| is not visible from here
|
||||
static NS_DEFINE_IID(kProxyObject_Identity_Class_IID, NS_PROXYEVENT_IDENTITY_CLASS_IID);
|
||||
|
||||
nsresult
|
||||
AutoProxyParameterList(PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMiniVariant * params,
|
||||
nsProxyObject::AutoProxyParameterList(PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMiniVariant * params,
|
||||
nsIInterfaceInfo *interfaceInfo, AutoProxyConvertTypes convertType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -660,3 +522,45 @@ AutoProxyParameterList(PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTC
|
|||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void DestroyHandler(PLEvent *self)
|
||||
{
|
||||
nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
|
||||
nsProxyObject* proxyObject = owner->GetProxyObject();
|
||||
|
||||
if (proxyObject->GetProxyType() & PROXY_ASYNC)
|
||||
{
|
||||
delete owner;
|
||||
}
|
||||
else
|
||||
{
|
||||
owner->SetCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
void* EventHandler(PLEvent *self)
|
||||
{
|
||||
nsProxyObjectCallInfo *info = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
|
||||
|
||||
if (info != nsnull)
|
||||
{
|
||||
nsProxyObject *proxyObject = info->GetProxyObject();
|
||||
|
||||
if (proxyObject)
|
||||
{
|
||||
// invoke the magic of xptc...
|
||||
nsresult rv = XPTC_InvokeByIndex( proxyObject->GetRealObject(),
|
||||
info->GetMethodIndex(),
|
||||
info->GetParameterCount(),
|
||||
info->GetParameterList());
|
||||
info->SetResult(rv);
|
||||
}
|
||||
else
|
||||
{
|
||||
info->SetResult(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@ static uint32 zero_methods_descriptor;
|
|||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// nsProxyEventClass
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kProxyEventClassIID, NS_PROXYEVENT_CLASS_IID);
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsProxyEventClass, kProxyEventClassIID)
|
||||
|
||||
// static
|
||||
|
@ -57,7 +60,7 @@ nsProxyEventClass::GetNewOrUsedClass(REFNSIID aIID)
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
nsProxyEventClass* clazz = nsnull;
|
||||
nsProxyEventClass* clazz = NULL;
|
||||
nsIDKey key(aIID);
|
||||
|
||||
if(iidToClassMap->Exists(&key))
|
||||
|
@ -67,20 +70,22 @@ nsProxyEventClass::GetNewOrUsedClass(REFNSIID aIID)
|
|||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iimgr = getter_AddRefs(XPTI_GetInterfaceInfoManager());
|
||||
if(iimgr)
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if(NULL != (iimgr = XPTI_GetInterfaceInfoManager()))
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, getter_AddRefs(info))))
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
/*
|
||||
Check to see if isISupportsDescendent
|
||||
*/
|
||||
nsCOMPtr<nsIInterfaceInfo> oldest = info;
|
||||
nsCOMPtr<nsIInterfaceInfo> parent;
|
||||
nsIInterfaceInfo* oldest = info;
|
||||
nsIInterfaceInfo* parent;
|
||||
|
||||
while(NS_SUCCEEDED(oldest->GetParent(getter_AddRefs(parent))))
|
||||
NS_ADDREF(oldest);
|
||||
while(NS_SUCCEEDED(oldest->GetParent(&parent)))
|
||||
{
|
||||
NS_RELEASE(oldest);
|
||||
oldest = parent;
|
||||
}
|
||||
|
||||
|
@ -91,7 +96,8 @@ nsProxyEventClass::GetNewOrUsedClass(REFNSIID aIID)
|
|||
isISupportsDescendent = iid->Equals(nsCOMTypeInfo<nsISupports>::GetIID());
|
||||
nsAllocator::Free(iid);
|
||||
}
|
||||
|
||||
NS_RELEASE(oldest);
|
||||
|
||||
NS_VERIFY(isISupportsDescendent,"!isISupportsDescendent");
|
||||
|
||||
if (isISupportsDescendent)
|
||||
|
@ -100,24 +106,24 @@ nsProxyEventClass::GetNewOrUsedClass(REFNSIID aIID)
|
|||
if(!clazz->mDescriptors)
|
||||
NS_RELEASE(clazz); // sets clazz to NULL
|
||||
}
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
nsProxyEventClass::nsProxyEventClass()
|
||||
{
|
||||
}
|
||||
|
||||
nsProxyEventClass::nsProxyEventClass(REFNSIID aIID, nsIInterfaceInfo* aInfo)
|
||||
: mIID(aIID),
|
||||
: mInfo(aInfo),
|
||||
mIID(aIID),
|
||||
mDescriptors(NULL)
|
||||
{
|
||||
NS_ADDREF(mInfo);
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
mInfo = aInfo;
|
||||
|
||||
/* add use to the used classes */
|
||||
nsIDKey key(aIID);
|
||||
|
@ -162,6 +168,8 @@ nsProxyEventClass::~nsProxyEventClass()
|
|||
{
|
||||
iidToClassMap->Remove(&key);
|
||||
}
|
||||
|
||||
NS_RELEASE(mInfo);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -206,9 +214,10 @@ nsProxyEventClass::CallQueryInterfaceOnProxy(nsProxyEventObject* self, REFNSIID
|
|||
// This 'ProxyEventClassIdentity' class and singleton allow us to figure out if
|
||||
// any given nsISupports* is implemented by a nsProxy object. This is done
|
||||
// using a QueryInterface call on the interface pointer with our ID. If
|
||||
// that call returns NS_OK and the pointer is to a nsProxyEventObject. It must
|
||||
// be released when done.
|
||||
|
||||
// that call returns NS_OK and the pointer is to our singleton, then the
|
||||
// interface must be implemented by a nsProxy object. NOTE: the
|
||||
// 'ProxyEventClassIdentity' object is not a real XPCOM object and should not be
|
||||
// used for anything else
|
||||
// NS_PROXYEVENT_IDENTITY_CLASS_IID defined in nsProxyEventPrivate.h
|
||||
class ProxyEventClassIdentity
|
||||
{
|
||||
|
@ -230,47 +239,24 @@ nsProxyEventClass::DelegatedQueryInterface(nsProxyEventObject* self,
|
|||
REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
|
||||
if(aIID.Equals(ProxyEventClassIdentity::GetIID()))
|
||||
if(NULL == aInstancePtr)
|
||||
{
|
||||
*aInstancePtr = (void**)self; //todo this should be a static cast
|
||||
NS_PRECONDITION(0, "null pointer");
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if(aIID.Equals(self->GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*) self;
|
||||
NS_ADDREF(self);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsProxyEventObject* sibling;
|
||||
|
||||
// This includes checking for nsISupports and the iid of self.
|
||||
// And it also checks for other wrappers that have been constructed
|
||||
// for this object.
|
||||
if(nsnull != (sibling = self->Find(aIID)))
|
||||
|
||||
if(aIID.Equals(ProxyEventClassIdentity::GetIID()))
|
||||
{
|
||||
NS_ADDREF(sibling);
|
||||
*aInstancePtr = (void*) sibling;
|
||||
*aInstancePtr = ProxyEventClassIdentity::GetSingleton();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// check if asking for an interface that we inherit from
|
||||
nsCOMPtr<nsIInterfaceInfo> current = GetInterfaceInfo();
|
||||
nsCOMPtr<nsIInterfaceInfo> parent;
|
||||
|
||||
while(NS_SUCCEEDED(current->GetParent(getter_AddRefs(parent))) && parent)
|
||||
{
|
||||
current = parent;
|
||||
|
||||
nsIID* iid;
|
||||
if(NS_SUCCEEDED(current->GetIID(&iid)) && iid)
|
||||
{
|
||||
PRBool found = aIID.Equals(*iid);
|
||||
nsAllocator::Free(iid);
|
||||
if(found)
|
||||
{
|
||||
*aInstancePtr = (void*) self;
|
||||
NS_ADDREF(self);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CallQueryInterfaceOnProxy(self, aIID, (nsProxyEventObject**)aInstancePtr);
|
||||
}
|
||||
|
|
|
@ -25,76 +25,6 @@
|
|||
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "xptcall.h"
|
||||
static NS_DEFINE_IID(kProxyObject_Identity_Class_IID, NS_PROXYEVENT_IDENTITY_CLASS_IID);
|
||||
|
||||
|
||||
#ifdef DEBUG_dougt
|
||||
static PRMonitor* mon = nsnull;
|
||||
static PRUint32 totalProxyObjects = 0;
|
||||
static PRUint32 outstandingProxyObjects = 0;
|
||||
|
||||
void
|
||||
nsProxyEventObject::DebugDump(const char * message, PRUint32 hashKey)
|
||||
{
|
||||
|
||||
if (mon == nsnull)
|
||||
{
|
||||
mon = PR_NewMonitor();
|
||||
}
|
||||
|
||||
PR_EnterMonitor(mon);
|
||||
|
||||
if (message)
|
||||
{
|
||||
printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-\n");
|
||||
printf("%s\n", message);
|
||||
|
||||
if(strcmp(message, "Create") == 0)
|
||||
{
|
||||
totalProxyObjects++;
|
||||
outstandingProxyObjects++;
|
||||
}
|
||||
else if(strcmp(message, "Delete") == 0)
|
||||
{
|
||||
outstandingProxyObjects--;
|
||||
}
|
||||
}
|
||||
printf("nsProxyEventObject @ %x with mRefCnt = %d\n", this, mRefCnt);
|
||||
|
||||
PRBool isRoot = mRoot == nsnull;
|
||||
printf("%s wrapper around @ %x\n", isRoot ? "ROOT":"non-root\n", GetRealObject());
|
||||
|
||||
if (mHashKey.HashValue()!=0)
|
||||
printf("Hashkey: %d\n", mHashKey.HashValue());
|
||||
|
||||
char* name;
|
||||
GetClass()->GetInterfaceInfo()->GetName(&name);
|
||||
printf("interface name is %s\n", name);
|
||||
if(name)
|
||||
nsAllocator::Free(name);
|
||||
char * iid = GetClass()->GetProxiedIID().ToString();
|
||||
printf("IID number is %s\n", iid);
|
||||
delete iid;
|
||||
printf("nsProxyEventClass @ %x\n", mClass);
|
||||
|
||||
if(mNext)
|
||||
{
|
||||
if(isRoot)
|
||||
{
|
||||
printf("Additional wrappers for this object...\n");
|
||||
}
|
||||
mNext->DebugDump(nsnull, 0);
|
||||
}
|
||||
|
||||
printf("[proxyobjects] %d total used in system, %d outstading\n", totalProxyObjects, outstandingProxyObjects);
|
||||
|
||||
if (message)
|
||||
printf("-=-=-=-=-=-=-=-=-=-=-=-=-\n");
|
||||
|
||||
PR_ExitMonitor(mon);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -102,101 +32,89 @@ nsProxyEventObject::DebugDump(const char * message, PRUint32 hashKey)
|
|||
// nsProxyEventObject
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
nsProxyEventObject*
|
||||
nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue,
|
||||
PRInt32 proxyType,
|
||||
nsISupports *aObj,
|
||||
REFNSIID aIID)
|
||||
{
|
||||
nsProxyEventObject* proxy = NULL;
|
||||
nsProxyEventObject* root = NULL;
|
||||
|
||||
nsCOMPtr<nsProxyEventObject> proxy = 0;
|
||||
nsCOMPtr<nsProxyEventObject> root = 0;
|
||||
nsProxyEventObject* peo;
|
||||
|
||||
// Get a class for this IID.
|
||||
nsCOMPtr<nsProxyEventClass> clazz = getter_AddRefs( nsProxyEventClass::GetNewOrUsedClass(aIID) );
|
||||
if(!clazz) return nsnull;
|
||||
nsProxyEventClass* clazz = nsProxyEventClass::GetNewOrUsedClass(aIID);
|
||||
if(!clazz)
|
||||
return NULL;
|
||||
|
||||
nsISupports* rootObject;
|
||||
// always find the native root
|
||||
if(NS_FAILED(aObj->QueryInterface(nsCOMTypeInfo<nsISupports>::GetIID(), (void**)&rootObject)))
|
||||
return NULL;
|
||||
|
||||
|
||||
/* find in our hash table */
|
||||
|
||||
// make sure that the object pass in is not a proxy.
|
||||
nsCOMPtr<nsProxyEventObject> aIdentificationObject;
|
||||
if (NS_SUCCEEDED(aObj->QueryInterface(kProxyObject_Identity_Class_IID, getter_AddRefs(aIdentificationObject))))
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
nsHashtable *realToProxyMap = manager->GetRealObjectToProxyObjectMap();
|
||||
|
||||
if (realToProxyMap == nsnull)
|
||||
{
|
||||
// someone is asking us to create a proxy for a proxy. Lets get
|
||||
// the real object and build aproxy for that!
|
||||
aObj = aIdentificationObject->GetRealObject();
|
||||
aIdentificationObject = 0;
|
||||
if (aObj == nsnull) return nsnull;
|
||||
if(clazz)
|
||||
NS_RELEASE(clazz);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
// always find the native root if the |real| object.
|
||||
nsCOMPtr<nsISupports> rootObject;
|
||||
if(NS_FAILED(aObj->QueryInterface(nsCOMTypeInfo<nsISupports>::GetIID(), getter_AddRefs(rootObject))))
|
||||
return nsnull;
|
||||
|
||||
// this will be our key in the hash table.
|
||||
nsVoidKey rootkey( (void*) GetProxyHashKey(rootObject.get(), destQueue, proxyType) );
|
||||
|
||||
/* get our hash table */
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
if (manager == nsnull) return nsnull;
|
||||
|
||||
nsHashtable *realToProxyMap = manager->GetRealObjectToProxyObjectMap();
|
||||
if (realToProxyMap == nsnull) return nsnull;
|
||||
|
||||
// we need to do make sure that we addref the passed in object as well as ensure
|
||||
// that it is of the requested IID;
|
||||
nsCOMPtr<nsISupports> requestedInterface;
|
||||
if(NS_FAILED(aObj->QueryInterface(aIID, getter_AddRefs(requestedInterface))))
|
||||
return nsnull;
|
||||
|
||||
/* find in our hash table */
|
||||
nsVoidKey rootkey(rootObject);
|
||||
if(realToProxyMap->Exists(&rootkey))
|
||||
{
|
||||
root = (nsProxyEventObject*) realToProxyMap->Get(&rootkey);
|
||||
root = (nsProxyEventObject*) realToProxyMap->Get(&rootkey);
|
||||
proxy = root->Find(aIID);
|
||||
|
||||
|
||||
if(proxy)
|
||||
goto return_proxy;
|
||||
{
|
||||
NS_ADDREF(proxy);
|
||||
goto return_wrapper;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// build the root proxy
|
||||
if (aObj == rootObject.get())
|
||||
if (aObj == rootObject)
|
||||
{
|
||||
// the root will do double duty as the interface wrapper
|
||||
peo = new nsProxyEventObject(destQueue,
|
||||
proxyType,
|
||||
requestedInterface,
|
||||
clazz,
|
||||
nsnull,
|
||||
rootkey.HashValue());
|
||||
|
||||
proxy = do_QueryInterface(peo);
|
||||
|
||||
if(proxy)
|
||||
realToProxyMap->Put(&rootkey, peo);
|
||||
|
||||
goto return_proxy;
|
||||
proxy = root = new nsProxyEventObject(destQueue, proxyType, aObj, clazz, nsnull);
|
||||
if(root)
|
||||
{
|
||||
nsVoidKey aKey(root);
|
||||
realToProxyMap->Put(&aKey, root);
|
||||
|
||||
NS_ADDREF(proxy); // since we are double duty, we need to make sure that our refCnt
|
||||
// reflects this.
|
||||
}
|
||||
goto return_wrapper;
|
||||
}
|
||||
else
|
||||
{
|
||||
// just a root proxy
|
||||
nsCOMPtr<nsProxyEventClass> rootClazz = getter_AddRefs ( nsProxyEventClass::GetNewOrUsedClass(
|
||||
nsCOMTypeInfo<nsISupports>::GetIID()) );
|
||||
nsProxyEventClass* rootClazz = nsProxyEventClass::GetNewOrUsedClass(nsCOMTypeInfo<nsISupports>::GetIID());
|
||||
if(!rootClazz)
|
||||
{
|
||||
goto return_wrapper;
|
||||
}
|
||||
|
||||
root = new nsProxyEventObject(destQueue, proxyType, rootObject, rootClazz, nsnull);
|
||||
NS_RELEASE(rootClazz);
|
||||
|
||||
if(!root)
|
||||
{
|
||||
goto return_wrapper;
|
||||
}
|
||||
|
||||
peo = new nsProxyEventObject(destQueue,
|
||||
proxyType,
|
||||
rootObject,
|
||||
rootClazz,
|
||||
nsnull,
|
||||
rootkey.HashValue());
|
||||
|
||||
if(!peo || !rootClazz)
|
||||
return nsnull;
|
||||
|
||||
root = do_QueryInterface(peo);
|
||||
|
||||
realToProxyMap->Put(&rootkey, peo);
|
||||
nsVoidKey aKey(root);
|
||||
realToProxyMap->Put(&aKey, root);
|
||||
}
|
||||
}
|
||||
// at this point we have a root and may need to build the specific proxy
|
||||
|
@ -205,94 +123,90 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue,
|
|||
|
||||
if(!proxy)
|
||||
{
|
||||
peo = new nsProxyEventObject(destQueue,
|
||||
proxyType,
|
||||
requestedInterface,
|
||||
clazz,
|
||||
root,
|
||||
0);
|
||||
|
||||
proxy = do_QueryInterface(peo);
|
||||
|
||||
proxy = new nsProxyEventObject(destQueue, proxyType, aObj, clazz, root);
|
||||
if(!proxy)
|
||||
return nsnull;
|
||||
{
|
||||
goto return_wrapper;
|
||||
}
|
||||
}
|
||||
|
||||
proxy->mNext = root->mNext;
|
||||
root->mNext = proxy;
|
||||
|
||||
return_proxy:
|
||||
return_wrapper:
|
||||
|
||||
if(clazz)
|
||||
NS_RELEASE(clazz);
|
||||
|
||||
|
||||
// Since we do not want to extra references, we will release the rootObject.
|
||||
//
|
||||
// There are one or more references to aObj which is passed in. When we create
|
||||
// a new proxy object via nsProxyEventObject(), that will addRef the aObj. Because
|
||||
// we QI addref to insure that we have a nsISupports ptr, its refcount goes up by one.
|
||||
// here we will decrement that.
|
||||
//
|
||||
if (rootObject)
|
||||
NS_RELEASE(rootObject);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(proxy)
|
||||
{
|
||||
peo = proxy;
|
||||
NS_ADDREF(peo);
|
||||
return peo;
|
||||
}
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
nsProxyEventObject::nsProxyEventObject()
|
||||
: mNext(nsnull),
|
||||
mHashKey((void*)0)
|
||||
{
|
||||
}
|
||||
|
||||
nsProxyEventObject::nsProxyEventObject(nsIEventQueue *destQueue,
|
||||
PRInt32 proxyType,
|
||||
nsISupports* aObj,
|
||||
nsProxyEventClass* aClass,
|
||||
nsProxyEventObject* root,
|
||||
PRUint32 hashValue)
|
||||
: mNext(nsnull),
|
||||
mHashKey((void*)hashValue)
|
||||
nsProxyEventObject* root)
|
||||
: mClass(aClass),
|
||||
mNext(NULL)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mRoot = root;
|
||||
mClass = aClass;
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
mProxyObject = new nsProxyObject(destQueue, proxyType, aObj);
|
||||
|
||||
#ifdef DEBUG_dougt
|
||||
DebugDump("Create", 0);
|
||||
#endif
|
||||
mProxyObject = new nsProxyObject(destQueue, proxyType, aObj);
|
||||
|
||||
mRoot = (root ? root : this);
|
||||
|
||||
// if we have a root, lets addref it.
|
||||
if (root)
|
||||
NS_ADDREF(mRoot);
|
||||
|
||||
NS_ADDREF(aClass);
|
||||
}
|
||||
|
||||
nsProxyEventObject::~nsProxyEventObject()
|
||||
{
|
||||
#ifdef DEBUG_dougt
|
||||
DebugDump("Delete", 0);
|
||||
#endif
|
||||
if (mRoot != nsnull)
|
||||
NS_IF_RELEASE(mProxyObject);
|
||||
NS_IF_RELEASE(mClass);
|
||||
|
||||
if (mRoot)
|
||||
{
|
||||
nsProxyEventObject* cur = mRoot;
|
||||
while(1)
|
||||
if (mRoot != this)
|
||||
{
|
||||
if(cur->mNext == this)
|
||||
{
|
||||
cur->mNext = mNext;
|
||||
break;
|
||||
}
|
||||
cur = cur->mNext;
|
||||
NS_ASSERTION(cur, "failed to find wrapper in its own chain");
|
||||
mRoot->RootRemoval();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
nsHashtable *realToProxyMap = manager->GetRealObjectToProxyObjectMap();
|
||||
|
||||
if (realToProxyMap != nsnull && mHashKey.HashValue() != 0)
|
||||
else
|
||||
{
|
||||
realToProxyMap->Remove(&mHashKey);
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
nsHashtable *realToProxyMap = manager->GetRealObjectToProxyObjectMap();
|
||||
|
||||
if (realToProxyMap != nsnull)
|
||||
{
|
||||
nsVoidKey key(this);
|
||||
realToProxyMap->Remove(&key);
|
||||
}
|
||||
}
|
||||
}
|
||||
// I am worried about ordering.
|
||||
// do not remove assignments.
|
||||
mProxyObject = 0;
|
||||
mClass = 0;
|
||||
mRoot = 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsProxyEventObject::RootRemoval()
|
||||
{
|
||||
if (--mRefCnt <= 1)
|
||||
NS_DELETEXPCOM(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsProxyEventObject);
|
||||
|
@ -301,44 +215,22 @@ NS_IMPL_RELEASE(nsProxyEventObject);
|
|||
NS_IMETHODIMP
|
||||
nsProxyEventObject::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if( aIID.Equals(GetIID()) )
|
||||
{
|
||||
*aInstancePtr = (void*) ( (nsISupports*)this ); //todo should use standard cast.
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return mClass->DelegatedQueryInterface(this, aIID, aInstancePtr);
|
||||
}
|
||||
// TODO: we need to wrap the object if it is not a proxy.
|
||||
|
||||
PRUint32
|
||||
nsProxyEventObject::GetProxyHashKey(nsISupports *rootProxy, nsIEventQueue *destQueue, PRInt32 proxyType)
|
||||
{ // FIX I need to worry about nsCOMPtr for rootProxy, and destQueue!
|
||||
|
||||
nsISupports* destQRoot;
|
||||
if(NS_FAILED(destQueue->QueryInterface(nsCOMTypeInfo<nsISupports>::GetIID(), (void**)&destQRoot)))
|
||||
return 0;
|
||||
PRInt32 value = (PRUint32)rootProxy + (PRUint32)destQRoot + proxyType;
|
||||
NS_RELEASE(destQRoot);
|
||||
return value;
|
||||
return mClass->DelegatedQueryInterface(this, aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
nsProxyEventObject*
|
||||
nsProxyEventObject::Find(REFNSIID aIID)
|
||||
{
|
||||
nsProxyEventObject* cur = (mRoot ? mRoot.get() : this);
|
||||
|
||||
if(aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
{
|
||||
return cur;
|
||||
}
|
||||
return mRoot;
|
||||
|
||||
nsProxyEventObject* cur = mRoot;
|
||||
do
|
||||
{
|
||||
if(aIID.Equals(GetClass()->GetProxiedIID()))
|
||||
{
|
||||
if(aIID.Equals(GetIID()))
|
||||
return cur;
|
||||
}
|
||||
|
||||
} while(NULL != (cur = cur->mNext));
|
||||
|
||||
|
@ -349,13 +241,11 @@ nsProxyEventObject::Find(REFNSIID aIID)
|
|||
NS_IMETHODIMP
|
||||
nsProxyEventObject::GetInterfaceInfo(nsIInterfaceInfo** info)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(info);
|
||||
NS_ASSERTION(GetClass(), "proxy without class");
|
||||
NS_ASSERTION(GetClass()->GetInterfaceInfo(), "proxy class without interface");
|
||||
|
||||
if(!(*info = GetClass()->GetInterfaceInfo()))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
NS_ADDREF(*info);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -365,10 +255,7 @@ nsProxyEventObject::CallMethod(PRUint16 methodIndex,
|
|||
const nsXPTMethodInfo* info,
|
||||
nsXPTCMiniVariant * params)
|
||||
{
|
||||
if (mProxyObject)
|
||||
return mProxyObject->Post(methodIndex, (nsXPTMethodInfo*)info, params, GetClass()->GetInterfaceInfo());
|
||||
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return mProxyObject->Post(methodIndex, (nsXPTMethodInfo*)info, params, GetClass()->GetInterfaceInfo());
|
||||
}
|
||||
|
||||
|
||||
|
@ -387,3 +274,6 @@ nsProxyEventObject::CallMethod(PRUint16 methodIndex,
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
#include "plevent.h"
|
||||
#include "xptcall.h" // defines nsXPTCVariant
|
||||
|
@ -45,44 +44,28 @@ class nsProxyEventClass;
|
|||
{ 0xeea90d45, 0xb059, 0x11d2, \
|
||||
{ 0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33 } }
|
||||
|
||||
|
||||
#define NS_PROXYEVENT_OBJECT_IID \
|
||||
{ 0xec373590, 0x9164, 0x11d3, \
|
||||
{0x8c, 0x73, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} }
|
||||
|
||||
static NS_DEFINE_IID(kProxyEventClassIID, NS_PROXYEVENT_CLASS_IID);
|
||||
static NS_DEFINE_IID(kProxyEventObjectIID, NS_PROXYEVENT_OBJECT_IID);
|
||||
|
||||
|
||||
class nsProxyEventClass : public nsISupports
|
||||
{
|
||||
public:
|
||||
// all the interface method declarations...
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
static const nsIID& GetIID() {static nsIID iid = kProxyEventClassIID; return iid;}
|
||||
NS_IMETHOD DelegatedQueryInterface(nsProxyEventObject* self, REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
static nsProxyEventClass* GetNewOrUsedClass(REFNSIID aIID);
|
||||
|
||||
NS_IMETHOD DelegatedQueryInterface( nsProxyEventObject* self,
|
||||
REFNSIID aIID,
|
||||
void** aInstancePtr);
|
||||
|
||||
|
||||
REFNSIID GetIID() const {return mIID;}
|
||||
nsIInterfaceInfo* GetInterfaceInfo() const {return mInfo;}
|
||||
const nsIID& GetProxiedIID() const {return mIID; }
|
||||
nsresult CallQueryInterfaceOnProxy(nsProxyEventObject* self, REFNSIID aIID, nsProxyEventObject** aInstancePtr);
|
||||
|
||||
protected:
|
||||
nsProxyEventClass();
|
||||
|
||||
nsProxyEventClass(REFNSIID aIID, nsIInterfaceInfo* aInfo);
|
||||
virtual ~nsProxyEventClass();
|
||||
|
||||
private:
|
||||
nsIID mIID;
|
||||
nsCOMPtr<nsIInterfaceInfo> mInfo;
|
||||
uint32* mDescriptors;
|
||||
|
||||
nsresult CallQueryInterfaceOnProxy(nsProxyEventObject* self,
|
||||
REFNSIID aIID,
|
||||
nsProxyEventObject** aInstancePtr);
|
||||
nsIInterfaceInfo* mInfo;
|
||||
nsIID mIID;
|
||||
uint32* mDescriptors;
|
||||
};
|
||||
|
||||
|
||||
|
@ -92,53 +75,42 @@ class nsProxyEventObject : public nsXPTCStubBase
|
|||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
static const nsIID& GetIID() {static nsIID iid = kProxyEventObjectIID; return iid;}
|
||||
|
||||
static nsProxyEventObject* GetNewOrUsedProxy(nsIEventQueue *destQueue,
|
||||
PRInt32 proxyType,
|
||||
nsISupports *aObj,
|
||||
REFNSIID aIID);
|
||||
|
||||
static PRUint32 GetProxyHashKey( nsISupports *rootProxy,
|
||||
nsIEventQueue *destQueue,
|
||||
PRInt32 proxyType);
|
||||
|
||||
|
||||
|
||||
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
|
||||
|
||||
// call this method and return result
|
||||
NS_IMETHOD CallMethod(PRUint16 methodIndex, const nsXPTMethodInfo* info, nsXPTCMiniVariant* params);
|
||||
|
||||
|
||||
static nsProxyEventObject* GetNewOrUsedProxy(nsIEventQueue *destQueue,
|
||||
PRInt32 proxyType,
|
||||
nsISupports *aObj,
|
||||
REFNSIID aIID);
|
||||
|
||||
|
||||
REFNSIID GetIID() const { return GetClass()->GetIID();}
|
||||
nsProxyEventClass* GetClass() const { return mClass; }
|
||||
nsIEventQueue* GetQueue() const { return (mProxyObject ? mProxyObject->GetQueue() : nsnull);}
|
||||
nsISupports* GetRealObject() const { return (mProxyObject ? mProxyObject->GetRealObject(): nsnull);}
|
||||
PRInt32 GetProxyType() const { return (mProxyObject ? mProxyObject->GetProxyType() : nsnull);}
|
||||
nsIEventQueue* GetQueue() const { return mProxyObject->GetQueue(); }
|
||||
nsISupports* GetRealObject() const { return mProxyObject->GetRealObject(); }
|
||||
|
||||
|
||||
nsProxyEventObject();
|
||||
protected:
|
||||
virtual ~nsProxyEventObject();
|
||||
|
||||
nsProxyEventObject(nsIEventQueue *destQueue,
|
||||
PRInt32 proxyType,
|
||||
nsISupports* aObj,
|
||||
nsProxyEventClass* aClass,
|
||||
nsProxyEventObject* root,
|
||||
PRUint32 hashValue);
|
||||
|
||||
virtual ~nsProxyEventObject();
|
||||
nsProxyEventObject* root);
|
||||
|
||||
nsProxyEventObject* Find(REFNSIID aIID);
|
||||
|
||||
#ifdef DEBUG_dougt
|
||||
void DebugDump(const char * message, PRUint32 hashKey);
|
||||
#endif
|
||||
private:
|
||||
nsresult RootRemoval();
|
||||
|
||||
protected:
|
||||
nsVoidKey mHashKey;
|
||||
|
||||
nsCOMPtr<nsProxyObject> mProxyObject;
|
||||
nsCOMPtr<nsProxyEventClass> mClass;
|
||||
nsCOMPtr<nsProxyEventObject> mRoot;
|
||||
|
||||
nsProxyObject* mProxyObject;
|
||||
nsProxyEventClass* mClass;
|
||||
nsProxyEventObject* mRoot;
|
||||
nsProxyEventObject* mNext;
|
||||
};
|
||||
|
||||
|
|
|
@ -77,6 +77,16 @@ NS_IMETHODIMP nsProxyCreateInstance::CreateInstanceByProgID(const char *aProgID,
|
|||
result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// nsProxyObjectManager
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
@ -171,12 +181,25 @@ nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, ns
|
|||
}
|
||||
}
|
||||
|
||||
nsISupports* realObject;
|
||||
|
||||
// we need to do make sure that we addref the passed in object as well as ensure
|
||||
// that it is of the requested IID;
|
||||
|
||||
rv = aObj->QueryInterface(aIID, (void**)&realObject);
|
||||
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
|
||||
// check to see if proxy is there or not.
|
||||
*aProxyObject = nsProxyEventObject::GetNewOrUsedProxy(postQ, proxyType, aObj, aIID);
|
||||
*aProxyObject = nsProxyEventObject::GetNewOrUsedProxy(postQ, proxyType, realObject, aIID);
|
||||
|
||||
if (*aProxyObject == nsnull)
|
||||
return NS_ERROR_NO_INTERFACE; //fix error code?
|
||||
|
||||
{
|
||||
NS_RELEASE(aObj);
|
||||
return NS_ERROR_NO_INTERFACE; //fix error code?
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче