Not yet part of the seamonkey build.

Moved nsInterfaceInfoManager files from the libxpt directory (where
they would have precipitated an unpleasant circular dependency between
xpidl and nsISupports.h) into a new subdirectory.

Added corresponding entries to allmakefiles.sh.

nsInterfaceInfoManager is intended to abstract the loading and
management of typelib information generated by xpidl, for use by
xpconnect.
This commit is contained in:
mccabe%netscape.com 1999-03-02 05:21:31 +00:00
Родитель ffe910ebcb
Коммит 5f572e6d7e
62 изменённых файлов: 2571 добавлений и 69 удалений

Просмотреть файл

@ -123,7 +123,7 @@ js/src/Makefile
js/src/fdlibm/Makefile
js/src/liveconnect/Makefile
js/src/liveconnect/classes/Makefile
js/src/xpcom/Makefile
# js/src/xpcom/Makefile
js/src/xpconnect/Makefile
layout/Makefile
layout/base/Makefile
@ -292,6 +292,10 @@ xpcom/libxpt/public/Makefile
xpcom/libxpt/src/Makefile
xpcom/libxpt/tests/Makefile
xpcom/libxpt/tools/Makefile
xpcom/libxpt/xptinfo/Makefile
xpcom/libxpt/xptinfo/public/Makefile
xpcom/libxpt/xptinfo/src/Makefile
xpcom/libxpt/xptinfo/tests/Makefile
xpcom/idl/Makefile
silentdl/Makefile
xpfe/Makefile

Просмотреть файл

@ -27,4 +27,6 @@ DIRS += tests
DIRS += tools
DIRS += xptinfo
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -1,35 +0,0 @@
#!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 = libxpt
EXPORTS = xpt_struct.h \
xpt_xdr.h \
xpt_cpp.h \
nsIInterfaceInfoManager.h \
nsIInterfaceInfo.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -28,12 +28,7 @@ CSRCS = xpt_struct.c \
xpt_xdr.c \
$(NULL)
CPPSRCS = nsInterfaceInfo.cpp \
nsInterfaceInfoManager.cpp \
nsXPTParamInfo.cpp \
$(NULL)
REQUIRES = $(MODULE) xpcom
REQUIRES = $(MODULE)
export:: libs

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -23,19 +23,13 @@ include $(DEPTH)/config/autoconf.mk
MODULE = libxpt
SIMPLE_PROGRAMS = PrimitiveTest SimpleTypeLib TestInterfaceInfo
SIMPLE_PROGRAMS = PrimitiveTest SimpleTypeLib
CSRCS = PrimitiveTest.c SimpleTypeLib.c
CPPSRCS = \
TestInterfaceInfo.cpp \
$(NULL)
LDFLAGS = \
-L$(DIST)/bin \
-lxpt \
-lxpcom \
-lreg \
$(NSPR_LIBS) \
$(NULL)

Просмотреть файл

Просмотреть файл

@ -30,8 +30,6 @@ CSRCS = xpt_dump.c xpt_link.c
LDFLAGS = \
-L$(DIST)/bin \
-lxpt \
-lxpcom \
-lreg \
$(NSPR_LIBS) \
$(NULL)

Просмотреть файл

@ -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) 1999 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

Просмотреть файл

@ -0,0 +1,33 @@
#!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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xptinfo
EXPORTS = xpt_cpp.h \
nsIInterfaceInfoManager.h \
nsIInterfaceInfo.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
DEPTH=..\..\..\..
EXPORTS = nsIInterfaceInfoManager.h \
nsIInterfaceInfo.h \
xpt_cpp.h \
$(NULL)
MODULE = xptinfo
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,55 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* The nsIInterfaceInfo xpcom public declaration. */
#ifndef nsIInterfaceInfo_h___
#define nsIInterfaceInfo_h___
#include "nsISupports.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_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERFACEINFO_IID)
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,63 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* The nsIInterfaceInfoManager xpcom public declaration. */
#ifndef nsIInterfaceInfoManager_h___
#define nsIInterfaceInfoManager_h___
#include "nsIInterfaceInfo.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:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERFACEINFO_MANAGER_IID)
// 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
// NOTE: these return IAllocatator alloc'd copies of the data
NS_IMETHOD GetIIDForName(const char* name, nsIID** iid) = 0;
NS_IMETHOD GetNameForIID(const nsIID* iid, char** name) = 0;
// XXX other methods?
};
// this is just for XPT_PUBLIC_API...
// should be removed with below.
#include "xpt_struct.h"
PR_BEGIN_EXTERN_C
// XXX remove this and use ServiceManager instead
XPT_PUBLIC_API(nsIInterfaceInfoManager*)
XPT_GetInterfaceInfoManager();
PR_END_EXTERN_C
#endif /* nsIInterfaceInfoManager_h___ */

Просмотреть файл

@ -0,0 +1,179 @@
/* -*- 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. */
#ifndef xpt_cpp_h___
#define xpt_cpp_h___
#include "xpt_struct.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;}
PRBool IsPointer() const
{return (PRBool) (XPT_TDP_IS_POINTER(flags));}
PRBool IsUniquePointer() const
{return (PRBool) (XPT_TDP_IS_UNIQUE_POINTER(flags));}
PRBool IsReference() const
{return (PRBool) (XPT_TDP_IS_REFERENCE(flags));}
PRBool IsArithmetic() const // terminology from Harbison/Steele
{return flags <= T_WCHAR;}
PRBool IsInterfacePointer() const
{return (PRBool) (TagPart() == T_INTERFACE ||
TagPart() == T_INTERFACE_IS);}
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_IID = TD_PNSIID ,
T_BSTR = TD_PBSTR ,
T_CHAR_STR = TD_PSTRING ,
T_WCHAR_STR = 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;}
PRBool IsIn() const {return (PRBool) (XPT_PD_IS_IN(flags));}
PRBool IsOut() const {return (PRBool) (XPT_PD_IS_OUT(flags));}
PRBool IsRetval() const {return (PRBool) (XPT_PD_IS_RETVAL(flags));}
const nsXPTType GetType() const {return type.prefix;}
uint8 GetInterfaceIsArgNumber() const
{
NS_PRECONDITION(GetType().TagPart() == 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 ;
// a *little* simpler than the above
const nsIID* GetInterfaceIID() 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;}
PRBool IsGetter() const {return (PRBool) (XPT_MD_IS_GETTER(flags) );}
PRBool IsSetter() const {return (PRBool) (XPT_MD_IS_SETTER(flags) );}
PRBool IsVarArgs() const {return (PRBool) (XPT_MD_IS_VARARGS(flags));}
PRBool IsConstructor() const {return (PRBool) (XPT_MD_IS_CTOR(flags) );}
PRBool IsHidden() const {return (PRBool) (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___ */

Просмотреть файл

@ -0,0 +1,38 @@
#!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 = xptinfo
LIBRARY_NAME = xptinfo
CSRCS = $(NULL)
CPPSRCS = nsInterfaceInfo.cpp \
nsInterfaceInfoManager.cpp \
nsXPTParamInfo.cpp \
$(NULL)
REQUIRES = $(MODULE)
export:: libs
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,63 @@
#!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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
DEPTH=..\..\..\..
LIBNAME = .\$(OBJDIR)\xptinfo$(MOZ_BITS)
DLL = $(LIBNAME).dll
LCFLAGS = -DEXPORT_XPT_API -DWIN32_LEAN_AND_MEAN
LINCS = \
-I$(PUBLIC)\libxpt \
-I$(PUBLIC)\xptinfo \
$(NULL)
LLIBS = \
$(LIBNSPR) \
$(DIST)\lib\libxpt.lib \
$(NULL)
CSRCS = \
$(NULL)
C_OBJS = \
$(NULL)
CPPSRCS = nsInterfaceInfoManager.cpp \
nsInterfaceInfo.cpp \
nsXPTParamInfo.cpp \
$(NULL)
CPP_OBJS = \
.\$(OBJDIR)\nsInterfaceInfoManager.obj \
.\$(OBJDIR)\nsInterfaceInfo.obj \
.\$(OBJDIR)\nsXPTParamInfo.obj \
$(NULL)
MODULE = xptinfo
include <$(DEPTH)\config\rules.mak>
libs:: $(DLL)
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib

Просмотреть файл

@ -0,0 +1,176 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIAllocator.h"
#include "nsInterfaceInfo.h"
#include "nsInterfaceInfoManager.h"
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
nsInterfaceInfo *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;
}
nsInterfaceInfo::~nsInterfaceInfo()
{
if(mParent)
NS_RELEASE(mParent);
}
NS_IMETHODIMP
nsInterfaceInfo::GetName(char** name)
{
NS_PRECONDITION(name, "bad param");
// nsIAllocator* allocator;
// if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
int len = strlen(mEntry->name)+1;
// char* p = (char*)allocator->Alloc(len);
// XXX malloc for now.
char *p = (char *)malloc(len);
// NS_RELEASE(allocator);
if(p) {
memcpy(p, mEntry->name, len);
*name = p;
return NS_OK;
}
// }
*name = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfo::GetIID(nsIID** iid)
{
NS_PRECONDITION(iid, "bad param");
// nsIAllocator* allocator;
// if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
// nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
// NS_RELEASE(allocator);
// XXX malloc for now.
nsIID* p = (nsIID*)malloc(sizeof(nsIID));
if(p) {
memcpy(p, &mEntry->iid, sizeof(nsIID));
*iid = p;
return NS_OK;
}
// }
*iid = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfo::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
nsInterfaceInfo::GetMethodCount(uint16* count)
{
NS_PRECONDITION(count, "bad param");
*count = mMethodBaseIndex + mMethodCount;
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetConstantCount(uint16* count)
{
NS_PRECONDITION(count, "bad param");
*count = mConstantBaseIndex + mConstantCount;
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::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_REINTERPRET_CAST(nsXPTMethodInfo*,
&mEntry->interface_descriptor->
method_descriptors[index - mMethodBaseIndex]);
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::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_REINTERPRET_CAST(nsXPTConstant*,
&mEntry->interface_descriptor->
const_descriptors[index-mConstantBaseIndex]);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,64 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInterfaceInfo_h___
#define nsInterfaceInfo_h___
#include "nsIInterfaceInfo.h"
#include "xpt_struct.h"
#include "xpt_cpp.h"
// XXX destroy this!
class nsInterfaceInfo : 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);
// why constructor public?
nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
nsInterfaceInfo *parent);
public:
virtual ~nsInterfaceInfo();
// should be private
XPTInterfaceDirectoryEntry* mEntry;
private:
nsInterfaceInfo* mParent;
uint16 mMethodBaseIndex;
uint16 mMethodCount;
uint16 mConstantBaseIndex;
uint16 mConstantCount;
};
#endif /* nsInterfaceInfo_h___ */

Просмотреть файл

@ -0,0 +1,276 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <sys/stat.h>
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInterfaceInfo.h"
#include "nsIServiceManager.h"
#include "nsIAllocator.h"
#include "nsInterfaceInfoManager.h"
#include "nsInterfaceInfo.h"
// this after nsISupports, to pick up IID
// so that xpt stuff doesn't try to define it itself...
// #include "xpt_struct.h"
#include "xpt_xdr.h"
// should get multiple xpt files from some well-known dir.
#define XPTFILE "simple.xpt"
// Stolen from xpt_dump.c
// todo - lazy loading of file, etc.
XPTHeader *getheader() {
XPTState *state;
XPTCursor curs, *cursor = &curs;
XPTHeader *header;
struct stat file_stat;
int flen;
char *whole;
FILE *in;
if (stat(XPTFILE, &file_stat) != 0) {
perror("FAILED: fstat");
return NULL;
}
flen = file_stat.st_size;
in = fopen(XPTFILE, "r");
if (!in) {
perror("FAILED: fopen");
return NULL;
}
whole = (char *)malloc(flen);
if (!whole) {
perror("FAILED: malloc for whole");
return NULL;
}
if (flen > 0) {
fread(whole, flen, 1, in);
state = XPT_NewXDRState(XPT_DECODE, whole, flen);
if (!XPT_MakeCursor(state, XPT_HEADER, 0, cursor)) {
fprintf(stdout, "MakeCursor failed\n");
return NULL;
}
if (!XPT_DoHeader(cursor, &header)) {
fprintf(stdout, "DoHeader failed\n");
return NULL;
}
free(header);
XPT_DestroyXDRState(state);
// assum'd to be OK
free(whole);
fclose(in);
return header;
}
free(whole);
fclose(in);
return NULL;
}
static NS_DEFINE_IID(kIIIManagerIID, NS_IINTERFACEINFO_MANAGER_IID);
NS_IMPL_ISUPPORTS(nsInterfaceInfoManager, kIIIManagerIID);
// static
nsInterfaceInfoManager*
nsInterfaceInfoManager::GetInterfaceInfoManager()
{
static nsInterfaceInfoManager* impl = NULL;
if(!impl)
{
impl = new nsInterfaceInfoManager();
// XXX ought to check for properly formed impl here..
}
if(impl)
NS_ADDREF(impl);
return impl;
}
// static
nsIAllocator*
nsInterfaceInfoManager::GetAllocator(nsInterfaceInfoManager* iim /*= NULL*/)
{
nsIAllocator* al;
nsInterfaceInfoManager* iiml = iim;
if(!iiml && !(iiml = GetInterfaceInfoManager()))
return NULL;
if(NULL != (al = iiml->mAllocator))
NS_ADDREF(al);
if(!iim)
NS_RELEASE(iiml);
return al;
}
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
#define HACK_CACHE_SIZE 200
nsInterfaceInfoManager::nsInterfaceInfoManager()
: mAllocator(NULL)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
mInfoArray = (nsInterfaceInfo**) calloc(HACK_CACHE_SIZE, sizeof(void*));
mHeader = getheader();
PR_ASSERT((mHeader != NULL));
nsServiceManager::GetService(kAllocatorCID,
kIAllocatorIID,
(nsISupports **)&mAllocator);
// just added this baby.
// allocator isn't currently registered, so just use malloc instead.
// PR_ASSERT((mAllocator != NULL));
}
nsInterfaceInfo *
nsInterfaceInfoManager::buildII(XPTInterfaceDirectoryEntry *entry) {
int i;
for (i = 0; i < HACK_CACHE_SIZE; i++) {
if (mInfoArray[i] == NULL)
break;
if (mInfoArray[i]->mEntry == entry)
return mInfoArray[i];
}
// ok, no dice. Does it have a parent?
nsInterfaceInfo *parent = NULL;
if (entry->interface_descriptor->parent_interface != NULL) {
for (i = 0; i < HACK_CACHE_SIZE; i++) {
if (mInfoArray[i] == NULL)
break;
if (mInfoArray[i]->mEntry ==
entry->interface_descriptor->parent_interface)
parent = mInfoArray[i];
}
if (parent == NULL)
parent = buildII(entry->interface_descriptor->parent_interface);
PR_ASSERT(parent);
}
nsInterfaceInfo *result = new nsInterfaceInfo(entry, parent);
while (mInfoArray[i] == NULL)
i++;
PR_ASSERT(i < HACK_CACHE_SIZE);
mInfoArray[i] = result;
return result;
}
nsInterfaceInfoManager::~nsInterfaceInfoManager()
{
// let the singleton leak
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetInfoForIID(const nsIID* iid,
nsIInterfaceInfo** info)
{
for(int i = 0; i < mHeader->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *entry = &mHeader->interface_directory[i];
if (iid->Equals(entry->iid)) {
*info = buildII(entry);
NS_ADDREF(*info);
return NS_OK;
}
}
*info = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetInfoForName(const char* name,
nsIInterfaceInfo** info)
{
for(int i = 0; i < mHeader->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *entry = &mHeader->interface_directory[i];
if (!strcmp(name, entry->name)) {
*info = buildII(entry);
NS_ADDREF(*info);
return NS_OK;
}
}
*info = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
{
for(int i = 0; i < mHeader->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *entry = &mHeader->interface_directory[i];
if (!strcmp(name, entry->name)) {
nsIID* p;
// Allocator isn't registered, so just use malloc for now...
// if(!(p = (nsIID*)mAllocator->Alloc(sizeof(nsIID))))
// break;
if (!(p = (nsIID*)malloc(sizeof(nsIID))))
break;
// XXX I'm confused here about the lifetime of IID pointers.
memcpy(p, &entry->iid, sizeof(nsIID));
*iid = p;
return NS_OK;
}
}
*iid = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetNameForIID(const nsIID* iid, char** name)
{
for(int i = 0; i < mHeader->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *entry = &mHeader->interface_directory[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;
}
// XXX this goes away; IIM should be a service.
// ... where does decl for this go?
XPT_PUBLIC_API(nsIInterfaceInfoManager*)
XPT_GetInterfaceInfoManager()
{
return nsInterfaceInfoManager::GetInterfaceInfoManager();
}

Просмотреть файл

@ -0,0 +1,60 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInterfaceInfoManager_h___
#define nsInterfaceInfoManager_h___
#include "nsIAllocator.h"
#include "xpt_struct.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsInterfaceInfo.h"
class nsInterfaceInfoManager : 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);
// should be private ?
nsInterfaceInfoManager();
public:
virtual ~nsInterfaceInfoManager();
static nsInterfaceInfoManager* GetInterfaceInfoManager();
static nsIAllocator* GetAllocator(nsInterfaceInfoManager* iim = NULL);
private:
// temporary hack
nsInterfaceInfo **mInfoArray;
nsInterfaceInfo *buildII(XPTInterfaceDirectoryEntry *entry);
XPTHeader *mHeader;
nsInterfaceInfo *mParent;
nsIAllocator* mAllocator;
};
#endif /* nsInterfaceInfoManager_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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// Convienence bits of nsXPTParamInfo that don't fit into xpt_cpp.h
// flyweight wrappers.
#include "nsISupports.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInterfaceInfo.h"
#include "nsInterfaceInfoManager.h"
#include "xpt_cpp.h"
// Placeholder - this implementation just returns NULL.
nsIInterfaceInfo*
nsXPTParamInfo::GetInterface() const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,"not an interface");
nsIInterfaceInfoManager* mgr;
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
return NULL;
nsIInterfaceInfo* info;
// mgr->GetInfoForIID(&InterfaceDirectoryEntryTable[type.type.interface].iid,
// &info);
NS_RELEASE(mgr);
return info;
}
const nsIID*
nsXPTParamInfo::GetInterfaceIID() const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,"not an interface");
// return &InterfaceDirectoryEntryTable[type.type.interface].iid;
return (const nsIID*) NULL;
}

Просмотреть файл

@ -0,0 +1,44 @@
#
# 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 = libxpt
SIMPLE_PROGRAMS = TestInterfaceInfo
CSRCS =
CPPSRCS = \
TestInterfaceInfo.cpp \
$(NULL)
LDFLAGS = \
-L$(DIST)/bin \
-lxptinfo \
-lxpt \
-lxpcom \
-lreg \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,35 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Some simple smoke tests of the typelib loader. */
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
// XTC_PUBLIC_API(nsIInterfaceInfoManager*)
// XPT_GetInterfaceInfoManager();
int main (int argc, char **argv) {
nsIInterfaceInfoManager *iim = XPT_GetInterfaceInfoManager();
nsIID *iid;
iim->GetIIDForName("Interface", &iid);
}

Просмотреть файл

@ -0,0 +1,71 @@
#!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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\TestInterfaceInfo.exe
PROGRAMS = $(PROG1)
LCFLAGS=-DUSE_NSREG
DEFINES=-DWIN32_LEAN_AND_MEAN -DDEBUG
REQUIRES=xpcom libxpt xptinfo
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(DIST)\lib\xptinfo32.lib \
$(LIBNSPR) \
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
!endif
include <$(DEPTH)\config\rules.mak>
install:: $(PROGRAMS)
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
-for %p in ($(TESTCASES)) do $(MAKE_INSTALL) %p $(DIST)\bin
# Move this into config/obj.inc when it's allowed
.c{.\$(OBJDIR)\}.exe:
$(CC) @<<$(CFGFILE)
$(CFLAGS)
$(LCFLAGS)
$(LINCS)
$(LINCS_1)
$(INCS)
$(LLIBS)
$(OS_LIBS)
-Fd$(PBDFILE)
-Fe.\$(OBJDIR)\
-Fo.\$(OBJDIR)\
$(CURDIR)$(*B).c
<<KEEP
clean :: clobber
clobber::
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
$(PROG1): $(OBJDIR) TestInterfaceInfo.cpp

Просмотреть файл

@ -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) 1999 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

Просмотреть файл

@ -0,0 +1,22 @@
#!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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
DIRS=public src tests
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,33 @@
#!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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xptinfo
EXPORTS = xpt_cpp.h \
nsIInterfaceInfoManager.h \
nsIInterfaceInfo.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
DEPTH=..\..\..\..
EXPORTS = nsIInterfaceInfoManager.h \
nsIInterfaceInfo.h \
xpt_cpp.h \
$(NULL)
MODULE = xptinfo
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,55 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* The nsIInterfaceInfo xpcom public declaration. */
#ifndef nsIInterfaceInfo_h___
#define nsIInterfaceInfo_h___
#include "nsISupports.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_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERFACEINFO_IID)
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,63 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* The nsIInterfaceInfoManager xpcom public declaration. */
#ifndef nsIInterfaceInfoManager_h___
#define nsIInterfaceInfoManager_h___
#include "nsIInterfaceInfo.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:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERFACEINFO_MANAGER_IID)
// 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
// NOTE: these return IAllocatator alloc'd copies of the data
NS_IMETHOD GetIIDForName(const char* name, nsIID** iid) = 0;
NS_IMETHOD GetNameForIID(const nsIID* iid, char** name) = 0;
// XXX other methods?
};
// this is just for XPT_PUBLIC_API...
// should be removed with below.
#include "xpt_struct.h"
PR_BEGIN_EXTERN_C
// XXX remove this and use ServiceManager instead
XPT_PUBLIC_API(nsIInterfaceInfoManager*)
XPT_GetInterfaceInfoManager();
PR_END_EXTERN_C
#endif /* nsIInterfaceInfoManager_h___ */

Просмотреть файл

@ -0,0 +1,179 @@
/* -*- 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. */
#ifndef xpt_cpp_h___
#define xpt_cpp_h___
#include "xpt_struct.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;}
PRBool IsPointer() const
{return (PRBool) (XPT_TDP_IS_POINTER(flags));}
PRBool IsUniquePointer() const
{return (PRBool) (XPT_TDP_IS_UNIQUE_POINTER(flags));}
PRBool IsReference() const
{return (PRBool) (XPT_TDP_IS_REFERENCE(flags));}
PRBool IsArithmetic() const // terminology from Harbison/Steele
{return flags <= T_WCHAR;}
PRBool IsInterfacePointer() const
{return (PRBool) (TagPart() == T_INTERFACE ||
TagPart() == T_INTERFACE_IS);}
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_IID = TD_PNSIID ,
T_BSTR = TD_PBSTR ,
T_CHAR_STR = TD_PSTRING ,
T_WCHAR_STR = 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;}
PRBool IsIn() const {return (PRBool) (XPT_PD_IS_IN(flags));}
PRBool IsOut() const {return (PRBool) (XPT_PD_IS_OUT(flags));}
PRBool IsRetval() const {return (PRBool) (XPT_PD_IS_RETVAL(flags));}
const nsXPTType GetType() const {return type.prefix;}
uint8 GetInterfaceIsArgNumber() const
{
NS_PRECONDITION(GetType().TagPart() == 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 ;
// a *little* simpler than the above
const nsIID* GetInterfaceIID() 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;}
PRBool IsGetter() const {return (PRBool) (XPT_MD_IS_GETTER(flags) );}
PRBool IsSetter() const {return (PRBool) (XPT_MD_IS_SETTER(flags) );}
PRBool IsVarArgs() const {return (PRBool) (XPT_MD_IS_VARARGS(flags));}
PRBool IsConstructor() const {return (PRBool) (XPT_MD_IS_CTOR(flags) );}
PRBool IsHidden() const {return (PRBool) (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___ */

Просмотреть файл

@ -0,0 +1,38 @@
#!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 = xptinfo
LIBRARY_NAME = xptinfo
CSRCS = $(NULL)
CPPSRCS = nsInterfaceInfo.cpp \
nsInterfaceInfoManager.cpp \
nsXPTParamInfo.cpp \
$(NULL)
REQUIRES = $(MODULE)
export:: libs
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,63 @@
#!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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
DEPTH=..\..\..\..
LIBNAME = .\$(OBJDIR)\xptinfo$(MOZ_BITS)
DLL = $(LIBNAME).dll
LCFLAGS = -DEXPORT_XPT_API -DWIN32_LEAN_AND_MEAN
LINCS = \
-I$(PUBLIC)\libxpt \
-I$(PUBLIC)\xptinfo \
$(NULL)
LLIBS = \
$(LIBNSPR) \
$(DIST)\lib\libxpt.lib \
$(NULL)
CSRCS = \
$(NULL)
C_OBJS = \
$(NULL)
CPPSRCS = nsInterfaceInfoManager.cpp \
nsInterfaceInfo.cpp \
nsXPTParamInfo.cpp \
$(NULL)
CPP_OBJS = \
.\$(OBJDIR)\nsInterfaceInfoManager.obj \
.\$(OBJDIR)\nsInterfaceInfo.obj \
.\$(OBJDIR)\nsXPTParamInfo.obj \
$(NULL)
MODULE = xptinfo
include <$(DEPTH)\config\rules.mak>
libs:: $(DLL)
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib

Просмотреть файл

@ -0,0 +1,176 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIAllocator.h"
#include "nsInterfaceInfo.h"
#include "nsInterfaceInfoManager.h"
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
nsInterfaceInfo::nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
nsInterfaceInfo *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;
}
nsInterfaceInfo::~nsInterfaceInfo()
{
if(mParent)
NS_RELEASE(mParent);
}
NS_IMETHODIMP
nsInterfaceInfo::GetName(char** name)
{
NS_PRECONDITION(name, "bad param");
// nsIAllocator* allocator;
// if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
int len = strlen(mEntry->name)+1;
// char* p = (char*)allocator->Alloc(len);
// XXX malloc for now.
char *p = (char *)malloc(len);
// NS_RELEASE(allocator);
if(p) {
memcpy(p, mEntry->name, len);
*name = p;
return NS_OK;
}
// }
*name = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfo::GetIID(nsIID** iid)
{
NS_PRECONDITION(iid, "bad param");
// nsIAllocator* allocator;
// if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
// nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
// NS_RELEASE(allocator);
// XXX malloc for now.
nsIID* p = (nsIID*)malloc(sizeof(nsIID));
if(p) {
memcpy(p, &mEntry->iid, sizeof(nsIID));
*iid = p;
return NS_OK;
}
// }
*iid = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfo::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
nsInterfaceInfo::GetMethodCount(uint16* count)
{
NS_PRECONDITION(count, "bad param");
*count = mMethodBaseIndex + mMethodCount;
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetConstantCount(uint16* count)
{
NS_PRECONDITION(count, "bad param");
*count = mConstantBaseIndex + mConstantCount;
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::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_REINTERPRET_CAST(nsXPTMethodInfo*,
&mEntry->interface_descriptor->
method_descriptors[index - mMethodBaseIndex]);
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::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_REINTERPRET_CAST(nsXPTConstant*,
&mEntry->interface_descriptor->
const_descriptors[index-mConstantBaseIndex]);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,64 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInterfaceInfo_h___
#define nsInterfaceInfo_h___
#include "nsIInterfaceInfo.h"
#include "xpt_struct.h"
#include "xpt_cpp.h"
// XXX destroy this!
class nsInterfaceInfo : 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);
// why constructor public?
nsInterfaceInfo(XPTInterfaceDirectoryEntry* entry,
nsInterfaceInfo *parent);
public:
virtual ~nsInterfaceInfo();
// should be private
XPTInterfaceDirectoryEntry* mEntry;
private:
nsInterfaceInfo* mParent;
uint16 mMethodBaseIndex;
uint16 mMethodCount;
uint16 mConstantBaseIndex;
uint16 mConstantCount;
};
#endif /* nsInterfaceInfo_h___ */

Просмотреть файл

@ -0,0 +1,276 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <sys/stat.h>
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInterfaceInfo.h"
#include "nsIServiceManager.h"
#include "nsIAllocator.h"
#include "nsInterfaceInfoManager.h"
#include "nsInterfaceInfo.h"
// this after nsISupports, to pick up IID
// so that xpt stuff doesn't try to define it itself...
// #include "xpt_struct.h"
#include "xpt_xdr.h"
// should get multiple xpt files from some well-known dir.
#define XPTFILE "simple.xpt"
// Stolen from xpt_dump.c
// todo - lazy loading of file, etc.
XPTHeader *getheader() {
XPTState *state;
XPTCursor curs, *cursor = &curs;
XPTHeader *header;
struct stat file_stat;
int flen;
char *whole;
FILE *in;
if (stat(XPTFILE, &file_stat) != 0) {
perror("FAILED: fstat");
return NULL;
}
flen = file_stat.st_size;
in = fopen(XPTFILE, "r");
if (!in) {
perror("FAILED: fopen");
return NULL;
}
whole = (char *)malloc(flen);
if (!whole) {
perror("FAILED: malloc for whole");
return NULL;
}
if (flen > 0) {
fread(whole, flen, 1, in);
state = XPT_NewXDRState(XPT_DECODE, whole, flen);
if (!XPT_MakeCursor(state, XPT_HEADER, 0, cursor)) {
fprintf(stdout, "MakeCursor failed\n");
return NULL;
}
if (!XPT_DoHeader(cursor, &header)) {
fprintf(stdout, "DoHeader failed\n");
return NULL;
}
free(header);
XPT_DestroyXDRState(state);
// assum'd to be OK
free(whole);
fclose(in);
return header;
}
free(whole);
fclose(in);
return NULL;
}
static NS_DEFINE_IID(kIIIManagerIID, NS_IINTERFACEINFO_MANAGER_IID);
NS_IMPL_ISUPPORTS(nsInterfaceInfoManager, kIIIManagerIID);
// static
nsInterfaceInfoManager*
nsInterfaceInfoManager::GetInterfaceInfoManager()
{
static nsInterfaceInfoManager* impl = NULL;
if(!impl)
{
impl = new nsInterfaceInfoManager();
// XXX ought to check for properly formed impl here..
}
if(impl)
NS_ADDREF(impl);
return impl;
}
// static
nsIAllocator*
nsInterfaceInfoManager::GetAllocator(nsInterfaceInfoManager* iim /*= NULL*/)
{
nsIAllocator* al;
nsInterfaceInfoManager* iiml = iim;
if(!iiml && !(iiml = GetInterfaceInfoManager()))
return NULL;
if(NULL != (al = iiml->mAllocator))
NS_ADDREF(al);
if(!iim)
NS_RELEASE(iiml);
return al;
}
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
#define HACK_CACHE_SIZE 200
nsInterfaceInfoManager::nsInterfaceInfoManager()
: mAllocator(NULL)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
mInfoArray = (nsInterfaceInfo**) calloc(HACK_CACHE_SIZE, sizeof(void*));
mHeader = getheader();
PR_ASSERT((mHeader != NULL));
nsServiceManager::GetService(kAllocatorCID,
kIAllocatorIID,
(nsISupports **)&mAllocator);
// just added this baby.
// allocator isn't currently registered, so just use malloc instead.
// PR_ASSERT((mAllocator != NULL));
}
nsInterfaceInfo *
nsInterfaceInfoManager::buildII(XPTInterfaceDirectoryEntry *entry) {
int i;
for (i = 0; i < HACK_CACHE_SIZE; i++) {
if (mInfoArray[i] == NULL)
break;
if (mInfoArray[i]->mEntry == entry)
return mInfoArray[i];
}
// ok, no dice. Does it have a parent?
nsInterfaceInfo *parent = NULL;
if (entry->interface_descriptor->parent_interface != NULL) {
for (i = 0; i < HACK_CACHE_SIZE; i++) {
if (mInfoArray[i] == NULL)
break;
if (mInfoArray[i]->mEntry ==
entry->interface_descriptor->parent_interface)
parent = mInfoArray[i];
}
if (parent == NULL)
parent = buildII(entry->interface_descriptor->parent_interface);
PR_ASSERT(parent);
}
nsInterfaceInfo *result = new nsInterfaceInfo(entry, parent);
while (mInfoArray[i] == NULL)
i++;
PR_ASSERT(i < HACK_CACHE_SIZE);
mInfoArray[i] = result;
return result;
}
nsInterfaceInfoManager::~nsInterfaceInfoManager()
{
// let the singleton leak
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetInfoForIID(const nsIID* iid,
nsIInterfaceInfo** info)
{
for(int i = 0; i < mHeader->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *entry = &mHeader->interface_directory[i];
if (iid->Equals(entry->iid)) {
*info = buildII(entry);
NS_ADDREF(*info);
return NS_OK;
}
}
*info = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetInfoForName(const char* name,
nsIInterfaceInfo** info)
{
for(int i = 0; i < mHeader->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *entry = &mHeader->interface_directory[i];
if (!strcmp(name, entry->name)) {
*info = buildII(entry);
NS_ADDREF(*info);
return NS_OK;
}
}
*info = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
{
for(int i = 0; i < mHeader->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *entry = &mHeader->interface_directory[i];
if (!strcmp(name, entry->name)) {
nsIID* p;
// Allocator isn't registered, so just use malloc for now...
// if(!(p = (nsIID*)mAllocator->Alloc(sizeof(nsIID))))
// break;
if (!(p = (nsIID*)malloc(sizeof(nsIID))))
break;
// XXX I'm confused here about the lifetime of IID pointers.
memcpy(p, &entry->iid, sizeof(nsIID));
*iid = p;
return NS_OK;
}
}
*iid = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetNameForIID(const nsIID* iid, char** name)
{
for(int i = 0; i < mHeader->num_interfaces; i++) {
XPTInterfaceDirectoryEntry *entry = &mHeader->interface_directory[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;
}
// XXX this goes away; IIM should be a service.
// ... where does decl for this go?
XPT_PUBLIC_API(nsIInterfaceInfoManager*)
XPT_GetInterfaceInfoManager()
{
return nsInterfaceInfoManager::GetInterfaceInfoManager();
}

Просмотреть файл

@ -0,0 +1,60 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInterfaceInfoManager_h___
#define nsInterfaceInfoManager_h___
#include "nsIAllocator.h"
#include "xpt_struct.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsInterfaceInfo.h"
class nsInterfaceInfoManager : 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);
// should be private ?
nsInterfaceInfoManager();
public:
virtual ~nsInterfaceInfoManager();
static nsInterfaceInfoManager* GetInterfaceInfoManager();
static nsIAllocator* GetAllocator(nsInterfaceInfoManager* iim = NULL);
private:
// temporary hack
nsInterfaceInfo **mInfoArray;
nsInterfaceInfo *buildII(XPTInterfaceDirectoryEntry *entry);
XPTHeader *mHeader;
nsInterfaceInfo *mParent;
nsIAllocator* mAllocator;
};
#endif /* nsInterfaceInfoManager_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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// Convienence bits of nsXPTParamInfo that don't fit into xpt_cpp.h
// flyweight wrappers.
#include "nsISupports.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInterfaceInfo.h"
#include "nsInterfaceInfoManager.h"
#include "xpt_cpp.h"
// Placeholder - this implementation just returns NULL.
nsIInterfaceInfo*
nsXPTParamInfo::GetInterface() const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,"not an interface");
nsIInterfaceInfoManager* mgr;
if(!(mgr = nsInterfaceInfoManager::GetInterfaceInfoManager()))
return NULL;
nsIInterfaceInfo* info;
// mgr->GetInfoForIID(&InterfaceDirectoryEntryTable[type.type.interface].iid,
// &info);
NS_RELEASE(mgr);
return info;
}
const nsIID*
nsXPTParamInfo::GetInterfaceIID() const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,"not an interface");
// return &InterfaceDirectoryEntryTable[type.type.interface].iid;
return (const nsIID*) NULL;
}

Просмотреть файл

@ -0,0 +1,44 @@
#
# 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 = libxpt
SIMPLE_PROGRAMS = TestInterfaceInfo
CSRCS =
CPPSRCS = \
TestInterfaceInfo.cpp \
$(NULL)
LDFLAGS = \
-L$(DIST)/bin \
-lxptinfo \
-lxpt \
-lxpcom \
-lreg \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,35 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Some simple smoke tests of the typelib loader. */
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
// XTC_PUBLIC_API(nsIInterfaceInfoManager*)
// XPT_GetInterfaceInfoManager();
int main (int argc, char **argv) {
nsIInterfaceInfoManager *iim = XPT_GetInterfaceInfoManager();
nsIID *iid;
iim->GetIIDForName("Interface", &iid);
}

Просмотреть файл

@ -0,0 +1,71 @@
#!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) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\TestInterfaceInfo.exe
PROGRAMS = $(PROG1)
LCFLAGS=-DUSE_NSREG
DEFINES=-DWIN32_LEAN_AND_MEAN -DDEBUG
REQUIRES=xpcom libxpt xptinfo
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(DIST)\lib\xptinfo32.lib \
$(LIBNSPR) \
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
!endif
include <$(DEPTH)\config\rules.mak>
install:: $(PROGRAMS)
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
-for %p in ($(TESTCASES)) do $(MAKE_INSTALL) %p $(DIST)\bin
# Move this into config/obj.inc when it's allowed
.c{.\$(OBJDIR)\}.exe:
$(CC) @<<$(CFGFILE)
$(CFLAGS)
$(LCFLAGS)
$(LINCS)
$(LINCS_1)
$(INCS)
$(LLIBS)
$(OS_LIBS)
-Fd$(PBDFILE)
-Fe.\$(OBJDIR)\
-Fo.\$(OBJDIR)\
$(CURDIR)$(*B).c
<<KEEP
clean :: clobber
clobber::
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
$(PROG1): $(OBJDIR) TestInterfaceInfo.cpp

Просмотреть файл

@ -27,4 +27,6 @@ DIRS += tests
DIRS += tools
DIRS += xptinfo
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -25,9 +25,6 @@ MODULE = libxpt
EXPORTS = xpt_struct.h \
xpt_xdr.h \
xpt_cpp.h \
nsIInterfaceInfoManager.h \
nsIInterfaceInfo.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -28,12 +28,7 @@ CSRCS = xpt_struct.c \
xpt_xdr.c \
$(NULL)
CPPSRCS = nsInterfaceInfo.cpp \
nsInterfaceInfoManager.cpp \
nsXPTParamInfo.cpp \
$(NULL)
REQUIRES = $(MODULE) xpcom
REQUIRES = $(MODULE)
export:: libs

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -23,19 +23,13 @@ include $(DEPTH)/config/autoconf.mk
MODULE = libxpt
SIMPLE_PROGRAMS = PrimitiveTest SimpleTypeLib TestInterfaceInfo
SIMPLE_PROGRAMS = PrimitiveTest SimpleTypeLib
CSRCS = PrimitiveTest.c SimpleTypeLib.c
CPPSRCS = \
TestInterfaceInfo.cpp \
$(NULL)
LDFLAGS = \
-L$(DIST)/bin \
-lxpt \
-lxpcom \
-lreg \
$(NSPR_LIBS) \
$(NULL)

Просмотреть файл

Просмотреть файл

@ -30,8 +30,6 @@ CSRCS = xpt_dump.c xpt_link.c
LDFLAGS = \
-L$(DIST)/bin \
-lxpt \
-lxpcom \
-lreg \
$(NSPR_LIBS) \
$(NULL)