2005-03-24 20:08:18 -05:00
|
|
|
/* Handle to devil Library */
|
2004-12-08 14:15:50 -05:00
|
|
|
#ifdef _WIN32
|
2005-05-29 17:24:18 -04:00
|
|
|
#include "extil.h"
|
|
|
|
static HMODULE devILhandle;
|
|
|
|
#else
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include "extil.h"
|
|
|
|
static void* devILhandle;
|
2005-05-18 13:36:42 -04:00
|
|
|
#endif
|
2004-12-08 14:15:50 -05:00
|
|
|
|
2006-07-02 17:59:10 -04:00
|
|
|
static const char* VERSION = "1.0beta2";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_devil_ILNative
|
|
|
|
* Method: getNativeLibraryVersion
|
|
|
|
* Signature: ()Ljava/lang/String;
|
|
|
|
*/
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_devil_ILNative_getNativeLibraryVersion(JNIEnv *env, jclass clazz) {
|
|
|
|
return NewStringNative(env, VERSION);
|
|
|
|
}
|
|
|
|
|
2005-03-24 20:08:18 -05:00
|
|
|
/**
|
|
|
|
* Retrieves a function pointer from the devil library
|
|
|
|
* @param function Name of function to retrieve
|
|
|
|
*/
|
|
|
|
static void *NativeGetFunctionPointer(const char *function) {
|
2004-12-08 14:15:50 -05:00
|
|
|
#ifdef _WIN32
|
2005-03-24 20:08:18 -05:00
|
|
|
return GetProcAddress(devILhandle, function);
|
2005-05-29 17:24:18 -04:00
|
|
|
#else
|
2005-03-24 20:08:18 -05:00
|
|
|
return dlsym(devILhandle, function);
|
|
|
|
#endif
|
2004-12-08 14:15:50 -05:00
|
|
|
}
|
|
|
|
|
2005-03-24 20:08:18 -05:00
|
|
|
/**
|
|
|
|
* Retrieves a pointer to the named function
|
|
|
|
*
|
|
|
|
* @param function Name of function
|
|
|
|
* @return pointer to named function, or NULL if not found
|
|
|
|
*/
|
|
|
|
static void* extil_GetProcAddress(const char* function) {
|
|
|
|
void *p = NativeGetFunctionPointer(function);
|
|
|
|
if (p == NULL) {
|
|
|
|
printfDebug("Could not locate symbol %s\n", function);
|
|
|
|
}
|
|
|
|
return p;
|
2004-12-08 14:15:50 -05:00
|
|
|
}
|
|
|
|
|
2005-03-24 20:08:18 -05:00
|
|
|
/**
|
|
|
|
* Initializes all functions for class
|
|
|
|
*/
|
|
|
|
void extil_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions) {
|
|
|
|
ext_InitializeClass(env, clazz, &extil_GetProcAddress, num_functions, functions);
|
2004-12-08 14:15:50 -05:00
|
|
|
}
|
|
|
|
|
2005-03-24 20:08:18 -05:00
|
|
|
/**
|
|
|
|
* Opens the native library
|
|
|
|
*/
|
|
|
|
bool extil_Open(JNIEnv *env, jobjectArray ilPaths) {
|
|
|
|
jsize pathcount = (*env)->GetArrayLength(env, ilPaths);
|
|
|
|
int i;
|
|
|
|
jstring path;
|
|
|
|
char *path_str;
|
|
|
|
|
|
|
|
printfDebug("Found %d devil paths\n", (int)pathcount);
|
|
|
|
for(i=0;i<pathcount;i++) {
|
|
|
|
path = (jstring) (*env)->GetObjectArrayElement(env, ilPaths, i);
|
|
|
|
path_str = GetStringNativeChars(env, path);
|
|
|
|
printfDebug("Testing '%s'\n", path_str);
|
2004-12-08 14:15:50 -05:00
|
|
|
#ifdef _WIN32
|
2005-03-24 20:08:18 -05:00
|
|
|
devILhandle = LoadLibrary(path_str);
|
2005-05-29 17:24:18 -04:00
|
|
|
#else
|
2005-03-24 20:08:18 -05:00
|
|
|
devILhandle = dlopen(path_str, RTLD_LAZY);
|
2005-05-29 17:24:18 -04:00
|
|
|
if(devILhandle == NULL) {
|
|
|
|
printfDebug("dlopen failure: %s", dlerror());
|
|
|
|
}
|
2005-03-24 20:08:18 -05:00
|
|
|
#endif
|
|
|
|
if (devILhandle != NULL) {
|
|
|
|
printfDebug("Found devil at '%s'\n", path_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(path_str);
|
|
|
|
if (devILhandle != NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throwException(env, "Could not load devil library.");
|
|
|
|
return false;
|
2004-12-08 14:15:50 -05:00
|
|
|
}
|
|
|
|
|
2005-03-24 20:08:18 -05:00
|
|
|
/**
|
|
|
|
* Closes the native library
|
|
|
|
*/
|
2004-12-12 05:13:55 -05:00
|
|
|
void extil_Close(void) {
|
2004-12-08 14:15:50 -05:00
|
|
|
#ifdef _WIN32
|
2005-03-24 20:08:18 -05:00
|
|
|
FreeLibrary(devILhandle);
|
2005-05-29 17:24:18 -04:00
|
|
|
#else
|
2005-03-24 20:08:18 -05:00
|
|
|
if (devILhandle != NULL) {
|
|
|
|
dlclose(devILhandle);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
devILhandle = NULL;
|
2005-03-25 05:25:07 -05:00
|
|
|
}
|
|
|
|
|