2003-10-11 12:29:40 -04:00
|
|
|
/*
|
2004-06-12 16:28:34 -04:00
|
|
|
* Copyright (c) 2002-2004 LWJGL Project
|
2003-10-11 12:29:40 -04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
2004-06-12 16:28:34 -04:00
|
|
|
* * Neither the name of 'LWJGL' nor the names of
|
2003-10-11 12:29:40 -04:00
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
|
|
|
* @version $Revision$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _COMMON_TOOLS_H
|
|
|
|
#define _COMMON_TOOLS_H
|
|
|
|
|
|
|
|
#include <jni.h>
|
2004-11-14 06:39:54 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2003-12-15 06:49:17 -05:00
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
#define ATTRIB_LIST_SIZE (256)
|
2003-10-11 12:29:40 -04:00
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
typedef struct {
|
|
|
|
int current_index;
|
|
|
|
int attribs[ATTRIB_LIST_SIZE];
|
|
|
|
} attrib_list_t;
|
|
|
|
|
2004-11-02 10:51:09 -05:00
|
|
|
#ifndef __cplusplus
|
|
|
|
#ifndef bool
|
2004-11-02 09:43:16 -05:00
|
|
|
typedef enum {false, true} bool;
|
2004-09-10 04:13:56 -04:00
|
|
|
#endif
|
2004-11-02 10:51:09 -05:00
|
|
|
#endif
|
2004-09-10 04:13:56 -04:00
|
|
|
|
2004-09-10 05:56:26 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define inline __inline
|
2005-02-16 15:25:23 -05:00
|
|
|
#include <Basetsd.h>
|
|
|
|
#else
|
|
|
|
#include <inttypes.h>
|
2004-09-10 05:56:26 -04:00
|
|
|
#endif
|
2003-10-11 12:29:40 -04:00
|
|
|
|
2005-02-09 05:57:33 -05:00
|
|
|
static inline void * safeGetBufferAddress(JNIEnv *env, jobject buffer) {
|
2004-09-10 05:56:26 -04:00
|
|
|
if (buffer != NULL) {
|
|
|
|
#ifdef __cplusplus
|
2005-02-09 05:57:33 -05:00
|
|
|
return (void *)((char *)env->GetDirectBufferAddress(buffer));
|
2004-09-10 05:56:26 -04:00
|
|
|
#else
|
2005-02-09 05:57:33 -05:00
|
|
|
return (void *)((char *)(*env)->GetDirectBufferAddress(env, buffer));
|
2004-09-10 05:56:26 -04:00
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
return NULL;
|
2004-01-05 17:43:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline jobject safeNewBuffer(JNIEnv *env, void *p, int size) {
|
2004-09-10 05:56:26 -04:00
|
|
|
if (p != NULL) {
|
|
|
|
#ifdef __cplusplus
|
|
|
|
return env->NewDirectByteBuffer(p, size);
|
|
|
|
#else
|
2004-09-10 04:13:56 -04:00
|
|
|
return (*env)->NewDirectByteBuffer(env, p, size);
|
2004-09-10 05:56:26 -04:00
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
return NULL;
|
2004-01-05 17:43:42 -05:00
|
|
|
}
|
|
|
|
|
2005-02-15 06:05:36 -05:00
|
|
|
static inline jobject safeNewBufferCached(JNIEnv *env, void *p, int size, jobject old_buffer) {
|
|
|
|
if (old_buffer != NULL) {
|
|
|
|
void *old_buffer_address = (*env)->GetDirectBufferAddress(env, old_buffer);
|
|
|
|
if (old_buffer_address == p)
|
|
|
|
return old_buffer;
|
|
|
|
}
|
|
|
|
return safeNewBuffer(env, p, size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:44:34 -05:00
|
|
|
static inline void *offsetToPointer(jlong offset) {
|
2005-01-13 07:14:10 -05:00
|
|
|
return (char *)NULL + offset;
|
2004-01-05 17:43:42 -05:00
|
|
|
}
|
|
|
|
|
2004-03-09 04:25:10 -05:00
|
|
|
typedef void *(* ExtGetProcAddressPROC) (const char *func_name);
|
|
|
|
typedef struct {
|
|
|
|
char *method_name;
|
|
|
|
char *signature;
|
|
|
|
void *method_pointer;
|
|
|
|
|
|
|
|
char *ext_function_name;
|
|
|
|
void **ext_function_pointer;
|
|
|
|
} JavaMethodAndExtFunction;
|
|
|
|
|
2004-03-11 07:38:13 -05:00
|
|
|
typedef struct {
|
|
|
|
char *ext_function_name;
|
|
|
|
void **ext_function_pointer;
|
|
|
|
} ExtFunction;
|
|
|
|
|
2004-03-09 04:25:10 -05:00
|
|
|
#define NUMFUNCTIONS(x) (sizeof(x)/sizeof(JavaMethodAndExtFunction));
|
|
|
|
|
2004-09-10 05:56:26 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2004-11-02 09:43:16 -05:00
|
|
|
extern JavaVM *getJVM();
|
2004-09-10 05:56:26 -04:00
|
|
|
extern void initAttribList(attrib_list_t *list);
|
|
|
|
extern void putAttrib(attrib_list_t *list, int attrib);
|
|
|
|
|
|
|
|
extern bool isDebugEnabled(void);
|
|
|
|
extern jstring getVersionString(JNIEnv *env);
|
2005-01-11 10:22:12 -05:00
|
|
|
extern void throwGeneralException(JNIEnv * env, const char *exception_name, const char * err);
|
2004-09-10 05:56:26 -04:00
|
|
|
extern void throwException(JNIEnv *env, const char *msg);
|
2006-01-31 07:31:41 -05:00
|
|
|
extern void throwFormattedException(JNIEnv * env, const char *format, ...);
|
2004-09-10 05:56:26 -04:00
|
|
|
extern void throwFMODException(JNIEnv * env, const char * err);
|
|
|
|
extern void setDebugEnabled(bool enable);
|
2004-12-11 14:44:53 -05:00
|
|
|
extern void printfDebugJava(JNIEnv *env, const char *format, ...);
|
2004-09-10 05:56:26 -04:00
|
|
|
extern void printfDebug(const char *format, ...);
|
|
|
|
extern bool getBooleanProperty(JNIEnv *env, const char* propertyName);
|
2004-11-13 16:06:38 -05:00
|
|
|
extern char * GetStringNativeChars(JNIEnv *env, jstring jstr);
|
2004-11-14 05:42:19 -05:00
|
|
|
extern jstring NewStringNative(JNIEnv *env, const char *str);
|
2006-07-07 06:36:26 -04:00
|
|
|
extern jstring NewStringNativeUnsigned(JNIEnv *env, const unsigned char *str);
|
2005-02-21 09:46:47 -05:00
|
|
|
extern jobject newJavaManagedByteBuffer(JNIEnv *env, const int size);
|
2006-07-03 14:07:44 -04:00
|
|
|
extern bool positionBuffer(JNIEnv *env, jobject buffer, jint position);
|
2004-09-10 05:56:26 -04:00
|
|
|
|
2004-07-04 09:14:06 -04:00
|
|
|
extern void ext_InitializeClass(JNIEnv *env, jclass clazz, ExtGetProcAddressPROC gpa, int num_functions, JavaMethodAndExtFunction *functions);
|
2004-03-11 07:38:13 -05:00
|
|
|
extern bool ext_InitializeFunctions(ExtGetProcAddressPROC gpa, int num_functions, ExtFunction *functions);
|
2004-03-09 04:25:10 -05:00
|
|
|
|
2004-09-10 05:56:26 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2003-10-11 12:29:40 -04:00
|
|
|
#endif
|
2004-09-10 05:56:26 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|