示例#1
0
        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);
        }
示例#2
0
        public int GetStaticIntField(JniHandle clazz, FieldId fieldID)
        {
            int res = getStaticIntField(envPtr, clazz, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#3
0
        public IntPtr GetStringChars(JniHandle str, byte *isCopy)
        {
            IntPtr res = getStringChars(envPtr, str, isCopy);

            ExceptionTest();
            return(res);
        }
示例#4
0
        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);
        }
示例#5
0
        public JniLocalHandle GetObjectField(JniHandle obj, FieldId fieldID)
        {
            JniLocalHandle res = getObjectField(envPtr, obj, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#6
0
        public JniLocalHandle CallStaticObjectMethod(JniHandle clazz, MethodId methodIdNative, params Value[] args)
        {
            JniLocalHandle res = callStaticObjectMethod(envPtr, clazz, methodIdNative.native, args);

            ExceptionTest();
            return(res);
        }
示例#7
0
        public float CallFloatMethod(JniHandle obj, MethodId methodIdNative, params Value[] args)
        {
            float res = callFloatMethod(envPtr, obj, methodIdNative.native, args);

            ExceptionTest();
            return(res);
        }
示例#8
0
        public char GetStaticCharField(JniHandle clazz, FieldId fieldID)
        {
            var res = (char)getStaticCharField(envPtr, clazz, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#9
0
        public long CallLongMethod(JniHandle obj, MethodId methodIdNative, params Value[] args)
        {
            long res = callLongMethod(envPtr, obj, methodIdNative.native, args);

            ExceptionTest();
            return(res);
        }
示例#10
0
        public double CallDoubleMethod(JniHandle obj, MethodId methodIdNative, params Value[] args)
        {
            double res = callDoubleMethod(envPtr, obj, methodIdNative.native, args);

            ExceptionTest();
            return(res);
        }
示例#11
0
        public bool CallBooleanMethod(JniHandle obj, MethodId methodIdNative, params Value[] args)
        {
            bool res = callBooleanMethod(envPtr, obj, methodIdNative.native, args) != 0;

            ExceptionTest();
            return(res);
        }
示例#12
0
        public double CallNonVirtualDoubleMethod(JniHandle obj, JniHandle clazz, MethodId methodIdNative, params Value[] args)
        {
            var res = callNonvirtualDoubleMethod(envPtr, obj, clazz, methodIdNative.native, args);

            ExceptionTest();
            return(res);
        }
示例#13
0
        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);
        }
示例#14
0
        public double GetStaticDoubleField(JniHandle clazz, FieldId fieldID)
        {
            double res = getStaticDoubleField(envPtr, clazz, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#15
0
        public char CallCharMethod(JniHandle obj, MethodId methodIdNative, params Value[] args)
        {
            var res = (char)callCharMethod(envPtr, obj, methodIdNative.native, args);

            ExceptionTest();
            return(res);
        }
示例#16
0
        public float GetStaticFloatField(JniHandle clazz, FieldId fieldID)
        {
            float res = getStaticFloatField(envPtr, clazz, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#17
0
        public int GetIntField(JniHandle obj, FieldId fieldID)
        {
            int res = getIntField(envPtr, obj, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#18
0
        public int GetArrayLength(JniHandle array)
        {
            int res = getArrayLength(envPtr, array);

            ExceptionTest();
            return(res);
        }
示例#19
0
        public bool GetStaticBooleanField(JniHandle clazz, IntPtr fieldID)
        {
            bool res = getStaticBooleanField(envPtr, clazz, fieldID) != 0;

            ExceptionTest();
            return(res);
        }
示例#20
0
        public JniLocalHandle GetStaticObjectField(JniHandle clazz, FieldId fieldID)
        {
            JniLocalHandle res = getStaticObjectField(envPtr, clazz, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#21
0
        public byte GetStaticByteField(JniHandle clazz, FieldId fieldID)
        {
            byte res = getStaticByteField(envPtr, clazz, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#22
0
        public JniLocalHandle GetObjectArrayElement(JniHandle array, int index)
        {
            JniLocalHandle res = getObjectArrayElement(envPtr, array, index);

            ExceptionTest();
            return(res);
        }
示例#23
0
        public short GetStaticShortField(JniHandle clazz, FieldId fieldID)
        {
            short res = getStaticShortField(envPtr, clazz, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#24
0
        public JniLocalHandle NewObjectArray(int len, JniHandle clazz, JniHandle init)
        {
            JniLocalHandle res = newObjectArray(envPtr, len, clazz, init);

            ExceptionTest();
            return(res);
        }
示例#25
0
        public long GetStaticLongField(JniHandle clazz, FieldId fieldID)
        {
            long res = getStaticLongField(envPtr, clazz, fieldID.native);

            ExceptionTest();
            return(res);
        }
示例#26
0
        private static string GetClassCanonicalName(JNIEnv env, JniHandle clazz)
        {
            InitializeClassMethods(env);
            JniLocalHandle nameHandle = env.CallObjectMethod(clazz, mGetCanonicalName);

            return(env.ConvertToString(nameHandle));
        }
示例#27
0
        internal JniLocalHandle PopLocalFrame(JniHandle result)
        {
            JniLocalHandle res = popLocalFrame(envPtr, result);

            ExceptionTest();
            return(res);
        }
示例#28
0
        public void Register(JniHandle clazz, JNIEnv env)
        {
            List <JNINativeMethod> l = new List <JNINativeMethod>();

            l.Add(this);
            Register(l, clazz, env);
        }
示例#29
0
        public short CallStaticShortMethod(JniHandle clazz, MethodId methodIdNative, params Value[] args)
        {
            short res = callStaticShortMethod(envPtr, clazz, methodIdNative.native, args);

            ExceptionTest();
            return(res);
        }
示例#30
0
        public byte CallStaticByteMethod(JniHandle clazz, MethodId methodIdNative, params Value[] args)
        {
            byte res = callStaticByteMethod(envPtr, clazz, methodIdNative.native, args);

            ExceptionTest();
            return(res);
        }
示例#31
0
 public void SetBooleanArrayRegion(JniHandle array, int start, int len, bool[] buf)
 {
     fixed (bool* ptr = &buf[0])
     {
         setBooleanArrayRegion(envPtr, array, start, len, (byte*) ptr);
     }
     ExceptionTest();
 }
示例#32
0
 public void SetByteArrayRegion(JniHandle array, int start, int len, byte[] buf)
 {
     fixed (byte* ptr = &buf[0])
     {
         setByteArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
示例#33
0
 public void SetCharArrayRegion(JniHandle array, int start, int len, char[] buf)
 {
     fixed (char* ptr = &buf[0])
     {
         setCharArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
示例#34
0
 public void SetLongArrayRegion(JniHandle array, int start, int len, long[] buf)
 {
     fixed (long* ptr = &buf[0])
     {
         setLongArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
示例#35
0
 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.");
     }
 }
示例#36
0
 public void SetFloatArrayRegion(JniHandle array, int start, int len, float[] buf)
 {
     fixed (float* ptr = &buf[0])
     {
         setFloatArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
示例#37
0
 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?");
     }
 }
示例#38
0
 internal void Throw(JniHandle ptr)
 {
     if (@throw(envPtr, ptr) != JNIResult.JNI_OK)
     {
         throw new JNIException("Can't throw");
     }
 }
示例#39
0
 internal void SetStaticShortField(JniHandle clazz, FieldId fieldID, short value)
 {
     setStaticShortField(envPtr, clazz, fieldID.native, value);
     ExceptionTest();
 }
示例#40
0
 public void SetObjectArrayElement(JniHandle array, int index, JniHandle val)
 {
     setObjectArrayElement(envPtr, array, index, val);
     ExceptionTest();
 }
示例#41
0
 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;
 }
示例#42
0
 internal void SetObjectField(JniHandle obj, FieldId fieldID, JniHandle value)
 {
     setObjectField(envPtr, obj, fieldID.native, value);
     ExceptionTest();
 }
示例#43
0
 public JniLocalHandle GetObjectField(JniHandle obj, FieldId fieldID)
 {
     JniLocalHandle res = getObjectField(envPtr, obj, fieldID.native);
     ExceptionTest();
     return res;
 }
示例#44
0
 public JniLocalHandle NewObjectArray(int len, JniHandle clazz, JniHandle init)
 {
     JniLocalHandle res = newObjectArray(envPtr, len, clazz, init);
     ExceptionTest();
     return res;
 }
示例#45
0
 public double CallDoubleMethod(JniHandle obj, MethodId methodIdNative, params Value[] args)
 {
     double res = callDoubleMethod(envPtr, obj, methodIdNative.native, args);
     ExceptionTest();
     return res;
 }
示例#46
0
 public IntPtr GetStringChars(JniHandle str, byte* isCopy)
 {
     IntPtr res = getStringChars(envPtr, str, isCopy);
     ExceptionTest();
     return res;
 }
示例#47
0
 public void ReleaseStringChars(JniHandle str, IntPtr chars)
 {
     releaseStringChars(envPtr, str, chars);
     ExceptionTest();
 }
示例#48
0
 public JniLocalHandle GetObjectArrayElement(JniHandle array, int index)
 {
     JniLocalHandle res = getObjectArrayElement(envPtr, array, index);
     ExceptionTest();
     return res;
 }
示例#49
0
 public JniLocalHandle CallStaticObjectMethod(JniHandle clazz, MethodId methodIdNative, params Value[] args)
 {
     JniLocalHandle res = callStaticObjectMethod(envPtr, clazz, methodIdNative.native, args);
     ExceptionTest();
     return res;
 }
示例#50
0
 public JniLocalHandle GetStaticObjectField(JniHandle clazz, FieldId fieldID)
 {
     JniLocalHandle res = getStaticObjectField(envPtr, clazz, fieldID.native);
     ExceptionTest();
     return res;
 }
示例#51
0
 internal void SetStaticObjectField(JniHandle clazz, FieldId fieldID, JavaObject value)
 {
     setStaticObjectField(envPtr, clazz, fieldID.native, value.JvmHandle);
     ExceptionTest();
 }
示例#52
0
 public void GetShortArrayRegion(JniHandle array, int start, int len, short[] buf)
 {
     fixed (short* ptr = &buf[0])
     {
         getShortArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
示例#53
0
 internal void SetStaticBooleanField(JniHandle clazz, IntPtr fieldID, bool value)
 {
     setStaticBooleanField(envPtr, clazz, fieldID, value ? (byte)1 : (byte)0);
     ExceptionTest();
 }
示例#54
0
 public void GetDoubleArrayRegion(JniHandle array, int start, int len, double[] buf)
 {
     fixed (double* ptr = &buf[0])
     {
         getDoubleArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
示例#55
0
 internal void SetShortField(JniHandle obj, FieldId fieldID, short value)
 {
     setShortField(envPtr, obj, fieldID.native, value);
     ExceptionTest();
 }
示例#56
0
 public int GetArrayLength(JniHandle array)
 {
     int res = getArrayLength(envPtr, array);
     ExceptionTest();
     return res;
 }
示例#57
0
 internal void SetStaticBooleanField(JniHandle clazz, FieldId fieldID, bool value)
 {
     SetStaticBooleanField(clazz, fieldID.native, value);
 }
示例#58
0
 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;
 }
示例#59
0
 public void Register(JniHandle clazz, JNIEnv env)
 {
     List<JNINativeMethod> l = new List<JNINativeMethod>();
     l.Add(this);
     Register(l, clazz, env);
 }
示例#60
0
 internal void SetStaticDoubleField(JniHandle clazz, FieldId fieldID, double value)
 {
     setStaticDoubleField(envPtr, clazz, fieldID.native, value);
     ExceptionTest();
 }