Ported BlackConnect to Linux. It is working wuth IBM jdk1.3
This commit is contained in:
idk%eng.sun.com 2000-07-15 06:18:54 +00:00
Родитель 8a64cb5198
Коммит 168ce6f019
10 изменённых файлов: 236 добавлений и 180 удалений

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

@ -1,65 +1,65 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (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/NPL/
#
# 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.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH=../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = bcorb
MODULE = bcorb
IS_COMPONENT = 1
OBJS = \
.\$(OBJDIR)\bcORB.cpp \
..\$(OBJDIR)\src\Allocator.cpp \
..\$(OBJDIR)\src\Call.cpp \
..\$(OBJDIR)\src\Marshaler.cpp \
..\$(OBJDIR)\src\ORB.cpp \
..\$(OBJDIR)\src\UnMarshaler.cpp \
..\$(OBJDIR)\src\util.cpp \
$(NULL)
EXPORTS = \
bcORB.h \
../public/bcIORB.h \
../public/bcDefs.h \
../public/bcICall.h \
../public/bcIUnMarshaler.h \
../public/bcIAllocator.h \
../public/bcIMarshaler.h \
../public/bcIStub.h \
../public/bcIThread.h
CXXFLAGS += -I../public -I../src
include $(topsrcdir)/config/rules.mk
#!gmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (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/NPL/
#
# 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.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH=../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = bcorb
MODULE = bcorb
IS_COMPONENT = 1
CPPSRCS = \
bcORB.cpp \
../src/Allocator.cpp \
../src/Call.cpp \
../src/Marshaler.cpp \
../src/ORB.cpp \
../src/UnMarshaler.cpp \
../src/util.cpp \
$(NULL)
EXPORTS = \
bcORB.h \
../public/bcIORB.h \
../public/bcDefs.h \
../public/bcICall.h \
../public/bcIUnMarshaler.h \
../public/bcIAllocator.h \
../public/bcIMarshaler.h \
../public/bcIStub.h \
../public/bcIThread.h
CXXFLAGS += -I../public -I../src
include $(topsrcdir)/config/rules.mk

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

@ -27,11 +27,6 @@ srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS= \
loader \
src \
classes \
test \
$(NULL)
DIRS= src loader classes test
include $(topsrcdir)/config/rules.mk

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

@ -26,52 +26,58 @@ import java.util.*;
public class ProxyClass { //nb it should not be public
public ProxyClass(IID _iid, Method[] _methods) { //nb it should not be public
iid = _iid;
methods = _methods;
if (classes == null) {
classes = new Hashtable();
}
classes.put(iid, this);
iid = _iid;
methods = _methods;
if (classes == null) {
classes = new Hashtable();
}
classes.put(iid, this);
}
Method getMethodByIndex(int mid) { //first method has index equal to 'offset'
System.out.println("--[java]ProxyClass.GetMehodByIndex "+mid);
Method result = null;
try {
result = methods[mid-offset];
} catch (Exception e) {
e.printStackTrace();
}
return result;
System.out.println("--[java]ProxyClass.GetMehodByIndex "+mid);
Method result = null;
try {
result = methods[mid-offset];
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
int getIndexByMethod(Method method) {
int result = 0;
if (method == null
||methods == null) {
return result;
}
for (int i = 0; i < methods.length; i++) {
if (methods[i].equals(method)) {
result = i + offset;
break;
}
}
return result;
int result = 0;
if (method == null
||methods == null) {
return result;
}
for (int i = 0; i < methods.length; i++) {
if (methods[i].equals(method)) {
result = i + offset;
break;
}
}
return result;
}
static ProxyClass getProxyClass(IID iid) {
ProxyClass result = null;
Object obj = null;
if (classes != null) {
obj = classes.get(iid);
if (obj != null
&& (obj instanceof ProxyClass)) {
result = (ProxyClass)obj;
}
}
return result;
ProxyClass result = null;
Object obj = null;
if (classes != null) {
obj = classes.get(iid);
if (obj != null
&& (obj instanceof ProxyClass)) {
result = (ProxyClass)obj;
}
}
return result;
}
private IID iid;
private Method[] methods;
private final int offset = 3; //from xpcom
static Hashtable classes = null;
}

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

@ -25,15 +25,15 @@ import java.lang.reflect.*;
public class Utilities {
static Object callMethodByIndex(Object obj, IID iid, int mid, Object[] args) {
System.out.println("--org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
System.out.println("--[java]org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
for (int i = 0; i < args.length; i++) {
System.out.println("--callMethodByIndex args["+i+"] = "+args[i]);
System.out.println("--[java]callMethodByIndex args["+i+"] = "+args[i]);
}
Method method = getMethodByIndex(mid,iid);
System.out.println("--callMethodByIndex method "+method);
try {
if (method != null) {
method.invoke(obj,args);
method.invoke(obj,args);
}
} catch (Exception e) {
e.printStackTrace();
@ -41,34 +41,34 @@ public class Utilities {
return null; //nb for testing
}
static Object callMethod(long oid, Method method, IID iid, long orb , Object[] args) {
System.out.println("--[java]Utilities.callMethod "+method);
int mid = getIndexByMethod(method, iid);
if (mid <= 0) {
return null;
}
System.out.println("--[java]Utilities.callMethod "+mid);
return callMethodByIndex(oid,mid,iid.getString(), orb, args);
System.out.println("--[java]Utilities.callMethod "+method);
int mid = getIndexByMethod(method, iid);
if (mid <= 0) {
return null;
}
System.out.println("--[java]Utilities.callMethod "+mid);
return callMethodByIndex(oid,mid,iid.getString(), orb, args);
}
private static Method getMethodByIndex(int index, IID iid) {
Method result = null;
ProxyClass proxyClass = ProxyClass.getProxyClass(iid);
if (proxyClass != null) {
result = proxyClass.getMethodByIndex(index);
}
return result;
Method result = null;
ProxyClass proxyClass = ProxyClass.getProxyClass(iid);
if (proxyClass != null) {
result = proxyClass.getMethodByIndex(index);
}
return result;
}
private static int getIndexByMethod(Method method, IID iid) {
int result = 0;
ProxyClass proxyClass = ProxyClass.getProxyClass(iid);
if (proxyClass != null) {
result = proxyClass.getIndexByMethod(method);
}
return result;
int result = 0;
ProxyClass proxyClass = ProxyClass.getProxyClass(iid);
if (proxyClass != null) {
result = proxyClass.getIndexByMethod(method);
}
return result;
}
private static native Object callMethodByIndex(long oid, int index, String iid, long orb, Object[] args);
static {
System.loadLibrary("bcjavastubs");
System.loadLibrary("bcjavastubs");
}
}
@ -76,3 +76,7 @@ public class Utilities {

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

@ -12,9 +12,9 @@
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# The Initial Developer of the Original Code is Sun Microsystems,
# Inc. Portions created by Sun are
# Copyright (C) 1999 Sun Microsystems, Inc. All
# Rights Reserved.
#
# Contributor(s):
@ -27,20 +27,23 @@ srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
MODULE = javaloader
LIBRARY_NAME = javaloader
IS_COMPONENT = 1
CPPSRCS = bcJavaComponentLoader.cpp bcJavaModule.cpp bcJavaComponentFactory.cpp
include $(topsrcdir)/config/rules.mk
ifneq ($(OS_ARCH),BeOS)
LIBS += -lmozjs -lxpcom $(NSPR_LIBS)
endif
EXTRA_DSO_LDOPTS += \
$(MOZ_COMPONENT_LIBS) \
CPPSRCS = \
bcJavaComponentLoader.cpp \
bcJavaModule.cpp \
bcJavaComponentFactory.cpp \
$(NULL)
CXXFLAGS += -I$(JDKHOME)/include -I$(JDKHOME)/include/linux $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
EXTRA_DSO_LDOPTS += \
-L$(DIST)/bin/components/ \
-lbcorb -lbcxpcomstubs -lbcjavastubs \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -22,7 +22,7 @@
#
DEPTH=../../../..
DEPTH =../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
@ -48,12 +48,12 @@ CPPSRCS = \
org_mozilla_xpcom_Utilities.cpp \
$(NULL)
CXXFLAGS += $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
CXXFLAGS += -I$(JDKHOME)/include -I$(JDKHOME)/include/linux $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
DSO_LDOPTS += \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/ \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/classic \
-ljava -ljvm \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/server \
-ljvm \
$(NULL)
ifneq ($(OS_ARCH), Linux)
@ -61,7 +61,11 @@ DSO_LDOPTS += \
-lthread -lXm -lX11 -lXt -lm
endif
EXTRA_DSO_LDOPTS += \
-L$(DIST)/bin/components/ \
-lbcorb \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -31,29 +31,41 @@ JavaVM *bcJavaGlobal::jvm = NULL;
#define PATH_SEPARATOR ':'
#endif
#ifdef JRI_MD_H //we are using jni.h from netscape
#define JNIENV
#else
#define JNIENV (void**)
#endif
JNIEnv * bcJavaGlobal::GetJNIEnv(void) {
JNIEnv * res;
printf("--bcJavaGlobal::GetJNIEnv begin\n");
JNIEnv * env;
int res;
if (!jvm) {
StartJVM();
StartJVM();
}
if (jvm) {
jvm->AttachCurrentThread(&res,NULL);
res = jvm->AttachCurrentThread(JNIENV &env,NULL);
}
printf("--bcJavaGlobal::GetJNIEnv \n");
return res;
printf("--bcJavaGlobal::GetJNIEnv %d\n",res);
return env;
}
void bcJavaGlobal::StartJVM() {
printf("--bcJavaGlobal::StartJVM begin\n");
JNIEnv *env = NULL;
jint res;
jsize jvmCount;
JNI_GetCreatedJavaVMs(&jvm, 1, &jvmCount);
printf("--bcJavaGlobal::StartJVM after GetCreatedJavaVMs\n");
if (jvmCount) {
return;
}
JDK1_1InitArgs vm_args;
char classpath[1024];
JNI_GetDefaultJavaVMInitArgs(&vm_args);
printf("--[c++] version %d",(int)vm_args.version);
vm_args.version = 0x00010001;
/* Append USER_CLASSPATH to the default system class path */
sprintf(classpath, "%s%c%s",
@ -65,10 +77,37 @@ void bcJavaGlobal::StartJVM() {
vm_args.properties = props;
vm_args.classpath = classpath;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, &env, &vm_args);
printf("--bcJavaGlobal::StartJVM jvm started\n");
res = JNI_CreateJavaVM(&jvm, JNIENV &env, &vm_args);
#if 0
char classpath[1024];
JavaVMInitArgs vm_args;
JavaVMOption options[2];
sprintf(classpath, "-Djava.class.path=%s",PR_GetEnv("CLASSPATH"));
options[0].optionString = classpath;
options[1].optionString="-Djava.compiler=NONE";
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
#endif
printf("--bcJavaGlobal::StartJVM jvm started res %d\n",res);
}

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

@ -23,7 +23,7 @@ import org.mozilla.xpcom.*;
import java.lang.reflect.*;
public class bcJavaSample implements bcIJavaSample {
public bcJavaSample() {
System.out.println("--[java]bcJavaSample constructor");
System.out.println("--[java]bcJavaSample constructor");
}
public void test0() {
System.out.println("--[java]bcJavaSample.test0 ");
@ -42,32 +42,30 @@ public class bcJavaSample implements bcIJavaSample {
}
}
public void test2(bcIJavaSample o) {
System.out.println("--[java]bcJavaSample.test2");
System.out.println("--[java]bcJavaSample.test2 :)))) Hey Hong");
if (o != null) {
System.out.println("--[java]bcJavaSample.test2 o!= null");
System.out.println("--[java]bcJavaSample.test2");
System.out.println("--[java]bcJavaSample.test2 :)))) Hi there");
if (o != null) {
System.out.println("--[java]bcJavaSample.test2 o!= null");
o.test0();
} else {
System.out.println("--[java]bcJavaSample.test2 o== null");
}
} else {
System.out.println("--[java]bcJavaSample.test2 o== null");
}
}
static IID iid;
static {
try {
Method[] methods = null;
Class bcIJavaSampleClass = Class.forName("bcIJavaSample");
Method[] javaSampleMethods = bcIJavaSampleClass.getMethods();
methods = new Method[3];
methods[0] = javaSampleMethods[javaSampleMethods.length-3];
methods[1] = javaSampleMethods[javaSampleMethods.length-2];
methods[2] = javaSampleMethods[javaSampleMethods.length-1];
System.out.println(methods[0]+" "+methods[1]+" "+methods[2]);
iid = new IID(bcIJavaSample.BC_IJAVASAMPLE_IID_STRING);
ProxyFactory.registerInterfaceForIID(bcIJavaSampleClass,iid);
new ProxyClass(iid, methods);
} catch (Exception e) {
}
try {
Method[] methods = null;
Class bcIJavaSampleClass = Class.forName("bcIJavaSample");
methods = new Method[3];
methods[0] = bcIJavaSampleClass.getDeclaredMethod("test0",new Class[]{});
methods[1] = bcIJavaSampleClass.getDeclaredMethod("test1",new Class[]{Integer.TYPE});
methods[2] = bcIJavaSampleClass.getDeclaredMethod("test2",new Class[]{bcIJavaSampleClass});
System.out.println(methods[0]+" "+methods[1]+" "+methods[2]);
iid = new IID(bcIJavaSample.BC_IJAVASAMPLE_IID_STRING);
ProxyFactory.registerInterfaceForIID(bcIJavaSampleClass,iid);
new ProxyClass(iid, methods);
} catch (Exception e) {
}
}
};

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

@ -46,6 +46,12 @@ LIBS = \
-lxptinfo \
$(NSPR_LIBS) \
$(NULL)
EXTRA_DSO_LDOPTS += \
-L$(DIST)/bin/components/ \
-lbcorb \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -36,6 +36,7 @@ bcXPCOMStub::~bcXPCOMStub() {
}
void bcXPCOMStub::Dispatch(bcICall *call) {
bcIID iid; bcOID oid; bcMID mid;
call->GetParams(&iid, &oid, &mid);
nsIInterfaceInfo *interfaceInfo;