📄 kni.h
字号:
KNIEXPORT jboolean KNI_GetStaticBooleanField(jclass classHandle, jfieldID fieldID);
KNIEXPORT jbyte KNI_GetStaticByteField(jclass classHandle, jfieldID fieldID);
KNIEXPORT jchar KNI_GetStaticCharField(jclass classHandle, jfieldID fieldID);
KNIEXPORT jshort KNI_GetStaticShortField(jclass classHandle, jfieldID fieldID);
KNIEXPORT jint KNI_GetStaticIntField(jclass classHandle, jfieldID fieldID);
KNIEXPORT jlong KNI_GetStaticLongField(jclass classHandle, jfieldID fieldID);
KNIEXPORT jfloat KNI_GetStaticFloatField(jclass classHandle, jfieldID fieldID);
KNIEXPORT jdouble KNI_GetStaticDoubleField(jclass classHandle, jfieldID fieldID);
KNIEXPORT void KNI_GetStaticObjectField(jclass classHandle, jfieldID fieldID, jobject toHandle);
KNIEXPORT void KNI_SetStaticBooleanField(jclass classHandle, jfieldID fieldID, jboolean value);
KNIEXPORT void KNI_SetStaticByteField(jclass classHandle, jfieldID fieldID, jbyte value);
KNIEXPORT void KNI_SetStaticCharField(jclass classHandle, jfieldID fieldID, jchar value);
KNIEXPORT void KNI_SetStaticShortField(jclass classHandle, jfieldID fieldID, jshort value);
KNIEXPORT void KNI_SetStaticIntField(jclass classHandle, jfieldID fieldID, jint value);
KNIEXPORT void KNI_SetStaticLongField(jclass classHandle, jfieldID fieldID, jlong value);
KNIEXPORT void KNI_SetStaticFloatField(jclass classHandle, jfieldID fieldID, jfloat value);
KNIEXPORT void KNI_SetStaticDoubleField(jclass classHandle, jfieldID fieldID, jdouble value);
KNIEXPORT void KNI_SetStaticObjectField(jclass classHandle, jfieldID fieldID, jobject fromHandle);
/* String operations */
KNIEXPORT jsize KNI_GetStringLength(jstring stringHandle);
KNIEXPORT void KNI_GetStringRegion(jstring stringHandle, jsize offset, jsize n, jchar* jcharbuf);
KNIEXPORT void KNI_NewString(const jchar* uchars, jsize length, jstring stringHandle);
KNIEXPORT void KNI_NewStringUTF(const char* utf8chars, jstring stringHandle);
/* Array operations */
KNIEXPORT jsize KNI_GetArrayLength(jarray arrayHandle);
KNIEXPORT jboolean KNI_GetBooleanArrayElement(jbooleanArray arrayHandle, jint index);
KNIEXPORT jbyte KNI_GetByteArrayElement(jbyteArray arrayHandle, jint index);
KNIEXPORT jchar KNI_GetCharArrayElement(jcharArray arrayHandle, jint index);
KNIEXPORT jshort KNI_GetShortArrayElement(jshortArray arrayHandle, jint index);
KNIEXPORT jint KNI_GetIntArrayElement(jintArray arrayHandle, jint index);
KNIEXPORT jfloat KNI_GetFloatArrayElement(jfloatArray arrayHandle, jint index);
KNIEXPORT jlong KNI_GetLongArrayElement(jlongArray arrayHandle, jint index);
KNIEXPORT jdouble KNI_GetDoubleArrayElement(jdoubleArray arrayHandle, jint index);
KNIEXPORT void KNI_GetObjectArrayElement(jobjectArray arrayHandle, jint index, jobject toHandle);
KNIEXPORT void KNI_SetBooleanArrayElement(jbooleanArray arrayHandle, jint index, jboolean value);
KNIEXPORT void KNI_SetByteArrayElement(jbyteArray arrayHandle, jint index, jbyte value);
KNIEXPORT void KNI_SetCharArrayElement(jcharArray arrayHandle, jint index, jchar value);
KNIEXPORT void KNI_SetShortArrayElement(jshortArray arrayHandle, jint index, jshort value);
KNIEXPORT void KNI_SetIntArrayElement(jintArray arrayHandle, jint index, jint value);
KNIEXPORT void KNI_SetFloatArrayElement(jfloatArray arrayHandle, jint index, jfloat value);
KNIEXPORT void KNI_SetLongArrayElement(jlongArray arrayHandle, jint index, jlong value);
KNIEXPORT void KNI_SetDoubleArrayElement(jdoubleArray arrayHandle, jint index, jdouble value);
KNIEXPORT void KNI_SetObjectArrayElement(jobjectArray arrayHandle, jint index, jobject fromHandle);
KNIEXPORT void KNI_GetRawArrayRegion(jarray arrayHandle, jsize offset, jsize n, jbyte* dstBuffer);
KNIEXPORT void KNI_SetRawArrayRegion(jarray arrayHandle, jsize offset, jsize n, const jbyte* srcBuffer);
/* Parameter access */
KNIEXPORT jboolean KNI_GetParameterAsBoolean(jint index);
KNIEXPORT jbyte KNI_GetParameterAsByte(jint index);
KNIEXPORT jchar KNI_GetParameterAsChar(jint index);
KNIEXPORT jshort KNI_GetParameterAsShort(jint index);
KNIEXPORT jint KNI_GetParameterAsInt(jint index);
KNIEXPORT jfloat KNI_GetParameterAsFloat(jint index);
KNIEXPORT jlong KNI_GetParameterAsLong(jint index);
KNIEXPORT jdouble KNI_GetParameterAsDouble(jint index);
KNIEXPORT void KNI_GetParameterAsObject(jint index, jobject toHandle);
KNIEXPORT void KNI_GetThisPointer(jobject toHandle);
KNIEXPORT void KNI_GetClassPointer(jclass toHandle);
#ifdef CLDCHI
extern unsigned char * _kni_parameter_base;
KNIEXPORT jboolean KNI_IsSameObject(jobject obj1, jobject obj2);
#define KNI_ReturnVoid() return
#define KNI_ReturnBoolean(value) return ((jint)((value) ? 1 : 0))
#define KNI_ReturnByte(value) return ((jint)((jbyte)(value)))
#define KNI_ReturnChar(value) return ((jint)((jchar)(value)))
#define KNI_ReturnShort(value) return ((jint)((jshort)(value)))
#define KNI_ReturnInt(value) return ((jint)(value))
#define KNI_ReturnFloat(value) return ((jfloat)(value))
#define KNI_ReturnLong(value) return ((jlong)(value))
#define KNI_ReturnDouble(value) return ((jdouble)(value))
#define KNI_registerCleanup(jobject, KNICleanupCallback)
typedef struct __KNI_HandleInfo {
struct __KNI_HandleInfo *prev; /* A _KNI_HandleInfo that nests
* this one. */
int total_count; /* Number of total handles */
int declared_count; /* Number of handles that has been
* declared using KNI_DeclareHandle() */
jobject *handles; /* Points to __handles__ in this scope */
} _KNI_HandleInfo;
/*
* Internal functions, do not use directly.
*/
KNIEXPORT int _KNI_push_handles(int, _KNI_HandleInfo*, jobject*);
KNIEXPORT void _KNI_pop_handles(_KNI_HandleInfo*);
/**
* Handle operations
*/
#define KNI_StartHandles(n) \
{ \
_KNI_HandleInfo __handle_info__; \
jobject __handles__[n]; \
int __dummy__ = _KNI_push_handles(n, &__handle_info__, __handles__)
#define KNI_DeclareHandle(x) \
jobject x = (jobject)&__handles__[__handle_info__.declared_count++]
#define KNI_IsNullHandle(x) \
(*(jobject*)x == 0)
#define KNI_ReleaseHandle(x) \
*(jobject*)x = 0
#ifdef CLDCHI
#define KNI_EndHandles() \
(void)_KNI_pop_handles(&__handle_info__); \
ASSERT(__handle_info__.declared_count<=__handle_info__.total_count);\
(void)__dummy__; \
}
#else
#define KNI_EndHandles() \
(void)_KNI_pop_handles(&__handle_info__); \
(void)__dummy__; \
}
#endif
#define KNI_EndHandlesAndReturnObject(x) \
(void)_KNI_pop_handles(&__handle_info__); \
(void)__dummy__; \
return *(jobject*)x; \
}
#ifdef __ARMCC_VERSION
/*
* For ADS, we need to declare __softfp for all floating point Java
* native methods, as well as all C floating point routines (such as
* jvm_fadd) that are called directly from the interpreter, which
* always uses integer registers for passing parameters and return
* values.
*/
#define JVM_SOFTFP_LINKAGE __softfp
#else
/*
* Change this if your C/C++ compiler uses a special keyword to indicate
* floating point linkage.
*/
#define JVM_SOFTFP_LINKAGE
#endif
/**
* Type macros
*/
#define KNI_RETURNTYPE_VOID void
#define KNI_RETURNTYPE_BOOLEAN jint
#define KNI_RETURNTYPE_BYTE jint
#define KNI_RETURNTYPE_CHAR jint
#define KNI_RETURNTYPE_SHORT jint
#define KNI_RETURNTYPE_INT jint
#define KNI_RETURNTYPE_FLOAT JVM_SOFTFP_LINKAGE jfloat
#define KNI_RETURNTYPE_LONG jlong
#define KNI_RETURNTYPE_DOUBLE JVM_SOFTFP_LINKAGE jdouble
#define KNI_RETURNTYPE_OBJECT jobject
#else /* !CLDCHI */
#define KNI_ReturnVoid() \
{ \
if (CurrentNativeMethod != NULL) { \
kvm_resetOperandStack(); \
} \
return; \
}
#define KNI_ReturnBoolean(value) \
{ \
kvm_resetOperandStack(); \
pushStack((value)); \
return; \
}
#define KNI_ReturnByte(value) \
{ \
kvm_resetOperandStack(); \
pushStack((value)); \
return; \
}
#define KNI_ReturnChar(value) \
{ \
kvm_resetOperandStack(); \
pushStack((value)); \
return; \
}
#define KNI_ReturnShort(value) \
{ \
kvm_resetOperandStack(); \
pushStack((value)); \
return; \
}
#define KNI_ReturnInt(value) \
{ \
kvm_resetOperandStack(); \
pushStack((value)); \
return; \
}
#define KNI_ReturnLong(value) \
{ \
kvm_resetOperandStack(); \
pushLong((value)); \
return; \
}
#define KNI_ReturnFloat(value) \
{ \
kvm_resetOperandStack(); \
pushStackAsType(float, (value)); \
return; \
}
#define KNI_ReturnDouble(value) \
{ \
kvm_resetOperandStack(); \
pushDouble(value); \
return; \
}
/* Handle operations (implemented as macros on the KVM) */
#define KNI_StartHandles(n) \
{ int _tmp_roots_ = TemporaryRootsLength
#define KNI_DeclareHandle(handle) \
DECLARE_TEMPORARY_ROOT(jobject, handle ## _0, NULL); \
jobject handle = (jobject)&(handle ## _0)
#define KNI_IsNullHandle(handle) \
((*(handle)) ? KNI_FALSE : KNI_TRUE)
#define KNI_IsSameObject(handle1, handle2) \
((*(handle1) == *(handle2)) ? KNI_TRUE : KNI_FALSE)
#define KNI_ReleaseHandle(handle) \
*(handle) = 0;
#define KNI_EndHandles() \
END_TEMPORARY_ROOTS
#define KNI_EndHandlesAndReturnObject(handle) \
kvm_resetOperandStack(); \
pushStack(*(cell*)(handle)); \
END_TEMPORARY_ROOTS \
return;
/* Private operations */
void kvm_resetOperandStack(void);
/*=========================================================================
* COMMENT:
* Since version 1.0.3, KVM garbage collector includes a special
* callback mechanism that allows each KVM port to register
* implementation-specific cleanup routines that get called
* automatically upon system exit. This mechanism can be used,
* e.g., for adding network or UI-widget cleanup routines to
* the system. These cleanup routines will be called automatically
* when the corresponding Java object gets garbage collected.
*
* In KVM 1.0.4, we have made this mechanism capable of
* being used from KNI functions. A separate cleanup
* registration function, KNI_registerCleanup, has been
* defined for this purpose. Unlike the regular register-
* Cleanup routine defined in file 'garbage.h', this function
* accepts parameters as 'jobject' handles instead of
* INSTANCE_HANDLEs.
*
* NOTE: These routines are not part of the KNI API!!
* They have been provided as a convenience for
* people who need to port existing class libraries
* onto KNI.
*=======================================================================*/
/* The function type of a cleanup callback function */
typedef void (*KNICleanupCallback)(jobject);
/*
* Register a cleanup function for the instance.
* When the gc finds the object unreachable it will see if there is
* an associated cleanup function and if so will call it with the instance.
*/
extern void KNI_registerCleanup(jobject, KNICleanupCallback);
#endif /* CLDCHI */
#ifdef __cplusplus
}
#endif
#endif /* _KNI_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -