public static JniLocalHandle ArrayStrongCp2J <TBoth>(JNIEnv env, TBoth obj) where TBoth : class //should be where TBoth : IJvmProxy[] { if (obj == null) { return(JniLocalHandle.Zero); } #if DEBUG if (!typeof(TBoth).IsArray) { throw new ArgumentException("Must be array type"); } #endif var array = (Array)(object)obj; int length = array.Length; Type elementType = typeof(TBoth).GetElementType(); Class elemClazz = Registry.GetCLRRecord(elementType).JVMInterface; JniLocalHandle res = env.NewObjectArrayPtr(length, elemClazz.jvmHandle, null); for (int i = 0; i < length; i++) { JniHandle item = StrongCp2J((IJvmProxy)array.GetValue(i)); env.SetObjectArrayElement(res, i, item); } return(res); }
internal void GetCharArrayRegion(JniHandle array, int start, int len, char[] buf) { fixed (char* ptr = &buf[0]) { getCharArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
public static String StrongJ2CpString(JNIEnv env, JniLocalHandle obj) { if (JniHandle.IsNull(obj)) { return(null); } return(String.CreateProxy(env, obj)); }
public static Class StrongJ2CpClass(JNIEnv env, JniLocalHandle obj) { if (JniHandle.IsNull(obj)) { return(null); } return(Class.CreateProxy(env, obj)); }
internal void GetByteArrayRegion(JniHandle array, int start, int len, byte[] buf) { fixed (byte* ptr = &buf[0]) { getByteArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
internal void GetBooleanArrayRegion(JniHandle array, int start, int len, bool[] buf) { fixed (bool* ptr = &buf[0]) { getBooleanArrayRegion(envPtr, array, start, len, (byte*) ptr); } ExceptionTest(); }
private static Type IsCLR(Class iface, JniHandle obj, JNIEnv env) { if (IClrProxy_._class.isAssignableFrom(iface)) { object real = __IClrProxy.GetObject(env, obj); return(real.GetType()); } return(null); }
public static string StrongJp2CString(JNIEnv env, JniLocalHandle obj) { if (JniHandle.IsNull(obj)) { return(null); } object res = __IClrProxy.GetObject(env, obj); return((string)res); }
public static string StrongJ2CString(JNIEnv env, JniLocalHandle obj) { if (JniHandle.IsNull(obj)) { return(null); } string res = env.ConvertToString(obj); return(res); }
internal static object GetObject(JNIEnv env, JniHandle obj) { long handle = getClrHandle(env, obj); if (handle==0) { return null; } object real = IntHandle.ToObject(handle); return real; }
public static TRes StrongJp2C <TRes>(JNIEnv env, JniLocalHandle obj) { if (JniHandle.IsNull(obj)) { return(default(TRes)); } object res = __IClrProxy.GetObject(env, obj); return((TRes)res); }
public static TRes StrongJ2Cp <TRes>(JNIEnv env, JniLocalHandle obj) where TRes : IJvmProxy { if (JniHandle.IsNull(obj)) { return(default(TRes)); } Class clazz = env.GetObjectClass(obj); RegistryRecord record = Registry.GetJVMRecord(clazz); return((TRes)record.CreateCLRProxy(env, obj)); }
public static RegistryRecord GetRecord(JNIEnv env, JniHandle obj, Class iface) { lock (typeof(Registry)) { RegistryRecord res; if (knownJVM.TryGetValue(iface, out res)) { return(res); } return(ResolveNew(iface)); } }
public static RegistryRecord GetRecord(JNIEnv env, JniHandle obj, Class iface) { lock (typeof (Registry)) { RegistryRecord res; if (knownJVM.TryGetValue(iface, out res)) { return res; } return ResolveNew(iface); } }
public static object StrongJ2CpUntyped(IntPtr ptr) { JNIEnv env = JNIEnv.ThreadEnv; JniLocalHandle obj = ptr; if (JniHandle.IsNull(obj)) { return(null); } Class clazz = env.GetObjectClass(obj); RegistryRecord record = Registry.GetJVMRecord(clazz); return(record.CreateCLRProxyNoDelete(env, obj)); }
public static TRes ArrayStrongJp2C <TRes, TElem>(JNIEnv env, JniLocalHandle array) where TRes : class //should be TRes : Array { if (JniHandle.IsNull(array)) { return(default(TRes)); } int length = env.GetArrayLength(array); var res = new TElem[length]; for (int i = 0; i < length; i++) { JniLocalHandle elementPtr = env.GetObjectArrayElementPtr(array, i); var element = StrongJp2C <TElem>(env, elementPtr); res.SetValue(element, i); } return((TRes)(object)res); }
public static TRes StrongJ2CpDelegate <TRes>(JNIEnv env, JniLocalHandle obj) where TRes : class //Delegate { #if DEBUG if (!typeof(Delegate).IsAssignableFrom(typeof(TRes))) { throw new ArgumentException("expected delegate"); } #endif if (JniHandle.IsNull(obj)) { return(default(TRes)); } object res = __IClrProxy.GetObject(env, obj); if (res == null) { //that's delegate implemented in Java RegistryRecord delRecord = Registry.GetCLRRecord(typeof(TRes)); IJvmProxy jvmProxy = delRecord.CreateCLRProxy(env, obj); return((TRes)(object)Delegate.CreateDelegate(typeof(TRes), jvmProxy, delRecord.JVMDelegateInvoke)); } return((TRes)res); }
internal JniLocalHandle GetObjectArrayElementPtr(JniHandle array, int index) { JniLocalHandle res = getObjectArrayElement(envPtr, array, index); ExceptionTest(); return res; }
internal void ReleaseStringChars(JniHandle str, IntPtr chars) { releaseStringChars(envPtr, str, chars); ExceptionTest(); }
public static bool IsNull(JniHandle handle) { return handle.handle == IntPtr.Zero; }
public static bool IsNull(JniHandle handle) { return(handle.handle == IntPtr.Zero); }
private static long getClrHandle(JNIEnv env, JniHandle obj) { return env.CallLongMethod(obj, _getClrHandle0); }
internal int GetArrayLength(JniHandle array) { int res = getArrayLength(envPtr, array); ExceptionTest(); return res; }
private static Type IsCLR(Class iface, JniHandle obj, JNIEnv env) { if (IClrProxy_._class.isAssignableFrom(iface)) { object real = __IClrProxy.GetObject(env, obj); return real.GetType(); } return null; }
internal void SetLongArrayRegion(JniHandle array, int start, int len, long[] buf) { fixed (long* ptr = &buf[0]) { setLongArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
internal void GetFloatArrayRegion(JniHandle array, int start, int len, float[] buf) { fixed (float* ptr = &buf[0]) { getFloatArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
internal void SetShortArrayRegion(JniHandle array, int start, int len, short[] buf) { fixed (short* ptr = &buf[0]) { setShortArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
public void SetObjectArrayElement(Object array, int index, JniHandle val) { SetObjectArrayElement(array.jvmHandle, index, val); }
internal JniLocalHandle GetObjectFieldPtr(JniHandle obj, FieldId fieldID) { JniLocalHandle res = getObjectField(envPtr, obj, fieldID.native); ExceptionTest(); return res; }
internal void SetDoubleArrayRegion(JniHandle array, int start, int len, double[] buf) { fixed (double* ptr = &buf[0]) { setDoubleArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
internal IntPtr GetStringChars(JniHandle str, byte* isCopy) { IntPtr res = getStringChars(envPtr, str, isCopy); ExceptionTest(); return res; }
public void SetObjectArrayElement(JniHandle array, int index, JniHandle val) { setObjectArrayElement(envPtr, array, index, val); ExceptionTest(); }