Exemple #1
0
 public sbyte ReadRawByte()
 {
     if (id_readRawByte == IntPtr.Zero)
     {
         id_readRawByte = JNIEnv.GetMethodID(class_ref, "readRawByte", "()B");
     }
     return(JNIEnv.CallByteMethod(Handle, id_readRawByte));
 }
 public unsafe sbyte Invoke櫯()
 {
     if (id_櫯 == IntPtr.Zero)
     {
         id_櫯 = JNIEnv.GetMethodID(class_ref, "櫯", "()B");
     }
     try {
         return(JNIEnv.CallByteMethod(Handle, id_櫯));
     } finally {
     }
 }
Exemple #3
0
        public virtual sbyte GetCommandLength(int p0)
        {
            if (id_getCommandLength_I == IntPtr.Zero)
            {
                id_getCommandLength_I = JNIEnv.GetMethodID(class_ref, "getCommandLength", "(I)B");
            }

            if (GetType() == ThresholdType)
            {
                return(JNIEnv.CallByteMethod(Handle, id_getCommandLength_I, new JValue(p0)));
            }
            else
            {
                return(JNIEnv.CallNonvirtualByteMethod(Handle, ThresholdClass, id_getCommandLength_I, new JValue(p0)));
            }
        }
Exemple #4
0
 public virtual unsafe sbyte ToByte()
 {
     if (id_toByte == IntPtr.Zero)
     {
         id_toByte = JNIEnv.GetMethodID(class_ref, "toByte", "()B");
     }
     try {
         if (((object)this).GetType() == ThresholdType)
         {
             return(JNIEnv.CallByteMethod(((global::Java.Lang.Object) this).Handle, id_toByte));
         }
         else
         {
             return(JNIEnv.CallNonvirtualByteMethod(((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "toByte", "()B")));
         }
     } finally {
     }
 }
        public virtual unsafe sbyte GetByte(int key)
        {
            if (id_getByte_I == IntPtr.Zero)
            {
                id_getByte_I = JNIEnv.GetMethodID(class_ref, "getByte", "(I)B");
            }
            try {
                JValue *__args = stackalloc JValue [1];
                __args [0] = new JValue(key);

                if (((object)this).GetType() == ThresholdType)
                {
                    return(JNIEnv.CallByteMethod(((global::Java.Lang.Object) this).Handle, id_getByte_I, __args));
                }
                else
                {
                    return(JNIEnv.CallNonvirtualByteMethod(((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "getByte", "(I)B"), __args));
                }
            } finally {
            }
        }
        public virtual unsafe sbyte GetByte(int p0)
        {
            if (id_getByte_I == IntPtr.Zero)
            {
                id_getByte_I = JNIEnv.GetMethodID(class_ref, "getByte", "(I)B");
            }
            try {
                JValue *__args = stackalloc JValue [1];
                __args [0] = new JValue(p0);

                if (GetType() == ThresholdType)
                {
                    return(JNIEnv.CallByteMethod(Handle, id_getByte_I, __args));
                }
                else
                {
                    return(JNIEnv.CallNonvirtualByteMethod(Handle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "getByte", "(I)B"), __args));
                }
            } finally {
            }
        }
Exemple #7
0
 private static object PrimJ2C(JniLocalHandle obj, JNIEnv env, Type type)
 {
     if (type == typeof(bool))
     {
         return(env.CallBooleanMethod(obj, boolValue));
     }
     if (type == typeof(char))
     {
         return(env.CallCharMethod(obj, charValue));
     }
     if (type == typeof(byte))
     {
         return(env.CallByteMethod(obj, byteValue));
     }
     if (type == typeof(short))
     {
         return(env.CallShortMethod(obj, shortValue));
     }
     if (type == typeof(int))
     {
         return(env.CallIntMethod(obj, intValue));
     }
     if (type == typeof(long))
     {
         return(env.CallLongMethod(obj, longValue));
     }
     if (type == typeof(double))
     {
         return(env.CallDoubleMethod(obj, doubleValue));
     }
     if (type == typeof(float))
     {
         return(env.CallFloatMethod(obj, floatValue));
     }
     throw new InvalidProgramException("Unnknown primitive type" + type);
 }
Exemple #8
0
        public T CallMethod <T>(string methodName, string sig, List <object> param)
        {
            IntPtr methodId = env.GetMethodId(javaClass, methodName, sig);

            try
            {
                if (typeof(T) == typeof(byte))
                {
                    // Call the byte method
                    byte res = env.CallByteMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(bool))
                {
                    // Call the boolean method
                    bool res = env.CallBooleanMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                if (typeof(T) == typeof(char))
                {
                    // Call the char method
                    char res = env.CallCharMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(short))
                {
                    // Call the short method
                    short res = env.CallShortMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(int))
                {
                    // Call the int method
                    int res = env.CallIntMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(long))
                {
                    // Call the long method
                    long res = env.CallLongMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(float))
                {
                    // Call the float method
                    float res = env.CallFloatMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(double))
                {
                    // Call the double method
                    double res = env.CallDoubleMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);  // need to fix this
                }
                else if (typeof(T) == typeof(string))
                {
                    // Call the string method
                    IntPtr jstr = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));

                    string res = env.JStringToString(jstr);
                    env.DeleteLocalRef(jstr);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(byte[]))
                {
                    // Call the string method
                    IntPtr jstr = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    if (jstr.ToInt32() == 0)
                    {
                        return(default(T));
                    }
                    byte[] res = env.JStringToByte(jstr);
                    env.DeleteLocalRef(jstr);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(object))
                {
                    // Call the object method and deal with whatever comes back in the call code
                    IntPtr res = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                return(default(T));
            }
            catch
            {
                throw new Exception(env.CatchJavaException());
            }
        }
Exemple #9
0
        /// <summary>
        /// Java object method callers
        /// </summary>
        /// <typeparam name="T">expect return type</typeparam>
        /// <param name="javaClass">Java class pointer</param>
        /// <param name="javaObject">Java Object pointer</param>
        /// <param name="methodName">Name of the method to call</param>
        /// <param name="sig">Method's JNI signature</param>
        /// <param name="param">Paramters of the method call</param>
        /// <returns></returns>
        public T CallMethod <T>(IntPtr javaClass, IntPtr javaObject, string methodName, string sig, params object[] param)
        {
            IntPtr methodId = env.GetMethodID(javaClass, methodName, sig);

            try {
                if (typeof(T) == typeof(byte))
                {
                    // Call the byte method
                    byte res = env.CallByteMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(bool))
                {
                    // Call the boolean method
                    bool res = env.CallBooleanMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                if (typeof(T) == typeof(char))
                {
                    // Call the char method
                    char res = env.CallCharMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(short))
                {
                    // Call the short method
                    short res = env.CallShortMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(int))
                {
                    // Call the int method
                    int res = env.CallIntMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(long))
                {
                    // Call the long method
                    long res = env.CallLongMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(float))
                {
                    // Call the float method
                    float res = env.CallFloatMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(double))
                {
                    // Call the double method
                    double res = env.CallDoubleMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res); // need to fix this
                }
                else if (typeof(T) == typeof(string))
                {
                    // Call the string method
                    IntPtr jstr = env.CallObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));

                    string res = env.JStringToString(jstr);
                    env.DeleteLocalRef(jstr);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(byte[]))
                {
                    // Call the byte method
                    IntPtr jobj = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }
                    byte[] res = env.JStringToByte(jobj);
                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(string[]))
                {
                    // Call the string array method
                    IntPtr jobj = env.CallObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }

                    IntPtr[] objArray = env.GetObjectArray(jobj);
                    string[] res      = new string[objArray.Length];

                    for (int i = 0; i < objArray.Length; i++)
                    {
                        res[i] = env.JStringToString(objArray[i]);
                    }

                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(int[]))
                {
                    // Call the int array method
                    IntPtr jobj = env.CallObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }
                    int[] res = env.GetIntArray(jobj);
                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(IntPtr))
                {
                    // Call the object method and deal with whatever comes back in the call code
                    IntPtr res = env.CallObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                return(default(T));
            } catch {
                throw new Exception(env.CatchJavaException());
            }
        }