Exemple #1
0
 internal JniThreadMonitor(JniEnvironment env, JniObject objectHandle)
 {
     JniObject.VerifyInputJniObject(objectHandle);
     mEnvironment = env;
     mObjectHandle = objectHandle;
     Enter();
 }
Exemple #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;
 }
Exemple #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;
 }
Exemple #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);
 }
Exemple #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;
 }
Exemple #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);
 }
Exemple #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;
 }
Exemple #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);
 }
Exemple #9
0
 internal static JniObject CreateObjectOfType(JniEnvironment environment, IntPtr handle,
     JniObject originalObject)
 {
     return CreateObjectOfType(environment, handle, originalObject, JniObjectLifecycle.Local);
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #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");
     }
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #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.
         }
     }
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #20
0
 internal static void VerifyInputJniObject(JniObject jniObject)
 {
     if (!(jniObject != null && (jniObject.Handle != IntPtr.Zero)))
     {
         throw new JniException("TODO");
     }
 }
Exemple #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);
 }
Exemple #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;
        }
Exemple #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);
 }
Exemple #24
0
 internal void Add(JniObject jniObject)
 {
     if (mTrackedObjects.Count >= (mCapacity + CAPACITY_FUDGE))
     {
         throw new JniException("TODO");
     }
     mTrackedObjects.AddLast(jniObject);
 }
Exemple #25
0
 public JniThreadMonitor CreateThreadMonitor(JniObject objectHandle)
 {
     return new JniThreadMonitor(this, objectHandle);
 }
Exemple #26
0
 internal void Remove(JniObject jniObject)
 {
     mTrackedObjects.Remove(jniObject);
 }
Exemple #27
0
 public void AssignObjectValue(JniObject value)
 {
     this.l = (value == null) ? IntPtr.Zero : value.Handle;
 }
Exemple #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();
 }
Exemple #29
0
 public JavaVMThreadAttachArguments(string name, JniObject groupHandle)
 {
     mName = name;
     mGroupHandle = groupHandle;
 }
Exemple #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);
 }