public unsafe short GetHttpStatus() { if (id_getHttpStatus == IntPtr.Zero) { id_getHttpStatus = JNIEnv.GetMethodID(class_ref, "getHttpStatus", "()S"); } return(JNIEnv.CallShortMethod(((global::Java.Lang.Object) this).Handle, id_getHttpStatus)); }
public unsafe short ReadShort() { if (id_readShort == IntPtr.Zero) { id_readShort = JNIEnv.GetMethodID(class_ref, "readShort", "()S"); } try { return(JNIEnv.CallShortMethod(((global::Java.Lang.Object) this).Handle, id_readShort)); } finally { } }
public virtual unsafe short GetbPictureCount() { if (id_getbPictureCount == IntPtr.Zero) { id_getbPictureCount = JNIEnv.GetMethodID(class_ref, "getbPictureCount", "()S"); } try { if (GetType() == ThresholdType) { return(JNIEnv.CallShortMethod(((global::Java.Lang.Object) this).Handle, id_getbPictureCount)); } else { return(JNIEnv.CallNonvirtualShortMethod(((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "getbPictureCount", "()S"))); } } finally { } }
public virtual unsafe short GetInt16(int p0) { if (id_getInt16_I == IntPtr.Zero) { id_getInt16_I = JNIEnv.GetMethodID(class_ref, "getInt16", "(I)S"); } try { JValue *__args = stackalloc JValue [1]; __args [0] = new JValue(p0); if (GetType() == ThresholdType) { return(JNIEnv.CallShortMethod(Handle, id_getInt16_I, __args)); } else { return(JNIEnv.CallNonvirtualShortMethod(Handle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "getInt16", "(I)S"), __args)); } } finally { } }
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); }
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()); } }
/// <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()); } }