Skip to content
This repository has been archived by the owner on Sep 6, 2020. It is now read-only.

Commit

Permalink
properly marshal abstract objects and interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Oct 12, 2010
1 parent 4c178d3 commit c37f485
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions MonoActivity/assets/android.dll.mdb
1 change: 0 additions & 1 deletion MonoActivity/assets/jni4net.n-0.8.1.0.dll

This file was deleted.

1 change: 0 additions & 1 deletion MonoActivity/assets/jni4net.n-0.8.1.0.dll.mdb

This file was deleted.

6 changes: 6 additions & 0 deletions jni/MonoJavaBridge/JavaBridge/JavaBridge.cs
Expand Up @@ -95,6 +95,11 @@ private static Wrapper GetWrapper(string className)
return ret;
// see if we can register a wrapper
Type type = FindType(className);
if (type != null && type.IsAbstract)
{
Console.WriteLine("Wrapping abstract type: " + className);
type = FindType(className + "_");
}
if (type != null)
{
ret = new Wrapper();
Expand Down Expand Up @@ -218,6 +223,7 @@ public static JavaObject WrapJavaObject(JniLocalHandle handle)
clazz = GetSuperclass(env, clazz);
}
var ret = wrapper.Constructor.Invoke(new object[] { env }) as JavaObject;
Console.WriteLine(wrapper.Type.ToString());
ret.Init(env, handle);
return ret;
}
Expand Down
19 changes: 11 additions & 8 deletions jni/MonoJavaBridge/JavaBridge/Javabridge.link.cs
Expand Up @@ -82,11 +82,11 @@ static JavaBridge()

//myStrongJ2CpUntyped = null;//typeof(net.sf.jni4net.utils.Convertor).GetMethod("StrongJ2CpUntyped");
mWrapJavaObject = typeof(JavaBridge).GetMethod("WrapJavaObject", new Type[] { typeof(JniLocalHandle) });
mWrapJavaArrayObject = typeof(JavaBridge).GetMethod("WrapJavaArrayObject", new Type[] { typeof(JniHandle) });
mWrapIJavaObject = typeof(JavaBridge).GetMethod("WrapIJavaObject", new Type[] { typeof(JniHandle) });
mWrapJavaArrayObject = typeof(JavaBridge).GetMethod("WrapJavaArrayObject", new Type[] { typeof(JniLocalHandle) });
mWrapIJavaObject = typeof(JavaBridge).GetMethod("WrapIJavaObject", new Type[] { typeof(JniLocalHandle) });
myCLRHandleToObject = typeof(JavaBridge).GetMethod("CLRHandleToObject");
myExpressionLambda = typeof(JavaBridge).GetMethod("LambdaPassthrough");
Console.WriteLine(myExpressionLambda);
//Console.WriteLine(myExpressionLambda);

myActions.Add(typeof(JniAction));
myActions.Add(typeof(JniAction<int>).GetGenericTypeDefinition());
Expand Down Expand Up @@ -179,7 +179,10 @@ static Expression MarshalArgument(Type argumentType, ParameterExpression paramet
// marshal if necessary, ie intptr to object
if (argumentType == parameter.Type)
return parameter;
return Expression.Convert(Expression.Call(mWrapJavaObject, Expression.Convert(parameter, typeof(JniLocalHandle))), argumentType);
if (!argumentType.IsInterface)
return Expression.Convert(Expression.Call(mWrapJavaObject, Expression.Convert(parameter, typeof(JniLocalHandle))), argumentType);
var wrapObject = mWrapIJavaObject.MakeGenericMethod(argumentType);
return Expression.Convert(Expression.Call(wrapObject, Expression.Convert(parameter, typeof(JniLocalHandle))), argumentType);
}

static JniGlobalHandle myMonoProxyClass;
Expand Down Expand Up @@ -275,15 +278,15 @@ public static void Link(IntPtr classHandle, IntPtr methodNameHandle, IntPtr meth
var methodSig = env.ConvertToString(methodSignatureHandle);
var methodPars = methodParametersHandle == IntPtr.Zero ? null : env.ConvertToString(methodParametersHandle);
string classCanonicalName = GetClassCanonicalName(env, classHandle);
Console.WriteLine("Linking java class method: {0}.{1}", classCanonicalName, methodName);
//Console.WriteLine("Linking java class method: {0}.{1}", classCanonicalName, methodName);
Type type = FindType(classCanonicalName);
if (type == null)
{
Console.WriteLine("Could not find clr type.");
return;
}

Console.WriteLine("Found clr type: {0}", type);
//Console.WriteLine("Found clr type: {0}", type);

Type[] parameterTypes = null;
if (!string.IsNullOrEmpty(methodPars))
Expand All @@ -295,8 +298,8 @@ public static void Link(IntPtr classHandle, IntPtr methodNameHandle, IntPtr meth
parameterTypes[i] = FindType(parameterTypeStrings[i]);
if (parameterTypes[i] == null)
Console.WriteLine("Could not find {0}", parameterTypeStrings[i]);
else
Console.WriteLine("Found type {0}", parameterTypes[i]);
//else
// Console.WriteLine("Found type {0}", parameterTypes[i]);
}
}

Expand Down

0 comments on commit c37f485

Please sign in to comment.