0N/A/*
2362N/A * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifndef JNI_UTIL_H
0N/A#define JNI_UTIL_H
0N/A
0N/A#include "jni.h"
0N/A#include "jlong.h"
0N/A
0N/A#ifdef __cplusplus
0N/Aextern "C" {
0N/A#endif
0N/A
0N/A/*
0N/A * This file contains utility functions that can be implemented in pure JNI.
0N/A *
0N/A * Caution: Callers of functions declared in this file should be
0N/A * particularly aware of the fact that these functions are convenience
0N/A * functions, and as such are often compound operations, each one of
0N/A * which may throw an exception. Therefore, the functions this file
0N/A * will often return silently if an exception has occured, and callers
0N/A * must check for exception themselves.
0N/A */
0N/A
0N/A/* Throw a Java exception by name. Similar to SignalError. */
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowByName(JNIEnv *env, const char *name, const char *msg);
0N/A
0N/A/* Throw common exceptions */
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowNullPointerException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowArrayIndexOutOfBoundsException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowOutOfMemoryError(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowIllegalArgumentException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowIllegalAccessError(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowIllegalAccessException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowInternalError(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowIOException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowNoSuchFieldException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowNoSuchMethodException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowClassNotFoundException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowNumberFormatException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowNoSuchFieldError(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowNoSuchMethodError(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowStringIndexOutOfBoundsException(JNIEnv *env, const char *msg);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowInstantiationException(JNIEnv *env, const char *msg);
0N/A
0N/A/* Throw an exception by name, using the string returned by
0N/A * JVM_LastErrorString for the detail string. If the last-error
0N/A * string is NULL, use the given default detail string.
0N/A */
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowByNameWithLastError(JNIEnv *env, const char *name,
0N/A const char *defaultMessage);
0N/A
0N/A/* Throw an IOException, using the last-error string for the detail
0N/A * string. If the last-error string is NULL, use the given default
0N/A * detail string.
0N/A */
0N/AJNIEXPORT void JNICALL
0N/AJNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *defaultDetail);
0N/A
0N/A/* Convert between Java strings and i18n C strings */
0N/AJNIEXPORT jstring
0N/ANewStringPlatform(JNIEnv *env, const char *str);
0N/A
0N/AJNIEXPORT const char *
0N/AGetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy);
0N/A
0N/AJNIEXPORT jstring JNICALL
0N/AJNU_NewStringPlatform(JNIEnv *env, const char *str);
0N/A
0N/AJNIEXPORT const char * JNICALL
0N/AJNU_GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_ReleaseStringPlatformChars(JNIEnv *env, jstring jstr, const char *str);
0N/A
0N/A/* Class constants */
0N/AJNIEXPORT jclass JNICALL
0N/AJNU_ClassString(JNIEnv *env);
0N/A
0N/AJNIEXPORT jclass JNICALL
0N/AJNU_ClassClass(JNIEnv *env);
0N/A
0N/AJNIEXPORT jclass JNICALL
0N/AJNU_ClassObject(JNIEnv *env);
0N/A
0N/AJNIEXPORT jclass JNICALL
0N/AJNU_ClassThrowable(JNIEnv *env);
0N/A
0N/A/* Copy count number of arguments from src to dst. Array bounds
0N/A * and ArrayStoreException are checked.
0N/A */
0N/AJNIEXPORT jint JNICALL
0N/AJNU_CopyObjectArray(JNIEnv *env, jobjectArray dst, jobjectArray src,
0N/A jint count);
0N/A
0N/A/* Invoke a object-returning static method, based on class name,
0N/A * method name, and signature string.
0N/A *
0N/A * The caller should check for exceptions by setting hasException
0N/A * argument. If the caller is not interested in whether an exception
0N/A * has occurred, pass in NULL.
0N/A */
0N/AJNIEXPORT jvalue JNICALL
0N/AJNU_CallStaticMethodByName(JNIEnv *env,
0N/A jboolean *hasException,
0N/A const char *class_name,
0N/A const char *name,
0N/A const char *signature,
0N/A ...);
0N/A
0N/A/* Invoke an instance method by name.
0N/A */
0N/AJNIEXPORT jvalue JNICALL
0N/AJNU_CallMethodByName(JNIEnv *env,
0N/A jboolean *hasException,
0N/A jobject obj,
0N/A const char *name,
0N/A const char *signature,
0N/A ...);
0N/A
0N/AJNIEXPORT jvalue JNICALL
0N/AJNU_CallMethodByNameV(JNIEnv *env,
0N/A jboolean *hasException,
0N/A jobject obj,
0N/A const char *name,
0N/A const char *signature,
0N/A va_list args);
0N/A
0N/A/* Construct a new object of class, specifying the class by name,
0N/A * and specififying which constructor to run and what arguments to
0N/A * pass to it.
0N/A *
0N/A * The method will return an initialized instance if successful.
0N/A * It will return NULL if an error has occured (for example if
0N/A * it ran out of memory) and the appropriate Java exception will
0N/A * have been thrown.
0N/A */
0N/AJNIEXPORT jobject JNICALL
0N/AJNU_NewObjectByName(JNIEnv *env, const char *class_name,
0N/A const char *constructor_sig, ...);
0N/A
0N/A/* returns:
0N/A * 0: object is not an instance of the class named by classname.
0N/A * 1: object is an instance of the class named by classname.
0N/A * -1: the class named by classname cannot be found. An exception
0N/A * has been thrown.
0N/A */
0N/AJNIEXPORT jint JNICALL
0N/AJNU_IsInstanceOfByName(JNIEnv *env, jobject object, char *classname);
0N/A
0N/A
0N/A/* Get or set class and instance fields.
0N/A * Note that set functions take a variable number of arguments,
0N/A * but only one argument of the appropriate type can be passed.
0N/A * For example, to set an integer field i to 100:
0N/A *
0N/A * JNU_SetFieldByName(env, &exc, obj, "i", "I", 100);
0N/A *
0N/A * To set a float field f to 12.3:
0N/A *
0N/A * JNU_SetFieldByName(env, &exc, obj, "f", "F", 12.3);
0N/A *
0N/A * The caller should check for exceptions by setting hasException
0N/A * argument. If the caller is not interested in whether an exception
0N/A * has occurred, pass in NULL.
0N/A */
0N/AJNIEXPORT jvalue JNICALL
0N/AJNU_GetFieldByName(JNIEnv *env,
0N/A jboolean *hasException,
0N/A jobject obj,
0N/A const char *name,
0N/A const char *sig);
0N/AJNIEXPORT void JNICALL
0N/AJNU_SetFieldByName(JNIEnv *env,
0N/A jboolean *hasException,
0N/A jobject obj,
0N/A const char *name,
0N/A const char *sig,
0N/A ...);
0N/A
0N/AJNIEXPORT jvalue JNICALL
0N/AJNU_GetStaticFieldByName(JNIEnv *env,
0N/A jboolean *hasException,
0N/A const char *classname,
0N/A const char *name,
0N/A const char *sig);
0N/AJNIEXPORT void JNICALL
0N/AJNU_SetStaticFieldByName(JNIEnv *env,
0N/A jboolean *hasException,
0N/A const char *classname,
0N/A const char *name,
0N/A const char *sig,
0N/A ...);
0N/A
0N/A
0N/A/*
0N/A * Calls the .equals method.
0N/A */
0N/AJNIEXPORT jboolean JNICALL
0N/AJNU_Equals(JNIEnv *env, jobject object1, jobject object2);
0N/A
0N/A
0N/A/************************************************************************
0N/A * Thread calls
0N/A *
0N/A * Convenience thread-related calls on the java.lang.Object class.
0N/A */
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_MonitorWait(JNIEnv *env, jobject object, jlong timeout);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_Notify(JNIEnv *env, jobject object);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_NotifyAll(JNIEnv *env, jobject object);
0N/A
0N/A
0N/A/************************************************************************
0N/A * Miscellaneous utilities used by the class libraries
0N/A */
0N/A
0N/A#define IS_NULL(obj) ((obj) == NULL)
0N/A#define JNU_IsNull(env,obj) ((obj) == NULL)
0N/A
0N/A
0N/A/************************************************************************
0N/A * Debugging utilities
0N/A */
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_PrintString(JNIEnv *env, char *hdr, jstring string);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJNU_PrintClass(JNIEnv *env, char *hdr, jobject object);
0N/A
0N/AJNIEXPORT jstring JNICALL
0N/AJNU_ToString(JNIEnv *env, jobject object);
0N/A
0N/A/*
0N/A * Package shorthand for use by native libraries
0N/A */
0N/A#define JNU_JAVAPKG "java/lang/"
0N/A#define JNU_JAVAIOPKG "java/io/"
0N/A#define JNU_JAVANETPKG "java/net/"
0N/A
0N/A/*
0N/A * Check if the current thread is attached to the VM, and returns
0N/A * the JNIEnv of the specified version if the thread is attached.
0N/A *
0N/A * If the current thread is not attached, this function returns 0.
0N/A *
0N/A * If the current thread is attached, this function returns the
0N/A * JNI environment, or returns (void *)JNI_ERR if the specified
0N/A * version is not supported.
0N/A */
0N/AJNIEXPORT void * JNICALL
0N/AJNU_GetEnv(JavaVM *vm, jint version);
0N/A
0N/A/*
0N/A * Warning free access to pointers stored in Java long fields.
0N/A */
0N/A#define JNU_GetLongFieldAsPtr(env,obj,id) \
0N/A (jlong_to_ptr((*(env))->GetLongField((env),(obj),(id))))
0N/A#define JNU_SetLongFieldFromPtr(env,obj,id,val) \
0N/A (*(env))->SetLongField((env),(obj),(id),ptr_to_jlong(val))
0N/A
1365N/A/*
1365N/A * Internal use only.
1365N/A */
1365N/Aenum {
1365N/A NO_ENCODING_YET = 0, /* "sun.jnu.encoding" not yet set */
1365N/A NO_FAST_ENCODING, /* Platform encoding is not fast */
1365N/A FAST_8859_1, /* ISO-8859-1 */
1365N/A FAST_CP1252, /* MS-DOS Cp1252 */
1365N/A FAST_646_US /* US-ASCII : ISO646-US */
1365N/A};
1365N/A
1365N/Ajstring nativeNewStringPlatform(JNIEnv *env, const char *str);
1365N/A
1365N/Achar* nativeGetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy);
1365N/A
1365N/Aint getFastEncoding();
1365N/A
1365N/Avoid initializeEncoding();
1365N/A
1365N/A
0N/A#ifdef __cplusplus
0N/A} /* extern "C" */
0N/A#endif /* __cplusplus */
0N/A
0N/A#endif /* JNI_UTIL_H */