Back to index

lightning-sunbird  0.9+nobinonly
jritypes.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Java Runtime Interface.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corp.
00019  * Portions created by the Initial Developer are Copyright (C) 1996
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */  
00037 
00038 #ifndef JRITYPES_H
00039 #define JRITYPES_H
00040 
00041 #include "jni.h"
00042 #include <stddef.h>
00043 #include <stdlib.h>
00044 #include <stdarg.h>
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 /*******************************************************************************
00051  * Types
00052  ******************************************************************************/
00053 
00054 struct JRIEnvInterface;
00055 
00056 typedef void*        JRIRef;
00057 typedef void*        JRIGlobalRef;
00058 
00059 typedef jint         JRIFieldID;
00060 typedef jint         JRIMethodID;
00061 
00062 /* synonyms: */
00063 typedef JRIGlobalRef jglobal;
00064 
00065 typedef union JRIValue {
00066        jbool                z;
00067        jbyte                b;
00068        jchar                c;
00069        jshort               s;
00070        jint                 i;
00071        jlong                l;
00072        jfloat               f;
00073        jdouble                     d;
00074        jref                 r;
00075 } JRIValue;
00076 
00077 typedef enum JRIBoolean {
00078     JRIFalse         = 0,
00079     JRITrue                 = 1
00080 } JRIBoolean;
00081 
00082 typedef enum JRIConstant {
00083        JRIUninitialized     = -1
00084 } JRIConstant;
00085 
00086 /* convenience types (these must be distinct struct types for c++ overloading): */
00087 #if 0  /* now in jni.h */
00088 typedef struct jbooleanArrayStruct*              jbooleanArray;
00089 typedef struct jbyteArrayStruct*          jbyteArray;
00090 typedef struct jcharArrayStruct*          jcharArray;
00091 typedef struct jshortArrayStruct*         jshortArray;
00092 typedef struct jintArrayStruct*                  jintArray;
00093 typedef struct jlongArrayStruct*          jlongArray;
00094 typedef struct jfloatArrayStruct*         jfloatArray;
00095 typedef struct jdoubleArrayStruct*        jdoubleArray;
00096 typedef struct jobjectArrayStruct*        jobjectArray;
00097 #endif
00098 typedef struct jstringArrayStruct*        jstringArray;
00099 typedef struct jarrayArrayStruct*         jarrayArray;
00100 
00101 #define JRIConstructorMethodName   "<init>"
00102 
00103 /*******************************************************************************
00104  * Signature Construction Macros
00105  ******************************************************************************/
00106 
00107 /*
00108 ** These macros can be used to construct signature strings. Hopefully their names
00109 ** are a little easier to remember than the single character they correspond to.
00110 ** For example, to specify the signature of the method:
00111 **
00112 **     public int read(byte b[], int off, int len);
00113 **
00114 ** you could write something like this in C:
00115 **
00116 **     char* readSig = JRISigMethod(JRISigArray(JRISigByte)
00117 **                                                       JRISigInt
00118 **                                                       JRISigInt) JRISigInt;
00119 **
00120 ** Of course, don't put commas between the types.
00121 */
00122 #define JRISigArray(T)             "[" T
00123 #define JRISigByte                 "B"
00124 #define JRISigChar                 "C"
00125 #define JRISigClass(name)   "L" name ";"
00126 #define JRISigFloat                "F"
00127 #define JRISigDouble        "D"
00128 #define JRISigMethod(args)  "(" args ")"
00129 #define JRISigNoArgs        ""
00130 #define JRISigInt                  "I"
00131 #define JRISigLong                 "J"
00132 #define JRISigShort                "S"
00133 #define JRISigVoid                 "V"
00134 #define JRISigBoolean              "Z"
00135 
00136 /*******************************************************************************
00137  * Environments
00138  ******************************************************************************/
00139 
00140 extern JRI_PUBLIC_API(const struct JRIEnvInterface**)
00141 JRI_GetCurrentEnv(void);
00142 
00143 /*******************************************************************************
00144  * Specific Scalar Array Types
00145  ******************************************************************************/
00146 
00147 /*
00148 ** The JRI Native Method Interface does not support boolean arrays. This
00149 ** is to allow Java runtime implementations to optimize boolean array
00150 ** storage. Using the ScalarArray operations on boolean arrays is bound
00151 ** to fail, so convert any boolean arrays to byte arrays in Java before
00152 ** passing them to a native method.
00153 */
00154 
00155 #define JRI_NewByteArray(env, length, initialValues)    \
00156        JRI_NewScalarArray(env, length, JRISigByte, (jbyte*)(initialValues))
00157 #define JRI_GetByteArrayLength(env, array)       \
00158        JRI_GetScalarArrayLength(env, array)
00159 #define JRI_GetByteArrayElements(env, array)     \
00160        JRI_GetScalarArrayElements(env, array)
00161 
00162 #define JRI_NewCharArray(env, length, initialValues)    \
00163        JRI_NewScalarArray(env, ((length) * sizeof(jchar)), JRISigChar, (jbyte*)(initialValues))
00164 #define JRI_GetCharArrayLength(env, array)       \
00165        JRI_GetScalarArrayLength(env, array)
00166 #define JRI_GetCharArrayElements(env, array)               \
00167        ((jchar*)JRI_GetScalarArrayElements(env, array))
00168 
00169 #define JRI_NewShortArray(env, length, initialValues)   \
00170        JRI_NewScalarArray(env, ((length) * sizeof(jshort)), JRISigShort, (jbyte*)(initialValues))
00171 #define JRI_GetShortArrayLength(env, array)      \
00172        JRI_GetScalarArrayLength(env, array)
00173 #define JRI_GetShortArrayElements(env, array)              \
00174        ((jshort*)JRI_GetScalarArrayElements(env, array))
00175 
00176 #define JRI_NewIntArray(env, length, initialValues)     \
00177        JRI_NewScalarArray(env, ((length) * sizeof(jint)), JRISigInt, (jbyte*)(initialValues))
00178 #define JRI_GetIntArrayLength(env, array) \
00179        JRI_GetScalarArrayLength(env, array)
00180 #define JRI_GetIntArrayElements(env, array)                \
00181        ((jint*)JRI_GetScalarArrayElements(env, array))
00182 
00183 #define JRI_NewLongArray(env, length, initialValues)    \
00184        JRI_NewScalarArray(env, ((length) * sizeof(jlong)), JRISigLong, (jbyte*)(initialValues))
00185 #define JRI_GetLongArrayLength(env, array)       \
00186        JRI_GetScalarArrayLength(env, array)
00187 #define JRI_GetLongArrayElements(env, array)               \
00188        ((jlong*)JRI_GetScalarArrayElements(env, array))
00189 
00190 #define JRI_NewFloatArray(env, length, initialValues)   \
00191        JRI_NewScalarArray(env, ((length) * sizeof(jfloat)), JRISigFloat, (jbyte*)(initialValues))
00192 #define JRI_GetFloatArrayLength(env, array)      \
00193        JRI_GetScalarArrayLength(env, array)
00194 #define JRI_GetFloatArrayElements(env, array)              \
00195        ((jfloat*)JRI_GetScalarArrayElements(env, array))
00196 
00197 #define JRI_NewDoubleArray(env, length, initialValues)  \
00198        JRI_NewScalarArray(env, ((length) * sizeof(jdouble)), JRISigDouble, (jbyte*)(initialValues))
00199 #define JRI_GetDoubleArrayLength(env, array)     \
00200        JRI_GetScalarArrayLength(env, array)
00201 #define JRI_GetDoubleArrayElements(env, array)             \
00202        ((jdouble*)JRI_GetScalarArrayElements(env, array))
00203 
00204 /******************************************************************************/
00205 /*
00206 ** JDK Stuff -- This stuff is still needed while we're using the JDK
00207 ** dynamic linking strategy to call native methods.
00208 */
00209 
00210 typedef union JRI_JDK_stack_item {
00211     /* Non pointer items */
00212     jint           i;
00213     jfloat         f;
00214     jint           o;
00215     /* Pointer items */
00216     void          *h;
00217     void          *p;
00218     unsigned char *addr;
00219 #ifdef IS_64
00220     double         d;
00221     long           l;              /* == 64bits! */
00222 #endif
00223 } JRI_JDK_stack_item;
00224 
00225 typedef union JRI_JDK_Java8Str {
00226     jint x[2];
00227     jdouble d;
00228     jlong l;
00229     void *p;
00230     float f;
00231 } JRI_JDK_Java8;
00232 
00233 /******************************************************************************/
00234 #ifdef __cplusplus
00235 }
00236 #endif
00237 #endif /* JRITYPES_H */
00238 /******************************************************************************/