kni.h

来自「This is a resource based on j2me embedde」· C头文件 代码 · 共 500 行 · 第 1/2 页

H
500
字号
/* * @(#)kni.h	1.43 06/10/10 10:03:30 * * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation.  *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt).  *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA  *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions.  */#ifndef _JAVASOFT_KNI_H_#define _JAVASOFT_KNI_H_/** * KNI is an implementation-level native function interface * for CLDC-category VMs.  KNI is intended to be significantly * more lightweight than JNI, so we have made some compromises: * * - Compile-time interface with static linking. * - Source-level (no binary level) compatibility. * - No argument marshalling. All native functions have *   signature void(*)(). Arguments are read explicitly, *   and return values are set explicitly. * - No invocation API (cannot call Java from native code). * - No class definition support. * - Limited object allocation support (strings only). * - Limited array region access for arrays of a primitive type. * - No monitorenter/monitorexit support. * - Limited error handling and exception support. *   KNI functions do not throw exceptions, but return error *   values/null instead, or go fatal for severe errors. * - Exceptions can be thrown explicitly, but no direct *   exception manipulation is supported. */#ifdef __cplusplusextern "C" {#endif#include "jni.h"#include "javavm/include/localroots.h"#include "javavm/include/indirectmem.h"#include "javavm/include/directmem.h"/* * New stuff for KNI on CNI */#define KNIDECLARGS CVMExecEnv* _ee,		\	  	    CVMStackVal32* _arguments,	\		    CVMMethodBlock** _p_mb,#define KNIPASSARGS _ee, _arguments, _p_mb,/* Macro for declaring a KNI method */#define KNIDECL(methodname)			\    CNI##methodname(CVMExecEnv* _ee,		\	  	    CVMStackVal32* _arguments,	\		    CVMMethodBlock** _p_mb)/** * KNI Basic Types * * Note: jbyte, jint and jlong are defined in the * machine-specific jni_md.h file. */#if 0 /* these are all handled in jni.h */typedef unsigned char   jboolean;typedef unsigned short  jchar;typedef short           jshort;typedef float           jfloat;typedef double          jdouble;typedef jint            jsize;#endif/** * KNI Reference Types * * Note: jfieldID and jobject are intended to be opaque * types.  The programmer should not make any assumptions * about the actual type of these types, since the actual * type may vary from one KNI implementation to another. */#if 0 /* these are all handled in jni.h */struct _jobject;typedef struct _jobject* jobject;typedef jobject jclass;typedef jobject jthrowable;typedef jobject jstring;typedef jobject jarray;typedef jarray  jbooleanArray;typedef jarray  jbyteArray;typedef jarray  jcharArray;typedef jarray  jshortArray;typedef jarray  jintArray;typedef jarray  jlongArray;typedef jarray  jfloatArray;typedef jarray  jdoubleArray;typedef jarray  jobjectArray;#endif/** * KNI Field Type */#if 0 /* these are all handled in jni.h */struct _jfieldID;typedef struct _jfieldID* jfieldID;#endif/** * jboolean constants */#define KNI_FALSE 0#define KNI_TRUE  1/** * Return values for KNI functions. * Values correspond to JNI. */#define KNI_OK           0                 // success#define KNI_ERR          (-1)              // unknown error#define KNI_ENOMEM       (-4)              // not enough memory#define KNI_EINVAL       (-6)              // invalid arguments#define KNIEXPORT JNIEXPORT/* * Version information */#define KNI_VERSION      0x00010000        // KNI version 1.0/****************************************************************** * KNI functions (refer to KNI Specification for details) ******************************************************************//** * Version information */KNIEXPORT jint KNI_GetVersion();#define KNI_GetVersion() (KNI_VERSION)/** * Class and interface operations * * WARNING: KNI_FindClass can cause a gc. * Not sure if this is per the KNI spec. */KNIEXPORT voidKNI_FindClassImpl(CVMExecEnv* ee, const char* name, jclass classHandle);KNIEXPORT voidKNI_GetSuperClassImpl(CVMExecEnv* ee, jclass classHandle,		      jclass superclassHandle);KNIEXPORT jbooleanKNI_IsAssignableFromPriv(CVMExecEnv* ee, jclass classHandle1,			 jclass classHandle2);#define KNI_FindClass(name, classHandle) \    KNI_FindClassImpl(_ee, name, classHandle)#define KNI_GetSuperClass(classHandle, superclassHandle) \    KNI_GetSuperClassImpl(_ee, classHandle, superclassHandle)#define KNI_IsAssignableFrom(classHandle1, classHandle2) \    KNI_IsAssignableFromPriv(_ee, classHandle1, classHandle2)/** * Exceptions and errors * * WARNING: KNI_ThrowNewPriv can cause a gc. * Not sure if this is per the KNI spec. */KNIEXPORT jintKNI_ThrowNewImpl(CVMExecEnv* ee, const char* name, const char* message);KNIEXPORT voidKNI_FatalErrorImpl(CVMExecEnv* ee, const char* message);#define KNI_ThrowNew(name, message) \    KNI_ThrowNewImpl(_ee, name, message)#define KNI_FatalError(message) \    KNI_FatalErrorImpl(_ee, message)/** * Object operations */KNIEXPORT voidKNI_GetObjectClass(jobject objectHandle, jclass classHandle);KNIEXPORT jbooleanKNI_IsInstanceOfPriv(CVMExecEnv* ee, jobject objectHandle, jclass classHandle);KNIEXPORT jbooleanKNI_IsSameObject(jobject obj1, jobject obj2);#define KNI_GetObjectClass(objectHandle, classHandle) {			\    CVMObject* classObject = CVMID_icellDirect(_ee, objectHandle);	\    CVMClassBlock* cb = CVMobjectGetClass(classObject);			\    CVMID_icellAssignDirect(_ee, classHandle, CVMcbJavaInstance(cb));	\}#define KNI_IsInstanceOf(objectHandle, classHandle) \    KNI_IsInstanceOfPriv(_ee, objectHandle, classHandle)#define KNI_IsSameObject(obj1, obj2)					\    (obj1 == NULL || obj2 == NULL 					\     ? obj1 == obj2							\     : CVMID_icellDirect(_ee, obj1) == CVMID_icellDirect(_ee, obj2))/** * Get an instance field or static field ID. */KNIEXPORT jfieldIDKNI_GetFieldIDPriv(CVMExecEnv* ee, jclass classHandle, const char* name,		   const char* signature, CVMBool isStatic);#define KNI_GetFieldID(classHandle, name, signature) \    KNI_GetFieldIDPriv(_ee, classHandle, name, signature, CVM_FALSE)#define KNI_GetStaticFieldID(classHandle, name, signature) \    KNI_GetFieldIDPriv(_ee, classHandle, name, signature, CVM_TRUE)/** * Instance field access. */KNIEXPORT jboolean KNI_GetBooleanField(jobject objectHandle, jfieldID fieldID);KNIEXPORT jbyte    KNI_GetByteField(jobject objectHandle, jfieldID fieldID);KNIEXPORT jchar    KNI_GetCharField(jobject objectHandle, jfieldID fieldID);KNIEXPORT jshort   KNI_GetShortField(jobject objectHandle, jfieldID fieldID);KNIEXPORT jint     KNI_GetIntField(jobject objectHandle, jfieldID fieldID);KNIEXPORT jlong    KNI_GetLongField(jobject objectHandle, jfieldID fieldID);KNIEXPORT jfloat   KNI_GetFloatField(jobject objectHandle, jfieldID fieldID);KNIEXPORT jdouble  KNI_GetDoubleField(jobject objectHandle, jfieldID fieldID);KNIEXPORT void     KNI_GetObjectField(jobject objectHandle, jfieldID fieldID,                       jobject toHandle);KNIEXPORT void     KNI_SetBooleanField(jobject objectHandle, jfieldID fieldID,                       jboolean value);KNIEXPORT void     KNI_SetByteField(jobject objectHandle, jfieldID fieldID,                       jbyte value);KNIEXPORT void     KNI_SetCharField(jobject objectHandle, jfieldID fieldID,                       jchar value);KNIEXPORT void     KNI_SetShortField(jobject objectHandle, jfieldID fieldID,                       jshort value);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?