aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/OSX/src
diff options
context:
space:
mode:
authorendolf <[email protected]>2007-06-10 15:03:27 +0000
committerendolf <[email protected]>2007-06-10 15:03:27 +0000
commitde335a22ccd4056a3e12192ba8f3254fd327b4cd (patch)
treefe3c7c14775ca2bb3a7e90b29fe519c3d4056e23 /plugins/OSX/src
parentf8ed18121deed1c97e28f229406a82bc980d8386 (diff)
Implement the isSupported method and make plugins work again. There was an issue where accessing the static methods in DefaultControllerEnvironment and ControllerEnvironment would cause ploblems when the plugins were loaded using the PluginLoader class loader.
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@187 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins/OSX/src')
-rwxr-xr-xplugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java67
1 files changed, 61 insertions, 6 deletions
diff --git a/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java b/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
index 66813b7..9ba03a1 100755
--- a/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
+++ b/plugins/OSX/src/java/net/java/games/input/OSXEnvironmentPlugin.java
@@ -38,6 +38,7 @@
*****************************************************************************/
package net.java.games.input;
+import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@@ -55,8 +56,54 @@ import java.security.PrivilegedAction;
* @version 1.0
*/
public final class OSXEnvironmentPlugin extends ControllerEnvironment implements Plugin {
+
+ private static boolean supported = false;
+
+ /**
+ * Static utility method for loading native libraries.
+ * It will try to load from either the path given by
+ * the net.java.games.input.librarypath property
+ * or through System.loadLibrary().
+ *
+ */
+ static void loadLibrary(final String lib_name) {
+ AccessController.doPrivileged(
+ new PrivilegedAction() {
+ public final Object run() {
+ String lib_path = System.getProperty("net.java.games.input.librarypath");
+ if (lib_path != null)
+ System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
+ else
+ System.loadLibrary(lib_name);
+ return null;
+ }
+ });
+ }
+
+ static String getPrivilegedProperty(final String property) {
+ return (String)AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty(property);
+ }
+ });
+ }
+
+
+ static String getPrivilegedProperty(final String property, final String default_value) {
+ return (String)AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty(property, default_value);
+ }
+ });
+ }
+
static {
- DefaultControllerEnvironment.loadLibrary("jinput-osx");
+ String osName = getPrivilegedProperty("os.name", "").trim();
+ if(osName.equals("Mac OS X")) {
+ // Could check isMacOSXEqualsOrBetterThan in here too.
+ supported = true;
+ loadLibrary("jinput-osx");
+ }
}
private final static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) {
@@ -70,7 +117,7 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
major = Integer.parseInt(major_str);
minor = Integer.parseInt(minor_str);
} catch (Exception e) {
- ControllerEnvironment.logln("Exception occurred while trying to determine OS version: " + e);
+ logln("Exception occurred while trying to determine OS version: " + e);
// Best guess, no
return false;
}
@@ -80,13 +127,21 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
private final Controller[] controllers;
public OSXEnvironmentPlugin() {
- this.controllers = enumerateControllers();
+ if(isSupported()) {
+ this.controllers = enumerateControllers();
+ } else {
+ this.controllers = new Controller[0];
+ }
}
public final Controller[] getControllers() {
return controllers;
}
+ public boolean isSupported() {
+ return supported;
+ }
+
private final static void addElements(OSXHIDQueue queue, List elements, List components, boolean map_mouse_buttons) throws IOException {
Iterator it = elements.iterator();
while (it.hasNext()) {
@@ -202,19 +257,19 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
createControllersFromDevice(device, controllers);
device_used = old_size != controllers.size();
} catch (IOException e) {
- ControllerEnvironment.logln("Failed to create controllers from device: " + device.getProductName());
+ logln("Failed to create controllers from device: " + device.getProductName());
}
if (!device_used)
device.release();
} catch (IOException e) {
- ControllerEnvironment.logln("Failed to enumerate device: " + e.getMessage());
+ logln("Failed to enumerate device: " + e.getMessage());
}
}
} finally {
it.close();
}
} catch (IOException e) {
- ControllerEnvironment.log("Failed to enumerate devices: " + e.getMessage());
+ log("Failed to enumerate devices: " + e.getMessage());
return new Controller[]{};
}
Controller[] controllers_array = new Controller[controllers.size()];