зеркало из https://github.com/mozilla/pjs.git
NOT YET PART OF SEAMONKEY - now using types based on xpcom/src/libxpt/public/xpt_struct.h. Using nsIAllocator (which has an implementation hacked in in test/TestXPC.cpp - since the real one in xpcom/src is not being registered and used)
This commit is contained in:
Родитель
a19c44a87e
Коммит
a34a2be5a5
|
@ -31,9 +31,9 @@ REQUIRES=xpcom js
|
|||
DEFINES=-DWIN32_LEAN_AND_MEAN -DEXPORT_XPC_API
|
||||
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\xpt_cpp.obj \
|
||||
.\$(OBJDIR)\nsXPConnect.obj \
|
||||
.\$(OBJDIR)\xpcarbitrary.obj \
|
||||
.\$(OBJDIR)\xpcbogusii.obj \
|
||||
.\$(OBJDIR)\xpccontext.obj \
|
||||
.\$(OBJDIR)\xpcconvert.obj \
|
||||
.\$(OBJDIR)\xpcinvoke.obj \
|
||||
|
@ -48,11 +48,12 @@ OBJS= \
|
|||
|
||||
EXPORTS = \
|
||||
nsIXPCScriptable.h \
|
||||
nsIInterfaceInfo.h \
|
||||
nsIInterfaceInfoManager.h \
|
||||
nsIXPConnect.h \
|
||||
xpcbogusii.h \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\raptor
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\raptor -I$(PUBLIC)\libxpt
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* The nsIInterfaceInfo xpcom public declaration. */
|
||||
|
||||
#ifndef nsIInterfaceInfo_h___
|
||||
#define nsIInterfaceInfo_h___
|
||||
|
||||
// forward declaration of non-XPCOM types
|
||||
class nsXPTMethodInfo;
|
||||
class nsXPTConstant;
|
||||
|
||||
// {215DBE04-94A7-11d2-BA58-00805F8A5DD7}
|
||||
#define NS_IINTERFACEINFO_IID \
|
||||
{ 0x215dbe04, 0x94a7, 0x11d2, \
|
||||
{ 0xba, 0x58, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
|
||||
|
||||
class nsIInterfaceInfo : public nsISupports
|
||||
{
|
||||
public:
|
||||
|
||||
NS_IMETHOD GetName(char** name) = 0; // returns IAllocatator alloc'd copy
|
||||
NS_IMETHOD GetIID(nsIID** iid) = 0; // returns IAllocatator alloc'd copy
|
||||
|
||||
NS_IMETHOD GetParent(nsIInterfaceInfo** parent) = 0;
|
||||
|
||||
// these include counts of parents
|
||||
NS_IMETHOD GetMethodCount(uint16* count) = 0;
|
||||
NS_IMETHOD GetConstantCount(uint16* count) = 0;
|
||||
|
||||
// These include methods and constants of parents.
|
||||
// There do *not* make copies ***explicit bending of XPCOM rules***
|
||||
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info) = 0;
|
||||
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIInterfaceInfo_h___ */
|
|
@ -0,0 +1,54 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* The nsIInterfaceInfoManager xpcom public declaration. */
|
||||
|
||||
#ifndef nsIInterfaceInfoManager_h___
|
||||
#define nsIInterfaceInfoManager_h___
|
||||
|
||||
// This should be implemented as a Service
|
||||
|
||||
// {8B161900-BE2B-11d2-9831-006008962422}
|
||||
#define NS_IINTERFACEINFO_MANAGER_IID \
|
||||
{ 0x8b161900, 0xbe2b, 0x11d2, \
|
||||
{ 0x98, 0x31, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
|
||||
|
||||
class nsIInterfaceInfoManager : public nsISupports
|
||||
{
|
||||
public:
|
||||
|
||||
// nsIInformationInfo management services
|
||||
NS_IMETHOD GetInfoForIID(const nsIID* iid, nsIInterfaceInfo** info) = 0;
|
||||
NS_IMETHOD GetInfoForName(const char* name, nsIInterfaceInfo** info) = 0;
|
||||
|
||||
// name <-> IID mapping services
|
||||
NS_IMETHOD GetIIDForName(const char* name, nsIID** iid) = 0;
|
||||
NS_IMETHOD GetNameForIID(const nsIID* iid, char** name) = 0;
|
||||
|
||||
// XXX other methods?
|
||||
|
||||
};
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
// XXX remove this an use ServiceManager instead
|
||||
XPC_PUBLIC_API(nsIInterfaceInfoManager*)
|
||||
XPT_GetInterfaceInfoManager();
|
||||
JS_END_EXTERN_C
|
||||
|
||||
|
||||
#endif /* nsIInterfaceInfoManager_h___ */
|
|
@ -21,7 +21,6 @@
|
|||
#ifndef nsIXPConnect_h___
|
||||
#define nsIXPConnect_h___
|
||||
|
||||
// XXX for now...
|
||||
#include "nsISupports.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
|
@ -42,9 +41,43 @@
|
|||
#define XPC_FRIEND_API(t) XPC_PUBLIC_API(t)
|
||||
#define XPC_FRIEND_DATA(t) XPC_PUBLIC_DATA(t)
|
||||
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
|
||||
// XXX break these up into separate files...
|
||||
// XXX declare them in XPIDL :)
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
// this is here just for testing...
|
||||
|
||||
// {159E36D0-991E-11d2-AC3F-00C09300144B}
|
||||
#define NS_ITESTXPC_FOO_IID \
|
||||
{ 0x159e36d0, 0x991e, 0x11d2, \
|
||||
{ 0xac, 0x3f, 0x0, 0xc0, 0x93, 0x0, 0x14, 0x4b } }
|
||||
|
||||
class nsITestXPCFoo : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD Test(int p1, int p2, int* retval) = 0;
|
||||
NS_IMETHOD Test2() = 0;
|
||||
};
|
||||
|
||||
// {5F9D20C0-9B6B-11d2-9FFE-000064657374}
|
||||
#define NS_ITESTXPC_FOO2_IID \
|
||||
{ 0x5f9d20c0, 0x9b6b, 0x11d2, \
|
||||
{ 0x9f, 0xfe, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
class nsITestXPCFoo2 : public nsITestXPCFoo
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
// forward declarations...
|
||||
class nsIXPCScriptable;
|
||||
|
@ -100,34 +133,6 @@ public:
|
|||
NS_IMETHOD GetIID(nsIID** iid) = 0; // returns IAllocatator alloc'd copy
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
// forward declarations of 2 non-XPCOM classes...
|
||||
class nsXPCMethodInfo;
|
||||
class nsXPCConstant;
|
||||
|
||||
// {215DBE04-94A7-11d2-BA58-00805F8A5DD7}
|
||||
#define NS_IINTERFACEINFO_IID \
|
||||
{ 0x215dbe04, 0x94a7, 0x11d2, \
|
||||
{ 0xba, 0x58, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
|
||||
|
||||
class nsIInterfaceInfo : public nsISupports
|
||||
{
|
||||
public:
|
||||
// XXX should return IAllocatator alloc'd copy
|
||||
NS_IMETHOD GetName(const char** name) = 0;
|
||||
NS_IMETHOD GetIID(const nsIID** iid) = 0;
|
||||
|
||||
NS_IMETHOD GetParent(nsIInterfaceInfo** parent) = 0;
|
||||
|
||||
// these include counts of parents
|
||||
NS_IMETHOD GetMethodCount(int* count) = 0;
|
||||
NS_IMETHOD GetConstantCount(int* count) = 0;
|
||||
|
||||
// these include methods and constants of parents
|
||||
NS_IMETHOD GetMethodInfo(unsigned index, const nsXPCMethodInfo** info) = 0;
|
||||
NS_IMETHOD GetConstant(unsigned index, const nsXPCConstant** constant) = 0;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
// {EFAE37B0-946D-11d2-BA58-00805F8A5DD7}
|
||||
#define NS_IXPCONNECT_IID \
|
||||
|
@ -141,9 +146,6 @@ public:
|
|||
NS_IMETHOD InitJSContext(JSContext* aJSContext,
|
||||
JSObject* aGlobalJSObj) = 0;
|
||||
|
||||
NS_IMETHOD GetInterfaceInfo(REFNSIID aIID,
|
||||
nsIInterfaceInfo** info) = 0;
|
||||
|
||||
NS_IMETHOD WrapNative(JSContext* aJSContext,
|
||||
nsISupports* aCOMObj,
|
||||
REFNSIID aIID,
|
||||
|
@ -163,18 +165,19 @@ public:
|
|||
};
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
// XXX remove this an use ServiceManager instead
|
||||
XPC_PUBLIC_API(nsIXPConnect*)
|
||||
XPC_GetXPConnect();
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#ifdef DEBUG
|
||||
JS_BEGIN_EXTERN_C
|
||||
// XXX temporary forward declaration
|
||||
struct nsXPCVariant;
|
||||
XPC_PUBLIC_API(nsresult)
|
||||
XPC_TestInvoke(void* that, PRUint32 index,
|
||||
uint32 paramCount, nsXPCVariant* params);
|
||||
JS_END_EXTERN_C
|
||||
#endif
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* nsIXPConnect_h___ */
|
||||
|
|
|
@ -44,13 +44,18 @@ nsXPConnect::GetXPConnect()
|
|||
mSelf = new nsXPConnect();
|
||||
if(mSelf && (!mSelf->mContextMap ||
|
||||
!mSelf->mAllocator ||
|
||||
!mSelf->mArbitraryScriptable))
|
||||
!mSelf->mArbitraryScriptable ||
|
||||
!mSelf->mInterfaceInfoManager))
|
||||
NS_RELEASE(mSelf);
|
||||
}
|
||||
return mSelf;
|
||||
}
|
||||
|
||||
nsXPConnect::nsXPConnect()
|
||||
: mContextMap(NULL),
|
||||
mAllocator(NULL),
|
||||
mArbitraryScriptable(NULL),
|
||||
mInterfaceInfoManager(NULL)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
|
@ -60,6 +65,9 @@ nsXPConnect::nsXPConnect()
|
|||
nsServiceManager::GetService(kAllocatorCID,
|
||||
kIAllocatorIID,
|
||||
(nsISupports **)&mAllocator);
|
||||
|
||||
// XXX later this will be a service
|
||||
mInterfaceInfoManager = XPT_GetInterfaceInfoManager();
|
||||
}
|
||||
|
||||
nsXPConnect::~nsXPConnect()
|
||||
|
@ -70,6 +78,9 @@ nsXPConnect::~nsXPConnect()
|
|||
nsServiceManager::ReleaseService(kAllocatorCID, mAllocator);
|
||||
if(mArbitraryScriptable)
|
||||
NS_RELEASE(mArbitraryScriptable);
|
||||
// XXX later this will be a service
|
||||
if(mInterfaceInfoManager)
|
||||
NS_RELEASE(mInterfaceInfoManager);
|
||||
|
||||
mSelf = NULL;
|
||||
}
|
||||
|
@ -116,18 +127,6 @@ nsXPConnect::NewContext(JSContext* cx, JSObject* global)
|
|||
return xpcc;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPConnect::GetInterfaceInfo(REFNSIID aIID,
|
||||
nsIInterfaceInfo** info)
|
||||
{
|
||||
NS_PRECONDITION(info,"bad param");
|
||||
// XXX implement...FOR REAL...
|
||||
|
||||
*info = new nsInterfaceInfo(aIID, "HARDCODED_INTERFACE_NAME", NULL);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPConnect::WrapNative(JSContext* aJSContext,
|
||||
nsISupports* aCOMObj,
|
||||
|
|
|
@ -1,10 +1,140 @@
|
|||
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "jsapi.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "xpcbogusii.h"
|
||||
|
||||
// XXX this should not be necessary, but the nsIAllocator service is not being
|
||||
// started right now.
|
||||
#include "nsAllocator.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
// copying in the contents of nsAllocator.cpp as a test...
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
|
||||
|
||||
nsAllocator::nsAllocator(nsISupports* outer)
|
||||
{
|
||||
NS_INIT_AGGREGATED(outer);
|
||||
}
|
||||
|
||||
nsAllocator::~nsAllocator(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_AGGREGATED(nsAllocator);
|
||||
|
||||
NS_METHOD
|
||||
nsAllocator::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIAllocatorIID) ||
|
||||
aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAllocator::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
||||
{
|
||||
if (outer && !aIID.Equals(kISupportsIID))
|
||||
return NS_NOINTERFACE; // XXX right error?
|
||||
nsAllocator* mm = new nsAllocator(outer);
|
||||
if (mm == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
mm->AddRef();
|
||||
if (aIID.Equals(kISupportsIID))
|
||||
*aInstancePtr = mm->GetInner();
|
||||
else
|
||||
*aInstancePtr = mm;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_METHOD_(void*)
|
||||
nsAllocator::Alloc(PRUint32 size)
|
||||
{
|
||||
return PR_Malloc(size);
|
||||
}
|
||||
|
||||
NS_METHOD_(void*)
|
||||
nsAllocator::Realloc(void* ptr, PRUint32 size)
|
||||
{
|
||||
return PR_Realloc(ptr, size);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAllocator::Free(void* ptr)
|
||||
{
|
||||
PR_Free(ptr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAllocator::HeapMinimize(void)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
// This used to live in the memory allocators no Mac, but does no more
|
||||
// Needs to be hooked up in the new world.
|
||||
// CallCacheFlushers(0x7fffffff);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsAllocatorFactory::nsAllocatorFactory(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
}
|
||||
|
||||
nsAllocatorFactory::~nsAllocatorFactory(void)
|
||||
{
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS(nsAllocatorFactory, kIFactoryIID);
|
||||
|
||||
NS_METHOD
|
||||
nsAllocatorFactory::CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult)
|
||||
{
|
||||
return nsAllocator::Create(aOuter, aIID, aResult);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAllocatorFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK; // XXX what?
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
static void RegAllocator()
|
||||
{
|
||||
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
||||
nsRepository::RegisterFactory(kAllocatorCID,
|
||||
(nsIFactory*)new nsAllocatorFactory(),
|
||||
PR_FALSE);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
class MyScriptable : public nsIXPCScriptable
|
||||
|
@ -49,28 +179,6 @@ MyScriptable::DefaultValue(JSContext *cx, JSObject *obj,
|
|||
|
||||
|
||||
/***************************************************************************/
|
||||
// {159E36D0-991E-11d2-AC3F-00C09300144B}
|
||||
#define NS_ITESTXPC_FOO_IID \
|
||||
{ 0x159e36d0, 0x991e, 0x11d2, \
|
||||
{ 0xac, 0x3f, 0x0, 0xc0, 0x93, 0x0, 0x14, 0x4b } }
|
||||
|
||||
class nsITestXPCFoo : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD Test(int p1, int p2, int* retval) = 0;
|
||||
NS_IMETHOD Test2() = 0;
|
||||
};
|
||||
|
||||
// {5F9D20C0-9B6B-11d2-9FFE-000064657374}
|
||||
#define NS_ITESTXPC_FOO2_IID \
|
||||
{ 0x5f9d20c0, 0x9b6b, 0x11d2, \
|
||||
{ 0x9f, 0xfe, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
class nsITestXPCFoo2 : public nsITestXPCFoo
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
|
||||
class nsTestXPCFoo : public nsITestXPCFoo2
|
||||
{
|
||||
|
@ -181,6 +289,8 @@ int main()
|
|||
|
||||
gOutFile = stdout;
|
||||
|
||||
RegAllocator();
|
||||
|
||||
rt = JS_NewRuntime(8L * 1024L * 1024L);
|
||||
if (!rt)
|
||||
return 1;
|
||||
|
|
|
@ -27,7 +27,8 @@ LCFLAGS=-DUSE_NSREG
|
|||
|
||||
REQUIRES=xpcom js xpconnect
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\xpconnect -I$(PUBLIC)\raptor
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\xpconnect \
|
||||
-I$(PUBLIC)\raptor -I..\..\..\..\xpcom\src
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
|
|
|
@ -31,52 +31,52 @@
|
|||
#define JAM_DOUBLE_U64(v,d) JAM_DOUBLE(((int64)v),d)
|
||||
|
||||
JSBool
|
||||
xpc_ConvertNativeData2JS(jsval* d, const void* s, const nsXPCType& type)
|
||||
xpc_ConvertNativeData2JS(jsval* d, const void* s, const nsXPTType& type)
|
||||
{
|
||||
NS_PRECONDITION(s, "bad param");
|
||||
NS_PRECONDITION(d, "bad param");
|
||||
|
||||
jsdouble dbl;
|
||||
|
||||
switch(type & nsXPCType::TYPE_MASK)
|
||||
switch(type.TagPart())
|
||||
{
|
||||
case nsXPCType::T_I8 : *d = INT_TO_JSVAL((int32)*((int8*)s)); break;
|
||||
case nsXPCType::T_I16 : *d = INT_TO_JSVAL((int32)*((int16*)s)); break;
|
||||
case nsXPCType::T_I32 : *d = FIT_32(*((int32*)s),dbl); break;
|
||||
case nsXPCType::T_I64 : *d = JAM_DOUBLE(*((int64*)s),dbl); break;
|
||||
case nsXPCType::T_U8 : *d = INT_TO_JSVAL((int32)*((uint8*)s)); break;
|
||||
case nsXPCType::T_U16 : *d = INT_TO_JSVAL((int32)*((uint16*)s)); break;
|
||||
case nsXPCType::T_U32 : *d = FIT_32(*((uint32*)s),dbl); break;
|
||||
case nsXPCType::T_U64 : *d = JAM_DOUBLE_U64(*((uint64*)s),dbl); break;
|
||||
case nsXPCType::T_FLOAT : *d = JAM_DOUBLE(*((float*)s),dbl); break;
|
||||
case nsXPCType::T_DOUBLE: *d = DOUBLE_TO_JSVAL(*((double*)s)); break;
|
||||
case nsXPCType::T_BOOL : *d = *((PRBool*)s)?JSVAL_TRUE:JSVAL_FALSE; break;
|
||||
case nsXPCType::T_CHAR : *d = INT_TO_JSVAL((int32)*((char*)s)); break;
|
||||
case nsXPCType::T_WCHAR : *d = INT_TO_JSVAL((int32)*((wchar_t*)s)); break;
|
||||
case nsXPTType::T_I8 : *d = INT_TO_JSVAL((int32)*((int8*)s)); break;
|
||||
case nsXPTType::T_I16 : *d = INT_TO_JSVAL((int32)*((int16*)s)); break;
|
||||
case nsXPTType::T_I32 : *d = FIT_32(*((int32*)s),dbl); break;
|
||||
case nsXPTType::T_I64 : *d = JAM_DOUBLE(*((int64*)s),dbl); break;
|
||||
case nsXPTType::T_U8 : *d = INT_TO_JSVAL((int32)*((uint8*)s)); break;
|
||||
case nsXPTType::T_U16 : *d = INT_TO_JSVAL((int32)*((uint16*)s)); break;
|
||||
case nsXPTType::T_U32 : *d = FIT_32(*((uint32*)s),dbl); break;
|
||||
case nsXPTType::T_U64 : *d = JAM_DOUBLE_U64(*((uint64*)s),dbl); break;
|
||||
case nsXPTType::T_FLOAT : *d = JAM_DOUBLE(*((float*)s),dbl); break;
|
||||
case nsXPTType::T_DOUBLE: *d = DOUBLE_TO_JSVAL(*((double*)s)); break;
|
||||
case nsXPTType::T_BOOL : *d = *((PRBool*)s)?JSVAL_TRUE:JSVAL_FALSE; break;
|
||||
case nsXPTType::T_CHAR : *d = INT_TO_JSVAL((int32)*((char*)s)); break;
|
||||
case nsXPTType::T_WCHAR : *d = INT_TO_JSVAL((int32)*((wchar_t*)s)); break;
|
||||
default:
|
||||
switch(type)
|
||||
{
|
||||
case nsXPCType::T_P_VOID:
|
||||
case nsXPTType::T_P_VOID:
|
||||
// XXX implement void*
|
||||
NS_ASSERTION(0,"void* params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_P_IID:
|
||||
case nsXPTType::T_P_IID:
|
||||
// XXX implement IID
|
||||
NS_ASSERTION(0,"iid params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_BSTR:
|
||||
case nsXPTType::T_BSTR:
|
||||
// XXX implement BSTR
|
||||
NS_ASSERTION(0,"string params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_P_CHAR_STR:
|
||||
case nsXPTType::T_P_CHAR_STR:
|
||||
// XXX implement CHAR_STR
|
||||
NS_ASSERTION(0,"string params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_P_WCHAR_STR:
|
||||
case nsXPTType::T_P_WCHAR_STR:
|
||||
// XXX implement WCHAR_STR
|
||||
NS_ASSERTION(0,"string params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_INTERFACE:
|
||||
case nsXPTType::T_INTERFACE:
|
||||
// XXX implement INTERFACE
|
||||
// make sure 'src' is an object
|
||||
// get the nsIInterfaceInfo* from the param and
|
||||
|
@ -84,7 +84,7 @@ xpc_ConvertNativeData2JS(jsval* d, const void* s, const nsXPCType& type)
|
|||
// XXX remember to release the wrapper in cleanup below
|
||||
NS_ASSERTION(0,"interface params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_INTERFACE_IS:
|
||||
case nsXPTType::T_INTERFACE_IS:
|
||||
// XXX implement INTERFACE_IS
|
||||
NS_ASSERTION(0,"interface_is params not supported");
|
||||
return JS_FALSE;
|
||||
|
@ -98,7 +98,7 @@ xpc_ConvertNativeData2JS(jsval* d, const void* s, const nsXPCType& type)
|
|||
|
||||
JSBool
|
||||
xpc_ConvertJSData2Native(JSContext* cx, void* d, const jsval* s,
|
||||
const nsXPCType& type)
|
||||
const nsXPTType& type)
|
||||
{
|
||||
NS_PRECONDITION(s, "bad param");
|
||||
NS_PRECONDITION(d, "bad param");
|
||||
|
@ -108,20 +108,20 @@ xpc_ConvertJSData2Native(JSContext* cx, void* d, const jsval* s,
|
|||
jsdouble td;
|
||||
JSBool r;
|
||||
|
||||
switch(type & nsXPCType::TYPE_MASK)
|
||||
switch(type.TagPart())
|
||||
{
|
||||
case nsXPCType::T_I8 :
|
||||
case nsXPTType::T_I8 :
|
||||
r = JS_ValueToECMAInt32(cx, *s, &ti);
|
||||
*((int8*)d) = (int8) ti;
|
||||
break;
|
||||
case nsXPCType::T_I16 :
|
||||
case nsXPTType::T_I16 :
|
||||
r = JS_ValueToECMAInt32(cx, *s, &ti);
|
||||
*((int16*)d) = (int16) ti;
|
||||
break;
|
||||
case nsXPCType::T_I32 :
|
||||
case nsXPTType::T_I32 :
|
||||
r = JS_ValueToECMAInt32(cx, *s, (int32*)d);
|
||||
break;
|
||||
case nsXPCType::T_I64 :
|
||||
case nsXPTType::T_I64 :
|
||||
if(JSVAL_IS_INT(*s))
|
||||
{
|
||||
r = JS_ValueToECMAInt32(cx, *s, &ti);
|
||||
|
@ -133,18 +133,18 @@ xpc_ConvertJSData2Native(JSContext* cx, void* d, const jsval* s,
|
|||
if(r) *((int64*)d) = (int64) td;
|
||||
}
|
||||
break;
|
||||
case nsXPCType::T_U8 :
|
||||
case nsXPTType::T_U8 :
|
||||
r = JS_ValueToECMAUint32(cx, *s, &tu);
|
||||
*((uint8*)d) = (uint8) tu;
|
||||
break;
|
||||
case nsXPCType::T_U16 :
|
||||
case nsXPTType::T_U16 :
|
||||
r = JS_ValueToECMAUint32(cx, *s, &tu);
|
||||
*((uint16*)d) = (uint16) tu;
|
||||
break;
|
||||
case nsXPCType::T_U32 :
|
||||
case nsXPTType::T_U32 :
|
||||
r = JS_ValueToECMAUint32(cx, *s, (uint32*)d);
|
||||
break;
|
||||
case nsXPCType::T_U64 :
|
||||
case nsXPTType::T_U64 :
|
||||
if(JSVAL_IS_INT(*s))
|
||||
{
|
||||
r = JS_ValueToECMAUint32(cx, *s, &tu);
|
||||
|
@ -157,48 +157,48 @@ xpc_ConvertJSData2Native(JSContext* cx, void* d, const jsval* s,
|
|||
if(r) *((uint64*)d) = (uint64)((int64) td);
|
||||
}
|
||||
break;
|
||||
case nsXPCType::T_FLOAT :
|
||||
case nsXPTType::T_FLOAT :
|
||||
r = JS_ValueToNumber(cx, *s, &td);
|
||||
if(r) *((float*)d) = (float) td;
|
||||
break;
|
||||
case nsXPCType::T_DOUBLE :
|
||||
case nsXPTType::T_DOUBLE :
|
||||
r = JS_ValueToNumber(cx, *s, (double*)d);
|
||||
break;
|
||||
case nsXPCType::T_BOOL :
|
||||
case nsXPTType::T_BOOL :
|
||||
r = JS_ValueToBoolean(cx, *s, (PRBool*)d);
|
||||
break;
|
||||
case nsXPCType::T_CHAR :
|
||||
case nsXPTType::T_CHAR :
|
||||
r = JS_ValueToECMAUint32(cx, *s, &tu);
|
||||
*((char*)d) = (char) tu;
|
||||
break;
|
||||
case nsXPCType::T_WCHAR :
|
||||
case nsXPTType::T_WCHAR :
|
||||
r = JS_ValueToECMAUint32(cx, *s, &tu);
|
||||
*((uint16*)d) = (uint16) tu;
|
||||
break;
|
||||
default:
|
||||
switch(type)
|
||||
{
|
||||
case nsXPCType::T_P_VOID:
|
||||
case nsXPTType::T_P_VOID:
|
||||
// XXX implement void*
|
||||
NS_ASSERTION(0,"void* params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_P_IID:
|
||||
case nsXPTType::T_P_IID:
|
||||
// XXX implement IID
|
||||
NS_ASSERTION(0,"iid params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_BSTR:
|
||||
case nsXPTType::T_BSTR:
|
||||
// XXX implement BSTR
|
||||
NS_ASSERTION(0,"string params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_P_CHAR_STR:
|
||||
case nsXPTType::T_P_CHAR_STR:
|
||||
// XXX implement CHAR_STR
|
||||
NS_ASSERTION(0,"string params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_P_WCHAR_STR:
|
||||
case nsXPTType::T_P_WCHAR_STR:
|
||||
// XXX implement WCHAR_STR
|
||||
NS_ASSERTION(0,"string params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_INTERFACE:
|
||||
case nsXPTType::T_INTERFACE:
|
||||
// XXX implement INTERFACE
|
||||
// make sure 'src' is an object
|
||||
// get the nsIInterfaceInfo* from the param and
|
||||
|
@ -206,7 +206,7 @@ xpc_ConvertJSData2Native(JSContext* cx, void* d, const jsval* s,
|
|||
// XXX remember to release the wrapper in cleanup below
|
||||
NS_ASSERTION(0,"interface params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPCType::T_INTERFACE_IS:
|
||||
case nsXPTType::T_INTERFACE_IS:
|
||||
// XXX implement INTERFACE_IS
|
||||
NS_ASSERTION(0,"interface_is params not supported");
|
||||
return JS_FALSE;
|
||||
|
|
|
@ -37,31 +37,31 @@ invoke_count_words(uint32 paramCount, nsXPCVariant* s)
|
|||
}
|
||||
switch(s->type)
|
||||
{
|
||||
case nsXPCType::T_I8 :
|
||||
case nsXPCType::T_I16 :
|
||||
case nsXPCType::T_I32 :
|
||||
case nsXPCType::T_I64 :
|
||||
case nsXPCType::T_U8 :
|
||||
case nsXPCType::T_U16 :
|
||||
case nsXPCType::T_U32 :
|
||||
case nsXPTType::T_I8 :
|
||||
case nsXPTType::T_I16 :
|
||||
case nsXPTType::T_I32 :
|
||||
case nsXPTType::T_I64 :
|
||||
case nsXPTType::T_U8 :
|
||||
case nsXPTType::T_U16 :
|
||||
case nsXPTType::T_U32 :
|
||||
result++;
|
||||
break;
|
||||
case nsXPCType::T_U64 :
|
||||
case nsXPTType::T_U64 :
|
||||
result+=2;
|
||||
break;
|
||||
case nsXPCType::T_FLOAT :
|
||||
case nsXPTType::T_FLOAT :
|
||||
result++;
|
||||
break;
|
||||
case nsXPCType::T_DOUBLE :
|
||||
case nsXPTType::T_DOUBLE :
|
||||
result+=2;
|
||||
break;
|
||||
case nsXPCType::T_BOOL :
|
||||
case nsXPCType::T_CHAR :
|
||||
case nsXPCType::T_WCHAR :
|
||||
case nsXPTType::T_BOOL :
|
||||
case nsXPTType::T_CHAR :
|
||||
case nsXPTType::T_WCHAR :
|
||||
result++;
|
||||
break;
|
||||
default:
|
||||
NS_ASSERTION(s->type & nsXPCType::IS_POINTER, "bad type");
|
||||
NS_ASSERTION(s->type.IsPointer(), "bad type");
|
||||
result++;
|
||||
break;
|
||||
}
|
||||
|
@ -81,21 +81,21 @@ invoke_copy_to_stack(uint32* d, uint32 paramCount, nsXPCVariant* s)
|
|||
}
|
||||
switch(s->type)
|
||||
{
|
||||
case nsXPCType::T_I8 : *((int8*) d) = s->val.i8; break;
|
||||
case nsXPCType::T_I16 : *((int16*) d) = s->val.i16; break;
|
||||
case nsXPCType::T_I32 : *((int32*) d) = s->val.i32; break;
|
||||
case nsXPCType::T_I64 : *((int64*) d) = s->val.i64; d++; break;
|
||||
case nsXPCType::T_U8 : *((uint8*) d) = s->val.u8; break;
|
||||
case nsXPCType::T_U16 : *((uint16*) d) = s->val.u16; break;
|
||||
case nsXPCType::T_U32 : *((uint32*) d) = s->val.u32; break;
|
||||
case nsXPCType::T_U64 : *((uint64*) d) = s->val.u64; d++; break;
|
||||
case nsXPCType::T_FLOAT : *((float*) d) = s->val.f; break;
|
||||
case nsXPCType::T_DOUBLE : *((double*) d) = s->val.d; d++; break;
|
||||
case nsXPCType::T_BOOL : *((PRBool*) d) = s->val.b; break;
|
||||
case nsXPCType::T_CHAR : *((char*) d) = s->val.c; break;
|
||||
case nsXPCType::T_WCHAR : *((wchar_t*)d) = s->val.wc; break;
|
||||
case nsXPTType::T_I8 : *((int8*) d) = s->val.i8; break;
|
||||
case nsXPTType::T_I16 : *((int16*) d) = s->val.i16; break;
|
||||
case nsXPTType::T_I32 : *((int32*) d) = s->val.i32; break;
|
||||
case nsXPTType::T_I64 : *((int64*) d) = s->val.i64; d++; break;
|
||||
case nsXPTType::T_U8 : *((uint8*) d) = s->val.u8; break;
|
||||
case nsXPTType::T_U16 : *((uint16*) d) = s->val.u16; break;
|
||||
case nsXPTType::T_U32 : *((uint32*) d) = s->val.u32; break;
|
||||
case nsXPTType::T_U64 : *((uint64*) d) = s->val.u64; d++; break;
|
||||
case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break;
|
||||
case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break;
|
||||
case nsXPTType::T_BOOL : *((PRBool*) d) = s->val.b; break;
|
||||
case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break;
|
||||
case nsXPTType::T_WCHAR : *((wchar_t*)d) = s->val.wc; break;
|
||||
default:
|
||||
NS_ASSERTION(s->type & nsXPCType::IS_POINTER, "bad type");
|
||||
NS_ASSERTION(s->type.IsPointer(), "bad type");
|
||||
*((void**)d) = s->val.p;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -28,12 +28,14 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "jsapi.h"
|
||||
#include "jshash.h"
|
||||
#include "xpt_cpp.h"
|
||||
#include "xpcforwards.h"
|
||||
|
||||
#include "xpcbogusii.h"
|
||||
#include "xpcvariant.h"
|
||||
|
||||
extern const char* XPC_VAL_STR; // 'val' property name for out params
|
||||
|
||||
|
@ -47,9 +49,6 @@ class nsXPConnect : public nsIXPConnect
|
|||
NS_IMETHOD InitJSContext(JSContext* aJSContext,
|
||||
JSObject* aGlobalJSObj);
|
||||
|
||||
NS_IMETHOD GetInterfaceInfo(REFNSIID aIID,
|
||||
nsIInterfaceInfo** info);
|
||||
|
||||
NS_IMETHOD WrapNative(JSContext* aJSContext,
|
||||
nsISupports* aCOMObj,
|
||||
REFNSIID aIID,
|
||||
|
@ -78,6 +77,13 @@ public:
|
|||
return mAllocator;
|
||||
}
|
||||
|
||||
nsIInterfaceInfoManager* GetInterfaceInfoManager()
|
||||
{
|
||||
if(mInterfaceInfoManager)
|
||||
NS_ADDREF(mInterfaceInfoManager);
|
||||
return mInterfaceInfoManager;
|
||||
}
|
||||
|
||||
virtual ~nsXPConnect();
|
||||
private:
|
||||
nsXPConnect();
|
||||
|
@ -88,6 +94,7 @@ private:
|
|||
JSContext2XPCContextMap* mContextMap;
|
||||
nsIAllocator* mAllocator;
|
||||
nsIXPCScriptable* mArbitraryScriptable;
|
||||
nsIInterfaceInfoManager* mInterfaceInfoManager;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
@ -169,7 +176,7 @@ public:
|
|||
JSObject* GetRootJSObject(JSObject* aJSObj);
|
||||
|
||||
NS_IMETHOD CallMethod(nsXPCWrappedJS* wrapper,
|
||||
const nsXPCMethodInfo* info,
|
||||
const nsXPTMethodInfo* info,
|
||||
nsXPCMiniVariant* params);
|
||||
|
||||
~nsXPCWrappedJSClass();
|
||||
|
@ -290,7 +297,7 @@ public:
|
|||
REFNSIID aIID);
|
||||
|
||||
REFNSIID GetIID() const {return mIID;}
|
||||
const char* GetInterfaceName() const;
|
||||
const char* GetInterfaceName();
|
||||
nsIInterfaceInfo* GetInterfaceInfo() const {return mInfo;}
|
||||
XPCContext* GetXPCContext() const {return mXPCContext;}
|
||||
JSContext* GetJSContext() {return mXPCContext->GetJSContext();}
|
||||
|
@ -361,6 +368,7 @@ private:
|
|||
private:
|
||||
XPCContext* mXPCContext;
|
||||
nsIID mIID;
|
||||
char* mName;
|
||||
nsIInterfaceInfo* mInfo;
|
||||
int mMemberCount;
|
||||
XPCNativeMemberDescriptor* mMembers;
|
||||
|
@ -438,11 +446,11 @@ xpc_NewIDObject(JSContext *cx, const nsID& aID);
|
|||
|
||||
JSBool
|
||||
xpc_ConvertNativeData2JS(jsval* d, const void* s,
|
||||
const nsXPCType& type);
|
||||
const nsXPTType& type);
|
||||
|
||||
JSBool
|
||||
xpc_ConvertJSData2Native(JSContext* cx, void* d, const jsval* s,
|
||||
const nsXPCType& type);
|
||||
const nsXPTType& type);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ PrepareAndDispatch(nsXPCWrappedJS* self, uint32 methodIndex,
|
|||
nsXPCMiniVariant* dispatchParams = NULL;
|
||||
nsXPCWrappedJSClass* clazz;
|
||||
nsIInterfaceInfo* iface_info;
|
||||
const nsXPCMethodInfo* info;
|
||||
const nsXPTMethodInfo* info;
|
||||
uint8 paramCount;
|
||||
uint8 i;
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
|
@ -48,7 +48,7 @@ PrepareAndDispatch(nsXPCWrappedJS* self, uint32 methodIndex,
|
|||
iface_info = clazz->GetInterfaceInfo();
|
||||
NS_ASSERTION(iface_info,"no interface info");
|
||||
|
||||
iface_info->GetMethodInfo(methodIndex, &info);
|
||||
iface_info->GetMethodInfo(uint16(methodIndex), &info);
|
||||
NS_ASSERTION(info,"no interface info");
|
||||
|
||||
paramCount = info->GetParamCount();
|
||||
|
@ -63,11 +63,11 @@ PrepareAndDispatch(nsXPCWrappedJS* self, uint32 methodIndex,
|
|||
uint32* ap = args;
|
||||
for(i = 0; i < paramCount; i++, ap++)
|
||||
{
|
||||
const nsXPCParamInfo& param = info->GetParam(i);
|
||||
const nsXPCType& type = param.GetType();
|
||||
const nsXPTParamInfo& param = info->GetParam(i);
|
||||
const nsXPTType& type = param.GetType();
|
||||
nsXPCMiniVariant* dp = &dispatchParams[i];
|
||||
|
||||
if(param.IsOut() || (type & nsXPCType::IS_POINTER))
|
||||
if(param.IsOut() || type.IsPointer())
|
||||
{
|
||||
dp->val.p = (void*) *ap;
|
||||
continue;
|
||||
|
@ -75,19 +75,19 @@ PrepareAndDispatch(nsXPCWrappedJS* self, uint32 methodIndex,
|
|||
// else
|
||||
switch(type)
|
||||
{
|
||||
case nsXPCType::T_I8 : dp->val.i8 = *((int8*) ap); break;
|
||||
case nsXPCType::T_I16 : dp->val.i16 = *((int16*) ap); break;
|
||||
case nsXPCType::T_I32 : dp->val.i32 = *((int32*) ap); break;
|
||||
case nsXPCType::T_I64 : dp->val.i64 = *((int64*) ap); ap++; break;
|
||||
case nsXPCType::T_U8 : dp->val.u8 = *((uint8*) ap); break;
|
||||
case nsXPCType::T_U16 : dp->val.u16 = *((uint16*) ap); break;
|
||||
case nsXPCType::T_U32 : dp->val.u32 = *((uint32*) ap); break;
|
||||
case nsXPCType::T_U64 : dp->val.u64 = *((uint64*) ap); ap++; break;
|
||||
case nsXPCType::T_FLOAT : dp->val.f = *((float*) ap); break;
|
||||
case nsXPCType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break;
|
||||
case nsXPCType::T_BOOL : dp->val.b = *((PRBool*) ap); break;
|
||||
case nsXPCType::T_CHAR : dp->val.c = *((char*) ap); break;
|
||||
case nsXPCType::T_WCHAR : dp->val.wc = *((wchar_t*)ap); break;
|
||||
case nsXPTType::T_I8 : dp->val.i8 = *((int8*) ap); break;
|
||||
case nsXPTType::T_I16 : dp->val.i16 = *((int16*) ap); break;
|
||||
case nsXPTType::T_I32 : dp->val.i32 = *((int32*) ap); break;
|
||||
case nsXPTType::T_I64 : dp->val.i64 = *((int64*) ap); ap++; break;
|
||||
case nsXPTType::T_U8 : dp->val.u8 = *((uint8*) ap); break;
|
||||
case nsXPTType::T_U16 : dp->val.u16 = *((uint16*) ap); break;
|
||||
case nsXPTType::T_U32 : dp->val.u32 = *((uint32*) ap); break;
|
||||
case nsXPTType::T_U64 : dp->val.u64 = *((uint64*) ap); ap++; break;
|
||||
case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break;
|
||||
case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break;
|
||||
case nsXPTType::T_BOOL : dp->val.b = *((PRBool*) ap); break;
|
||||
case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break;
|
||||
case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*)ap); break;
|
||||
default:
|
||||
// XXX deal with other types
|
||||
NS_ASSERTION(0, "type not yet supported");
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* Variant unions used internally be XPConnect - only include locally. */
|
||||
|
||||
#ifndef xpcvariant_h___
|
||||
#define xpcvariant_h___
|
||||
|
||||
// this is used only for WrappedJS stub param repackaging
|
||||
struct nsXPCMiniVariant
|
||||
{
|
||||
// No ctors or dtors so that we can use arrays of these on the stack
|
||||
// with no penalty.
|
||||
union
|
||||
{
|
||||
int8 i8;
|
||||
int16 i16;
|
||||
int32 i32;
|
||||
int64 i64;
|
||||
uint8 u8;
|
||||
uint16 u16;
|
||||
uint32 u32;
|
||||
uint64 u64;
|
||||
float f;
|
||||
double d;
|
||||
PRBool b;
|
||||
char c;
|
||||
wchar_t wc;
|
||||
void* p;
|
||||
} val;
|
||||
};
|
||||
|
||||
struct nsXPCVariant
|
||||
{
|
||||
// No ctors or dtors so that we can use arrays of these on the stack
|
||||
// with no penalty.
|
||||
union
|
||||
{
|
||||
int8 i8;
|
||||
int16 i16;
|
||||
int32 i32;
|
||||
int64 i64;
|
||||
uint8 u8;
|
||||
uint16 u16;
|
||||
uint32 u32;
|
||||
uint64 u64;
|
||||
float f;
|
||||
double d;
|
||||
PRBool b;
|
||||
char c;
|
||||
wchar_t wc;
|
||||
void* p;
|
||||
nsID id;
|
||||
|
||||
} val;
|
||||
void* ptr;
|
||||
void* ptr2;
|
||||
nsXPTType type;
|
||||
uint8 flags;
|
||||
|
||||
enum
|
||||
{
|
||||
PTR_IS_DATA = 0x1, // used for OUT params, ptr points to data in val
|
||||
VAL_IS_OWNED = 0x2 // val.p holds an alloced ptr that must be freed
|
||||
};
|
||||
|
||||
JSBool IsPtrData() const {return (JSBool) (flags & PTR_IS_DATA);}
|
||||
JSBool IsValOwned() const {return (JSBool) (flags & VAL_IS_OWNED);}
|
||||
};
|
||||
|
||||
#endif /* xpcvariant_h___ */
|
|
@ -46,12 +46,21 @@ nsXPCWrappedJSClass::GetNewOrUsedClass(XPCContext* xpcc,
|
|||
}
|
||||
else
|
||||
{
|
||||
nsIInterfaceInfo* info;
|
||||
nsXPConnect* xpc;
|
||||
if((xpc = nsXPConnect::GetXPConnect()) != NULL &&
|
||||
NS_SUCCEEDED(xpc->GetInterfaceInfo(aIID, &info)))
|
||||
if((xpc = nsXPConnect::GetXPConnect()) != NULL)
|
||||
{
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if((iimgr = xpc->GetInterfaceInfoManager()) != NULL)
|
||||
{
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
clazz = new nsXPCWrappedJSClass(xpcc, aIID, info);
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
}
|
||||
NS_RELEASE(xpc);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
|
@ -220,7 +229,7 @@ nsXPCWrappedJSClass::GetRootJSObject(JSObject* aJSObj)
|
|||
|
||||
NS_IMETHODIMP
|
||||
nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper,
|
||||
const nsXPCMethodInfo* info,
|
||||
const nsXPTMethodInfo* info,
|
||||
nsXPCMiniVariant* params)
|
||||
{
|
||||
#define ARGS_BUFFER_COUNT 32
|
||||
|
@ -257,8 +266,8 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper,
|
|||
// build the args
|
||||
for(i = 0; i < argc; i++)
|
||||
{
|
||||
const nsXPCParamInfo& param = info->GetParam(i);
|
||||
const nsXPCType& type = param.GetType();
|
||||
const nsXPTParamInfo& param = info->GetParam(i);
|
||||
const nsXPTType& type = param.GetType();
|
||||
|
||||
jsval val;
|
||||
|
||||
|
@ -271,7 +280,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper,
|
|||
else
|
||||
pv = ¶ms[i];
|
||||
|
||||
if(type & nsXPCType::IS_POINTER)
|
||||
if(type.IsPointer())
|
||||
pv = (nsXPCMiniVariant*) pv->val.p;
|
||||
|
||||
if(!xpc_ConvertNativeData2JS(&val, &pv->val, type))
|
||||
|
@ -312,12 +321,12 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper,
|
|||
// NOTE: this is the total number of native params, not just the args
|
||||
for(i = 0; i < paramCount; i++)
|
||||
{
|
||||
const nsXPCParamInfo& param = info->GetParam(i);
|
||||
const nsXPTParamInfo& param = info->GetParam(i);
|
||||
|
||||
if(param.IsOut())
|
||||
{
|
||||
jsval val;
|
||||
const nsXPCType& type = param.GetType();
|
||||
const nsXPTType& type = param.GetType();
|
||||
nsXPCMiniVariant* pv;
|
||||
|
||||
if(param.IsRetval())
|
||||
|
@ -326,7 +335,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper,
|
|||
goto done;
|
||||
|
||||
pv = (nsXPCMiniVariant*) params[i].val.p;
|
||||
if(type & nsXPCType::IS_POINTER)
|
||||
if(type.IsPointer())
|
||||
pv = (nsXPCMiniVariant*) pv->val.p;
|
||||
|
||||
if(!xpc_ConvertJSData2Native(cx, &pv->val, &val, type))
|
||||
|
|
|
@ -46,17 +46,23 @@ nsXPCWrappedNativeClass::GetNewOrUsedClass(XPCContext* xpcc,
|
|||
}
|
||||
else
|
||||
{
|
||||
nsIInterfaceInfo* info;
|
||||
nsXPConnect* xpc;
|
||||
if((xpc = nsXPConnect::GetXPConnect()) != NULL &&
|
||||
NS_SUCCEEDED(xpc->GetInterfaceInfo(aIID, &info)))
|
||||
if((xpc = nsXPConnect::GetXPConnect()) != NULL)
|
||||
{
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if((iimgr = xpc->GetInterfaceInfoManager()) != NULL)
|
||||
{
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
clazz = new nsXPCWrappedNativeClass(xpcc, aIID, info);
|
||||
if(-1 == clazz->mMemberCount) // -1 means 'failed to init'
|
||||
{
|
||||
NS_RELEASE(clazz);
|
||||
clazz = NULL;
|
||||
NS_RELEASE(clazz); // NULLs out 'clazz'
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
}
|
||||
NS_RELEASE(xpc);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
|
@ -66,6 +72,7 @@ nsXPCWrappedNativeClass::nsXPCWrappedNativeClass(XPCContext* xpcc, REFNSIID aIID
|
|||
nsIInterfaceInfo* aInfo)
|
||||
: mXPCContext(xpcc),
|
||||
mIID(aIID),
|
||||
mName(NULL),
|
||||
mInfo(aInfo),
|
||||
mMemberCount(-1),
|
||||
mMembers(NULL)
|
||||
|
@ -84,6 +91,20 @@ nsXPCWrappedNativeClass::~nsXPCWrappedNativeClass()
|
|||
{
|
||||
mXPCContext->GetWrappedNativeClassMap()->Remove(this);
|
||||
DestroyMemberDescriptors();
|
||||
if(mName)
|
||||
{
|
||||
nsXPConnect* xpc;
|
||||
if((xpc = nsXPConnect::GetXPConnect()) != NULL)
|
||||
{
|
||||
nsIAllocator* al;
|
||||
if((al = xpc->GetAllocator()) != NULL)
|
||||
{
|
||||
al->Free(mName);
|
||||
NS_RELEASE(al);
|
||||
}
|
||||
NS_RELEASE(xpc);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(mInfo);
|
||||
}
|
||||
|
||||
|
@ -91,9 +112,9 @@ JSBool
|
|||
nsXPCWrappedNativeClass::BuildMemberDescriptors()
|
||||
{
|
||||
int i;
|
||||
int constCount;
|
||||
int methodCount;
|
||||
int totalCount;
|
||||
uint16 constCount;
|
||||
uint16 methodCount;
|
||||
uint16 totalCount;
|
||||
JSContext* cx = GetJSContext();
|
||||
|
||||
if(NS_FAILED(mInfo->GetMethodCount(&methodCount))||
|
||||
|
@ -119,7 +140,7 @@ nsXPCWrappedNativeClass::BuildMemberDescriptors()
|
|||
jsval idval;
|
||||
jsid id;
|
||||
XPCNativeMemberDescriptor* desc;
|
||||
const nsXPCMethodInfo* info;
|
||||
const nsXPTMethodInfo* info;
|
||||
if(NS_FAILED(mInfo->GetMethodInfo(i, &info)))
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -164,7 +185,7 @@ nsXPCWrappedNativeClass::BuildMemberDescriptors()
|
|||
jsval idval;
|
||||
jsid id;
|
||||
XPCNativeMemberDescriptor* desc;
|
||||
const nsXPCConstant* constant;
|
||||
const nsXPTConstant* constant;
|
||||
if(NS_FAILED(mInfo->GetConstant(i, &constant)))
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -278,7 +299,7 @@ nsXPCWrappedNativeClass::GetMemberName(const XPCNativeMemberDescriptor* desc) co
|
|||
{
|
||||
case XPCNativeMemberDescriptor::CONSTANT:
|
||||
{
|
||||
const nsXPCConstant* constant;
|
||||
const nsXPTConstant* constant;
|
||||
if(NS_SUCCEEDED(mInfo->GetConstant(desc->index, &constant)))
|
||||
return constant->GetName();
|
||||
break;
|
||||
|
@ -287,7 +308,7 @@ nsXPCWrappedNativeClass::GetMemberName(const XPCNativeMemberDescriptor* desc) co
|
|||
case XPCNativeMemberDescriptor::ATTRIB_RO:
|
||||
case XPCNativeMemberDescriptor::ATTRIB_RW:
|
||||
{
|
||||
const nsXPCMethodInfo* info;
|
||||
const nsXPTMethodInfo* info;
|
||||
if(NS_SUCCEEDED(mInfo->GetMethodInfo(desc->index, &info)))
|
||||
return info->GetName();
|
||||
break;
|
||||
|
@ -301,11 +322,11 @@ nsXPCWrappedNativeClass::GetMemberName(const XPCNativeMemberDescriptor* desc) co
|
|||
}
|
||||
|
||||
const char*
|
||||
nsXPCWrappedNativeClass::GetInterfaceName() const
|
||||
nsXPCWrappedNativeClass::GetInterfaceName()
|
||||
{
|
||||
const char* name;
|
||||
mInfo->GetName(&name);
|
||||
return name;
|
||||
if(!mName)
|
||||
mInfo->GetName(&mName);
|
||||
return mName;
|
||||
}
|
||||
|
||||
JSBool
|
||||
|
@ -313,7 +334,7 @@ nsXPCWrappedNativeClass::GetConstantAsJSVal(nsXPCWrappedNative* wrapper,
|
|||
const XPCNativeMemberDescriptor* desc,
|
||||
jsval* vp)
|
||||
{
|
||||
const nsXPCConstant* constant;
|
||||
const nsXPTConstant* constant;
|
||||
|
||||
NS_ASSERTION(desc->category == XPCNativeMemberDescriptor::CONSTANT,"bad type");
|
||||
if(NS_FAILED(mInfo->GetConstant(desc->index, &constant)))
|
||||
|
@ -322,9 +343,15 @@ nsXPCWrappedNativeClass::GetConstantAsJSVal(nsXPCWrappedNative* wrapper,
|
|||
*vp = JSVAL_NULL;
|
||||
return JS_TRUE;
|
||||
}
|
||||
const nsXPCVariant& var = constant->GetValue();
|
||||
const nsXPCMiniVariant& mv = *constant->GetValue();
|
||||
|
||||
return xpc_ConvertNativeData2JS(vp, &var.val, var.type);
|
||||
// XXX Big Hack!
|
||||
nsXPCVariant v;
|
||||
v.flags = 0;
|
||||
v.type = constant->GetType();
|
||||
memcpy(&v.val, &mv.val, sizeof(mv.val));
|
||||
|
||||
return xpc_ConvertNativeData2JS(vp, &v.val, v.type);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -350,7 +377,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(nsXPCWrappedNative* wrapper,
|
|||
nsXPCVariant* dispatchParams = NULL;
|
||||
JSContext* cx = GetJSContext();
|
||||
uint8 i;
|
||||
const nsXPCMethodInfo* info;
|
||||
const nsXPTMethodInfo* info;
|
||||
uint8 requiredArgs;
|
||||
uint8 paramCount;
|
||||
uint8 dispatchParamsInitedCount = 0;
|
||||
|
@ -402,8 +429,8 @@ nsXPCWrappedNativeClass::CallWrappedMethod(nsXPCWrappedNative* wrapper,
|
|||
// iterate through the params doing conversions
|
||||
for(i = 0; i < paramCount; i++)
|
||||
{
|
||||
const nsXPCParamInfo& param = info->GetParam(i);
|
||||
const nsXPCType& type = param.GetType();
|
||||
const nsXPTParamInfo& param = info->GetParam(i);
|
||||
const nsXPTType& type = param.GetType();
|
||||
|
||||
nsXPCVariant* dp = &dispatchParams[i];
|
||||
dp->type = type;
|
||||
|
@ -419,7 +446,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(nsXPCWrappedNative* wrapper,
|
|||
dp->flags = nsXPCVariant::PTR_IS_DATA;
|
||||
|
||||
// XXX are there no type alignment issues here?
|
||||
if(type & nsXPCType::IS_POINTER)
|
||||
if(type.IsPointer())
|
||||
{
|
||||
dp->ptr = &dp->ptr2;
|
||||
dp->ptr2 = &dp->val;
|
||||
|
@ -449,7 +476,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(nsXPCWrappedNative* wrapper,
|
|||
}
|
||||
else
|
||||
{
|
||||
if(type & nsXPCType::IS_POINTER)
|
||||
if(type.IsPointer())
|
||||
{
|
||||
dp->ptr = &dp->val;
|
||||
dp->flags = nsXPCVariant::PTR_IS_DATA;
|
||||
|
@ -478,8 +505,8 @@ nsXPCWrappedNativeClass::CallWrappedMethod(nsXPCWrappedNative* wrapper,
|
|||
// iterate through the params to gather the results
|
||||
for(i = 0; i < paramCount; i++)
|
||||
{
|
||||
const nsXPCParamInfo& param = info->GetParam(i);
|
||||
const nsXPCType& type = param.GetType();
|
||||
const nsXPTParamInfo& param = info->GetParam(i);
|
||||
const nsXPTType& type = param.GetType();
|
||||
|
||||
nsXPCVariant* dp = &dispatchParams[i];
|
||||
if(param.IsOut())
|
||||
|
@ -520,7 +547,7 @@ done:
|
|||
continue;
|
||||
if(dp->flags & nsXPCVariant::VAL_IS_OWNED)
|
||||
delete [] p;
|
||||
else if(info->GetParam(i).GetType() == nsXPCType::T_INTERFACE)
|
||||
else if(info->GetParam(i).GetType() == nsXPTType::T_INTERFACE)
|
||||
((nsISupports*)p)->Release();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,463 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* InterfaceInfo support code - some temporary. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
// declare this in the .cpp file for now
|
||||
class InterfaceInfoImpl : public nsIInterfaceInfo
|
||||
{
|
||||
NS_DECL_ISUPPORTS;
|
||||
|
||||
NS_IMETHOD GetName(char** name); // returns IAllocatator alloc'd copy
|
||||
NS_IMETHOD GetIID(nsIID** iid); // returns IAllocatator alloc'd copy
|
||||
|
||||
NS_IMETHOD GetParent(nsIInterfaceInfo** parent);
|
||||
|
||||
// these include counts of parents
|
||||
NS_IMETHOD GetMethodCount(uint16* count);
|
||||
NS_IMETHOD GetConstantCount(uint16* count);
|
||||
|
||||
// These include methods and constants of parents.
|
||||
// There do *not* make copies ***explicit bending of XPCOM rules***
|
||||
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info);
|
||||
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
|
||||
|
||||
public:
|
||||
InterfaceInfoImpl(XPTInterfaceDirectoryEntry* entry,
|
||||
InterfaceInfoImpl* parent);
|
||||
virtual ~InterfaceInfoImpl();
|
||||
|
||||
private:
|
||||
PRBool GetAllocator(nsIAllocator** allocator);
|
||||
void ReleaseAllocator(nsIAllocator** allocator);
|
||||
|
||||
private:
|
||||
XPTInterfaceDirectoryEntry* mEntry;
|
||||
InterfaceInfoImpl* mParent;
|
||||
uint16 mMethodBaseIndex;
|
||||
uint16 mMethodCount;
|
||||
uint16 mConstantBaseIndex;
|
||||
uint16 mConstantCount;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// declare this in the .cpp file for now
|
||||
class InterfaceInfoManagerImpl : public nsIInterfaceInfoManager
|
||||
{
|
||||
NS_DECL_ISUPPORTS;
|
||||
|
||||
// nsIInformationInfo management services
|
||||
NS_IMETHOD GetInfoForIID(const nsIID* iid, nsIInterfaceInfo** info);
|
||||
NS_IMETHOD GetInfoForName(const char* name, nsIInterfaceInfo** info);
|
||||
|
||||
// name <-> IID mapping services
|
||||
NS_IMETHOD GetIIDForName(const char* name, nsIID** iid);
|
||||
NS_IMETHOD GetNameForIID(const nsIID* iid, char** name);
|
||||
|
||||
public:
|
||||
InterfaceInfoManagerImpl();
|
||||
~InterfaceInfoManagerImpl();
|
||||
private:
|
||||
PRBool BuildInterfaceForEntry(uint16 index);
|
||||
|
||||
private:
|
||||
// bogus implementation...
|
||||
InterfaceInfoImpl** mInfoArray;
|
||||
nsIAllocator* mAllocator;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
// hacked hardcoded simulation...
|
||||
|
||||
XPTParamDescriptor ResultParam[] = {
|
||||
{XPT_PD_OUT, {TD_UINT32,0}}
|
||||
};
|
||||
|
||||
XPTParamDescriptor QueryInterfaceParams[2] = {
|
||||
{XPT_PD_IN, {TD_PNSIID|XPT_TDP_POINTER|XPT_TDP_REFERENCE,0}},
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_PVOID,0}}
|
||||
};
|
||||
|
||||
XPTParamDescriptor TestParams[3] = {
|
||||
{XPT_PD_IN, {TD_INT32,0}},
|
||||
{XPT_PD_IN, {TD_INT32,0}},
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_UINT32,0}}
|
||||
};
|
||||
|
||||
XPTMethodDescriptor nsISupportsMethods[3] = {
|
||||
{0, "QueryInterface", 2, QueryInterfaceParams, ResultParam},
|
||||
{0, "AddRef", 0, NULL, ResultParam},
|
||||
{0, "Release", 0, NULL, ResultParam}
|
||||
};
|
||||
|
||||
XPTMethodDescriptor nsITestXPCFooMethods[2] = {
|
||||
{0, "Test", 3, TestParams, ResultParam},
|
||||
{0, "Test2", 0, NULL, ResultParam}
|
||||
};
|
||||
|
||||
XPTConstDescriptor nsITestXPCFooConstants[3] = {
|
||||
{"five", {TD_INT32,0}, 5},
|
||||
{"six", {TD_INT32,0}, 6},
|
||||
{"seven", {TD_INT32,0}, 7}
|
||||
};
|
||||
|
||||
XPTInterfaceDescriptor nsISupportsInterfaceDescriptor =
|
||||
{NULL, 3, nsISupportsMethods, 0, NULL};
|
||||
|
||||
XPTInterfaceDescriptor nsITestXPCFooInterfaceDescriptor =
|
||||
{NULL, 2, nsITestXPCFooMethods, 3, nsITestXPCFooConstants};
|
||||
|
||||
XPTInterfaceDirectoryEntry InterfaceDirectoryEntryTable[] = {
|
||||
{NS_ISUPPORTS_IID, "nsISupports", "", &nsISupportsInterfaceDescriptor},
|
||||
{NS_ITESTXPC_FOO_IID, "nsITestXPCFoo", "", &nsITestXPCFooInterfaceDescriptor},
|
||||
{NS_ITESTXPC_FOO2_IID, "nsITestXPCFoo2", "", &nsITestXPCFooInterfaceDescriptor}
|
||||
};
|
||||
|
||||
#define ENTRY_COUNT (sizeof(InterfaceDirectoryEntryTable)/sizeof(InterfaceDirectoryEntryTable[0]))
|
||||
#define TABLE_INDEX(p) ((p-InterfaceDirectoryEntryTable)/sizeof(InterfaceDirectoryEntryTable[0]))
|
||||
|
||||
static BogusTableInit()
|
||||
{
|
||||
nsITestXPCFooInterfaceDescriptor.parent_interface =
|
||||
&InterfaceDirectoryEntryTable[1];
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
nsIInterfaceInfo*
|
||||
nsXPTParamInfo::GetInterface() const
|
||||
{
|
||||
NS_PRECONDITION(GetType() == nsXPTType::T_INTERFACE,"not an interface");
|
||||
|
||||
// not optimal!
|
||||
nsIInterfaceInfoManager* mgr = XPT_GetInterfaceInfoManager();
|
||||
if(!mgr)
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo* info;
|
||||
mgr->GetInfoForIID(&InterfaceDirectoryEntryTable[type.type.interface].iid,
|
||||
&info);
|
||||
NS_RELEASE(mgr);
|
||||
return info;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
// VERY simple implementations...
|
||||
|
||||
NS_IMPL_ISUPPORTS(InterfaceInfoManagerImpl, NS_IINTERFACEINFO_MANAGER_IID)
|
||||
|
||||
XPC_PUBLIC_API(nsIInterfaceInfoManager*)
|
||||
XPT_GetInterfaceInfoManager()
|
||||
{
|
||||
static InterfaceInfoManagerImpl* impl = NULL;
|
||||
if(!impl)
|
||||
{
|
||||
impl = new InterfaceInfoManagerImpl();
|
||||
// XXX ought to check for properly formed impl here..
|
||||
}
|
||||
if(impl)
|
||||
NS_ADDREF(impl);
|
||||
return impl;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
||||
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
|
||||
|
||||
InterfaceInfoManagerImpl::InterfaceInfoManagerImpl()
|
||||
: mInfoArray(NULL),
|
||||
mAllocator(NULL)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
BogusTableInit();
|
||||
|
||||
mInfoArray = (InterfaceInfoImpl**) calloc(ENTRY_COUNT,sizeof(void*));
|
||||
|
||||
nsServiceManager::GetService(kAllocatorCID,
|
||||
kIAllocatorIID,
|
||||
(nsISupports **)&mAllocator);
|
||||
}
|
||||
|
||||
InterfaceInfoManagerImpl::~InterfaceInfoManagerImpl()
|
||||
{
|
||||
// let the singleton leak
|
||||
}
|
||||
|
||||
PRBool
|
||||
InterfaceInfoManagerImpl::BuildInterfaceForEntry(uint16 i)
|
||||
{
|
||||
XPTInterfaceDirectoryEntry *parent_interface =
|
||||
InterfaceDirectoryEntryTable[i].interface_descriptor->parent_interface;
|
||||
uint16 parent_index = 0;
|
||||
|
||||
if(parent_interface)
|
||||
{
|
||||
parent_index = TABLE_INDEX(parent_interface);
|
||||
if(!mInfoArray[parent_index] && ! BuildInterfaceForEntry(parent_index))
|
||||
return PR_FALSE;
|
||||
}
|
||||
mInfoArray[i] = new InterfaceInfoImpl(&InterfaceDirectoryEntryTable[i],
|
||||
parent_interface ?
|
||||
mInfoArray[parent_index] : NULL);
|
||||
return (PRBool) mInfoArray[i];
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoManagerImpl::GetInfoForIID(const nsIID* iid, nsIInterfaceInfo** info)
|
||||
{
|
||||
for(int i = 0; i < ENTRY_COUNT;i++)
|
||||
{
|
||||
XPTInterfaceDirectoryEntry* entry = &InterfaceDirectoryEntryTable[i];
|
||||
if(iid->Equals(entry->iid))
|
||||
{
|
||||
if(!mInfoArray[i] && !BuildInterfaceForEntry(i))
|
||||
break;
|
||||
*info = mInfoArray[i];
|
||||
NS_ADDREF(*info);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
*info = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoManagerImpl::GetInfoForName(const char* name, nsIInterfaceInfo** info)
|
||||
{
|
||||
for(int i = 0; i < ENTRY_COUNT;i++)
|
||||
{
|
||||
XPTInterfaceDirectoryEntry* entry = &InterfaceDirectoryEntryTable[i];
|
||||
if(!strcmp(name, entry->name))
|
||||
{
|
||||
if(!mInfoArray[i] && !BuildInterfaceForEntry(i))
|
||||
break;
|
||||
*info = mInfoArray[i];
|
||||
NS_ADDREF(*info);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
*info = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoManagerImpl::GetIIDForName(const char* name, nsIID** iid)
|
||||
{
|
||||
for(int i = 0; i < ENTRY_COUNT;i++)
|
||||
{
|
||||
XPTInterfaceDirectoryEntry* entry = &InterfaceDirectoryEntryTable[i];
|
||||
if(!strcmp(name, entry->name))
|
||||
{
|
||||
nsIID* p;
|
||||
if(!(p = (nsIID*)mAllocator->Alloc(sizeof(nsIID))))
|
||||
break;
|
||||
memcpy(p, &entry->iid, sizeof(nsIID));
|
||||
*iid = p;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
*iid = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoManagerImpl::GetNameForIID(const nsIID* iid, char** name)
|
||||
{
|
||||
for(int i = 0; i < ENTRY_COUNT;i++)
|
||||
{
|
||||
XPTInterfaceDirectoryEntry* entry = &InterfaceDirectoryEntryTable[i];
|
||||
if(iid->Equals(entry->iid))
|
||||
{
|
||||
char* p;
|
||||
int len = strlen(entry->name)+1;
|
||||
if(!(p = (char*)mAllocator->Alloc(len)))
|
||||
break;
|
||||
memcpy(p, &entry->name, len);
|
||||
*name = p;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
*name = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
NS_IMPL_ISUPPORTS(InterfaceInfoImpl, NS_IINTERFACEINFO_IID)
|
||||
|
||||
InterfaceInfoImpl::InterfaceInfoImpl(XPTInterfaceDirectoryEntry* entry,
|
||||
InterfaceInfoImpl* parent)
|
||||
: mEntry(entry),
|
||||
mParent(parent)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
if(mParent)
|
||||
NS_ADDREF(mParent);
|
||||
if(mParent)
|
||||
{
|
||||
mMethodBaseIndex = mParent->mMethodBaseIndex + mParent->mMethodCount;
|
||||
mConstantBaseIndex = mParent->mConstantBaseIndex + mParent->mConstantCount;
|
||||
}
|
||||
else
|
||||
mMethodBaseIndex = mConstantBaseIndex = 0;
|
||||
|
||||
mMethodCount = mEntry->interface_descriptor->num_methods;
|
||||
mConstantCount = mEntry->interface_descriptor->num_constants;
|
||||
}
|
||||
|
||||
InterfaceInfoImpl::~InterfaceInfoImpl()
|
||||
{
|
||||
if(mParent)
|
||||
NS_RELEASE(mParent);
|
||||
}
|
||||
|
||||
PRBool
|
||||
InterfaceInfoImpl::GetAllocator(nsIAllocator** allocator)
|
||||
{
|
||||
return NS_SUCCEEDED(nsServiceManager::GetService(kAllocatorCID,
|
||||
kIAllocatorIID,
|
||||
(nsISupports **)allocator));
|
||||
}
|
||||
void
|
||||
InterfaceInfoImpl::ReleaseAllocator(nsIAllocator** allocator)
|
||||
{
|
||||
nsServiceManager::ReleaseService(kAllocatorCID,
|
||||
(nsISupports *)*allocator, NULL);
|
||||
*allocator = NULL;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetName(char** name)
|
||||
{
|
||||
nsIAllocator* allocator;
|
||||
|
||||
NS_PRECONDITION(name, "bad param");
|
||||
if(GetAllocator(&allocator))
|
||||
{
|
||||
int len = strlen(mEntry->name)+1;
|
||||
char* p = (char*)allocator->Alloc(len);
|
||||
ReleaseAllocator(&allocator);
|
||||
if(p)
|
||||
{
|
||||
memcpy(p, &mEntry->name, len);
|
||||
*name = p;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
*name = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetIID(nsIID** iid)
|
||||
{
|
||||
nsIAllocator* allocator;
|
||||
|
||||
NS_PRECONDITION(iid, "bad param");
|
||||
if(GetAllocator(&allocator))
|
||||
{
|
||||
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
|
||||
ReleaseAllocator(&allocator);
|
||||
if(p)
|
||||
{
|
||||
memcpy(p, &mEntry->iid, sizeof(nsIID));
|
||||
*iid = p;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
*iid = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetParent(nsIInterfaceInfo** parent)
|
||||
{
|
||||
NS_PRECONDITION(parent, "bad param");
|
||||
if(mParent)
|
||||
{
|
||||
NS_ADDREF(mParent);
|
||||
*parent = mParent;
|
||||
return NS_OK;
|
||||
}
|
||||
*parent = NULL;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetMethodCount(uint16* count)
|
||||
{
|
||||
NS_PRECONDITION(count, "bad param");
|
||||
*count = mMethodBaseIndex + mMethodCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetConstantCount(uint16* count)
|
||||
{
|
||||
NS_PRECONDITION(count, "bad param");
|
||||
*count = mConstantBaseIndex + mConstantCount;
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetMethodInfo(uint16 index, const nsXPTMethodInfo** info)
|
||||
{
|
||||
NS_PRECONDITION(info, "bad param");
|
||||
if(index < mMethodBaseIndex)
|
||||
return mParent->GetMethodInfo(index, info);
|
||||
|
||||
if(index >= mMethodBaseIndex + mMethodCount)
|
||||
{
|
||||
NS_PRECONDITION(0, "bad param");
|
||||
*info = NULL;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// else...
|
||||
*info = NS_STATIC_CAST(nsXPTMethodInfo*, &mEntry->interface_descriptor->method_descriptors[index-mMethodBaseIndex]);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetConstant(uint16 index, const nsXPTConstant** constant)
|
||||
{
|
||||
NS_PRECONDITION(constant, "bad param");
|
||||
if(index < mConstantBaseIndex)
|
||||
return mParent->GetConstant(index, constant);
|
||||
|
||||
if(index >= mConstantBaseIndex + mConstantCount)
|
||||
{
|
||||
NS_PRECONDITION(0, "bad param");
|
||||
*constant = NULL;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// else...
|
||||
*constant = NS_STATIC_CAST(nsXPTConstant*,&mEntry->interface_descriptor->const_descriptors[index-mConstantBaseIndex]);
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* The InterfaceInfo support public stuff. */
|
||||
|
||||
#include "xpt_struct.h"
|
||||
|
||||
#ifndef xpt_cpp_h___
|
||||
#define xpt_cpp_h___
|
||||
|
||||
// Everything here is dependent upon - and sensitive to changes in -
|
||||
// xpcom/libxpt/xpt_struct.h!
|
||||
|
||||
class nsXPTType : public XPTTypeDescriptorPrefix
|
||||
{
|
||||
// NO DATA - this a flyweight wrapper
|
||||
public:
|
||||
nsXPTType()
|
||||
{} // random contents
|
||||
nsXPTType(const XPTTypeDescriptorPrefix& prefix)
|
||||
{*(XPTTypeDescriptorPrefix*)this = prefix;}
|
||||
|
||||
nsXPTType(const uint8& prefix)
|
||||
{*(uint8*)this = prefix;}
|
||||
|
||||
nsXPTType& operator=(uint8 val)
|
||||
{flags = val; return *this;}
|
||||
|
||||
operator uint8() const
|
||||
{return flags;}
|
||||
|
||||
JSBool IsPointer() const
|
||||
{return (JSBool) (XPT_TDP_IS_POINTER(flags));}
|
||||
|
||||
JSBool IsUniquePointer() const
|
||||
{return (JSBool) (XPT_TDP_IS_UNIQUE_POINTER(flags));}
|
||||
|
||||
JSBool IsReference() const
|
||||
{return (JSBool) (XPT_TDP_IS_REFERENCE(flags));}
|
||||
|
||||
uint8 TagPart() const
|
||||
{return (uint8) (flags & XPT_TDP_TAGMASK);}
|
||||
|
||||
enum
|
||||
{
|
||||
T_I8 = TD_INT8,
|
||||
T_I16 = TD_INT16,
|
||||
T_I32 = TD_INT32,
|
||||
T_I64 = TD_INT64,
|
||||
T_U8 = TD_UINT8,
|
||||
T_U16 = TD_UINT16,
|
||||
T_U32 = TD_UINT32,
|
||||
T_U64 = TD_UINT64,
|
||||
T_FLOAT = TD_FLOAT,
|
||||
T_DOUBLE = TD_DOUBLE,
|
||||
T_BOOL = TD_BOOL,
|
||||
T_CHAR = TD_CHAR,
|
||||
T_WCHAR = TD_WCHAR,
|
||||
T_VOID = TD_VOID,
|
||||
|
||||
T_P_I8 = XPT_TDP_POINTER | TD_PINT8,
|
||||
T_P_I16 = XPT_TDP_POINTER | TD_PINT16,
|
||||
T_P_I32 = XPT_TDP_POINTER | TD_PINT32,
|
||||
T_P_I64 = XPT_TDP_POINTER | TD_PINT64,
|
||||
T_P_U8 = XPT_TDP_POINTER | TD_PUINT8,
|
||||
T_P_U16 = XPT_TDP_POINTER | TD_PUINT16,
|
||||
T_P_U32 = XPT_TDP_POINTER | TD_PUINT32,
|
||||
T_P_U64 = XPT_TDP_POINTER | TD_PUINT64,
|
||||
T_P_FLOAT = XPT_TDP_POINTER | TD_PFLOAT,
|
||||
T_P_DOUBLE = XPT_TDP_POINTER | TD_PDOUBLE,
|
||||
T_P_BOOL = XPT_TDP_POINTER | TD_PBOOL,
|
||||
T_P_CHAR = XPT_TDP_POINTER | TD_PCHAR,
|
||||
T_P_WCHAR = XPT_TDP_POINTER | TD_PWCHAR,
|
||||
T_P_VOID = XPT_TDP_POINTER | TD_PVOID,
|
||||
T_P_IID = XPT_TDP_POINTER | TD_PNSIID,
|
||||
T_BSTR = XPT_TDP_POINTER | TD_PBSTR,
|
||||
T_P_CHAR_STR = XPT_TDP_POINTER | TD_PSTRING,
|
||||
T_P_WCHAR_STR = XPT_TDP_POINTER | TD_PWSTRING,
|
||||
|
||||
T_INTERFACE = TD_INTERFACE_TYPE,
|
||||
T_INTERFACE_IS = TD_INTERFACE_IS_TYPE
|
||||
};
|
||||
// NO DATA - this a flyweight wrapper
|
||||
};
|
||||
|
||||
class nsXPTParamInfo : public XPTParamDescriptor
|
||||
{
|
||||
// NO DATA - this a flyweight wrapper
|
||||
public:
|
||||
nsXPTParamInfo(const XPTParamDescriptor& desc)
|
||||
{*(XPTParamDescriptor*)this = desc;}
|
||||
|
||||
|
||||
JSBool IsIn() const {return (JSBool) (XPT_PD_IS_IN(flags));}
|
||||
JSBool IsOut() const {return (JSBool) (XPT_PD_IS_OUT(flags));}
|
||||
JSBool IsRetval() const {return (JSBool) (XPT_PD_IS_RETVAL(flags));}
|
||||
const nsXPTType GetType() const {return type.prefix;}
|
||||
|
||||
uint8 GetInterfaceIsArgNumber() const
|
||||
{
|
||||
NS_PRECONDITION(GetType() == nsXPTType::T_INTERFACE_IS,"not an interface_is");
|
||||
return type.type.argnum;
|
||||
}
|
||||
|
||||
// This is not inlined, it is more involved!
|
||||
// If XPTInterfaceDirectoryEntry references remain indexes, then it
|
||||
// may be necessary to pass in a param here indicating which typelib
|
||||
// - or at least XPTInterfaceDirectoryEntry - this particular param
|
||||
// is associated with so that we can find the table this index indexes
|
||||
// and then find the referenced XPTInterfaceDirectoryEntry so that we can
|
||||
// find (or build) the appropriate nsIInterfaceInfo. Simple :)
|
||||
nsIInterfaceInfo* GetInterface() const ;
|
||||
|
||||
private:
|
||||
nsXPTParamInfo(); // no implementation
|
||||
// NO DATA - this a flyweight wrapper
|
||||
};
|
||||
|
||||
class nsXPTMethodInfo : public XPTMethodDescriptor
|
||||
{
|
||||
// NO DATA - this a flyweight wrapper
|
||||
public:
|
||||
nsXPTMethodInfo(const XPTMethodDescriptor& desc)
|
||||
{*(XPTMethodDescriptor*)this = desc;}
|
||||
|
||||
JSBool IsGetter() const {return (JSBool) (XPT_MD_IS_GETTER(flags) );}
|
||||
JSBool IsSetter() const {return (JSBool) (XPT_MD_IS_SETTER(flags) );}
|
||||
JSBool IsVarArgs() const {return (JSBool) (XPT_MD_IS_VARARGS(flags));}
|
||||
JSBool IsConstructor() const {return (JSBool) (XPT_MD_IS_CTOR(flags) );}
|
||||
JSBool IsHidden() const {return (JSBool) (XPT_MD_IS_HIDDEN(flags) );}
|
||||
const char* GetName() const {return name;}
|
||||
uint8 GetParamCount() const {return num_args;}
|
||||
const nsXPTParamInfo GetParam(uint8 index) const
|
||||
{
|
||||
NS_PRECONDITION(index < GetParamCount(),"bad arg");
|
||||
return params[index];
|
||||
}
|
||||
const nsXPTParamInfo GetResult() const
|
||||
{return *result;}
|
||||
private:
|
||||
nsXPTMethodInfo(); // no implementation
|
||||
// NO DATA - this a flyweight wrapper
|
||||
};
|
||||
|
||||
|
||||
// forward declaration
|
||||
struct nsXPCMiniVariant;
|
||||
|
||||
class nsXPTConstant : public XPTConstDescriptor
|
||||
{
|
||||
// NO DATA - this a flyweight wrapper
|
||||
public:
|
||||
nsXPTConstant(const XPTConstDescriptor& desc)
|
||||
{*(XPTConstDescriptor*)this = desc;}
|
||||
|
||||
const char* GetName() const
|
||||
{return name;}
|
||||
|
||||
const nsXPTType GetType() const
|
||||
{return type.prefix;}
|
||||
|
||||
// XXX this is ugly
|
||||
const nsXPCMiniVariant* GetValue() const
|
||||
{return (nsXPCMiniVariant*) &value;}
|
||||
private:
|
||||
nsXPTConstant(); // no implementation
|
||||
// NO DATA - this a flyweight wrapper
|
||||
};
|
||||
|
||||
#endif /* xpt_cpp_h___ */
|
Загрузка…
Ссылка в новой задаче