Exemple #1
0
        private static List <JNINativeMethod> __Init2(JNIEnv @__env, Class @__class)
        {
            Type @__type = typeof(__Bridge);
            var  methods = new List <JNINativeMethod>();

            methods.Add(JNINativeMethod.Create(@__type, "WrapJVM", "WrapJVM", "(Ljava/lang/Object;)J"));
            methods.Add(JNINativeMethod.Create(@__type, "Convert", "Convert", "(Ljava/lang/String;)J"));
            methods.Add(JNINativeMethod.Create(@__type, "UnwrapJVM", "UnwrapJVM", "(J)Ljava/lang/Object;"));
            methods.Add(JNINativeMethod.Create(@__type, "DisposeClrHandle", "DisposeClrHandle", "(J)V"));
            methods.Add(JNINativeMethod.Create(@__type, "Cast", "Cast", "(Ljava/lang/Object;Ljava/lang/Class;)Lnet/sf/jni4net/inj/IClrProxy;"));
            return(methods);
        }
Exemple #2
0
        static internal void UnregisterNative()
        {
            JNIEnv env = JNIEnv.ThreadEnv;

            foreach (var proxy in nativeMethods)
            {
                try
                {
                    JNINativeMethod.Unregister(proxy.Key, env);
                }
                catch (Exception ex)
                {
                    throw new JNIException("Failed unbinding native methods for " + proxy.Key, ex);
                }
            }
        }
Exemple #3
0
        internal static void RegisterNative(MethodInfo initializer, JNIEnv env, Class jvmProxy, Class jvmInterface)
        {
            var registrations = (List <JNINativeMethod>)initializer.Invoke(null, new object[] { env, jvmProxy });

            if (registrations.Count > 0)
            {
                if (Bridge.Setup.Debug)
                {
                    foreach (JNINativeMethod registration in registrations)
                    {
                        string n = Marshal.PtrToStringAnsi(registration.name);
                        string s = Marshal.PtrToStringAnsi(registration.signature);
                        if (env.GetMethodIDNoThrow(jvmInterface, n, s) == null)
                        {
                            if (env.GetStaticMethodIDNoThrow(jvmInterface, n, s) == null)
                            {
                                throw new JNIException("Can't find native method" + n + "()" +
                                                       s + " in class " + jvmInterface);
                            }
                        }
                    }

                    /*if (Bridge.clrLoaded)
                     * {
                     *  if (!jvmProxy.getClassLoader().equals(ClassLoader.getSystemClassLoader()))
                     *  {
                     *      Console.Error.WriteLine("Class " + jvmProxy.toString() +
                     *                              " is not in system classloader. It may fail binding native methods.");
                     *  }
                     * }*/
                }
                try
                {
                    JNINativeMethod.Register(registrations, jvmProxy, env);
                    if (!nativeMethods.ContainsKey(jvmProxy))
                    {
                        nativeMethods.Add(jvmProxy, registrations);
                    }
                }
                catch (Exception ex)
                {
                    throw new JNIException("Failed binding native methods for " + jvmInterface, ex);
                }
            }
        }
Exemple #4
0
		internal static int RegisterNatives(JNIEnv* pEnv, IntPtr clazz, JNINativeMethod* methods, int nMethods)
		{
			try
			{
				TypeWrapper wrapper = TypeWrapper.FromClass((java.lang.Class)pEnv->UnwrapRef(clazz));
				wrapper.Finish();
				for(int i = 0; i < nMethods; i++)
				{
					string methodName = StringFromUTF8(methods[i].name);
					string methodSig = StringFromUTF8(methods[i].signature);
					Tracer.Info(Tracer.Jni, "Registering native method: {0}.{1}{2}, fnPtr = 0x{3:X}", wrapper.Name, methodName, methodSig, ((IntPtr)methods[i].fnPtr).ToInt64());
					FieldInfo fi = null;
					// don't allow dotted names!
					if(methodSig.IndexOf('.') < 0)
					{
						// TODO this won't work when we're putting the JNI methods in jniproxy.dll
						fi = wrapper.TypeAsTBD.GetField(JNI.METHOD_PTR_FIELD_PREFIX + methodName + methodSig, BindingFlags.Static | BindingFlags.NonPublic);
					}
					if(fi == null)
					{
						Tracer.Error(Tracer.Jni, "Failed to register native method: {0}.{1}{2}", wrapper.Name, methodName, methodSig);
						SetPendingException(pEnv, new java.lang.NoSuchMethodError(methodName));
						return JNI_ERR;
					}
					fi.SetValue(null, (IntPtr)methods[i].fnPtr);
				}
				return JNI_OK;
			}
			catch(RetargetableJavaException x)
			{
				SetPendingException(pEnv, x.ToJava());
				return JNI_ERR;
			}
			catch(Exception x)
			{
				SetPendingException(pEnv, x);
				return JNI_ERR;
			}
		}
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(JNINativeMethod obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
 public JNIResult RegisterNatives(jclass* clazz, JNINativeMethod* methods, int nMethods)
 {
     if (registerNatives == null)
     {
         Util.GetDelegateForFunctionPointer(functions.RegisterNatives, ref registerNatives);
     }
     return registerNatives.Invoke(real, clazz, methods, nMethods);
 }