internal JniThreadMonitor(JniEnvironment env, JniObject objectHandle) { JniObject.VerifyInputJniObject(objectHandle); mEnvironment = env; mObjectHandle = objectHandle; Enter(); }
public JavaVMAttachArgs(JniVersion jniVersion, string theName, JniObject groupHandle) { this.version = (int)jniVersion; this.name = IntPtr.Zero; if (theName != null) { this.name = Marshal.StringToHGlobalAnsi(theName); } group = (groupHandle == null) ? IntPtr.Zero : groupHandle.Handle; }
private void Exit() { int result = JniEnvironment.Functions.MonitorExit(mEnvironment.Handle, mObjectHandle.Handle); if (0 != result) { JniException.CheckErrorCode(mEnvironment, result); } // EXCEPTION CHECK: Do nothing, already checked for exception above. mObjectHandle = null; }
public bool GetBooleanField( JniEnvironment environment, JniObject jniObject) { VerifyReturnType(JniType.Boolean); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); byte result = JniEnvironment.Functions.GetBooleanField(environment.Handle, jniObject.Handle, this.Handle); JniThrowable.CheckException(environment); return JBooleanConverter.From(result); }
public double GetDoubleField( JniEnvironment environment, JniObject jniObject) { VerifyReturnType(JniType.Double); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); double result = JniEnvironment.Functions.GetDoubleField(environment.Handle, jniObject.Handle, this.Handle); JniThrowable.CheckException(environment); return result; }
public bool CallBooleanMethod( JniEnvironment environment, JniObject jniObject, JValue[] arguments ) { VerifyReturnType(JniType.Boolean); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); // NOTE: OK if "JValue[] arguments" is null byte result = JniEnvironment.Functions.CallBooleanMethodA(environment.Handle, jniObject.Handle, this.Handle, arguments); JniThrowable.CheckException(environment); return JBooleanConverter.From(result); }
public char CallCharMethod( JniEnvironment environment, JniObject jniObject, JValue[] arguments ) { VerifyReturnType(JniType.Char); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); // NOTE: OK if "JValue[] arguments" is null char result = JniEnvironment.Functions.CallCharMethodA(environment.Handle, jniObject.Handle, this.Handle, arguments); JniThrowable.CheckException(environment); return result; }
public static JniObjectArray NewObjectArray( JniEnvironment environment, int length, JniClass jniClass, JniObject init ) { VerifyEnvironment(environment); VerifyInputJniObject(jniClass); IntPtr safeInit = (init == null) ? IntPtr.Zero : init.Handle; // OK if initial value is null IntPtr result = JniEnvironment.Functions.NewObjectArray(environment.Handle, length, jniClass.Handle, safeInit); if (IntPtr.Zero == result) { JniThrowable.ThrowCurrentException(environment); // null result means an exception occurred } // EXCEPTION CHECK: Do nothing, already checked for exception above. return new JniObjectArray(environment, result, JniObjectLifecycle.Local, -1, JniType.Null); }
internal static JniObject CreateObjectOfType(JniEnvironment environment, IntPtr handle, JniObject originalObject) { return CreateObjectOfType(environment, handle, originalObject, JniObjectLifecycle.Local); }
public string GetStringField( JniEnvironment environment, JniObject jniObject) { VerifyReturnType(JniType.String); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); IntPtr result = JniEnvironment.Functions.GetObjectField(environment.Handle, jniObject.Handle, this.Handle); JniThrowable.CheckException(environment); return JniString.ExtractAndRelease(environment, result); }
public void SetObjectArrayElement( JniEnvironment environment, int index, JniObject value ) { VerifyEnvironment(environment); // NOTE: OK if "JniObject value" is null IntPtr safeValue = ((value == null) ? IntPtr.Zero : value.Handle); JniEnvironment.Functions.SetObjectArrayElement(environment.Handle, this.Handle, index, safeValue); JniThrowable.CheckException(environment); }
internal void RemoveFromCurrentFrame(JniObject jniObject) { #if (DEBUG) CheckThreadAffinity(); #endif // DEBUG if (mFrameStack.Count > 0) { mFrameStack.Peek().Remove(jniObject); } else { // NOTE: All local Java references MUST be added to a frame, see JniLocalFrame for details. throw new JniException("TODO"); } }
public void SetBooleanField( JniEnvironment environment, JniObject jniObject, bool value ) { VerifyReturnType(JniType.Boolean); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); JniEnvironment.Functions.SetBooleanField(environment.Handle, jniObject.Handle, this.Handle, JBooleanConverter.To(value)); JniThrowable.CheckException(environment); }
public void SetShortField( JniEnvironment environment, JniObject jniObject, short value ) { VerifyReturnType(JniType.Short); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); JniEnvironment.Functions.SetShortField(environment.Handle, jniObject.Handle, this.Handle, value); JniThrowable.CheckException(environment); }
public void SetStaticObjectField( JniEnvironment environment, JniObject value ) { VerifyObjectReturnType(); VerifyEnvironment(environment); VerifyStatic(); // NOTE: OK if "JniObject value" is null IntPtr safeValue = ((value == null) ? IntPtr.Zero : value.Handle); JniEnvironment.Functions.SetStaticObjectField(environment.Handle, this.DeclaringClass.Handle, this.Handle, safeValue); JniThrowable.CheckException(environment); }
public JniObject CallObjectMethod( JniEnvironment environment, JniObject jniObject, JValue[] arguments ) { VerifyObjectReturnType(); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); // NOTE: OK if "JValue[] arguments" is null IntPtr result = JniEnvironment.Functions.CallObjectMethodA(environment.Handle, jniObject.Handle, this.Handle, arguments); JniThrowable.CheckException(environment); return JniObject.CreateReturnObject(environment, result, this); }
public void SetStringField( JniEnvironment environment, JniObject jniObject, string value ) { VerifyReturnType(JniType.String); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); // NOTE: OK if "string value" is null IntPtr safeValue = ((value == null) ? IntPtr.Zero : JniString.NewStringCore(environment, value)); try { JniEnvironment.Functions.SetObjectField(environment.Handle, jniObject.Handle, this.Handle, safeValue); JniThrowable.CheckException(environment); } finally { if (safeValue != IntPtr.Zero) { JniEnvironment.Functions.DeleteLocalRef(environment.Handle, safeValue); // EXCEPTION CHECK: Do nothing, this method safe to call while exception is pending, does // not raise additional exceptions. } } }
public bool IsSameObject(JniEnvironment environment, JniObject otherObject) { if (otherObject == null) { return false; } if (this.IsDead && otherObject.IsDead) { return true; } if ((this.IsDead && !otherObject.IsDead) || (!this.IsDead && otherObject.IsDead)) { return false; } VerifyEnvironment(environment); byte result = JniEnvironment.Functions.IsSameObject(environment.Handle, this.Handle, otherObject.Handle); JniThrowable.CheckException(environment); return JBooleanConverter.From(result); }
private static JniObject CreateObjectOfType(JniEnvironment environment, IntPtr handle, JniObject originalObject, JniObjectLifecycle lifecycle) { if (originalObject.ConcreteType == JniConcreteObjectType.ObjectArray) { JniObjectArray objectArray = originalObject as JniObjectArray; return new JniObjectArray(environment, handle, lifecycle, objectArray.ArrayRank, objectArray.ElementType); } return CreateObjectOfType(environment, handle, originalObject.ConcreteType, lifecycle); }
internal static void VerifyInputJniObject(JniObject jniObject) { if (!(jniObject != null && (jniObject.Handle != IntPtr.Zero))) { throw new JniException("TODO"); } }
public string CallStringMethod( JniEnvironment environment, JniObject jniObject, JValue[] arguments ) { VerifyReturnType(JniType.String); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); // NOTE: OK if "JValue[] arguments" is null IntPtr result = JniEnvironment.Functions.CallObjectMethodA(environment.Handle, jniObject.Handle, this.Handle, arguments); JniThrowable.CheckException(environment); return JniString.ExtractAndRelease(environment, result); }
public JniObject Pop(JniObject resultIn) { //#if (DEBUG) // Sanity check that this JniLocalFrame is not being used across threads if (!JniEnvironmentCache.CheckThreadAffinity(mEnvironment)) { throw new JniException("TODO"); } //#endif if (mPopped) { throw new JniException("Cannot pop more than once"); } mPopped = true; // TODO - fix here because we may need to clear pending exceptions // In some versions of the JNI, not safe to call PopLocalFrame // with a pending exception. // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6369169 // NOTE: OK if "JniObject result" is null IntPtr safeResult = ((resultIn == null) ? IntPtr.Zero : resultIn.Handle); IntPtr callResult = JniEnvironment.Functions.PopLocalFrame(mEnvironment.Handle, safeResult); PopInternal(resultIn); JniThrowable.CheckException(mEnvironment); JniObject resultOut = (resultIn == null) ? null : JniObject.CreateObjectOfType(mEnvironment, callResult, resultIn); GC.SuppressFinalize(this); return resultOut; }
public void CallVoidMethod( JniEnvironment environment, JniObject jniObject, JValue[] arguments ) { VerifyReturnType(JniType.Void); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); // NOTE: OK if "JValue[] arguments" is null JniEnvironment.Functions.CallVoidMethodA(environment.Handle, jniObject.Handle, this.Handle, arguments); JniThrowable.CheckException(environment); }
internal void Add(JniObject jniObject) { if (mTrackedObjects.Count >= (mCapacity + CAPACITY_FUDGE)) { throw new JniException("TODO"); } mTrackedObjects.AddLast(jniObject); }
public JniThreadMonitor CreateThreadMonitor(JniObject objectHandle) { return new JniThreadMonitor(this, objectHandle); }
internal void Remove(JniObject jniObject) { mTrackedObjects.Remove(jniObject); }
public void AssignObjectValue(JniObject value) { this.l = (value == null) ? IntPtr.Zero : value.Handle; }
private void PopInternal(JniObject resultIn) { mEnvironment.PopFrame(this); if (resultIn != null) { mTrackedObjects.Remove(resultIn); mEnvironment.AddToCurrentFrame(resultIn); } foreach (JniObject tracked in mTrackedObjects) { tracked.PopRelease(); } mTrackedObjects.Clear(); }
public JavaVMThreadAttachArguments(string name, JniObject groupHandle) { mName = name; mGroupHandle = groupHandle; }
public JniObject GetObjectField( JniEnvironment environment, JniObject jniObject) { VerifyObjectReturnType(); VerifyEnvironment(environment); VerifyNotStatic(); VerifyInputJniObject(jniObject); IntPtr result = JniEnvironment.Functions.GetObjectField(environment.Handle, jniObject.Handle, this.Handle); JniThrowable.CheckException(environment); return JniObject.CreateReturnObject(environment, result, this); }