示例#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);
        }
示例#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();
 }
示例#3
0
 public static String StrongJ2CpString(JNIEnv env, JniLocalHandle obj)
 {
     if (JniHandle.IsNull(obj))
     {
         return(null);
     }
     return(String.CreateProxy(env, obj));
 }
示例#4
0
 public static Class StrongJ2CpClass(JNIEnv env, JniLocalHandle obj)
 {
     if (JniHandle.IsNull(obj))
     {
         return(null);
     }
     return(Class.CreateProxy(env, obj));
 }
示例#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();
 }
示例#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();
 }
示例#7
0
文件: Registry.cs 项目: gywerd/WinJNI
 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);
 }
示例#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);
        }
示例#9
0
        public static string StrongJ2CString(JNIEnv env, JniLocalHandle obj)
        {
            if (JniHandle.IsNull(obj))
            {
                return(null);
            }
            string res = env.ConvertToString(obj);

            return(res);
        }
示例#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;
 }
示例#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);
        }
示例#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));
        }
示例#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));
     }
 }
示例#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);
     }
 }
示例#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));
        }
示例#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);
        }
示例#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);
        }
示例#18
0
 internal JniLocalHandle GetObjectArrayElementPtr(JniHandle array, int index)
 {
     JniLocalHandle res = getObjectArrayElement(envPtr, array, index);
     ExceptionTest();
     return res;
 }
示例#19
0
 internal void ReleaseStringChars(JniHandle str, IntPtr chars)
 {
     releaseStringChars(envPtr, str, chars);
     ExceptionTest();
 }
示例#20
0
 public static bool IsNull(JniHandle handle)
 {
     return handle.handle == IntPtr.Zero;
 }
示例#21
0
 public static bool IsNull(JniHandle handle)
 {
     return(handle.handle == IntPtr.Zero);
 }
示例#22
0
 private static long getClrHandle(JNIEnv env, JniHandle obj)
 {
     return env.CallLongMethod(obj, _getClrHandle0);
 }
示例#23
0
 internal int GetArrayLength(JniHandle array)
 {
     int res = getArrayLength(envPtr, array);
     ExceptionTest();
     return res;
 }
示例#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;
 }
示例#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();
 }
示例#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();
 }
示例#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();
 }
示例#28
0
 public void SetObjectArrayElement(Object array, int index, JniHandle val)
 {
     SetObjectArrayElement(array.jvmHandle, index, val);
 }
示例#29
0
 internal JniLocalHandle GetObjectFieldPtr(JniHandle obj, FieldId fieldID)
 {
     JniLocalHandle res = getObjectField(envPtr, obj, fieldID.native);
     ExceptionTest();
     return res;
 }
示例#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();
 }
示例#31
0
 internal IntPtr GetStringChars(JniHandle str, byte* isCopy)
 {
     IntPtr res = getStringChars(envPtr, str, isCopy);
     ExceptionTest();
     return res;
 }
示例#32
0
 public void SetObjectArrayElement(JniHandle array, int index, JniHandle val)
 {
     setObjectArrayElement(envPtr, array, index, val);
     ExceptionTest();
 }