Permalink
Browse files

Generate stub classes for inbound interfaces

  • Loading branch information...
1 parent d4ef38f commit 6433ba44c1d35efc387506f4ff5007ecc597141e @paddybyers committed Dec 2, 2011
@@ -6,8 +6,6 @@
import org.meshpoint.anode.idl.IDLInterface.Attribute;
import org.meshpoint.anode.idl.IDLInterface.Operation;
import org.meshpoint.anode.java.Base;
-import org.meshpoint.anode.js.JSInterface;
-import org.meshpoint.anode.js.JSObject;
import org.meshpoint.anode.type.IValue;
public class BridgeNative {
@@ -31,12 +29,12 @@
native static int length(long instHandle);
/* declaratively typed */
- native static IValue callAsInterface(long instHandle, int classIdx, int methodIdx, IValue[] args);
+ public native static Object invokeJSInterface(long instHandle, long interfaceHandle, int opIdx, Object[] args);
+ public native static Object getJSInterface(long instHandle, long interfaceHandle, int attrIdx);
+ public native static void setJSInterface(long instHandle, long interfaceHandle, int attrIdx, Object val);
/* instance handle management */
native static void releaseObjectHandle(long instHandle);
- public native static void wrapJSObject(long instHandle, JSObject obj);
- public native static void wrapJSInterface(long instHandle, JSInterface obj, IDLInterface iface);
public native static long wrapJavaInterface(Base obj, IDLInterface iface);
/* interface handle management */
@@ -133,7 +133,7 @@ private Env(long nodeIsolate, long v8Isolate) {
this.nodeIsolate = nodeIsolate;
this.v8Isolate = v8Isolate;
this.threadid = Thread.currentThread().getId();
- interfaceManager = new InterfaceManager();
+ interfaceManager = new InterfaceManager(null);
finalizeQueue = new FinalizeQueue(this);
wrapQueue = new WrapQueue(this);
pendingOps = new ArrayList<SynchronousOperation>();
@@ -53,11 +53,8 @@
* public API
********************/
- public IDLInterface(InterfaceManager mgr, Class<? extends Object> javaClass) {
- String ifaceName = javaClass.getCanonicalName();
- if(!ifaceName.startsWith(Types.INTERFACE_TYPE_PREFIX))
- throw new IllegalArgumentException("InterfaceImpl(): interface " + ifaceName + " is not in expected package");
- this.name = ifaceName.substring(Types.INTERFACE_TYPE_PREFIX.length());
+ public IDLInterface(InterfaceManager mgr, Class<?> javaClass) {
+ name = javaClass.getCanonicalName();
this.javaClass = javaClass;
id = mgr.put(this);
}
@@ -66,6 +63,10 @@ public int getId() {
return id;
}
+ public long getHandle() {
+ return inboundBinding;
+ }
+
public Class<? extends Object> getJavaClass() {
return javaClass;
}
@@ -20,8 +20,10 @@
/******************
* public API
******************/
- public InterfaceManager() {
- classLoader = this.getClass().getClassLoader(); /* we might support distinct loaders in future */
+ public InterfaceManager(ClassLoader classLoader) {
+ if(classLoader == null)
+ classLoader = this.getClass().getClassLoader();
+ this.classLoader = classLoader;
interfaces = new ArrayList<IDLInterface>();
nameMap = new HashMap<String, IDLInterface>();
classMap = new HashMap<Class<? extends Object>, IDLInterface>();
@@ -31,29 +33,26 @@ ClassLoader getClassLoader() {
return classLoader;
}
- public synchronized int put(IDLInterface iface) {
- int result = (int)iface.getId();
- if(result == -1) {
- result = interfaces.size();
- interfaces.add(iface);
- nameMap.put(iface.getName(), iface);
- classMap.put(iface.getJavaClass(), iface);
- }
- return result;
- }
-
public synchronized IDLInterface getById(int id) {
return interfaces.get(id);
}
public synchronized IDLInterface getByName(String name) {
- return nameMap.get(name);
+ IDLInterface result = nameMap.get(name);
+ if(result != null)
+ return result;
+
+ try {
+ Class<?> javaClass = classLoader.loadClass(name);
+ result = loadClass(javaClass);
+ } catch (ClassNotFoundException e) {}
+ return result;
}
/****************
* class loading
****************/
- public IDLInterface loadClass(Class<? extends Object> javaClass) {
+ public IDLInterface loadClass(Class<?> javaClass) {
IDLInterface result;
synchronized(this) {
result = classMap.get(javaClass);
@@ -63,14 +62,16 @@ public IDLInterface loadClass(Class<? extends Object> javaClass) {
return result;
}
- private IDLInterface defineClass(Class<? extends Object> javaClass) {
+ private IDLInterface defineClass(Class<?> javaClass) {
String canonicalName = javaClass.getCanonicalName().intern();
- if(canonicalName == "java.lang.Object" || canonicalName.startsWith(Types.INTERFACE_TYPE_PREFIX))
+ if(canonicalName == "java.lang.Object")
return null;
/* add to manager, and resolve parent */
IDLInterface result = new IDLInterface(this, javaClass);
- result.parent = loadClass(javaClass.getSuperclass());
+ Class<?> parentClass = javaClass.getSuperclass();
+ if(parentClass != null)
+ result.parent = loadClass(parentClass);
/* resolve fields */
ArrayList<Attribute> attributeList = new ArrayList<Attribute>();
@@ -124,6 +125,17 @@ private IDLInterface defineClass(Class<? extends Object> javaClass) {
/**********************
* private
**********************/
+ synchronized int put(IDLInterface iface) {
+ int result = (int)iface.getId();
+ if(result == -1) {
+ result = interfaces.size();
+ interfaces.add(iface);
+ nameMap.put(iface.getName(), iface);
+ classMap.put(iface.getJavaClass(), iface);
+ }
+ return result;
+ }
+
public void dispose() {
for(IDLInterface iface : interfaces) {
iface.dispose();
@@ -116,11 +116,10 @@ public static int fromJavaType(InterfaceManager interfaceManager, Type javaType)
return baseClassIndex;
/* handle interface types */
String canonicalName = javaClass.getCanonicalName();
- if(canonicalName.startsWith(INTERFACE_TYPE_PREFIX)) {
- IDLInterface iface = interfaceManager.loadClass(javaClass);
- if(iface != null)
- return classid2Type(iface.getId());
- }
+ IDLInterface iface = interfaceManager.getByName(canonicalName);
+ if(iface != null)
+ return classid2Type(iface.getId());
+
return TYPE_INVALID;
}
@@ -141,8 +140,6 @@ public static int getInterfaceType(InterfaceManager interfaceManager, IDLInterfa
public class Map {}
public class Function {}
- public class ValueType {}
- public static final String INTERFACE_TYPE_PREFIX = "org.meshpoint.node.iface.";
/******************
* private state
@@ -160,7 +157,18 @@ public static int getInterfaceType(InterfaceManager interfaceManager, IDLInterfa
String.class,
Map.class,
Function.class,
- ValueType.class,
- Date.class
+ Date.class,
+ null,
+ null,
+ null,
+ Object.class,
+ null,
+ null,
+ Boolean.class,
+ Byte.class,
+ Short.class,
+ Integer.class,
+ Long.class,
+ Double.class,
}));
}
@@ -12,31 +12,30 @@
* private state
*********************/
long instHandle; /* (long)Persistent<Object>* */
- Env env;
- IDLInterface idlInterface;
+ protected Env env = Env.getCurrent();
+ private IDLInterface iface;
+ private long interfaceHandle;
/*********************
* private API
*********************/
- JSInterface(long instHandle, IDLInterface idlInterface) {
+ protected JSInterface(long instHandle, IDLInterface iface) {
this.instHandle = instHandle;
- this.idlInterface = idlInterface;
- env = Env.getCurrent();
- BridgeNative.wrapJSInterface(instHandle, this, idlInterface);
+ this.iface = iface;
+ interfaceHandle = iface.getHandle();
}
/*********************
* public API
*********************/
-
@Override
public JSType getType() {
return JSType.OBJECT;
}
@Override
public IDLInterface getDeclaredType() {
- return idlInterface;
+ return iface;
}
public void finalize() {
@@ -46,6 +45,21 @@ public void finalize() {
@Override
public void release() {
// TODO Auto-generated method stub
-
}
+
+ /*********************
+ * bridge API
+ *********************/
+ protected Object __invoke(int opIdx, Object[] args) {
+ return BridgeNative.invokeJSInterface(instHandle, interfaceHandle, opIdx, args);
+ }
+
+ protected Object __get(int attrIdx) {
+ return BridgeNative.getJSInterface(instHandle, interfaceHandle, attrIdx);
+ }
+
+ protected void __set(int attrIdx, Object val) {
+ BridgeNative.setJSInterface(instHandle, interfaceHandle, attrIdx, val);
+ }
+
}
@@ -3,7 +3,6 @@
import java.util.Collection;
import org.meshpoint.anode.bridge.Env;
-import org.meshpoint.anode.bridge.BridgeNative;
import org.meshpoint.anode.idl.Types.JSType;
import org.meshpoint.anode.type.ICollection;
import org.meshpoint.anode.type.IFunction;
@@ -24,9 +24,9 @@
************************/
int type;
- long longValue;
- double dblValue;
- Object obValue;
+ public long longValue;
+ public double dblValue;
+ public Object obValue;
/************************
* public API
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/bridge-java"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>bridge-stub-generator</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Oops, something went wrong.

0 comments on commit 6433ba4

Please sign in to comment.