Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 internal void GetCharArrayRegion(JniHandle array, int start, int len, char[] buf)
 {
     fixed (char* ptr = &buf[0])
     {
         getCharArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
Esempio n. 3
0
 public static String StrongJ2CpString(JNIEnv env, JniLocalHandle obj)
 {
     if (JniHandle.IsNull(obj))
     {
         return(null);
     }
     return(String.CreateProxy(env, obj));
 }
Esempio n. 4
0
 public static Class StrongJ2CpClass(JNIEnv env, JniLocalHandle obj)
 {
     if (JniHandle.IsNull(obj))
     {
         return(null);
     }
     return(Class.CreateProxy(env, obj));
 }
Esempio n. 5
0
 internal void GetByteArrayRegion(JniHandle array, int start, int len, byte[] buf)
 {
     fixed (byte* ptr = &buf[0])
     {
         getByteArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
Esempio n. 6
0
 internal void GetBooleanArrayRegion(JniHandle array, int start, int len, bool[] buf)
 {
     fixed (bool* ptr = &buf[0])
     {
         getBooleanArrayRegion(envPtr, array, start, len, (byte*) ptr);
     }
     ExceptionTest();
 }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
        public static string StrongJp2CString(JNIEnv env, JniLocalHandle obj)
        {
            if (JniHandle.IsNull(obj))
            {
                return(null);
            }
            object res = __IClrProxy.GetObject(env, obj);

            return((string)res);
        }
Esempio n. 9
0
        public static string StrongJ2CString(JNIEnv env, JniLocalHandle obj)
        {
            if (JniHandle.IsNull(obj))
            {
                return(null);
            }
            string res = env.ConvertToString(obj);

            return(res);
        }
Esempio n. 10
0
 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;
 }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
 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));
     }
 }
Esempio n. 14
0
 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);
     }
 }
Esempio n. 15
0
        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));
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
 internal JniLocalHandle GetObjectArrayElementPtr(JniHandle array, int index)
 {
     JniLocalHandle res = getObjectArrayElement(envPtr, array, index);
     ExceptionTest();
     return res;
 }
Esempio n. 19
0
 internal void ReleaseStringChars(JniHandle str, IntPtr chars)
 {
     releaseStringChars(envPtr, str, chars);
     ExceptionTest();
 }
Esempio n. 20
0
 public static bool IsNull(JniHandle handle)
 {
     return handle.handle == IntPtr.Zero;
 }
Esempio n. 21
0
 public static bool IsNull(JniHandle handle)
 {
     return(handle.handle == IntPtr.Zero);
 }
Esempio n. 22
0
 private static long getClrHandle(JNIEnv env, JniHandle obj)
 {
     return env.CallLongMethod(obj, _getClrHandle0);
 }
Esempio n. 23
0
 internal int GetArrayLength(JniHandle array)
 {
     int res = getArrayLength(envPtr, array);
     ExceptionTest();
     return res;
 }
Esempio n. 24
0
 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;
 }
Esempio n. 25
0
 internal void SetLongArrayRegion(JniHandle array, int start, int len, long[] buf)
 {
     fixed (long* ptr = &buf[0])
     {
         setLongArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
Esempio n. 26
0
 internal void GetFloatArrayRegion(JniHandle array, int start, int len, float[] buf)
 {
     fixed (float* ptr = &buf[0])
     {
         getFloatArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
Esempio n. 27
0
 internal void SetShortArrayRegion(JniHandle array, int start, int len, short[] buf)
 {
     fixed (short* ptr = &buf[0])
     {
         setShortArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
Esempio n. 28
0
 public void SetObjectArrayElement(Object array, int index, JniHandle val)
 {
     SetObjectArrayElement(array.jvmHandle, index, val);
 }
Esempio n. 29
0
 internal JniLocalHandle GetObjectFieldPtr(JniHandle obj, FieldId fieldID)
 {
     JniLocalHandle res = getObjectField(envPtr, obj, fieldID.native);
     ExceptionTest();
     return res;
 }
Esempio n. 30
0
 internal void SetDoubleArrayRegion(JniHandle array, int start, int len, double[] buf)
 {
     fixed (double* ptr = &buf[0])
     {
         setDoubleArrayRegion(envPtr, array, start, len, ptr);
     }
     ExceptionTest();
 }
Esempio n. 31
0
 internal IntPtr GetStringChars(JniHandle str, byte* isCopy)
 {
     IntPtr res = getStringChars(envPtr, str, isCopy);
     ExceptionTest();
     return res;
 }
Esempio n. 32
0
 public void SetObjectArrayElement(JniHandle array, int index, JniHandle val)
 {
     setObjectArrayElement(envPtr, array, index, val);
     ExceptionTest();
 }