Latest xpcom stuff from raptor work.
git-svn-id: svn://10.0.0.236/branches/XPCOM_BRANCH@121 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -318,7 +318,7 @@ BINREL_DIST=$(XPDIST)\WIN954.0_OPT.OBJ
|
||||
BINREL_DIST=$(XPDIST)\WIN954.0_DBG.OBJD
|
||||
!endif
|
||||
!endif
|
||||
|
||||
|
||||
LINK_LIBS= \
|
||||
!if "$(MOZ_BITS)"=="32"
|
||||
!ifndef NSPR20
|
||||
@@ -1533,7 +1533,7 @@ $(GENDIR)\tdlogo.rc: $(MOZ_SRC)\ns\lib\xp\tdlogo.gif
|
||||
|
||||
AboutImages: $(GENDIR) \
|
||||
$(GENDIR)\flamer.rc
|
||||
|
||||
|
||||
$(GENDIR)\flamer.rc: $(MOZ_SRC)\ns\lib\xp\flamer.gif
|
||||
$(BIN2RC) $(MOZ_SRC)\ns\lib\xp\flamer.gif image/gif > $(GENDIR)\flamer.rc
|
||||
!endif
|
||||
@@ -1547,7 +1547,7 @@ prebuild: $(GENDIR) $(GENDIR)\initpref.rc $(GENDIR)\allpref.rc \
|
||||
$(GENDIR)\allpref2.rc $(GENDIR)\allpref3.rc $(GENDIR)\allpref4.rc\
|
||||
$(GENDIR)\winpref.rc $(GENDIR)\config.rc NavCenterImages \
|
||||
AboutImages
|
||||
|
||||
|
||||
$(GENDIR)\initpref.rc: $(MOZ_SRC)\ns\modules\libpref\src\initpref.js
|
||||
$(TXT2RC) init_prefs $(MOZ_SRC)\ns\modules\libpref\src\initpref.js \
|
||||
$(GENDIR)\initpref.rc
|
||||
@@ -1658,6 +1658,9 @@ install: \
|
||||
!IF EXIST($(DIST)\bin\sched32.dll)
|
||||
$(OUTDIR)\sched32.dll \
|
||||
!ENDIF
|
||||
!IF EXIST($(DIST)\bin\libreg32.dll)
|
||||
$(OUTDIR)\libreg32.dll \
|
||||
!ENDIF
|
||||
!IF EXIST($(DIST)\bin\jrt32$(VERSION_NUMBER).dll)
|
||||
$(OUTDIR)\jrt32$(VERSION_NUMBER).dll \
|
||||
!ENDIF
|
||||
@@ -1665,7 +1668,7 @@ install: \
|
||||
$(OUTDIR)\uni3200.dll \
|
||||
!ENDIF
|
||||
!IF EXIST($(DIST)\bin\awt32$(VERSION_NUMBER).dll)
|
||||
$(OUTDIR)\java\bin\awt32$(VERSION_NUMBER).dll \
|
||||
$(OUTDIR)\java\bin\awt32$(VERSION_NUMBER).dll \
|
||||
!ENDIF
|
||||
!if defined(MOZ_TRACKGDI)
|
||||
!IF EXIST($(DIST)\bin\trackgdi.dll)
|
||||
@@ -1763,6 +1766,9 @@ install: \
|
||||
!IF EXIST($(DIST)\bin\sched16.dll)
|
||||
$(OUTDIR)\sched16.dll \
|
||||
!ENDIF
|
||||
!IF EXIST($(DIST)\bin\libreg16.dll)
|
||||
$(OUTDIR)\libreg16.dll \
|
||||
!ENDIF
|
||||
!IF EXIST($(DIST)\bin\nsinit.exe)
|
||||
$(OUTDIR)\nsinit.exe \
|
||||
!ENDIF
|
||||
@@ -1914,6 +1920,9 @@ $(OUTDIR)\xppref32.dll: $(DIST)\bin\xppref32.dll
|
||||
$(OUTDIR)\sched32.dll: $(DIST)\bin\sched32.dll
|
||||
@IF EXIST $(DIST)\bin\sched32.dll copy $(DIST)\bin\sched32.dll $(OUTDIR)\sched32.dll
|
||||
|
||||
$(OUTDIR)\libreg32.dll: $(DIST)\bin\libreg32.dll
|
||||
@IF EXIST $(DIST)\bin\libreg32.dll copy $(DIST)\bin\libreg32.dll $(OUTDIR)\libreg32.dll
|
||||
|
||||
$(OUTDIR)\uni3200.dll: $(DIST)\bin\uni3200.dll
|
||||
@IF EXIST $(DIST)\bin\uni3200.dll copy $(DIST)\bin\uni3200.dll $(OUTDIR)\uni3200.dll
|
||||
|
||||
@@ -1989,6 +1998,9 @@ $(OUTDIR)\xppref16.dll: $(DIST)\bin\xppref16.dll
|
||||
$(OUTDIR)\sched16.dll: $(DIST)\bin\sched16.dll
|
||||
@IF EXIST $(DIST)\bin\sched16.dll copy $(DIST)\bin\sched16.dll $(OUTDIR)\sched16.dll
|
||||
|
||||
$(OUTDIR)\libreg16.dll: $(DIST)\bin\libreg16.dll
|
||||
@IF EXIST $(DIST)\bin\libreg16.dll copy $(DIST)\bin\libreg16.dll $(OUTDIR)\libreg16.dll
|
||||
|
||||
$(OUTDIR)\uni1600.dll: $(DIST)\bin\uni1600.dll
|
||||
@IF EXIST $(DIST)\bin\uni1600.dll copy $(DIST)\bin\uni1600.dll $(OUTDIR)\uni1600.dll
|
||||
|
||||
@@ -2288,7 +2300,8 @@ BUILD_SOURCE: $(OBJ_FILES)
|
||||
$(DIST)\lib\htmldg16.lib +
|
||||
$(DIST)\lib\hook.lib +
|
||||
$(DIST)\lib\png.lib +
|
||||
$(DIST)\lib\sched16.lib +
|
||||
$(DIST)\lib\sched16.lib +
|
||||
$(DIST)\lib\libreg16.lib +
|
||||
$(DIST)\lib\rdf16.lib +
|
||||
$(DIST)\lib\xpstrdll.lib +
|
||||
!ifdef MOZ_MAIL_NEWS
|
||||
@@ -2662,7 +2675,7 @@ symbols:
|
||||
@echo "MOZ_USERNAME = $(MOZ_USERNAME)"
|
||||
@echo "MOZ_USERDEBUG = $(MOZ_USERDEBUG)"
|
||||
!endif
|
||||
|
||||
|
||||
|
||||
ns.zip:
|
||||
cd $(OUTDIR)
|
||||
@@ -2703,6 +2716,7 @@ ns.zip:
|
||||
edpref32.dll \
|
||||
editor32.dll \
|
||||
xppref32.dll \
|
||||
sched32.dll \
|
||||
sched32.dll \
|
||||
libreg32.dll \
|
||||
netscape.cfg \
|
||||
moz40p3
|
||||
|
||||
@@ -108,7 +108,7 @@ nsPluginManager::MemFlush(PRUint32 size)
|
||||
static NS_DEFINE_IID(kPluginManagerIID, NP_IPLUGINMANAGER_IID);
|
||||
//static NS_DEFINE_IID(kNPIJVMPluginManagerIID, NP_IJVMPLUGINMANAGER_IID);
|
||||
|
||||
NS_METHOD
|
||||
NS_IMETHODIMP
|
||||
nsPluginManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
@@ -184,7 +184,7 @@ NS_IMPL_AGGREGATED(nsPluginInstancePeer);
|
||||
static NS_DEFINE_IID(kLiveConnectPluginInstancePeerIID, NP_ILIVECONNECTPLUGININSTANCEPEER_IID);
|
||||
static NS_DEFINE_IID(kPluginInstancePeerIID, NP_IPLUGININSTANCEPEER_IID);
|
||||
|
||||
NS_METHOD
|
||||
NS_IMETHODIMP
|
||||
nsPluginInstancePeer::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
|
||||
DEPTH = ../..
|
||||
|
||||
DIRS = include src
|
||||
DIRS = include src
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
@@ -81,17 +81,17 @@ typedef struct _reginfo
|
||||
#define UNIX_GLOBAL_FLAG "MOZILLA_SHARED_REGISTRY"
|
||||
|
||||
/* Platform-dependent declspec for library interface */
|
||||
#if defined(STANDALONE_REGISTRY) && defined(XP_PC)
|
||||
#if defined(WIN32)
|
||||
#define VR_INTERFACE(type) __declspec(dllexport) type __stdcall
|
||||
#elif defined(XP_OS2)
|
||||
#define VR_INTERFACE(type) type _Optlink
|
||||
#else
|
||||
#define VR_INTERFACE(type) type _far _pascal _export
|
||||
#endif
|
||||
#if defined(XP_PC)
|
||||
#if defined(WIN32)
|
||||
#define VR_INTERFACE(type) __declspec(dllexport) type __stdcall
|
||||
#elif defined(XP_OS2)
|
||||
#define VR_INTERFACE(type) type _Optlink
|
||||
#else
|
||||
#define VR_INTERFACE(type) type _far _pascal _export
|
||||
#endif
|
||||
#else
|
||||
#define VR_INTERFACE(type) type
|
||||
#endif /* STANDALONE_REGISTRY and XP_PC */
|
||||
#define VR_INTERFACE(type) type
|
||||
#endif
|
||||
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
@@ -113,6 +113,10 @@ VR_INTERFACE(REGERR) NR_RegPack(
|
||||
HREG hReg /* handle of open registry to pack */
|
||||
);
|
||||
|
||||
VR_INTERFACE(REGERR) NR_RegSetUsername(
|
||||
const char *name /* name of current user */
|
||||
);
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* Registry API -- Key Management functions
|
||||
* ---------------------------------------------------------------------
|
||||
@@ -207,8 +211,8 @@ VR_INTERFACE(REGERR) NR_RegEnumEntries(
|
||||
);
|
||||
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
void NR_ShutdownRegistry(void);
|
||||
void NR_StartupRegistry(void);
|
||||
VR_INTERFACE(void) NR_ShutdownRegistry(void);
|
||||
VR_INTERFACE(void) NR_StartupRegistry(void);
|
||||
#endif /* STANDALONE_REGISTRY */
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
@@ -54,14 +54,10 @@ VR_INTERFACE(REGERR) VR_InRegistry(char *path);
|
||||
VR_INTERFACE(REGERR) VR_ValidateComponent(char *path);
|
||||
VR_INTERFACE(REGERR) VR_Enum(REGENUM *state, char *buffer, uint32 buflen);
|
||||
|
||||
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
VR_INTERFACE(void) VR_Initialize(void* env);
|
||||
#endif
|
||||
VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path);
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif /* _VERREG_H_ */
|
||||
|
||||
/* EOF: VerReg.h */
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ DEPTH=..\..
|
||||
#// DIRS - There are subdirectories to process
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
DIRS=include src
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
@@ -22,7 +22,7 @@ LIBRARY_NAME = reg
|
||||
|
||||
REQUIRES = libreg nspr dbm pref js
|
||||
|
||||
CSRCS = reg.c VerReg.c
|
||||
CSRCS = reg.c VerReg.c vr_stubs.c
|
||||
|
||||
BIN_SRCS = VerReg.c reg.c vr_stubs.c
|
||||
BIN_OBJS = $(addprefix $(OBJDIR)/R_,$(BIN_SRCS:.c=.o))
|
||||
@@ -42,9 +42,9 @@ PROGRAM = $(OBJDIR)/vreg$(BIN_SUFFIX)
|
||||
$(PROGRAM): $(BIN_OBJS)
|
||||
@$(MAKE_OBJDIR)
|
||||
ifeq ($(OS_ARCH), OS2)
|
||||
$(LINK_EXE) -OUT:$@ $(BIN_OBJS) $(LDFLAGS) $(OS_LIBS) $(DIST)/lib/libxp.$(LIB_SUFFIX)
|
||||
$(LINK_EXE) -OUT:$@ $(BIN_OBJS) $(LDFLAGS) $(OS_LIBS)
|
||||
else
|
||||
$(CCF) -o $@ $(BIN_OBJS) $(LDFLAGS) $(DIST)/lib/lib$(LITE_PREFIX)xp.$(LIB_SUFFIX)
|
||||
$(CCF) -o $@ $(BIN_OBJS) $(LDFLAGS)
|
||||
endif
|
||||
|
||||
$(OBJDIR)/R_VerReg.o: VerReg.c
|
||||
|
||||
@@ -37,36 +37,10 @@
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
#include "xp_mcom.h"
|
||||
#include "xp_core.h"
|
||||
#ifndef NSPR20
|
||||
#include "prosdep.h"
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include <Folders.h>
|
||||
#include "prosdep.h"
|
||||
#else
|
||||
#include "md/prosdep.h"
|
||||
#endif
|
||||
#endif
|
||||
#include "prmon.h"
|
||||
#ifdef BROKEN
|
||||
#include "su_folderspec.h"
|
||||
#endif
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include <types.h>
|
||||
#include <stat.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#include "reg.h"
|
||||
#include "NSReg.h"
|
||||
@@ -115,6 +89,7 @@ XP_Bool bGlobalRegistry = FALSE;
|
||||
PRMonitor *vr_monitor = NULL;
|
||||
#endif
|
||||
|
||||
static char *app_dir = NULL;
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* local functions
|
||||
@@ -160,14 +135,14 @@ static REGERR vr_Init(void)
|
||||
|
||||
if (!isInited)
|
||||
{
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
#ifdef BROKEN
|
||||
curPath = FE_GetDirectoryPath(eCommunicatorFolder);
|
||||
#else
|
||||
/* can't use Version Registry interface until "BROKEN" works */
|
||||
err = REGERR_FAIL;
|
||||
goto done;
|
||||
#endif
|
||||
#if !defined(STANDALONE_REGISTRY)
|
||||
curPath = app_dir;
|
||||
if (curPath == NULL) {
|
||||
/* can't use Version Registry interface until "BROKEN" works */
|
||||
err = REGERR_FAIL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
#ifdef XP_UNIX
|
||||
if (curPath != NULL) {
|
||||
regbuf = (char*)XP_ALLOC( 10 + XP_STRLEN(curPath) );
|
||||
@@ -259,7 +234,6 @@ static REGERR vr_Init(void)
|
||||
done:
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
PR_ExitMonitor(vr_monitor);
|
||||
XP_FREEIF(curPath);
|
||||
#ifdef XP_UNIX
|
||||
XP_FREEIF(regbuf);
|
||||
#endif
|
||||
@@ -1101,7 +1075,7 @@ VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path)
|
||||
}
|
||||
|
||||
urlPath = path;
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
#ifdef BROKEN
|
||||
url = XP_PlatformFileToURL(path);
|
||||
if ( url == NULL )
|
||||
return REGERR_MEMORY;
|
||||
@@ -1144,4 +1118,17 @@ VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path)
|
||||
#pragma export reset
|
||||
#endif
|
||||
|
||||
VR_INTERFACE(REGERR) VR_SetRegDirectory(const char *path)
|
||||
{
|
||||
char *tmp = XP_STRDUP(path);
|
||||
if (NULL == tmp) {
|
||||
return REGERR_MEMORY;
|
||||
}
|
||||
|
||||
XP_FREEIF(app_dir);
|
||||
app_dir = tmp;
|
||||
|
||||
return REGERR_OK;
|
||||
}
|
||||
|
||||
/* EOF: VerReg.c */
|
||||
|
||||
@@ -31,7 +31,7 @@ IGNORE_MANIFEST=1
|
||||
DEPTH= ..\..\..
|
||||
|
||||
!ifndef MAKE_OBJ_TYPE
|
||||
MAKE_OBJ_TYPE=EXE
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
@@ -39,8 +39,6 @@ MAKE_OBJ_TYPE=EXE
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LIBNAME=libreg$(MOZ_BITS)
|
||||
PDBFILE=$(LIBNAME).pdb
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
@@ -51,6 +49,7 @@ PDBFILE=$(LIBNAME).pdb
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\reg.obj \
|
||||
.\$(OBJDIR)\VerReg.obj \
|
||||
.\$(OBJDIR)\vr_stubs.obj \
|
||||
$(NULL)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
@@ -60,6 +59,8 @@ OBJS= \
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
LIBNAME=libreg$(MOZ_BITS)
|
||||
DLL=$(OBJDIR)\$(LIBNAME).dll
|
||||
LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
@@ -69,15 +70,14 @@ LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
LCFLAGS = $(LCFLAGS)
|
||||
LLIBS = $(LLIBS) $(LIBNSPR)
|
||||
|
||||
#//
|
||||
#// Win16 places ALL public header files in $(PUBLIC)/win16
|
||||
#//
|
||||
!if "$(MOZ_BITS)" != "16"
|
||||
LINCS= $(LINCS) -I$(PUBLIC)/libreg \
|
||||
-I$(PUBLIC)/nspr \
|
||||
-I$(PUBLIC)/dbm \
|
||||
-I$(PUBLIC)/pref \
|
||||
-I$(PUBLIC)/js \
|
||||
$(NULL)
|
||||
!endif
|
||||
|
||||
@@ -88,6 +88,11 @@ LINCS= $(LINCS) -I$(PUBLIC)/libreg \
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
libs:: $(DLL)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
$(MAKE_INSTALL) $(DLL) $(DIST)\bin
|
||||
|
||||
clobber::
|
||||
$(RM) $(DIST)\bin\$(DLL)
|
||||
$(RM) $(DIST)\lib\$(LIBRARY)
|
||||
|
||||
|
||||
@@ -33,13 +33,10 @@
|
||||
#define VERIFY_READ 1
|
||||
#endif
|
||||
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
#include "xp_mcom.h"
|
||||
#include "xp_error.h"
|
||||
#include "prmon.h"
|
||||
#include "prefapi.h"
|
||||
#else
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include <size_t.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -49,7 +46,6 @@
|
||||
#ifdef SUNOS4
|
||||
#include <unistd.h> /* for SEEK_SET */
|
||||
#endif /* SUNOS4 */
|
||||
#endif /* STANDALONE_REGISTRY */
|
||||
|
||||
#include "reg.h"
|
||||
#include "NSReg.h"
|
||||
@@ -97,7 +93,7 @@ static XP_Bool bRegStarted = FALSE;
|
||||
#if !defined(STANDALONE_REGISTRY)
|
||||
static PRMonitor *reglist_monitor;
|
||||
#endif
|
||||
|
||||
static char *user_name = NULL;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
@@ -1513,6 +1509,8 @@ static void nr_InitStdRkeys( REGFILE *reg );
|
||||
static Bool nr_ProtectedNode( REGFILE *reg, REGOFF key );
|
||||
static REGERR nr_RegAddKey( REGFILE *reg, RKEY key, char *path, RKEY *newKey );
|
||||
static void nr_Upgrade_1_1( REGFILE *reg );
|
||||
static char* nr_GetUsername();
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -1549,9 +1547,8 @@ static REGOFF nr_TranslateKey( REGFILE *reg, RKEY key )
|
||||
REGERR err;
|
||||
char* profName;
|
||||
|
||||
err = PREF_CopyDefaultCharPref( "profile.name", &profName );
|
||||
|
||||
if (err == PREF_NOERROR ) {
|
||||
profName = nr_GetUsername();
|
||||
if ( NULL != profName ) {
|
||||
/* Don't assign a slot for missing or magic profile */
|
||||
if ( '\0' == *profName ||
|
||||
0 == XP_STRCMP(ASW_MAGIC_PROFILE_NAME, profName))
|
||||
@@ -1790,12 +1787,42 @@ static void nr_Upgrade_1_1(REGFILE *reg)
|
||||
|
||||
}
|
||||
|
||||
|
||||
static char *nr_GetUsername()
|
||||
{
|
||||
if (NULL == user_name) {
|
||||
return "default";
|
||||
} else {
|
||||
return user_name;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* Public API
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* NR_RegSetUsername - Set the current username
|
||||
*
|
||||
* Parameters:
|
||||
* name - name of the current user
|
||||
*
|
||||
* Output:
|
||||
* ---------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
VR_INTERFACE(REGERR) NR_RegSetUsername(const char *name)
|
||||
{
|
||||
char *tmp = XP_STRDUP(name);
|
||||
if (NULL == tmp) {
|
||||
return REGERR_MEMORY;
|
||||
}
|
||||
|
||||
XP_FREEIF(user_name);
|
||||
user_name = tmp;
|
||||
|
||||
return REGERR_OK;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* NReg_Open - Open a netscape XP registry
|
||||
*
|
||||
@@ -2845,19 +2872,13 @@ VR_INTERFACE(REGERR) NR_RegEnumEntries( HREG hReg, RKEY key, REGENUM *state,
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
#include "VerReg.h"
|
||||
|
||||
#ifdef WIN32
|
||||
extern BOOL WFE_IsMoveFileExBroken();
|
||||
#endif
|
||||
/* ---------------------------------------------------------------------
|
||||
* ---------------------------------------------------------------------
|
||||
* Registry initialization and shut-down
|
||||
* ---------------------------------------------------------------------
|
||||
* ---------------------------------------------------------------------
|
||||
*/
|
||||
#ifdef BROKEN
|
||||
extern void SU_InitMonitor(void);
|
||||
extern void SU_DestroyMonitor(void);
|
||||
#endif
|
||||
|
||||
extern PRMonitor *vr_monitor;
|
||||
#ifdef XP_UNIX
|
||||
extern XP_Bool bGlobalRegistry;
|
||||
@@ -2867,14 +2888,12 @@ extern XP_Bool bGlobalRegistry;
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
void NR_StartupRegistry(void)
|
||||
VR_INTERFACE(void) NR_StartupRegistry(void)
|
||||
{
|
||||
HREG reg;
|
||||
RKEY key;
|
||||
REGERR err;
|
||||
REGENUM state;
|
||||
XP_Bool removeFromList;
|
||||
XP_StatStruct stat;
|
||||
|
||||
if (bRegStarted)
|
||||
return;
|
||||
|
||||
vr_monitor = PR_NewMonitor();
|
||||
XP_ASSERT( vr_monitor != NULL );
|
||||
@@ -2884,110 +2903,10 @@ void NR_StartupRegistry(void)
|
||||
bGlobalRegistry = ( getenv(UNIX_GLOBAL_FLAG) != NULL );
|
||||
#endif
|
||||
|
||||
#ifdef BROKEN
|
||||
SU_InitMonitor();
|
||||
#endif
|
||||
bRegStarted = TRUE;
|
||||
/* need to register a PREF callback for "profile.name" */
|
||||
|
||||
/* check to see that we have a valid registry */
|
||||
if (REGERR_OK == NR_RegOpen("", ®))
|
||||
{
|
||||
#ifdef XP_PC
|
||||
/* perform scheduled file deletions and replacements (PC only) */
|
||||
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE,
|
||||
REG_DELETE_LIST_KEY,&key))
|
||||
{
|
||||
char *urlFile;
|
||||
char *pFile;
|
||||
char buf[MAXREGNAMELEN];
|
||||
|
||||
state = 0;
|
||||
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state,
|
||||
buf, sizeof(buf), NULL ))
|
||||
{
|
||||
urlFile = XP_PlatformFileToURL(buf);
|
||||
if ( urlFile == NULL)
|
||||
continue;
|
||||
pFile = urlFile+7;
|
||||
|
||||
removeFromList = FALSE;
|
||||
if (0 == XP_FileRemove(pFile, xpURL)) {
|
||||
/* file was successfully deleted */
|
||||
removeFromList = TRUE;
|
||||
}
|
||||
else if (XP_Stat(pFile, &stat, xpURL) != 0) {
|
||||
/* file doesn't appear to exist */
|
||||
removeFromList = TRUE;
|
||||
}
|
||||
|
||||
if (removeFromList) {
|
||||
err = NR_RegDeleteEntry( reg, key, buf );
|
||||
/* must reset state or enum will stop on deleted entry */
|
||||
if ( err == REGERR_OK )
|
||||
state = 0;
|
||||
}
|
||||
|
||||
XP_FREEIF(urlFile);
|
||||
}
|
||||
/* delete list node if empty */
|
||||
state = 0;
|
||||
if (REGERR_NOMORE == NR_RegEnumEntries( reg, key, &state, buf,
|
||||
sizeof(buf), NULL ))
|
||||
{
|
||||
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
/* replace files if any listed */
|
||||
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE,
|
||||
REG_REPLACE_LIST_KEY, &key))
|
||||
{
|
||||
char tmpfile[MAXREGNAMELEN];
|
||||
char target[MAXREGNAMELEN];
|
||||
|
||||
state = 0;
|
||||
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state,
|
||||
tmpfile, sizeof(tmpfile), NULL ))
|
||||
{
|
||||
removeFromList = FALSE;
|
||||
if (XP_Stat(tmpfile, &stat, xpURL) != 0)
|
||||
{
|
||||
/* new file is gone! */
|
||||
removeFromList = TRUE;
|
||||
}
|
||||
else if ( REGERR_OK != NR_RegGetEntryString( reg, key,
|
||||
tmpfile, target, sizeof(target) ) )
|
||||
{
|
||||
/* can't read target filename, corruption? */
|
||||
removeFromList = TRUE;
|
||||
}
|
||||
else {
|
||||
if (XP_Stat(target, &stat, xpURL) == 0) {
|
||||
/* need to delete old file first */
|
||||
XP_FileRemove( target, xpURL );
|
||||
}
|
||||
if (0 == XP_FileRename(tmpfile, xpURL, target, xpURL)) {
|
||||
removeFromList = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (removeFromList) {
|
||||
err = NR_RegDeleteEntry( reg, key, tmpfile );
|
||||
/* must reset state or enum will stop on deleted entry */
|
||||
if ( err == REGERR_OK )
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
/* delete list node if empty */
|
||||
state = 0;
|
||||
if (REGERR_NOMORE == NR_RegEnumEntries(reg, key, &state, tmpfile,
|
||||
sizeof(tmpfile), NULL ))
|
||||
{
|
||||
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
|
||||
}
|
||||
}
|
||||
#endif /* XP_PC */
|
||||
if (REGERR_OK == NR_RegOpen("", ®)) {
|
||||
NR_RegClose(reg);
|
||||
}
|
||||
else {
|
||||
@@ -2996,9 +2915,10 @@ void NR_StartupRegistry(void)
|
||||
VR_InRegistry("/Netscape");
|
||||
VR_Close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void NR_ShutdownRegistry(void)
|
||||
VR_INTERFACE(void) NR_ShutdownRegistry(void)
|
||||
{
|
||||
REGFILE* pReg;
|
||||
|
||||
@@ -3022,9 +2942,10 @@ void NR_ShutdownRegistry(void)
|
||||
PR_DestroyMonitor( reglist_monitor );
|
||||
reglist_monitor = NULL;
|
||||
}
|
||||
#ifdef BROKEN
|
||||
SU_DestroyMonitor();
|
||||
#endif
|
||||
|
||||
XP_FREEIF(user_name);
|
||||
|
||||
bRegStarted = FALSE;
|
||||
}
|
||||
|
||||
#ifdef XP_MAC
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
#ifndef _REG_H_
|
||||
#define _REG_H_
|
||||
|
||||
#ifdef STANDALONE_REGISTRY
|
||||
#include "vr_stubs.h"
|
||||
#else
|
||||
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
#include "prmon.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -19,10 +19,12 @@
|
||||
/* this file contains stubs needed to build the registry routines
|
||||
* into a stand-alone library for use with our installers
|
||||
*/
|
||||
#ifdef STANDALONE_REGISTRY
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
#include "prtypes.h"
|
||||
#endif
|
||||
#include "vr_stubs.h"
|
||||
|
||||
#ifdef XP_MAC
|
||||
@@ -176,7 +178,11 @@ char *strdup(const char *source)
|
||||
return newAllocation;
|
||||
}
|
||||
|
||||
int strcasecmp(const char *str1, const char *str2)
|
||||
#endif /* XP_MAC */
|
||||
|
||||
#if defined(XP_MAC) || defined(XP_UNIX)
|
||||
|
||||
int vr_strcasecmp(const char *str1, const char *str2)
|
||||
{
|
||||
char currentChar1, currentChar2;
|
||||
|
||||
@@ -205,7 +211,7 @@ int strcasecmp(const char *str1, const char *str2)
|
||||
return currentChar1 - currentChar2;
|
||||
}
|
||||
|
||||
int strncasecmp(const char *str1, const char *str2, int length)
|
||||
int vr_strncasecmp(const char *str1, const char *str2, int length)
|
||||
{
|
||||
char currentChar1, currentChar2;
|
||||
|
||||
@@ -234,7 +240,7 @@ int strncasecmp(const char *str1, const char *str2, int length)
|
||||
|
||||
return currentChar1 - currentChar2;
|
||||
}
|
||||
#endif /* XP_MAC */
|
||||
#endif /* XP_MAC || XP_UNIX */
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
@@ -255,32 +261,63 @@ int strncasecmp(const char *str1, const char *str2, int length)
|
||||
#include "NSReg.h"
|
||||
#include "VerReg.h"
|
||||
|
||||
char *TheRegistry;
|
||||
char *TheRegistry = "registry";
|
||||
char *Flist;
|
||||
/* WARNING: build hackery */
|
||||
#ifdef STANDALONE_REGISTRY
|
||||
long BUILDNUM =
|
||||
#include "../../../build/build_number"
|
||||
;
|
||||
|
||||
#endif
|
||||
|
||||
REGERR vr_ParseVersion(char *verstr, VERSION *result);
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
#ifdef XP_UNIX
|
||||
XP_File VR_StubOpen (const char * mode)
|
||||
|
||||
#define DEF_REG "/.netscape/registry"
|
||||
|
||||
XP_File VR_StubOpen (const char *name, const char * mode)
|
||||
{
|
||||
XP_File fh;
|
||||
struct stat st;
|
||||
|
||||
if ( stat( TheRegistry, &st ) == 0 )
|
||||
fh = fopen( TheRegistry, XP_FILE_UPDATE_BIN );
|
||||
else
|
||||
fh = fopen( TheRegistry, XP_FILE_WRITE_BIN );
|
||||
|
||||
return fh;
|
||||
}
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
char *def = NULL;
|
||||
if (name == NULL || *name == '\0') {
|
||||
char *home = getenv("HOME");
|
||||
if (home != NULL) {
|
||||
def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_REG));
|
||||
if (def != NULL) {
|
||||
XP_STRCPY(def, home);
|
||||
XP_STRCAT(def, DEF_REG);
|
||||
}
|
||||
}
|
||||
if (def != NULL) {
|
||||
name = def;
|
||||
} else {
|
||||
name = TheRegistry;
|
||||
}
|
||||
}
|
||||
#else
|
||||
name = TheRegistry;
|
||||
#endif
|
||||
|
||||
if ( stat( name, &st ) == 0 )
|
||||
fh = fopen( name, XP_FILE_UPDATE_BIN );
|
||||
else
|
||||
fh = fopen( name, XP_FILE_WRITE_BIN );
|
||||
|
||||
#ifndef STANDALONE_REGISTRY
|
||||
XP_FREEIF(def);
|
||||
#endif
|
||||
|
||||
return fh;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef STANDALONE_REGISTRY
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
XP_File fh;
|
||||
@@ -361,6 +398,7 @@ int main(int argc, char *argv[])
|
||||
fclose( fh );
|
||||
return 0;
|
||||
}
|
||||
#endif /* XP_UNIX || XP_OS2 */
|
||||
|
||||
#endif /* STANDALONE_REGISTRY */
|
||||
|
||||
#endif /* XP_UNIX || XP_OS2 */
|
||||
|
||||
@@ -69,12 +69,17 @@
|
||||
#define XP_FileFlush(file) fflush(file)
|
||||
#define XP_FileClose(file) fclose(file)
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define XP_FileOpen(name,type,mode) VR_StubOpen((name), (mode))
|
||||
#else
|
||||
#define XP_FileOpen(name,type,mode) VR_StubOpen((mode))
|
||||
#endif
|
||||
|
||||
#define XP_BEGIN_PROTOS
|
||||
#define XP_END_PROTOS
|
||||
|
||||
#define XP_ASSERT(x) ((void)0)
|
||||
#define XP_STRCAT(a,b) strcat((a),(b))
|
||||
#define XP_STRCPY(a,b) strcpy((a),(b))
|
||||
#define XP_STRLEN(x) strlen(x)
|
||||
#define XP_SPRINTF sprintf
|
||||
@@ -88,34 +93,27 @@
|
||||
#define XP_MEMSET(d, c, l) memset((d), (c), (l))
|
||||
|
||||
#ifdef XP_PC
|
||||
#define XP_STRCASECMP(x,y) strcmpi((x),(y))
|
||||
|
||||
#ifdef XP_OS2
|
||||
#define XP_STRCASECMP(x,y) stricmp((x),(y))
|
||||
#define XP_STRNCASECMP(x,y,n) strnicmp((x),(y),(n))
|
||||
#else
|
||||
#define XP_STRNCASECMP(x,y,n) strncmpi((x),(y),(n))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef XP_MAC
|
||||
#if defined(XP_MAC) || defined(XP_UNIX)
|
||||
#define XP_STRCASECMP(x,y) strcasecmp((x),(y))
|
||||
#define XP_STRNCASECMP(x,y,n) strncasecmp((x),(y),(n))
|
||||
extern int strcasecmp(const char *str1, const char *str2);
|
||||
extern int strncasecmp(const char *str1, const char *str2, int length);
|
||||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define XP_STRCASECMP strcasecomp /* from libxp.a */
|
||||
extern int vr_strcasecmp(const char *str1, const char *str2);
|
||||
extern int vr_strncasecmp(const char *str1, const char *str2, int length);
|
||||
#endif
|
||||
|
||||
typedef FILE * XP_File;
|
||||
|
||||
#ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
|
||||
typedef long int32;
|
||||
typedef unsigned long uint32;
|
||||
typedef short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned char uint8;
|
||||
#endif
|
||||
|
||||
typedef char Bool;
|
||||
typedef int XP_Bool;
|
||||
@@ -128,7 +126,10 @@ typedef int XP_Bool;
|
||||
#define XP_Stat(file,data,type) stat((file),(data))
|
||||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
extern XP_File VR_StubOpen (const char *name, const char * mode);
|
||||
#else
|
||||
extern XP_File VR_StubOpen (const char * mode);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _VR_STUBS_H_ */
|
||||
|
||||
@@ -15,6 +15,6 @@
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ..
|
||||
DIRS = src
|
||||
DIRS = src tests
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
@@ -47,6 +47,20 @@ NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Break: at file %s, line %d", aFile, aLine));
|
||||
PR_LogFlush();
|
||||
//XXX this works on win32 only for now. For all the other platforms call Abort
|
||||
#if defined(_WIN32)
|
||||
::DebugBreak();
|
||||
#else
|
||||
Abort(aFile, aLine);
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
@@ -54,7 +68,7 @@ NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("PreCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
|
||||
@@ -64,7 +78,7 @@ NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("PostCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
|
||||
@@ -74,7 +88,7 @@ NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Assertion: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
|
||||
@@ -84,7 +98,7 @@ NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("NotYetImplemented: \"%s\" at file %s, line %d", aMessage,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::NotReached(const char* aMessage,
|
||||
@@ -93,7 +107,7 @@ NS_COM void nsDebug::NotReached(const char* aMessage,
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("NotReached: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Error(const char* aMessage,
|
||||
@@ -102,7 +116,7 @@ NS_COM void nsDebug::Error(const char* aMessage,
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Error: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Warning(const char* aMessage,
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "prlink.h"
|
||||
#include "nsRepository.h"
|
||||
#ifdef USE_NSREG
|
||||
#define STANDALONE_REGISTRY
|
||||
#define XP_BEGIN_PROTOS extern "C" {
|
||||
#define XP_END_PROTOS };
|
||||
#include "NSReg.h"
|
||||
@@ -31,7 +30,6 @@
|
||||
nsHashtable *NSRepository::factories = NULL;
|
||||
PRMonitor *NSRepository::monitor = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kFactory2IID, NS_IFACTORY2_IID);
|
||||
|
||||
class FactoryEntry {
|
||||
@@ -74,15 +72,15 @@ public:
|
||||
id = aID;
|
||||
}
|
||||
|
||||
PRUint32 HashValue() {
|
||||
PRUint32 HashValue(void) const {
|
||||
return id.m0;
|
||||
}
|
||||
|
||||
PRBool Equals(nsHashKey *aKey) {
|
||||
return (id.Equals(((IDKey *) aKey)->id));
|
||||
PRBool Equals(const nsHashKey *aKey) const {
|
||||
return (id.Equals(((const IDKey *) aKey)->id));
|
||||
}
|
||||
|
||||
nsHashKey *Clone() {
|
||||
nsHashKey *Clone(void) const {
|
||||
return new IDKey(id);
|
||||
}
|
||||
};
|
||||
@@ -97,15 +95,16 @@ static nsresult platformRegister(const nsCID &aCID, const char *aLibrary)
|
||||
if (err == REGERR_OK) {
|
||||
RKEY key;
|
||||
err = NR_RegAddKey(hreg, ROOTKEY_COMMON,
|
||||
"SOFTWARE\\Netscape\\CID", &key);
|
||||
"Classes", &key);
|
||||
if (err == REGERR_OK) {
|
||||
char *cidString = aCID.ToString();
|
||||
NR_RegSetEntryString(hreg, key, cidString, (char *) aLibrary);
|
||||
err = NR_RegSetEntryString(hreg, key, cidString, (char *) aLibrary);
|
||||
delete [] cidString;
|
||||
}
|
||||
NR_RegClose(hreg);
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static nsresult platformUnregister(const nsCID &aCID, const char *aLibrary)
|
||||
@@ -115,15 +114,15 @@ static nsresult platformUnregister(const nsCID &aCID, const char *aLibrary)
|
||||
if (err == REGERR_OK) {
|
||||
RKEY key;
|
||||
err = NR_RegAddKey(hreg, ROOTKEY_COMMON,
|
||||
"SOFTWARE\\Netscape\\CID", &key);
|
||||
"Classes", &key);
|
||||
if (err == REGERR_OK) {
|
||||
char *cidString = aCID.ToString();
|
||||
NR_RegDeleteEntry(hreg, key, cidString);
|
||||
err = NR_RegDeleteEntry(hreg, key, cidString);
|
||||
delete [] cidString;
|
||||
}
|
||||
NR_RegClose(hreg);
|
||||
}
|
||||
return NS_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
static FactoryEntry *platformFind(const nsCID &aCID)
|
||||
@@ -134,11 +133,11 @@ static FactoryEntry *platformFind(const nsCID &aCID)
|
||||
if (err == REGERR_OK) {
|
||||
RKEY key;
|
||||
err = NR_RegGetKey(hreg, ROOTKEY_COMMON,
|
||||
"SOFTWARE\\Netscape\\CID", &key);
|
||||
"SOFTWARE/Netscape/CID", &key);
|
||||
if (err == REGERR_OK) {
|
||||
char *cidString = aCID.ToString();
|
||||
char library[_MAX_PATH];
|
||||
uint32 len = _MAX_PATH;
|
||||
char library[256];
|
||||
uint32 len = 256;
|
||||
err = NR_RegGetEntryString(hreg, key, cidString, library, len);
|
||||
|
||||
delete [] cidString;
|
||||
@@ -291,6 +290,9 @@ nsresult NSRepository::Initialize()
|
||||
monitor = PR_NewMonitor();
|
||||
}
|
||||
|
||||
#ifdef USE_NSREG
|
||||
NR_StartupRegistry();
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
|
||||
static PR_CALLBACK PLHashNumber _hashValue(const void *key)
|
||||
{
|
||||
return ((nsHashKey *) key)->HashValue();
|
||||
return ((const nsHashKey *) key)->HashValue();
|
||||
}
|
||||
|
||||
static PR_CALLBACK PRIntn _hashKeyCompare(const void *key1, const void *key2) {
|
||||
return ((nsHashKey *) key1)->Equals((nsHashKey *) key2);
|
||||
return ((const nsHashKey *) key1)->Equals((const nsHashKey *) key2);
|
||||
}
|
||||
|
||||
static PR_CALLBACK PRIntn _hashValueCompare(const void *value1,
|
||||
|
||||
307
mozilla/xpcom/ds/nsSupportsArray.cpp
Normal file
307
mozilla/xpcom/ds/nsSupportsArray.cpp
Normal file
@@ -0,0 +1,307 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsArrayIID, NS_ISUPPORTSARRAY_IID);
|
||||
|
||||
class SupportsArrayImpl : public nsISupportsArray {
|
||||
public:
|
||||
SupportsArrayImpl(void);
|
||||
~SupportsArrayImpl(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD_(nsISupportsArray&) operator=(const nsISupportsArray& aOther);
|
||||
NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& aOther) const { return Equals(&aOther); }
|
||||
NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* aOther) const;
|
||||
|
||||
NS_IMETHOD_(PRInt32) Count(void) const { return mCount; }
|
||||
|
||||
NS_IMETHOD_(nsISupports*) ElementAt(PRInt32 aIndex) const;
|
||||
NS_IMETHOD_(nsISupports*) operator[](PRInt32 aIndex) const { return ElementAt(aIndex); }
|
||||
|
||||
NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex = 0) const;
|
||||
NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRInt32 aIndex);
|
||||
|
||||
NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex);
|
||||
|
||||
NS_IMETHOD_(PRBool) AppendElement(nsISupports* aElement) {
|
||||
return InsertElementAt(aElement, mCount);
|
||||
}
|
||||
|
||||
NS_IMETHOD_(PRBool) RemoveElementAt(PRInt32 aIndex);
|
||||
NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex = 0);
|
||||
NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement);
|
||||
NS_IMETHOD_(void) Clear(void);
|
||||
|
||||
NS_IMETHOD_(void) Compact(void);
|
||||
|
||||
protected:
|
||||
void DeleteArray(void);
|
||||
|
||||
nsISupports** mArray;
|
||||
PRInt32 mArraySize;
|
||||
PRInt32 mCount;
|
||||
|
||||
private:
|
||||
// Copy constructors are not allowed
|
||||
SupportsArrayImpl(const nsISupportsArray& other);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
static PRInt32 kGrowArrayBy = 8;
|
||||
|
||||
SupportsArrayImpl::SupportsArrayImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mArray = 0;
|
||||
mArraySize = 0;
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
SupportsArrayImpl::~SupportsArrayImpl()
|
||||
{
|
||||
DeleteArray();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(SupportsArrayImpl, kISupportsArrayIID);
|
||||
|
||||
void SupportsArrayImpl::DeleteArray(void)
|
||||
{
|
||||
if (0 != mArray) {
|
||||
Clear();
|
||||
delete[] mArray;
|
||||
mArray = 0;
|
||||
mArraySize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsISupportsArray& SupportsArrayImpl::operator=(const nsISupportsArray& aOther)
|
||||
{
|
||||
PRInt32 otherCount = aOther.Count();
|
||||
|
||||
if (otherCount > mArraySize) {
|
||||
DeleteArray();
|
||||
mArraySize = otherCount;
|
||||
mArray = new nsISupports*[mArraySize];
|
||||
}
|
||||
else {
|
||||
Clear();
|
||||
}
|
||||
mCount = otherCount;
|
||||
while (0 <= --otherCount) {
|
||||
mArray[otherCount] = aOther.ElementAt(otherCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::Equals(const nsISupportsArray* aOther) const
|
||||
{
|
||||
if (0 != aOther) {
|
||||
const SupportsArrayImpl* other = (const SupportsArrayImpl*)aOther;
|
||||
if (mCount == other->mCount) {
|
||||
PRInt32 index = mCount;
|
||||
while (0 <= --index) {
|
||||
if (mArray[index] != other->mArray[index]) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsISupports* SupportsArrayImpl::ElementAt(PRInt32 aIndex) const
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
nsISupports* element = mArray[aIndex];
|
||||
NS_ADDREF(element);
|
||||
return element;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 SupportsArrayImpl::IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex) const
|
||||
{
|
||||
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
|
||||
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
|
||||
const nsISupports** ep = (start + aStartIndex);
|
||||
const nsISupports** end = (start + mCount);
|
||||
while (ep < end) {
|
||||
if (aPossibleElement == *ep) {
|
||||
return (ep - start);
|
||||
}
|
||||
ep++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRInt32 SupportsArrayImpl::LastIndexOf(const nsISupports* aPossibleElement) const
|
||||
{
|
||||
if (0 < mCount) {
|
||||
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
|
||||
const nsISupports** ep = (start + mCount);
|
||||
while (start <= --ep) {
|
||||
if (aPossibleElement == *ep) {
|
||||
return (ep - start);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::InsertElementAt(nsISupports* aElement, PRInt32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex <= mCount)) {
|
||||
if (mArraySize < (mCount + 1)) { // need to grow the array
|
||||
mArraySize += kGrowArrayBy;
|
||||
nsISupports** oldArray = mArray;
|
||||
mArray = new nsISupports*[mArraySize];
|
||||
if (0 == mArray) { // ran out of memory
|
||||
mArray = oldArray;
|
||||
mArraySize -= kGrowArrayBy;
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (0 != oldArray) { // need to move old data
|
||||
if (0 < aIndex) {
|
||||
::memcpy(mArray, oldArray, aIndex * sizeof(nsISupports*));
|
||||
}
|
||||
PRInt32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memcpy(mArray + aIndex + 1, oldArray + aIndex, slide * sizeof(nsISupports*));
|
||||
}
|
||||
delete[] oldArray;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PRInt32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memmove(mArray + aIndex + 1, mArray + aIndex, slide * sizeof(nsISupports*));
|
||||
}
|
||||
}
|
||||
|
||||
mArray[aIndex] = aElement;
|
||||
NS_ADDREF(aElement);
|
||||
mCount++;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
NS_ADDREF(aElement); // addref first in case it's the same object!
|
||||
NS_RELEASE(mArray[aIndex]);
|
||||
mArray[aIndex] = aElement;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::RemoveElementAt(PRInt32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
NS_RELEASE(mArray[aIndex]);
|
||||
mCount--;
|
||||
PRInt32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memmove(mArray + aIndex, mArray + aIndex + 1,
|
||||
slide * sizeof(nsISupports*));
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex)
|
||||
{
|
||||
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
|
||||
nsISupports** ep = mArray;
|
||||
nsISupports** end = ep + mCount;
|
||||
while (ep < end) {
|
||||
if (*ep == aElement) {
|
||||
return RemoveElementAt(PRInt32(ep - mArray));
|
||||
}
|
||||
ep++;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::RemoveLastElement(const nsISupports* aElement)
|
||||
{
|
||||
if (0 < mCount) {
|
||||
nsISupports** ep = (mArray + mCount);
|
||||
while (mArray <= --ep) {
|
||||
if (*ep == aElement) {
|
||||
return RemoveElementAt(PRInt32(ep - mArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void SupportsArrayImpl::Clear(void)
|
||||
{
|
||||
while (0 <= --mCount) {
|
||||
NS_RELEASE(mArray[mCount]);
|
||||
}
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
void SupportsArrayImpl::Compact(void)
|
||||
{
|
||||
if (mArraySize != mCount) {
|
||||
nsISupports** oldArray = mArray;
|
||||
mArray = new nsISupports*[mCount];
|
||||
if (0 == mArray) {
|
||||
mArray = oldArray;
|
||||
return;
|
||||
}
|
||||
::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*));
|
||||
delete[] oldArray;
|
||||
mArraySize = mCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult)
|
||||
{
|
||||
if (aInstancePtrResult == 0) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
SupportsArrayImpl *it = new SupportsArrayImpl();
|
||||
|
||||
if (0 == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kISupportsArrayIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,20 @@ NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Break: at file %s, line %d", aFile, aLine));
|
||||
PR_LogFlush();
|
||||
//XXX this works on win32 only for now. For all the other platforms call Abort
|
||||
#if defined(_WIN32)
|
||||
::DebugBreak();
|
||||
#else
|
||||
Abort(aFile, aLine);
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
@@ -54,7 +68,7 @@ NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("PreCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
|
||||
@@ -64,7 +78,7 @@ NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("PostCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
|
||||
@@ -74,7 +88,7 @@ NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Assertion: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
|
||||
@@ -84,7 +98,7 @@ NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("NotYetImplemented: \"%s\" at file %s, line %d", aMessage,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::NotReached(const char* aMessage,
|
||||
@@ -93,7 +107,7 @@ NS_COM void nsDebug::NotReached(const char* aMessage,
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("NotReached: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Error(const char* aMessage,
|
||||
@@ -102,7 +116,7 @@ NS_COM void nsDebug::Error(const char* aMessage,
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Error: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Warning(const char* aMessage,
|
||||
|
||||
@@ -20,6 +20,6 @@ IGNORE_MANIFEST=1
|
||||
#
|
||||
|
||||
DEPTH=..
|
||||
DIRS=src
|
||||
DIRS=src tests
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
@@ -22,20 +22,24 @@ LIBRARY_NAME = xpcom
|
||||
CPPSRCS = nsDebug.cpp \
|
||||
nsHashtable.cpp \
|
||||
nsID.cpp \
|
||||
nsSupportsArray.cpp \
|
||||
nsRepository.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = nsAgg.h \
|
||||
nsCom.h \
|
||||
EXPORTS = nsCom.h \
|
||||
nsDebug.h \
|
||||
nsError.h \
|
||||
nsHashtable.h \
|
||||
nsID.h \
|
||||
nsIFactory.h \
|
||||
nsISupports.h \
|
||||
nsISupportsArray.h \
|
||||
nsRepository.h \
|
||||
nsIEnumerator.h \
|
||||
$(NULL)
|
||||
|
||||
DEFINES = -D_IMPL_NS_COM
|
||||
LCFLAGS = -D_IMPL_NS_COM -DUSE_NSREG
|
||||
|
||||
REQUIRES = libreg
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
@@ -21,38 +21,45 @@ MAKE_OBJ_TYPE = DLL
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
LINCS = \
|
||||
-I$(PUBLIC)\libreg \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(DIST)\lib\libreg32.lib \
|
||||
$(NULL)
|
||||
|
||||
LIBNAME = .\$(OBJDIR)\xpcom$(MOZ_BITS)
|
||||
DLL = $(LIBNAME).dll
|
||||
|
||||
LCFLAGS = -D_IMPL_NS_COM
|
||||
|
||||
REQUIRES =
|
||||
LCFLAGS = -D_IMPL_NS_COM -DUSE_NSREG
|
||||
|
||||
CPPSRCS = \
|
||||
nsDebug.cpp \
|
||||
nsHashtable.cpp \
|
||||
nsID.cpp \
|
||||
nsRepository.cpp \
|
||||
|
||||
nsSupportsArray.cpp \
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsDebug.obj \
|
||||
.\$(OBJDIR)\nsHashtable.obj \
|
||||
.\$(OBJDIR)\nsID.obj \
|
||||
.\$(OBJDIR)\nsSupportsArray.obj \
|
||||
.\$(OBJDIR)\nsRepository.obj \
|
||||
|
||||
EXPORTS = \
|
||||
nsAgg.h \
|
||||
nsCom.h \
|
||||
nsDebug.h \
|
||||
nsError.h \
|
||||
nsHashtable.h \
|
||||
nsID.h \
|
||||
nsIFactory.h \
|
||||
nsISupports.h \
|
||||
nsISupportsArray.h \
|
||||
nsRepository.h \
|
||||
nsIEnumerator.h \
|
||||
$(NULL)
|
||||
@@ -62,6 +69,7 @@ MODULE = xpcom
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib
|
||||
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ protected: \
|
||||
\
|
||||
/* You must implement this operation instead of the nsISupports */ \
|
||||
/* methods if you inherit from nsAggregated. */ \
|
||||
NS_IMETHOD AggregatedQueryInterface(const nsIID& aIID, \
|
||||
void** aInstancePtr); \
|
||||
NS_IMETHOD \
|
||||
AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr); \
|
||||
\
|
||||
class Internal : public nsISupports { \
|
||||
public: \
|
||||
@@ -38,7 +38,7 @@ protected: \
|
||||
Internal() {} \
|
||||
\
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, \
|
||||
void** aInstancePtr); \
|
||||
void** aInstancePtr); \
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void); \
|
||||
NS_IMETHOD_(nsrefcnt) Release(void); \
|
||||
\
|
||||
@@ -60,7 +60,7 @@ public: \
|
||||
|
||||
// Put this in your class's implementation file:
|
||||
#define NS_IMPL_AGGREGATED(_class) \
|
||||
NS_METHOD \
|
||||
NS_IMETHODIMP \
|
||||
_class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); \
|
||||
@@ -74,7 +74,7 @@ _class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
|
||||
return AggregatedQueryInterface(aIID, aInstancePtr); \
|
||||
} \
|
||||
\
|
||||
NS_METHOD_(nsrefcnt) \
|
||||
NS_IMETHODIMP_(nsrefcnt) \
|
||||
_class::AddRef(void) \
|
||||
{ \
|
||||
if (fOuter) \
|
||||
@@ -83,7 +83,7 @@ _class::AddRef(void) \
|
||||
return ++mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_METHOD_(nsrefcnt) \
|
||||
NS_IMETHODIMP_(nsrefcnt) \
|
||||
_class::Release(void) \
|
||||
{ \
|
||||
if (fOuter) \
|
||||
@@ -97,21 +97,21 @@ _class::Release(void) \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
NS_METHOD \
|
||||
NS_IMETHODIMP \
|
||||
_class::Internal::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
|
||||
return agg->AggregatedQueryInterface(aIID, aInstancePtr); \
|
||||
} \
|
||||
\
|
||||
NS_METHOD \
|
||||
NS_IMETHODIMP_(nsrefcnt) \
|
||||
_class::Internal::AddRef(void) \
|
||||
{ \
|
||||
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
|
||||
return ++agg->mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_METHOD \
|
||||
NS_IMETHODIMP_(nsrefcnt) \
|
||||
_class::Internal::Release(void) \
|
||||
{ \
|
||||
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
|
||||
|
||||
@@ -24,41 +24,50 @@
|
||||
*/
|
||||
|
||||
#ifdef _IMPL_NS_COM
|
||||
# ifdef XP_PC
|
||||
# define NS_COM _declspec(dllexport)
|
||||
# else // !XP_PC
|
||||
# define NS_COM
|
||||
# endif // !XP_PC
|
||||
#ifdef XP_PC
|
||||
#define NS_COM _declspec(dllexport)
|
||||
#else // !XP_PC
|
||||
#define NS_COM
|
||||
#endif // !XP_PC
|
||||
#else // !_IMPL_NS_COM
|
||||
# ifdef XP_PC
|
||||
# define NS_COM _declspec(dllimport)
|
||||
# else // !XP_PC
|
||||
# define NS_COM
|
||||
# endif // !XP_PC
|
||||
#ifdef XP_PC
|
||||
#define NS_COM _declspec(dllimport)
|
||||
#else // !XP_PC
|
||||
#define NS_COM
|
||||
#endif // !XP_PC
|
||||
#endif // !_IMPL_NS_COM
|
||||
|
||||
/*
|
||||
* DLL Export macro
|
||||
*/
|
||||
|
||||
#ifndef NS_EXPORT
|
||||
# ifdef XP_PC
|
||||
# define NS_EXPORT _declspec(dllexport)
|
||||
# else // !XP_PC
|
||||
# define NS_EXPORT
|
||||
# endif // !XP_PC
|
||||
#endif // !NS_EXPORT
|
||||
|
||||
#ifdef XP_PC
|
||||
# define NS_METHOD_(Type) Type __stdcall
|
||||
# define NS_METHOD nsresult __stdcall
|
||||
#else // !XP_PC
|
||||
# define NS_METHOD_(Type) Type
|
||||
# define NS_METHOD nsresult
|
||||
#endif // !XP_PC
|
||||
|
||||
#define NS_IMETHOD_(Type) virtual NS_METHOD_(Type)
|
||||
#define NS_IMETHOD virtual NS_METHOD
|
||||
#define NS_EXPORT _declspec(dllexport)
|
||||
#define NS_EXPORT_(type) _declspec(dllexport) type __stdcall
|
||||
|
||||
#define NS_IMETHOD_(type) virtual type __stdcall
|
||||
#define NS_IMETHOD virtual nsresult __stdcall
|
||||
#define NS_IMETHODIMP_(type) type __stdcall
|
||||
#define NS_IMETHODIMP nsresult __stdcall
|
||||
|
||||
#define NS_METHOD_(type) type __stdcall
|
||||
#define NS_METHOD nsresult __stdcall
|
||||
|
||||
#else // !XP_PC
|
||||
|
||||
#define NS_EXPORT
|
||||
#define NS_EXPORT_(type) type
|
||||
|
||||
#define NS_IMETHOD_(type) virtual type
|
||||
#define NS_IMETHOD virtual nsresult
|
||||
#define NS_IMETHODIMP_(type) type
|
||||
#define NS_IMETHODIMP nsresult
|
||||
|
||||
#define NS_METHOD_(type) type
|
||||
#define NS_METHOD nsresult
|
||||
|
||||
#endif // !XP_PC
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -47,6 +47,20 @@ NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Break: at file %s, line %d", aFile, aLine));
|
||||
PR_LogFlush();
|
||||
//XXX this works on win32 only for now. For all the other platforms call Abort
|
||||
#if defined(_WIN32)
|
||||
::DebugBreak();
|
||||
#else
|
||||
Abort(aFile, aLine);
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
@@ -54,7 +68,7 @@ NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("PreCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
|
||||
@@ -64,7 +78,7 @@ NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("PostCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
|
||||
@@ -74,7 +88,7 @@ NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Assertion: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
|
||||
@@ -84,7 +98,7 @@ NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("NotYetImplemented: \"%s\" at file %s, line %d", aMessage,
|
||||
aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::NotReached(const char* aMessage,
|
||||
@@ -93,7 +107,7 @@ NS_COM void nsDebug::NotReached(const char* aMessage,
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("NotReached: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Error(const char* aMessage,
|
||||
@@ -102,7 +116,7 @@ NS_COM void nsDebug::Error(const char* aMessage,
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Error: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
Abort(aFile, aLine);
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Warning(const char* aMessage,
|
||||
|
||||
@@ -41,6 +41,11 @@ public:
|
||||
*/
|
||||
static NS_COM void Abort(const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Break the executing program into the debugger.
|
||||
*/
|
||||
static NS_COM void Break(const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Log a pre-condition message to the debug log
|
||||
*/
|
||||
@@ -101,6 +106,15 @@ if (!(expr)) \
|
||||
if (!(expr)) \
|
||||
nsDebug::Assertion(str, #expr, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Test an assertion for truth. If the expression is not true then
|
||||
* trigger a program failure. The expression will still be
|
||||
* executed in release mode.
|
||||
*/
|
||||
#define NS_VERIFY(expr,str) \
|
||||
if (!(expr)) \
|
||||
nsDebug::Assertion(str, #expr, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Test a post-condition for truth. If the expression is not true then
|
||||
* trigger a program failure.
|
||||
@@ -141,16 +155,24 @@ if (!(expr)) \
|
||||
#define NS_ABORT() \
|
||||
nsDebug::Abort(__FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Cause a break
|
||||
*/
|
||||
#define NS_BREAK() \
|
||||
nsDebug::Break(__FILE__, __LINE__)
|
||||
|
||||
#else /* NS_DEBUG */
|
||||
|
||||
#define NS_PRECONDITION(expr,str) {}
|
||||
#define NS_ASSERTION(expr,str) {}
|
||||
#define NS_VERIFY(expr,str) expr
|
||||
#define NS_POSTCONDITION(expr,str) {}
|
||||
#define NS_NOTYETIMPLEMENTED(str) {}
|
||||
#define NS_NOTREACHED(str) {}
|
||||
#define NS_ERROR(str) {}
|
||||
#define NS_WARNING(str) {}
|
||||
#define NS_ABORT() {}
|
||||
#define NS_BREAK() {}
|
||||
|
||||
#endif /* ! NS_DEBUG */
|
||||
|
||||
|
||||
81
mozilla/xpcom/src/nsError.h
Normal file
81
mozilla/xpcom/src/nsError.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsError_h
|
||||
#define nsError_h
|
||||
|
||||
#define NS_FAILED(_nsresult) ((_nsresult) & 0x80000000)
|
||||
#define NS_SUCCEEDED(_nsresult) (!((_nsresult) & 0x80000000))
|
||||
|
||||
// Standard "it worked" return value
|
||||
#define NS_OK 0
|
||||
|
||||
#define NS_ERROR_BASE ((nsresult) 0xC1F30000)
|
||||
|
||||
// Returned when an instance is not initialized
|
||||
#define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
|
||||
|
||||
// Returned when an instance is already initialized
|
||||
#define NS_ERROR_ALREADY_INITIALIZED (NS_ERROR_BASE + 2)
|
||||
|
||||
// Returned by a not implemented function
|
||||
#define NS_ERROR_NOT_IMPLEMENTED ((nsresult) 0x80004001L)
|
||||
|
||||
// Returned when a given interface is not supported.
|
||||
#define NS_NOINTERFACE ((nsresult) 0x80004002L)
|
||||
#define NS_ERROR_NO_INTERFACE NS_NOINTERFACE
|
||||
|
||||
#define NS_ERROR_INVALID_POINTER ((nsresult) 0x80004003L)
|
||||
#define NS_ERROR_NULL_POINTER NS_ERROR_INVALID_POINTER
|
||||
|
||||
// Returned when a function aborts
|
||||
#define NS_ERROR_ABORT ((nsresult) 0x80004004L)
|
||||
|
||||
// Returned when a function fails
|
||||
#define NS_ERROR_FAILURE ((nsresult) 0x80004005L)
|
||||
|
||||
// Returned when an unexpected error occurs
|
||||
#define NS_ERROR_UNEXPECTED ((nsresult) 0x8000ffffL)
|
||||
|
||||
// Returned when a memory allocation failes
|
||||
#define NS_ERROR_OUT_OF_MEMORY ((nsresult) 0x8007000eL)
|
||||
|
||||
// Returned when an illegal value is passed
|
||||
#define NS_ERROR_ILLEGAL_VALUE ((nsresult) 0x80070057L)
|
||||
|
||||
// Returned when a class doesn't allow aggregation
|
||||
#define NS_ERROR_NO_AGGREGATION ((nsresult) 0x80040110L)
|
||||
|
||||
// Returned when a class doesn't allow aggregation
|
||||
#define NS_ERROR_NOT_AVAILABLE ((nsresult) 0x80040111L)
|
||||
|
||||
// Returned when a class is not registered
|
||||
#define NS_ERROR_FACTORY_NOT_REGISTERED ((nsresult) 0x80040154L)
|
||||
|
||||
// Returned when a dynamically loaded factory couldn't be found
|
||||
#define NS_ERROR_FACTORY_NOT_LOADED ((nsresult) 0x800401f8L)
|
||||
|
||||
// Returned when a factory doesn't support signatures
|
||||
#define NS_ERROR_FACTORY_NO_SIGNATURE_SUPPORT \
|
||||
(NS_ERROR_BASE + 0x101)
|
||||
|
||||
// Returned when a factory already is registered
|
||||
#define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
|
||||
static PR_CALLBACK PLHashNumber _hashValue(const void *key)
|
||||
{
|
||||
return ((nsHashKey *) key)->HashValue();
|
||||
return ((const nsHashKey *) key)->HashValue();
|
||||
}
|
||||
|
||||
static PR_CALLBACK PRIntn _hashKeyCompare(const void *key1, const void *key2) {
|
||||
return ((nsHashKey *) key1)->Equals((nsHashKey *) key2);
|
||||
return ((const nsHashKey *) key1)->Equals((const nsHashKey *) key2);
|
||||
}
|
||||
|
||||
static PR_CALLBACK PRIntn _hashValueCompare(const void *value1,
|
||||
|
||||
@@ -20,19 +20,20 @@
|
||||
#define nsHashtable_h__
|
||||
|
||||
#include "plhash.h"
|
||||
#include "nsCom.h"
|
||||
|
||||
class nsHashKey {
|
||||
public:
|
||||
virtual PRUint32 HashValue() = 0;
|
||||
virtual PRBool Equals(nsHashKey *aKey) = 0;
|
||||
virtual nsHashKey *Clone() = 0;
|
||||
virtual PRUint32 HashValue(void) const = 0;
|
||||
virtual PRBool Equals(const nsHashKey *aKey) const = 0;
|
||||
virtual nsHashKey *Clone(void) const = 0;
|
||||
};
|
||||
|
||||
// Enumerator callback function. Use
|
||||
|
||||
typedef PRBool (*nsHashtableEnumFunc)(nsHashKey *aKey, void *aData);
|
||||
|
||||
class nsHashtable {
|
||||
class NS_COM nsHashtable {
|
||||
private:
|
||||
// members
|
||||
PLHashTable *hashtable;
|
||||
|
||||
@@ -46,10 +46,10 @@ typedef nsID nsCID;
|
||||
class nsIFactory: public nsISupports {
|
||||
public:
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
REFNSIID aIID,
|
||||
void **aResult) = 0;
|
||||
|
||||
NS_IMETHOD_(void) LockFactory(PRBool aLock) = 0;
|
||||
NS_IMETHOD LockFactory(PRBool aLock) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
class nsIFactory2: public nsIFactory {
|
||||
public:
|
||||
NS_IMETHOD CreateInstance2(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
REFNSIID aIID,
|
||||
void *aSignature,
|
||||
void **aResult) = 0;
|
||||
};
|
||||
|
||||
@@ -21,17 +21,27 @@
|
||||
|
||||
#include "nsDebug.h"
|
||||
#include "nsID.h"
|
||||
#include "nsError.h"
|
||||
|
||||
// An "interface id" which can be used to uniquely identify a given
|
||||
// interface. Primarily used as an argument to nsISupports.QueryInterface
|
||||
// method.
|
||||
// interface.
|
||||
|
||||
typedef nsID nsIID;
|
||||
|
||||
#define REFNSIID const nsIID&
|
||||
|
||||
// Define an IID
|
||||
#define NS_DEFINE_IID(_name, _iidspec) \
|
||||
const nsIID _name = _iidspec
|
||||
|
||||
#ifdef NS_IMPL_IDS
|
||||
#define NS_DECLARE_ID(_name,m0,m1,m2,m30,m31,m32,m33,m34,m35,m36,m37) \
|
||||
extern "C" const nsID _name = {m0,m1,m2,{m30,m31,m32,m33,m34,m35,m36,m37}}
|
||||
#else
|
||||
#define NS_DECLARE_ID(_name,m0,m1,m2,m30,m31,m32,m33,m34,m35,m36,m37) \
|
||||
extern "C" const nsID _name
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// IID for the nsISupports interface
|
||||
@@ -40,30 +50,9 @@ typedef nsID nsIID;
|
||||
{ 0x00000000, 0x0000, 0x0000, \
|
||||
{0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} }
|
||||
|
||||
#define NS_FAILED(_nsresult) ((_nsresult) & 0x80000000)
|
||||
#define NS_SUCCEEDED(_nsresult) (!((_nsresult) & 0x80000000))
|
||||
|
||||
// Standard "it worked" return value
|
||||
#define NS_OK 0
|
||||
|
||||
#define NS_ERROR_BASE ((nsresult) 0xC1F30000)
|
||||
|
||||
// Some standard error codes we use
|
||||
#define NS_ERROR_OUT_OF_MEMORY (NS_ERROR_BASE + 0)
|
||||
#define NS_ERROR_NO_AGGREGATION (NS_ERROR_BASE + 1)
|
||||
#define NS_ERROR_NULL_POINTER (NS_ERROR_BASE + 2)
|
||||
#define NS_ERROR_ILLEGAL_VALUE (NS_ERROR_BASE + 3)
|
||||
#define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 4)
|
||||
#define NS_ERROR_ALREADY_INITIALIZED (NS_ERROR_BASE + 5)
|
||||
#define NS_ERROR_NOT_IMPLEMENTED (NS_ERROR_BASE + 6)
|
||||
|
||||
// Generic result data type
|
||||
typedef PRUint32 nsresult;
|
||||
|
||||
// This is returned by QueryInterface when a given interface is not
|
||||
// supported.
|
||||
#define NS_NOINTERFACE ((nsresult) 0x80004002L)
|
||||
|
||||
// Reference count values
|
||||
typedef PRUint32 nsrefcnt;
|
||||
|
||||
@@ -73,7 +62,7 @@ typedef PRUint32 nsrefcnt;
|
||||
// modelled after the win32 IUnknown API.
|
||||
class nsISupports {
|
||||
public:
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID,
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr) = 0;
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) = 0;
|
||||
@@ -87,7 +76,7 @@ public:
|
||||
// AddRef and QueryInterface methods.
|
||||
#define NS_DECL_ISUPPORTS \
|
||||
public: \
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, \
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, \
|
||||
void** aInstancePtr); \
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void); \
|
||||
NS_IMETHOD_(nsrefcnt) Release(void); \
|
||||
@@ -144,7 +133,7 @@ nsrefcnt _class::Release(void) \
|
||||
// _classiiddef is the name of the #define symbol that defines the IID
|
||||
// for the class (e.g. NS_ISUPPORTS_IID)
|
||||
#define NS_IMPL_QUERY_INTERFACE(_class,_classiiddef) \
|
||||
nsresult _class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
|
||||
nsresult _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
if (NULL == aInstancePtr) { \
|
||||
return NS_ERROR_NULL_POINTER; \
|
||||
|
||||
66
mozilla/xpcom/src/nsISupportsArray.h
Normal file
66
mozilla/xpcom/src/nsISupportsArray.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsISupportsArray_h___
|
||||
#define nsISupportsArray_h___
|
||||
|
||||
#include "nsCom.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
// {791eafa0-b9e6-11d1-8031-006008159b5a}
|
||||
#define NS_ISUPPORTSARRAY_IID \
|
||||
{0x791eafa0, 0xb9e6, 0x11d1, \
|
||||
{0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
|
||||
|
||||
class nsISupportsArray : public nsISupports {
|
||||
public:
|
||||
NS_IMETHOD_(nsISupportsArray&) operator=(const nsISupportsArray& other) = 0;
|
||||
NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& other) const = 0;
|
||||
NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* other) const = 0;
|
||||
|
||||
NS_IMETHOD_(PRInt32) Count(void) const = 0;
|
||||
|
||||
NS_IMETHOD_(nsISupports*) ElementAt(PRInt32 aIndex) const = 0;
|
||||
NS_IMETHOD_(nsISupports*) operator[](PRInt32 aIndex) const = 0;
|
||||
|
||||
NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex = 0) const = 0;
|
||||
NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement) const = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRInt32 aIndex) = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex) = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) AppendElement(nsISupports* aElement) = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) RemoveElementAt(PRInt32 aIndex) = 0;
|
||||
NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex = 0) = 0;
|
||||
NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement) = 0;
|
||||
NS_IMETHOD_(void) Clear(void) = 0;
|
||||
|
||||
NS_IMETHOD_(void) Compact(void) = 0;
|
||||
|
||||
private:
|
||||
// Copy constructors are not allowed
|
||||
// XXX test wether this has to be here nsISupportsArray(const nsISupportsArray& other);
|
||||
};
|
||||
|
||||
extern NS_COM nsresult
|
||||
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult);
|
||||
|
||||
|
||||
#endif // nsISupportsArray_h___
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "prlink.h"
|
||||
#include "nsRepository.h"
|
||||
#ifdef USE_NSREG
|
||||
#define STANDALONE_REGISTRY
|
||||
#define XP_BEGIN_PROTOS extern "C" {
|
||||
#define XP_END_PROTOS };
|
||||
#include "NSReg.h"
|
||||
@@ -31,7 +30,6 @@
|
||||
nsHashtable *NSRepository::factories = NULL;
|
||||
PRMonitor *NSRepository::monitor = NULL;
|
||||
|
||||
static NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kFactory2IID, NS_IFACTORY2_IID);
|
||||
|
||||
class FactoryEntry {
|
||||
@@ -74,15 +72,15 @@ public:
|
||||
id = aID;
|
||||
}
|
||||
|
||||
PRUint32 HashValue() {
|
||||
PRUint32 HashValue(void) const {
|
||||
return id.m0;
|
||||
}
|
||||
|
||||
PRBool Equals(nsHashKey *aKey) {
|
||||
return (id.Equals(((IDKey *) aKey)->id));
|
||||
PRBool Equals(const nsHashKey *aKey) const {
|
||||
return (id.Equals(((const IDKey *) aKey)->id));
|
||||
}
|
||||
|
||||
nsHashKey *Clone() {
|
||||
nsHashKey *Clone(void) const {
|
||||
return new IDKey(id);
|
||||
}
|
||||
};
|
||||
@@ -97,15 +95,16 @@ static nsresult platformRegister(const nsCID &aCID, const char *aLibrary)
|
||||
if (err == REGERR_OK) {
|
||||
RKEY key;
|
||||
err = NR_RegAddKey(hreg, ROOTKEY_COMMON,
|
||||
"SOFTWARE\\Netscape\\CID", &key);
|
||||
"Classes", &key);
|
||||
if (err == REGERR_OK) {
|
||||
char *cidString = aCID.ToString();
|
||||
NR_RegSetEntryString(hreg, key, cidString, (char *) aLibrary);
|
||||
err = NR_RegSetEntryString(hreg, key, cidString, (char *) aLibrary);
|
||||
delete [] cidString;
|
||||
}
|
||||
NR_RegClose(hreg);
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static nsresult platformUnregister(const nsCID &aCID, const char *aLibrary)
|
||||
@@ -115,15 +114,15 @@ static nsresult platformUnregister(const nsCID &aCID, const char *aLibrary)
|
||||
if (err == REGERR_OK) {
|
||||
RKEY key;
|
||||
err = NR_RegAddKey(hreg, ROOTKEY_COMMON,
|
||||
"SOFTWARE\\Netscape\\CID", &key);
|
||||
"Classes", &key);
|
||||
if (err == REGERR_OK) {
|
||||
char *cidString = aCID.ToString();
|
||||
NR_RegDeleteEntry(hreg, key, cidString);
|
||||
err = NR_RegDeleteEntry(hreg, key, cidString);
|
||||
delete [] cidString;
|
||||
}
|
||||
NR_RegClose(hreg);
|
||||
}
|
||||
return NS_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
static FactoryEntry *platformFind(const nsCID &aCID)
|
||||
@@ -134,11 +133,11 @@ static FactoryEntry *platformFind(const nsCID &aCID)
|
||||
if (err == REGERR_OK) {
|
||||
RKEY key;
|
||||
err = NR_RegGetKey(hreg, ROOTKEY_COMMON,
|
||||
"SOFTWARE\\Netscape\\CID", &key);
|
||||
"SOFTWARE/Netscape/CID", &key);
|
||||
if (err == REGERR_OK) {
|
||||
char *cidString = aCID.ToString();
|
||||
char library[_MAX_PATH];
|
||||
uint32 len = _MAX_PATH;
|
||||
char library[256];
|
||||
uint32 len = 256;
|
||||
err = NR_RegGetEntryString(hreg, key, cidString, library, len);
|
||||
|
||||
delete [] cidString;
|
||||
@@ -291,6 +290,9 @@ nsresult NSRepository::Initialize()
|
||||
monitor = PR_NewMonitor();
|
||||
}
|
||||
|
||||
#ifdef USE_NSREG
|
||||
NR_StartupRegistry();
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,28 +23,34 @@
|
||||
#include "prmon.h"
|
||||
#include "nsCom.h"
|
||||
#include "nsID.h"
|
||||
#include "nsError.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
/*
|
||||
* NSIRepository class
|
||||
* Prototypes for dynamic library export functions
|
||||
*/
|
||||
|
||||
// Errors
|
||||
#define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
|
||||
#define NS_ERROR_FACTORY_NOT_REGISTERED (NS_ERROR_BASE + 0x101)
|
||||
#define NS_ERROR_FACTORY_NOT_LOADED (NS_ERROR_BASE + 0x102)
|
||||
#define NS_ERROR_FACTORY_NO_SIGNATURE_SUPPORT (NS_ERROR_BASE + 0x103)
|
||||
#define NS_ERROR_FACTORY_NOT_UNREGISTERED (NS_ERROR_BASE + 0x104)
|
||||
extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" NS_EXPORT PRBool NSCanUnload(void);
|
||||
extern "C" NS_EXPORT nsresult NSRegisterSelf(const char *path);
|
||||
extern "C" NS_EXPORT nsresult NSUnregisterSelf(const char *path);
|
||||
|
||||
/*
|
||||
* Dynamic library export function types
|
||||
*/
|
||||
|
||||
typedef nsresult (*nsFactoryProc)(const nsCID &aCLass,
|
||||
nsIFactory **aFactory);
|
||||
typedef PRBool (*nsCanUnloadProc)();
|
||||
typedef PRBool (*nsCanUnloadProc)(void);
|
||||
typedef nsresult (*nsRegisterProc)(const char *path);
|
||||
typedef nsresult (*nsUnregisterProc)(const char *path);
|
||||
|
||||
class FactoryEntry;
|
||||
/*
|
||||
* NSRepository class
|
||||
*/
|
||||
|
||||
class NS_COM NSRepository {
|
||||
private:
|
||||
|
||||
307
mozilla/xpcom/src/nsSupportsArray.cpp
Normal file
307
mozilla/xpcom/src/nsSupportsArray.cpp
Normal file
@@ -0,0 +1,307 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsArrayIID, NS_ISUPPORTSARRAY_IID);
|
||||
|
||||
class SupportsArrayImpl : public nsISupportsArray {
|
||||
public:
|
||||
SupportsArrayImpl(void);
|
||||
~SupportsArrayImpl(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD_(nsISupportsArray&) operator=(const nsISupportsArray& aOther);
|
||||
NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& aOther) const { return Equals(&aOther); }
|
||||
NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* aOther) const;
|
||||
|
||||
NS_IMETHOD_(PRInt32) Count(void) const { return mCount; }
|
||||
|
||||
NS_IMETHOD_(nsISupports*) ElementAt(PRInt32 aIndex) const;
|
||||
NS_IMETHOD_(nsISupports*) operator[](PRInt32 aIndex) const { return ElementAt(aIndex); }
|
||||
|
||||
NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex = 0) const;
|
||||
NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRInt32 aIndex);
|
||||
|
||||
NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex);
|
||||
|
||||
NS_IMETHOD_(PRBool) AppendElement(nsISupports* aElement) {
|
||||
return InsertElementAt(aElement, mCount);
|
||||
}
|
||||
|
||||
NS_IMETHOD_(PRBool) RemoveElementAt(PRInt32 aIndex);
|
||||
NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex = 0);
|
||||
NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement);
|
||||
NS_IMETHOD_(void) Clear(void);
|
||||
|
||||
NS_IMETHOD_(void) Compact(void);
|
||||
|
||||
protected:
|
||||
void DeleteArray(void);
|
||||
|
||||
nsISupports** mArray;
|
||||
PRInt32 mArraySize;
|
||||
PRInt32 mCount;
|
||||
|
||||
private:
|
||||
// Copy constructors are not allowed
|
||||
SupportsArrayImpl(const nsISupportsArray& other);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
static PRInt32 kGrowArrayBy = 8;
|
||||
|
||||
SupportsArrayImpl::SupportsArrayImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mArray = 0;
|
||||
mArraySize = 0;
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
SupportsArrayImpl::~SupportsArrayImpl()
|
||||
{
|
||||
DeleteArray();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(SupportsArrayImpl, kISupportsArrayIID);
|
||||
|
||||
void SupportsArrayImpl::DeleteArray(void)
|
||||
{
|
||||
if (0 != mArray) {
|
||||
Clear();
|
||||
delete[] mArray;
|
||||
mArray = 0;
|
||||
mArraySize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsISupportsArray& SupportsArrayImpl::operator=(const nsISupportsArray& aOther)
|
||||
{
|
||||
PRInt32 otherCount = aOther.Count();
|
||||
|
||||
if (otherCount > mArraySize) {
|
||||
DeleteArray();
|
||||
mArraySize = otherCount;
|
||||
mArray = new nsISupports*[mArraySize];
|
||||
}
|
||||
else {
|
||||
Clear();
|
||||
}
|
||||
mCount = otherCount;
|
||||
while (0 <= --otherCount) {
|
||||
mArray[otherCount] = aOther.ElementAt(otherCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::Equals(const nsISupportsArray* aOther) const
|
||||
{
|
||||
if (0 != aOther) {
|
||||
const SupportsArrayImpl* other = (const SupportsArrayImpl*)aOther;
|
||||
if (mCount == other->mCount) {
|
||||
PRInt32 index = mCount;
|
||||
while (0 <= --index) {
|
||||
if (mArray[index] != other->mArray[index]) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsISupports* SupportsArrayImpl::ElementAt(PRInt32 aIndex) const
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
nsISupports* element = mArray[aIndex];
|
||||
NS_ADDREF(element);
|
||||
return element;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 SupportsArrayImpl::IndexOf(const nsISupports* aPossibleElement, PRInt32 aStartIndex) const
|
||||
{
|
||||
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
|
||||
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
|
||||
const nsISupports** ep = (start + aStartIndex);
|
||||
const nsISupports** end = (start + mCount);
|
||||
while (ep < end) {
|
||||
if (aPossibleElement == *ep) {
|
||||
return (ep - start);
|
||||
}
|
||||
ep++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRInt32 SupportsArrayImpl::LastIndexOf(const nsISupports* aPossibleElement) const
|
||||
{
|
||||
if (0 < mCount) {
|
||||
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
|
||||
const nsISupports** ep = (start + mCount);
|
||||
while (start <= --ep) {
|
||||
if (aPossibleElement == *ep) {
|
||||
return (ep - start);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::InsertElementAt(nsISupports* aElement, PRInt32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex <= mCount)) {
|
||||
if (mArraySize < (mCount + 1)) { // need to grow the array
|
||||
mArraySize += kGrowArrayBy;
|
||||
nsISupports** oldArray = mArray;
|
||||
mArray = new nsISupports*[mArraySize];
|
||||
if (0 == mArray) { // ran out of memory
|
||||
mArray = oldArray;
|
||||
mArraySize -= kGrowArrayBy;
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (0 != oldArray) { // need to move old data
|
||||
if (0 < aIndex) {
|
||||
::memcpy(mArray, oldArray, aIndex * sizeof(nsISupports*));
|
||||
}
|
||||
PRInt32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memcpy(mArray + aIndex + 1, oldArray + aIndex, slide * sizeof(nsISupports*));
|
||||
}
|
||||
delete[] oldArray;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PRInt32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memmove(mArray + aIndex + 1, mArray + aIndex, slide * sizeof(nsISupports*));
|
||||
}
|
||||
}
|
||||
|
||||
mArray[aIndex] = aElement;
|
||||
NS_ADDREF(aElement);
|
||||
mCount++;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::ReplaceElementAt(nsISupports* aElement, PRInt32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
NS_ADDREF(aElement); // addref first in case it's the same object!
|
||||
NS_RELEASE(mArray[aIndex]);
|
||||
mArray[aIndex] = aElement;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::RemoveElementAt(PRInt32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
NS_RELEASE(mArray[aIndex]);
|
||||
mCount--;
|
||||
PRInt32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memmove(mArray + aIndex, mArray + aIndex + 1,
|
||||
slide * sizeof(nsISupports*));
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::RemoveElement(const nsISupports* aElement, PRInt32 aStartIndex)
|
||||
{
|
||||
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
|
||||
nsISupports** ep = mArray;
|
||||
nsISupports** end = ep + mCount;
|
||||
while (ep < end) {
|
||||
if (*ep == aElement) {
|
||||
return RemoveElementAt(PRInt32(ep - mArray));
|
||||
}
|
||||
ep++;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool SupportsArrayImpl::RemoveLastElement(const nsISupports* aElement)
|
||||
{
|
||||
if (0 < mCount) {
|
||||
nsISupports** ep = (mArray + mCount);
|
||||
while (mArray <= --ep) {
|
||||
if (*ep == aElement) {
|
||||
return RemoveElementAt(PRInt32(ep - mArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void SupportsArrayImpl::Clear(void)
|
||||
{
|
||||
while (0 <= --mCount) {
|
||||
NS_RELEASE(mArray[mCount]);
|
||||
}
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
void SupportsArrayImpl::Compact(void)
|
||||
{
|
||||
if (mArraySize != mCount) {
|
||||
nsISupports** oldArray = mArray;
|
||||
mArray = new nsISupports*[mCount];
|
||||
if (0 == mArray) {
|
||||
mArray = oldArray;
|
||||
return;
|
||||
}
|
||||
::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*));
|
||||
delete[] oldArray;
|
||||
mArraySize = mCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult)
|
||||
{
|
||||
if (aInstancePtrResult == 0) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
SupportsArrayImpl *it = new SupportsArrayImpl();
|
||||
|
||||
if (0 == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kISupportsArrayIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
@@ -20,17 +20,19 @@ DEPTH=../..
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
RegFactory.cpp \
|
||||
TestFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
INCLUDES=-I../src
|
||||
INCLUDES=-I../src -I$(DIST)/include
|
||||
|
||||
DIRS = dynamic
|
||||
|
||||
OBJS = $(CPPSRCS:.cpp=.o)
|
||||
|
||||
EX_LIBS = \
|
||||
$(DIST)/lib/libxpcom.a \
|
||||
$(DIST)/bin/libreg.so \
|
||||
$(DIST)/bin/libxpcom.so \
|
||||
$(DIST)/lib/libplc21.a \
|
||||
$(DIST)/lib/libplds21.a \
|
||||
$(DIST)/lib/libnspr21.a \
|
||||
@@ -45,7 +47,7 @@ include $(DEPTH)/config/rules.mk
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CCC) -o $@ $(CFLAGS) -c $*.cpp
|
||||
$(CCC) -o $@ $(CFLAGS) -DUSE_NSREG -c $*.cpp
|
||||
|
||||
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS)
|
||||
@$(MAKE_OBJDIR)
|
||||
@@ -53,6 +55,6 @@ $(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS)
|
||||
|
||||
export::
|
||||
|
||||
instal:: $(TARGETS)
|
||||
$(INSTALL) NON_DIRS $(DIST)/bin
|
||||
install:: $(PROGS)
|
||||
$(INSTALL) $(PROGS) $(DIST)/bin
|
||||
|
||||
|
||||
@@ -23,6 +23,25 @@
|
||||
|
||||
static PRBool gUnreg = PR_FALSE;
|
||||
|
||||
void print_err(nsresult err)
|
||||
{
|
||||
switch (err) {
|
||||
case NS_ERROR_FACTORY_NOT_LOADED:
|
||||
cerr << "Factory not loaded";
|
||||
break;
|
||||
case NS_NOINTERFACE:
|
||||
cerr << "No Interface";
|
||||
break;
|
||||
case NS_ERROR_NULL_POINTER:
|
||||
cerr << "Null pointer";
|
||||
break;
|
||||
case NS_ERROR_OUT_OF_MEMORY:
|
||||
cerr << "Out of memory";
|
||||
break;
|
||||
default:
|
||||
cerr << hex << err << dec;
|
||||
}
|
||||
}
|
||||
PRLibrary *GetLib(const char *path) {
|
||||
return PR_LoadLibrary(path);
|
||||
}
|
||||
@@ -87,14 +106,18 @@ int ProcessArgs(int argc, char *argv[])
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
cout << "Successfully unregistered: " << argv[i] << "\n";
|
||||
} else {
|
||||
cerr << "Unregister failed (" << res << "): " << argv[i] << "\n";
|
||||
cerr << "Unregister failed (";
|
||||
print_err(res);
|
||||
cerr << "): " << argv[i] << "\n";
|
||||
}
|
||||
} else {
|
||||
res = Register(argv[i]);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
cout << "Successfully registered: " << argv[i] << "\n";
|
||||
} else {
|
||||
cerr << "Register failed (" << res << "): " << argv[i] << "\n";
|
||||
cerr << "Register failed (";
|
||||
print_err(res);
|
||||
cerr << "): " << argv[i] << "\n";
|
||||
}
|
||||
}
|
||||
i++;
|
||||
|
||||
196
mozilla/xpcom/tests/TestArray.cpp
Normal file
196
mozilla/xpcom/tests/TestArray.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
// {9e70a320-be02-11d1-8031-006008159b5a}
|
||||
#define NS_IFOO_IID \
|
||||
{0x9e70a320, 0xbe02, 0x11d1, \
|
||||
{0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
|
||||
|
||||
static const PRBool kExitOnError = PR_TRUE;
|
||||
|
||||
static NS_DEFINE_IID(kIFooIID, NS_IFOO_IID);
|
||||
|
||||
class IFoo : public nsISupports {
|
||||
public:
|
||||
IFoo(PRInt32 aID);
|
||||
~IFoo();
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
PRInt32 mRefCnt;
|
||||
PRInt32 mID;
|
||||
static PRInt32 gCount;
|
||||
};
|
||||
|
||||
PRInt32 IFoo::gCount;
|
||||
|
||||
IFoo::IFoo(PRInt32 aID)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mID = aID;
|
||||
gCount++;
|
||||
fprintf(stdout, "init: %d (%x), %d total)\n", mID, this, gCount);
|
||||
}
|
||||
|
||||
IFoo::~IFoo()
|
||||
{
|
||||
gCount--;
|
||||
fprintf(stdout, "destruct: %d (%x), %d remain)\n", mID, this, gCount);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(IFoo, NS_IFOO_IID);
|
||||
|
||||
const char* AssertEqual(PRInt32 aValue1, PRInt32 aValue2)
|
||||
{
|
||||
if (aValue1 == aValue2) {
|
||||
return "OK";
|
||||
}
|
||||
if (kExitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
void DumpArray(nsISupportsArray* aArray, PRInt32 aExpectedCount, PRInt32 aElementIDs[], PRInt32 aExpectedTotal)
|
||||
{
|
||||
PRInt32 count = aArray->Count();
|
||||
PRInt32 index;
|
||||
|
||||
fprintf(stdout, "object count %d = %d %s\n", IFoo::gCount, aExpectedTotal,
|
||||
AssertEqual(IFoo::gCount, aExpectedTotal));
|
||||
fprintf(stdout, "array count %d = %d %s\n", count, aExpectedCount,
|
||||
AssertEqual(count, aExpectedCount));
|
||||
|
||||
for (index = 0; (index < count) && (index < aExpectedCount); index++) {
|
||||
IFoo* foo = (IFoo*)(aArray->ElementAt(index));
|
||||
fprintf(stdout, "%2d: %d=%d (%x) c: %d %s\n",
|
||||
index, aElementIDs[index], foo->mID, foo, foo->mRefCnt - 1,
|
||||
AssertEqual(foo->mID, aElementIDs[index]));
|
||||
foo->Release();
|
||||
}
|
||||
}
|
||||
|
||||
void FillArray(nsISupportsArray* aArray, PRInt32 aCount)
|
||||
{
|
||||
PRInt32 index;
|
||||
for (index = 0; index < aCount; index++) {
|
||||
IFoo* foo = new IFoo(index);
|
||||
foo->AddRef();
|
||||
aArray->AppendElement(foo);
|
||||
foo->Release();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
nsISupportsArray* array;
|
||||
nsresult rv;
|
||||
|
||||
if (NS_OK == (rv = NS_NewISupportsArray(&array))) {
|
||||
FillArray(array, 10);
|
||||
fprintf(stdout, "Array created:\n");
|
||||
PRInt32 fillResult[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
DumpArray(array, 10, fillResult, 10);
|
||||
|
||||
// test insert
|
||||
IFoo* foo = (IFoo*)array->ElementAt(3);
|
||||
foo->Release(); // pre-release to fix ref count for dumps
|
||||
array->InsertElementAt(foo, 5);
|
||||
fprintf(stdout, "insert 3 at 5:\n");
|
||||
PRInt32 insertResult[11] = {0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9};
|
||||
DumpArray(array, 11, insertResult, 10);
|
||||
fprintf(stdout, "insert 3 at 0:\n");
|
||||
array->InsertElementAt(foo, 0);
|
||||
PRInt32 insertResult2[12] = {3, 0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9};
|
||||
DumpArray(array, 12, insertResult2, 10);
|
||||
fprintf(stdout, "append 3:\n");
|
||||
array->AppendElement(foo);
|
||||
PRInt32 appendResult[13] = {3, 0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9, 3};
|
||||
DumpArray(array, 13, appendResult, 10);
|
||||
|
||||
|
||||
// test IndexOf && LastIndexOf
|
||||
PRInt32 expectedIndex[5] = {0, 4, 6, 12, -1};
|
||||
PRInt32 count = 0;
|
||||
PRInt32 index = array->IndexOf(foo);
|
||||
fprintf(stdout, "IndexOf(foo): %d=%d %s\n", index, expectedIndex[count],
|
||||
AssertEqual(index, expectedIndex[count]));
|
||||
while (-1 != index) {
|
||||
count++;
|
||||
index = array->IndexOf(foo, index + 1);
|
||||
if (-1 != index)
|
||||
fprintf(stdout, "IndexOf(foo): %d=%d %s\n", index, expectedIndex[count],
|
||||
AssertEqual(index, expectedIndex[count]));
|
||||
}
|
||||
index = array->LastIndexOf(foo);
|
||||
count--;
|
||||
fprintf(stdout, "LastIndexOf(foo): %d=%d %s\n", index, expectedIndex[count],
|
||||
AssertEqual(index, expectedIndex[count]));
|
||||
|
||||
// test ReplaceElementAt
|
||||
fprintf(stdout, "ReplaceElementAt(8):\n");
|
||||
array->ReplaceElementAt(foo, 8);
|
||||
PRInt32 replaceResult[13] = {3, 0, 1, 2, 3, 4, 3, 5, 3, 7, 8, 9, 3};
|
||||
DumpArray(array, 13, replaceResult, 9);
|
||||
|
||||
// test RemoveElementAt, RemoveElement RemoveLastElement
|
||||
fprintf(stdout, "RemoveElementAt(0):\n");
|
||||
array->RemoveElementAt(0);
|
||||
PRInt32 removeResult[12] = {0, 1, 2, 3, 4, 3, 5, 3, 7, 8, 9, 3};
|
||||
DumpArray(array, 12, removeResult, 9);
|
||||
fprintf(stdout, "RemoveElementAt(7):\n");
|
||||
array->RemoveElementAt(7);
|
||||
PRInt32 removeResult2[11] = {0, 1, 2, 3, 4, 3, 5, 7, 8, 9, 3};
|
||||
DumpArray(array, 11, removeResult2, 9);
|
||||
fprintf(stdout, "RemoveElement(foo):\n");
|
||||
array->RemoveElement(foo);
|
||||
PRInt32 removeResult3[10] = {0, 1, 2, 4, 3, 5, 7, 8, 9, 3};
|
||||
DumpArray(array, 10, removeResult3, 9);
|
||||
fprintf(stdout, "RemoveLastElement(foo):\n");
|
||||
array->RemoveLastElement(foo);
|
||||
PRInt32 removeResult4[9] = {0, 1, 2, 4, 3, 5, 7, 8, 9};
|
||||
DumpArray(array, 9, removeResult4, 9);
|
||||
|
||||
// test clear
|
||||
fprintf(stdout, "clear array:\n");
|
||||
array->Clear();
|
||||
DumpArray(array, 0, 0, 0);
|
||||
fprintf(stdout, "add 4 new:\n");
|
||||
FillArray(array, 4);
|
||||
DumpArray(array, 4, fillResult, 4);
|
||||
|
||||
// test compact
|
||||
fprintf(stdout, "compact array:\n");
|
||||
array->Compact();
|
||||
DumpArray(array, 4, fillResult, 4);
|
||||
|
||||
// test delete
|
||||
fprintf(stdout, "release array:\n");
|
||||
NS_RELEASE(array);
|
||||
}
|
||||
else {
|
||||
fprintf(stdout, "error can't create array: %x\n", rv);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD_(void) LockFactory(PRBool aLock) {};
|
||||
NS_IMETHOD LockFactory(PRBool aLock) { return NS_OK; }
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(TestFactory, kFactoryIID);
|
||||
@@ -134,7 +134,7 @@ extern "C" void RegisterTestFactories() {
|
||||
PR_FALSE);
|
||||
|
||||
// Windows can use persistant registry
|
||||
#ifndef XP_PC
|
||||
#ifndef USE_NSREG
|
||||
NSRepository::RegisterFactory(kTestLoadedFactoryCID,
|
||||
"libtestdynamic.so",
|
||||
PR_FALSE,
|
||||
|
||||
@@ -27,9 +27,6 @@ NS_DEFINE_IID(kFactoryIID, NS_IFACTORY_IID);
|
||||
NS_DEFINE_CID(kTestLoadedFactoryCID, NS_TESTLOADEDFACTORY_CID);
|
||||
NS_DEFINE_IID(kTestClassIID, NS_ITESTCLASS_IID);
|
||||
|
||||
static PRInt32 g_InstanceCount = 0;
|
||||
static PRInt32 g_LockCount = 0;
|
||||
|
||||
/**
|
||||
* ITestClass implementation
|
||||
*/
|
||||
@@ -39,13 +36,7 @@ class TestDynamicClassImpl: public ITestClass {
|
||||
|
||||
TestDynamicClassImpl() {
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
~TestDynamicClassImpl() {
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
void Test();
|
||||
};
|
||||
|
||||
@@ -59,28 +50,32 @@ void TestDynamicClassImpl::Test() {
|
||||
* TestFactory implementation
|
||||
*/
|
||||
|
||||
static PRInt32 g_FactoryCount = 0;
|
||||
static PRInt32 g_LockCount = 0;
|
||||
|
||||
class TestDynamicFactory: public nsIFactory {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
TestDynamicFactory() {
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
PR_AtomicIncrement(&g_FactoryCount);
|
||||
}
|
||||
|
||||
~TestDynamicFactory() {
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
PR_AtomicDecrement(&g_FactoryCount);
|
||||
}
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD_(void) LockFactory(PRBool aLock) {
|
||||
NS_IMETHOD LockFactory(PRBool aLock) {
|
||||
if (aLock) {
|
||||
PR_AtomicIncrement(&g_LockCount);
|
||||
} else {
|
||||
PR_AtomicDecrement(&g_LockCount);
|
||||
}
|
||||
return NS_OK;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -128,7 +123,7 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aCID,
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT PRBool NSCanUnload() {
|
||||
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
|
||||
return PRBool(g_FactoryCount == 0 && g_LockCount == 0);
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSRegisterSelf(const char *path)
|
||||
|
||||
@@ -24,7 +24,12 @@ DIRS = dynamic windows
|
||||
MAKE_OBJ_TYPE = EXE
|
||||
PROG1 = .\$(OBJDIR)\TestFactory.exe
|
||||
PROG2 = .\$(OBJDIR)\RegFactory.exe
|
||||
PROGRAMS = $(PROG1) $(PROG2)
|
||||
PROG3 = .\$(OBJDIR)\TestArray.exe
|
||||
PROGRAMS = $(PROG1) $(PROG2) $(PROG3)
|
||||
|
||||
LCFLAGS=-DUSE_NSREG
|
||||
|
||||
REQUIRES=libreg
|
||||
|
||||
LINCS=-I..\src
|
||||
|
||||
@@ -59,4 +64,5 @@ clobber::
|
||||
|
||||
$(PROG1): $(OBJDIR) TestFactory.cpp
|
||||
$(PROG2): $(OBJDIR) RegFactory.cpp
|
||||
$(PROG3): $(OBJDIR) TestArray.cpp
|
||||
|
||||
|
||||
@@ -86,10 +86,11 @@ public:
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD_(void) LockFactory(PRBool aLock) {
|
||||
NS_IMETHOD LockFactory(PRBool aLock) {
|
||||
cout << "nsTestComFactory: ";
|
||||
cout << (aLock == PR_TRUE ? "Locking server" : "Unlocking server");
|
||||
cout << "\n";
|
||||
return S_OK;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user