From 95cf7ab8e7f030e1fc79de1dc640fbc9b3cad7d5 Mon Sep 17 00:00:00 2001 From: endolf Date: Wed, 31 Aug 2005 06:43:02 +0000 Subject: [PATCH] It helps if you add the files the new changes depend on. Ooops (force feedback changes I committed yesterday that is) --- .../net/java/games/input/JInputLibrary.java | 225 ++++++++++++++++++ .../net_java_games_input_JInputLibrary.h | 156 ++++++++++++ 2 files changed, 381 insertions(+) create mode 100644 plugins/linux/src/java/net/java/games/input/JInputLibrary.java create mode 100644 plugins/linux/src/native/net_java_games_input_JInputLibrary.h diff --git a/plugins/linux/src/java/net/java/games/input/JInputLibrary.java b/plugins/linux/src/java/net/java/games/input/JInputLibrary.java new file mode 100644 index 0000000..dbfda64 --- /dev/null +++ b/plugins/linux/src/java/net/java/games/input/JInputLibrary.java @@ -0,0 +1,225 @@ +package net.java.games.input; + +public class JInputLibrary { + static { + if(isSupported()) { + System.loadLibrary("jinput-linux"); + } + } + + private static boolean inited = false; + private static Object workerThreadMonitor = new Object(); + private static boolean shutdown = false; + private static Object shutdownThreadMonitor = new Object(); + private static boolean cleanupDone = false; + private static int rumbler; + private static float force; + + public static boolean isSupported() { + System.out.println("OS name is: " + System.getProperty("os.name")); + if(System.getProperty("os.name").indexOf("Linux")!=-1) { + System.out.println("Linux plugin is supported"); + return true; + } + System.out.println("Linux plugin is not supported"); + return false; + } + + public static void init() { + if(!inited) { + System.out.println("Initing JInputLibrary"); + Thread initShutdownThread = new Thread() { + public void run() { + + nativeInit(); + inited=true; + + synchronized (workerThreadMonitor) { + workerThreadMonitor.notify(); + } + + synchronized(workerThreadMonitor) { + while(!shutdown) { + System.out.println("Waiting on monitor"); + System.out.flush(); + try { + workerThreadMonitor.wait(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(rumbler>=0) { + nativeRumble(rumbler,force); + rumbler =-1; + } + } + } + System.out.println("Cleaning up from shutdown thread"); + realCleanup(); + cleanupDone = true; + synchronized (shutdownThreadMonitor) { + System.out.println("Notifying on shutdownThreadMonitor after shutdown"); + System.out.flush(); + shutdownThreadMonitor.notifyAll(); + System.out.println("Notified on shutdownThreadMonitor after shutdown"); + System.out.flush(); + } + } + }; + + initShutdownThread.setDaemon(true); + initShutdownThread.start(); + + System.out.println("Shutdown thread created and run"); + + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + cleanup(); + } + }); + + synchronized (workerThreadMonitor) { + while(!inited) { + try { + workerThreadMonitor.wait(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } + } + } + + private static void realCleanup() { + //Give the rumblers chance to cleanup + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("Environment cleanup"); + for(int i=0;i +/* Header for class net_java_games_input_JInputLibrary */ + +#ifndef _Included_net_java_games_input_JInputLibrary +#define _Included_net_java_games_input_JInputLibrary +#ifdef __cplusplus +extern "C" { +#endif +/* Inaccessible static: inited */ +/* Inaccessible static: workerThreadMonitor */ +/* Inaccessible static: shutdown */ +/* Inaccessible static: shutdownThreadMonitor */ +/* Inaccessible static: cleanupDone */ +/* Inaccessible static: rumbler */ +/* Inaccessible static: force */ +/* + * Class: net_java_games_input_JInputLibrary + * Method: getDeviceName + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_net_java_games_input_JInputLibrary_getDeviceName + (JNIEnv *, jclass, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getNumAbsAxes + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumAbsAxes + (JNIEnv *, jclass, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getNumRelAxes + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumRelAxes + (JNIEnv *, jclass, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getNumButtons + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumButtons + (JNIEnv *, jclass, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: nativeInit + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_nativeInit + (JNIEnv *, jclass); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getNumberOfDevices + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNumberOfDevices + (JNIEnv *, jclass); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getSupportedAbsAxes + * Signature: (I[I)V + */ +JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedAbsAxes + (JNIEnv *, jclass, jint, jintArray); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getSupportedRelAxes + * Signature: (I[I)V + */ +JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedRelAxes + (JNIEnv *, jclass, jint, jintArray); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getSupportedButtons + * Signature: (I[I)V + */ +JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_getSupportedButtons + (JNIEnv *, jclass, jint, jintArray); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: poll + * Signature: (I[I[I[I)I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_poll + (JNIEnv *, jclass, jint, jintArray, jintArray, jintArray); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getAbsAxisFuzz + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisFuzz + (JNIEnv *, jclass, jint, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getAbsAxisMaximum + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisMaximum + (JNIEnv *, jclass, jint, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getAbsAxisMinimum + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getAbsAxisMinimum + (JNIEnv *, jclass, jint, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getNativePortType + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_net_java_games_input_JInputLibrary_getNativePortType + (JNIEnv *, jclass, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: getFFEnabled + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_net_java_games_input_JInputLibrary_getFFEnabled + (JNIEnv *, jclass, jint); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: nativeRumble + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_nativeRumble + (JNIEnv *, jclass, jint, jfloat); + +/* + * Class: net_java_games_input_JInputLibrary + * Method: nativeCleanup + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_net_java_games_input_JInputLibrary_nativeCleanup + (JNIEnv *, jclass, jint); + +#ifdef __cplusplus +} +#endif +#endif