예제 #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
파일: Registry.cs 프로젝트: koush/jni4net.n
 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();
 }