void initMethods(JNIEnv* env) { //InitProtection(); if (!gAddressMethod) { gObjectClass = FIND_GLOBAL_CLASS("java/lang/Object"); gRunnableClass = FIND_GLOBAL_CLASS("java/lang/Runnable"); #define INIT_PRIM(prim, shortName, methShort, type, letter) \ g ## shortName ## Class = FIND_GLOBAL_CLASS(prim); \ g ## shortName ## ValueMethod = (*env)->GetMethodID(env, g ## shortName ## Class, #type "Value", "()" letter); \ g ## shortName ## ValueOfMethod = (*env)->GetStaticMethodID(env, g ## shortName ## Class, "valueOf", "(" letter ")L" prim ";"); INIT_PRIM("org/bridj/SizeT", SizeT, Long, long, "J"); INIT_PRIM("org/bridj/TimeT", TimeT, Long, long, "J"); INIT_PRIM("org/bridj/CLong", CLong, Long, long, "J"); INIT_PRIM("java/lang/Integer", Int, Int, int, "I"); INIT_PRIM("java/lang/Long", Long, Long, long, "J"); INIT_PRIM("java/lang/Short", Short, Short, short, "S"); INIT_PRIM("java/lang/Byte", Byte, Byte, byte, "B"); INIT_PRIM("java/lang/Boolean", Boolean, Boolean, boolean, "Z"); INIT_PRIM("java/lang/Character", Char, Char, char, "C"); INIT_PRIM("java/lang/Float", Float, Float, float, "F"); INIT_PRIM("java/lang/Double", Double, Double, double, "D"); gBridJClass = FIND_GLOBAL_CLASS("org/bridj/BridJ"); //gFlagSetClass = FIND_GLOBAL_CLASS("org/bridj/FlagSet"); gValuedEnumClass = FIND_GLOBAL_CLASS("org/bridj/ValuedEnum"); //gStructFieldsIOClass = FIND_GLOBAL_CLASS("org/bridj/StructFieldsIO"); gPointerClass = FIND_GLOBAL_CLASS("org/bridj/Pointer"); gMethodCallInfoClass = FIND_GLOBAL_CLASS("org/bridj/MethodCallInfo"); gCallIOClass = FIND_GLOBAL_CLASS("org/bridj/CallIO"); gLastErrorClass = FIND_GLOBAL_CLASS("org/bridj/LastError"); gRunnableRunMethod = (*env)->GetMethodID(env, gRunnableClass, "run", "()V"); //gGetTempCallStruct = (*env)->GetStaticMethodID(env, gBridJClass, "getTempCallStruct", "()J"); //gReleaseTempCallStruct = (*env)->GetStaticMethodID(env, gBridJClass, "releaseTempCallStruct", "(J)V"); gGetValuedEnumValueMethod = (*env)->GetMethodID(env, gValuedEnumClass, "value", "()J"); gGetJavaObjectFromNativePeerMethod = (*env)->GetStaticMethodID(env, gBridJClass, "getJavaObjectFromNativePeer", "(J)" OBJECT_SIG); //gNewFlagSetMethod = (*env)->GetStaticMethodID(env, gFlagSetClass, "fromValue", "(J" CLASS_SIG ")Lorg/bridj/FlagSet;"); gAddressMethod = (*env)->GetStaticMethodID(env, gPointerClass, "getAddress", "(Lorg/bridj/NativeObject;" CLASS_SIG ")J"); gGetPeerMethod = (*env)->GetMethodID(env, gPointerClass, "getPeer", "()J"); gCreatePeerMethod = (*env)->GetStaticMethodID(env, gPointerClass, "pointerToAddress", "(JLjava/lang/Class;)" POINTER_SIG); gThrowNewLastErrorMethod = (*env)->GetStaticMethodID(env, gLastErrorClass, "throwNewInstance", "(I" STRING_SIG ")V"); gGetCallIOsMethod = (*env)->GetMethodID(env, gMethodCallInfoClass, "getCallIOs", "()[Lorg/bridj/CallIO;"); gNewCallIOInstance = (*env)->GetMethodID(env, gCallIOClass, "newInstance", "(J)" OBJECT_SIG); gLogCallMethod = (*env)->GetStaticMethodID(env, gBridJClass, "logCall", "(" METHOD_SIG ")V"); gLogCallsField = (*env)->GetStaticFieldID(env, gBridJClass, "logCalls", "Z"); gProtectedModeField = (*env)->GetStaticFieldID(env, gBridJClass, "protectedMode", "Z"); #ifdef __GNUC__ gSignalErrorClass = FIND_GLOBAL_CLASS("org/bridj/SignalError"); gSignalErrorThrowMethod = (*env)->GetStaticMethodID(env, gSignalErrorClass, "throwNew", "(IIJ)V"); #else gWindowsErrorClass = FIND_GLOBAL_CLASS("org/bridj/WindowsError"); gWindowsErrorThrowMethod = (*env)->GetStaticMethodID(env, gWindowsErrorClass, "throwNew", "(IJJ)V"); #endif #define GETFIELD_ID(out, name, sig) \ if (!(gFieldId_ ## out = (*env)->GetFieldID(env, gMethodCallInfoClass, name, sig))) \ throwException(env, "Failed to get the field " #name " in MethodCallInfo !"); GETFIELD_ID(javaSignature , "javaSignature" , STRING_SIG ); GETFIELD_ID(dcSignature , "dcSignature" , STRING_SIG ); GETFIELD_ID(symbolName , "symbolName" , STRING_SIG ); GETFIELD_ID(nativeClass , "nativeClass" , "J" ); GETFIELD_ID(methodName , "methodName" , STRING_SIG ); GETFIELD_ID(method , "method" , METHOD_SIG ); GETFIELD_ID(declaringClass , "declaringClass" , CLASS_SIG ); GETFIELD_ID(paramsValueTypes , "paramsValueTypes" , "[I" ); GETFIELD_ID(returnValueType , "returnValueType" , "I" ); GETFIELD_ID(forwardedPointer , "forwardedPointer" , "J" ); GETFIELD_ID(virtualIndex , "virtualIndex" , "I" ); GETFIELD_ID(virtualTableOffset , "virtualTableOffset" , "I" ); //GETFIELD_ID(javaCallback , "javaCallback" , "Lorg/bridj/Callback;" ); GETFIELD_ID(javaCallback , "javaCallback" , OBJECT_SIG ); GETFIELD_ID(isGenericCallback , "isGenericCallback" , "Z" ); GETFIELD_ID(isObjCBlock , "isObjCBlock" , "Z" ); GETFIELD_ID(direct , "direct" , "Z" ); GETFIELD_ID(isCPlusPlus , "isCPlusPlus" , "Z" ); GETFIELD_ID(isStatic , "isStatic" , "Z" ); GETFIELD_ID(startsWithThis , "startsWithThis" , "Z" ); GETFIELD_ID(bNeedsThisPointer , "bNeedsThisPointer" , "Z" ); GETFIELD_ID(bThrowLastError , "bThrowLastError" , "Z" ); GETFIELD_ID(dcCallingConvention, "dcCallingConvention" , "I" ); gLog = (*env)->GetStaticBooleanField(env, gBridJClass, gLogCallsField); gProtected = (*env)->GetStaticBooleanField(env, gBridJClass, gProtectedModeField); initPlatformMethods(env); }
void initMethods(JNIEnv* env) { //InitProtection(); if (!gAddressMethod) { #define FIND_GLOBAL_CLASS(name) (*env)->NewGlobalRef(env, (*env)->FindClass(env, name)) gObjectClass = FIND_GLOBAL_CLASS("java/lang/Object"); #define INIT_PRIM(prim, shortName, methShort, type, letter) \ g ## shortName ## Class = FIND_GLOBAL_CLASS(prim); \ g ## shortName ## ValueMethod = (*env)->GetMethodID(env, g ## shortName ## Class, #type "Value", "()" letter); \ g ## shortName ## ValueOfMethod = (*env)->GetStaticMethodID(env, g ## shortName ## Class, "valueOf", "(" letter ")L" prim ";"); INIT_PRIM("org/bridj/SizeT", SizeT, Long, long, "J"); INIT_PRIM("org/bridj/CLong", CLong, Long, long, "J"); INIT_PRIM("java/lang/Integer", Int, Int, int, "I"); INIT_PRIM("java/lang/Long", Long, Long, long, "J"); INIT_PRIM("java/lang/Short", Short, Short, short, "S"); INIT_PRIM("java/lang/Byte", Byte, Byte, byte, "B"); INIT_PRIM("java/lang/Boolean", Boolean, Boolean, boolean, "Z"); INIT_PRIM("java/lang/Character", Char, Char, char, "C"); INIT_PRIM("java/lang/Float", Float, Float, float, "F"); INIT_PRIM("java/lang/Double", Double, Double, double, "D"); gBridJClass = FIND_GLOBAL_CLASS("org/bridj/BridJ"); gFlagSetClass = FIND_GLOBAL_CLASS("org/bridj/FlagSet"); gValuedEnumClass = FIND_GLOBAL_CLASS("org/bridj/ValuedEnum"); //gStructFieldsIOClass = FIND_GLOBAL_CLASS("org/bridj/StructFieldsIO"); gPointerClass = FIND_GLOBAL_CLASS("org/bridj/Pointer"); gMethodCallInfoClass = FIND_GLOBAL_CLASS("org/bridj/MethodCallInfo"); gCallIOClass = FIND_GLOBAL_CLASS("org/bridj/CallIO"); gLastErrorClass = FIND_GLOBAL_CLASS("org/bridj/LastError"); //gGetTempCallStruct = (*env)->GetStaticMethodID(env, gBridJClass, "getTempCallStruct", "()J"); //gReleaseTempCallStruct = (*env)->GetStaticMethodID(env, gBridJClass, "releaseTempCallStruct", "(J)V"); gGetValuedEnumValueMethod = (*env)->GetMethodID(env, gValuedEnumClass, "value", "()J"); gGetJavaObjectFromNativePeerMethod = (*env)->GetStaticMethodID(env, gBridJClass, "getJavaObjectFromNativePeer", "(J)Ljava/lang/Object;"); gNewFlagSetMethod = (*env)->GetStaticMethodID(env, gFlagSetClass, "fromValue", "(JLjava/lang/Class;)Lorg/bridj/FlagSet;"); gAddressMethod = (*env)->GetStaticMethodID(env, gPointerClass, "getAddress", "(Lorg/bridj/NativeObject;Ljava/lang/Class;)J"); gGetPeerMethod = (*env)->GetMethodID(env, gPointerClass, "getPeer", "()J"); gCreatePeerMethod = (*env)->GetStaticMethodID(env, gPointerClass, "pointerToAddress", "(JLjava/lang/Class;)Lorg/bridj/Pointer;"); gThrowNewLastErrorMethod = (*env)->GetStaticMethodID(env, gLastErrorClass, "throwNewInstance", "(ILjava/lang/String;)V"); gGetCallIOsMethod = (*env)->GetMethodID(env, gMethodCallInfoClass, "getCallIOs", "()[Lorg/bridj/CallIO;"); gNewCallIOInstance = (*env)->GetMethodID(env, gCallIOClass, "newInstance", "(J)Ljava/lang/Object;"); #define GETFIELD_ID(out, name, sig) \ if (!(gFieldId_ ## out = (*env)->GetFieldID(env, gMethodCallInfoClass, name, sig))) \ throwException(env, "Failed to get the field " #name " in MethodCallInfo !"); GETFIELD_ID(javaSignature , "javaSignature" , "Ljava/lang/String;" ); GETFIELD_ID(dcSignature , "dcSignature" , "Ljava/lang/String;" ); GETFIELD_ID(symbolName , "symbolName" , "Ljava/lang/String;" ); GETFIELD_ID(nativeClass , "nativeClass" , "J" ); GETFIELD_ID(methodName , "methodName" , "Ljava/lang/String;" ); GETFIELD_ID(declaringClass , "declaringClass" , "Ljava/lang/Class;" ); GETFIELD_ID(paramsValueTypes , "paramsValueTypes" , "[I" ); GETFIELD_ID(returnValueType , "returnValueType" , "I" ); GETFIELD_ID(forwardedPointer , "forwardedPointer" , "J" ); GETFIELD_ID(virtualIndex , "virtualIndex" , "I" ); GETFIELD_ID(virtualTableOffset , "virtualTableOffset" , "I" ); //GETFIELD_ID(javaCallback , "javaCallback" , "Lorg/bridj/Callback;" ); GETFIELD_ID(javaCallback , "javaCallback" , "Ljava/lang/Object;" ); GETFIELD_ID(isGenericCallback , "isGenericCallback" , "Z" ); GETFIELD_ID(direct , "direct" , "Z" ); GETFIELD_ID(isCPlusPlus , "isCPlusPlus" , "Z" ); GETFIELD_ID(isStatic , "isStatic" , "Z" ); GETFIELD_ID(startsWithThis , "startsWithThis" , "Z" ); GETFIELD_ID(bNeedsThisPointer , "bNeedsThisPointer" , "Z" ); GETFIELD_ID(bThrowLastError , "bThrowLastError" , "Z" ); GETFIELD_ID(dcCallingConvention, "dcCallingConvention" , "I" ); }