Back to index

lightning-sunbird  0.9+nobinonly
jritypes.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 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 mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
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 /*******************************************************************************
00039  * Java Runtime Interface
00040  ******************************************************************************/
00041 
00042 #ifndef JRITYPES_H
00043 #define JRITYPES_H
00044 
00045 #include "jri_md.h"
00046 #include "jni.h"
00047 #include <stddef.h>
00048 #include <stdlib.h>
00049 #include <stdarg.h>
00050 
00051 #ifdef __cplusplus
00052 extern "C" {
00053 #endif
00054 
00055 /*******************************************************************************
00056  * Types
00057  ******************************************************************************/
00058 
00059 struct JRIEnvInterface;
00060 
00061 typedef void*        JRIRef;
00062 typedef void*        JRIGlobalRef;
00063 
00064 typedef jint         JRIFieldID;
00065 typedef jint         JRIMethodID;
00066 
00067 /* synonyms: */
00068 typedef JRIGlobalRef jglobal;
00069 
00070 typedef union JRIValue {
00071        jbool                z;
00072        jbyte                b;
00073        jchar                c;
00074        jshort               s;
00075        jint                 i;
00076        jlong                l;
00077        jfloat               f;
00078        jdouble                     d;
00079        jref                 r;
00080 } JRIValue;
00081 
00082 typedef enum JRIBoolean {
00083     JRIFalse         = 0,
00084     JRITrue                 = 1
00085 } JRIBoolean;
00086 
00087 typedef enum JRIConstant {
00088        JRIUninitialized     = -1
00089 } JRIConstant;
00090 
00091 /* convenience types (these must be distinct struct types for c++ overloading): */
00092 #if 0  /* now in jni.h */
00093 typedef struct jbooleanArrayStruct*              jbooleanArray;
00094 typedef struct jbyteArrayStruct*          jbyteArray;
00095 typedef struct jcharArrayStruct*          jcharArray;
00096 typedef struct jshortArrayStruct*         jshortArray;
00097 typedef struct jintArrayStruct*                  jintArray;
00098 typedef struct jlongArrayStruct*          jlongArray;
00099 typedef struct jfloatArrayStruct*         jfloatArray;
00100 typedef struct jdoubleArrayStruct*        jdoubleArray;
00101 typedef struct jobjectArrayStruct*        jobjectArray;
00102 #endif
00103 typedef struct jstringArrayStruct*        jstringArray;
00104 typedef struct jarrayArrayStruct*         jarrayArray;
00105 
00106 #define JRIConstructorMethodName   "<init>"
00107 
00108 /*******************************************************************************
00109  * Signature Construction Macros
00110  ******************************************************************************/
00111 
00112 /*
00113 ** These macros can be used to construct signature strings. Hopefully their names
00114 ** are a little easier to remember than the single character they correspond to.
00115 ** For example, to specify the signature of the method:
00116 **
00117 **     public int read(byte b[], int off, int len);
00118 **
00119 ** you could write something like this in C:
00120 **
00121 **     char* readSig = JRISigMethod(JRISigArray(JRISigByte)
00122 **                                                       JRISigInt
00123 **                                                       JRISigInt) JRISigInt;
00124 **
00125 ** Of course, don't put commas between the types.
00126 */
00127 #define JRISigArray(T)             "[" T
00128 #define JRISigByte                 "B"
00129 #define JRISigChar                 "C"
00130 #define JRISigClass(name)   "L" name ";"
00131 #define JRISigFloat                "F"
00132 #define JRISigDouble        "D"
00133 #define JRISigMethod(args)  "(" args ")"
00134 #define JRISigNoArgs        ""
00135 #define JRISigInt                  "I"
00136 #define JRISigLong                 "J"
00137 #define JRISigShort                "S"
00138 #define JRISigVoid                 "V"
00139 #define JRISigBoolean              "Z"
00140 
00141 /*******************************************************************************
00142  * Environments
00143  ******************************************************************************/
00144 
00145 extern JRI_PUBLIC_API(const struct JRIEnvInterface**)
00146 JRI_GetCurrentEnv(void);
00147 
00148 /*******************************************************************************
00149  * Specific Scalar Array Types
00150  ******************************************************************************/
00151 
00152 /*
00153 ** The JRI Native Method Interface does not support boolean arrays. This
00154 ** is to allow Java runtime implementations to optimize boolean array
00155 ** storage. Using the ScalarArray operations on boolean arrays is bound
00156 ** to fail, so convert any boolean arrays to byte arrays in Java before
00157 ** passing them to a native method.
00158 */
00159 
00160 #define JRI_NewByteArray(env, length, initialValues)    \
00161        JRI_NewScalarArray(env, length, JRISigByte, (jbyte*)(initialValues))
00162 #define JRI_GetByteArrayLength(env, array)       \
00163        JRI_GetScalarArrayLength(env, array)
00164 #define JRI_GetByteArrayElements(env, array)     \
00165        JRI_GetScalarArrayElements(env, array)
00166 
00167 #define JRI_NewCharArray(env, length, initialValues)    \
00168        JRI_NewScalarArray(env, ((length) * sizeof(jchar)), JRISigChar, (jbyte*)(initialValues))
00169 #define JRI_GetCharArrayLength(env, array)       \
00170        JRI_GetScalarArrayLength(env, array)
00171 #define JRI_GetCharArrayElements(env, array)               \
00172        ((jchar*)JRI_GetScalarArrayElements(env, array))
00173 
00174 #define JRI_NewShortArray(env, length, initialValues)   \
00175        JRI_NewScalarArray(env, ((length) * sizeof(jshort)), JRISigShort, (jbyte*)(initialValues))
00176 #define JRI_GetShortArrayLength(env, array)      \
00177        JRI_GetScalarArrayLength(env, array)
00178 #define JRI_GetShortArrayElements(env, array)              \
00179        ((jshort*)JRI_GetScalarArrayElements(env, array))
00180 
00181 #define JRI_NewIntArray(env, length, initialValues)     \
00182        JRI_NewScalarArray(env, ((length) * sizeof(jint)), JRISigInt, (jbyte*)(initialValues))
00183 #define JRI_GetIntArrayLength(env, array) \
00184        JRI_GetScalarArrayLength(env, array)
00185 #define JRI_GetIntArrayElements(env, array)                \
00186        ((jint*)JRI_GetScalarArrayElements(env, array))
00187 
00188 #define JRI_NewLongArray(env, length, initialValues)    \
00189        JRI_NewScalarArray(env, ((length) * sizeof(jlong)), JRISigLong, (jbyte*)(initialValues))
00190 #define JRI_GetLongArrayLength(env, array)       \
00191        JRI_GetScalarArrayLength(env, array)
00192 #define JRI_GetLongArrayElements(env, array)               \
00193        ((jlong*)JRI_GetScalarArrayElements(env, array))
00194 
00195 #define JRI_NewFloatArray(env, length, initialValues)   \
00196        JRI_NewScalarArray(env, ((length) * sizeof(jfloat)), JRISigFloat, (jbyte*)(initialValues))
00197 #define JRI_GetFloatArrayLength(env, array)      \
00198        JRI_GetScalarArrayLength(env, array)
00199 #define JRI_GetFloatArrayElements(env, array)              \
00200        ((jfloat*)JRI_GetScalarArrayElements(env, array))
00201 
00202 #define JRI_NewDoubleArray(env, length, initialValues)  \
00203        JRI_NewScalarArray(env, ((length) * sizeof(jdouble)), JRISigDouble, (jbyte*)(initialValues))
00204 #define JRI_GetDoubleArrayLength(env, array)     \
00205        JRI_GetScalarArrayLength(env, array)
00206 #define JRI_GetDoubleArrayElements(env, array)             \
00207        ((jdouble*)JRI_GetScalarArrayElements(env, array))
00208 
00209 /******************************************************************************/
00210 /*
00211 ** JDK Stuff -- This stuff is still needed while we're using the JDK
00212 ** dynamic linking strategy to call native methods.
00213 */
00214 
00215 typedef union JRI_JDK_stack_item {
00216     /* Non pointer items */
00217     jint           i;
00218     jfloat         f;
00219     jint           o;
00220     /* Pointer items */
00221     void          *h;
00222     void          *p;
00223     unsigned char *addr;
00224 #ifdef IS_64
00225     double         d;
00226     long           l;              /* == 64bits! */
00227 #endif
00228 } JRI_JDK_stack_item;
00229 
00230 typedef union JRI_JDK_Java8Str {
00231     jint x[2];
00232     jdouble d;
00233     jlong l;
00234     void *p;
00235     float f;
00236 } JRI_JDK_Java8;
00237 
00238 /******************************************************************************/
00239 #ifdef __cplusplus
00240 }
00241 #endif
00242 #endif /* JRITYPES_H */
00243 /******************************************************************************/