GetEnvForVm() private method

private GetEnvForVm ( JavaVM vm ) : JNIEnv
vm JavaVM
return JNIEnv
Exemplo n.º 1
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.º 2
0
        public static void Link(IntPtr classHandle, IntPtr methodNameHandle, IntPtr methodSignatureHandle, IntPtr methodParametersHandle)
        {
            JNIEnv env = JNIEnv.GetEnvForVm(myVM);

            var    methodName         = env.ConvertToString(methodNameHandle);
            var    methodSig          = env.ConvertToString(methodSignatureHandle);
            var    methodPars         = methodParametersHandle == IntPtr.Zero ? null : env.ConvertToString(methodParametersHandle);
            string classCanonicalName = GetClassCanonicalName(env, classHandle);
            //Console.WriteLine("Linking java class method: {0}.{1}", classCanonicalName, methodName);
            Type type = FindType(classCanonicalName);

            if (type == null)
            {
                Console.WriteLine("Could not find clr type.");
                return;
            }

            //Console.WriteLine("Found clr type: {0}", type);

            Type[] parameterTypes = null;
            if (!string.IsNullOrEmpty(methodPars))
            {
                var parameterTypeStrings = methodPars.Split(',');
                parameterTypes = new Type[parameterTypeStrings.Length];
                for (int i = 0; i < parameterTypeStrings.Length; i++)
                {
                    parameterTypes[i] = FindType(parameterTypeStrings[i]);
                    if (parameterTypes[i] == null)
                    {
                        Console.WriteLine("Could not find {0}", parameterTypeStrings[i]);
                    }
                    //else
                    //    Console.WriteLine("Found type {0}", parameterTypes[i]);
                }
            }

            var method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance, null, parameterTypes ?? new Type[] {}, null);

            Console.WriteLine("Linking Method: {0} to {1}", method, methodSig);
            var del = MakeWrapper(method);

            myLinks.Add(del);

            JNINativeMethod m = JNINativeMethod.Create(del, methodName, methodSig);

            m.Register(classHandle, env);
            Console.WriteLine("Registration complete");
        }
Exemplo n.º 3
0
 static JNIEnv GetEnv()
 {
     return(JNIEnv.GetEnvForVm(myVM));
 }