BlackConnect M2 check in.
It should be possible to implement any scriptable interface in java.
Also it should be possible to use any scriptable object from java.
Fixed: 15498, 15500
This commit is contained in:
idk%eng.sun.com 2000-09-12 08:54:13 +00:00
Родитель e38f460093
Коммит a6c42417f0
43 изменённых файлов: 1638 добавлений и 1226 удалений

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

@ -31,6 +31,7 @@ DIRS= \
connect \
xpcom \
java \
xpcom/test/ \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -31,6 +31,7 @@ DIRS= \
connect \
xpcom \
java \
xpcom/test/ \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -1,76 +0,0 @@
Black Connect
================================
This directory contains the Black Connect
The sources is divided into three directories
connect
public headers.
ORB implementation.
xpcom
XPCOM stubs and proxy implementation
java
JAVA stubs and proxy implementation
Java component loader
===============================================
Solaris directions
===============================================
Requirements:
* current mozilla built tree
* JDK1.3
* Perl 5 must be in your path
How To Build:
* make sure the environment var JDKHOME is set to your jdk installation
directory, ie export JDKHOME=/usr/local/jdk1.3
* Add following directories to to your LD_LIBRARY_PATH:
$MOZILLA_FIVE_HOME:$JDKHOME/jre/lib/$HOSTTYPE/native_threads:$JDKHOME/jre/lib/$HOSTTYPE/classic:
$JDKHOME/jre/lib/$HOSTTYPE/:
* type "gmake"
==============================================
Linux directions
===============================================
Requirements:
* mozilla m16 build tree
* JDK1.3 from IBM
* Perl 5 must be in your path
How To Build:
* make sure the environment var JDKHOME is set to your jdk installation
directory, ie export JDKHOME=/usr/local/jdk1.3
* Add following directories to to your LD_LIBRARY_PATH:
$MOZILLA_FIVE_HOME:$JDKHOME/jre/bin:$JDKHOME/jre/bin/classic:
* type "gmake"
==============================================
How to run test java component
===============================================
* cd java/test
* gmake
* add $MOZILLA_FIVE_HOME/dist/classes to your CLASSPATH
Test component would be placed in dist/bin/componets and loaded on mozilla
sturtup (or you can use regxpcom for testing)

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

@ -1,36 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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/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.
*
* The Original Code is mozilla.org code.
*
* 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIMarshaler_h
#define __bcIMarshaler_h
#include "bcIAllocator.h"
#include "bcDefs.h"
class bcIMarshaler {
public:
virtual int WriteSimple(void *ptr, bcXPType type) = 0;
virtual int WriteString(void *ptr, size_t size) = 0;
virtual int WriteArray(void *ptr, size_t length, bcXPType type) = 0;
};
#endif

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

@ -1,36 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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/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.
*
* The Original Code is mozilla.org code.
*
* 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIUnMarshaler_h
#define __bcIUnMarshaler_h
#include "bcIAllocator.h"
#include "bcDefs.h"
class bcIUnMarshaler {
public:
virtual int ReadSimple(void *ptr, bcXPType type) = 0;
virtual int ReadString(void *ptr, size_t *size, bcIAllocator * allocator = 0) = 0;
virtual int ReadArray(void *ptr, size_t *length, bcXPType type, bcIAllocator * allocator) = 0;
};
#endif

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

@ -1,78 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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/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.
*
* The Original Code is mozilla.org code.
*
* 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "Call.h"
#include "Marshaler.h"
#include "UnMarshaler.h"
Call::Call() {
}
Call::Call(bcIID *_iid, bcOID *_oid, bcMID _mid, bcIORB *_orb):out(0),in(0) {
iid = *_iid;
oid = *_oid;
mid = _mid;
orb = _orb;
}
Call::~Call() {
if (out)
delete out;
if (in)
delete in;
}
int Call::GetParams(bcIID *_iid, bcOID *_oid, bcMID *_mid) {
*_iid = iid;
*_oid = oid;
*_mid = mid;
return 0;
}
bcIMarshaler * Call::GetMarshaler() {
out = new ostrstream();
return new Marshaler(out);
}
bcIUnMarshaler * Call::GetUnMarshaler() {
if (!out) {
return NULL;
}
char *buf = out->str();
cout<<"Call::GetUnMarshaler "<<out->pcount()<<"\n";
#if 0
cout<<"Call::GetUnMarshaler buf:\n";
for (int i = 0; i < out->pcount(); i++) {
cout<<" buf["<<i<<"]"<<(unsigned)buf[i]<<"\n";
}
#endif
if (out->pcount()) {
in = new istrstream(buf,out->pcount());
}
return new UnMarshaler(in);
}
bcIORB * Call::GetORB() {
return orb;
}

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

@ -43,38 +43,10 @@ int Marshaler::WriteString(void *ptr, size_t size) {
&& ptr) {
size = 1;
}
WriteArray(ptr,size, bc_T_CHAR);
out->write((const char*)&size, sizeof(size_t));
if (size) {
out->write((const char*)ptr,type2size(bc_T_CHAR)*size);
}
return 0;
}
int Marshaler::WriteArray(void *ptr, size_t length, bcXPType type) {
if (!ptr) {
length = 0;
}
cout<<"Marshaler::WriteArray("<<length<<")\n";
out->write((const char*)&length, sizeof(size_t));
switch (type) {
case bc_T_CHAR_STR:
case bc_T_WCHAR_STR:
{
for (unsigned int i = 0; i < length; i++) {
char *str = ((char**)ptr)[i];
size_t size = (!str) ? 0 : strlen(str)+1; //we want to store \0
WriteString((void *)str, size);
}
break;
}
default:
if (length) {
out->write((const char*)ptr,type2size(type)*length);
}
}
return 0;
}

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

@ -1,42 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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/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.
*
* The Original Code is mozilla.org code.
*
* 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __Marshaler_h
#define __Marshaler_h
#include <iostream.h>
#include "bcIMarshaler.h"
class Marshaler : public bcIMarshaler {
public:
Marshaler(ostream *out);
virtual ~Marshaler();
virtual int WriteSimple(void *ptr, bcXPType type);
virtual int WriteString(void *ptr, size_t size);
virtual int WriteArray(void *ptr, size_t length, bcXPType type);
private:
ostream * out;
};
#endif

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

@ -24,9 +24,9 @@
#include "Call.h"
ORB::ORB() {
currentID = 0;
currentID = 1;
for (int i = 0; i < STUBS_COUNT; i++) {
stubs[i] = 0;
stubs[i] = 0;
}
}
@ -50,10 +50,10 @@ int ORB::SendReceive(bcICall *call) {
call->GetParams(&iid,&oid,&mid);
bcIStub *stub = GetStub(&oid);
if (stub) {
stub->Dispatch(call);
return 0;
stub->Dispatch(call);
return 0;
} else {
return 1; //nb need to think about error values
return 1; //nb need to think about error values
}
}

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

@ -37,7 +37,13 @@ int UnMarshaler::ReadSimple(void *ptr, bcXPType type) {
return 0;
}
int UnMarshaler::ReadString(void *ptr, size_t *size, bcIAllocator * allocator) {
ReadArray(ptr, size, bc_T_CHAR, allocator);
size_t length;
in->read((char*)size,sizeof(size_t));
*(char**)ptr = (char *)allocator->Alloc(*size * type2size(bc_T_CHAR));
if (*size) {
in->read(*(char**)ptr,*size * type2size(bc_T_CHAR));
}
if (*size == 1) {
if (!(*(char**)ptr)[0]) {
*size = 0;
@ -45,85 +51,3 @@ int UnMarshaler::ReadString(void *ptr, size_t *size, bcIAllocator * allocator) {
}
return 0;
}
int UnMarshaler::ReadArray(void *ptr, size_t *length, bcXPType type, bcIAllocator * allocator) {
in->read((char*)length,sizeof(size_t));
cout<<"UnMarshaler *length "<<*length<<"\n";
if (!length) {
ptr = 0;
}
switch (type) {
case bc_T_CHAR_STR:
case bc_T_WCHAR_STR:
{
char **strArray = *(char***)ptr;
*strArray = (char*)allocator->Alloc(*length * sizeof(char*));
for (unsigned int i = 0; i < *length; i++) {
char * str;
size_t size;
ReadString((void*)&str, &size, allocator);
strArray[i] = str;
}
break;
}
default:
char *p = *(char**)ptr = (char *)allocator->Alloc(*length * type2size(type));
if (*length) {
in->read(p,*length * type2size(type));
}
}
return 0;
}

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

@ -1,39 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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/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.
*
* The Original Code is mozilla.org code.
*
* 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __UnMarshaler_h
#define __UnMarshaler_h
#include <iostream.h>
#include "bcIUnMarshaler.h"
class UnMarshaler : public bcIUnMarshaler {
public:
UnMarshaler(istream *in);
virtual ~UnMarshaler();
virtual int ReadSimple(void *ptr, bcXPType type);
virtual int ReadString(void *ptr, size_t *size, bcIAllocator * allocator);
virtual int ReadArray(void *ptr, size_t *length, bcXPType type, bcIAllocator * allocator);
private:
istream *in;
};
#endif

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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
@ -23,33 +23,36 @@ package org.mozilla.xpcom;
public class IID {
public IID(String iid) {
this.iid = (iid == null) ? "" : iid;
this.iid = (iid == null) ? "" : iid;
}
public boolean equals(Object obj) {
if (! (obj instanceof IID)) {
return false;
}
boolean res = iid.equals(((IID)obj).iid);
return res;
if (! (obj instanceof IID)) {
return false;
}
boolean res = iid.equals(((IID)obj).iid);
return res;
}
public String toString() {
return "org.mozilla.xpcom.IID@"+iid;
return "org.mozilla.xpcom.IID@"+iid;
}
public int hashCode() {
int h = iid.hashCode();
return h;
int h = iid.hashCode();
return h;
}
public String getString() {
return iid;
return iid;
}
private String iid;
public static Class TYPE;
static {
try {
TYPE = Class.forName("org.mozilla.xpcom.Proxy");
} catch (Exception e) { //it could not happen
TYPE = null;
}
try {
TYPE = Class.forName("org.mozilla.xpcom.Proxy");
} catch (Exception e) { //it could not happen
TYPE = null;
}
}
}

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

@ -1,83 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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/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.
*
* The Original Code is mozilla.org code.
*
* 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):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.xpcom;
import java.lang.reflect.*;
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);
}
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;
}
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;
}
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;
}
private IID iid;
private Method[] methods;
private final int offset = 3; //from xpcom
static Hashtable classes = null;
}

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

@ -48,45 +48,60 @@ class ProxyKey {
public class ProxyFactory {
public static void registerInterfaceForIID(Class inter, IID iid) {
System.out.println("--[java] ProxyFactory.registerInterfaceForIID "+iid);
if (interfaces == null) {
interfaces = new Hashtable();
}
interfaces.put(iid, inter); //nb who is gonna remove object from cache?
System.out.println("--[java] ProxyFactory.registerInterfaceForIID "+iid);
if (interfaces == null) {
interfaces = new Hashtable();
}
interfaces.put(iid, inter); //nb who is gonna remove object from cache?
}
public static Class getInterface(IID iid) {
System.out.println("--[java] ProxyFactory.getInterface "+iid);
Object obj = null;
if (interfaces != null) {
obj = interfaces.get(iid);
if (obj == null) {
System.out.println("--[java] ProxyFactory.getInterface interface== null");
return null;
}
}
if (!(obj instanceof Class)) {
System.out.println("--[java] ProxyFactory.getInterface !(obj instanceof Class"+obj);
return null;
}
return (Class)obj;
}
public static Object getProxy(long oid, IID iid, long orb) {
System.out.println("--[java] ProxyFactory.getProxy "+iid);
ProxyKey key = new ProxyKey(oid, iid);
Object obj = null;
Object result = null;
if (proxies != null) {
obj = proxies.get(key);
if (obj != null
&& (obj instanceof Reference)) {
result = ((Reference)obj).get();
}
} else {
proxies = new Hashtable();
}
if (result == null) {
if (interfaces != null) {
obj = interfaces.get(iid);
if (obj == null) {
System.out.println("--[java] ProxyFactory.getProxy obj == null");
return null;
}
}
if (!(obj instanceof Class)) {
System.out.println("--[java] ProxyFactory.getProxy !(obj instanceof Class"+obj);
return null;
}
Class inter = (Class) obj;
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
proxies.put(new WeakReference(result), key);
}
System.out.println("--[java] ProxyFactory.getProxy end"+result);
return result;
try {
System.out.println("--[java] ProxyFactory.getProxy "+iid);
ProxyKey key = new ProxyKey(oid, iid);
Object obj = null;
Object result = null;
if (proxies != null) {
obj = proxies.get(key);
if (obj != null
&& (obj instanceof Reference)) {
result = ((Reference)obj).get();
}
} else {
proxies = new Hashtable();
}
if (result == null) {
Class inter = getInterface(iid);
if (inter == null) {
System.out.println("--[java] ProxyFactory.getProxy we did not find interface for iid="+iid+"returing null");
return null;
}
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
proxies.put(new WeakReference(result), key);
}
System.out.println("--[java] ProxyFactory.getProxy we got proxy "+result);
return result;
} catch (Exception e) {
System.out.println("--[java] ProxyFactory.getProxy we got exception "+e);
}
return null;
}
protected static Hashtable proxies = null;
private static Hashtable interfaces = null;

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

@ -32,10 +32,14 @@ class ProxyHandler implements InvocationHandler {
public Object invoke(Object proxy,
Method method,
Object[] args) throws Throwable {
return Utilities.callMethod(oid, method, iid, orb, args);
System.out.println("--[java]ProxyHandler.invoke "+method);
if ("toString".equals(method.getName())) {
return "ProxyObject@{oid = "+oid+" iid = "+iid+"}";
}
return Utilities.callMethod(oid, method, iid, orb, args);
}
private long oid;
private IID iid;
private long orb;
}

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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
@ -24,26 +24,29 @@ package org.mozilla.xpcom;
import java.lang.reflect.*;
public class Utilities {
static Object callMethodByIndex(Object obj, IID iid, int mid, Object[] args) {
System.out.println("--[java]org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
for (int i = 0; i < args.length; 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);
}
} catch (Exception e) {
e.printStackTrace();
}
return null; //nb for testing
System.out.println("--[java]org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
for (int i = 0; i < args.length; i++) {
System.out.println("--[java]callMethodByIndex args["+i+"] = "+args[i]);
}
Method method = getMethodByIndex(mid,iid);
System.out.println("--[java] org.mozilla.xpcom.Utilities.callMethodByIndex method "+method);
try {
if (method != null) {
method.invoke(obj,args);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("--callMethodByIndex method finished"+method);
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) {
System.out.println("--[java]Utilities.callMethod we do not have implementation for "+method);
return null;
}
System.out.println("--[java]Utilities.callMethod "+mid);

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

@ -49,18 +49,18 @@ NS_IMETHODIMP bcJavaComponentFactory::CreateInstance(nsISupports *aOuter, const
nsresult r;
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance javaStubsAndProxies failed \n");
return r;
printf("--bcJavaComponentFactory::CreateInstance javaStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance xpcomStubsAndProxies failed \n");
return r;
printf("--bcJavaComponentFactory::CreateInstance xpcomStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance bcORB failed \n");
return r;
printf("--bcJavaComponentFactory::CreateInstance bcORB failed \n");
return r;
}
bcIORB *orb;
_orb->GetORB(&orb);
@ -68,6 +68,7 @@ NS_IMETHODIMP bcJavaComponentFactory::CreateInstance(nsISupports *aOuter, const
r = javaStubsAndProxies->GetOID(location, &oid);
printf("--bcJavaComponentFactory::CreateInstance after GetOID");
nsISupports *proxy;
printf("--[c++]bcJavaComponentFactory::CreateInstance iid:%s\n",iid.ToString());
xpcomStubsAndProxies->GetProxy(oid, iid, orb, &proxy);
*result = proxy;
printf("--bcJavaComponentFactory::CreateInstance end");

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

@ -298,7 +298,7 @@ nsresult bcJavaComponentLoader::SetRegistryInfo(const char *registryLocation,
NS_FAILED(rv = mRegistry->SetLongLong(key, fileSizeValueName, &fileSize)))
return rv;
printf("SetRegistryInfo(%s) => (%d,%d)\n", registryLocation,
modDate, fileSize);
(int)modDate, (int)fileSize);
return NS_OK;
}

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

@ -55,7 +55,7 @@ NS_IMETHODIMP bcJavaModule::GetClassObject(nsIComponentManager *aCompMgr, const
/* void registerSelf (in nsIComponentManager aCompMgr, in nsIFile location, in string registryLocation, in string componentType); */
NS_IMETHODIMP bcJavaModule::RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *_location, const char *registryLocation, const char *componentType) {
nsresult result;
nsresult result = NS_OK;
printf("--JavaModule::RegisterSelf\n");
ifstream in(location);
char cidStr[500], progid[1000], desc[1000];
@ -66,7 +66,7 @@ NS_IMETHODIMP bcJavaModule::RegisterSelf(nsIComponentManager *aCompMgr, nsIFile
nsCID cid;
cid.Parse((const char *)cidStr);
aCompMgr->RegisterComponentWithType(cid, desc, progid, _location, registryLocation, PR_TRUE, PR_TRUE, componentType);
return NS_OK;
return result;
}
/* void unregisterSelf (in nsIComponentManager aCompMgr, in nsIFile location, in string registryLocation); */

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

@ -51,17 +51,18 @@ CPPSRCS = \
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 \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/native_threads \
-ljvm -lhpi -ljava\
$(NULL)
#DSO_LDOPTS += \
# -L$(JDKHOME)/jre/lib/$(HOSTTYPE)/ \
# -L$(JDKHOME)/jre/lib/$(HOSTTYPE)/classic \
# -L$(JDKHOME)/jre/bin \
# -L$(JDKHOME)/jre/bin/classic \
# -ljvm \
# $(NULL)
DSO_LDOPTS += \
-L$(JDKHOME)/jre/bin \
-L$(JDKHOME)/jre/bin/classic \
-ljvm \
$(NULL)
ifneq ($(OS_ARCH), Linux)
DSO_LDOPTS += \

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

@ -70,7 +70,7 @@ jobject bcIIDJava::GetObject(nsIID *iid) {
char *str = iid->ToString(); //nb free ?
jstring jstr = NULL;
if (str) {
char *siid = str+1; //we do need to have {_fdsf_}
char *siid = str+1; //we do need to have it. The format is {_xxx-xxx-xxx_}
siid[strlen(siid)-1] = 0;
jstr = env->NewStringUTF((const char *)siid);
}
@ -90,7 +90,7 @@ nsIID bcIIDJava::GetIID(jobject obj) {
}
jstring jstr = (jstring)env->CallObjectMethod(obj, getStringMID);
const char * str = NULL;
str = env->GetStringUTFChars(jstr,NULL);
str = env->GetStringUTFChars(jstr,NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jstr,str);

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

@ -38,7 +38,6 @@ JavaVM *bcJavaGlobal::jvm = NULL;
#endif
JNIEnv * bcJavaGlobal::GetJNIEnv(void) {
printf("--bcJavaGlobal::GetJNIEnv begin\n");
JNIEnv * env;
int res;
if (!jvm) {
@ -47,7 +46,6 @@ JNIEnv * bcJavaGlobal::GetJNIEnv(void) {
if (jvm) {
res = jvm->AttachCurrentThread(JNIENV &env,NULL);
}
printf("--bcJavaGlobal::GetJNIEnv %d\n",res);
return env;
}
@ -62,6 +60,7 @@ void bcJavaGlobal::StartJVM() {
if (jvmCount) {
return;
}
#if 0
JDK1_1InitArgs vm_args;
char classpath[1024];
JNI_GetDefaultJavaVMInitArgs(&vm_args);
@ -78,16 +77,18 @@ void bcJavaGlobal::StartJVM() {
vm_args.classpath = classpath;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, JNIENV &env, &vm_args);
#if 0
#endif
#if 1
char classpath[1024];
JavaVMInitArgs vm_args;
JavaVMOption options[2];
sprintf(classpath, "-Djava.class.path=%s",PR_GetEnv("CLASSPATH"));
sprintf(classpath, "-Djava.class.path=%s:/ws/mozilla/dist/classes",PR_GetEnv("CLASSPATH"));
printf("--[c++] classpath %s\n",classpath);
options[0].optionString = classpath;
options[1].optionString="-Djava.compiler=NONE";
options[1].optionString=""; //-Djava.compiler=NONE";
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.nOptions = 2;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

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

@ -28,39 +28,54 @@
#include "nsIServiceManager.h"
jclass bcJavaMarshalToolkit::objectClass = NULL;
jclass bcJavaMarshalToolkit::objectArrayClass = NULL;
jclass bcJavaMarshalToolkit::booleanClass = NULL;
jclass bcJavaMarshalToolkit::booleanArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::booleanInitMID = NULL;
jmethodID bcJavaMarshalToolkit::booleanValueMID = NULL;
jclass bcJavaMarshalToolkit::characterClass = NULL;
jmethodID bcJavaMarshalToolkit::characterInitMID = NULL;
jmethodID bcJavaMarshalToolkit::characterValueMID = NULL;
jclass bcJavaMarshalToolkit::charClass = NULL;
jclass bcJavaMarshalToolkit::charArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::charInitMID = NULL;
jmethodID bcJavaMarshalToolkit::charValueMID = NULL;
jclass bcJavaMarshalToolkit::byteClass = NULL;
jclass bcJavaMarshalToolkit::byteArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::byteInitMID = NULL;
jmethodID bcJavaMarshalToolkit::byteValueMID = NULL;
jclass bcJavaMarshalToolkit::shortClass = NULL;
jclass bcJavaMarshalToolkit::shortArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::shortInitMID = NULL;
jmethodID bcJavaMarshalToolkit::shortValueMID = NULL;
jclass bcJavaMarshalToolkit::integerClass = NULL;
jmethodID bcJavaMarshalToolkit::integerInitMID = NULL;
jmethodID bcJavaMarshalToolkit::integerValueMID = NULL;
jclass bcJavaMarshalToolkit::intClass = NULL;
jclass bcJavaMarshalToolkit::intArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::intInitMID = NULL;
jmethodID bcJavaMarshalToolkit::intValueMID = NULL;
jclass bcJavaMarshalToolkit::longClass = NULL;
jclass bcJavaMarshalToolkit::longArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::longInitMID = NULL;
jmethodID bcJavaMarshalToolkit::longValueMID = NULL;
jclass bcJavaMarshalToolkit::floatClass = NULL;
jclass bcJavaMarshalToolkit::floatArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::floatInitMID = NULL;
jmethodID bcJavaMarshalToolkit::floatValueMID = NULL;
jclass bcJavaMarshalToolkit::doubleClass = NULL;
jclass bcJavaMarshalToolkit::doubleArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::doubleInitMID = NULL;
jmethodID bcJavaMarshalToolkit::doubleValueMID = NULL;
jclass bcJavaMarshalToolkit::stringClass = NULL;
jclass bcJavaMarshalToolkit::stringArrayClass = NULL;
jclass bcJavaMarshalToolkit::iidClass = NULL;
jclass bcJavaMarshalToolkit::iidArrayClass = NULL;
jmethodID bcJavaMarshalToolkit::getClassMID = NULL;
static NS_DEFINE_CID(kJavaStubsAndProxies,BC_JAVASTUBSANDPROXIES_CID);
@ -85,12 +100,6 @@ bcJavaMarshalToolkit::bcJavaMarshalToolkit(PRUint16 _methodIndex,
bcJavaMarshalToolkit::~bcJavaMarshalToolkit() {
}
nsresult bcJavaMarshalToolkit::Marshal(bcIMarshaler *m) {
//nb todo
return NS_OK;
}
class javaAllocator : public bcIAllocator {
public:
javaAllocator(nsIAllocator *_allocator) {
@ -110,351 +119,589 @@ private:
nsCOMPtr<nsIAllocator> allocator;
};
nsresult bcJavaMarshalToolkit::Marshal(bcIMarshaler *m) {
PRUint32 paramCount = info->GetParamCount();
nsresult r = NS_OK;
for (unsigned int i = 0; (i < paramCount) && NS_SUCCEEDED(r); i++) {
nsXPTParamInfo param = info->GetParam(i);
if ((callSide == onClient && !param.IsIn())
|| (callSide == onServer && !param.IsOut())) {
continue;
}
jobject object = env->GetObjectArrayElement(args,i);
r = MarshalElement(m, object, param.IsOut(), &param, XPTType2bcXPType(param.GetType().TagPart()), i);
}
return r;
}
nsresult bcJavaMarshalToolkit::UnMarshal(bcIUnMarshaler *um) {
printf("--nsresult bcJavaMarshalToolkit::UnMarshal\n");
bcIAllocator * allocator = new javaAllocator(nsAllocator::GetGlobalAllocator());
PRUint32 paramCount = info->GetParamCount();
jobject value;
void * data = allocator->Alloc(sizeof(nsXPTCMiniVariant)); // sizeof(nsXPTCMiniVariant) is ok
for (unsigned int i = 0; i < paramCount; i++) {
nsXPTParamInfo param = info->GetParam(i);
PRBool isOut = param.IsOut();
nsXPTType type = param.GetType();
if ( (callSide == onServer && !param.IsIn()
if ( (callSide == onServer && !param.IsIn()
|| (callSide == onClient && !param.IsOut()))){
if (callSide == onServer
&& isOut) { //we need to allocate memory for out parametr
value = Native2Java(NULL,XPTType2bcXPType(type.TagPart()),1);
UnMarshalElement(&value, i, NULL, 1, &param, XPTType2bcXPType(type.TagPart()),allocator);
env->SetObjectArrayElement(args,i,value);
}
continue;
}
switch(type.TagPart()) {
case nsXPTType::T_IID :
case nsXPTType::T_I8 :
case nsXPTType::T_U8 :
case nsXPTType::T_I16 :
case nsXPTType::T_U16 :
case nsXPTType::T_I32 :
case nsXPTType::T_U32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
um->ReadSimple(data,XPTType2bcXPType(type.TagPart()));
value = Native2Java(data,XPTType2bcXPType(type.TagPart()),isOut);
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
size_t size;
um->ReadString(data,&size,allocator);
//nb to do
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
{
printf("--[c++] we have an interface\n");
bcOID oid;
um->ReadSimple(&oid,XPTType2bcXPType(type.TagPart()));
printf("%d oid", oid);
nsIID iid;
um->ReadSimple(&iid,bc_T_IID);
void * p[2];
p[0]=&oid; p[1]= &iid;
data = p;
value = Native2Java(data,bc_T_INTERFACE,isOut);
break;
}
case nsXPTType::T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, &param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
//nb to do array
break;
}
default:
return NS_ERROR_FAILURE;
}
UnMarshalElement(&value, i, um, isOut, &param, XPTType2bcXPType(type.TagPart()),allocator);
env->SetObjectArrayElement(args,i,value);
}
delete allocator;
return NS_OK;
}
#define MARSHAL_SIMPLE_ELEMENT(_type_,_Type_) \
do { \
int indexInArray; \
j##_type_ data; \
if (! isOut \
&& (modifier == none)) { \
data = env->Call##_Type_##Method(value,_type_##ValueMID); \
} else if (isOut && (modifier == array)) { \
/* could not happend. We take care about it in T_ARRAY case */ \
} else if (modifier == arrayElement \
|| (isOut && (modifier == none))) { \
indexInArray = (modifier == arrayElement) ? ind : 0; \
env->Get##_Type_##ArrayRegion((j##_type_##Array)value, indexInArray, 1, &data); \
} \
m->WriteSimple(&data,type); \
} while (0)
nsresult
bcJavaMarshalToolkit::MarshalElement(bcIMarshaler *m, jobject value, PRBool isOut, nsXPTParamInfo * param,
bcXPType type, uint8 ind, ArrayModifier modifier) {
nsresult r = NS_OK;
switch(type) {
case bc_T_I8:
case bc_T_U8:
{
MARSHAL_SIMPLE_ELEMENT(byte,Byte);
break;
}
case bc_T_I16:
case bc_T_U16:
{
MARSHAL_SIMPLE_ELEMENT(short,Short);
break;
};
case bc_T_I32:
case bc_T_U32:
{
MARSHAL_SIMPLE_ELEMENT(int,Int);
break;
}
case bc_T_I64:
case bc_T_U64:
{
MARSHAL_SIMPLE_ELEMENT(long,Long);
break;
}
case bc_T_FLOAT:
{
MARSHAL_SIMPLE_ELEMENT(float,Float);
break;
}
case bc_T_DOUBLE:
{
MARSHAL_SIMPLE_ELEMENT(double,Double);
break;
}
case bc_T_BOOL:
{
MARSHAL_SIMPLE_ELEMENT(boolean,Boolean);
break;
}
case bc_T_CHAR:
case bc_T_WCHAR:
{
MARSHAL_SIMPLE_ELEMENT(char,Char);
break;
}
case bc_T_CHAR_STR:
case bc_T_WCHAR_STR: //nb not sure about this
{
int indexInArray;
jstring data = NULL;
if (! isOut
&& (modifier == none)) {
data = (jstring)value;
} else if (modifier == arrayElement
|| (isOut && (modifier == none))) {
indexInArray = (modifier == arrayElement) ? ind : 0;
data = (jstring)env->GetObjectArrayElement((jobjectArray)value,indexInArray);
}
char * str = NULL;
if (data) {
str = (char*)env->GetStringUTFChars((jstring)data,NULL);
m->WriteString(str,strlen(str)+1);
env->ReleaseStringUTFChars(data,str);
} else {
m->WriteString(str,0);
}
break;
}
case bc_T_IID:
{
int indexInArray;
jobject data = NULL;
if (! isOut
&& (modifier == none)) {
data = value;
} else if (modifier == arrayElement
|| (isOut && (modifier == none))) {
indexInArray = (modifier == arrayElement) ? ind : 0;
data = (jstring)env->GetObjectArrayElement((jobjectArray)value,indexInArray);
}
nsIID iid = bcIIDJava::GetIID(data);
m->WriteSimple(&iid, type);
break;
}
case bc_T_INTERFACE:
{
int indexInArray;
jobject data = NULL;
printf("--marshalElement we got interface\n");
bcOID oid = 0;
nsIID *iid;
if (! isOut
&& (modifier == none)) {
data = value;
} else if (modifier == arrayElement
|| (isOut && (modifier == none))) {
indexInArray = (modifier == arrayElement) ? ind : 0;
data = env->GetObjectArrayElement((jobjectArray)value,indexInArray);
}
if (data != NULL) {
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
return NS_ERROR_FAILURE;
}
javaStubsAndProxies->GetOID(data, orb, &oid);
}
m->WriteSimple(&oid,type);
if (param->GetType().TagPart() == nsXPTType::T_INTERFACE) {
if(NS_FAILED(r = interfaceInfo->
GetIIDForParam(methodIndex, param, &iid))) {
return r;
}
m->WriteSimple(iid,bc_T_IID);
} else {
uint8 argnum;
if (NS_FAILED(r = interfaceInfo->GetInterfaceIsArgNumberForParam(methodIndex,
param, &argnum))) {
return r;
}
const nsXPTParamInfo& arg_param = info->GetParam(argnum);
jobject object = env->GetObjectArrayElement(args,argnum);
r = MarshalElement(m, object, arg_param.IsOut(),(nsXPTParamInfo*)&arg_param,
XPTType2bcXPType(arg_param.GetType().TagPart()), (uint8)0);
}
break;
}
case bc_T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
bcXPType type = XPTType2bcXPType(datumType.TagPart());
jobject arrayValue = value;
if (isOut) {
arrayValue = env->GetObjectArrayElement((jobjectArray)value,0);
}
if (m != NULL) {
PRUint32 arraySize = (arrayValue == NULL) ? 0 : env->GetArrayLength((jarray)arrayValue);
m->WriteSimple(&arraySize,bc_T_U32);
for (PRUint32 i = 0; i < arraySize; i++) {
MarshalElement(m,arrayValue,PR_FALSE,param,type,i,arrayElement);
}
}
break;
}
default:
printf("--it should not happend\n");
;
}
return r;
}
#define UNMARSHAL_SIMPLE_ELEMENT(_type_,_Type_) \
do { \
int indexInArray; \
j##_type_ data; \
if (um) { \
um->ReadSimple(&data,type); \
} \
if ( ! isOut \
&& (modifier == none) ) { \
*value = env->NewObject(_type_##Class,_type_##InitMID,data); \
} else if (isOut && (modifier == array)) { \
*value = env->NewObjectArray(1, _type_##ArrayClass, NULL); \
} else if (isOut \
|| (modifier == array)) { \
int arraySize; \
arraySize = (modifier == array) ? ind : 1; \
*value = env->New##_Type_##Array(arraySize); \
} \
if (modifier == arrayElement \
|| (isOut && (modifier == none)) \
) { \
indexInArray = (modifier == arrayElement) ? ind : 0; \
env->Set##_Type_##ArrayRegion((j##_type_##Array)*value, indexInArray, 1, &data); \
} \
} while(0)
nsresult
bcJavaMarshalToolkit::UnMarshalElement(jobject *value, uint8 ind, bcIUnMarshaler *um, int isOut, nsXPTParamInfo * param,
bcXPType type, bcIAllocator *allocator, ArrayModifier modifier) {
switch(type) {
case bc_T_I8:
case bc_T_U8:
{
UNMARSHAL_SIMPLE_ELEMENT(byte,Byte);
break;
}
case bc_T_I16:
case bc_T_U16:
{
UNMARSHAL_SIMPLE_ELEMENT(short,Short);
break;
};
case bc_T_I32:
case bc_T_U32:
{
UNMARSHAL_SIMPLE_ELEMENT(int,Int);
break;
}
case bc_T_I64:
case bc_T_U64:
{
UNMARSHAL_SIMPLE_ELEMENT(long,Long);
break;
}
case bc_T_FLOAT:
{
UNMARSHAL_SIMPLE_ELEMENT(float,Float);
break;
}
case bc_T_DOUBLE:
{
UNMARSHAL_SIMPLE_ELEMENT(double,Double);
break;
}
case bc_T_BOOL:
{
UNMARSHAL_SIMPLE_ELEMENT(boolean,Boolean);
break;
}
case bc_T_CHAR:
case bc_T_WCHAR:
{
UNMARSHAL_SIMPLE_ELEMENT(char,Char);
break;
}
case bc_T_CHAR_STR:
case bc_T_WCHAR_STR: //nb not sure about this
{
int indexInArray;
size_t size;
jstring data = NULL;
if (um) {
um->ReadString(&data,&size,allocator);
data = env->NewStringUTF((const char*)data);
}
if ( ! isOut
&& (modifier == none) ) {
*value = data;
} else if (isOut && (modifier == array)) {
*value = env->NewObjectArray(1, stringArrayClass, NULL);
} else if (isOut
|| (modifier == array)) {
int arraySize;
arraySize = (modifier == array) ? ind : 1;
*value = env->NewObjectArray(arraySize,stringClass,NULL);
}
if (modifier == arrayElement
|| (isOut && (modifier == none))
) {
indexInArray = (modifier == arrayElement) ? ind : 0;
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
}
break;
}
case bc_T_IID:
{
int indexInArray = 0;
jobject data = NULL;
if (um) {
nsIID iid;
um->ReadSimple(&iid,type);
data = bcIIDJava::GetObject(&iid);
}
if ( ! isOut
&& (modifier == none) ) {
*value = data;
} else if (isOut && (modifier == array)) {
*value = env->NewObjectArray(1, iidArrayClass, NULL);
} else if (isOut
|| (modifier == array)) {
int arraySize;
arraySize = (modifier == array) ? ind : 1;
*value = env->NewObjectArray(arraySize,iidClass,NULL);
}
if (modifier == arrayElement
|| (isOut && (modifier == none))
) {
indexInArray = (modifier == arrayElement) ? ind : 0;
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
}
break;
}
case bc_T_INTERFACE:
{
printf("--[c++] bcJavaMarshalToolkit::UnMarshalElement we have an interface\n");
int indexInArray = 0;
jobject data = NULL;
bcOID oid = 0;
nsIID iid;
nsresult r;
jclass clazz = objectClass;
if (um) {
um->ReadSimple(&oid,type);
um->ReadSimple(&iid,bc_T_IID);
printf("%d oid\n",(int) oid);
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
return NS_ERROR_FAILURE;
}
if (oid != 0) {
javaStubsAndProxies->GetProxy(oid, iid, orb, &data);
}
javaStubsAndProxies->GetInterface(iid,&clazz);
}
if ( ! isOut
&& (modifier == none) ) {
*value = data;
} else if (isOut && (modifier == array)) { //how to create type[][] ?
jobject arrayObject;
arrayObject = env->NewObjectArray(1,clazz,NULL);
jclass arrayClass = (jclass) env->CallObjectMethod(arrayObject,getClassMID); //nb how to to it better ?
*value = env->NewObjectArray(1, arrayClass, NULL);
} else if (isOut
|| (modifier == array)) {
int arraySize;
arraySize = (modifier == array) ? ind : 1;
*value = env->NewObjectArray(arraySize,clazz,NULL);
}
if (modifier == arrayElement
|| (isOut && (modifier == none))
) {
indexInArray = (modifier == arrayElement) ? ind : 0;
env->SetObjectArrayElement((jobjectArray)*value, indexInArray, data);
}
break;
}
case bc_T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
bcXPType type = XPTType2bcXPType(datumType.TagPart());
if (isOut) {
UnMarshalElement(value,ind,NULL,isOut,param,type,allocator,array);
}
if (um != NULL) {
PRUint32 arraySize;
um->ReadSimple(&arraySize,bc_T_U32);
jobject arrayValue = NULL;
UnMarshalElement(&arrayValue,arraySize,NULL,0,param,type,allocator,array);
if (isOut) {
env->SetObjectArrayElement((jobjectArray)*value,0,arrayValue);
} else {
*value = arrayValue;
}
for (PRUint32 i = 0; i < arraySize; i++) {
UnMarshalElement(&arrayValue,i,um,0,param,type,allocator,arrayElement);
}
}
break;
}
default:
;
}
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return NS_ERROR_FAILURE;
}
return NS_OK;
}
bcXPType bcJavaMarshalToolkit::XPTType2bcXPType(uint8 type) {
switch(type) {
case nsXPTType::T_I8 :
return bc_T_I8;
case nsXPTType::T_U8 :
return bc_T_U8;
case nsXPTType::T_I16 :
return bc_T_I16;
case nsXPTType::T_U16 :
return bc_T_U16;
case nsXPTType::T_I32 :
return bc_T_I32;
case nsXPTType::T_U32 :
return bc_T_U32;
case nsXPTType::T_I64 :
return bc_T_I64;
case nsXPTType::T_U64 :
return bc_T_U64;
case nsXPTType::T_FLOAT :
return bc_T_FLOAT;
case nsXPTType::T_DOUBLE :
return bc_T_DOUBLE;
case nsXPTType::T_BOOL :
return bc_T_BOOL;
case nsXPTType::T_CHAR :
return bc_T_CHAR;
case nsXPTType::T_WCHAR :
return bc_T_WCHAR;
case nsXPTType::T_IID :
return bc_T_IID;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_PSTRING_SIZE_IS:
return bc_T_CHAR_STR;
case nsXPTType::T_WCHAR_STR :
case nsXPTType::T_PWSTRING_SIZE_IS:
return bc_T_WCHAR_STR;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
return bc_T_INTERFACE;
case nsXPTType::T_ARRAY:
return bc_T_ARRAY;
default:
return bc_T_UNDEFINED;
case nsXPTType::T_I8 :
return bc_T_I8;
case nsXPTType::T_U8 :
return bc_T_U8;
case nsXPTType::T_I16 :
return bc_T_I16;
case nsXPTType::T_U16 :
return bc_T_U16;
case nsXPTType::T_I32 :
return bc_T_I32;
case nsXPTType::T_U32 :
return bc_T_U32;
case nsXPTType::T_I64 :
return bc_T_I64;
case nsXPTType::T_U64 :
return bc_T_U64;
case nsXPTType::T_FLOAT :
return bc_T_FLOAT;
case nsXPTType::T_DOUBLE :
return bc_T_DOUBLE;
case nsXPTType::T_BOOL :
return bc_T_BOOL;
case nsXPTType::T_CHAR :
return bc_T_CHAR;
case nsXPTType::T_WCHAR :
return bc_T_WCHAR;
case nsXPTType::T_IID :
return bc_T_IID;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_PSTRING_SIZE_IS:
return bc_T_CHAR_STR;
case nsXPTType::T_WCHAR_STR :
case nsXPTType::T_PWSTRING_SIZE_IS:
return bc_T_WCHAR_STR;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
return bc_T_INTERFACE;
case nsXPTType::T_ARRAY:
return bc_T_ARRAY;
default:
return bc_T_UNDEFINED;
}
}
//if p == 0 and isOut than return one element array
jobject bcJavaMarshalToolkit::Native2Java(void *p, bcXPType type, int isOut) {
//nb we shoud care about endianes. should we?
printf("--[c++]bcJavaMarshalToolkit::Native2Java \n");
jobject res = NULL;
if (!p
&& !isOut) {
printf("--[c++]bcJavaMarshalToolkit::Native2Java !p && !isOut\n");
return res;
}
switch (type) {
case bc_T_I8:
case bc_T_U8:
if (isOut) {
res = env->NewByteArray(1);
if (p) {
env->SetByteArrayRegion((jbyteArray)res,0,1,(jbyte*)p);
}
} else {
res = env->NewObject(byteClass,byteInitMID,*(jbyte*)p);
}
break;
case bc_T_I16:
case bc_T_U16:
if (isOut) {
res = env->NewShortArray(1);
if (p) {
env->SetShortArrayRegion((jshortArray)res,0,1,(jshort*)p);
}
} else {
res = env->NewObject(shortClass,shortInitMID,*(jshort*)p);
}
break;
case bc_T_I32:
case bc_T_U32:
if (isOut) {
res = env->NewIntArray(1);
if (p) {
env->SetIntArrayRegion((jintArray)res,0,1,(jint*)p);
}
} else {
res = env->NewObject(integerClass,integerInitMID,*(jint*)p);
printf("--bcJavaMarshalToolkit::Native2Java we'v got i32\n");
}
break;
case bc_T_I64:
case bc_T_U64:
if (isOut) {
res = env->NewLongArray(1);
if (p) {
env->SetLongArrayRegion((jlongArray)res,0,1,(jlong*)p);
}
} else {
res = env->NewObject(longClass,longInitMID,*(jlong*)p);
}
break;
case bc_T_FLOAT:
if (isOut) {
res = env->NewFloatArray(1);
if (p) {
env->SetFloatArrayRegion((jfloatArray)res,0,1,(jfloat*)p);
}
} else {
res = env->NewObject(floatClass,floatInitMID,*(jfloat*)p);
}
break;
case bc_T_DOUBLE:
if (isOut) {
res = env->NewDoubleArray(1);
if (p) {
env->SetDoubleArrayRegion((jdoubleArray)res,0,1,(jdouble*)p);
}
} else {
res = env->NewObject(doubleClass,doubleInitMID,*(jdouble*)p);
}
break;
case bc_T_BOOL:
if (isOut) {
res = env->NewBooleanArray(1);
if (p) {
env->SetBooleanArrayRegion((jbooleanArray)res,0,1,(jboolean*)p);
}
} else {
res = env->NewObject(booleanClass,booleanInitMID,*(jboolean*)p);
}
break;
case bc_T_CHAR:
case bc_T_WCHAR:
if (isOut) {
res = env->NewCharArray(1);
if (p) {
env->SetCharArrayRegion((jcharArray)res,0,1,(jchar*)p);
}
} else {
res = env->NewObject(characterClass,characterInitMID,*(jchar*)p);
}
break;
case bc_T_CHAR_STR:
case bc_T_WCHAR_STR: //nb not sure about this
{
jstring str = NULL;
if (p) {
str = env->NewStringUTF((const char*)p);
}
if (isOut) {
res = env->NewObjectArray(1,stringClass,NULL);
if (str) {
env->SetObjectArrayElement((jobjectArray)res,0,str);
}
} else {
res = str;
}
break;
}
case bc_T_IID:
{
jobject iid = NULL;
if (p) {
iid = bcIIDJava::GetObject((nsIID*)p);
}
if (isOut) {
res = env->NewObjectArray(1,bcIIDJava::GetClass(),NULL);
env->SetObjectArrayElement((jobjectArray)res,0,iid);
} else {
res = iid;
}
break;
}
case bc_T_INTERFACE:
{
printf("--[c++]bcJavaMarshalToolkit::... we have an Interfaces \n");
jobject obj = NULL;
nsresult r;
nsIID *iid;
bcOID *oid;
jobject proxy;
if (p) {
oid = (bcOID*)((void**)p)[0];
iid = (bcIID*)((void**)p)[1];
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
return NULL;
}
javaStubsAndProxies->GetProxy(*oid, *iid, orb, &proxy);
}
if (isOut) { //nb to do
/*
res = env->NewObjectArray(1,bcIIDJava::GetClass(),NULL);
env->SetObjectArrayElement((jobjectArray)res,0,proxy);
*/
} else {
res = proxy;
}
break;
}
default:
;
}
return res;
}
void bcJavaMarshalToolkit::InitializeStatic() {
jclass clazz;
if (!(clazz = env->FindClass("java/lang/Object"))
|| !(objectClass = (jclass) env->NewGlobalRef(clazz))) {
return;
|| !(objectClass = (jclass) env->NewGlobalRef(clazz))
) {
return;
}
if (!(clazz = env->FindClass("java/lang/Boolean"))
|| !(booleanClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(booleanClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/Boolean;"))
|| !(booleanArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
return;
}
if (!(clazz = env->FindClass("java/lang/Character"))
|| !(characterClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(charClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/Character;"))
|| !(charArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
return;
}
if (!(clazz = env->FindClass("java/lang/Byte"))
|| !(byteClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(byteClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/Byte;"))
|| !(byteArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
return;
}
if (!(clazz = env->FindClass("java/lang/Short"))
|| !(shortClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(shortClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/Short;"))
|| !(shortArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
return;
}
if (!(clazz = env->FindClass("java/lang/Integer"))
|| !(integerClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(intClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/Integer;"))
|| !(intArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
return;
}
if (!(clazz = env->FindClass("java/lang/Long"))
|| !(longClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(longClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/Long;"))
) {
DeInitializeStatic();
return;
return;
}
if (!(clazz = env->FindClass("java/lang/Float"))
|| !(floatClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(floatClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/Float;"))
|| !(floatArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
return;
}
if (!(clazz = env->FindClass("java/lang/Double"))
|| !(doubleClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(doubleClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/Double;"))
|| !(doubleArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
return;
}
if (!(clazz = env->FindClass("java/lang/String"))
|| !(stringClass = (jclass) env->NewGlobalRef(clazz))) {
|| !(stringClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Ljava/lang/String;"))
|| !(stringArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
return;
}
if (!(clazz = env->FindClass("org/mozilla/xpcom/IID"))
|| !(iidClass = (jclass) env->NewGlobalRef(clazz))
|| !(clazz = env->FindClass("[Lorg/mozilla/xpcom/IID;"))
|| !(iidArrayClass = (jclass) env->NewGlobalRef(clazz))
) {
DeInitializeStatic();
return;
}
if (!(booleanInitMID = env->GetMethodID(booleanClass,"<init>","(Z)V"))) {
DeInitializeStatic();
return;
@ -464,11 +711,11 @@ void bcJavaMarshalToolkit::InitializeStatic() {
return;
}
if (!(characterInitMID = env->GetMethodID(characterClass,"<init>","(C)V"))) {
if (!(charInitMID = env->GetMethodID(charClass,"<init>","(C)V"))) {
DeInitializeStatic();
return;
}
if (!(characterValueMID = env->GetMethodID(characterClass,"charValue","()C"))) {
if (!(charValueMID = env->GetMethodID(charClass,"charValue","()C"))) {
DeInitializeStatic();
return;
}
@ -490,11 +737,11 @@ void bcJavaMarshalToolkit::InitializeStatic() {
return;
}
if (!(integerInitMID = env->GetMethodID(integerClass,"<init>","(I)V"))) {
if (!(intInitMID = env->GetMethodID(intClass,"<init>","(I)V"))) {
DeInitializeStatic();
return;
}
if (!(integerValueMID = env->GetMethodID(integerClass,"intValue","()I"))) {
if (!(intValueMID = env->GetMethodID(intClass,"intValue","()I"))) {
DeInitializeStatic();
return;
}
@ -507,7 +754,7 @@ void bcJavaMarshalToolkit::InitializeStatic() {
DeInitializeStatic();
return;
}
if (!(floatInitMID = env->GetMethodID(floatClass,"<init>","(F)V"))) {
DeInitializeStatic();
return;
@ -526,11 +773,15 @@ void bcJavaMarshalToolkit::InitializeStatic() {
return;
}
if (!(getClassMID = env->GetMethodID(objectClass,"getClass","()Ljava/lang/Class;"))) {
DeInitializeStatic();
return;
}
}
void bcJavaMarshalToolkit::DeInitializeStatic() { //nb need to do
printf("--[c++]void bcJavaMarshalToolkit::DeInitializeStatic() - boomer \n");
}

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

@ -40,6 +40,9 @@ public:
nsresult Marshal(bcIMarshaler *);
nsresult UnMarshal(bcIUnMarshaler *);
private:
enum ArrayModifier { none, arrayElement, array};
enum { unDefined, onServer, onClient } callSide;
JNIEnv *env;
PRUint16 methodIndex;
@ -49,38 +52,64 @@ private:
jobjectArray args;
static jclass objectClass;
static jclass objectArrayClass;
static jclass booleanClass;
static jclass booleanArrayClass;
static jmethodID booleanInitMID;
static jmethodID booleanValueMID;
static jclass characterClass;
static jmethodID characterInitMID;
static jmethodID characterValueMID;
static jclass charClass;
static jclass charArrayClass;
static jmethodID charInitMID;
static jmethodID charValueMID;
static jclass byteClass;
static jclass byteArrayClass;
static jmethodID byteInitMID;
static jmethodID byteValueMID;
static jclass shortClass;
static jclass shortArrayClass;
static jmethodID shortInitMID;
static jmethodID shortValueMID;
static jclass integerClass;
static jmethodID integerInitMID;
static jmethodID integerValueMID;
static jclass intClass;
static jclass intArrayClass;
static jmethodID intInitMID;
static jmethodID intValueMID;
static jclass longClass;
static jclass longArrayClass;
static jmethodID longInitMID;
static jmethodID longValueMID;
static jclass floatClass;
static jclass floatArrayClass;
static jmethodID floatInitMID;
static jmethodID floatValueMID;
static jclass doubleClass;
static jclass doubleArrayClass;
static jmethodID doubleInitMID;
static jmethodID doubleValueMID;
static jclass stringClass;
static jclass stringArrayClass;
static jclass iidClass;
static jclass iidArrayClass;
static jmethodID getClassMID;
void InitializeStatic();
void DeInitializeStatic();
bcXPType XPTType2bcXPType(uint8 type);
jobject Native2Java(void *,bcXPType type,int isOut = 0);
// nsresult MarshalElement(bcIMarshaler *m, jobject array, nsXPTParamInfo * param, bcXPType type,
// uint8 ind, ArrayModifier modifier = none);
nsresult
MarshalElement(bcIMarshaler *m, jobject value, PRBool isOut, nsXPTParamInfo * param,
bcXPType type, uint8 ind, ArrayModifier modifier = none);
nsresult
UnMarshalElement(jobject *value, uint8 ind, bcIUnMarshaler *um, PRBool isOut , nsXPTParamInfo * param,
bcXPType type, bcIAllocator *allocator, ArrayModifier modifier = none);
};
#endif

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

@ -57,7 +57,7 @@ void bcJavaStub::Dispatch(bcICall *call) {
call->GetParams(&iid, &oid, &mid);
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if(iimgr = XPTI_GetInterfaceInfoManager()) {
if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
return; //nb exception handling
}
@ -81,8 +81,10 @@ void bcJavaStub::Dispatch(bcICall *call) {
jobject jiid = bcIIDJava::GetObject(&iid);
bcJavaGlobal::GetJNIEnv()->CallStaticObjectMethod(utilitiesClass, callMethodByIndexMID, object, jiid, (jint)mid, args);
//nb return value; excepion handling
bcIMarshaler * m = call->GetMarshaler(); //nb ** to do
bcIMarshaler * m = call->GetMarshaler();
mt->Marshal(m);
//nb memory deallocation
delete m; delete um; delete mt;
return;
}

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

@ -32,6 +32,7 @@ jmethodID bcJavaStubsAndProxies::loadComponentID = 0;
jclass bcJavaStubsAndProxies::proxyFactory = 0;
jmethodID bcJavaStubsAndProxies::getProxyID = 0;
jmethodID bcJavaStubsAndProxies::getInterfaceID = 0;
NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaStubsAndProxies);
@ -60,7 +61,7 @@ bcJavaStubsAndProxies::~bcJavaStubsAndProxies() {
NS_IMETHODIMP bcJavaStubsAndProxies::GetStub(jobject obj, bcIStub **stub) {
if (!stub) {
return NS_ERROR_NULL_POINTER;
return NS_ERROR_NULL_POINTER;
}
*stub = new bcJavaStub(obj);
return NS_OK;
@ -69,7 +70,7 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetStub(jobject obj, bcIStub **stub) {
NS_IMETHODIMP bcJavaStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, jobject *proxy) {
printf("--[c++] bcJavaStubsAndProxies::GetProxy\n");
if (!componentLoader) {
Init();
Init();
}
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
@ -78,6 +79,23 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIOR
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetInterface(const nsIID &iid, jclass *clazz) {
printf("--[c++] bcJavaStubsAndProxies::GetInterface\n");
if (!componentLoader) {
Init();
}
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
*clazz = (jclass)env->CallStaticObjectMethod(proxyFactory,getInterfaceID, jiid);
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID *oid) {
bcIStub *stub = new bcJavaStub(object);
*oid = orb->RegisterStub(stub);
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
printf("--bcJavaStubsAndProxies::GetOID %s\n",location);
@ -85,7 +103,7 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
nsresult result;
if (!componentLoader) {
Init();
Init();
}
//location[strlen(location)-5] = 0; //nb dirty hack. location is xyz.jar.info
strcpy(location + strlen(location)-4,"comp");
@ -94,8 +112,8 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
bcIStub *stub = new bcJavaStub(object);
NS_WITH_SERVICE(bcORB,_orb,kORBCIID,&result);
if (NS_FAILED(result)) {
printf("--bcJavaStubsAndProxies::GetOID failed\n");
return result;
printf("--bcJavaStubsAndProxies::GetOID failed\n");
return result;
}
bcIORB *orb;
_orb->GetORB(&orb);
@ -108,40 +126,47 @@ void bcJavaStubsAndProxies::Init(void) {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
componentLoader = env->FindClass("org/mozilla/xpcom/ComponentLoader");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
env->ExceptionDescribe();
componentLoader = 0;
return;
}
componentLoader = (jclass)env->NewGlobalRef(componentLoader);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
env->ExceptionDescribe();
componentLoader = 0;
return;
}
loadComponentID = env->GetStaticMethodID(componentLoader,"loadComponent","(Ljava/lang/String;)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
env->ExceptionDescribe();
componentLoader = 0;
return;
}
proxyFactory = env->FindClass("org/mozilla/xpcom/ProxyFactory");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
env->ExceptionDescribe();
componentLoader = 0;
return;
}
proxyFactory = (jclass)env->NewGlobalRef(proxyFactory);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
env->ExceptionDescribe();
componentLoader = 0;
return;
}
getProxyID = env->GetStaticMethodID(proxyFactory, "getProxy","(JLorg/mozilla/xpcom/IID;J)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
env->ExceptionDescribe();
componentLoader = 0;
return;
}
getInterfaceID = env->GetStaticMethodID(proxyFactory, "getInterface","(Lorg/mozilla/xpcom/IID;)Ljava/lang/Class;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
}

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

@ -45,7 +45,9 @@ class bcJavaStubsAndProxies : public nsISupports {
NS_DEFINE_STATIC_IID_ACCESSOR(BC_JAVASTUBSANDPROXIES_IID)
NS_IMETHOD GetStub(jobject obj, bcIStub **stub);
NS_IMETHOD GetOID(char *location, bcOID *); //load component by location
NS_IMETHOD GetOID(jobject object, bcIORB *orb, bcOID *oid);
NS_IMETHOD GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, jobject *proxy);
NS_IMETHOD GetInterface(const nsIID &iid, jclass *clazz);
bcJavaStubsAndProxies();
virtual ~bcJavaStubsAndProxies();
protected:
@ -54,6 +56,7 @@ class bcJavaStubsAndProxies : public nsISupports {
static jmethodID loadComponentID;
static jclass proxyFactory;
static jmethodID getProxyID;
static jmethodID getInterfaceID;
};
#endif /* __bcJavaStubsAndProxies_h */

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

@ -24,7 +24,10 @@
#include "bcIORB.h"
#include "bcICall.h"
#include "bcDefs.h"
#include "xptcall.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "bcJavaMarshalToolkit.h"
/*
* Class: org_mozilla_xpcom_Utilities
@ -33,17 +36,36 @@
*/
JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_Utilities_callMethodByIndex
(JNIEnv *env, jclass clazz, jlong _oid, jint mid, jstring jiid, jlong _orb, jobjectArray) {
(JNIEnv *env, jclass clazz, jlong _oid, jint mid, jstring jiid, jlong _orb, jobjectArray args) {
bcIORB * orb = (bcIORB*) _orb;
bcOID oid = (bcOID)_oid;
nsIID iid;
printf("--[c++] jni %d\n",(int)mid);
printf("--[c++] jni Java_org_mozilla_xpcom_Utilities_callMethodByIndex %d\n",(int)mid);
const char * str = NULL;
str = env->GetStringUTFChars(jiid,NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jiid,str);
bcICall *call = orb->CreateCall(&iid, &oid, mid);
/*****/
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if( (iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
return NULL; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
return NULL;
}
/*****/
bcIMarshaler * m = call->GetMarshaler();
bcJavaMarshalToolkit * mt = new bcJavaMarshalToolkit(mid, interfaceInfo, args, env, 0, orb);
mt->Marshal(m);
orb->SendReceive(call);
bcIUnMarshaler * um = call->GetUnMarshaler();
mt->UnMarshal(um);
delete m; delete um; delete mt;
return NULL;
}

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

@ -6,4 +6,7 @@ interface bcIJavaSample : nsISupports
void test0();
void test1(in long l);
void test2(in bcIJavaSample o);
void test3(in PRUint32 count,[array, size_is(count)] in long valueArray);
void test4(in PRUint32 count,[array, size_is(count)] inout string valueArray);
};

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

@ -4,11 +4,16 @@
* IID: 0xca1e2656-1dd1-11b2-9c4e-f49ea557abde
*/
import org.mozilla.xpcom.*;
public interface bcIJavaSample
{
public static final String BC_IJAVASAMPLE_IID_STRING =
"ca1e2656-1dd1-11b2-9c4e-f49ea557abde";
void queryInterface(IID iid, Object[] result);
void test0();
void test1(int l);
void test2(bcIJavaSample o);
void test3(int count, int[] valueArray);
void test4(int count, String[][] valueArray);
}

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

@ -60,17 +60,42 @@ NS_IMETHODIMP bcJavaSample::Test0()
/* void test1 (in long l); */
NS_IMETHODIMP bcJavaSample::Test1(PRInt32 l)
{
printf("--[c++] bcJavaSample.test1\n");
printf("--[c++] bcJavaSample.test1 l=%d\n",l);
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void test2 (in bcIJavaSample o); */
NS_IMETHODIMP bcJavaSample::Test2(bcIJavaSample *o)
{ printf("--[c++] bcJavaSample.test2\n");
return NS_ERROR_NOT_IMPLEMENTED;
{
printf("--[c++] bcJavaSample.test2\n");
o->Test0();
return NS_OK;
}
/* void test3 (in PRUint32 count, [array, size_is (count)] in long valueArray); */
NS_IMETHODIMP bcJavaSample::Test3(PRUint32 count, PRInt32 *valueArray) {
printf("--[c++] bcJavaSample.test3 coutn %d\n",count);
for(unsigned int i = 0; i < count; i++) {
printf("--[c++] valueArray[%d]=%d\n",i,valueArray[i]);
}
return NS_OK;
}
/* void test4 (in PRUint32 count, [array, size_is (count)] inout string valueArray); */
NS_IMETHODIMP bcJavaSample::Test4(PRUint32 count, char ***valueArray) {
printf("--[c++] bcJavaSample.test4 coutn %d\n",count);
for(unsigned int i = 0; i < count; i++) {
printf("--[c++] valueArray[%d]=%s\n",i,(*valueArray)[i]);
}
char ** array = (char **)malloc(sizeof(char*)*4);
array[0] = "1";
array[1] = "2";
array[2] = "hello";
array[3] = "world";
*valueArray = array;
return NS_OK;
}
void test() {
printf("--BlackConnect test start\n");
nsresult r;
@ -82,12 +107,30 @@ void test() {
(void**)&test);
//sigsend(P_PID, getpid(),SIGINT);
//test->Test1(2000);
//test->Test1(1000);
#if 0
test->Test1(1000);
bcIJavaSample *test1;
if (NS_FAILED(r)) {
printf("failed to get component. try to restart test\n");
printf("failed to get component. try to restart test\n");
} else {
test->Test2(a);
}
test->QueryInterface(NS_GET_IID(bcIJavaSample),(void**)&test1);
int intArray[] = {1,2,3};
test->Test3(3, intArray);
#endif
{
char ** valueArray = (char **)malloc(sizeof(char*)*4);
valueArray[0] = "hi";
valueArray[1] = "there";
valueArray[2] = "a";
valueArray[3] = "b";
char *** valueArray2 = &valueArray;
test->Test4(4,valueArray2);
for (int i = 0; i < 4; i++) {
printf("valueArray2[%d]=%s\n",i,(*valueArray2)[i]);
}
}
printf("--BlackConnect test end\n");
}

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

@ -25,47 +25,78 @@ public class bcJavaSample implements bcIJavaSample {
public bcJavaSample() {
System.out.println("--[java]bcJavaSample constructor");
}
public void queryInterface(IID iid, Object[] result) {
System.out.println("--[java]bcJavaSample::queryInterface iid="+iid);
if ( iid.equals(nsISupportsIID)
|| iid.equals(bcIJavaSampleIID)) {
result[0] = this;
} else {
result = null;
}
}
public void test0() {
System.out.println("--[java]bcJavaSample.test0 ");
System.out.println("--[java]bcJavaSample.test0 ");
}
public void test1(int l) {
try {
System.out.println("--[java]bcJavaSample.test1 "+l);
System.out.println("--[java]bcJavaSample.test1\n :)))) Hey Hong"+l);
Object obj = ProxyFactory.getProxy(0,iid,0);
if (obj instanceof bcIJavaSample) {
bcIJavaSample proxy = (bcIJavaSample)obj;
proxy.test2(null);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("--[java]bcJavaSample.test1 "+l+"\n");
}
public void test2(bcIJavaSample o) {
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();
o.test0();
o.test1(1000);
o.test2(this);
int[] array={3,2,1};
o.test3(3,array);
} else {
System.out.println("--[java]bcJavaSample.test2 o== null");
System.out.println("--[java]bcJavaSample.test2 o = null");
}
}
static IID iid;
public void test3(int count, int[] valueArray) {
System.out.println("--[java]bcJavaSample.test3");
System.out.println(valueArray.length);
for (int i = 0; i < valueArray.length; i++) {
System.out.println("--[java]callMethodByIndex args["+i+"] = "+valueArray[i]);
}
}
public void test4(int count, String[][] valueArray) {
System.out.println("--[java]bcJavaSample.test4");
String[] array = valueArray[0];
for (int i = 0; i < array.length; i++) {
System.out.println("--[java]callMethodByIndex args["+i+"] = "+array[i]);
}
String[] returnArray = {"4","3","2","1"};
valueArray[0] = returnArray;
}
static IID bcIJavaSampleIID;
static IID nsISupportsIID;
static {
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);
Class IIDClass = Class.forName("org.mozilla.xpcom.IID");
methods = new Method[100];
Class ObjectArrayClass = (new Object[1]).getClass();
Class IntArrayClass = (new int[1]).getClass();
Class StringArrayArrayClass = (new String[1][1]).getClass();
methods[0] = bcIJavaSampleClass.getDeclaredMethod("queryInterface",new Class[]{IIDClass,ObjectArrayClass});
methods[3] = bcIJavaSampleClass.getDeclaredMethod("test0",new Class[]{});
methods[4] = bcIJavaSampleClass.getDeclaredMethod("test1",new Class[]{Integer.TYPE});
methods[5] = bcIJavaSampleClass.getDeclaredMethod("test2",new Class[]{bcIJavaSampleClass});
methods[6] = bcIJavaSampleClass.getDeclaredMethod("test3",new Class[]{Integer.TYPE,IntArrayClass});
methods[7] = bcIJavaSampleClass.getDeclaredMethod("test4",new Class[]{Integer.TYPE,StringArrayArrayClass});
System.out.println(methods[0]+" "+methods[3]+" "+methods[4]+" "+methods[5]+" "+methods[6]+" "+methods[7]);
bcIJavaSampleIID = new IID(bcIJavaSample.BC_IJAVASAMPLE_IID_STRING);
nsISupportsIID = new IID("00000000-0000-0000-c000-000000000046");
ProxyFactory.registerInterfaceForIID(bcIJavaSampleClass,bcIJavaSampleIID);
new ProxyClass(bcIJavaSampleIID, methods);
//new ProxyClass(nsISupportsIID, methods);
} catch (Exception e) {
System.out.println(e);
}
}
};

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

@ -40,19 +40,19 @@ bcXPCOMMarshalToolkit::bcXPCOMMarshalToolkit(PRUint16 _methodIndex, nsIInterface
params = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
if (params == nsnull) {
return;
}
for (unsigned int i = 0; i < paramCount; i++) {
}
for (unsigned int i = 0; i < paramCount; i++) {
(params)[i].Init(_params[i], info->GetParam(i).GetType());
if (info->GetParam(i).IsOut()) {
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
params[i].ptr = params[i].val.p = _params[i].val.p;
}
if (info->GetParam(i).IsOut()) {
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
params[i].ptr = params[i].val.p = _params[i].val.p;
}
}
}
}
bcXPCOMMarshalToolkit::bcXPCOMMarshalToolkit(PRUint16 _methodIndex, nsIInterfaceInfo *_interfaceInfo,
nsXPTCVariant* _params) {
nsXPTCVariant* _params) {
callSide = onServer;
methodIndex = _methodIndex;
interfaceInfo = _interfaceInfo;
@ -64,136 +64,45 @@ bcXPCOMMarshalToolkit::~bcXPCOMMarshalToolkit() {
//nb
}
class xpAllocator : public bcIAllocator { //nb make is smarter. It should deallocate allocated memory.
public:
xpAllocator(nsIAllocator *_allocator) {
allocator = _allocator;
}
virtual ~xpAllocator() {}
virtual void * Alloc(size_t size) {
return allocator->Alloc(size);
}
virtual void Free(void *ptr) {
allocator->Free(ptr);
}
virtual void * Realloc(void* ptr, size_t size) {
return allocator->Realloc(ptr,size);
}
private:
nsCOMPtr<nsIAllocator> allocator;
};
nsresult bcXPCOMMarshalToolkit::Marshal(bcIMarshaler *m) {
//printf("--bcXPCOMMarshalToolkit::Marshal\n");
nsresult r = NS_OK;
PRUint32 paramCount = info->GetParamCount();
for (unsigned int i = 0; i < paramCount; i++) {
for (unsigned int i = 0; (i < paramCount) && NS_SUCCEEDED(r); i++) {
nsXPTParamInfo param = info->GetParam(i);
nsXPTType type = param.GetType();
PRBool isOut = param.IsOut();
if ((callSide == onClient && !param.IsIn())
|| (callSide == onServer && !param.IsOut())) {
continue;
}
nsXPTCVariant *value = & params[i];
void *data = (isOut)? value->val.p : value;
nsresult r;
switch(type.TagPart()) {
case nsXPTType::T_IID :
data = *(char**)data;
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
m->WriteSimple(data, XPTType2bcXPType(type.TagPart()));
break;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
data = *(char **)data;
m->WriteString(data,strlen((char*)data)+1);
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
{
nsIID *iid;
if (type.TagPart() == nsXPTType::T_INTERFACE) {
if(NS_FAILED(r = interfaceInfo->
GetIIDForParam(methodIndex, &param, &iid))) {
return r;
}
} else {
uint8 argnum;
if (NS_FAILED(r = interfaceInfo->GetInterfaceIsArgNumberForParam(methodIndex,
&param, &argnum))) {
return r;
}
const nsXPTParamInfo& arg_param = info->GetParam(argnum);
const nsXPTType& arg_type = arg_param.GetType();
if(arg_type.IsPointer() &&
arg_type.TagPart() == nsXPTType::T_IID) {
if(arg_param.IsOut())
iid =*((nsID**)params[argnum].val.p);
else
iid = (nsID*)params[argnum].val.p;
}
}
printf("--[c++]XPCOMMarshallToolkit INTERFACE iid=%s\n",iid->ToString());
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
return r; //nb am I sure about that?
}
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
return r;
}
bcIORB *orb;
_orb->GetORB(&orb);
bcIStub *stub = NULL;
xpcomStubsAndProxies->GetStub(*(nsISupports**)data, &stub);
bcOID oid = orb->RegisterStub(stub);
m->WriteSimple(&oid, XPTType2bcXPType(type.TagPart()));
m->WriteSimple(iid,bc_T_IID);
break;
}
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
break;
case nsXPTType::T_ARRAY:
{
PRUint32 arraySize;
if(!GetArraySizeFromParam(interfaceInfo,info,param,methodIndex,i,params,GET_LENGTH, &arraySize)) {
return NS_ERROR_FAILURE;
}
if (type.TagPart() == nsXPTType::T_ARRAY) {
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, &param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
//nb array need to do
} else {
m->WriteString(data, arraySize);
}
break;
}
default:
return NS_ERROR_FAILURE;
}
void *data;
data = (isOut) ? value->val.p : value;
r = MarshalElement(m,data,&param,param.GetType().TagPart(),i);
}
return NS_ERROR_FAILURE;
return r;
}
class xpAllocator : public bcIAllocator {
public:
xpAllocator(nsIAllocator *_allocator) {
allocator = _allocator;
}
virtual ~xpAllocator() {}
virtual void * Alloc(size_t size) {
return allocator->Alloc(size);
}
virtual void Free(void *ptr) {
allocator->Free(ptr);
}
virtual void * Realloc(void* ptr, size_t size) {
return allocator->Realloc(ptr,size);
}
private:
nsCOMPtr<nsIAllocator> allocator;
};
nsresult bcXPCOMMarshalToolkit::UnMarshal(bcIUnMarshaler *um) {
bcIAllocator * allocator = new xpAllocator(nsAllocator::GetGlobalAllocator());
PRUint32 paramCount = info->GetParamCount();
@ -204,79 +113,34 @@ nsresult bcXPCOMMarshalToolkit::UnMarshal(bcIUnMarshaler *um) {
nsXPTCMiniVariant * value;
value = &tmpValue;
nsXPTType type = param.GetType();
if (callSide == onServer
&& param.IsOut()) { //we need to allocate memory for out parametr
value->val.p = allocator->Alloc(sizeof(nsXPTCMiniVariant)); // sizeof(nsXPTCMiniVariant) is good
params[i].Init(*value,type);
params[i].ptr = params[i].val.p = value->val.p;
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
}
if (callSide == onServer
&& param.IsOut()) { //we need to allocate memory for out parametr
value->val.p = allocator->Alloc(sizeof(nsXPTCMiniVariant)); // sizeof(nsXPTCMiniVariant) is good
params[i].Init(*value,type);
params[i].ptr = params[i].val.p = value->val.p;
params[i].flags |= nsXPTCVariant::PTR_IS_DATA;
}
if ( (callSide == onServer && !param.IsIn()
|| (callSide == onClient && !param.IsOut()))){
continue;
}
void *data = (isOut)? value->val.p : value;
switch(type.TagPart()) {
case nsXPTType::T_IID :
data = *(char**)data;
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
um->ReadSimple(data,XPTType2bcXPType(type.TagPart()));
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
size_t size;
um->ReadString(data,&size,allocator);
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
//nb to do interface
break;
case nsXPTType::T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, &param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
//nb to do array
break;
}
default:
return NS_ERROR_FAILURE;
}
void *data = (isOut) ? value->val.p : value;
UnMarshalElement(data, um, &param, param.GetType().TagPart(),allocator);
params[i].Init(*value,type);
if (isOut) {
params[i].flags |= nsXPTCVariant::PTR_IS_DATA; //nb ?
params[i].ptr = params[i].val.p = value->val.p;
}
}
return NS_OK;
}
nsresult bcXPCOMMarshalToolkit::GetArraySizeFromParam( nsIInterfaceInfo *_interfaceInfo,
const nsXPTMethodInfo* method,
const nsXPTParamInfo& param,
uint16 _methodIndex,
uint8 paramIndex,
nsXPTCVariant* nativeParams,
SizeMode mode,
PRUint32* result) {
const nsXPTMethodInfo* method,
const nsXPTParamInfo& param,
uint16 _methodIndex,
uint8 paramIndex,
nsXPTCVariant* nativeParams,
SizeMode mode,
PRUint32* result) {
//code borrowed from mozilla/js/src/xpconnect/src/xpcwrappedjsclass.cpp
uint8 argnum;
nsresult rv;
@ -305,53 +169,277 @@ nsresult bcXPCOMMarshalToolkit::GetArraySizeFromParam( nsIInterfaceInfo *_interf
bcXPType bcXPCOMMarshalToolkit::XPTType2bcXPType(uint8 type) {
switch(type) {
case nsXPTType::T_I8 :
return bc_T_I8;
case nsXPTType::T_U8 :
return bc_T_U8;
case nsXPTType::T_I16 :
return bc_T_I16;
case nsXPTType::T_U16 :
return bc_T_U16;
case nsXPTType::T_I32 :
return bc_T_I32;
case nsXPTType::T_U32 :
return bc_T_U32;
case nsXPTType::T_I64 :
return bc_T_I64;
case nsXPTType::T_U64 :
return bc_T_U64;
case nsXPTType::T_FLOAT :
return bc_T_FLOAT;
case nsXPTType::T_DOUBLE :
return bc_T_DOUBLE;
case nsXPTType::T_BOOL :
return bc_T_BOOL;
case nsXPTType::T_CHAR :
return bc_T_CHAR;
case nsXPTType::T_WCHAR :
return bc_T_WCHAR;
case nsXPTType::T_IID :
return bc_T_IID;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_PSTRING_SIZE_IS:
return bc_T_CHAR_STR;
case nsXPTType::T_WCHAR_STR :
case nsXPTType::T_PWSTRING_SIZE_IS:
return bc_T_WCHAR_STR;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
return bc_T_INTERFACE;
case nsXPTType::T_ARRAY:
return bc_T_ARRAY;
case nsXPTType::T_I8 :
return bc_T_I8;
case nsXPTType::T_U8 :
return bc_T_U8;
case nsXPTType::T_I16 :
return bc_T_I16;
case nsXPTType::T_U16 :
return bc_T_U16;
case nsXPTType::T_I32 :
return bc_T_I32;
case nsXPTType::T_U32 :
return bc_T_U32;
case nsXPTType::T_I64 :
return bc_T_I64;
case nsXPTType::T_U64 :
return bc_T_U64;
case nsXPTType::T_FLOAT :
return bc_T_FLOAT;
case nsXPTType::T_DOUBLE :
return bc_T_DOUBLE;
case nsXPTType::T_BOOL :
return bc_T_BOOL;
case nsXPTType::T_CHAR :
return bc_T_CHAR;
case nsXPTType::T_WCHAR :
return bc_T_WCHAR;
case nsXPTType::T_IID :
return bc_T_IID;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_PSTRING_SIZE_IS:
return bc_T_CHAR_STR;
case nsXPTType::T_WCHAR_STR :
case nsXPTType::T_PWSTRING_SIZE_IS:
return bc_T_WCHAR_STR;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
return bc_T_INTERFACE;
case nsXPTType::T_ARRAY:
return bc_T_ARRAY;
default:
return bc_T_UNDEFINED;
}
}
nsresult bcXPCOMMarshalToolkit::MarshalElement(bcIMarshaler *m, void *data, nsXPTParamInfo * param,
uint8 type, uint8 ind) {
//printf("--bcXPCOMMarshalToolkit::MarshalElement ind=%d\n",ind);
nsresult r = NS_OK;
switch(type) {
case nsXPTType::T_IID :
data = *(char**)data;
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
m->WriteSimple(data, XPTType2bcXPType(type));
break;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
data = *(char **)data;
m->WriteString(data,strlen((char*)data)+1);
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
{
nsIID *iid;
if (type == nsXPTType::T_INTERFACE) {
if(NS_FAILED(r = interfaceInfo->
GetIIDForParam(methodIndex, param, &iid))) {
return r;
}
} else {
uint8 argnum;
if (NS_FAILED(r = interfaceInfo->GetInterfaceIsArgNumberForParam(methodIndex,
param, &argnum))) {
return r;
}
const nsXPTParamInfo& arg_param = info->GetParam(argnum);
const nsXPTType& arg_type = arg_param.GetType();
if(arg_type.IsPointer() &&
arg_type.TagPart() == nsXPTType::T_IID) {
if(arg_param.IsOut())
iid =*((nsID**)params[argnum].val.p);
else
iid = (nsID*)params[argnum].val.p;
}
}
//printf("--[c++]XPCOMMarshallToolkit INTERFACE iid=%s\n",iid->ToString());
bcOID oid = 0;
if (data != NULL) {
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
return r; //nb am I sure about that?
}
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
return r;
}
bcIORB *orb;
_orb->GetORB(&orb);
bcIStub *stub = NULL;
xpcomStubsAndProxies->GetStub(*(nsISupports**)data, &stub);
oid = orb->RegisterStub(stub);
}
m->WriteSimple(&oid, XPTType2bcXPType(type));
m->WriteSimple(iid,bc_T_IID);
break;
}
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_ARRAY:
//nb array of interfaces [to do]
{
PRUint32 arraySize;
if (!GetArraySizeFromParam(interfaceInfo,info, *param,methodIndex,
ind,params,GET_LENGTH, &arraySize)) {
return NS_ERROR_FAILURE;
}
if (type == nsXPTType::T_ARRAY) {
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
m->WriteSimple(&arraySize,bc_T_U32);
PRInt16 elemSize = GetSimpleSize(type);
char *current = *(char**)data;
for (unsigned int i = 0; i < arraySize; i++, current+=elemSize) {
MarshalElement(m,current,param,datumType.TagPart(),0);
}
} else {
m->WriteString(data, arraySize);
}
break;
}
default:
return NS_ERROR_FAILURE;
}
return r;
}
nsresult
bcXPCOMMarshalToolkit::UnMarshalElement(void *data, bcIUnMarshaler *um, nsXPTParamInfo * param, uint8 type, bcIAllocator * allocator) {
nsresult r = NS_OK;
switch(type) {
case nsXPTType::T_IID :
allocator->Free(*(char**)data);
*(char**)data = (char*)new nsIID(); //nb memory leak. how are we going to release it
data = *(char**)data;
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
um->ReadSimple(data,XPTType2bcXPType(type));
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
size_t size;
um->ReadString(data,&size,allocator);
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
{
printf("--[c++] we have an interface\n");
bcOID oid;
um->ReadSimple(&oid,XPTType2bcXPType(type));
printf("%d oid",(int) oid);
nsIID iid;
um->ReadSimple(&iid,bc_T_IID);
nsISupports *proxy;
if (oid != 0) {
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
return r; //nb am I sure about that?
}
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies,
kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
return r;
}
bcIORB *orb;
_orb->GetORB(&orb);
xpcomStubsAndProxies->GetProxy(oid, iid, orb,&proxy);
}
*(nsISupports**)data = proxy;
break;
}
case nsXPTType::T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
PRUint32 arraySize;
PRInt16 elemSize = GetSimpleSize(type);
um->ReadSimple(&arraySize,bc_T_U32);
char * current;
*(char**)data = current = (char *) allocator->Alloc(elemSize*arraySize);
//nb what about arraySize=0?
for (unsigned int i = 0; i < arraySize; i++, current+=elemSize) {
UnMarshalElement(current, um, param, datumType.TagPart(), allocator);
}
break;
}
default:
return NS_ERROR_FAILURE;
}
return r;
}
PRInt16 bcXPCOMMarshalToolkit::GetSimpleSize(uint8 type) {
PRInt16 size = -1;
switch(type) {
case nsXPTType::T_I8:
case nsXPTType::T_U8:
size = sizeof(PRInt8);
break;
case nsXPTType::T_I16:
case nsXPTType::T_U16:
size = sizeof(PRInt16);
break;
case nsXPTType::T_I32:
case nsXPTType::T_U32:
size = sizeof(PRInt32);
break;
case nsXPTType::T_I64:
case nsXPTType::T_U64:
size = sizeof(PRInt64);
break;
case nsXPTType::T_FLOAT:
size = sizeof(float);
break;
case nsXPTType::T_DOUBLE:
size = sizeof(double);
break;
case nsXPTType::T_BOOL:
size = sizeof(PRBool);
break;
case nsXPTType::T_CHAR:
size = sizeof(char);
break;
case nsXPTType::T_WCHAR:
size = sizeof(PRUnichar);
break;
default:
size = sizeof(void*);
}
return size;
}

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

@ -54,6 +54,10 @@ private:
SizeMode mode,
PRUint32* result);
bcXPType XPTType2bcXPType(uint8 type); //conversion from xpcom to our own types system
nsresult MarshalElement(bcIMarshaler *m, void *data, nsXPTParamInfo * param, uint8 type, uint8 ind);
nsresult UnMarshalElement(void *data, bcIUnMarshaler *um, nsXPTParamInfo * param, uint8 type,
bcIAllocator * allocator);
PRInt16 GetSimpleSize(uint8 type);
};
#endif /* __XPCOMMarshalToolkit_h */

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

@ -25,7 +25,8 @@
#include "bcXPCOMProxy.h"
#include "bcXPCOMMarshalToolkit.h"
NS_IMPL_ISUPPORTS(bcXPCOMProxy, NS_GET_IID(bcXPCOMProxy));
#include "signal.h"
//NS_IMPL_ISUPPORTS(bcXPCOMProxy, NS_GET_IID(bcXPCOMProxy));
bcXPCOMProxy::bcXPCOMProxy(bcOID _oid, const nsIID &_iid, bcIORB *_orb) {
@ -34,6 +35,7 @@ bcXPCOMProxy::bcXPCOMProxy(bcOID _oid, const nsIID &_iid, bcIORB *_orb) {
iid = _iid;
orb = _orb;
interfaceInfo = NULL;
printf("--[c++] bcXPCOMProxy::bcXPCOMProxy this: %p iid: %s\n",this, iid.ToString());
}
bcXPCOMProxy::~bcXPCOMProxy() {
@ -42,12 +44,13 @@ bcXPCOMProxy::~bcXPCOMProxy() {
NS_IMETHODIMP bcXPCOMProxy::GetInterfaceInfo(nsIInterfaceInfo** info) {
printf("--[c++] bcXPCOMProxy::GetInterfaceInfo iid=%s\n",iid.ToString());
if(!info) {
return NS_ERROR_FAILURE;
}
if (!interfaceInfo) {
nsIInterfaceInfoManager* iimgr;
if(iimgr = XPTI_GetInterfaceInfoManager()) {
if((iimgr = XPTI_GetInterfaceInfoManager())) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
printf("--bcXPCOMProxy::GetInterfaceInfo failed\n");
return NS_ERROR_FAILURE;
@ -65,20 +68,52 @@ NS_IMETHODIMP bcXPCOMProxy::GetInterfaceInfo(nsIInterfaceInfo** info) {
NS_IMETHODIMP bcXPCOMProxy::CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params) {
printf("--bcXPCOMProxy::CallMethod %d\n",methodIndex);
//sigsend(P_PID, getpid(),SIGINT);
printf("--bcXPCOMProxy::CallMethod %s [%d]\n",info->GetName(),methodIndex);
bcICall *call = orb->CreateCall(&iid, &oid, methodIndex);
bcIMarshaler *marshaler = call->GetMarshaler();
bcXPCOMMarshalToolkit * mt = new bcXPCOMMarshalToolkit(methodIndex, interfaceInfo, params);
mt->Marshal(marshaler);
orb->SendReceive(call);
bcIUnMarshaler * unmarshaler = call->GetUnMarshaler();
//nb *******
delete call; delete marshaler; delete unmarshaler;
mt->UnMarshal(unmarshaler);
delete call; delete marshaler; delete unmarshaler; delete mt;
return NS_OK;
}
nsrefcnt bcXPCOMProxy::AddRef(void) {
nsrefcnt cnt = (nsrefcnt) PR_AtomicIncrement((PRInt32*)&mRefCnt);
printf("--[c++] bcXPCOMProxy::AddRef %d\n",(unsigned)cnt);
return cnt;
}
nsrefcnt bcXPCOMProxy::Release(void) {
nsrefcnt cnt = (nsrefcnt) PR_AtomicDecrement((PRInt32*)&mRefCnt);
printf("--[c++] bcXPCOMProxy::AddRef %d\n",(unsigned)cnt);
if(0 == cnt) {
delete this;
}
return cnt;
}
NS_IMETHODIMP bcXPCOMProxy::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
PRUint16 methodIndex = 0;
const nsXPTMethodInfo *info;
nsIInterfaceInfo *inInfo;
GetInterfaceInfo(&inInfo); //nb add error handling
/* These do *not* make copies ***explicit bending of XPCOM rules***/
inInfo->GetMethodInfo(methodIndex,&info);
NS_RELEASE(inInfo);
nsXPTCMiniVariant params[2];
params[0].val.p = (void*)&aIID;
params[1].val.p = aInstancePtr;
nsresult r = CallMethod(methodIndex,info,params);
if (*aInstancePtr == NULL) {
printf("--bcXPCOMProxy.QueryInterface nointerface %s\n",aIID.ToString());
r = NS_NOINTERFACE;
}
printf("--bcXPCOMProxy.QueryInterface we got interface %s\n",aIID.ToString());
return r;
}

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

@ -41,7 +41,7 @@ void bcXPCOMStub::Dispatch(bcICall *call) {
call->GetParams(&iid, &oid, &mid);
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if(iimgr = XPTI_GetInterfaceInfoManager()) {
if( (iimgr = XPTI_GetInterfaceInfoManager()) ) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
return; //nb exception handling
}
@ -53,18 +53,21 @@ void bcXPCOMStub::Dispatch(bcICall *call) {
nsXPTMethodInfo* info;
interfaceInfo->GetMethodInfo(mid,(const nsXPTMethodInfo **)&info);
int paramCount = info->GetParamCount();
bcXPCOMMarshalToolkit * mt;
bcXPCOMMarshalToolkit * mt = NULL;
if (paramCount > 0) {
printf("--[c++]bcXPCOMStub paramCount %d\n",paramCount);
params = (nsXPTCVariant *) malloc(sizeof(nsXPTCVariant)*paramCount);
params = (nsXPTCVariant *) PR_Malloc(sizeof(nsXPTCVariant)*paramCount);
mt = new bcXPCOMMarshalToolkit(mid, interfaceInfo, params);
bcIUnMarshaler * um = call->GetUnMarshaler(); //nb ** to do
bcIUnMarshaler * um = call->GetUnMarshaler();
mt->UnMarshal(um);
}
//nb return value; excepion handling
XPTC_InvokeByIndex(object, mid, paramCount, params);
//bcIMarshaler * m = call->GetMarshaler(); //nb ** to do
//mt->Marshal(m);
if (mt != NULL) { //nb to do what about nsresult ?
bcIMarshaler * m = call->GetMarshaler();
mt->Marshal(m);
}
//nb memory deallocation
return;
}

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

@ -28,7 +28,7 @@
class bcXPCOMStub : public bcIStub {
public:
bcXPCOMStub(nsISupports *obj);
~bcXPCOMStub();
virtual ~bcXPCOMStub();
virtual void Dispatch(bcICall *call) ;
private:
nsISupports *object;

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

@ -58,12 +58,13 @@ NS_IMETHODIMP bcXPCOMStubsAndProxies::GetStub(nsISupports *obj, bcIStub **stub)
}
NS_IMETHODIMP bcXPCOMStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, nsISupports **proxy) {
printf("--bcXPCOMStubsAndProxies::GetProxy\n");
printf("--bcXPCOMStubsAndProxies::GetProxy iid=%s\n",iid.ToString());
if (!proxy) {
printf("--bcXPCOMStubsAndProxies::GetProxy failed\n");
return NS_ERROR_NULL_POINTER;
printf("--bcXPCOMStubsAndProxies::GetProxy failed\n");
return NS_ERROR_NULL_POINTER;
}
*proxy = new bcXPCOMProxy(oid,iid,orb);
NS_IF_ADDREF(*proxy);
return NS_OK;
}

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

@ -0,0 +1,52 @@
#!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 = ../../../../
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = bcTest
MODULE = bcTest
IS_COMPONENT = 1
XPIDLSRCS = bcITest.idl
CPPSRCS = \
bcTestImpl.cpp \
$(NULL)
EXTRA_DSO_LDOPTS += \
-L$(DIST)/bin/components/ \
-lbcorb -lbcxpcomstubs \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

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

@ -0,0 +1,279 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla 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/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.
*
* The Original Code is mozilla.org code.
*
* 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):
* Leila.Garin@eng.sun.com
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include <stdio.h>
#include "bcTestImpl.h"
static char * className = "bcTestImpl";
nsrefcnt bcTestImpl::AddRef(void) {
static const char * methodName="AddRef";
printf("--%s::%s this=%p",className, methodName,this);
nsrefcnt cnt = (nsrefcnt) PR_AtomicIncrement((PRInt32*)&mRefCnt);
return cnt;
}
nsrefcnt bcTestImpl::Release(void) {
static const char * methodName="Release";
nsrefcnt cnt = (nsrefcnt) PR_AtomicDecrement((PRInt32*)&mRefCnt);
printf("--%s::%s this=%p",className, methodName,this);
if(0 == cnt) {
delete this;
}
return cnt;
}
NS_IMETHODIMP bcTestImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
static const char * methodName="QueryInterface";
printf("--%s::%s aIID=%s this=%p",className, methodName,aIID.ToString(),this);
if ( !aInstancePtr ) {
return NS_ERROR_NULL_POINTER;
}
if ( aIID.Equals(NS_GET_IID(nsISupports))
|| aIID.Equals(NS_GET_IID(bcITest)))
{
*(nsISupports**)aInstancePtr = this;
return NS_OK;
} else {
return NS_NOINTERFACE;
}
}
/*void test1(inout long l);*/
NS_IMETHODIMP bcTestImpl::Test1(PRInt32 *l) {
static char * methodName="Test1";
printf("--%s::%s ",className, methodName);
printf("this=%p l=%d\n", this, *l);
*l = 1234;
printf("--%s::%s ",className, methodName);
printf("After l assignment. l=%d\n",*l);
return NS_OK;
}
/*void test2(in long l1,inout long l2);*/
NS_IMETHODIMP bcTestImpl::Test2(PRInt32 l1, PRInt32* l2) {
static char * methodName="Test2";
printf("this=%p l1=%d l2=%d\n", this, l1, *l2);
*l2 = l1;
printf("--%s::%s ",className, methodName);
printf("After assignment. l1=%d l2=%d\n",l1,*l2);
return NS_OK;
}
/*void test3(in string s1,inout string s2);*/
NS_IMETHODIMP bcTestImpl::Test3(const char *s1, char **s2) {
static char * methodName="Test3";
printf("--%s::%s ",className, methodName);
printf("this=%p s1=%s s2=%s\n",this, s1,*s2);
*s2 = "hi";
printf("--%s::%s ",className, methodName);
printf("After assignment. s2=%s\n",*s2);
return NS_OK;
}
/*void test4(in PRUint32 count,[array, size_is(count)] in string valueArray);*/
NS_IMETHODIMP bcTestImpl::Test4(PRUint32 count, const char **valueArray) {
static char * methodName="Test4";
printf("--%s::%s ",className, methodName);
printf("this=%p count=%d",this, count);
for (unsigned int i = 0; i < count; i++) {
printf("--%s::%s ",className, methodName);
printf("valueArray[%d]=%s\n",i,valueArray[i]);
}
return NS_OK;
}
/*void test5(in PRUint32 count,[array, size_is(count)] inout string valueArray);*/
NS_IMETHODIMP bcTestImpl::Test5(PRUint32 count, char ***valueArray) {
static char * methodName="Test5";
printf("--%s::%s ",className, methodName);
printf("this=%p count=%d\n",this, count);
// char ***value = valueArray;
//printf("value = %p *value = %p **value %p\n",value, *(char***)value,
// **(char***)value);
for (unsigned int i = 0; i < count; i++) {
printf("--%s::%s ",className, methodName);
printf("valueArray[%d]=%s\n",i,(*valueArray)[i]);
}
char ** array = (char **)malloc(sizeof(char*)*4);
array[0] = "1";
array[1] = "2";
array[2] = "hello";
array[3] = "world";
*valueArray = array;
//printf("value = %p *value = %p **value %p\n",value, *(char***)value,
// **(char***)value);
return NS_OK;
}
NS_IMETHODIMP bcTestImpl::Test6(class bcITest *o) {
static const char * methodName="Test6";
printf("--%s::%s ",className, methodName);
printf("this=%p o=%p\n",this, o);
PRInt32 l = 1234;
o->Test1(&l);
return NS_OK;
}
/* void test7 (out bcITest o); */
NS_IMETHODIMP bcTestImpl::Test7(bcITest **o) {
static const char * methodName="Test7";
printf("--%s::%s ",className, methodName);
printf("this=%p *o=%p\n",this,*o);
if (o == NULL) {
return NS_ERROR_NULL_POINTER;
}
*o = new bcTestImpl();
printf("--%s::%s ",className, methodName);
printf("o=%p\n",o);
return NS_OK;
}
/****************************************************/
#include "nsIModule.h"
#include "bcORB.h"
#include "nsIServiceManager.h"
#include "bcXPCOMStubsAndProxies.h"
#include "bcIStub.h"
static NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static void test(void) {
nsresult r;
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
printf("--bcTestImpl test failed\n");
return;
}
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcTestImpl test failed\n");
return;
}
bcIORB *orb;
_orb->GetORB(&orb);
bcIStub *stub = NULL;
bcITest *object = new bcTestImpl();
object->AddRef();
bcITest *proxy = NULL;
xpcomStubsAndProxies->GetStub((nsISupports*)object, &stub);
bcOID oid = orb->RegisterStub(stub);
printf("---bcTestImpl iid=%s\n",NS_GET_IID(bcITest).ToString());
r = xpcomStubsAndProxies->GetProxy(oid,NS_GET_IID(bcITest),orb,(nsISupports**)&proxy);
if (NS_FAILED(r)) {
printf("--bcTestImpl test failed\n");
return;
}
/*******************************************/
char ** valueArray = (char **)malloc(sizeof(char*)*4);
valueArray[0] = "hi";
valueArray[1] = "there";
valueArray[2] = "a";
valueArray[3] = "b";
PRInt32 l1 = 1999;
object->Test1(&l1);
l1 = 1999;
proxy->Test1(&l1);
printf("--bcTestImpl after Test1 l=%d\n",l1);
/*******************************************/
PRInt32 l2 = 2000;
l1 = 1999;
proxy->Test2(l1,&l2);
printf("--bcTestImpl after Test2 l2=%d\n",l2);
/*******************************************/
const char * s1 = "s1";
char * s2 = "s2";
proxy->Test3(s1,&s2);
printf("--bcTestImpl after Test3 s2=%s\n",s2);
/*******************************************/
proxy->Test4(4,(const char **)valueArray);
/*******************************************/
char ***valueArray2 = &valueArray;
printf("call object\n");
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
object->Test5(4,valueArray2);
printf("after calling object\n");
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
valueArray2 = (char ***)&valueArray;
proxy->Test5(4,valueArray2);
for (unsigned int i = 0; i < 4; i++) {
printf("valueArray[%d]=%s\n",i,(*valueArray2)[i]);
}
/*********************************************/
proxy->Test6(object);
/*********************************************/
{
bcITest *p1;
proxy->Test7(&p1);
printf("p1=%p",p1);
PRInt32 l = 1234;
p1->Test1(&l);
bcITest *p3;
printf("--before QueryInterface calling \n");
if (NS_SUCCEEDED(p1->QueryInterface(NS_GET_IID(bcITest),(void**)&p3))) {
l=2000;
p3->Test1(&l);
}
}
}
static int counter = 0; //we do not need to call it on unload time;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *compMgr,
nsIFile *location,
nsIModule** result) //I am using it for runnig test *only*
{
if (counter == 0) {
counter ++;
test();
}
return NS_ERROR_FAILURE;
}

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