private static bool CheckAlreadyLoaded(BridgeSetup newSetup, JNIEnv env) { if (clrLoaded) { return(true); } if (newSetup.BindNative) { JniLocalHandle br = env.FindClassPtrNoThrow("net/sf/jni4net/Bridge"); if (JniLocalHandle.IsNull(br)) { throw new JNIException("Can't find class net.sf.jni4net.Bridge on classpath"); } IntPtr ir = env.GetStaticFieldIDPtr(br, "isRegistered", "Z"); bool isRegistered = env.GetStaticBooleanField(br, ir); if (isRegistered) { // rather neat. When called like Clr->Java->Clr this dll gets loaded twice. // which means two separate sets CLR of classes and static members if (newSetup.Verbose) { Console.WriteLine("Already initialized jni4net core before"); } return(true); } } return(false); }
internal static int initDotNetImpl(IntPtr envi, IntPtr clazz) { JNIEnv env = null; try { try { env = JNIEnv.Wrap(envi); } catch (Exception ex) { Console.Error.WriteLine("Can't bind env:\n" + ex.Message); Console.Error.WriteLine("Can't bind env:\n" + ex); return(-3); } JniLocalHandle br = env.FindClassPtrNoThrow("net/sf/jni4net/Bridge"); if (JniLocalHandle.IsNull(br)) { Console.Error.WriteLine("Can't find net/sf/jni4net/Bridge class"); return(-2); } IntPtr vb = env.GetStaticFieldIDPtr(br, "verbose", "Z"); IntPtr db = env.GetStaticFieldIDPtr(br, "debug", "Z"); if (IntPtr.Zero == vb || IntPtr.Zero == db) { Console.Error.WriteLine("Can't find verbose or debug fields"); return(-6); } var newSetup = new BridgeSetup(false) { Verbose = env.GetStaticBooleanField(br, vb), Debug = env.GetStaticBooleanField(br, db), BindStatic = true, BindNative = true }; BindCore(env, newSetup); if (Setup.JavaHome == null) { Setup.JavaHome = java.lang.System.getProperty("java.home"); } DumpRuntimeVersions(); } catch (Exception ex) { try { Console.Error.WriteLine("Can't bind bridge:" + ex.Message); Console.Error.WriteLine("Can't bind bridge:" + ex); Class exClazz = env.FindClass("net/sf/jni4net/inj/INJException"); env.ThrowNew(exClazz, ex.Message); return(-4); } catch (Exception) { return(-5); } } return(0); }
public void DeleteLocalRef(JniLocalHandle lref) { if (JniLocalHandle.IsNull(lref)) { throw new ArgumentNullException("lref"); } deleteLocalRef(envPtr, lref); //optimized away ExceptionTest(); }
public JniGlobalHandle NewGlobalRef(JniHandle lobj) { if (JniLocalHandle.IsNull(lobj)) { throw new ArgumentNullException("lobj"); } JniGlobalHandleNs res = newGlobalRef(envPtr, lobj); return(new JniGlobalHandle(res.handle, GetJavaVM())); }
public void ExceptionTest() { JniLocalHandle occurred = ExceptionOccurred(); if (!JniLocalHandle.IsNull(occurred)) { //ExceptionDescribe(); ExceptionClear(); Exception exception = Convertor.FullJ2C <Exception>(this, occurred); throw exception; } }
public bool ExceptionRead() { JniLocalHandle occurred = ExceptionOccurred(); if (!JniLocalHandle.IsNull(occurred)) { if (Bridge.Setup.VeryVerbose) { ExceptionDescribe(); } ExceptionClear(); return(true); } return(false); }