Landing xpcom proxies.
git-svn-id: svn://10.0.0.236/trunk@30725 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
18f06a678e
commit
a539b0b3d7
28
mozilla/xpcom/proxy/Makefile.in
Normal file
28
mozilla/xpcom/proxy/Makefile.in
Normal file
@ -0,0 +1,28 @@
|
||||
#!gmake
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
DIRS += tests
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
21
mozilla/xpcom/proxy/makefile.win
Normal file
21
mozilla/xpcom/proxy/makefile.win
Normal file
@ -0,0 +1,21 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
DIRS=public src tests
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
29
mozilla/xpcom/proxy/public/makefile.win
Normal file
29
mozilla/xpcom/proxy/public/makefile.win
Normal file
@ -0,0 +1,29 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
MODULE=libproxy
|
||||
|
||||
EXPORTS = \
|
||||
nsProxyEvent.h \
|
||||
nsProxyObjectManager.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
86
mozilla/xpcom/proxy/public/nsProxyEvent.h
Normal file
86
mozilla/xpcom/proxy/public/nsProxyEvent.h
Normal file
@ -0,0 +1,86 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __nsProxyEvent_h_
|
||||
#define __nsProxyEvent_h_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
#include "plevent.h"
|
||||
#include "xptcall.h"
|
||||
|
||||
|
||||
class NS_EXPORT nsProxyObject
|
||||
{
|
||||
public:
|
||||
nsProxyObject();
|
||||
nsProxyObject(PLEventQueue *destQueue, nsISupports *realObject);
|
||||
nsProxyObject(PLEventQueue *destQueue, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID);
|
||||
|
||||
virtual ~nsProxyObject();
|
||||
|
||||
|
||||
nsresult Post( PRUint32 methodIndex, /* which method to be called? */
|
||||
PRUint32 paramCount, /* number of params */
|
||||
nsXPTCVariant *params);
|
||||
|
||||
|
||||
nsresult GetLastResult() const { return mResult; }
|
||||
nsISupports* GetRealObject() const { return mRealObject; }
|
||||
PRUint32 GetMethodIndex() const { return mMethodIndex; }
|
||||
PRUint32 GetParameterCount() const { return mParameterCount; }
|
||||
nsXPTCVariant* GetParameterList() const { return mParameterList; }
|
||||
PLEventQueue* GetQueue() const { return mDestQueue; }
|
||||
|
||||
|
||||
|
||||
// These are called from PLEvent. They must be public. You should not use them.
|
||||
|
||||
static void* EventHandler(PLEvent *self);
|
||||
static void DestroyHandler(PLEvent *self);
|
||||
void InvokeMethod(void);
|
||||
private:
|
||||
|
||||
PLEventQueue *mDestQueue; /* destination queue */
|
||||
nsISupports *mRealObject; /* the non-proxy object that this event is referring to */
|
||||
PRBool mRealObjectOwned;
|
||||
|
||||
PRUint32 mMethodIndex; /* which method to be called? */
|
||||
nsresult mResult; /* this is the return result of the called function */
|
||||
PRUint32 mParameterCount; /* number of params */
|
||||
nsXPTCVariant *mParameterList; /* marshalled in parameter buffer */
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_PROXY(_class, _interface) \
|
||||
public: \
|
||||
_class(PLEventQueue *, _interface *); \
|
||||
private: \
|
||||
nsProxyObject mProxyObject;\
|
||||
public:
|
||||
|
||||
|
||||
#define NS_IMPL_PROXY(_class, _interface)\
|
||||
_class::_class(PLEventQueue *eventQueue, _interface *realObject) \
|
||||
: mProxyObject(eventQueue, realObject) \
|
||||
{\
|
||||
}\
|
||||
|
||||
#endif
|
||||
101
mozilla/xpcom/proxy/public/nsProxyObjectManager.h
Normal file
101
mozilla/xpcom/proxy/public/nsProxyObjectManager.h
Normal file
@ -0,0 +1,101 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __nsProxyObjectManager_h_
|
||||
#define __nsProxyObjectManager_h_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
#include "nsHashtable.h"
|
||||
|
||||
#include "plevent.h"
|
||||
#include "xptcall.h" // defines nsXPTCVariant
|
||||
|
||||
#include "nsProxyEvent.h"
|
||||
|
||||
|
||||
#define NS_PROXYEVENT_FACTORY_IID \
|
||||
{ 0xeea90d40, \
|
||||
0xb059, \
|
||||
0x11d2, \
|
||||
{0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33}\
|
||||
}
|
||||
|
||||
|
||||
#define NS_IPROXYEVENT_MANAGER_IID \
|
||||
{ 0xeea90d43, \
|
||||
0xb059, \
|
||||
0x11d2, \
|
||||
{0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33}\
|
||||
}
|
||||
|
||||
#define NS_PROXYEVENT_MANAGER_CID \
|
||||
{ 0xeea90d41, \
|
||||
0xb059, \
|
||||
0x11d2, \
|
||||
{0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33}\
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsProxyEventFactory:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsProxyEventFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
|
||||
nsProxyEventFactory();
|
||||
virtual ~nsProxyEventFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIProxyObjectManager
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsIProxyObjectManager : public nsISupports
|
||||
{
|
||||
public:
|
||||
|
||||
NS_IMETHOD GetProxyObject(PLEventQueue *destQueue,
|
||||
REFNSIID aIID,
|
||||
nsISupports* aObj,
|
||||
void** aProxyObject) = 0;
|
||||
|
||||
NS_IMETHOD GetProxyObject(PLEventQueue *destQueue,
|
||||
const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void** aProxyObject) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
31
mozilla/xpcom/proxy/src/Makefile.in
Normal file
31
mozilla/xpcom/proxy/src/Makefile.in
Normal file
@ -0,0 +1,31 @@
|
||||
#!gmake
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xpcom
|
||||
LIBRARY_NAME = xpproxy
|
||||
|
||||
CPPSRCS = \
|
||||
nsProxyEvent.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
6
mozilla/xpcom/proxy/src/idl/mk.bat
Executable file
6
mozilla/xpcom/proxy/src/idl/mk.bat
Executable file
@ -0,0 +1,6 @@
|
||||
xpidl -w -I ../../../../js/src/xpconnect/idl/ -m header nsIProxyCreateInstance.idl
|
||||
xpidl -w -I ../../../../js/src/xpconnect/idl/ -m typelib nsIProxyCreateInstance.idl
|
||||
|
||||
cp nsIProxyCreateInstance.xpt ../../../../dist/win32_d.obj/bin/components
|
||||
cp nsIProxyCreateInstance.h ../
|
||||
|
||||
20
mozilla/xpcom/proxy/src/idl/nsIProxyCreateInstance.idl
Normal file
20
mozilla/xpcom/proxy/src/idl/nsIProxyCreateInstance.idl
Normal file
@ -0,0 +1,20 @@
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/* XXX should be built in */
|
||||
native nsID(nsID *);
|
||||
|
||||
[scriptable, uuid(948c2080-0398-11d3-915e-0000863011c4)]
|
||||
|
||||
interface nsIProxyCreateInstance : nsISupports
|
||||
{
|
||||
void CreateInstanceByIID(in nsIIDRef cid,
|
||||
in nsISupports aOuter,
|
||||
in nsIIDRef iid,
|
||||
out voidStar result);
|
||||
|
||||
void CreateInstanceByProgID(in string aProgID,
|
||||
in nsISupports aOuter,
|
||||
in nsIIDRef iid,
|
||||
out voidStar result);
|
||||
};
|
||||
|
||||
58
mozilla/xpcom/proxy/src/makefile.win
Normal file
58
mozilla/xpcom/proxy/src/makefile.win
Normal file
@ -0,0 +1,58 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
MODULE=libproxy
|
||||
|
||||
DLL=.\$(OBJDIR)\$(MODULE).dll
|
||||
|
||||
LINCS = \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\xptcall \
|
||||
-I$(PUBLIC)\xptinfo \
|
||||
-I$(PUBLIC)\libxpt \
|
||||
-I$(PUBLIC)\libproxy \
|
||||
-I$(PUBLIC)\raptor \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\xptinfo32.lib \
|
||||
$(DIST)\lib\xptcall32.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(NULL)
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsProxyEvent.obj \
|
||||
.\$(OBJDIR)\nsProxyObjectManager.obj \
|
||||
.\$(OBJDIR)\nsProxyEventClass.obj \
|
||||
.\$(OBJDIR)\nsProxyEventObject.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(MODULE).lib
|
||||
rm -f $(DIST)\bin\$(MODULE).dll
|
||||
39
mozilla/xpcom/proxy/src/nsIProxyCreateInstance.h
Normal file
39
mozilla/xpcom/proxy/src/nsIProxyCreateInstance.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsIProxyCreateInstance.idl
|
||||
*/
|
||||
|
||||
#ifndef __gen_nsIProxyCreateInstance_h__
|
||||
#define __gen_nsIProxyCreateInstance_h__
|
||||
|
||||
#include "nsISupports.h" /* interface nsISupports */
|
||||
#include "nsrootidl.h" /* interface nsrootidl */
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
#include "jsapi.h"
|
||||
#endif
|
||||
|
||||
/* starting interface: nsIProxyCreateInstance */
|
||||
|
||||
/* {948c2080-0398-11d3-915e-0000863011c4} */
|
||||
#define NS_IPROXYCREATEINSTANCE_IID_STR "948c2080-0398-11d3-915e-0000863011c4"
|
||||
#define NS_IPROXYCREATEINSTANCE_IID \
|
||||
{0x948c2080, 0x0398, 0x11d3, \
|
||||
{ 0x91, 0x5e, 0x00, 0x00, 0x86, 0x30, 0x11, 0xc4 }}
|
||||
|
||||
class nsIProxyCreateInstance : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPROXYCREATEINSTANCE_IID)
|
||||
|
||||
/* void CreateInstanceByIID (in nsIIDRef cid, in nsISupports aOuter, in nsIIDRef iid, out voidStar result); */
|
||||
NS_IMETHOD CreateInstanceByIID(const nsIID & cid, nsISupports *aOuter, const nsIID & iid, void * *result) = 0;
|
||||
|
||||
/* void CreateInstanceByProgID (in string aProgID, in nsISupports aOuter, in nsIIDRef iid, out voidStar result); */
|
||||
NS_IMETHOD CreateInstanceByProgID(const char *aProgID, nsISupports *aOuter, const nsIID & iid, void * *result) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIProxyCreateInstance *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* __gen_nsIProxyCreateInstance_h__ */
|
||||
153
mozilla/xpcom/proxy/src/nsProxyEvent.cpp
Normal file
153
mozilla/xpcom/proxy/src/nsProxyEvent.cpp
Normal file
@ -0,0 +1,153 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsProxyEvent.h"
|
||||
#include "prmem.h" // for PR_NEW
|
||||
#include "xptcall.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
|
||||
nsProxyObject::nsProxyObject()
|
||||
{
|
||||
mRealObjectOwned = PR_FALSE;
|
||||
mRealObject = nsnull;
|
||||
mDestQueue = nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsProxyObject::nsProxyObject(PLEventQueue *destQueue, nsISupports *realObject)
|
||||
{
|
||||
mRealObjectOwned = PR_FALSE;
|
||||
mRealObject = realObject;
|
||||
mDestQueue = destQueue;
|
||||
|
||||
mRealObject->AddRef();
|
||||
}
|
||||
|
||||
|
||||
nsProxyObject::nsProxyObject(PLEventQueue *destQueue, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID)
|
||||
{
|
||||
mRealObjectOwned = PR_TRUE;
|
||||
mDestQueue = destQueue;
|
||||
|
||||
nsresult rv = nsComponentManager::CreateInstance(aClass,
|
||||
aDelegate,
|
||||
aIID,
|
||||
(void**) &mRealObject);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
mRealObjectOwned = PR_FALSE;
|
||||
mRealObject = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsProxyObject::~nsProxyObject()
|
||||
{
|
||||
PL_ENTER_EVENT_QUEUE_MONITOR(mDestQueue);
|
||||
PL_RevokeEvents(mDestQueue, this);
|
||||
|
||||
if(mRealObject != nsnull)
|
||||
{
|
||||
if (!mRealObjectOwned)
|
||||
mRealObject->Release();
|
||||
else
|
||||
NS_RELEASE(mRealObject);
|
||||
}
|
||||
|
||||
PL_EXIT_EVENT_QUEUE_MONITOR(mDestQueue);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsProxyObject::Post( PRUint32 methodIndex, /* which method to be called? */
|
||||
PRUint32 paramCount, /* number of params */
|
||||
nsXPTCVariant *params)
|
||||
{
|
||||
|
||||
PL_ENTER_EVENT_QUEUE_MONITOR(mDestQueue);
|
||||
|
||||
PLEvent *event = PR_NEW(PLEvent);
|
||||
if (event == NULL) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ASSERTION(mRealObject, "no native object");
|
||||
|
||||
PL_InitEvent(event,
|
||||
this,
|
||||
nsProxyObject::EventHandler,
|
||||
nsProxyObject::DestroyHandler);
|
||||
|
||||
|
||||
mMethodIndex = methodIndex;
|
||||
mParameterCount = paramCount;
|
||||
mParameterList = params;
|
||||
|
||||
PL_PostSynchronousEvent(mDestQueue, (PLEvent *)event);
|
||||
|
||||
PL_EXIT_EVENT_QUEUE_MONITOR(mDestQueue);
|
||||
|
||||
PR_FREEIF(event);
|
||||
|
||||
return mResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
nsProxyObject::InvokeMethod()
|
||||
{
|
||||
// invoke the magic of xptc...
|
||||
PL_ENTER_EVENT_QUEUE_MONITOR(mDestQueue);
|
||||
|
||||
mResult = XPTC_InvokeByIndex( mRealObject,
|
||||
mMethodIndex,
|
||||
mParameterCount,
|
||||
mParameterList);
|
||||
|
||||
PL_EXIT_EVENT_QUEUE_MONITOR(mDestQueue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void nsProxyObject::DestroyHandler(PLEvent *self) {}
|
||||
|
||||
|
||||
void* nsProxyObject::EventHandler(PLEvent *self)
|
||||
{
|
||||
nsProxyObject* proxyObject = (nsProxyObject*)PL_GetEventOwner(self);
|
||||
|
||||
if (proxyObject != nsnull)
|
||||
{
|
||||
proxyObject->InvokeMethod();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
280
mozilla/xpcom/proxy/src/nsProxyEventClass.cpp
Normal file
280
mozilla/xpcom/proxy/src/nsProxyEventClass.cpp
Normal file
@ -0,0 +1,280 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsProxyEvent.h"
|
||||
#include "nsProxyObjectManager.h"
|
||||
#include "nsProxyEventPrivate.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "xptcall.h"
|
||||
|
||||
|
||||
|
||||
static uint32 zero_methods_descriptor;
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// nsProxyEventClass
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kProxyEventClassIID, NS_PROXYEVENT_CLASS_IID);
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsProxyEventClass, kProxyEventClassIID)
|
||||
|
||||
// static
|
||||
nsProxyEventClass*
|
||||
nsProxyEventClass::GetNewOrUsedClass(REFNSIID aIID)
|
||||
{
|
||||
/* find in our hash table */
|
||||
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
nsHashtable *iidToClassMap = manager->GetIIDToProxyClassMap();
|
||||
|
||||
|
||||
nsProxyEventClass* clazz = NULL;
|
||||
nsIDKey key(aIID);
|
||||
|
||||
if(iidToClassMap->Exists(&key))
|
||||
{
|
||||
clazz = (nsProxyEventClass*) iidToClassMap->Get(&key);
|
||||
NS_ADDREF(clazz);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if(NULL != (iimgr = XPTI_GetInterfaceInfoManager()))
|
||||
{
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
/*
|
||||
Check to see if IsISupportsDescendent
|
||||
*/
|
||||
nsIInterfaceInfo* oldest = info;
|
||||
nsIInterfaceInfo* parent;
|
||||
|
||||
NS_ADDREF(oldest);
|
||||
while(NS_SUCCEEDED(oldest->GetParent(&parent)))
|
||||
{
|
||||
NS_RELEASE(oldest);
|
||||
oldest = parent;
|
||||
}
|
||||
|
||||
PRBool IsISupportsDescendent = PR_FALSE;
|
||||
nsID* iid;
|
||||
if(NS_SUCCEEDED(oldest->GetIID(&iid)))
|
||||
{
|
||||
IsISupportsDescendent = iid->Equals(nsISupports::GetIID());
|
||||
nsAllocator::Free(iid);
|
||||
}
|
||||
NS_RELEASE(oldest);
|
||||
|
||||
NS_ASSERTION(IsISupportsDescendent,"!IsISupportsDescendent");
|
||||
|
||||
if (IsISupportsDescendent)
|
||||
{
|
||||
clazz = new nsProxyEventClass(aIID, info);
|
||||
if(!clazz->mDescriptors)
|
||||
NS_RELEASE(clazz); // sets clazz to NULL
|
||||
}
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
|
||||
nsProxyEventClass::nsProxyEventClass(REFNSIID aIID, nsIInterfaceInfo* aInfo)
|
||||
: mInfo(aInfo),
|
||||
mIID(aIID),
|
||||
mDescriptors(NULL)
|
||||
{
|
||||
NS_ADDREF(mInfo);
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
/* add use to the used classes */
|
||||
nsIDKey key(aIID);
|
||||
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
nsHashtable *iidToClassMap = manager->GetIIDToProxyClassMap();
|
||||
|
||||
iidToClassMap->Put(&key, this);
|
||||
|
||||
uint16 methodCount;
|
||||
if(NS_SUCCEEDED(mInfo->GetMethodCount(&methodCount)))
|
||||
{
|
||||
if(methodCount)
|
||||
{
|
||||
int wordCount = (methodCount/32)+1;
|
||||
if(NULL != (mDescriptors = new uint32[wordCount]))
|
||||
{
|
||||
int i;
|
||||
// init flags to 0;
|
||||
for(i = wordCount-1; i >= 0; i--)
|
||||
mDescriptors[i] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mDescriptors = &zero_methods_descriptor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsProxyEventClass::~nsProxyEventClass()
|
||||
{
|
||||
if(mDescriptors && mDescriptors != &zero_methods_descriptor)
|
||||
delete [] mDescriptors;
|
||||
|
||||
nsIDKey key(mIID);
|
||||
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
nsHashtable *iidToClassMap = manager->GetIIDToProxyClassMap();
|
||||
iidToClassMap->Remove(&key);
|
||||
|
||||
NS_RELEASE(mInfo);
|
||||
}
|
||||
|
||||
nsProxyEventObject*
|
||||
nsProxyEventClass::CallQueryInterfaceOnProxy(nsProxyEventObject* self, REFNSIID aIID)
|
||||
{
|
||||
|
||||
nsISupports* aInstancePtr;
|
||||
|
||||
// The functions we will call: QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
|
||||
nsXPTCMiniVariant *var = new nsXPTCMiniVariant[2];
|
||||
if (var == nsnull) return nsnull;
|
||||
|
||||
(&var[0])->val.p = (void*)&aIID;
|
||||
(&var[1])->val.p = &aInstancePtr;
|
||||
|
||||
nsIInterfaceInfoManager *iim = XPTI_GetInterfaceInfoManager();
|
||||
nsIInterfaceInfo *nsISupportsInfo;
|
||||
const nsXPTMethodInfo *mi;
|
||||
|
||||
iim->GetInfoForName("nsISupports", &nsISupportsInfo);
|
||||
nsISupportsInfo->GetMethodInfo(0, &mi); // 0 is QueryInterface
|
||||
|
||||
nsresult rv = self->CallMethod(0, mi, var);
|
||||
|
||||
aInstancePtr = (nsISupports*) *((void**)var[1].val.p);
|
||||
|
||||
delete [] var;
|
||||
|
||||
if (rv == NS_OK)
|
||||
{
|
||||
nsProxyEventObject* proxyObj = nsProxyEventObject::GetNewOrUsedProxy(self->GetQueue(), aInstancePtr, aIID);
|
||||
if(proxyObj)
|
||||
{
|
||||
return proxyObj;
|
||||
}
|
||||
}
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
// 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 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 } }
|
||||
|
||||
class ProxyEventClassIdentity
|
||||
{
|
||||
// no instance methods...
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_PROXYEVENT_IDENTITY_CLASS_IID)
|
||||
|
||||
static void* GetSingleton()
|
||||
{
|
||||
static ProxyEventClassIdentity* singleton = NULL;
|
||||
if(!singleton)
|
||||
singleton = new ProxyEventClassIdentity();
|
||||
return (void*) singleton;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProxyEventClass::DelegatedQueryInterface(nsProxyEventObject* self,
|
||||
REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if(aIID.Equals(nsISupports::GetIID()))
|
||||
{
|
||||
nsProxyEventObject* root = self->GetRootProxyObject();
|
||||
*aInstancePtr = (void*) root;
|
||||
NS_ADDREF(root);
|
||||
return NS_OK;
|
||||
}
|
||||
else if(aIID.Equals(self->GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void*) self;
|
||||
NS_ADDREF(self);
|
||||
return NS_OK;
|
||||
}
|
||||
else if(aIID.Equals(ProxyEventClassIdentity::GetIID()))
|
||||
{
|
||||
*aInstancePtr = ProxyEventClassIdentity::GetSingleton();
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*aInstancePtr = CallQueryInterfaceOnProxy(self, aIID);
|
||||
if (*aInstancePtr == nsnull)
|
||||
return NS_NOINTERFACE;
|
||||
else
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsProxyEventObject*
|
||||
nsProxyEventClass::GetRootProxyObject(nsProxyEventObject* anObject)
|
||||
{
|
||||
nsProxyEventObject* result = CallQueryInterfaceOnProxy(anObject, nsISupports::GetIID());
|
||||
return result ? result : anObject;
|
||||
}
|
||||
296
mozilla/xpcom/proxy/src/nsProxyEventObject.cpp
Normal file
296
mozilla/xpcom/proxy/src/nsProxyEventObject.cpp
Normal file
@ -0,0 +1,296 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsProxyEvent.h"
|
||||
#include "nsProxyObjectManager.h"
|
||||
#include "nsProxyEventPrivate.h"
|
||||
|
||||
#include "nsHashtable.h"
|
||||
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "xptcall.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// nsProxyEventObject
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
nsProxyEventObject*
|
||||
nsProxyEventObject::GetNewOrUsedProxy(PLEventQueue *destQueue,
|
||||
nsISupports *aObj,
|
||||
REFNSIID aIID)
|
||||
{
|
||||
nsProxyEventObject* proxy = NULL;
|
||||
nsProxyEventObject* root = NULL;
|
||||
|
||||
|
||||
nsProxyEventClass* clazz = nsProxyEventClass::GetNewOrUsedClass(aIID);
|
||||
if(!clazz)
|
||||
return NULL;
|
||||
|
||||
nsISupports* rootObject;
|
||||
// always find the native root
|
||||
if(NS_FAILED(aObj->QueryInterface(nsISupports::GetIID(), (void**)&rootObject)))
|
||||
return NULL;
|
||||
|
||||
|
||||
/* find in our hash table */
|
||||
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
nsHashtable *realToProxyMap = manager->GetRealObjectToProxyObjectMap();
|
||||
|
||||
nsVoidKey key(rootObject);
|
||||
if(realToProxyMap->Exists(&key))
|
||||
{
|
||||
root = (nsProxyEventObject*) realToProxyMap->Get(&key);
|
||||
proxy = root->Find(aIID);
|
||||
|
||||
if(proxy)
|
||||
{
|
||||
NS_ADDREF(proxy);
|
||||
goto return_wrapper;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// build the root proxy
|
||||
if (aObj = rootObject)
|
||||
{
|
||||
// the root will do double duty as the interface wrapper
|
||||
proxy = root = new nsProxyEventObject(destQueue, aObj, clazz, nsnull);
|
||||
if(root)
|
||||
realToProxyMap->Put(&key, root);
|
||||
goto return_wrapper;
|
||||
}
|
||||
else
|
||||
{
|
||||
// just a root proxy
|
||||
nsProxyEventClass* rootClazz = nsProxyEventClass::GetNewOrUsedClass(nsISupports::GetIID());
|
||||
if(!rootClazz)
|
||||
{
|
||||
goto return_wrapper;
|
||||
}
|
||||
|
||||
root = new nsProxyEventObject(destQueue, rootObject, rootClazz, nsnull);
|
||||
NS_RELEASE(rootClazz);
|
||||
|
||||
if(!root)
|
||||
{
|
||||
goto return_wrapper;
|
||||
}
|
||||
realToProxyMap->Put(&key, root);
|
||||
}
|
||||
}
|
||||
// at this point we have a root and may need to build the specific proxy
|
||||
NS_ASSERTION(root,"bad root");
|
||||
NS_ASSERTION(clazz,"bad clazz");
|
||||
|
||||
if(!proxy)
|
||||
{
|
||||
proxy = new nsProxyEventObject(destQueue, aObj, clazz, root);
|
||||
if(!proxy)
|
||||
{
|
||||
goto return_wrapper;
|
||||
}
|
||||
}
|
||||
proxy->mNext = root->mNext;
|
||||
root->mNext = 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
nsProxyEventObject::nsProxyEventObject(PLEventQueue *destQueue,
|
||||
nsISupports* aObj,
|
||||
nsProxyEventClass* aClass,
|
||||
nsProxyEventObject* root)
|
||||
: mClass(aClass),
|
||||
mNext(NULL)
|
||||
{
|
||||
mRoot = (root ? root : this);
|
||||
mProxyObject = new nsProxyObject(destQueue, aObj);
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
NS_ADDREF(aClass);
|
||||
}
|
||||
|
||||
nsProxyEventObject::~nsProxyEventObject()
|
||||
{
|
||||
NS_PRECONDITION(0 == mRefCnt, "refcounting error");
|
||||
if(mRoot == this && GetClass())
|
||||
{
|
||||
nsVoidKey key(this);
|
||||
|
||||
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
|
||||
nsHashtable *realToProxyMap = manager->GetRealObjectToProxyObjectMap();
|
||||
realToProxyMap->Remove(&key);
|
||||
}
|
||||
|
||||
if (mProxyObject != nsnull)
|
||||
delete mProxyObject;
|
||||
|
||||
NS_RELEASE(mClass);
|
||||
|
||||
if(mNext)
|
||||
NS_DELETEXPCOM(mNext); // cascaded delete
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProxyEventObject::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if(NULL == aInstancePtr)
|
||||
{
|
||||
NS_PRECONDITION(0, "null pointer");
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
return mClass->DelegatedQueryInterface(this, aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
|
||||
nsrefcnt
|
||||
nsProxyEventObject::AddRef(void)
|
||||
{
|
||||
NS_PRECONDITION(mRoot, "bad root");
|
||||
|
||||
if(1 == ++mRefCnt && mRoot && mRoot != this)
|
||||
NS_ADDREF(mRoot);
|
||||
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt
|
||||
nsProxyEventObject::Release(void)
|
||||
{
|
||||
NS_PRECONDITION(mRoot, "bad root");
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
||||
|
||||
if(0 == --mRefCnt)
|
||||
{
|
||||
if(mRoot == this)
|
||||
{
|
||||
NS_DELETEXPCOM(this); // cascaded delete
|
||||
}
|
||||
else
|
||||
{
|
||||
mRoot->Release();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
|
||||
nsProxyEventObject*
|
||||
nsProxyEventObject::Find(REFNSIID aIID)
|
||||
{
|
||||
if(aIID.Equals(nsISupports::GetIID()))
|
||||
return mRoot;
|
||||
|
||||
nsProxyEventObject* cur = mRoot;
|
||||
do
|
||||
{
|
||||
if(aIID.Equals(GetIID()))
|
||||
return cur;
|
||||
|
||||
} while(NULL != (cur = cur->mNext));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProxyEventObject::GetInterfaceInfo(nsIInterfaceInfo** 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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
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;
|
||||
}
|
||||
|
||||
nsresult rv = mProxyObject->Post(methodIndex, paramCount, fullParam);
|
||||
|
||||
if (fullParam)
|
||||
free( (void*) fullParam);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
156
mozilla/xpcom/proxy/src/nsProxyEventPrivate.h
Normal file
156
mozilla/xpcom/proxy/src/nsProxyEventPrivate.h
Normal file
@ -0,0 +1,156 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __nsProxyEventPrivate_h_
|
||||
#define __nsProxyEventPrivate_h_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
#include "plevent.h"
|
||||
#include "xptcall.h" // defines nsXPTCVariant
|
||||
|
||||
#include "nsProxyEvent.h"
|
||||
|
||||
class nsProxyEventObject;
|
||||
class nsProxyEventClass;
|
||||
|
||||
#define NS_PROXYEVENT_CLASS_IID \
|
||||
{ 0xeea90d42, \
|
||||
0xb059, \
|
||||
0x11d2, \
|
||||
{0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33}\
|
||||
}
|
||||
|
||||
class nsProxyEventClass : public nsISupports
|
||||
{
|
||||
// all the interface method declarations...
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
static nsProxyEventClass* GetNewOrUsedClass(REFNSIID aIID);
|
||||
|
||||
|
||||
NS_IMETHOD DelegatedQueryInterface(nsProxyEventObject* self, REFNSIID aIID, void** aInstancePtr);
|
||||
REFNSIID GetIID() const {return mIID;}
|
||||
nsIInterfaceInfo* GetInterfaceInfo() const {return mInfo;}
|
||||
nsProxyEventObject* GetRootProxyObject(nsProxyEventObject* anObject);
|
||||
nsProxyEventObject* CallQueryInterfaceOnProxy(nsProxyEventObject* self, REFNSIID aIID);
|
||||
|
||||
virtual ~nsProxyEventClass();
|
||||
private:
|
||||
nsProxyEventClass(); // not implemented
|
||||
nsProxyEventClass(REFNSIID aIID, nsIInterfaceInfo* aInfo);
|
||||
|
||||
private:
|
||||
nsIInterfaceInfo* mInfo;
|
||||
nsIID mIID;
|
||||
uint32* mDescriptors;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class nsProxyEventObject : public nsXPTCStubBase
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
|
||||
|
||||
// call this method and return result
|
||||
NS_IMETHOD CallMethod(PRUint16 methodIndex,
|
||||
const nsXPTMethodInfo* info,
|
||||
nsXPTCMiniVariant* params);
|
||||
|
||||
|
||||
static nsProxyEventObject* GetNewOrUsedProxy(PLEventQueue *destQueue,
|
||||
nsISupports *aObj,
|
||||
REFNSIID aIID);
|
||||
|
||||
|
||||
PLEventQueue* GetQueue() const { return mProxyObject->GetQueue(); }
|
||||
|
||||
REFNSIID GetIID() const {return GetClass()->GetIID();}
|
||||
nsProxyEventClass* GetClass() const { return mClass; }
|
||||
|
||||
nsProxyEventObject* GetRootProxyObject() const { return mRoot; }
|
||||
|
||||
nsProxyEventObject* Find(REFNSIID aIID);
|
||||
|
||||
virtual ~nsProxyEventObject();
|
||||
|
||||
private:
|
||||
nsProxyEventObject::nsProxyEventObject(); // not implemented
|
||||
nsProxyEventObject::nsProxyEventObject(PLEventQueue *destQueue,
|
||||
nsISupports* aObj,
|
||||
nsProxyEventClass* aClass,
|
||||
nsProxyEventObject* root);
|
||||
|
||||
|
||||
nsProxyObject* mProxyObject;
|
||||
|
||||
nsProxyEventClass* mClass;
|
||||
nsProxyEventObject* mRoot;
|
||||
nsProxyEventObject* mNext;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsProxyObjectManager
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsProxyObjectManager: public nsIProxyObjectManager
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS;
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPROXYEVENT_MANAGER_IID);
|
||||
|
||||
NS_IMETHOD GetProxyObject(PLEventQueue *destQueue,
|
||||
REFNSIID aIID,
|
||||
nsISupports* aObj,
|
||||
void** aProxyObject);
|
||||
|
||||
NS_IMETHOD GetProxyObject(PLEventQueue *destQueue,
|
||||
const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void** aProxyObject);
|
||||
nsProxyObjectManager();
|
||||
virtual ~nsProxyObjectManager();
|
||||
|
||||
static nsProxyObjectManager *GetInstance();
|
||||
|
||||
nsHashtable *GetRealObjectToProxyObjectMap();
|
||||
nsHashtable *GetIIDToProxyClassMap();
|
||||
|
||||
private:
|
||||
static nsProxyObjectManager* mInstance;
|
||||
|
||||
PRLock *mLock;
|
||||
nsHashtable *mProxyObjectMap;
|
||||
nsHashtable *mProxyClassMap;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
363
mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp
Normal file
363
mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp
Normal file
@ -0,0 +1,363 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsProxyEvent.h"
|
||||
#include "nsProxyObjectManager.h"
|
||||
#include "nsProxyEventPrivate.h"
|
||||
|
||||
#include "nsIProxyCreateInstance.h"
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "plevent.h"
|
||||
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* nsProxyCreateInstance */
|
||||
/* This private class will allow us to create Instances on another thread */
|
||||
/***************************************************************************/
|
||||
class nsProxyCreateInstance : public nsIProxyCreateInstance
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_IMETHOD CreateInstanceByIID(const nsIID & cid, nsISupports *aOuter, const nsIID & iid, void * *result);
|
||||
NS_IMETHOD CreateInstanceByProgID(const char *aProgID, nsISupports *aOuter, const nsIID & iid, void * *result);
|
||||
|
||||
nsProxyCreateInstance();
|
||||
~nsProxyCreateInstance();
|
||||
|
||||
};
|
||||
|
||||
nsProxyCreateInstance::nsProxyCreateInstance()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
}
|
||||
|
||||
nsProxyCreateInstance::~nsProxyCreateInstance()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsProxyCreateInstance,NS_IPROXYCREATEINSTANCE_IID)
|
||||
|
||||
NS_IMETHODIMP nsProxyCreateInstance::CreateInstanceByIID(const nsIID & cid, nsISupports *aOuter, const nsIID & iid, void * *result)
|
||||
{
|
||||
return nsComponentManager::CreateInstance( cid,
|
||||
aOuter,
|
||||
iid,
|
||||
result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsProxyCreateInstance::CreateInstanceByProgID(const char *aProgID, nsISupports *aOuter, const nsIID & iid, void * *result)
|
||||
{
|
||||
return nsComponentManager::CreateInstance( aProgID,
|
||||
aOuter,
|
||||
iid,
|
||||
result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// nsProxyObjectManager
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsProxyObjectManager* nsProxyObjectManager::mInstance = nsnull;
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsProxyObjectManager, NS_IPROXYEVENT_MANAGER_IID)
|
||||
|
||||
nsProxyObjectManager::nsProxyObjectManager()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mProxyClassMap = new nsHashtable(256, PR_TRUE);
|
||||
mProxyObjectMap = new nsHashtable(256, PR_TRUE);
|
||||
}
|
||||
|
||||
nsProxyObjectManager::~nsProxyObjectManager()
|
||||
{
|
||||
delete mProxyClassMap;
|
||||
delete mProxyObjectMap;
|
||||
}
|
||||
|
||||
nsProxyObjectManager *
|
||||
nsProxyObjectManager::GetInstance()
|
||||
{
|
||||
if (mInstance == NULL)
|
||||
{
|
||||
mInstance = new nsProxyObjectManager();
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProxyObjectManager::GetProxyObject(PLEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, void** aProxyObject)
|
||||
{
|
||||
|
||||
*aProxyObject = nsnull;
|
||||
|
||||
// check to see if proxy is there or not.
|
||||
*aProxyObject = nsProxyEventObject::GetNewOrUsedProxy(destQueue, aObj, aIID);
|
||||
if (*aProxyObject != nsnull)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FACTORY_NOT_REGISTERED; //fix error code?
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProxyObjectManager::GetProxyObject(PLEventQueue *destQueue,
|
||||
const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void** aProxyObject)
|
||||
{
|
||||
*aProxyObject = nsnull;
|
||||
|
||||
nsIProxyCreateInstance* ciProxy = nsnull;
|
||||
nsProxyCreateInstance* ciObject = new nsProxyCreateInstance();
|
||||
|
||||
if (ciObject == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
GetProxyObject(destQueue, nsIProxyCreateInstance::GetIID(), ciObject, (void**)&ciProxy);
|
||||
|
||||
// release ownership of ciObject so that ciProxy owns it.
|
||||
if (ciObject)
|
||||
NS_RELEASE(ciObject);
|
||||
|
||||
|
||||
if (ciProxy == nsnull)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
|
||||
nsISupports* aObj;
|
||||
|
||||
nsresult rv = ciProxy->CreateInstanceByIID(aClass,
|
||||
aDelegate,
|
||||
aIID,
|
||||
(void**)&aObj);
|
||||
|
||||
|
||||
if (aObj == nsnull)
|
||||
return rv;
|
||||
|
||||
|
||||
GetProxyObject(destQueue, aIID, aObj, aProxyObject);
|
||||
|
||||
// release ownership of aObj so that aProxyObject owns it.
|
||||
if (aObj)
|
||||
NS_RELEASE(aObj);
|
||||
|
||||
if (aProxyObject != nsnull)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FACTORY_NOT_REGISTERED; //fix error code?
|
||||
}
|
||||
|
||||
nsHashtable*
|
||||
nsProxyObjectManager::GetRealObjectToProxyObjectMap()
|
||||
{
|
||||
NS_ASSERTION(mProxyObjectMap, "no hashtable");
|
||||
return mProxyObjectMap;
|
||||
}
|
||||
|
||||
nsHashtable*
|
||||
nsProxyObjectManager::GetIIDToProxyClassMap()
|
||||
{
|
||||
NS_ASSERTION(mProxyClassMap, "no hashtable");
|
||||
return mProxyClassMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// nsProxyEventFactory
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
nsProxyEventFactory::nsProxyEventFactory(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsProxyEventFactory::~nsProxyEventFactory(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsProxyEventFactory,kIFactoryIID)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProxyEventFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aResult == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
nsProxyObjectManager *inst = nsProxyObjectManager::GetInstance();
|
||||
|
||||
if (inst == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult result = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
if (NS_FAILED(result))
|
||||
{
|
||||
*aResult = NULL;
|
||||
}
|
||||
|
||||
NS_ADDREF(inst); // Are we sure that we need to addref???
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProxyEventFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
// not implemented.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DLL Entry Points:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
extern "C" NS_EXPORT PRBool
|
||||
NSCanUnload(nsISupports* aServMgr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSRegisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("*** nsProxyObjectManager is being registered. Hold on to your seat...\n");
|
||||
#endif
|
||||
|
||||
rv = compMgr->RegisterComponent(kProxyObjectManagerCID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
done:
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("*** nsProxyObjectManager is being unregistered. Na na na na hey hey\n");
|
||||
#endif
|
||||
|
||||
rv = compMgr->UnregisterFactory(kProxyObjectManagerCID, path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
done:
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSGetFactory(nsISupports* aServMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
if (aFactory == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aFactory = NULL;
|
||||
nsISupports *inst;
|
||||
|
||||
|
||||
if (aClass.Equals(kProxyObjectManagerCID) )
|
||||
inst = new nsProxyEventFactory();
|
||||
else
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
if (inst == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = inst->QueryInterface(kIFactoryIID, (void**) aFactory);
|
||||
|
||||
if (NS_FAILED(res))
|
||||
{
|
||||
delete inst;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
36
mozilla/xpcom/proxy/tests/Makefile.in
Normal file
36
mozilla/xpcom/proxy/tests/Makefile.in
Normal file
@ -0,0 +1,36 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = libproxy
|
||||
|
||||
SIMPLE_PROGRAMS = main
|
||||
|
||||
CSRCS = main.c
|
||||
|
||||
LIBS = \
|
||||
-L$(DIST)/bin \
|
||||
-lxpt \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
5
mozilla/xpcom/proxy/tests/idl/mk.bat
Executable file
5
mozilla/xpcom/proxy/tests/idl/mk.bat
Executable file
@ -0,0 +1,5 @@
|
||||
xpidl -w -I ../../../../js/src/xpconnect/idl/ -m header nsITestProxyFoo.idl
|
||||
xpidl -w -I ../../../../js/src/xpconnect/idl/ -m typelib nsITestProxyFoo.idl
|
||||
|
||||
cp nsITestProxyFoo.xpt ../../../../dist/win32_d.obj/bin/components
|
||||
|
||||
1
mozilla/xpcom/proxy/tests/idl/nsITestProxyFoo.idl
Normal file
1
mozilla/xpcom/proxy/tests/idl/nsITestProxyFoo.idl
Normal file
@ -0,0 +1 @@
|
||||
#include "nsISupports.idl"
|
||||
54
mozilla/xpcom/proxy/tests/makefile.win
Normal file
54
mozilla/xpcom/proxy/tests/makefile.win
Normal file
@ -0,0 +1,54 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
DEPTH=..\..\..
|
||||
|
||||
MAKE_OBJ_TYPE = EXE
|
||||
PROGRAM = .\$(OBJDIR)\ProxyEventTest.exe
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\proxytests.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\xptinfo32.lib \
|
||||
$(DIST)\lib\xptcall32.lib \
|
||||
$(DIST)\lib\libproxy.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(NULL)
|
||||
|
||||
LINCS = \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\xptcall \
|
||||
-I$(PUBLIC)\xptinfo \
|
||||
-I$(PUBLIC)\libxpt \
|
||||
-I$(PUBLIC)\libproxy \
|
||||
-I$(PUBLIC)\raptor \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
export:: $(PROGRAM)
|
||||
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\ProxyEventTest.exe
|
||||
|
||||
$(PROGRAM):: $(OBJS) $(LLIBS)
|
||||
|
||||
477
mozilla/xpcom/proxy/tests/proxytests.cpp
Normal file
477
mozilla/xpcom/proxy/tests/proxytests.cpp
Normal file
@ -0,0 +1,477 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nsRepository.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsSpecialSystemDirectory.h" // For exe dir
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nspr.h"
|
||||
#include "prmon.h"
|
||||
|
||||
|
||||
#include "../../../js/src/xpconnect/public/xpctest.h"
|
||||
#include "idl/nsITestProxyFoo.h"
|
||||
|
||||
#include "nsProxyObjectManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kProxyObjectManagerIID, NS_IPROXYEVENT_MANAGER_IID);
|
||||
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Setup nsIAllocator */
|
||||
/***************************************************************************/
|
||||
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
|
||||
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
||||
|
||||
#ifdef XP_PC
|
||||
#define XPCOM_DLL "xpcom32.dll"
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#define XPCOM_DLL "XPCOM_DLL"
|
||||
#else
|
||||
#define XPCOM_DLL "libxpcom.so"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XP_PC
|
||||
#define LIBPROXY_DLL "libproxy.dll"
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#define LIBPROXY_DLL "??????????????????"
|
||||
#else
|
||||
#define LIBPROXY_DLL "libproxy.so"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
extern "C" void
|
||||
NS_SetupRegistry()
|
||||
{
|
||||
// Autoregistration happens here. The rest of RegisterComponent() calls should happen
|
||||
// only for dlls not in the components directory.
|
||||
|
||||
// Create exeDir/"components"
|
||||
nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
sysdir += "components";
|
||||
const char *componentsDir = sysdir.GetCString(); // native path
|
||||
if (componentsDir != NULL)
|
||||
{
|
||||
#ifdef XP_PC
|
||||
/* The PC version of the directory from filePath is of the form
|
||||
* /y|/moz/mozilla/dist/bin/components
|
||||
* We need to remove the initial / and change the | to :
|
||||
* for all this to work with NSPR.
|
||||
*/
|
||||
#endif /* XP_PC */
|
||||
printf("nsComponentManager: Using components dir: %s\n", componentsDir);
|
||||
|
||||
#ifdef XP_MAC
|
||||
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull);
|
||||
#else
|
||||
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, componentsDir);
|
||||
#endif /* XP_MAC */
|
||||
// XXX Look for user specific components
|
||||
// XXX UNIX: ~/.mozilla/components
|
||||
}
|
||||
|
||||
|
||||
nsComponentManager::RegisterComponent(kAllocatorCID, NULL, NULL, XPCOM_DLL,
|
||||
PR_FALSE, PR_FALSE);
|
||||
|
||||
nsComponentManager::RegisterComponent(kProxyObjectManagerCID, NULL, NULL, LIBPROXY_DLL,
|
||||
PR_FALSE, PR_FALSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* nsTestProxy */
|
||||
/***************************************************************************/
|
||||
class nsTestProxy : public nsITestProxyFoo
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Test(nsISupports *p1, nsISupports **p2);
|
||||
|
||||
nsTestProxy();
|
||||
~nsTestProxy();
|
||||
};
|
||||
|
||||
|
||||
nsTestProxy::nsTestProxy()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
}
|
||||
|
||||
nsTestProxy::~nsTestProxy()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsTestProxy,NS_ITESTPROXYFOO_IID)
|
||||
|
||||
NS_IMETHODIMP nsTestProxy::Test(nsISupports *p1, nsISupports **p2)
|
||||
{
|
||||
*p2 = this;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* nsTestXPCFoo */
|
||||
/***************************************************************************/
|
||||
class nsTestXPCFoo : public nsITestXPCFoo
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_IMETHOD Test(int p1, int p2, int* retval);
|
||||
NS_IMETHOD Test2();
|
||||
nsTestXPCFoo();
|
||||
~nsTestXPCFoo();
|
||||
|
||||
};
|
||||
|
||||
nsTestXPCFoo::nsTestXPCFoo()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
}
|
||||
|
||||
nsTestXPCFoo::~nsTestXPCFoo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsTestXPCFoo,NS_ITESTXPCFOO_IID)
|
||||
|
||||
NS_IMETHODIMP nsTestXPCFoo::Test(int p1, int p2, int* retval)
|
||||
{
|
||||
printf("Thread (%d) Test Called successfully! Party on...\n", p1);
|
||||
*retval = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTestXPCFoo::Test2()
|
||||
{
|
||||
printf("The quick brown netscape jumped over the old lazy ie..\n");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* nsTestXPCFoo2 */
|
||||
/***************************************************************************/
|
||||
class nsTestXPCFoo2 : public nsITestXPCFoo
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_IMETHOD Test(int p1, int p2, int* retval);
|
||||
NS_IMETHOD Test2();
|
||||
nsTestXPCFoo2();
|
||||
~nsTestXPCFoo2();
|
||||
|
||||
};
|
||||
|
||||
nsTestXPCFoo2::nsTestXPCFoo2()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
}
|
||||
|
||||
nsTestXPCFoo2::~nsTestXPCFoo2()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsTestXPCFoo2,NS_ITESTXPCFOO_IID)
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTestXPCFoo2::Test(int p1, int p2, int* retval)
|
||||
{
|
||||
printf("Thread (%d) nsTestXPCFoo2::Test2() called successfully! Party on...\n", p1);
|
||||
*retval = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTestXPCFoo2::Test2()
|
||||
{
|
||||
printf("nsTestXPCFoo2::Test2() called\n");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct _ArgsStruct
|
||||
{
|
||||
PLEventQueue* queue;
|
||||
int threadNumber;
|
||||
}ArgsStruct;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// This will create two objects both descendants of a single IID.
|
||||
void TestCase_TwoClassesOneInterface(void *arg)
|
||||
{
|
||||
|
||||
ArgsStruct *argsStruct = (ArgsStruct*) arg;
|
||||
|
||||
|
||||
nsIProxyObjectManager* proxyObjectFactory;
|
||||
|
||||
nsComponentManager::CreateInstance(kProxyObjectManagerCID,
|
||||
nsnull,
|
||||
nsIProxyObjectManager::GetIID(),
|
||||
(void**)&proxyObjectFactory);
|
||||
|
||||
PR_ASSERT(proxyObjectFactory);
|
||||
|
||||
nsITestXPCFoo *proxyObject;
|
||||
nsITestXPCFoo *proxyObject2;
|
||||
|
||||
nsTestXPCFoo* foo = new nsTestXPCFoo();
|
||||
nsTestXPCFoo2* foo2 = new nsTestXPCFoo2();
|
||||
|
||||
|
||||
PR_ASSERT(foo);
|
||||
PR_ASSERT(foo2);
|
||||
|
||||
proxyObjectFactory->GetProxyObject(argsStruct->queue, nsITestXPCFoo::GetIID(), foo, (void**)&proxyObject);
|
||||
|
||||
proxyObjectFactory->GetProxyObject(argsStruct->queue, nsITestXPCFoo::GetIID(), foo2, (void**)&proxyObject2);
|
||||
|
||||
if (proxyObject && proxyObject2)
|
||||
{
|
||||
// release ownership of the real object.
|
||||
//printf("Deleting real Object (%ld)\n", threadNumber);
|
||||
NS_RELEASE(foo);
|
||||
|
||||
//printf("Deleting real Object 2 (%ld)\n", threadNumber);
|
||||
NS_RELEASE(foo2);
|
||||
|
||||
|
||||
int a;
|
||||
nsresult rv;
|
||||
int threadNumber = argsStruct->threadNumber;
|
||||
|
||||
//printf("Thread (%ld) Prior to calling proxyObject->Test.\n", threadNumber);
|
||||
rv = proxyObject->Test(threadNumber, 0, &a);
|
||||
//printf("Thread (%ld) error: %ld.\n", threadNumber, rv);
|
||||
|
||||
|
||||
//printf("Thread (%ld) Prior to calling proxyObject->Test2.\n", threadNumber);
|
||||
rv = proxyObject->Test2();
|
||||
//printf("Thread (%ld) error: %ld.\n", threadNumber, rv);
|
||||
|
||||
|
||||
//printf("Thread (%ld) Prior to calling proxyObject2->Test.\n", threadNumber);
|
||||
rv = proxyObject2->Test(threadNumber, 0, &a);
|
||||
//printf("Thread (%ld) proxyObject2 error: %ld.\n", threadNumber, rv);
|
||||
|
||||
//printf("Thread (%ld) Prior to calling proxyObject2->Test2.\n", threadNumber);
|
||||
rv = proxyObject2->Test2();
|
||||
//printf("Thread (%ld) proxyObject2 error: %ld.\n", threadNumber, rv);
|
||||
|
||||
//printf("Deleting Proxy Object (%ld)\n", threadNumber );
|
||||
NS_RELEASE(proxyObject);
|
||||
|
||||
//printf("Deleting Proxy Object 2 (%ld)\n", threadNumber );
|
||||
NS_RELEASE(proxyObject2);
|
||||
}
|
||||
|
||||
free((void*) arg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void TestCase_2(void *arg)
|
||||
{
|
||||
|
||||
ArgsStruct *argsStruct = (ArgsStruct*) arg;
|
||||
|
||||
nsIProxyObjectManager* proxyObjectFactory;
|
||||
|
||||
nsComponentManager::CreateInstance(kProxyObjectManagerCID,
|
||||
nsnull,
|
||||
nsIProxyObjectManager::GetIID(),
|
||||
(void**)&proxyObjectFactory);
|
||||
|
||||
PR_ASSERT(proxyObjectFactory);
|
||||
|
||||
nsITestXPCFoo *proxyObject;
|
||||
|
||||
proxyObjectFactory->GetProxyObject(argsStruct->queue,
|
||||
nsITestXPCFoo::GetIID(), // should be a cid
|
||||
nsnull,
|
||||
nsITestXPCFoo::GetIID(),
|
||||
(void**)&proxyObject);
|
||||
|
||||
if (proxyObject != nsnull)
|
||||
{
|
||||
nsISupports *a;
|
||||
nsISupports *b;
|
||||
|
||||
NS_RELEASE(proxyObject);
|
||||
|
||||
}
|
||||
|
||||
free((void*) arg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* ProxyTest */
|
||||
/***************************************************************************/
|
||||
|
||||
static void PR_CALLBACK ProxyTest( void *arg )
|
||||
{
|
||||
// TestCase_TwoClassesOneInterface(arg);
|
||||
TestCase_2(arg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
PLEventQueue *gEventQueue = nsnull;
|
||||
|
||||
static void PR_CALLBACK EventLoop( void *arg )
|
||||
{
|
||||
printf("Creating EventQueue...\n");
|
||||
|
||||
gEventQueue = PL_CreateEventQueue("mainqueue", PR_GetCurrentThread());
|
||||
|
||||
printf("Looping for events.\n");
|
||||
|
||||
while ( PR_SUCCESS == PR_Sleep( PR_MillisecondsToInterval(1)) )
|
||||
{
|
||||
PL_HandleEvent(PL_GetEvent(gEventQueue));
|
||||
}
|
||||
|
||||
PL_ProcessPendingEvents(gEventQueue);
|
||||
|
||||
printf("Closing down Event Queue.\n");
|
||||
PL_DestroyEventQueue( gEventQueue );
|
||||
|
||||
|
||||
printf("End looping for events.\n\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int numberOfThreads = 1;
|
||||
|
||||
if (argc > 1)
|
||||
numberOfThreads = atoi(argv[1]);
|
||||
|
||||
NS_SetupRegistry();
|
||||
|
||||
|
||||
static PRThread** threads = (PRThread**) calloc(sizeof(PRThread*), numberOfThreads);
|
||||
static PRThread* aEventThread;
|
||||
|
||||
aEventThread = PR_CreateThread(PR_USER_THREAD,
|
||||
EventLoop,
|
||||
NULL,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_JOINABLE_THREAD,
|
||||
0 );
|
||||
|
||||
|
||||
PR_Sleep(PR_MillisecondsToInterval(1000));
|
||||
|
||||
PR_ASSERT(gEventQueue); // BAD BAD BAD. EVENT THREAD DID NOT CREATE QUEUE. This may be a timing issue, set the
|
||||
// sleep about longer, and try again.
|
||||
|
||||
printf("Spawn Threads:\n");
|
||||
for (int spawn = 0; spawn < numberOfThreads; spawn++)
|
||||
{
|
||||
|
||||
ArgsStruct *args = (ArgsStruct *) malloc (sizeof(ArgsStruct));
|
||||
|
||||
args->queue = gEventQueue;
|
||||
args->threadNumber = spawn;
|
||||
|
||||
threads[spawn] = PR_CreateThread(PR_USER_THREAD,
|
||||
ProxyTest,
|
||||
args,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_JOINABLE_THREAD,
|
||||
0 );
|
||||
|
||||
printf("\tThread (%d) spawned\n", spawn);
|
||||
|
||||
//PR_Sleep( PR_MillisecondsToInterval(250) );
|
||||
}
|
||||
|
||||
printf("All Threads Spawned.\n\n");
|
||||
|
||||
|
||||
printf("Wait for threads.\n");
|
||||
for (int i = 0; i < numberOfThreads; i++)
|
||||
{
|
||||
PRStatus rv;
|
||||
printf("Thread (%d) Join...\n", i);
|
||||
rv = PR_JoinThread(threads[i]);
|
||||
printf("Thread (%d) Joined. (error: %ld).\n", i, rv);
|
||||
}
|
||||
|
||||
PR_Interrupt(aEventThread);
|
||||
PR_JoinThread(aEventThread);
|
||||
|
||||
|
||||
printf("Calling Cleanup.\n");
|
||||
PR_Cleanup();
|
||||
|
||||
printf("Return zero.\n");
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user