Example #1
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");
        }
Example #2
0
 public JNIResult RegisterNatives(JniHandle clazz, JNINativeMethod[] methods, int nMethods)
 {
     JNIResult natives = registerNatives.Invoke(envPtr, clazz, methods, nMethods);
     ExceptionTest();
     return natives;
 }