Some cleanup, and update to new mozilla source. In particular:

- Removed #if 0 code in genproxy.c and elsewhere.

- Used jlong_* macros for portability (and defined in xpjava.h if not
  elsewhere)

- Commented out calls to PR_Atomic{In,De}crement in JSSample.cpp, and began
  to use "official" XPCOM macros.

- Removed Java interfaces for test components; will be autogenerated by
  xpidl and/or genproxy.

- Extend genproxy to generate interfaces.

- Updated README with note on the jni.h problem
This commit is contained in:
frankm%eng.sun.com 1999-09-14 21:56:19 +00:00
Родитель b1ec7ea992
Коммит 9f88f309ff
12 изменённых файлов: 286 добавлений и 1036 удалений

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

@ -33,6 +33,10 @@ difficult, and
1. Make sure MOZILLA_FIVE_HOME is set correctly, and that JDKHOME indicates
a valid JDK 1.2 installation.
*IMPORTANT*: remove the jni.h, jni_md.h, and jri.h in mozilla/dist/bin,
before compiling native code. Otherwise, the header
mismatch will cause crashes in JNI code.
2. Insure that the following are in your LD_LIBRARY_PATH:
$MOZILLA_FIVE_HOME

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

@ -88,3 +88,5 @@ recycled.
-- Cache previously allocated wrapper objects, to prevent unnecessary
allocation.
-- Thread-safe object release

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

@ -59,6 +59,28 @@ static inline void* ToPtr(jlong l) {
return (void *)result;
}
#undef DEBUG_GETSET_ID
#ifdef DEBUG_GETSET_ID
static void GetClassName(char *namebuf, JNIEnv *env, jobject self, int len) {
jclass clazz = env->GetObjectClass(self);
jclass clazz_clazz = env->GetObjectClass(clazz);
jmethodID nameID = env->GetMethodID(clazz_clazz, "getName", "()Ljava/lang/String;");
jstring string = (jstring)env->CallObjectMethod(clazz, nameID);
jsize jstrlen = env->GetStringUTFLength(string);
const char *utf = env->GetStringUTFChars(string, NULL);
if (jstrlen >= len) {
jstrlen = len;
}
strncpy(namebuf, utf, jstrlen);
namebuf[jstrlen] = '\0';
env->ReleaseStringUTFChars(string, utf);
}
#endif
/********************** ID **************************/
jobject ID_NewJavaID(JNIEnv *env, const nsIID* iid) {
@ -78,6 +100,14 @@ nsID *ID_GetNative(JNIEnv *env, jobject self) {
jclass clazz = env->FindClass(ID_CLASS_NAME);
jfieldID nsidptrID = env->GetFieldID(clazz, ID_FIELD_NAME, ID_FIELD_TYPE);
#ifdef DEBUG_GETSET_ID
char classname[128];
GetClassName(classname, env, self, sizeof(classname));
fprintf(stderr, "ID_GetNative: self instanceof %s\n", classname);
fflush(stderr);
#endif
assert(env->IsInstanceOf(self, clazz));
jlong nsidptr = env->GetLongField(self, nsidptrID);
@ -89,6 +119,14 @@ void ID_SetNative(JNIEnv *env, jobject self, nsID *id) {
jclass clazz = env->FindClass(ID_CLASS_NAME);
jfieldID nsidptrID = env->GetFieldID(clazz, ID_FIELD_NAME, ID_FIELD_TYPE);
#ifdef DEBUG_GETSET_ID
char classname[128];
GetClassName(classname, env, self, sizeof(classname));
fprintf(stderr, "ID_SetNative: self instanceof %s\n", classname);
fflush(stderr);
#endif
assert(env->IsInstanceOf(self, clazz));
jlong nsidptr = ToJLong(id);
@ -101,6 +139,17 @@ jboolean ID_IsEqual(JNIEnv *env, jobject self, jobject other) {
jclass clazz = env->FindClass(ID_CLASS_NAME);
jfieldID nsidptrID = env->GetFieldID(clazz, ID_FIELD_NAME, ID_FIELD_TYPE);
#ifdef DEBUG_GETSET_ID
char classname[128];
GetClassName(classname, env, self, sizeof(classname));
fprintf(stderr, "ID_IsEqual: self instanceof %s\n", classname);
GetClassName(classname, env, other, sizeof(classname));
fprintf(stderr, "ID_IsEqual: other instanceof %s\n", classname);
fflush(stderr);
#endif
assert(env->IsInstanceOf(self, clazz));
if (other != NULL && env->IsInstanceOf(other, clazz)) {

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

@ -720,10 +720,11 @@ extern jobject VariantToJObject(JNIEnv *env, const nsXPTCVariant *current) {
nsresult InitXPCOM() {
nsresult res;
#ifdef DEBUG_frankm
cerr << "Initializing XPCOM" << endl;
#endif
// Autoregistration happens here. The rest of RegisterComponent() calls should happen
// only for dlls not in the components directory.
// Autoregistration magic. Boogeda boogeda.
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull);
@ -746,7 +747,9 @@ nsresult InitXPCOM() {
// Get InterfaceInfoManager
#ifdef DEBUG_frankm
cerr << "Getting InterfaceInfoManager" << endl;
#endif
interfaceInfoManager = XPTI_GetInterfaceInfoManager();
@ -755,6 +758,10 @@ nsresult InitXPCOM() {
return res;
}
#ifdef DEBUG_frankm
cerr << "XPCOM Initialized" << endl;
#endif
return res;
}

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

@ -71,6 +71,11 @@ extern nsID* ID_GetNative(JNIEnv *env, jobject self);
extern void ID_SetNative(JNIEnv *env, jobject self, nsID* id);
extern jboolean ID_IsEqual(JNIEnv *env, jobject self, jobject other);
#ifndef jlong_L2I
# define jlong_L2I(_i, _l) ((_i) = (_l))
# define jlong_I2L(_l, _i) ((_l) = (_i))
#endif
#ifdef __cplusplus
}
#endif

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

@ -1,50 +0,0 @@
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Contributors:
* Frank Mitchell (frank.mitchell@sun.com)
*/
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from JSISample.idl.
*/
package org.mozilla.xpcom;
import org.mozilla.xpcom.nsISupports;
import org.mozilla.xpcom.nsID;
/*
* Interface JSIComplex
*
* IID: 0x57ecad91-ae1a-11d1-b66c-00805f8a2676
*/
public interface JSIComplex extends nsISupports
{
public static final String JSICOMPLEX_IID_STRING =
"57ecad91-ae1a-11d1-b66c-00805f8a2676";
public static final nsID JSICOMPLEX_IID =
new nsID("57ecad91-ae1a-11d1-b66c-00805f8a2676");
/* attribute long real; */
public int getReal();
public void setReal(int value);
/* attribute long imaginary; */
public int getImaginary();
public void setImaginary(int value);
}
/*
* end
*/

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

@ -1,97 +0,0 @@
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Contributors:
* Frank Mitchell (frank.mitchell@sun.com)
*/
/*
* ************* DO NOT EDIT THIS FILE ***********
*
* This file was automatically generated from JSISample.idl.
*/
package org.mozilla.xpcom;
import org.mozilla.xpcom.nsISupports;
import org.mozilla.xpcom.nsID;
/**
* Interface JSISample
*
* IID: 0x57ecad90-ae1a-11d1-b66c-00805f8a2676
*/
public interface JSISample extends nsISupports
{
public static final String JSISAMPLE_IID_STRING =
"57ecad90-ae1a-11d1-b66c-00805f8a2676";
public static final nsID JSISAMPLE_IID =
new nsID("57ecad90-ae1a-11d1-b66c-00805f8a2676");
/* void PrintStats (); */
public void PrintStats();
/* attribute long someInt; */
public int getSomeInt();
public void setSomeInt(int value);
/* attribute boolean someBool; */
public boolean getSomeBool();
public void setSomeBool(boolean value);
/* readonly attribute long roInt; */
public int getRoInt();
/* attribute double someDouble; */
public double getSomeDouble();
public void setSomeDouble(double value);
/* attribute string someName; */
public String getSomeName();
public void setSomeName(String value);
/* readonly attribute string roString; */
public String getRoString();
/* void TakeInt (in long anInt); */
public void TakeInt(int anInt);
/* long GiveInt (); */
public int GiveInt();
/* long GiveAndTake (inout long anInt); */
public int GiveAndTake(int[] anInt);
/* string TooManyArgs (in short oneInt, in short twoInt, inout long redInt, out short blueInt, in double orNothing, in long long johnSilver, in boolean algebra); */
public String TooManyArgs(short oneInt, short twoInt, int[] redInt, short[] blueInt, double orNothing, long johnSilver, boolean algebra);
/* string CatStrings (in string str1, in string str2); */
public String CatStrings(String str1, String str2);
/* void AppendString (inout string str1, in string str2); */
public void AppendString(String[] str1, String str2);
/* JSIComplex NewComplex (in long aReal, in long anImaginary); */
public JSIComplex NewComplex(int aReal, int anImaginary);
/* JSIComplex AddComplex (in JSIComplex complex1, in JSIComplex complex2); */
public JSIComplex AddComplex(JSIComplex complex1, JSIComplex complex2);
/* void AddInPlace (inout JSIComplex complex1, in JSIComplex complex2); */
public void AddInPlace(JSIComplex[] complex1, JSIComplex complex2);
/* long AddTwoInts (in long int1, in long int2); */
public int AddTwoInts(int int1, int int2);
}
/*
* end
*/

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

@ -30,67 +30,8 @@ public:
// nsISupports methods
NS_DECL_ISUPPORTS
/* void PrintStats (); */
NS_IMETHOD PrintStats();
/* attribute long someInt; */
NS_IMETHOD GetSomeInt(PRInt32 *aSomeInt);
NS_IMETHOD SetSomeInt(PRInt32 aSomeInt);
/* attribute boolean someBool; */
NS_IMETHOD GetSomeBool(PRBool *aSomeBool);
NS_IMETHOD SetSomeBool(PRBool aSomeBool);
/* readonly attribute long roInt; */
NS_IMETHOD GetRoInt(PRInt32 *aRoInt);
/* attribute double someDouble; */
NS_IMETHOD GetSomeDouble(double *aSomeDouble);
NS_IMETHOD SetSomeDouble(double aSomeDouble);
/* attribute string someName; */
NS_IMETHOD GetSomeName(char * *aSomeName);
NS_IMETHOD SetSomeName(char * aSomeName);
/* readonly attribute string roString; */
NS_IMETHOD GetRoString(char * *aRoString);
/* void TakeInt (in long anInt); */
NS_IMETHOD TakeInt(PRInt32 anInt);
/* long GiveInt (); */
NS_IMETHOD GiveInt(PRInt32 *_retval);
/* long GiveAndTake (inout long anInt); */
NS_IMETHOD GiveAndTake(PRInt32 *anInt, PRInt32 *_retval);
/* string TooManyArgs (in short oneInt, in short twoInt, inout long redInt, out short blueInt, in double orNothing, in long johnSilver, in boolean algebra); */
NS_IMETHOD TooManyArgs(PRInt16 oneInt,
PRInt16 twoInt,
PRInt32 *redInt,
PRInt16 *blueInt,
double orNothing,
PRInt64 johnSilver,
PRBool algebra,
char **_retval);
/* string CatStrings (in string str1, in string str2); */
NS_IMETHOD CatStrings(const char *str1, const char *str2, char **_retval);
/* void AppendString (inout string str1, in string str2); */
NS_IMETHOD AppendString(char **str1, const char *str2);
/* JSIComplex NewComplex (in long complex1, in long complex2); */
NS_IMETHOD NewComplex(PRInt32 aReal, PRInt32 aImaginary, JSIComplex **_retval);
/* JSIComplex AddComplex (in JSIComplex complex1, in JSIComplex complex2); */
NS_IMETHOD AddComplex(JSIComplex *complex1, JSIComplex *complex2, JSIComplex **_retval);
/* void AddInPlace (inout JSIComplex complex1, in JSIComplex complex2); */
NS_IMETHOD AddInPlace(JSIComplex **complex1, JSIComplex *complex2);
/* long AddTwoInts(int long complex1, in JSIComplex complex2); */
NS_IMETHOD AddTwoInts(PRInt32 int1, PRInt32 int2, PRInt32 *_retval);
// JSISample methods
NS_DECL_JSISAMPLE
private:
/* attribute long someInt; */
@ -113,14 +54,8 @@ private:
};
// Globals, need to check if safe to unload module
static PRInt32 gLockCnt = 0;
static PRInt32 gInstanceCnt = 0;
// Define constants for easy use
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kISampleIID, JSISAMPLE_IID);
static NS_DEFINE_IID(kIComplexIID, JSICOMPLEX_IID);
//static PRInt32 gLockCnt = 0;
// static PRInt32 gInstanceCnt = 0;
static NS_DEFINE_CID(kSampleCID, JS_SAMPLE_CID);
@ -141,13 +76,8 @@ public:
// nsISupports methods
NS_DECL_ISUPPORTS
/* attribute long real; */
NS_IMETHOD GetReal(PRInt32 *aReal);
NS_IMETHOD SetReal(PRInt32 aReal);
/* attribute long imaginary; */
NS_IMETHOD GetImaginary(PRInt32 *aImaginary);
NS_IMETHOD SetImaginary(PRInt32 aImaginary);
// nsISupports methods
NS_DECL_JSICOMPLEX
private:
PRInt32 real_;
@ -182,7 +112,7 @@ JSSample::JSSample()
{
// Zero reference counter
NS_INIT_ISUPPORTS();
PR_AtomicIncrement(&gInstanceCnt);
// PR_AtomicIncrement(&gInstanceCnt);
}
JSSample::~JSSample()
@ -190,40 +120,13 @@ JSSample::~JSSample()
// Make sure there are no dangling pointers to us,
// debug only
NS_ASSERTION(mRefCnt == 0,"Wrong ref count");
PR_AtomicDecrement(&gInstanceCnt);
// PR_AtomicDecrement(&gInstanceCnt);
}
NS_IMETHODIMP JSSample::QueryInterface(const nsIID &aIID,
void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aResult = NULL;
// Use the official macros to implement nsISupports
NS_IMPL_ISUPPORTS1(JSSample, JSISample)
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
} else if (aIID.Equals(kISampleIID)) {
*aResult = NS_STATIC_CAST(JSISample*, this);
}
else {
*aResult = nsnull;
return NS_ERROR_NO_INTERFACE;
}
// Add reference counter for outgoing pointer
NS_ADDREF(NS_REINTERPRET_CAST(nsISupports*,*aResult));
return NS_OK;
}
// Use the convenience macros to implement reference counting.
// They simply add or decrement the reference counter variable,
// Release also deletes this object if the counter reaches zero.
NS_IMPL_ADDREF(JSSample)
NS_IMPL_RELEASE(JSSample)
NS_IMETHODIMP JSSample::PrintStats()
{
@ -452,7 +355,7 @@ JSComplex::JSComplex()
{
// Zero reference counter
NS_INIT_ISUPPORTS();
PR_AtomicIncrement(&gInstanceCnt);
// PR_AtomicIncrement(&gInstanceCnt);
}
JSComplex::JSComplex(int aReal, int aImaginary) :
@ -460,7 +363,7 @@ JSComplex::JSComplex(int aReal, int aImaginary) :
{
// Zero reference counter
NS_INIT_ISUPPORTS();
PR_AtomicIncrement(&gInstanceCnt);
// PR_AtomicIncrement(&gInstanceCnt);
}
JSComplex::~JSComplex()
@ -468,40 +371,13 @@ JSComplex::~JSComplex()
// Make sure there are no dangling pointers to us,
// debug only
NS_ASSERTION(mRefCnt == 0,"Wrong ref count");
PR_AtomicDecrement(&gInstanceCnt);
// PR_AtomicDecrement(&gInstanceCnt);
}
NS_IMETHODIMP JSComplex::QueryInterface(const nsIID &aIID,
void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aResult = NULL;
// Use the official macros to implement nsISupports
NS_IMPL_ISUPPORTS1(JSComplex, JSIComplex)
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
} else if (aIID.Equals(kIComplexIID)) {
*aResult = NS_STATIC_CAST(JSIComplex*, this);
}
else {
*aResult = nsnull;
return NS_ERROR_NO_INTERFACE;
}
// Add reference counter for outgoing pointer
NS_ADDREF(NS_REINTERPRET_CAST(nsISupports*,*aResult));
return NS_OK;
}
// Use the convenience macros to implement reference counting.
// They simply add or decrement the reference counter variable,
// Release also deletes this object if the counter reaches zero.
NS_IMPL_ADDREF(JSComplex)
NS_IMPL_RELEASE(JSComplex)
/* attribute long real; */
NS_IMETHODIMP JSComplex::GetReal(PRInt32 *aReal) {
@ -539,7 +415,7 @@ JSSampleFactory::JSSampleFactory()
{
// Zero reference counter
NS_INIT_ISUPPORTS();
PR_AtomicIncrement(&gInstanceCnt);
// PR_AtomicIncrement(&gInstanceCnt);
}
JSSampleFactory::~JSSampleFactory()
@ -547,42 +423,12 @@ JSSampleFactory::~JSSampleFactory()
// Make sure there are no dangling pointers to us,
// debug only
NS_ASSERTION(mRefCnt == 0,"Wrong ref count");
PR_AtomicDecrement(&gInstanceCnt);
// PR_AtomicDecrement(&gInstanceCnt);
}
NS_IMETHODIMP JSSampleFactory::QueryInterface(const nsIID &aIID,
void **aResult)
{
if (!aResult) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aResult = nsnull;
if (aIID.Equals(kISupportsIID)) {
// Every interface supports nsISupports
*aResult = NS_STATIC_CAST(nsISupports*,this);
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*,this);
} else {
// We do not support this interface.
// Null result, and return error.
*aResult = nsnull;
return NS_ERROR_NO_INTERFACE;
}
// Add reference counter for outgoing pointer
NS_ADDREF(NS_REINTERPRET_CAST(nsISupports*,*aResult));
return NS_OK;
}
// Use the convenience macros to implement reference counting.
// They simply add or decrement the reference counter variable,
// Release also deletes this object if the counter reaches zero.
NS_IMPL_ADDREF(JSSampleFactory)
NS_IMPL_RELEASE(JSSampleFactory)
// Use the official macros to implement nsISupports
NS_IMPL_ISUPPORTS1(JSSampleFactory, nsIFactory)
NS_IMETHODIMP JSSampleFactory::CreateInstance(nsISupports *aOuter,
@ -614,9 +460,9 @@ NS_IMETHODIMP JSSampleFactory::CreateInstance(nsISupports *aOuter,
NS_IMETHODIMP JSSampleFactory::LockFactory(PRBool aLock)
{
if (aLock) {
PR_AtomicIncrement(&gLockCnt);
// PR_AtomicIncrement(&gLockCnt);
} else {
PR_AtomicDecrement(&gLockCnt);
// PR_AtomicDecrement(&gLockCnt);
}
return NS_OK;
@ -654,7 +500,7 @@ extern "C" {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = inst->QueryInterface(kIFactoryIID,
nsresult rv = inst->QueryInterface(NS_GET_IID(nsIFactory),
(void **) aResult);
if (NS_FAILED(rv)) {
@ -665,7 +511,8 @@ extern "C" {
}
NS_EXPORT PRBool NSCanUnload(nsISupports* serviceMgr) {
return PRBool(gInstanceCnt == 0 && gLockCnt == 0);
return PR_FALSE;
// return PRBool(gInstanceCnt == 0 && gLockCnt == 0);
}
NS_EXPORT nsresult NSRegisterSelf(nsISupports* serviceMgr,

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

@ -10,9 +10,9 @@ SHLIB_FLAGS=-fpic
SHLIB_LDFLAGS=-shared
DEFINES=-DXP_UNIX
INCLUDE=-I$(MOZILLA)/dist/include -I$(MOZILLA)/xpcom/public -I../src -I$(JDKHOME)/include -I$(JDKHOME)/include/solaris -I$(JDKHOME)/include/linux
#LIBS=-L$(MOZILLA)/dist/lib -lxptinfo -lxptcmd -lxptcall -lxpt -lxpcom -lxp -lreg -lplds3 -lplc3 -lnspr3 -lstdc++
LIBS=-L$(MOZILLA)/dist/lib -lxptinfo -lxptcmd -lxptcall -lxpt -lxpcom -lxp -lplds3 -lplc3 -lnspr3 -lstdc++
XPTDIR=$(MOZILLA)/dist/bin/components
LIBS=-L$(MOZILLA)/dist/lib -lxptinfo -lxptcmd -lxptcall -lxpt -lxpcom -lplds3 -lplc3 -lnspr3
COMPDIR=$(MOZILLA)/dist/bin/components
XPIDL=$(MOZILLA)/dist/bin/xpidl
@ -25,16 +25,13 @@ CLASSDIR=$(MOZILLA)/dist/classes
TEST_CLASSES=XPCTest.class
PROXY_CLASSES=org/mozilla/xpcom/JSISample__Proxy.class \
org/mozilla/xpcom/JSIComplex__Proxy.class
PROXY_SRCS=JSISample__Proxy.java \
JSIComplex__Proxy.java
PROXY_JAR=sample.jar
PROXY_DIR=_genproxy
.SUFFIXES: .java .class .cpp .o
all: sample xptest $(TEST_CLASSES)
all: sample xptest $(TEST_CLASSES) $(PROXY_JAR)
#
# Build class files.
@ -52,7 +49,7 @@ all: sample xptest $(TEST_CLASSES)
#
# Sample XPCOM module.
#
sample: JSISample.h libsample.so $(XPTDIR)/JSISample.xpt
sample: JSISample.h $(COMPDIR)/libxpjtest.so $(COMPDIR)/xpjtest.xpt
#
# Build sample header & typelib
@ -62,15 +59,18 @@ JSISample.cpp: JSISample.h
JSISample.h: JSISample.idl
$(XPIDL) -w -v -m header -I $(MOZILLA)/dist/idl JSISample.idl
$(XPTDIR)/JSISample.xpt: JSISample.idl
$(XPIDL) -w -v -m typelib -o $(XPTDIR)/JSISample -I $(MOZILLA)/dist/idl JSISample.idl
$(COMPDIR)/xpjtest.xpt: JSISample.idl
$(XPIDL) -w -v -m typelib -o $(COMPDIR)/xpjtest -I $(MOZILLA)/dist/idl JSISample.idl
#
# Sample object shared library
#
libsample.so: JSISample.h JSSample.o
$(CPP) $(SHLIB_LDFLAGS) $(LIBS) -o libsample.so JSSample.o
chmod +x libsample.so
libxpjtest.so: JSISample.h JSSample.o
$(CPP) $(SHLIB_LDFLAGS) -L$(MOZILLA)/dist/lib -lxpcom -o libxpjtest.so JSSample.o
chmod +x libxpjtest.so
$(COMPDIR)/libxpjtest.so: libxpjtest.so
../../../config/nsinstall -R -m 555 libxpjtest.so $(COMPDIR)
#
# C++ test program
@ -80,9 +80,12 @@ xptest: xptest.o ../src/libxpjava.so
xptest.cpp: ../src/xpjava.h
#$(PROXY_CLASSES): $(GENPROXY) $(XPTDIR)/JSISample.xpt
# genproxy $(XPTDIR)/JSISample.xpt
# $(JAVAC) -g -d . -classpath $(CLASSDIR):. *.java
$(PROXY_JAR): $(GENPROXY) $(COMPDIR)/xpjtest.xpt
- mkdir $(PROXY_DIR)
$(GENPROXY) -d $(PROXY_DIR) $(COMPDIR)/xpjtest.xpt
$(GENPROXY) -i -d $(PROXY_DIR) $(COMPDIR)/xpjtest.xpt
$(JAVAC) -g -d $(PROXY_DIR) -classpath $(CLASSDIR):. $(PROXY_DIR)/*.java
(cd $(PROXY_DIR); jar cf ../$(PROXY_JAR) org)
clean:
$(RM) *.o *.so core xptest $(XPTDIR)/JSISample.xpt JSISample.h $(TEST_CLASSES) $(PROXY_SRCS) $(PROXY_CLASSES)
$(RM) -r *.o *.so core xptest $(COMPDIR)/libxpjtest.so $(COMPDIR)/xpjtest.xpt JSISample.h $(TEST_CLASSES) $(PROXY_JAR) $(PROXY_DIR)

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

@ -13,11 +13,10 @@
*/
import java.util.Vector;
import java.lang.reflect.Method;
import org.mozilla.xpcom.*;
public class XPCTest {
private static boolean didRegister = false;
static ComObject CreateSampleInstance() {
nsID kSampleCID =
new nsID("d3944dd0-ae1a-11d1-b66c-00805f8a2676");
@ -26,16 +25,7 @@ public class XPCTest {
new nsID("57ecad90-ae1a-11d1-b66c-00805f8a2676");
if (!didRegister) {
XPComUtilities.RegisterComponent(kSampleCID,
"JSSample",
"component://javasoft/sample",
"libsample.so",
false,
false);
didRegister = true;
}
// XXX: convert to nsIComponentManager calls
return (ComObject)XPComUtilities.CreateInstance(kSampleCID,
null,
kISampleIID);
@ -44,13 +34,9 @@ public class XPCTest {
public static void main(String[] argv) {
String command = "PrintStats";
int cmdOffset = -1;
boolean useXPCMethod = true;
try {
// KLUDGE: load libraries
//System.out.println(System.getProperty("java.library.path"));
//System.loadLibrary("plds3");
//System.loadLibrary("xpcom");
Object[] params = null;
// Process arguments
@ -58,12 +44,25 @@ public class XPCTest {
params = new Object[0];
}
else {
command = argv[0];
int argi = 0;
while (argv[argi].charAt(0) == '-') {
switch(argv[argi].charAt(1)) {
case 'r':
useXPCMethod = false;
break;
case 'x':
useXPCMethod = true;
break;
}
argi++;
}
command = argv[argi++];
if (Character.isDigit(command.charAt(0))) {
cmdOffset = Integer.parseInt(command);
}
params = paramArray(argv, 1);
params = paramArray(argv, argi);
}
ComObject sample = CreateSampleInstance();
@ -83,11 +82,24 @@ public class XPCTest {
cmdOffset,
params);
}
else {
else if (useXPCMethod) {
XPCMethod method = new XPCMethod(kISampleIID, command);
method.invoke(sample, params);
}
else {
Method[] methods = sample.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(command)) {
Object retval =
methods[i].invoke(sample, params);
System.out.print("Retval: "); // DEBUG
System.out.println(retval); // DEBUG
break;
}
}
}
// Get "out" parameters and return value
System.out.print("Results: "); // DEBUG
@ -160,6 +172,10 @@ public class XPCTest {
case '0':
vector.addElement(null);
break;
case '@':
argi++;
vector.addElement(new nsID(argv[argi]));
break;
case 'z':
argi++;
vector.addElement(Boolean.valueOf(argv[argi]));

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

@ -38,24 +38,25 @@ static NS_DEFINE_CID(kSampleCID, JS_SAMPLE_CID);
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
#ifdef XP_PC
#define XPCOM_DLL "xpcom32.dll"
#define SAMPLE_DLL "sampl32.dll"
#define XPCOM_DLL "xpcom.dll"
#define SAMPLE_DLL "xpjtest.dll"
#else
#ifdef XP_MAC
#define XPCOM_DLL "XPCOM_DLL"
#define SAMPLE_DLL "SAMPL_DLL"
#define SAMPLE_DLL "XPJTEST_DLL"
#else
#define XPCOM_DLL "libxpcom.so"
#define SAMPLE_DLL "libsample.so"
#define SAMPLE_DLL "libxpjtest.so"
#endif
#endif
nsXPTCVariant *ParamsFromArgv(const nsXPTMethodInfo *mi,
int argi, int argc, char **argv) {
void ParamsFromArgv(nsXPTCVariant *result,
const nsXPTMethodInfo *mi,
int argi, int argc, char **argv) {
uint8 paramcount = mi->GetParamCount();
nsXPTCVariant *result = new nsXPTCVariant[paramcount];
memset(result, 0, sizeof(nsXPTCVariant) * paramcount);
for (int i = 0; i < paramcount; i++) {
nsXPTParamInfo param = mi->GetParam(i);
@ -120,7 +121,6 @@ nsXPTCVariant *ParamsFromArgv(const nsXPTMethodInfo *mi,
break;
case nsXPTType::T_CHAR_STR:
result[i].val.p = argv[argi];
#if 0
// Copying every time would be wasteful
if (param.IsOut()) {
char *tmpstr = new char[strlen(argv[argi]) + 1];
@ -128,7 +128,6 @@ nsXPTCVariant *ParamsFromArgv(const nsXPTMethodInfo *mi,
result[i].val.p = tmpstr;
result[i].flags |= nsXPTCVariant::VAL_IS_OWNED;
}
#endif
break;
case nsXPTType::T_VOID:
case nsXPTType::T_IID:
@ -220,21 +219,6 @@ int main(int argc, char **argv)
// Initialize XPCOM
InitXPCOM();
// Register Factory
cerr << "Registering Sample Factory" << endl;
res = nsComponentManager::RegisterComponent(kSampleCID,
"JSSample",
"component://javasoft/sample",
SAMPLE_DLL,
PR_FALSE,
PR_FALSE);
if (NS_FAILED(res)) {
cerr << "Failed to register factory" << endl;
return res;
}
// Create Instance
res = nsComponentManager::CreateInstance(kSampleCID,
nsnull,
@ -280,7 +264,14 @@ int main(int argc, char **argv)
}
// Translate and marshall arguments
nsXPTCVariant *params = ParamsFromArgv(mi, 2, argc, argv);
nsXPTCVariant params[32];
if (paramcount > (sizeof(params)/sizeof(nsXPTCVariant))) {
cerr << "Too Many Params" << endl;
return 1;
}
ParamsFromArgv(params, mi, 2, argc, argv);
cerr << "Arguments are: " << endl;

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

@ -49,9 +49,10 @@ static char *rtype_array[20] = {"Byte", "Short", "Integer", "Long",
PRBool
GenproxyClass(FILE *out,
XPTCursor *cursor,
XPTInterfaceDirectoryEntry *ide,
XPTHeader *header);
XPTCursor *cursor,
XPTInterfaceDirectoryEntry *ide,
XPTHeader *header,
PRBool iface);
PRBool GenproxyMethodPrototype(FILE *out,
XPTHeader *header,
@ -73,7 +74,7 @@ GenproxyGetStringForRefType(XPTHeader *header, XPTTypeDescriptor *td,
static void
genproxy_usage(char *argv[]) {
fprintf(stdout, "Usage: %s [-v] <filename.xpt>\n"
fprintf(stdout, "Usage: %s [-v] [-i] <filename.xpt>\n"
" -v verbose mode\n", argv[0]);
}
@ -86,7 +87,7 @@ static int mac_get_args(char*** argv)
*argv = args;
printf("choose an .xpt file to dump.\n");
printf("choose an .xpt file to parse.\n");
StandardGetFile(NULL, 0, NULL, &reply);
if (reply.sfGood && !reply.sfIsFolder) {
@ -135,46 +136,49 @@ int
main(int argc, char **argv)
{
PRBool verbose_mode = PR_FALSE;
PRBool interface_mode = PR_FALSE;
PRBool bytecode_mode = PR_FALSE;
XPTState *state;
XPTCursor curs, *cursor = &curs;
XPTHeader *header;
size_t flen;
char *name;
const char *dirname = NULL;
char *whole;
FILE *in;
FILE *out;
int i;
int c;
#ifdef XP_MAC
if (argc == 0 || argv == NULL)
if (argc == 0 || argv == NULL)
argc = mac_get_args(&argv);
#endif
switch (argc) {
case 2:
if (argv[1][0] == '-') {
while ((c = getopt(argc, argv, "vibd:")) != EOF) {
switch (c) {
case 'v':
verbose_mode = PR_TRUE;
break;
case 'i':
interface_mode = PR_TRUE;
break;
case 'b':
bytecode_mode = PR_TRUE;
break;
case 'd':
dirname = optarg;
break;
case '?':
genproxy_usage(argv);
return 1;
}
name = argv[1];
flen = get_file_length(name);
in = fopen(name, "rb");
break;
case 3:
verbose_mode = PR_TRUE;
if (argv[1][0] != '-' || argv[1][1] != 'v') {
genproxy_usage(argv);
return 1;
}
name = argv[2];
flen = get_file_length(name);
in = fopen(name, "rb");
break;
default:
genproxy_usage(argv);
return 1;
}
name = argv[optind];
flen = get_file_length(name);
in = fopen(name, "rb");
if (!in) {
perror("FAILED: fopen");
return 1;
@ -215,12 +219,29 @@ main(int argc, char **argv)
XPTInterfaceDirectoryEntry *ide = &header->interface_directory[i];
char javaname[256];
javaname[0] = 0;
if (ide->interface_descriptor == NULL) {
continue;
}
strcpy(javaname, ide->name);
strcat(javaname, "__Proxy.java");
/* XXX: is this XP? */
if (dirname != NULL) {
int len;
strcpy(javaname, dirname);
len = strlen(javaname);
if (javaname[len - 1] != '/') {
javaname[len] = '/';
javaname[len+1] = 0;
}
}
strcat(javaname, ide->name);
if (interface_mode) {
strcat(javaname, ".java");
}
else {
strcat(javaname, "__Proxy.java");
}
out = fopen(javaname, "w");
@ -229,7 +250,7 @@ main(int argc, char **argv)
return 1;
}
if (!GenproxyClass(out, cursor, ide, header)) {
if (!GenproxyClass(out, cursor, ide, header, interface_mode)) {
return PR_FALSE;
perror("FAILED: Cannot print interface");
return 1;
@ -272,15 +293,28 @@ classname_iid_define(const char *className)
return result;
}
static void
print_IID(struct nsID *iid, FILE *file)
{
fprintf(file, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) iid->m0, (PRUint32) iid->m1,(PRUint32) iid->m2,
(PRUint32) iid->m3[0], (PRUint32) iid->m3[1],
(PRUint32) iid->m3[2], (PRUint32) iid->m3[3],
(PRUint32) iid->m3[4], (PRUint32) iid->m3[5],
(PRUint32) iid->m3[6], (PRUint32) iid->m3[7]);
}
PRBool
GenproxyClass(FILE *out,
XPTCursor *cursor,
XPTInterfaceDirectoryEntry *ide,
XPTHeader *header) {
XPTHeader *header,
PRBool iface) {
int i;
XPTInterfaceDescriptor *id = ide->interface_descriptor;
XPTInterfaceDirectoryEntry *parent_ide = NULL;
const char *iidName = classname_iid_define(ide->name); /* XXX: Leak */
const char *iidName = classname_iid_define(ide->name);
if (id->parent_interface) {
parent_ide = &header->interface_directory[id->parent_interface - 1];
@ -303,30 +337,63 @@ GenproxyClass(FILE *out,
parent_ide->name_space ? parent_ide->name_space : "org.mozilla.xpcom",
parent_ide->name);
}
else {
else if (!iface) {
fprintf(out, "import org.mozilla.xpcom.XPComUtilities;\n");
fprintf(out, "import org.mozilla.xpcom.ComObject;\n");
}
fprintf(out, "import org.mozilla.xpcom.nsID;\n");
fprintf(out, "\nclass %s__Proxy", ide->name);
if (iface) {
fprintf(out, "\npublic interface %s", ide->name);
if (parent_ide) {
fprintf(out, " extends %s__Proxy", parent_ide->name);
if (parent_ide) {
fprintf(out, " extends %s", parent_ide->name);
}
fprintf(out, " {\n", ide->name);
fprintf(out,
"\n public static final String %s_STRING = \"", iidName);
print_IID(&ide->iid, out);
fprintf(out, "\";\n\n");
fprintf(out,
" public static final nsID %s = new nsID(%s_STRING);\n",
iidName, iidName);
}
else {
fprintf(out, "\nclass %s__Proxy", ide->name);
fprintf(out, " implements %s {\n", ide->name);
if (parent_ide) {
fprintf(out, " extends %s__Proxy", parent_ide->name);
}
fprintf(out, " implements %s {\n", ide->name);
}
for (i = 0; i < id->num_methods; i++) {
if (!GenproxyMethodPrototype(out, header, &id->method_descriptors[i])) {
XPTMethodDescriptor *md = &id->method_descriptors[i];
if (XPT_MD_IS_HIDDEN(md->flags)) {
continue;
}
if (!GenproxyMethodPrototype(out, header, md)) {
return PR_FALSE;
}
/* XXX: KLUDGE method index for now */
if (!GenproxyMethodBody(out, header,
&id->method_descriptors[i], i+3, iidName)) {
return PR_FALSE;
if (iface) {
fprintf(out, ";\n");
}
else {
/* XXX: KLUDGE method index for now */
if (!GenproxyMethodBody(out, header, md, i+3, iidName)) {
return PR_FALSE;
}
}
fprintf(out, "\n");
}
fprintf(out, "}\n");
free((void *)iidName);
return PR_TRUE;
}
@ -337,10 +404,6 @@ GenproxyMethodPrototype(FILE *out, XPTHeader *header, XPTMethodDescriptor *md) {
int retval_ind = -1;
XPTParamDescriptor *pd;
if (XPT_MD_IS_HIDDEN(md->flags)) {
return PR_TRUE;
}
/* Find index of retval */
for (i = 0; i < md->num_args; i++) {
pd = &md->params[i];
@ -350,13 +413,21 @@ GenproxyMethodPrototype(FILE *out, XPTHeader *header, XPTMethodDescriptor *md) {
}
}
/* "Hidden" methods are protected (if reflected at all) */
if (XPT_MD_IS_HIDDEN(md->flags)) {
fprintf(out, " protected ");
}
else {
fprintf(out, " public ");
}
if (XPT_MD_IS_GETTER(md->flags)) {
pd = &md->params[0];
if (!GenproxyGetStringForType(header, &pd->type, &param_type)) {
return PR_FALSE;
}
fprintf(out, " public %s get%c%s()",
fprintf(out, "%s get%c%s()",
param_type,
toupper(md->name[0]),
(md->name)+1);
@ -367,7 +438,7 @@ GenproxyMethodPrototype(FILE *out, XPTHeader *header, XPTMethodDescriptor *md) {
if (!GenproxyGetStringForType(header, &pd->type, &param_type)) {
return PR_FALSE;
}
fprintf(out, " public void set%c%s(%s p0)",
fprintf(out, "void set%c%s(%s p0)",
toupper(md->name[0]),
(md->name)+1,
param_type);
@ -384,7 +455,7 @@ GenproxyMethodPrototype(FILE *out, XPTHeader *header, XPTMethodDescriptor *md) {
}
}
fprintf(out, " public %s %s(", param_type, md->name);
fprintf(out, "%s %s(", param_type, md->name);
for (i = 0; i < md->num_args; i++) {
pd = &md->params[i];
@ -402,11 +473,6 @@ GenproxyMethodPrototype(FILE *out, XPTHeader *header, XPTMethodDescriptor *md) {
fprintf(out, "%s", param_type);
if (XPT_PD_IS_OUT(pd->flags)) {
fprintf(out, "[]");
/*
if (XPT_PD_IS_SHARED(pd->flags)) {
fprintf(out, "shared ");
}
*/
}
fprintf(out, " p%d", i);
}
@ -574,597 +640,4 @@ GenproxyXPTString(FILE *out, XPTString *str)
return PR_TRUE;
}
#if 0
PRBool
GenproxyHeader(XPTCursor *cursor, XPTHeader *header,
const int indent, PRBool verbose_mode)
{
int i;
fprintf(stdout, "Header:\n");
if (verbose_mode) {
fprintf(stdout, "%*sMagic beans: ", indent, " ");
for (i=0; i<16; i++) {
fprintf(stdout, "%02x", header->magic[i]);
}
fprintf(stdout, "\n");
if (strncmp((const char*)header->magic, XPT_MAGIC, 16) == 0)
fprintf(stdout, "%*s PASSED\n", indent, " ");
else
fprintf(stdout, "%*s FAILED\n", indent, " ");
}
fprintf(stdout, "%*sMajor version: %d\n", indent, " ",
header->major_version);
fprintf(stdout, "%*sMinor version: %d\n", indent, " ",
header->minor_version);
fprintf(stdout, "%*sNumber of interfaces: %d\n", indent, " ",
header->num_interfaces);
if (verbose_mode) {
fprintf(stdout, "%*sFile length: %d\n", indent, " ",
header->file_length);
fprintf(stdout, "%*sData pool offset: %d\n\n", indent, " ",
header->data_pool);
}
fprintf(stdout, "%*sAnnotations:\n", indent, " ");
if (!GenproxyAnnotations(header->annotations, indent*2, verbose_mode))
return PR_FALSE;
fprintf(stdout, "\nInterface Directory:\n");
for (i=0; i<header->num_interfaces; i++) {
if (verbose_mode) {
fprintf(stdout, "%*sInterface #%d:\n", indent, " ", i);
if (!GenproxyInterfaceDirectoryEntry(cursor,
&header->interface_directory[i],
header, indent*2,
verbose_mode)) {
return PR_FALSE;
}
} else {
if (!GenproxyInterfaceDirectoryEntry(cursor,
&header->interface_directory[i],
header, indent,
verbose_mode)) {
return PR_FALSE;
}
}
}
return PR_TRUE;
}
PRBool
GenproxyAnnotations(XPTAnnotation *ann, const int indent, PRBool verbose_mode)
{
int i = -1;
XPTAnnotation *last;
int new_indent = indent + BASE_INDENT;
do {
i++;
if (XPT_ANN_IS_PRIVATE(ann->flags)) {
if (verbose_mode) {
fprintf(stdout, "%*sAnnotation #%d is private.\n",
indent, " ", i);
} else {
fprintf(stdout, "%*sAnnotation #%d:\n",
indent, " ", i);
}
fprintf(stdout, "%*sCreator: ", new_indent, " ");
if (!GenproxyXPTString(ann->creator))
return PR_FALSE;
fprintf(stdout, "\n");
fprintf(stdout, "%*sPrivate Data: ", new_indent, " ");
if (!GenproxyXPTString(ann->private_data))
return PR_FALSE;
fprintf(stdout, "\n");
} else {
fprintf(stdout, "%*sAnnotation #%d is empty.\n",
indent, " ", i);
}
last = ann;
ann = ann->next;
} while (!XPT_ANN_IS_LAST(last->flags));
if (verbose_mode) {
fprintf(stdout, "%*sAnnotation #%d is the last annotation.\n",
indent, " ", i);
}
return PR_TRUE;
}
static void
print_IID(struct nsID *iid, FILE *file)
{
fprintf(file, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) iid->m0, (PRUint32) iid->m1,(PRUint32) iid->m2,
(PRUint32) iid->m3[0], (PRUint32) iid->m3[1],
(PRUint32) iid->m3[2], (PRUint32) iid->m3[3],
(PRUint32) iid->m3[4], (PRUint32) iid->m3[5],
(PRUint32) iid->m3[6], (PRUint32) iid->m3[7]);
}
PRBool
GenproxyInterfaceDirectoryEntry(XPTCursor *cursor,
XPTInterfaceDirectoryEntry *ide,
XPTHeader *header, const int indent,
PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
if (verbose_mode) {
fprintf(stdout, "%*sIID: ", indent, " ");
print_IID(&ide->iid, stdout);
fprintf(stdout, "\n");
fprintf(stdout, "%*sName: %s\n",
indent, " ", ide->name);
fprintf(stdout, "%*sNamespace: %s\n",
indent, " ", ide->name_space ? ide->name_space : "none");
fprintf(stdout, "%*sAddress of interface descriptor: %p\n",
indent, " ", ide->interface_descriptor);
fprintf(stdout, "%*sDescriptor:\n", indent, " ");
if (!GenproxyInterfaceDescriptor(cursor, ide->interface_descriptor,
header, new_indent, verbose_mode)) {
return PR_FALSE;
}
} else {
fprintf(stdout, "%*s- %s::%s (", indent, " ",
ide->name_space ? ide->name_space : "", ide->name);
print_IID(&ide->iid, stdout);
fprintf(stdout, "):\n");
if (!GenproxyInterfaceDescriptor(cursor, ide->interface_descriptor,
header, new_indent, verbose_mode)) {
return PR_FALSE;
}
}
return PR_TRUE;
}
PRBool
GenproxyInterfaceDescriptor(XPTCursor *cursor, XPTInterfaceDescriptor *id,
XPTHeader *header, const int indent,
PRBool verbose_mode)
{
XPTInterfaceDirectoryEntry *parent_ide;
int i;
int new_indent = indent + BASE_INDENT;
int more_indent = new_indent + BASE_INDENT;
if (!id) {
fprintf(stdout, "%*s[Unresolved]\n", indent, " ");
return PR_TRUE;
}
if (id->parent_interface) {
parent_ide = &header->interface_directory[id->parent_interface - 1];
fprintf(stdout, "%*sParent: %s::%s\n", indent, " ",
parent_ide->name_space ?
parent_ide->name_space : "",
parent_ide->name);
}
fprintf(stdout, "%*sFlags:\n", indent, " ");
fprintf(stdout, "%*sScriptable: %s\n", new_indent, " ",
XPT_ID_IS_SCRIPTABLE(id->flags) ? "TRUE" : "FALSE");
if (verbose_mode) {
if (id->parent_interface) {
fprintf(stdout,
"%*sIndex of parent interface (in data pool): %d\n",
indent, " ", id->parent_interface);
}
} else {
}
if (id->num_methods > 0) {
if (verbose_mode) {
fprintf(stdout,
"%*s# of Method Descriptors: %d\n",
indent, " ", id->num_methods);
} else {
fprintf(stdout, "%*sMethods:\n", indent, " ");
}
for (i=0; i<id->num_methods; i++) {
if (verbose_mode) {
fprintf(stdout, "%*sMethod #%d:\n", new_indent, " ", i);
if (!GenproxyMethodDescriptor(header,
&id->method_descriptors[i],
more_indent, verbose_mode)) {
return PR_FALSE;
}
} else {
if (!GenproxyMethodDescriptor(header,
&id->method_descriptors[i],
new_indent, verbose_mode)) {
return PR_FALSE;
}
}
}
} else {
fprintf(stdout, "%*sMethods:\n", indent, " ");
fprintf(stdout, "%*sNo Methods\n", new_indent, " ");
}
if (id->num_constants > 0) {
if (verbose_mode) {
fprintf(stdout,
"%*s# of Constant Descriptors: %d\n",
indent, " ", id->num_constants);
} else {
fprintf(stdout, "%*sConstants:\n", indent, " ");
}
for (i=0; i<id->num_constants; i++) {
if (verbose_mode) {
fprintf(stdout, "%*sConstant #%d:\n", new_indent, " ", i);
if (!GenproxyConstDescriptor(header,
&id->const_descriptors[i],
more_indent, verbose_mode))
return PR_FALSE;
} else {
if (!GenproxyConstDescriptor(header,
&id->const_descriptors[i],
new_indent, verbose_mode)) {
return PR_FALSE;
}
}
}
} else {
fprintf(stdout, "%*sConstants:\n", indent, " ");
fprintf(stdout, "%*sNo Constants\n", new_indent, " ");
}
return PR_TRUE;
}
PRBool
GenproxyMethodDescriptor(XPTHeader *header, XPTMethodDescriptor *md,
const int indent, PRBool verbose_mode)
{
int i;
int new_indent = indent + BASE_INDENT;
int more_indent = new_indent + BASE_INDENT;
if (verbose_mode) {
fprintf(stdout, "%*sName: %s\n", indent, " ", md->name);
fprintf(stdout, "%*sIs Getter? ", indent, " ");
if (XPT_MD_IS_GETTER(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Setter? ", indent, " ");
if (XPT_MD_IS_SETTER(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Varargs? ", indent, " ");
if (XPT_MD_IS_VARARGS(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Constructor? ", indent, " ");
if (XPT_MD_IS_CTOR(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Hidden? ", indent, " ");
if (XPT_MD_IS_HIDDEN(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*s# of arguments: %d\n", indent, " ", md->num_args);
fprintf(stdout, "%*sParameter Descriptors:\n", indent, " ");
for (i=0; i<md->num_args; i++) {
fprintf(stdout, "%*sParameter #%d:\n", new_indent, " ", i);
if (!GenproxyParamDescriptor(header, &md->params[i], more_indent,
verbose_mode, PR_FALSE))
return PR_FALSE;
}
fprintf(stdout, "%*sResult:\n", indent, " ");
if (!GenproxyParamDescriptor(header, md->result, new_indent,
verbose_mode, PR_TRUE)) {
return PR_FALSE;
}
} else {
char *param_type;
XPTParamDescriptor *pd;
if (!GenproxyGetStringForType(header, &md->result->type, &param_type)) {
return PR_FALSE;
}
fprintf(stdout, "%*s%c%c%c%c%c %s %s(", indent - 6, " ",
XPT_MD_IS_GETTER(md->flags) ? 'G' : ' ',
XPT_MD_IS_SETTER(md->flags) ? 'S' : ' ',
XPT_MD_IS_HIDDEN(md->flags) ? 'H' : ' ',
XPT_MD_IS_VARARGS(md->flags) ? 'V' : ' ',
XPT_MD_IS_CTOR(md->flags) ? 'C' : ' ',
param_type, md->name);
for (i=0; i<md->num_args; i++) {
if (i!=0) {
fprintf(stdout, ", ");
}
pd = &md->params[i];
if (XPT_PD_IS_IN(pd->flags)) {
fprintf(stdout, "in");
if (XPT_PD_IS_OUT(pd->flags)) {
fprintf(stdout, "/out ");
if (XPT_PD_IS_RETVAL(pd->flags)) {
fprintf(stdout, "retval ");
}
if (XPT_PD_IS_SHARED(pd->flags)) {
fprintf(stdout, "shared ");
}
} else {
fprintf(stdout, " ");
}
} else {
if (XPT_PD_IS_OUT(pd->flags)) {
fprintf(stdout, "out ");
if (XPT_PD_IS_RETVAL(pd->flags)) {
fprintf(stdout, "retval ");
}
if (XPT_PD_IS_SHARED(pd->flags)) {
fprintf(stdout, "shared ");
}
} else {
param_problems = PR_TRUE;
fprintf(stdout, "XXX ");
}
}
if (!GenproxyGetStringForType(header, &pd->type, &param_type)) {
return PR_FALSE;
}
fprintf(stdout, "%s", param_type);
}
fprintf(stdout, ");\n");
}
return PR_TRUE;
}
PRBool
GenproxyParamDescriptor(XPTHeader *header, XPTParamDescriptor *pd,
const int indent, PRBool verbose_mode,
PRBool is_result)
{
int new_indent = indent + BASE_INDENT;
if (!XPT_PD_IS_IN(pd->flags) &&
!XPT_PD_IS_OUT(pd->flags) &&
(XPT_PD_IS_RETVAL(pd->flags) ||
XPT_PD_IS_SHARED(pd->flags))) {
param_problems = PR_TRUE;
fprintf(stdout, "XXX\n");
} else {
if (!XPT_PD_IS_IN(pd->flags) && !XPT_PD_IS_OUT(pd->flags)) {
if (is_result) {
if (XPT_TDP_TAG(pd->type.prefix) != TD_UINT32 &&
XPT_TDP_TAG(pd->type.prefix) != TD_VOID) {
param_problems = PR_TRUE;
fprintf(stdout, "XXX\n");
}
} else {
param_problems = PR_TRUE;
fprintf(stdout, "XXX\n");
}
}
}
fprintf(stdout, "%*sIn Param? ", indent, " ");
if (XPT_PD_IS_IN(pd->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sOut Param? ", indent, " ");
if (XPT_PD_IS_OUT(pd->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sRetval? ", indent, " ");
if (XPT_PD_IS_RETVAL(pd->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sShared? ", indent, " ");
if (XPT_PD_IS_SHARED(pd->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sType Descriptor:\n", indent, " ");
if (!GenproxyTypeDescriptor(&pd->type, new_indent, verbose_mode))
return PR_FALSE;
return PR_TRUE;
}
PRBool
GenproxyTypeDescriptor(XPTTypeDescriptor *td, int indent, PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
fprintf(stdout, "%*sIs Pointer? ", indent, " ");
if (XPT_TDP_IS_POINTER(td->prefix.flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Unique Pointer? ", indent, " ");
if (XPT_TDP_IS_UNIQUE_POINTER(td->prefix.flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Reference? ", indent, " ");
if (XPT_TDP_IS_REFERENCE(td->prefix.flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sTag: %d\n", indent, " ",
XPT_TDP_TAG(td->prefix));
if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE) {
fprintf(stdout, "%*sInterfaceTypeDescriptor:\n", indent, " ");
fprintf(stdout, "%*sIndex of IDE: %d\n", new_indent, " ",
td->type.interface);
}
if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_IS_TYPE) {
fprintf(stdout, "%*sInterfaceTypeDescriptor:\n", indent, " ");
fprintf(stdout, "%*sIndex of Method Argument: %d\n", new_indent, " ",
td->type.argnum);
}
return PR_TRUE;
}
PRBool
GenproxyConstDescriptor(XPTHeader *header, XPTConstDescriptor *cd,
const int indent, PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
char *const_type;
/* char *out; */
PRUint32 uintout;
PRInt32 intout;
if (verbose_mode) {
fprintf(stdout, "%*sName: %s\n", indent, " ", cd->name);
fprintf(stdout, "%*sType Descriptor: \n", indent, " ");
if (!GenproxyTypeDescriptor(&cd->type, new_indent, verbose_mode))
return PR_FALSE;
fprintf(stdout, "%*sValue: ", indent, " ");
} else {
if (!GenproxyGetStringForType(header, &cd->type, &const_type)) {
return PR_FALSE;
}
fprintf(stdout, "%*s%s %s = ", indent, " ", const_type, cd->name);
}
switch(XPT_TDP_TAG(cd->type.prefix)) {
case TD_INT8:
fprintf(stdout, "%d", cd->value.i8);
break;
case TD_INT16:
fprintf(stdout, "%d", cd->value.i16);
break;
case TD_INT64:
/* XXX punt for now to remove NSPR linkage...
* borrow from mozilla/nsprpub/pr/src/io/prprf.c::cvt_ll? */
/* out = PR_smprintf("%lld", cd->value.i64); */
/* fputs(out, stdout); */
/* PR_smprintf_free(out); */
LL_L2I(intout, cd->value.i64);
fprintf(stdout, "%d", intout);
break;
case TD_INT32:
fprintf(stdout, "%d", cd->value.i32);
break;
case TD_UINT8:
fprintf(stdout, "%d", cd->value.ui8);
break;
case TD_UINT16:
fprintf(stdout, "%d", cd->value.ui16);
break;
case TD_UINT64:
/* out = PR_smprintf("%lld", cd->value.ui64); */
/* fputs(out, stdout); */
/* PR_smprintf_free(out); */
/* XXX punt for now to remove NSPR linkage. */
LL_L2UI(uintout, cd->value.ui64);
fprintf(stdout, "%d", uintout);
break;
case TD_UINT32:
fprintf(stdout, "%d", cd->value.ui32);
break;
case TD_FLOAT:
fprintf(stdout, "%f", cd->value.flt);
break;
case TD_DOUBLE:
fprintf(stdout, "%g", cd->value.dbl);
break;
case TD_BOOL:
if (cd->value.bul)
fprintf(stdout, "TRUE");
else
fprintf(stdout, "FALSE");
break;
case TD_CHAR:
fprintf(stdout, "%c", cd->value.ch);
break;
case TD_WCHAR:
fprintf(stdout, "%c", cd->value.wch & 0xff);
break;
case TD_VOID:
fprintf(stdout, "VOID");
break;
case TD_PNSIID:
if (XPT_TDP_IS_POINTER(cd->type.prefix.flags)) {
print_IID(cd->value.iid, stdout);
} else
return PR_FALSE;
break;
case TD_PBSTR:
if (XPT_TDP_IS_POINTER(cd->type.prefix.flags)) {
if (!GenproxyXPTString(cd->value.string))
return PR_FALSE;
} else
return PR_FALSE;
break;
case TD_PSTRING:
if (XPT_TDP_IS_POINTER(cd->type.prefix.flags)) {
fprintf(stdout, "%s", cd->value.str);
} else
return PR_FALSE;
break;
case TD_PWSTRING:
if (XPT_TDP_IS_POINTER(cd->type.prefix.flags)) {
PRUint16 *ch = cd->value.wstr;
while (*ch) {
fprintf(stdout, "%c", *ch & 0xff);
ch++;
}
} else
return PR_FALSE;
break;
default:
perror("Unrecognized type");
return PR_FALSE;
break;
}
if (verbose_mode) {
fprintf(stdout, "\n");
} else {
fprintf(stdout, ";\n");
}
return PR_TRUE;
}
#endif