]> git.saurik.com Git - apple/javascriptcore.git/blob - bindings/jni/jni_utility.h
3b4955f9d3ff8d303a8dad47a8c2e3c63850be4d
[apple/javascriptcore.git] / bindings / jni / jni_utility.h
1 /*
2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef _JNI_UTILITY_H_
27 #define _JNI_UTILITY_H_
28
29 #if ENABLE(JAVA_BINDINGS)
30
31 #include <list.h>
32
33 #include <JavaVM/jni.h>
34
35 // The order of these items can not be modified as they are tightly
36 // bound with the JVM on Mac OSX. If new types need to be added, they
37 // should be added to the end. It is used in jni_obc.mm when calling
38 // through to the JVM. Newly added items need to be made compatible
39 // in that file.
40 typedef enum {
41 invalid_type = 0,
42 void_type,
43 object_type,
44 boolean_type,
45 byte_type,
46 char_type,
47 short_type,
48 int_type,
49 long_type,
50 float_type,
51 double_type,
52 array_type
53 } JNIType;
54
55 namespace KJS {
56
57 namespace Bindings {
58
59 class JavaParameter;
60
61 const char *getCharactersFromJString(jstring aJString);
62 void releaseCharactersForJString(jstring aJString, const char *s);
63
64 const char *getCharactersFromJStringInEnv(JNIEnv *env, jstring aJString);
65 void releaseCharactersForJStringInEnv(JNIEnv *env, jstring aJString, const char *s);
66 const jchar *getUCharactersFromJStringInEnv(JNIEnv *env, jstring aJString);
67 void releaseUCharactersForJStringInEnv(JNIEnv *env, jstring aJString, const jchar *s);
68
69 JNIType JNITypeFromClassName(const char *name);
70 JNIType JNITypeFromPrimitiveType(char type);
71 const char *signatureFromPrimitiveType(JNIType type);
72
73 jvalue convertValueToJValue(ExecState *exec, JSValue *value, JNIType _JNIType, const char *javaClassName);
74
75 jvalue getJNIField(jobject obj, JNIType type, const char *name, const char *signature);
76
77 jmethodID getMethodID(jobject obj, const char *name, const char *sig);
78
79 jobject callJNIObjectMethod(jobject obj, const char *name, const char *sig, ... );
80 void callJNIVoidMethod(jobject obj, const char *name, const char *sig, ... );
81 jboolean callJNIBooleanMethod(jobject obj, const char *name, const char *sig, ... );
82 jboolean callJNIStaticBooleanMethod(jclass cls, const char *name, const char *sig, ... );
83 jbyte callJNIByteMethod(jobject obj, const char *name, const char *sig, ... );
84 jchar callJNICharMethod(jobject obj, const char *name, const char *sig, ... );
85 jshort callJNIShortMethod(jobject obj, const char *name, const char *sig, ... );
86 jint callJNIIntMethod(jobject obj, const char *name, const char *sig, ... );
87 jlong callJNILongMethod(jobject obj, const char *name, const char *sig, ... );
88 jfloat callJNIFloatMethod(jobject obj, const char *name, const char *sig, ... );
89 jdouble callJNIDoubleMethod(jobject obj, const char *name, const char *sig, ... );
90
91 jobject callJNIObjectMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
92 void callJNIVoidMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
93 jboolean callJNIBooleanMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
94 jbyte callJNIByteMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
95 jchar callJNICharMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
96 jshort callJNIShortMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
97 jint callJNIIntMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
98 jlong callJNILongMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
99 jfloat callJNIFloatMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
100 jdouble callJNIDoubleMethodA(jobject obj, const char *name, const char *sig, jvalue *args);
101
102 jobject callJNIObjectMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
103 void callJNIVoidMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
104 jboolean callJNIBooleanMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
105 jbyte callJNIByteMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
106 jchar callJNICharMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
107 jshort callJNIShortMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
108 jint callJNIIntMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
109 jlong callJNILongMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
110 jfloat callJNIFloatMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
111 jdouble callJNIDoubleMethodIDA(jobject obj, jmethodID methodID, jvalue *args);
112
113 JavaVM *getJavaVM();
114 void setJavaVM(JavaVM *javaVM);
115 JNIEnv *getJNIEnv();
116
117 bool dispatchJNICall(const void *targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue *args, jvalue &result, const char *callingURL, JSValue *&exceptionDescription);
118
119 } // namespace Bindings
120
121 } // namespace KJS
122
123 #endif // ENABLE(JAVA_BINDINGS)
124
125 #endif // _JNI_UTILITY_H_