Exemplo n.º 1
0
 public JNIEnv(IntPtr native)
 {
     this.envPtr = native;
     functions = *(*(JavaPtr*) native.ToPointer()).functions;
     InitMethods();
     if (defaultVM == null)
     {
         defaultVM = GetJavaVM();
     }
 }
Exemplo n.º 2
0
 public JNIEnv(IntPtr native)
 {
     this.envPtr = native;
     functions   = *(*(JavaPtr *)native.ToPointer()).functions;
     InitMethods();
     if (defaultVM == null)
     {
         defaultVM = GetJavaVM();
     }
 }
Exemplo n.º 3
0
        static void Initialize(IntPtr vm)
        {
            myVM = JNIEnv.defaultVM = new JavaVM(vm);
            Log("Setting JVM");
            var env = JNIEnv.GetEnvForVm(myVM);

            myMonoProxyClass = env.NewGlobalRef(env.FindClass("com/koushikdutta/monojavabridge/MonoProxy"));
            mySetGCHandle    = env.GetMethodID(myMonoProxyClass, "setGCHandle", "(J)V");
            myGetGCHandle    = env.GetMethodID(myMonoProxyClass, "getGCHandle", "()J");
        }
Exemplo n.º 4
0
 public JavaVM GetJavaVM()
 {
     if (javaVM == null)
     {
         IntPtr jvm;
         getJavaVM.Invoke(envPtr, out jvm);
         ExceptionTest();
         javaVM = new JavaVM(jvm);
     }
     return(javaVM);
 }
Exemplo n.º 5
0
 public JavaVM GetJavaVM()
 {
     if (javaVM == null)
     {
         IntPtr jvm;
         getJavaVM.Invoke(envPtr, out jvm);
         ExceptionTest();
         javaVM = new JavaVM(jvm);
     }
     return javaVM;
 }
Exemplo n.º 6
0
 public static JNIEnv GetEnvNoThrow(JavaVM vm)
 {
     if (threadJNIEnv == null)
     {
         JNIResult result = vm.AttachCurrentThreadAsDaemon(out threadJNIEnv, null);
         if (result != JNIResult.JNI_OK)
         {
             return(null);
         }
     }
     return(threadJNIEnv);
 }
Exemplo n.º 7
0
 public static JNIEnv GetEnvForVm(JavaVM vm)
 {
     if (threadJNIEnv == null)
     {
         JNIResult result = vm.AttachCurrentThreadAsDaemon(out threadJNIEnv, null);
         if (result != JNIResult.JNI_OK)
         {
             throw new JNIException("AttachCurrentThreadAsDaemon failed: " + result);
         }
     }
     return(threadJNIEnv);
 }
Exemplo n.º 8
0
 public static JNIEnv GetEnvForVm(JavaVM vm)
 {
     if (threadJNIEnv == null)
     {
         JNIResult result = vm.AttachCurrentThreadAsDaemon(out threadJNIEnv, null);
         if (result != JNIResult.JNI_OK)
         {
             throw new JNIException("AttachCurrentThreadAsDaemon failed: " + result);
         }
     }
     return threadJNIEnv;
 }
Exemplo n.º 9
0
        public JavaVM(IntPtr native)
        {
            if (defaultVM != null)
                throw new Exception("Why is a second VM being initialized?");
            this.native = native;
            defaultVM = this;
            functions = *(*(JavaPtr*) native.ToPointer()).functions;

            Helper.GetDelegateForFunctionPointer(functions.AttachCurrentThreadAsDaemon, ref attachCurrentThreadAsDaemon);
            Helper.GetDelegateForFunctionPointer(functions.AttachCurrentThread, ref attachCurrentThread);
            Helper.GetDelegateForFunctionPointer(functions.DestroyJavaVM, ref destroyJavaVM);
            Helper.GetDelegateForFunctionPointer(functions.DetachCurrentThread, ref detachCurrentThread);
            Helper.GetDelegateForFunctionPointer(functions.GetEnv, ref getEnv);

            var env = JNIEnv.ThreadEnv;
            var classLoaderClass = env.FindClass("java/lang/ClassLoader");
            findClass = env.GetMethodID(classLoaderClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
        }
Exemplo n.º 10
0
 public static JNIEnv GetEnvNoThrow(JavaVM vm)
 {
     if (threadJNIEnv == null)
     {
         JNIResult result = vm.AttachCurrentThreadAsDaemon(out threadJNIEnv, null);
         if (result != JNIResult.JNI_OK)
         {
             return null;
         }
     }
     return threadJNIEnv;
 }
Exemplo n.º 11
0
 public JniGlobalHandle(JniGlobalHandleNs handleValue, JavaVM javaVM)
     : base(IntPtr.Zero, true)
 {
     this.javaVM = javaVM;
     SetHandle(handleValue.handle);
 }
Exemplo n.º 12
0
 public JniGlobalHandle(IntPtr handleValue, JavaVM javaVM)
     : base(IntPtr.Zero, true)
 {
     this.javaVM = javaVM;
     SetHandle(handleValue);
 }