Example #1
0
 internal JniThreadMonitor(JniEnvironment env, JniObject objectHandle)
 {
     JniObject.VerifyInputJniObject(objectHandle);
     mEnvironment = env;
     mObjectHandle = objectHandle;
     Enter();
 }
Example #2
0
 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;
 }
Example #3
0
 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;
 }
Example #4
0
 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);
 }
Example #5
0
 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;
 }
Example #6
0
 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);
 }
Example #7
0
 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;
 }
Example #8
0
 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);
 }
Example #9
0
 internal static JniObject CreateObjectOfType(JniEnvironment environment, IntPtr handle,
     JniObject originalObject)
 {
     return CreateObjectOfType(environment, handle, originalObject, JniObjectLifecycle.Local);
 }
Example #10
0
 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);
 }
Example #11
0
 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);
 }
Example #12
0
 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");
     }
 }
Example #13
0
 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);
 }
Example #14
0
 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);
 }
Example #15
0
 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);
 }
Example #16
0
 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);
 }
Example #17
0
 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.
         }
     }
 }
Example #18
0
 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);
 }
Example #19
0
 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);
 }
Example #20
0
 internal static void VerifyInputJniObject(JniObject jniObject)
 {
     if (!(jniObject != null && (jniObject.Handle != IntPtr.Zero)))
     {
         throw new JniException("TODO");
     }
 }
Example #21
0
 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);
 }
Example #22
0
        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;
        }
Example #23
0
 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);
 }
Example #24
0
 internal void Add(JniObject jniObject)
 {
     if (mTrackedObjects.Count >= (mCapacity + CAPACITY_FUDGE))
     {
         throw new JniException("TODO");
     }
     mTrackedObjects.AddLast(jniObject);
 }
Example #25
0
 public JniThreadMonitor CreateThreadMonitor(JniObject objectHandle)
 {
     return new JniThreadMonitor(this, objectHandle);
 }
Example #26
0
 internal void Remove(JniObject jniObject)
 {
     mTrackedObjects.Remove(jniObject);
 }
Example #27
0
 public void AssignObjectValue(JniObject value)
 {
     this.l = (value == null) ? IntPtr.Zero : value.Handle;
 }
Example #28
0
 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();
 }
Example #29
0
 public JavaVMThreadAttachArguments(string name, JniObject groupHandle)
 {
     mName = name;
     mGroupHandle = groupHandle;
 }
Example #30
0
 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);
 }