*not part of tbox builds*
Added shortcuts implementation (we would not wrap wrappers any more) XPCOM object get called at the same thread the stub was created. git-svn-id: svn://10.0.0.236/trunk@83937 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -55,6 +55,10 @@ class ProxyHandler implements InvocationHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
long getOID() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
private long oid;
|
||||
private IID iid;
|
||||
private long orb;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "bcJavaGlobal.h"
|
||||
#include "bcORB.h"
|
||||
#include "bcIIDJava.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
jclass bcJavaStubsAndProxies::componentLoader = 0;
|
||||
jmethodID bcJavaStubsAndProxies::loadComponentID = 0;
|
||||
@@ -34,6 +35,11 @@ jclass bcJavaStubsAndProxies::proxyFactory = 0;
|
||||
jmethodID bcJavaStubsAndProxies::getProxyID = 0;
|
||||
jmethodID bcJavaStubsAndProxies::getInterfaceID = 0;
|
||||
|
||||
jclass bcJavaStubsAndProxies::java_lang_reflect_Proxy = 0;
|
||||
jmethodID bcJavaStubsAndProxies::getInvocationHandlerID = 0;
|
||||
jclass bcJavaStubsAndProxies::org_mozilla_xpcom_ProxyHandler = 0;
|
||||
jmethodID bcJavaStubsAndProxies::getOIDID = 0;
|
||||
|
||||
NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaStubsAndProxies);
|
||||
|
||||
@@ -52,11 +58,34 @@ NS_IMPL_NSGETMODULE("BlackConnect Java stubs and proxies",components);
|
||||
NS_IMPL_ISUPPORTS(bcJavaStubsAndProxies,NS_GET_IID(bcJavaStubsAndProxies));
|
||||
|
||||
|
||||
class bcOIDKey : public nsHashKey {
|
||||
protected:
|
||||
bcOID key;
|
||||
public:
|
||||
bcOIDKey(bcOID oid) {
|
||||
key = oid;
|
||||
}
|
||||
virtual ~bcOIDKey() {
|
||||
}
|
||||
PRUint32 HashCode(void) const {
|
||||
return (PRUint32)key;
|
||||
}
|
||||
|
||||
PRBool Equals(const nsHashKey *aKey) const {
|
||||
return (key == ((const bcOIDKey *) aKey)->key);
|
||||
}
|
||||
nsHashKey *Clone() const {
|
||||
return new bcOIDKey(key);
|
||||
}
|
||||
};
|
||||
|
||||
bcJavaStubsAndProxies::bcJavaStubsAndProxies() {
|
||||
NS_INIT_REFCNT();
|
||||
oid2objectMap = new nsHashtable(256,PR_TRUE);
|
||||
}
|
||||
|
||||
bcJavaStubsAndProxies::~bcJavaStubsAndProxies() {
|
||||
delete oid2objectMap;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcJavaStubsAndProxies::GetStub(jobject obj, bcIStub **stub) {
|
||||
@@ -73,10 +102,18 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIOR
|
||||
if (!componentLoader) {
|
||||
Init();
|
||||
}
|
||||
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
|
||||
*proxy = env->CallStaticObjectMethod(proxyFactory,getProxyID, (jlong)oid, jiid, (jlong)orb);
|
||||
bcOIDKey *key = new bcOIDKey(oid);
|
||||
void *tmp = oid2objectMap->Get(key);
|
||||
delete key;
|
||||
if (tmp != NULL) { //we have shortcut
|
||||
*proxy = (jobject)tmp;
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("\n--bcJavaStubsAndProxies::GetProxy we have shortcut for oid=%d\n",oid));
|
||||
} else {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
|
||||
*proxy = env->CallStaticObjectMethod(proxyFactory,getProxyID, (jlong)oid, jiid, (jlong)orb);
|
||||
EXCEPTION_CHECKING(env);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -94,9 +131,26 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetInterface(const nsIID &iid, jclass *cla
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID *oid) {
|
||||
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
|
||||
nsresult rv = NS_OK;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
if (env->IsInstanceOf(object,java_lang_reflect_Proxy)) {
|
||||
EXCEPTION_CHECKING(env);
|
||||
jobject handler = env->CallStaticObjectMethod(java_lang_reflect_Proxy,getInvocationHandlerID,object);
|
||||
EXCEPTION_CHECKING(env);
|
||||
if (handler != NULL
|
||||
&& env->IsInstanceOf(handler,org_mozilla_xpcom_ProxyHandler)) {
|
||||
EXCEPTION_CHECKING(env);
|
||||
*oid = env->CallLongMethod(handler,getOIDID);
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--bcJavaStubsAndProxies::GetOID we are using old oid %d\n",*oid));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
bcIStub *stub = new bcJavaStub(object);
|
||||
*oid = orb->RegisterStub(stub);
|
||||
return NS_OK;
|
||||
oid2objectMap->Put(new bcOIDKey(*oid),object);
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
|
||||
@@ -172,7 +226,48 @@ void bcJavaStubsAndProxies::Init(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
java_lang_reflect_Proxy = env->FindClass("java/lang/reflect/Proxy");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
getInvocationHandlerID =
|
||||
env->GetStaticMethodID(java_lang_reflect_Proxy, "getInvocationHandler",
|
||||
"(Ljava/lang/Object;)Ljava/lang/reflect/InvocationHandler;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
java_lang_reflect_Proxy = (jclass)env->NewGlobalRef(java_lang_reflect_Proxy);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
org_mozilla_xpcom_ProxyHandler = env->FindClass("org/mozilla/xpcom/ProxyHandler");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
org_mozilla_xpcom_ProxyHandler = (jclass)env->NewGlobalRef(org_mozilla_xpcom_ProxyHandler);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
getOIDID = env->GetMethodID(org_mozilla_xpcom_ProxyHandler, "getOID","()J");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
{0x7cadf6e8, 0x1dd2, 0x11b2, \
|
||||
{0x9a, 0x6e, 0xb1, 0xc3, 0x78,0x44, 0xe0, 0x04}}
|
||||
|
||||
class nsHashtable;
|
||||
class bcJavaStubsAndProxies : public nsISupports {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(BC_JAVASTUBSANDPROXIES_IID)
|
||||
@@ -57,6 +58,13 @@ class bcJavaStubsAndProxies : public nsISupports {
|
||||
static jclass proxyFactory;
|
||||
static jmethodID getProxyID;
|
||||
static jmethodID getInterfaceID;
|
||||
|
||||
static jclass java_lang_reflect_Proxy;
|
||||
static jmethodID getInvocationHandlerID;
|
||||
static jclass org_mozilla_xpcom_ProxyHandler;
|
||||
static jmethodID getOIDID;
|
||||
nsHashtable * oid2objectMap;
|
||||
|
||||
};
|
||||
|
||||
#endif /* __bcJavaStubsAndProxies_h */
|
||||
|
||||
@@ -32,8 +32,9 @@ static NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
|
||||
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
|
||||
|
||||
bcXPCOMMarshalToolkit::bcXPCOMMarshalToolkit(PRUint16 _methodIndex, nsIInterfaceInfo *_interfaceInfo,
|
||||
nsXPTCMiniVariant* _params) {
|
||||
nsXPTCMiniVariant* _params, bcIORB *_orb) {
|
||||
callSide = onClient;
|
||||
orb = _orb;
|
||||
methodIndex = _methodIndex;
|
||||
interfaceInfo = _interfaceInfo;
|
||||
interfaceInfo->GetMethodInfo(methodIndex,(const nsXPTMethodInfo**) &info); // These do *not* make copies ***explicit bending of XPCOM rules***
|
||||
@@ -54,8 +55,9 @@ bcXPCOMMarshalToolkit::bcXPCOMMarshalToolkit(PRUint16 _methodIndex, nsIInterface
|
||||
}
|
||||
|
||||
bcXPCOMMarshalToolkit::bcXPCOMMarshalToolkit(PRUint16 _methodIndex, nsIInterfaceInfo *_interfaceInfo,
|
||||
nsXPTCVariant* _params) {
|
||||
nsXPTCVariant* _params, bcIORB *_orb) {
|
||||
callSide = onServer;
|
||||
orb = _orb;
|
||||
methodIndex = _methodIndex;
|
||||
interfaceInfo = _interfaceInfo;
|
||||
interfaceInfo->GetMethodInfo(methodIndex,(const nsXPTMethodInfo **)&info); // These do *not* make copies ***explicit bending of XPCOM rules***
|
||||
@@ -297,21 +299,11 @@ nsresult bcXPCOMMarshalToolkit::MarshalElement(bcIMarshaler *m, void *data, nsXP
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--[c++]XPCOMMarshallToolkit INTERFACE iid=%s\n",iid->ToString()));
|
||||
bcOID oid = 0;
|
||||
if (*(char**)data != NULL) {
|
||||
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
return r; //nb am I sure about that?
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
|
||||
if (NS_FAILED(r)) {
|
||||
return r;
|
||||
}
|
||||
|
||||
bcIORB *orb;
|
||||
_orb->GetORB(&orb);
|
||||
bcIStub *stub = NULL;
|
||||
xpcomStubsAndProxies->GetStub(*(nsISupports**)data, &stub);
|
||||
oid = orb->RegisterStub(stub);
|
||||
xpcomStubsAndProxies->GetOID(*(nsISupports**)data, orb,&oid);
|
||||
}
|
||||
m->WriteSimple(&oid, XPTType2bcXPType(type));
|
||||
m->WriteSimple(iid,bc_T_IID);
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
class bcXPCOMMarshalToolkit {
|
||||
public:
|
||||
bcXPCOMMarshalToolkit(PRUint16 methodIndex,
|
||||
nsIInterfaceInfo *interfaceInfo, nsXPTCMiniVariant* params);
|
||||
nsIInterfaceInfo *interfaceInfo, nsXPTCMiniVariant* params, bcIORB *orb);
|
||||
bcXPCOMMarshalToolkit(PRUint16 methodIndex,
|
||||
nsIInterfaceInfo *interfaceInfo, nsXPTCVariant* params);
|
||||
nsIInterfaceInfo *interfaceInfo, nsXPTCVariant* params, bcIORB *orb);
|
||||
virtual ~bcXPCOMMarshalToolkit();
|
||||
nsresult Marshal(bcIMarshaler *);
|
||||
nsresult UnMarshal(bcIUnMarshaler *);
|
||||
@@ -45,6 +45,7 @@ private:
|
||||
nsXPTMethodInfo *info;
|
||||
nsXPTCVariant *params;
|
||||
nsIInterfaceInfo * interfaceInfo;
|
||||
bcIORB *orb;
|
||||
nsresult GetArraySizeFromParam( nsIInterfaceInfo *interfaceInfo,
|
||||
const nsXPTMethodInfo* method,
|
||||
const nsXPTParamInfo& param,
|
||||
|
||||
@@ -76,7 +76,7 @@ NS_IMETHODIMP bcXPCOMProxy::CallMethod(PRUint16 methodIndex,
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMProxy::CallMethod %s [%d]\n",info->GetName(),methodIndex));
|
||||
bcICall *call = orb->CreateCall(&iid, &oid, methodIndex);
|
||||
bcIMarshaler *marshaler = call->GetMarshaler();
|
||||
bcXPCOMMarshalToolkit * mt = new bcXPCOMMarshalToolkit(methodIndex, interfaceInfo, params);
|
||||
bcXPCOMMarshalToolkit * mt = new bcXPCOMMarshalToolkit(methodIndex, interfaceInfo, params,orb);
|
||||
mt->Marshal(marshaler);
|
||||
orb->SendReceive(call);
|
||||
bcIUnMarshaler * unmarshaler = call->GetUnMarshaler();
|
||||
@@ -105,6 +105,10 @@ nsrefcnt bcXPCOMProxy::Release(void) {
|
||||
|
||||
NS_IMETHODIMP bcXPCOMProxy::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
|
||||
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
|
||||
if (aIID.Equals(NS_GET_IID(bcXPCOMProxy))) { //hack for getting oid
|
||||
*aInstancePtr = &oid;
|
||||
return NS_OK;
|
||||
}
|
||||
PRUint16 methodIndex = 0;
|
||||
const nsXPTMethodInfo *info;
|
||||
nsIInterfaceInfo *inInfo;
|
||||
|
||||
@@ -28,9 +28,34 @@
|
||||
#include "bcXPCOMStub.h"
|
||||
#include "bcXPCOMLog.h"
|
||||
|
||||
bcXPCOMStub::bcXPCOMStub(nsISupports *o) {
|
||||
object = o;
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIThread.h"
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
struct CallInfo;
|
||||
|
||||
static void* PR_CALLBACK EventHandler(PLEvent *self);
|
||||
static void PR_CALLBACK DestroyHandler(PLEvent *self);
|
||||
|
||||
|
||||
struct CallInfo {
|
||||
CallInfo(nsIEventQueue * eq, bcICall *c, bcIStub *s) {
|
||||
callersEventQ = eq; call = c; stub = s; completed = PR_FALSE;
|
||||
}
|
||||
nsCOMPtr<nsIEventQueue> callersEventQ;
|
||||
bcICall *call;
|
||||
bcIStub *stub;
|
||||
PRBool completed;
|
||||
};
|
||||
|
||||
bcXPCOMStub::bcXPCOMStub(nsISupports *o) : object(o) {
|
||||
NS_ADDREF(object);
|
||||
_mOwningThread = NS_CurrentThread();
|
||||
eventQService = do_GetService(kEventQueueServiceCID);
|
||||
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(owningEventQ));
|
||||
}
|
||||
|
||||
bcXPCOMStub::~bcXPCOMStub() {
|
||||
@@ -39,44 +64,95 @@ bcXPCOMStub::~bcXPCOMStub() {
|
||||
|
||||
void bcXPCOMStub::Dispatch(bcICall *call) {
|
||||
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
|
||||
bcIID iid; bcOID oid; bcMID mid;
|
||||
call->GetParams(&iid, &oid, &mid);
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
|
||||
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
|
||||
return; //nb exception handling
|
||||
if (_mOwningThread == NS_CurrentThread()) {
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStub::Dispatch(bcICall *call)\n"));
|
||||
bcIID iid; bcOID oid; bcMID mid;
|
||||
call->GetParams(&iid, &oid, &mid);
|
||||
nsIInterfaceInfo *interfaceInfo;
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
|
||||
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
|
||||
return; //nb exception handling
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
} else {
|
||||
nsXPTCVariant *params;
|
||||
nsXPTMethodInfo* info;
|
||||
interfaceInfo->GetMethodInfo(mid,(const nsXPTMethodInfo **)&info);
|
||||
int paramCount = info->GetParamCount();
|
||||
bcXPCOMMarshalToolkit * mt = NULL;
|
||||
if (paramCount > 0) {
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--[c++]bcXPCOMStub paramCount %d\n",paramCount));
|
||||
params = (nsXPTCVariant *) PR_Malloc(sizeof(nsXPTCVariant)*paramCount);
|
||||
mt = new bcXPCOMMarshalToolkit(mid, interfaceInfo, params, call->GetORB());
|
||||
bcIUnMarshaler * um = call->GetUnMarshaler();
|
||||
mt->UnMarshal(um);
|
||||
}
|
||||
//nb return value; excepion handling
|
||||
XPTC_InvokeByIndex(object, mid, paramCount, params);
|
||||
if (mt != NULL) { //nb to do what about nsresult ?
|
||||
bcIMarshaler * m = call->GetMarshaler();
|
||||
mt->Marshal(m);
|
||||
}
|
||||
//nb memory deallocation
|
||||
return;
|
||||
}
|
||||
nsXPTCVariant *params;
|
||||
nsXPTMethodInfo* info;
|
||||
interfaceInfo->GetMethodInfo(mid,(const nsXPTMethodInfo **)&info);
|
||||
int paramCount = info->GetParamCount();
|
||||
bcXPCOMMarshalToolkit * mt = NULL;
|
||||
if (paramCount > 0) {
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--[c++]bcXPCOMStub paramCount %d\n",paramCount));
|
||||
params = (nsXPTCVariant *) PR_Malloc(sizeof(nsXPTCVariant)*paramCount);
|
||||
mt = new bcXPCOMMarshalToolkit(mid, interfaceInfo, params);
|
||||
bcIUnMarshaler * um = call->GetUnMarshaler();
|
||||
mt->UnMarshal(um);
|
||||
}
|
||||
//nb return value; excepion handling
|
||||
XPTC_InvokeByIndex(object, mid, paramCount, params);
|
||||
if (mt != NULL) { //nb to do what about nsresult ?
|
||||
bcIMarshaler * m = call->GetMarshaler();
|
||||
mt->Marshal(m);
|
||||
}
|
||||
//nb memory deallocation
|
||||
return;
|
||||
} else {
|
||||
PRBool eventLoopCreated = PR_FALSE;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> eventQ;
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = eventQService->CreateMonitoredThreadEventQueue();
|
||||
eventLoopCreated = PR_TRUE;
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
CallInfo * callInfo = new CallInfo(eventQ,call,this);
|
||||
PLEvent *event = PR_NEW(PLEvent);
|
||||
PL_InitEvent(event,
|
||||
callInfo,
|
||||
EventHandler,
|
||||
DestroyHandler);
|
||||
owningEventQ->PostEvent(event);
|
||||
while (1) {
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--Dispatch we got new event\n"));
|
||||
PLEvent *nextEvent;
|
||||
rv = eventQ->WaitForEvent(&nextEvent);
|
||||
if (callInfo->completed) {
|
||||
PR_DELETE(nextEvent);
|
||||
break; //we are done
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
eventQ->HandleEvent(nextEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void* EventHandler(PLEvent *self) {
|
||||
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--about to EventHandler\n"));
|
||||
CallInfo * callInfo = (CallInfo*)PL_GetEventOwner(self);
|
||||
callInfo->stub->Dispatch(callInfo->call);
|
||||
callInfo->completed = PR_TRUE;
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--about to callInfo->callersEventQ->PostEvent;\n"));
|
||||
PLEvent *event = PR_NEW(PLEvent);
|
||||
callInfo->callersEventQ->PostEvent(event);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void PR_CALLBACK DestroyHandler(PLEvent *self) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#define __bcXPCOMStub_h
|
||||
#include "nsISupports.h"
|
||||
#include "bcIStub.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
|
||||
class bcXPCOMStub : public bcIStub {
|
||||
public:
|
||||
@@ -32,6 +34,9 @@ public:
|
||||
virtual void Dispatch(bcICall *call) ;
|
||||
private:
|
||||
nsISupports *object;
|
||||
void* _mOwningThread;
|
||||
nsCOMPtr<nsIEventQueue> owningEventQ;
|
||||
nsCOMPtr<nsIEventQueueService> eventQService;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "bcXPCOMStubsAndProxies.h"
|
||||
#include "bcXPCOMStub.h"
|
||||
#include "bcXPCOMProxy.h"
|
||||
@@ -43,11 +44,36 @@ NS_IMPL_NSGETMODULE("BlackConnect XPCOM stubs and proxies",components);
|
||||
NS_IMPL_ISUPPORTS(bcXPCOMStubsAndProxies,NS_GET_IID(bcXPCOMStubsAndProxies));
|
||||
|
||||
|
||||
|
||||
class bcOIDKey : public nsHashKey {
|
||||
protected:
|
||||
bcOID key;
|
||||
public:
|
||||
bcOIDKey(bcOID oid) {
|
||||
key = oid;
|
||||
}
|
||||
virtual ~bcOIDKey() {
|
||||
}
|
||||
PRUint32 HashCode(void) const {
|
||||
return (PRUint32)key;
|
||||
}
|
||||
|
||||
PRBool Equals(const nsHashKey *aKey) const {
|
||||
return (key == ((const bcOIDKey *) aKey)->key);
|
||||
}
|
||||
nsHashKey *Clone() const {
|
||||
return new bcOIDKey(key);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
bcXPCOMStubsAndProxies::bcXPCOMStubsAndProxies() {
|
||||
NS_INIT_REFCNT();
|
||||
oid2objectMap = new nsSupportsHashtable(256, PR_TRUE);
|
||||
}
|
||||
|
||||
bcXPCOMStubsAndProxies::~bcXPCOMStubsAndProxies() {
|
||||
delete oid2objectMap;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcXPCOMStubsAndProxies::GetStub(nsISupports *obj, bcIStub **stub) {
|
||||
@@ -58,16 +84,41 @@ NS_IMETHODIMP bcXPCOMStubsAndProxies::GetStub(nsISupports *obj, bcIStub **stub)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcXPCOMStubsAndProxies::GetOID(nsISupports *obj, bcIORB *orb, bcOID *oid) {
|
||||
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
|
||||
bcOID *tmp;
|
||||
if (NS_SUCCEEDED(obj->QueryInterface(NS_GET_IID(bcXPCOMProxy),(void**)&tmp))) {
|
||||
*oid = *tmp;
|
||||
PR_LOG(log, PR_LOG_DEBUG,("--[c++] bcXPCOMProxy::GetOID obj %p is a proxy to oid %d\n",obj,*oid));
|
||||
} else {
|
||||
bcIStub *stub = NULL;
|
||||
GetStub(obj, &stub);
|
||||
*oid = orb->RegisterStub(stub);
|
||||
oid2objectMap->Put(new bcOIDKey(*oid),obj);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcXPCOMStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, nsISupports **proxy) {
|
||||
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
|
||||
nsresult rv = NS_OK;
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStubsAndProxies::GetProxy iid=%s\n",iid.ToString()));
|
||||
if (!proxy) {
|
||||
printf("--bcXPCOMStubsAndProxies::GetProxy failed\n");
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStubsAndProxies::GetProxy failed\n"));
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
*proxy = new bcXPCOMProxy(oid,iid,orb);
|
||||
NS_IF_ADDREF(*proxy);
|
||||
return NS_OK;
|
||||
*proxy = NULL;
|
||||
nsHashKey * key = new bcOIDKey(oid);
|
||||
*proxy = oid2objectMap->Get(key); //doing shortcut
|
||||
delete key;
|
||||
if (*proxy != NULL) {
|
||||
rv = (*proxy)->QueryInterface(iid,(void **)proxy);
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStubsAndProxies::GetProxy we have shortcut for oid=%d\n",oid));
|
||||
} else {
|
||||
*proxy = new bcXPCOMProxy(oid,iid,orb);
|
||||
NS_IF_ADDREF(*proxy);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,12 +39,25 @@
|
||||
{0x7de11df0, 0x1dd2, 0x11b2, \
|
||||
{0xb1, 0xe1, 0xd9, 0xd5, 0xc6, 0xdd, 0x06, 0x8b }}
|
||||
|
||||
class nsSupportsHashtable;
|
||||
|
||||
class bcXPCOMStubsAndProxies : public nsISupports {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(BC_XPCOMSTUBSANDPROXIES_IID)
|
||||
NS_IMETHOD GetStub(nsISupports *obj, bcIStub **stub);
|
||||
NS_IMETHOD GetOID(nsISupports *obj, bcIORB *orb, bcOID *oid);
|
||||
NS_IMETHOD GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, nsISupports **proxy);
|
||||
bcXPCOMStubsAndProxies();
|
||||
virtual ~bcXPCOMStubsAndProxies();
|
||||
private:
|
||||
nsSupportsHashtable * oid2objectMap;
|
||||
};
|
||||
#endif /* __bcXPCOMStubsAndProxies_h */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user