Beispiel #1
0
 public JNIEnv(IntPtr native)
 {
     this.envPtr = native;
     functions = *(*(JavaPtr*) native.ToPointer()).functions;
     InitMethods();
     if (defaultVM == null)
     {
         defaultVM = GetJavaVM();
     }
 }
Beispiel #2
0
 public JNIEnv(IntPtr native)
 {
     this.envPtr = native;
     functions   = *(*(JavaPtr *)native.ToPointer()).functions;
     InitMethods();
     if (defaultVM == null)
     {
         defaultVM = GetJavaVM();
     }
 }
Beispiel #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");
        }
Beispiel #4
0
 public JavaVM GetJavaVM()
 {
     if (javaVM == null)
     {
         IntPtr jvm;
         getJavaVM.Invoke(envPtr, out jvm);
         ExceptionTest();
         javaVM = new JavaVM(jvm);
     }
     return(javaVM);
 }
Beispiel #5
0
 public JavaVM GetJavaVM()
 {
     if (javaVM == null)
     {
         IntPtr jvm;
         getJavaVM.Invoke(envPtr, out jvm);
         ExceptionTest();
         javaVM = new JavaVM(jvm);
     }
     return javaVM;
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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;
 }
Beispiel #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;");
        }
Beispiel #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;
 }
Beispiel #11
0
 public JniGlobalHandle(JniGlobalHandleNs handleValue, JavaVM javaVM)
     : base(IntPtr.Zero, true)
 {
     this.javaVM = javaVM;
     SetHandle(handleValue.handle);
 }
Beispiel #12
0
 public JniGlobalHandle(IntPtr handleValue, JavaVM javaVM)
     : base(IntPtr.Zero, true)
 {
     this.javaVM = javaVM;
     SetHandle(handleValue);
 }