Adding Autoproxification.
git-svn-id: svn://10.0.0.236/trunk@34629 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -18,20 +18,27 @@
|
||||
|
||||
|
||||
#include "nsProxyEvent.h"
|
||||
#include "nsProxyEventPrivate.h"
|
||||
#include "nsProxyObjectManager.h"
|
||||
|
||||
#include "prmem.h" // for PR_NEW
|
||||
#include "xptcall.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
static NS_DEFINE_IID(kProxyObjectManagerIID, NS_IPROXYEVENT_MANAGER_IID);
|
||||
static NS_DEFINE_IID(kProxyObject_Identity_Class_IID, NS_PROXYEVENT_IDENTITY_CLASS_IID);
|
||||
|
||||
static void* EventHandler(PLEvent *self);
|
||||
static void DestroyHandler(PLEvent *self);
|
||||
|
||||
nsProxyObjectCallInfo::nsProxyObjectCallInfo(nsProxyObject* owner,
|
||||
PRUint32 methodIndex,
|
||||
nsXPTCVariant* parameterList,
|
||||
PRUint32 parameterCount,
|
||||
PLEvent *event)
|
||||
PRUint32 methodIndex,
|
||||
nsXPTCVariant* parameterList,
|
||||
PRUint32 parameterCount,
|
||||
PLEvent *event)
|
||||
{
|
||||
mOwner = owner;
|
||||
mMethodIndex = methodIndex;
|
||||
@@ -76,6 +83,7 @@ nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, nsIS
|
||||
|
||||
NS_ADDREF(mRealObject);
|
||||
NS_ADDREF(mDestQueue);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +114,7 @@ nsProxyObject::~nsProxyObject()
|
||||
{
|
||||
if (mDestQueue)
|
||||
mDestQueue->EnterMonitor();
|
||||
// Shit! mDestQueue->RevokeEvents(this);
|
||||
// FIX! mDestQueue->RevokeEvents(this);
|
||||
|
||||
if(mRealObject != nsnull)
|
||||
{
|
||||
@@ -124,17 +132,35 @@ nsProxyObject::~nsProxyObject()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsProxyObject::Post( PRUint32 methodIndex, /* which method to be called? */
|
||||
PRUint32 paramCount, /* number of params */
|
||||
nsXPTCVariant *params)
|
||||
nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMiniVariant * params, nsIInterfaceInfo *interfaceInfo)
|
||||
{
|
||||
|
||||
if (mDestQueue == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (mRealObject == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Auto-proxification
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
AutoProxyParameterList(methodInfo, params, interfaceInfo, convertInParameters);
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// convert the nsXPTCMiniVariant to a nsXPTCVariant
|
||||
|
||||
uint8 paramCount = methodInfo->GetParamCount();
|
||||
|
||||
nsXPTCVariant *fullParam = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
|
||||
|
||||
for (int index = 0; index < paramCount; index++)
|
||||
{
|
||||
fullParam[index].flags = 0;
|
||||
fullParam[index].val = params[index].val;
|
||||
}
|
||||
|
||||
|
||||
mDestQueue->EnterMonitor();
|
||||
|
||||
NS_ASSERTION(mRealObject, "no native object");
|
||||
@@ -149,11 +175,11 @@ nsProxyObject::Post( PRUint32 methodIndex, /* which method to
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsProxyObjectCallInfo *info = new nsProxyObjectCallInfo(this, methodIndex, params, paramCount, event);
|
||||
nsProxyObjectCallInfo *proxyInfo = new nsProxyObjectCallInfo(this, methodIndex, fullParam, paramCount, event);
|
||||
|
||||
|
||||
PL_InitEvent(event,
|
||||
info,
|
||||
proxyInfo,
|
||||
EventHandler,
|
||||
DestroyHandler);
|
||||
|
||||
@@ -161,9 +187,15 @@ nsProxyObject::Post( PRUint32 methodIndex, /* which method to
|
||||
{
|
||||
mDestQueue->PostSynchronousEvent(event, nsnull);
|
||||
|
||||
nsresult rv = info->GetResult();
|
||||
delete info;
|
||||
nsresult rv = proxyInfo->GetResult();
|
||||
delete proxyInfo;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Auto-proxification
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
AutoProxyParameterList(methodInfo, params, interfaceInfo, convertOutParameters);
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
mDestQueue->ExitMonitor();
|
||||
return rv;
|
||||
}
|
||||
@@ -180,6 +212,80 @@ nsProxyObject::Post( PRUint32 methodIndex, /* which method to
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsProxyObject::AutoProxyParameterList(nsXPTMethodInfo *methodInfo, nsXPTCMiniVariant * params,
|
||||
nsIInterfaceInfo *interfaceInfo, AutoProxyConvertTypes convertType)
|
||||
{
|
||||
uint8 paramCount = methodInfo->GetParamCount();
|
||||
|
||||
for (PRUint32 i = 0; i < paramCount; i++)
|
||||
{
|
||||
nsXPTParamInfo paramInfo = methodInfo->GetParam(i);
|
||||
|
||||
if (paramInfo.GetType().TagPart() != nsXPTType::T_INTERFACE )
|
||||
continue;
|
||||
|
||||
if ( (convertType == convertOutParameters && paramInfo.IsOut()) ||
|
||||
(convertType == convertInParameters && paramInfo.IsIn()) ||
|
||||
(convertType == convertAllParameters))
|
||||
{
|
||||
// We found an out parameter which is a interface, check for proxy
|
||||
if (params[i].val.p == nsnull)
|
||||
continue;
|
||||
|
||||
nsISupports* anInterface = nsnull;
|
||||
|
||||
if (paramInfo.IsOut())
|
||||
anInterface = *((nsISupports**)params[i].val.p);
|
||||
else
|
||||
anInterface = ((nsISupports*)params[i].val.p);
|
||||
|
||||
|
||||
if (anInterface == nsnull)
|
||||
continue;
|
||||
|
||||
nsISupports *aProxyObject;
|
||||
nsresult rv = anInterface->QueryInterface(kProxyObject_Identity_Class_IID, (void**)&aProxyObject);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
// create a proxy
|
||||
nsIProxyObjectManager* manager;
|
||||
|
||||
rv = nsServiceManager::GetService( NS_XPCOMPROXY_PROGID,
|
||||
kProxyObjectManagerIID,
|
||||
(nsISupports **)&manager);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsIID* iid;
|
||||
|
||||
interfaceInfo->GetIIDForParam(¶mInfo, &iid);
|
||||
|
||||
manager->GetProxyObject( GetQueue(),
|
||||
*iid,
|
||||
anInterface,
|
||||
GetProxyType(),
|
||||
(void**) &aProxyObject);
|
||||
|
||||
nsAllocator::Free((void*)iid);
|
||||
|
||||
if (paramInfo.IsOut())
|
||||
*((void**)params[i].val.p) = ((void*)aProxyObject);
|
||||
else
|
||||
(params[i].val.p) = ((void*)aProxyObject);
|
||||
|
||||
NS_RELEASE(manager);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// It already is a proxy!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DestroyHandler(PLEvent *self)
|
||||
{
|
||||
nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
|
||||
@@ -210,14 +316,14 @@ void* EventHandler(PLEvent *self)
|
||||
|
||||
eventQ->EnterMonitor();
|
||||
|
||||
// invoke the magic of xptc...
|
||||
// invoke the magic of xptc...
|
||||
nsresult rv = XPTC_InvokeByIndex( proxyObject->GetRealObject(),
|
||||
info->GetMethodIndex(),
|
||||
info->GetParameterCount(),
|
||||
info->GetParameterList());
|
||||
|
||||
info->SetResult(rv);
|
||||
|
||||
|
||||
eventQ->ExitMonitor();
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -223,13 +223,8 @@ nsProxyEventClass::CallQueryInterfaceOnProxy(nsProxyEventObject* self, REFNSIID
|
||||
// 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 (hence it is declared in this implementation file).
|
||||
|
||||
/* eea90d45-b059-11d2-915e-c12b696c9333 */
|
||||
#define NS_PROXYEVENT_IDENTITY_CLASS_IID \
|
||||
{ 0xeea90d45, 0xb059, 0x11d2, \
|
||||
{ 0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33 } }
|
||||
|
||||
// used for anything else
|
||||
// NS_PROXYEVENT_IDENTITY_CLASS_IID defined in nsProxyEventPrivate.h
|
||||
class ProxyEventClassIdentity
|
||||
{
|
||||
// no instance methods...
|
||||
|
||||
@@ -270,19 +270,7 @@ nsProxyEventObject::CallMethod(PRUint16 methodIndex,
|
||||
const nsXPTMethodInfo* info,
|
||||
nsXPTCMiniVariant * params)
|
||||
{
|
||||
uint8 paramCount = info->GetParamCount();
|
||||
|
||||
nsXPTCVariant *fullParam = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
|
||||
|
||||
for (int index = 0; index < paramCount; index++)
|
||||
{
|
||||
fullParam[index].flags = 0;
|
||||
fullParam[index].val = params[index].val;
|
||||
}
|
||||
|
||||
// fullParam will be deleted inside the mProxyObject
|
||||
|
||||
return mProxyObject->Post(methodIndex, paramCount, fullParam);
|
||||
return mProxyObject->Post(methodIndex, (nsXPTMethodInfo*)info, params, GetClass()->GetInterfaceInfo());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,6 +40,11 @@ class nsProxyEventClass;
|
||||
{0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33}\
|
||||
}
|
||||
|
||||
#define NS_PROXYEVENT_IDENTITY_CLASS_IID \
|
||||
{ 0xeea90d45, 0xb059, 0x11d2, \
|
||||
{ 0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33 } }
|
||||
|
||||
|
||||
class nsProxyEventClass : public nsISupports
|
||||
{
|
||||
// all the interface method declarations...
|
||||
|
||||
Reference in New Issue
Block a user