public static T WrapIJavaObject <T>(JniLocalHandle handle) where T : class, IJavaObject { if (JniHandle.IsNull(handle)) { return(null); } // see if we can find the appropriate class instance Type type = typeof(T); string className = type.FullName; JNIEnv env = JNIEnv.ThreadEnv; JniLocalHandle clazz = env.GetObjectClass(handle); Wrapper wrapper = GetWrapper(env, clazz); if (!wrapper.Type.GetInterfaces().Contains(typeof(T))) { // failed to find the instance, so let's go with the interface wrapper wrapper = GetWrapper(className + "_"); } var ret = wrapper.Constructor.Invoke(new object[] { env }) as T; ret.Init(env, handle); return(ret); }
public int GetStaticIntField(JniHandle clazz, FieldId fieldID) { int res = getStaticIntField(envPtr, clazz, fieldID.native); ExceptionTest(); return(res); }
public IntPtr GetStringChars(JniHandle str, byte *isCopy) { IntPtr res = getStringChars(envPtr, str, isCopy); ExceptionTest(); return(res); }
private static Value ConvertToValue(JNIEnv env, object o) { // check if this is a primitive Type type = o.GetType(); if (type.IsPrimitive) { return(ConvertPrimitiveToValue(env, o, type)); } // if it's not an array, cast to IJavaObject Array array = o as Array; if (array == null) { return(ConvertToValue(o)); } // it's an array, so create the proper array type and convert the individual elements recursively string classSignature = GetSignature(type.GetElementType().FullName); JniLocalHandle clazzHandle = env.FindClass(classSignature); JniLocalHandle arrayHandle = env.NewObjectArray(array.Length, clazzHandle, JniLocalHandle.Zero); for (int i = 0; i < array.Length; i++) { JniHandle element = new JniHandle(); element.handle = ConvertToValue(env, array.GetValue(i))._object; env.SetObjectArrayElement(arrayHandle, i, element); } Value ret = new Value(); ret._object = arrayHandle; return(ret); }
public JniLocalHandle GetObjectField(JniHandle obj, FieldId fieldID) { JniLocalHandle res = getObjectField(envPtr, obj, fieldID.native); ExceptionTest(); return(res); }
public JniLocalHandle CallStaticObjectMethod(JniHandle clazz, MethodId methodIdNative, params Value[] args) { JniLocalHandle res = callStaticObjectMethod(envPtr, clazz, methodIdNative.native, args); ExceptionTest(); return(res); }
public float CallFloatMethod(JniHandle obj, MethodId methodIdNative, params Value[] args) { float res = callFloatMethod(envPtr, obj, methodIdNative.native, args); ExceptionTest(); return(res); }
public char GetStaticCharField(JniHandle clazz, FieldId fieldID) { var res = (char)getStaticCharField(envPtr, clazz, fieldID.native); ExceptionTest(); return(res); }
public long CallLongMethod(JniHandle obj, MethodId methodIdNative, params Value[] args) { long res = callLongMethod(envPtr, obj, methodIdNative.native, args); ExceptionTest(); return(res); }
public double CallDoubleMethod(JniHandle obj, MethodId methodIdNative, params Value[] args) { double res = callDoubleMethod(envPtr, obj, methodIdNative.native, args); ExceptionTest(); return(res); }
public bool CallBooleanMethod(JniHandle obj, MethodId methodIdNative, params Value[] args) { bool res = callBooleanMethod(envPtr, obj, methodIdNative.native, args) != 0; ExceptionTest(); return(res); }
public double CallNonVirtualDoubleMethod(JniHandle obj, JniHandle clazz, MethodId methodIdNative, params Value[] args) { var res = callNonvirtualDoubleMethod(envPtr, obj, clazz, methodIdNative.native, args); ExceptionTest(); return(res); }
public float CallNonVirtualFloatMethod(JavaObject obj, JniHandle clazz, MethodId methodIdNative, params Value[] args) { var res = callNonvirtualFloatMethod(envPtr, obj.JvmHandle, clazz, methodIdNative.native, args); ExceptionTest(); return(res); }
public double GetStaticDoubleField(JniHandle clazz, FieldId fieldID) { double res = getStaticDoubleField(envPtr, clazz, fieldID.native); ExceptionTest(); return(res); }
public char CallCharMethod(JniHandle obj, MethodId methodIdNative, params Value[] args) { var res = (char)callCharMethod(envPtr, obj, methodIdNative.native, args); ExceptionTest(); return(res); }
public float GetStaticFloatField(JniHandle clazz, FieldId fieldID) { float res = getStaticFloatField(envPtr, clazz, fieldID.native); ExceptionTest(); return(res); }
public int GetIntField(JniHandle obj, FieldId fieldID) { int res = getIntField(envPtr, obj, fieldID.native); ExceptionTest(); return(res); }
public int GetArrayLength(JniHandle array) { int res = getArrayLength(envPtr, array); ExceptionTest(); return(res); }
public bool GetStaticBooleanField(JniHandle clazz, IntPtr fieldID) { bool res = getStaticBooleanField(envPtr, clazz, fieldID) != 0; ExceptionTest(); return(res); }
public JniLocalHandle GetStaticObjectField(JniHandle clazz, FieldId fieldID) { JniLocalHandle res = getStaticObjectField(envPtr, clazz, fieldID.native); ExceptionTest(); return(res); }
public byte GetStaticByteField(JniHandle clazz, FieldId fieldID) { byte res = getStaticByteField(envPtr, clazz, fieldID.native); ExceptionTest(); return(res); }
public JniLocalHandle GetObjectArrayElement(JniHandle array, int index) { JniLocalHandle res = getObjectArrayElement(envPtr, array, index); ExceptionTest(); return(res); }
public short GetStaticShortField(JniHandle clazz, FieldId fieldID) { short res = getStaticShortField(envPtr, clazz, fieldID.native); ExceptionTest(); return(res); }
public JniLocalHandle NewObjectArray(int len, JniHandle clazz, JniHandle init) { JniLocalHandle res = newObjectArray(envPtr, len, clazz, init); ExceptionTest(); return(res); }
public long GetStaticLongField(JniHandle clazz, FieldId fieldID) { long res = getStaticLongField(envPtr, clazz, fieldID.native); ExceptionTest(); return(res); }
private static string GetClassCanonicalName(JNIEnv env, JniHandle clazz) { InitializeClassMethods(env); JniLocalHandle nameHandle = env.CallObjectMethod(clazz, mGetCanonicalName); return(env.ConvertToString(nameHandle)); }
internal JniLocalHandle PopLocalFrame(JniHandle result) { JniLocalHandle res = popLocalFrame(envPtr, result); ExceptionTest(); return(res); }
public void Register(JniHandle clazz, JNIEnv env) { List <JNINativeMethod> l = new List <JNINativeMethod>(); l.Add(this); Register(l, clazz, env); }
public short CallStaticShortMethod(JniHandle clazz, MethodId methodIdNative, params Value[] args) { short res = callStaticShortMethod(envPtr, clazz, methodIdNative.native, args); ExceptionTest(); return(res); }
public byte CallStaticByteMethod(JniHandle clazz, MethodId methodIdNative, params Value[] args) { byte res = callStaticByteMethod(envPtr, clazz, methodIdNative.native, args); ExceptionTest(); return(res); }
public void SetBooleanArrayRegion(JniHandle array, int start, int len, bool[] buf) { fixed (bool* ptr = &buf[0]) { setBooleanArrayRegion(envPtr, array, start, len, (byte*) ptr); } ExceptionTest(); }
public void SetByteArrayRegion(JniHandle array, int start, int len, byte[] buf) { fixed (byte* ptr = &buf[0]) { setByteArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
public void SetCharArrayRegion(JniHandle array, int start, int len, char[] buf) { fixed (char* ptr = &buf[0]) { setCharArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
public void SetLongArrayRegion(JniHandle array, int start, int len, long[] buf) { fixed (long* ptr = &buf[0]) { setLongArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
public static unsafe void Unregister(JniHandle clazz, JNIEnv env) { JNIResult res = env.UnregisterNatives(clazz); if (res != JNIResult.JNI_OK) { throw new JNIException("Can't unbind native methods to class."); } }
public void SetFloatArrayRegion(JniHandle array, int start, int len, float[] buf) { fixed (float* ptr = &buf[0]) { setFloatArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
public static unsafe void Register(List<JNINativeMethod> registrations, JniHandle clazz, JNIEnv env) { JNINativeMethod[] methods = registrations.ToArray(); JNIResult res = env.RegisterNatives(clazz, methods, methods.Length); if (res!=JNIResult.JNI_OK) { throw new JNIException("Can't bind native methods to class. Is it in system classloader?"); } }
internal void Throw(JniHandle ptr) { if (@throw(envPtr, ptr) != JNIResult.JNI_OK) { throw new JNIException("Can't throw"); } }
internal void SetStaticShortField(JniHandle clazz, FieldId fieldID, short value) { setStaticShortField(envPtr, clazz, fieldID.native, value); ExceptionTest(); }
public void SetObjectArrayElement(JniHandle array, int index, JniHandle val) { setObjectArrayElement(envPtr, array, index, val); ExceptionTest(); }
public JniLocalHandle ToReflectedField(JniHandle cls, FieldId fieldID, bool isStatic) { JniLocalHandle res = toReflectedField.Invoke(envPtr, cls, fieldID.native, isStatic ? (byte) 1 : (byte) 0); ExceptionTest(); return res; }
internal void SetObjectField(JniHandle obj, FieldId fieldID, JniHandle value) { setObjectField(envPtr, obj, fieldID.native, value); ExceptionTest(); }
public JniLocalHandle GetObjectField(JniHandle obj, FieldId fieldID) { JniLocalHandle res = getObjectField(envPtr, obj, fieldID.native); ExceptionTest(); return res; }
public JniLocalHandle NewObjectArray(int len, JniHandle clazz, JniHandle init) { JniLocalHandle res = newObjectArray(envPtr, len, clazz, init); ExceptionTest(); return res; }
public double CallDoubleMethod(JniHandle obj, MethodId methodIdNative, params Value[] args) { double res = callDoubleMethod(envPtr, obj, methodIdNative.native, args); ExceptionTest(); return res; }
public IntPtr GetStringChars(JniHandle str, byte* isCopy) { IntPtr res = getStringChars(envPtr, str, isCopy); ExceptionTest(); return res; }
public void ReleaseStringChars(JniHandle str, IntPtr chars) { releaseStringChars(envPtr, str, chars); ExceptionTest(); }
public JniLocalHandle GetObjectArrayElement(JniHandle array, int index) { JniLocalHandle res = getObjectArrayElement(envPtr, array, index); ExceptionTest(); return res; }
public JniLocalHandle CallStaticObjectMethod(JniHandle clazz, MethodId methodIdNative, params Value[] args) { JniLocalHandle res = callStaticObjectMethod(envPtr, clazz, methodIdNative.native, args); ExceptionTest(); return res; }
public JniLocalHandle GetStaticObjectField(JniHandle clazz, FieldId fieldID) { JniLocalHandle res = getStaticObjectField(envPtr, clazz, fieldID.native); ExceptionTest(); return res; }
internal void SetStaticObjectField(JniHandle clazz, FieldId fieldID, JavaObject value) { setStaticObjectField(envPtr, clazz, fieldID.native, value.JvmHandle); ExceptionTest(); }
public void GetShortArrayRegion(JniHandle array, int start, int len, short[] buf) { fixed (short* ptr = &buf[0]) { getShortArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
internal void SetStaticBooleanField(JniHandle clazz, IntPtr fieldID, bool value) { setStaticBooleanField(envPtr, clazz, fieldID, value ? (byte)1 : (byte)0); ExceptionTest(); }
public void GetDoubleArrayRegion(JniHandle array, int start, int len, double[] buf) { fixed (double* ptr = &buf[0]) { getDoubleArrayRegion(envPtr, array, start, len, ptr); } ExceptionTest(); }
internal void SetShortField(JniHandle obj, FieldId fieldID, short value) { setShortField(envPtr, obj, fieldID.native, value); ExceptionTest(); }
public int GetArrayLength(JniHandle array) { int res = getArrayLength(envPtr, array); ExceptionTest(); return res; }
internal void SetStaticBooleanField(JniHandle clazz, FieldId fieldID, bool value) { SetStaticBooleanField(clazz, fieldID.native, value); }
public JniLocalHandle ToReflectedMethod(JniHandle cls, MethodId methodId, bool isStatic) { JniLocalHandle res = toReflectedMethod.Invoke(envPtr, cls, methodId.native, isStatic ? (byte) 1 : (byte) 0); ExceptionTest(); return res; }
public void Register(JniHandle clazz, JNIEnv env) { List<JNINativeMethod> l = new List<JNINativeMethod>(); l.Add(this); Register(l, clazz, env); }
internal void SetStaticDoubleField(JniHandle clazz, FieldId fieldID, double value) { setStaticDoubleField(envPtr, clazz, fieldID.native, value); ExceptionTest(); }