First stab at OSX maven build.

This commit is contained in:
Endolf 2018-05-12 11:17:38 +01:00
parent e0a512be48
commit 4e98105deb
27 changed files with 152 additions and 168 deletions

View file

@ -0,0 +1,141 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.util.Map;
import java.util.HashMap;
/** Button Usages
* @author elias
* @version 1.0
*/
final class ButtonUsage implements Usage {
private final static Map map = new HashMap();
private final int button_id;
public final static ButtonUsage map(int button_id) {
Integer button_id_obj = new Integer(button_id);
ButtonUsage existing = (ButtonUsage)map.get(button_id_obj);
if (existing != null)
return existing;
ButtonUsage new_button = new ButtonUsage(button_id);
map.put(button_id_obj, new_button);
return new_button;
}
private ButtonUsage(int button_id) {
this.button_id = button_id;
}
public final Component.Identifier.Button getIdentifier() {
switch (button_id) {
case 1:
return Component.Identifier.Button._0;
case 2:
return Component.Identifier.Button._1;
case 3:
return Component.Identifier.Button._2;
case 4:
return Component.Identifier.Button._3;
case 5:
return Component.Identifier.Button._4;
case 6:
return Component.Identifier.Button._5;
case 7:
return Component.Identifier.Button._6;
case 8:
return Component.Identifier.Button._7;
case 9:
return Component.Identifier.Button._8;
case 10:
return Component.Identifier.Button._9;
case 11:
return Component.Identifier.Button._10;
case 12:
return Component.Identifier.Button._11;
case 13:
return Component.Identifier.Button._12;
case 14:
return Component.Identifier.Button._13;
case 15:
return Component.Identifier.Button._14;
case 16:
return Component.Identifier.Button._15;
case 17:
return Component.Identifier.Button._16;
case 18:
return Component.Identifier.Button._17;
case 19:
return Component.Identifier.Button._18;
case 20:
return Component.Identifier.Button._19;
case 21:
return Component.Identifier.Button._20;
case 22:
return Component.Identifier.Button._21;
case 23:
return Component.Identifier.Button._22;
case 24:
return Component.Identifier.Button._23;
case 25:
return Component.Identifier.Button._24;
case 26:
return Component.Identifier.Button._25;
case 27:
return Component.Identifier.Button._26;
case 28:
return Component.Identifier.Button._27;
case 29:
return Component.Identifier.Button._28;
case 30:
return Component.Identifier.Button._29;
case 31:
return Component.Identifier.Button._30;
case 32:
return Component.Identifier.Button._31;
default:
return null;
}
}
public final String toString() {
return "ButtonUsage (" + button_id + ")";
}
}

View file

@ -0,0 +1,74 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.lang.reflect.Method;
/** HID Element types
* @author elias
* @version 1.0
*/
final class ElementType {
private final static ElementType[] map = new ElementType[514];
public final static ElementType INPUT_MISC = new ElementType(1);
public final static ElementType INPUT_BUTTON = new ElementType(2);
public final static ElementType INPUT_AXIS = new ElementType(3);
public final static ElementType INPUT_SCANCODES = new ElementType(4);
public final static ElementType OUTPUT = new ElementType(129);
public final static ElementType FEATURE = new ElementType(257);
public final static ElementType COLLECTION = new ElementType(513);
private final int type_id;
public final static ElementType map(int type_id) {
if (type_id < 0 || type_id >= map.length)
return null;
return map[type_id];
}
private ElementType(int type_id) {
map[type_id] = this;
this.type_id = type_id;
}
public final String toString() {
return "ElementType (0x" + Integer.toHexString(type_id) + ")";
}
}

View file

@ -0,0 +1,142 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
/** Generic Desktop Usages
* @author elias
* @version 1.0
*/
final class GenericDesktopUsage implements Usage {
private final static GenericDesktopUsage[] map = new GenericDesktopUsage[0xFF];
public final static GenericDesktopUsage POINTER = new GenericDesktopUsage(0x01); /* Physical Collection */
public final static GenericDesktopUsage MOUSE = new GenericDesktopUsage(0x02); /* Application Collection */
/* 0x03 Reserved */
public final static GenericDesktopUsage JOYSTICK = new GenericDesktopUsage(0x04); /* Application Collection */
public final static GenericDesktopUsage GAME_PAD = new GenericDesktopUsage(0x05); /* Application Collection */
public final static GenericDesktopUsage KEYBOARD = new GenericDesktopUsage(0x06); /* Application Collection */
public final static GenericDesktopUsage KEYPAD = new GenericDesktopUsage(0x07); /* Application Collection */
public final static GenericDesktopUsage MULTI_AXIS_CONTROLLER = new GenericDesktopUsage(0x08); /* Application Collection */
/* 0x09 - 0x2F Reserved */
public final static GenericDesktopUsage X = new GenericDesktopUsage(0x30); /* Dynamic Value */
public final static GenericDesktopUsage Y = new GenericDesktopUsage(0x31); /* Dynamic Value */
public final static GenericDesktopUsage Z = new GenericDesktopUsage(0x32); /* Dynamic Value */
public final static GenericDesktopUsage RX = new GenericDesktopUsage(0x33); /* Dynamic Value */
public final static GenericDesktopUsage RY = new GenericDesktopUsage(0x34); /* Dynamic Value */
public final static GenericDesktopUsage RZ = new GenericDesktopUsage(0x35); /* Dynamic Value */
public final static GenericDesktopUsage SLIDER = new GenericDesktopUsage(0x36); /* Dynamic Value */
public final static GenericDesktopUsage DIAL = new GenericDesktopUsage(0x37); /* Dynamic Value */
public final static GenericDesktopUsage WHEEL = new GenericDesktopUsage(0x38); /* Dynamic Value */
public final static GenericDesktopUsage HATSWITCH = new GenericDesktopUsage(0x39); /* Dynamic Value */
public final static GenericDesktopUsage COUNTED_BUFFER = new GenericDesktopUsage(0x3A); /* Logical Collection */
public final static GenericDesktopUsage BYTE_COUNT = new GenericDesktopUsage(0x3B); /* Dynamic Value */
public final static GenericDesktopUsage MOTION_WAKEUP = new GenericDesktopUsage(0x3C); /* One-Shot Control */
public final static GenericDesktopUsage START = new GenericDesktopUsage(0x3D); /* On/Off Control */
public final static GenericDesktopUsage SELECT = new GenericDesktopUsage(0x3E); /* On/Off Control */
/* 0x3F Reserved */
public final static GenericDesktopUsage VX = new GenericDesktopUsage(0x40); /* Dynamic Value */
public final static GenericDesktopUsage VY = new GenericDesktopUsage(0x41); /* Dynamic Value */
public final static GenericDesktopUsage VZ = new GenericDesktopUsage(0x42); /* Dynamic Value */
public final static GenericDesktopUsage VBRX = new GenericDesktopUsage(0x43); /* Dynamic Value */
public final static GenericDesktopUsage VBRY = new GenericDesktopUsage(0x44); /* Dynamic Value */
public final static GenericDesktopUsage VBRZ = new GenericDesktopUsage(0x45); /* Dynamic Value */
public final static GenericDesktopUsage VNO = new GenericDesktopUsage(0x46); /* Dynamic Value */
/* 0x47 - 0x7F Reserved */
public final static GenericDesktopUsage SYSTEM_CONTROL = new GenericDesktopUsage(0x80); /* Application Collection */
public final static GenericDesktopUsage SYSTEM_POWER_DOWN = new GenericDesktopUsage(0x81); /* One-Shot Control */
public final static GenericDesktopUsage SYSTEM_SLEEP = new GenericDesktopUsage(0x82); /* One-Shot Control */
public final static GenericDesktopUsage SYSTEM_WAKE_UP = new GenericDesktopUsage(0x83); /* One-Shot Control */
public final static GenericDesktopUsage SYSTEM_CONTEXT_MENU = new GenericDesktopUsage(0x84); /* One-Shot Control */
public final static GenericDesktopUsage SYSTEM_MAIN_MENU = new GenericDesktopUsage(0x85); /* One-Shot Control */
public final static GenericDesktopUsage SYSTEM_APP_MENU = new GenericDesktopUsage(0x86); /* One-Shot Control */
public final static GenericDesktopUsage SYSTEM_MENU_HELP = new GenericDesktopUsage(0x87); /* One-Shot Control */
public final static GenericDesktopUsage SYSTEM_MENU_EXIT = new GenericDesktopUsage(0x88); /* One-Shot Control */
public final static GenericDesktopUsage SYSTEM_MENU = new GenericDesktopUsage(0x89); /* Selector */
public final static GenericDesktopUsage SYSTEM_MENU_RIGHT = new GenericDesktopUsage(0x8A); /* Re-Trigger Control */
public final static GenericDesktopUsage SYSTEM_MENU_LEFT = new GenericDesktopUsage(0x8B); /* Re-Trigger Control */
public final static GenericDesktopUsage SYSTEM_MENU_UP = new GenericDesktopUsage(0x8C); /* Re-Trigger Control */
public final static GenericDesktopUsage SYSTEM_MENU_DOWN = new GenericDesktopUsage(0x8D); /* Re-Trigger Control */
/* 0x8E - 0x8F Reserved */
public final static GenericDesktopUsage DPAD_UP = new GenericDesktopUsage(0x90); /* On/Off Control */
public final static GenericDesktopUsage DPAD_DOWN = new GenericDesktopUsage(0x91); /* On/Off Control */
public final static GenericDesktopUsage DPAD_RIGHT = new GenericDesktopUsage(0x92); /* On/Off Control */
public final static GenericDesktopUsage DPAD_LEFT = new GenericDesktopUsage(0x93); /* On/Off Control */
/* 0x94 - 0xFFFF Reserved */
private final int usage_id;
public final static GenericDesktopUsage map(int usage_id) {
if (usage_id < 0 || usage_id >= map.length)
return null;
return map[usage_id];
}
private GenericDesktopUsage(int usage_id) {
map[usage_id] = this;
this.usage_id = usage_id;
}
public final String toString() {
return "GenericDesktopUsage (0x" + Integer.toHexString(usage_id) + ")";
}
public final Component.Identifier getIdentifier() {
if (this == GenericDesktopUsage.X) {
return Component.Identifier.Axis.X;
} else if (this == GenericDesktopUsage.Y) {
return Component.Identifier.Axis.Y;
} else if (this == GenericDesktopUsage.Z || this == GenericDesktopUsage.WHEEL) {
return Component.Identifier.Axis.Z;
} else if (this == GenericDesktopUsage.RX) {
return Component.Identifier.Axis.RX;
} else if (this == GenericDesktopUsage.RY) {
return Component.Identifier.Axis.RY;
} else if (this == GenericDesktopUsage.RZ) {
return Component.Identifier.Axis.RZ;
} else if (this == GenericDesktopUsage.SLIDER) {
return Component.Identifier.Axis.SLIDER;
} else if (this == GenericDesktopUsage.HATSWITCH) {
return Component.Identifier.Axis.POV;
} else if (this == GenericDesktopUsage.SELECT) {
return Component.Identifier.Button.SELECT;
} else
return null;
}
}

View file

@ -0,0 +1,251 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.util.Map;
import java.util.HashMap;
/** Mapping from Keyboard HID usages to Component.Identifier.Key
* @author elias
* @version 1.0
*/
final class KeyboardUsage implements Usage {
private final static KeyboardUsage[] map = new KeyboardUsage[0xFF];
public static final KeyboardUsage ERRORROLLOVER = new KeyboardUsage(0x01); /* ErrorRollOver */
public static final KeyboardUsage POSTFAIL = new KeyboardUsage(0x02); /* POSTFail */
public static final KeyboardUsage ERRORUNDEFINED = new KeyboardUsage(0x03); /* ErrorUndefined */
public static final KeyboardUsage A = new KeyboardUsage(Component.Identifier.Key.A, 0x04); /* a or A */
public static final KeyboardUsage B = new KeyboardUsage(Component.Identifier.Key.B, 0x05); /* b or B */
public static final KeyboardUsage C = new KeyboardUsage(Component.Identifier.Key.C, 0x06); /* c or C */
public static final KeyboardUsage D = new KeyboardUsage(Component.Identifier.Key.D, 0x07); /* d or D */
public static final KeyboardUsage E = new KeyboardUsage(Component.Identifier.Key.E, 0x08); /* e or E */
public static final KeyboardUsage F = new KeyboardUsage(Component.Identifier.Key.F, 0x09); /* f or F */
public static final KeyboardUsage G = new KeyboardUsage(Component.Identifier.Key.G, 0x0A); /* g or G */
public static final KeyboardUsage H = new KeyboardUsage(Component.Identifier.Key.H, 0x0B); /* h or H */
public static final KeyboardUsage I = new KeyboardUsage(Component.Identifier.Key.I, 0x0C); /* i or I */
public static final KeyboardUsage J = new KeyboardUsage(Component.Identifier.Key.J, 0x0D); /* j or J */
public static final KeyboardUsage K = new KeyboardUsage(Component.Identifier.Key.K, 0x0E); /* k or K */
public static final KeyboardUsage L = new KeyboardUsage(Component.Identifier.Key.L, 0x0F); /* l or L */
public static final KeyboardUsage M = new KeyboardUsage(Component.Identifier.Key.M, 0x10); /* m or M */
public static final KeyboardUsage N = new KeyboardUsage(Component.Identifier.Key.N, 0x11); /* n or N */
public static final KeyboardUsage O = new KeyboardUsage(Component.Identifier.Key.O, 0x12); /* o or O */
public static final KeyboardUsage P = new KeyboardUsage(Component.Identifier.Key.P, 0x13); /* p or P */
public static final KeyboardUsage Q = new KeyboardUsage(Component.Identifier.Key.Q, 0x14); /* q or Q */
public static final KeyboardUsage R = new KeyboardUsage(Component.Identifier.Key.R, 0x15); /* r or R */
public static final KeyboardUsage S = new KeyboardUsage(Component.Identifier.Key.S, 0x16); /* s or S */
public static final KeyboardUsage T = new KeyboardUsage(Component.Identifier.Key.T, 0x17); /* t or T */
public static final KeyboardUsage U = new KeyboardUsage(Component.Identifier.Key.U, 0x18); /* u or U */
public static final KeyboardUsage V = new KeyboardUsage(Component.Identifier.Key.V, 0x19); /* v or V */
public static final KeyboardUsage W = new KeyboardUsage(Component.Identifier.Key.W, 0x1A); /* w or W */
public static final KeyboardUsage X = new KeyboardUsage(Component.Identifier.Key.X, 0x1B); /* x or X */
public static final KeyboardUsage Y = new KeyboardUsage(Component.Identifier.Key.Y, 0x1C); /* y or Y */
public static final KeyboardUsage Z = new KeyboardUsage(Component.Identifier.Key.Z, 0x1D); /* z or Z */
public static final KeyboardUsage _1 = new KeyboardUsage(Component.Identifier.Key._1, 0x1E); /* 1 or ! */
public static final KeyboardUsage _2 = new KeyboardUsage(Component.Identifier.Key._2, 0x1F); /* 2 or @ */
public static final KeyboardUsage _3 = new KeyboardUsage(Component.Identifier.Key._3, 0x20); /* 3 or # */
public static final KeyboardUsage _4 = new KeyboardUsage(Component.Identifier.Key._4, 0x21); /* 4 or $ */
public static final KeyboardUsage _5 = new KeyboardUsage(Component.Identifier.Key._5, 0x22); /* 5 or % */
public static final KeyboardUsage _6 = new KeyboardUsage(Component.Identifier.Key._6, 0x23); /* 6 or ^ */
public static final KeyboardUsage _7 = new KeyboardUsage(Component.Identifier.Key._7, 0x24); /* 7 or & */
public static final KeyboardUsage _8 = new KeyboardUsage(Component.Identifier.Key._8, 0x25); /* 8 or * */
public static final KeyboardUsage _9 = new KeyboardUsage(Component.Identifier.Key._9, 0x26); /* 9 or ( */
public static final KeyboardUsage _0 = new KeyboardUsage(Component.Identifier.Key._0, 0x27); /* 0 or ) */
public static final KeyboardUsage ENTER = new KeyboardUsage(Component.Identifier.Key.RETURN, 0x28); /* Return (Enter) */
public static final KeyboardUsage ESCAPE = new KeyboardUsage(Component.Identifier.Key.ESCAPE, 0x29); /* Escape */
public static final KeyboardUsage BACKSPACE = new KeyboardUsage(Component.Identifier.Key.BACK, 0x2A); /* Delete (Backspace) */
public static final KeyboardUsage TAB = new KeyboardUsage(Component.Identifier.Key.TAB, 0x2B); /* Tab */
public static final KeyboardUsage SPACEBAR = new KeyboardUsage(Component.Identifier.Key.SPACE, 0x2C); /* Spacebar */
public static final KeyboardUsage HYPHEN = new KeyboardUsage(Component.Identifier.Key.MINUS, 0x2D); /* - or _ */
public static final KeyboardUsage EQUALSIGN = new KeyboardUsage(Component.Identifier.Key.EQUALS, 0x2E); /* = or + */
public static final KeyboardUsage OPENBRACKET = new KeyboardUsage(Component.Identifier.Key.LBRACKET, 0x2F); /* [ or { */
public static final KeyboardUsage CLOSEBRACKET = new KeyboardUsage(Component.Identifier.Key.RBRACKET, 0x30); /* ] or } */
public static final KeyboardUsage BACKSLASH = new KeyboardUsage(Component.Identifier.Key.BACKSLASH, 0x31); /* \ or | */
public static final KeyboardUsage NONUSPOUNT = new KeyboardUsage(Component.Identifier.Key.PERIOD, 0x32); /* Non-US # or _ */
public static final KeyboardUsage SEMICOLON = new KeyboardUsage(Component.Identifier.Key.SEMICOLON, 0x33); /* ; or : */
public static final KeyboardUsage QUOTE = new KeyboardUsage(Component.Identifier.Key.APOSTROPHE, 0x34); /* ' or " */
public static final KeyboardUsage TILDE = new KeyboardUsage(Component.Identifier.Key.GRAVE, 0x35); /* Grave Accent and Tilde */
public static final KeyboardUsage COMMA = new KeyboardUsage(Component.Identifier.Key.COMMA, 0x36); /* , or < */
public static final KeyboardUsage PERIOD = new KeyboardUsage(Component.Identifier.Key.PERIOD, 0x37); /* . or > */
public static final KeyboardUsage SLASH = new KeyboardUsage(Component.Identifier.Key.SLASH, 0x38); /* / or ? */
public static final KeyboardUsage CAPSLOCK = new KeyboardUsage(Component.Identifier.Key.CAPITAL, 0x39); /* Caps Lock */
public static final KeyboardUsage F1 = new KeyboardUsage(Component.Identifier.Key.F1, 0x3A); /* F1 */
public static final KeyboardUsage F2 = new KeyboardUsage(Component.Identifier.Key.F2, 0x3B); /* F2 */
public static final KeyboardUsage F3 = new KeyboardUsage(Component.Identifier.Key.F3, 0x3C); /* F3 */
public static final KeyboardUsage F4 = new KeyboardUsage(Component.Identifier.Key.F4, 0x3D); /* F4 */
public static final KeyboardUsage F5 = new KeyboardUsage(Component.Identifier.Key.F5, 0x3E); /* F5 */
public static final KeyboardUsage F6 = new KeyboardUsage(Component.Identifier.Key.F6, 0x3F); /* F6 */
public static final KeyboardUsage F7 = new KeyboardUsage(Component.Identifier.Key.F7, 0x40); /* F7 */
public static final KeyboardUsage F8 = new KeyboardUsage(Component.Identifier.Key.F8, 0x41); /* F8 */
public static final KeyboardUsage F9 = new KeyboardUsage(Component.Identifier.Key.F9, 0x42); /* F9 */
public static final KeyboardUsage F10 = new KeyboardUsage(Component.Identifier.Key.F10, 0x43); /* F10 */
public static final KeyboardUsage F11 = new KeyboardUsage(Component.Identifier.Key.F11, 0x44); /* F11 */
public static final KeyboardUsage F12 = new KeyboardUsage(Component.Identifier.Key.F12, 0x45); /* F12 */
public static final KeyboardUsage PRINTSCREEN = new KeyboardUsage(Component.Identifier.Key.SYSRQ, 0x46); /* PrintScreen */
public static final KeyboardUsage SCROLLLOCK = new KeyboardUsage(Component.Identifier.Key.SCROLL, 0x47); /* Scroll Lock */
public static final KeyboardUsage PAUSE = new KeyboardUsage(Component.Identifier.Key.PAUSE, 0x48); /* Pause */
public static final KeyboardUsage INSERT = new KeyboardUsage(Component.Identifier.Key.INSERT, 0x49); /* Insert */
public static final KeyboardUsage HOME = new KeyboardUsage(Component.Identifier.Key.HOME, 0x4A); /* Home */
public static final KeyboardUsage PAGEUP = new KeyboardUsage(Component.Identifier.Key.PAGEUP, 0x4B); /* Page Up */
public static final KeyboardUsage DELETE = new KeyboardUsage(Component.Identifier.Key.DELETE, 0x4C); /* Delete Forward */
public static final KeyboardUsage END = new KeyboardUsage(Component.Identifier.Key.END, 0x4D); /* End */
public static final KeyboardUsage PAGEDOWN = new KeyboardUsage(Component.Identifier.Key.PAGEDOWN, 0x4E); /* Page Down */
public static final KeyboardUsage RIGHTARROW = new KeyboardUsage(Component.Identifier.Key.RIGHT, 0x4F); /* Right Arrow */
public static final KeyboardUsage LEFTARROW = new KeyboardUsage(Component.Identifier.Key.LEFT, 0x50); /* Left Arrow */
public static final KeyboardUsage DOWNARROW = new KeyboardUsage(Component.Identifier.Key.DOWN, 0x51); /* Down Arrow */
public static final KeyboardUsage UPARROW = new KeyboardUsage(Component.Identifier.Key.UP, 0x52); /* Up Arrow */
public static final KeyboardUsage KEYPAD_NUMLOCK = new KeyboardUsage(Component.Identifier.Key.NUMLOCK, 0x53); /* Keypad NumLock or Clear */
public static final KeyboardUsage KEYPAD_SLASH = new KeyboardUsage(Component.Identifier.Key.DIVIDE, 0x54); /* Keypad / */
public static final KeyboardUsage KEYPAD_ASTERICK = new KeyboardUsage(0x55); /* Keypad * */
public static final KeyboardUsage KEYPAD_HYPHEN = new KeyboardUsage(Component.Identifier.Key.SUBTRACT, 0x56); /* Keypad - */
public static final KeyboardUsage KEYPAD_PLUS = new KeyboardUsage(Component.Identifier.Key.ADD, 0x57); /* Keypad + */
public static final KeyboardUsage KEYPAD_ENTER = new KeyboardUsage(Component.Identifier.Key.NUMPADENTER, 0x58); /* Keypad Enter */
public static final KeyboardUsage KEYPAD_1 = new KeyboardUsage(Component.Identifier.Key.NUMPAD1, 0x59); /* Keypad 1 or End */
public static final KeyboardUsage KEYPAD_2 = new KeyboardUsage(Component.Identifier.Key.NUMPAD2, 0x5A); /* Keypad 2 or Down Arrow */
public static final KeyboardUsage KEYPAD_3 = new KeyboardUsage(Component.Identifier.Key.NUMPAD3, 0x5B); /* Keypad 3 or Page Down */
public static final KeyboardUsage KEYPAD_4 = new KeyboardUsage(Component.Identifier.Key.NUMPAD4, 0x5C); /* Keypad 4 or Left Arrow */
public static final KeyboardUsage KEYPAD_5 = new KeyboardUsage(Component.Identifier.Key.NUMPAD5, 0x5D); /* Keypad 5 */
public static final KeyboardUsage KEYPAD_6 = new KeyboardUsage(Component.Identifier.Key.NUMPAD6, 0x5E); /* Keypad 6 or Right Arrow */
public static final KeyboardUsage KEYPAD_7 = new KeyboardUsage(Component.Identifier.Key.NUMPAD7, 0x5F); /* Keypad 7 or Home */
public static final KeyboardUsage KEYPAD_8 = new KeyboardUsage(Component.Identifier.Key.NUMPAD8, 0x60); /* Keypad 8 or Up Arrow */
public static final KeyboardUsage KEYPAD_9 = new KeyboardUsage(Component.Identifier.Key.NUMPAD9, 0x61); /* Keypad 9 or Page Up */
public static final KeyboardUsage KEYPAD_0 = new KeyboardUsage(Component.Identifier.Key.NUMPAD0, 0x62); /* Keypad 0 or Insert */
public static final KeyboardUsage KEYPAD_PERIOD = new KeyboardUsage(Component.Identifier.Key.DECIMAL, 0x63); /* Keypad . or Delete */
public static final KeyboardUsage NONUSBACKSLASH = new KeyboardUsage(Component.Identifier.Key.BACKSLASH, 0x64); /* Non-US \ or | */
public static final KeyboardUsage APPLICATION = new KeyboardUsage(Component.Identifier.Key.APPS, 0x65); /* Application */
public static final KeyboardUsage POWER = new KeyboardUsage(Component.Identifier.Key.POWER, 0x66); /* Power */
public static final KeyboardUsage KEYPAD_EQUALSIGN = new KeyboardUsage(Component.Identifier.Key.NUMPADEQUAL, 0x67); /* Keypad = */
public static final KeyboardUsage F13 = new KeyboardUsage(Component.Identifier.Key.F13, 0x68); /* F13 */
public static final KeyboardUsage F14 = new KeyboardUsage(Component.Identifier.Key.F14, 0x69); /* F14 */
public static final KeyboardUsage F15 = new KeyboardUsage(Component.Identifier.Key.F15, 0x6A); /* F15 */
public static final KeyboardUsage F16 = new KeyboardUsage(0x6B); /* F16 */
public static final KeyboardUsage F17 = new KeyboardUsage(0x6C); /* F17 */
public static final KeyboardUsage F18 = new KeyboardUsage(0x6D); /* F18 */
public static final KeyboardUsage F19 = new KeyboardUsage(0x6E); /* F19 */
public static final KeyboardUsage F20 = new KeyboardUsage(0x6F); /* F20 */
public static final KeyboardUsage F21 = new KeyboardUsage(0x70); /* F21 */
public static final KeyboardUsage F22 = new KeyboardUsage(0x71); /* F22 */
public static final KeyboardUsage F23 = new KeyboardUsage(0x72); /* F23 */
public static final KeyboardUsage F24 = new KeyboardUsage(0x73); /* F24 */
public static final KeyboardUsage EXECUTE = new KeyboardUsage(0x74); /* Execute */
public static final KeyboardUsage HELP = new KeyboardUsage(0x75); /* Help */
public static final KeyboardUsage MENU = new KeyboardUsage(0x76); /* Menu */
public static final KeyboardUsage SELECT = new KeyboardUsage(0x77); /* Select */
public static final KeyboardUsage STOP = new KeyboardUsage(Component.Identifier.Key.STOP, 0x78); /* Stop */
public static final KeyboardUsage AGAIN = new KeyboardUsage(0x79); /* Again */
public static final KeyboardUsage UNDO = new KeyboardUsage(0x7A); /* Undo */
public static final KeyboardUsage CUT = new KeyboardUsage(0x7B); /* Cut */
public static final KeyboardUsage COPY = new KeyboardUsage(0x7C); /* Copy */
public static final KeyboardUsage PASTE = new KeyboardUsage(0x7D); /* Paste */
public static final KeyboardUsage FIND = new KeyboardUsage(0x7E); /* Find */
public static final KeyboardUsage MUTE = new KeyboardUsage(0x7F); /* Mute */
public static final KeyboardUsage VOLUMEUP = new KeyboardUsage(0x80); /* Volume Up */
public static final KeyboardUsage VOLUMEDOWN = new KeyboardUsage(0x81); /* Volume Down */
public static final KeyboardUsage LOCKINGCAPSLOCK = new KeyboardUsage(Component.Identifier.Key.CAPITAL, 0x82); /* Locking Caps Lock */
public static final KeyboardUsage LOCKINGNUMLOCK = new KeyboardUsage(Component.Identifier.Key.NUMLOCK, 0x83); /* Locking Num Lock */
public static final KeyboardUsage LOCKINGSCROLLLOCK = new KeyboardUsage(Component.Identifier.Key.SCROLL, 0x84); /* Locking Scroll Lock */
public static final KeyboardUsage KEYPAD_COMMA = new KeyboardUsage(Component.Identifier.Key.COMMA, 0x85); /* Keypad Comma */
public static final KeyboardUsage KEYPAD_EQUALSSIGNAS400 = new KeyboardUsage(0x86); /* Keypad Equal Sign for AS/400 */
public static final KeyboardUsage INTERNATIONAL1 = new KeyboardUsage(0x87); /* International1 */
public static final KeyboardUsage INTERNATIONAL2 = new KeyboardUsage(0x88); /* International2 */
public static final KeyboardUsage INTERNATIONAL3 = new KeyboardUsage(0x89); /* International3 */
public static final KeyboardUsage INTERNATIONAL4 = new KeyboardUsage(0x8A); /* International4 */
public static final KeyboardUsage INTERNATIONAL5 = new KeyboardUsage(0x8B); /* International5 */
public static final KeyboardUsage INTERNATIONAL6 = new KeyboardUsage(0x8C); /* International6 */
public static final KeyboardUsage INTERNATIONAL7 = new KeyboardUsage(0x8D); /* International7 */
public static final KeyboardUsage INTERNATIONAL8 = new KeyboardUsage(0x8E); /* International8 */
public static final KeyboardUsage INTERNATIONAL9 = new KeyboardUsage(0x8F); /* International9 */
public static final KeyboardUsage LANG1 = new KeyboardUsage(0x90); /* LANG1 */
public static final KeyboardUsage LANG2 = new KeyboardUsage(0x91); /* LANG2 */
public static final KeyboardUsage LANG3 = new KeyboardUsage(0x92); /* LANG3 */
public static final KeyboardUsage LANG4 = new KeyboardUsage(0x93); /* LANG4 */
public static final KeyboardUsage LANG5 = new KeyboardUsage(0x94); /* LANG5 */
public static final KeyboardUsage LANG6 = new KeyboardUsage(0x95); /* LANG6 */
public static final KeyboardUsage LANG7 = new KeyboardUsage(0x96); /* LANG7 */
public static final KeyboardUsage LANG8 = new KeyboardUsage(0x97); /* LANG8 */
public static final KeyboardUsage LANG9 = new KeyboardUsage(0x98); /* LANG9 */
public static final KeyboardUsage ALTERNATEERASE = new KeyboardUsage(0x99); /* AlternateErase */
public static final KeyboardUsage SYSREQORATTENTION = new KeyboardUsage(Component.Identifier.Key.SYSRQ, 0x9A); /* SysReq/Attention */
public static final KeyboardUsage CANCEL = new KeyboardUsage(0x9B); /* Cancel */
public static final KeyboardUsage CLEAR = new KeyboardUsage(0x9C); /* Clear */
public static final KeyboardUsage PRIOR = new KeyboardUsage(Component.Identifier.Key.PAGEUP, 0x9D); /* Prior */
public static final KeyboardUsage RETURN = new KeyboardUsage(Component.Identifier.Key.RETURN, 0x9E); /* Return */
public static final KeyboardUsage SEPARATOR = new KeyboardUsage(0x9F); /* Separator */
public static final KeyboardUsage OUT = new KeyboardUsage(0xA0); /* Out */
public static final KeyboardUsage OPER = new KeyboardUsage(0xA1); /* Oper */
public static final KeyboardUsage CLEARORAGAIN = new KeyboardUsage(0xA2); /* Clear/Again */
public static final KeyboardUsage CRSELORPROPS = new KeyboardUsage(0xA3); /* CrSel/Props */
public static final KeyboardUsage EXSEL = new KeyboardUsage(0xA4); /* ExSel */
/* 0xA5-0xDF Reserved */
public static final KeyboardUsage LEFTCONTROL = new KeyboardUsage(Component.Identifier.Key.LCONTROL, 0xE0); /* Left Control */
public static final KeyboardUsage LEFTSHIFT = new KeyboardUsage(Component.Identifier.Key.LSHIFT, 0xE1); /* Left Shift */
public static final KeyboardUsage LEFTALT = new KeyboardUsage(Component.Identifier.Key.LALT, 0xE2); /* Left Alt */
public static final KeyboardUsage LEFTGUI = new KeyboardUsage(Component.Identifier.Key.LWIN, 0xE3); /* Left GUI */
public static final KeyboardUsage RIGHTCONTROL = new KeyboardUsage(Component.Identifier.Key.RCONTROL, 0xE4); /* Right Control */
public static final KeyboardUsage RIGHTSHIFT = new KeyboardUsage(Component.Identifier.Key.RSHIFT, 0xE5); /* Right Shift */
public static final KeyboardUsage RIGHTALT = new KeyboardUsage(Component.Identifier.Key.RALT, 0xE6); /* Right Alt */
public static final KeyboardUsage RIGHTGUI = new KeyboardUsage(Component.Identifier.Key.RWIN, 0xE7); /* Right GUI */
private final int usage;
private final Component.Identifier.Key identifier;
public final Component.Identifier.Key getIdentifier() {
return identifier;
}
public final static KeyboardUsage map(int usage) {
if (usage < 0 || usage >= map.length)
return null;
return map[usage];
}
private KeyboardUsage(int usage) {
this(Component.Identifier.Key.UNKNOWN, usage);
}
private KeyboardUsage(Component.Identifier.Key id, int usage) {
this.identifier = id;
this.usage = usage;
map[usage] = this;
}
public final String toString() {
return "KeyboardUsage (0x" + Integer.toHexString(usage) + ")";
}
}

View file

@ -0,0 +1,74 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
/** Represents an OSX AbstractController
* @author elias
* @version 1.0
*/
final class OSXAbstractController extends AbstractController {
private final PortType port;
private final OSXHIDQueue queue;
private final Type type;
protected OSXAbstractController(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers, Type type) {
super(device.getProductName(), components, children, rumblers);
this.queue = queue;
this.type = type;
this.port = device.getPortType();
}
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return OSXControllers.getNextDeviceEvent(event, queue);
}
protected final void setDeviceEventQueueSize(int size) throws IOException {
queue.setQueueDepth(size);
}
public Type getType() {
return type;
}
public final PortType getPortType() {
return port;
}
}

View file

@ -0,0 +1,70 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
/** Represents an OSX Component
* @author elias
* @version 1.0
*/
class OSXComponent extends AbstractComponent {
private final OSXHIDElement element;
public OSXComponent(Component.Identifier id, OSXHIDElement element) {
super(id.getName(), id);
this.element = element;
}
public final boolean isRelative() {
return element.isRelative();
}
public boolean isAnalog() {
return element.isAnalog();
}
public final OSXHIDElement getElement() {
return element;
}
protected float poll() throws IOException {
return OSXControllers.poll(element);
}
}

View file

@ -0,0 +1,64 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
/** helper methods for OSX specific Controllers
* @author elias
* @version 1.0
*/
final class OSXControllers {
private final static OSXEvent osx_event = new OSXEvent();
public final static synchronized float poll(OSXHIDElement element) throws IOException {
element.getElementValue(osx_event);
return element.convertValue(osx_event.getValue());
}
/* synchronized to protect osx_event */
public final static synchronized boolean getNextDeviceEvent(Event event, OSXHIDQueue queue) throws IOException {
if (queue.getNextEvent(osx_event)) {
OSXComponent component = queue.mapEvent(osx_event);
event.set(component, component.getElement().convertValue(osx_event.getValue()), osx_event.getNanos());
return true;
} else
return false;
}
}

View file

@ -0,0 +1,288 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;
import net.java.games.util.plugins.Plugin;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** OSX HIDManager implementation
* @author elias
* @author gregorypierce
* @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() {
try {
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);
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
supported = false;
}
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 {
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) {
String os_version = System.getProperty("os.version");
StringTokenizer version_tokenizer = new StringTokenizer(os_version, ".");
int major;
int minor;
try {
String major_str = version_tokenizer.nextToken();
String minor_str = version_tokenizer.nextToken();
major = Integer.parseInt(major_str);
minor = Integer.parseInt(minor_str);
} catch (Exception e) {
logln("Exception occurred while trying to determine OS version: " + e);
// Best guess, no
return false;
}
return major > major_required || (major == major_required && minor >= minor_required);
}
private final Controller[] controllers;
public OSXEnvironmentPlugin() {
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()) {
OSXHIDElement element = (OSXHIDElement)it.next();
Component.Identifier id = element.getIdentifier();
if (id == null)
continue;
if (map_mouse_buttons) {
if (id == Component.Identifier.Button._0) {
id = Component.Identifier.Button.LEFT;
} else if (id == Component.Identifier.Button._1) {
id = Component.Identifier.Button.RIGHT;
} else if (id == Component.Identifier.Button._2) {
id = Component.Identifier.Button.MIDDLE;
}
}
OSXComponent component = new OSXComponent(id, element);
components.add(component);
queue.addElement(element, component);
}
}
private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List elements) throws IOException {
List components = new ArrayList();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try {
addElements(queue, elements, components, false);
} catch (IOException e) {
queue.release();
throw e;
}
Component[] components_array = new Component[components.size()];
components.toArray(components_array);
Keyboard keyboard = new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
return keyboard;
}
private final static Mouse createMouseFromDevice(OSXHIDDevice device, List elements) throws IOException {
List components = new ArrayList();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try {
addElements(queue, elements, components, true);
} catch (IOException e) {
queue.release();
throw e;
}
Component[] components_array = new Component[components.size()];
components.toArray(components_array);
Mouse mouse = new OSXMouse(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
if (mouse.getPrimaryButton() != null && mouse.getX() != null && mouse.getY() != null) {
return mouse;
} else {
queue.release();
return null;
}
}
private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List elements, Controller.Type type) throws IOException {
List components = new ArrayList();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try {
addElements(queue, elements, components, false);
} catch (IOException e) {
queue.release();
throw e;
}
Component[] components_array = new Component[components.size()];
components.toArray(components_array);
AbstractController controller = new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type);
return controller;
}
private final static void createControllersFromDevice(OSXHIDDevice device, List controllers) throws IOException {
UsagePair usage_pair = device.getUsagePair();
if (usage_pair == null)
return;
List elements = device.getElements();
if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.MOUSE ||
usage_pair.getUsage() == GenericDesktopUsage.POINTER)) {
Controller mouse = createMouseFromDevice(device, elements);
if (mouse != null)
controllers.add(mouse);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.KEYBOARD ||
usage_pair.getUsage() == GenericDesktopUsage.KEYPAD)) {
Controller keyboard = createKeyboardFromDevice(device, elements);
if (keyboard != null)
controllers.add(keyboard);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.JOYSTICK) {
Controller joystick = createControllerFromDevice(device, elements, Controller.Type.STICK);
if (joystick != null)
controllers.add(joystick);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.MULTI_AXIS_CONTROLLER) {
Controller multiaxis = createControllerFromDevice(device, elements, Controller.Type.STICK);
if (multiaxis != null)
controllers.add(multiaxis);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.GAME_PAD) {
Controller game_pad = createControllerFromDevice(device, elements, Controller.Type.GAMEPAD);
if (game_pad != null)
controllers.add(game_pad);
}
}
private final static Controller[] enumerateControllers() {
List controllers = new ArrayList();
try {
OSXHIDDeviceIterator it = new OSXHIDDeviceIterator();
try {
while (true) {
OSXHIDDevice device;
try {
device = it.next();
if (device == null)
break;
boolean device_used = false;
try {
int old_size = controllers.size();
createControllersFromDevice(device, controllers);
device_used = old_size != controllers.size();
} catch (IOException e) {
logln("Failed to create controllers from device: " + device.getProductName());
}
if (!device_used)
device.release();
} catch (IOException e) {
logln("Failed to enumerate device: " + e.getMessage());
}
}
} finally {
it.close();
}
} catch (IOException e) {
log("Failed to enumerate devices: " + e.getMessage());
return new Controller[]{};
}
Controller[] controllers_array = new Controller[controllers.size()];
controllers.toArray(controllers_array);
return controllers_array;
}
}

View file

@ -0,0 +1,73 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
/** OSX Event structure corresponding to IOHIDEventStruct
* @author elias
* @version 1.0
*/
class OSXEvent {
private long type;
private long cookie;
private int value;
private long nanos;
public void set(long type, long cookie, int value, long nanos) {
this.type = type;
this.cookie = cookie;
this.value = value;
this.nanos = nanos;
}
public long getType() {
return type;
}
public long getCookie() {
return cookie;
}
public int getValue() {
return value;
}
public long getNanos() {
return nanos;
}
}

View file

@ -0,0 +1,320 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Iterator;
import java.util.logging.Logger;
/** OSX HIDManager implementation
* @author elias
* @author gregorypierce
* @version 1.0
*/
final class OSXHIDDevice {
private final static Logger log = Logger.getLogger(OSXHIDDevice.class.getName());
private final static int AXIS_DEFAULT_MIN_VALUE = 0;
private final static int AXIS_DEFAULT_MAX_VALUE = 64*1024;
private final static String kIOHIDTransportKey = "Transport";
private final static String kIOHIDVendorIDKey = "VendorID";
private final static String kIOHIDVendorIDSourceKey = "VendorIDSource";
private final static String kIOHIDProductIDKey = "ProductID";
private final static String kIOHIDVersionNumberKey = "VersionNumber";
private final static String kIOHIDManufacturerKey = "Manufacturer";
private final static String kIOHIDProductKey = "Product";
private final static String kIOHIDSerialNumberKey = "SerialNumber";
private final static String kIOHIDCountryCodeKey = "CountryCode";
private final static String kIOHIDLocationIDKey = "LocationID";
private final static String kIOHIDDeviceUsageKey = "DeviceUsage";
private final static String kIOHIDDeviceUsagePageKey = "DeviceUsagePage";
private final static String kIOHIDDeviceUsagePairsKey = "DeviceUsagePairs";
private final static String kIOHIDPrimaryUsageKey = "PrimaryUsage";
private final static String kIOHIDPrimaryUsagePageKey = "PrimaryUsagePage";
private final static String kIOHIDMaxInputReportSizeKey = "MaxInputReportSize";
private final static String kIOHIDMaxOutputReportSizeKey = "MaxOutputReportSize";
private final static String kIOHIDMaxFeatureReportSizeKey = "MaxFeatureReportSize";
private final static String kIOHIDElementKey = "Elements";
private final static String kIOHIDElementCookieKey = "ElementCookie";
private final static String kIOHIDElementTypeKey = "Type";
private final static String kIOHIDElementCollectionTypeKey = "CollectionType";
private final static String kIOHIDElementUsageKey = "Usage";
private final static String kIOHIDElementUsagePageKey = "UsagePage";
private final static String kIOHIDElementMinKey = "Min";
private final static String kIOHIDElementMaxKey = "Max";
private final static String kIOHIDElementScaledMinKey = "ScaledMin";
private final static String kIOHIDElementScaledMaxKey = "ScaledMax";
private final static String kIOHIDElementSizeKey = "Size";
private final static String kIOHIDElementReportSizeKey = "ReportSize";
private final static String kIOHIDElementReportCountKey = "ReportCount";
private final static String kIOHIDElementReportIDKey = "ReportID";
private final static String kIOHIDElementIsArrayKey = "IsArray";
private final static String kIOHIDElementIsRelativeKey = "IsRelative";
private final static String kIOHIDElementIsWrappingKey = "IsWrapping";
private final static String kIOHIDElementIsNonLinearKey = "IsNonLinear";
private final static String kIOHIDElementHasPreferredStateKey = "HasPreferredState";
private final static String kIOHIDElementHasNullStateKey = "HasNullState";
private final static String kIOHIDElementUnitKey = "Unit";
private final static String kIOHIDElementUnitExponentKey = "UnitExponent";
private final static String kIOHIDElementNameKey = "Name";
private final static String kIOHIDElementValueLocationKey = "ValueLocation";
private final static String kIOHIDElementDuplicateIndexKey = "DuplicateIndex";
private final static String kIOHIDElementParentCollectionKey = "ParentCollection";
private final long device_address;
private final long device_interface_address;
private final Map properties;
private boolean released;
public OSXHIDDevice(long device_address, long device_interface_address) throws IOException {
this.device_address = device_address;
this.device_interface_address = device_interface_address;
this.properties = getDeviceProperties();
open();
}
public final Controller.PortType getPortType() {
String transport = (String)properties.get(kIOHIDTransportKey);
if (transport == null)
return Controller.PortType.UNKNOWN;
if (transport.equals("USB")) {
return Controller.PortType.USB;
} else {
return Controller.PortType.UNKNOWN;
}
}
public final String getProductName() {
return (String)properties.get(kIOHIDProductKey);
}
private final OSXHIDElement createElementFromElementProperties(Map element_properties) {
/* long size = getLongFromProperties(element_properties, kIOHIDElementSizeKey);
// ignore elements that can't fit into the 32 bit value field of a hid event
if (size > 32)
return null;*/
long element_cookie = getLongFromProperties(element_properties, kIOHIDElementCookieKey);
int element_type_id = getIntFromProperties(element_properties, kIOHIDElementTypeKey);
ElementType element_type = ElementType.map(element_type_id);
int min = (int)getLongFromProperties(element_properties, kIOHIDElementMinKey, AXIS_DEFAULT_MIN_VALUE);
int max = (int)getLongFromProperties(element_properties, kIOHIDElementMaxKey, AXIS_DEFAULT_MAX_VALUE);
/* long scaled_min = getLongFromProperties(element_properties, kIOHIDElementScaledMinKey, Long.MIN_VALUE);
long scaled_max = getLongFromProperties(element_properties, kIOHIDElementScaledMaxKey, Long.MAX_VALUE);*/
UsagePair device_usage_pair = getUsagePair();
boolean default_relative = device_usage_pair != null && (device_usage_pair.getUsage() == GenericDesktopUsage.POINTER || device_usage_pair.getUsage() == GenericDesktopUsage.MOUSE);
boolean is_relative = getBooleanFromProperties(element_properties, kIOHIDElementIsRelativeKey, default_relative);
/* boolean is_wrapping = getBooleanFromProperties(element_properties, kIOHIDElementIsWrappingKey);
boolean is_non_linear = getBooleanFromProperties(element_properties, kIOHIDElementIsNonLinearKey);
boolean has_preferred_state = getBooleanFromProperties(element_properties, kIOHIDElementHasPreferredStateKey);
boolean has_null_state = getBooleanFromProperties(element_properties, kIOHIDElementHasNullStateKey);*/
int usage = getIntFromProperties(element_properties, kIOHIDElementUsageKey);
int usage_page = getIntFromProperties(element_properties, kIOHIDElementUsagePageKey);
UsagePair usage_pair = createUsagePair(usage_page, usage);
if (usage_pair == null || (element_type != ElementType.INPUT_MISC && element_type != ElementType.INPUT_BUTTON && element_type != ElementType.INPUT_AXIS)) {
//log.info("element_type = 0x" + element_type + " | usage = " + usage + " | usage_page = " + usage_page);
return null;
} else {
return new OSXHIDElement(this, usage_pair, element_cookie, element_type, min, max, is_relative);
}
}
private final void addElements(List elements, Map properties) {
Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey);
if (elements_properties == null)
return;
for (int i = 0; i < elements_properties.length; i++) {
Map element_properties = (Map)elements_properties[i];
OSXHIDElement element = createElementFromElementProperties(element_properties);
if (element != null) {
elements.add(element);
}
addElements(elements, element_properties);
}
}
public final List getElements() {
List elements = new ArrayList();
addElements(elements, properties);
return elements;
}
private final static long getLongFromProperties(Map properties, String key, long default_value) {
Long long_obj = (Long)properties.get(key);
if (long_obj == null)
return default_value;
return long_obj.longValue();
}
private final static boolean getBooleanFromProperties(Map properties, String key, boolean default_value) {
return getLongFromProperties(properties, key, default_value ? 1 : 0) != 0;
}
private final static int getIntFromProperties(Map properties, String key) {
return (int)getLongFromProperties(properties, key);
}
private final static long getLongFromProperties(Map properties, String key) {
Long long_obj = (Long)properties.get(key);
return long_obj.longValue();
}
private final static UsagePair createUsagePair(int usage_page_id, int usage_id) {
UsagePage usage_page = UsagePage.map(usage_page_id);
if (usage_page != null) {
Usage usage = usage_page.mapUsage(usage_id);
if (usage != null)
return new UsagePair(usage_page, usage);
}
return null;
}
public final UsagePair getUsagePair() {
int usage_page_id = getIntFromProperties(properties, kIOHIDPrimaryUsagePageKey);
int usage_id = getIntFromProperties(properties, kIOHIDPrimaryUsageKey);
return createUsagePair(usage_page_id, usage_id);
}
/*
public final List getUsagePairs() {
List usage_pairs_list = new ArrayList();
Object[] usage_pairs = (Object[])properties.get(kIOHIDDeviceUsagePairsKey);
if (usage_pairs == null) {
int usage_page_id = getIntFromProperties(properties, kIOHIDPrimaryUsagePageKey);
int usage_id = getIntFromProperties(properties, kIOHIDPrimaryUsageKey);
UsagePair pair = createUsagePair(usage_page_id, usage_id);
if (pair != null)
usage_pairs_list.add(pair);
}
for (int i = 0; i < usage_pairs.length; i++) {
Map usage_pair = (Map)usage_pairs[i];
int usage_page_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsagePageKey);
int usage_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsageKey);
UsagePair pair = createUsagePair(usage_page_id, usage_id);
if (pair != null)
usage_pairs_list.add(pair);
}
return usage_pairs_list;
}
*/
private final void dumpProperties() {
log.info(toString());
dumpMap("", properties);
}
private final static void dumpArray(String prefix, Object[] array) {
log.info(prefix + "{");
for (int i = 0; i < array.length; i++) {
dumpObject(prefix + "\t", array[i]);
log.info(prefix + ",");
}
log.info(prefix + "}");
}
private final static void dumpMap(String prefix, Map map) {
Iterator keys = map.keySet().iterator();
while (keys.hasNext()) {
Object key = keys.next();
Object value = map.get(key);
dumpObject(prefix, key);
dumpObject(prefix + "\t", value);
}
}
private final static void dumpObject(String prefix, Object obj) {
if (obj instanceof Long) {
Long l = (Long)obj;
log.info(prefix + "0x" + Long.toHexString(l.longValue()));
} else if (obj instanceof Map)
dumpMap(prefix, (Map)obj);
else if (obj.getClass().isArray())
dumpArray(prefix, (Object[])obj);
else
log.info(prefix + obj);
}
private final Map getDeviceProperties() throws IOException {
return nGetDeviceProperties(device_address);
}
private final static native Map nGetDeviceProperties(long device_address) throws IOException;
public final synchronized void release() throws IOException {
try {
close();
} finally {
released = true;
nReleaseDevice(device_address, device_interface_address);
}
}
private final static native void nReleaseDevice(long device_address, long device_interface_address);
public final synchronized void getElementValue(long element_cookie, OSXEvent event) throws IOException {
checkReleased();
nGetElementValue(device_interface_address, element_cookie, event);
}
private final static native void nGetElementValue(long device_interface_address, long element_cookie, OSXEvent event) throws IOException;
public final synchronized OSXHIDQueue createQueue(int queue_depth) throws IOException {
checkReleased();
long queue_address = nCreateQueue(device_interface_address);
return new OSXHIDQueue(queue_address, queue_depth);
}
private final static native long nCreateQueue(long device_interface_address) throws IOException;
private final void open() throws IOException {
nOpen(device_interface_address);
}
private final static native void nOpen(long device_interface_address) throws IOException;
private final void close() throws IOException {
nClose(device_interface_address);
}
private final static native void nClose(long device_interface_address) throws IOException;
private final void checkReleased() throws IOException {
if (released)
throw new IOException();
}
}

View file

@ -0,0 +1,65 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
/** OSX HIDManager implementation
* @author elias
* @author gregorypierce
* @version 1.0
*/
final class OSXHIDDeviceIterator {
private final long iterator_address;
public OSXHIDDeviceIterator() throws IOException {
this.iterator_address = nCreateIterator();
}
private final static native long nCreateIterator();
public final void close(){
nReleaseIterator(iterator_address);
}
private final static native void nReleaseIterator(long iterator_address);
public final OSXHIDDevice next() throws IOException {
return nNext(iterator_address);
}
private final static native OSXHIDDevice nNext(long iterator_address) throws IOException;
}

View file

@ -0,0 +1,143 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
/** Represents an OSX HID Element
* @author elias
* @author gregorypierce
* @version 1.0
*/
final class OSXHIDElement {
private final OSXHIDDevice device;
private final UsagePair usage_pair;
private final long element_cookie;
private final ElementType element_type;
private final int min;
private final int max;
private final Component.Identifier identifier;
private final boolean is_relative;
public OSXHIDElement(OSXHIDDevice device, UsagePair usage_pair, long element_cookie, ElementType element_type, int min, int max, boolean is_relative) {
this.device = device;
this.usage_pair = usage_pair;
this.element_cookie = element_cookie;
this.element_type = element_type;
this.min = min;
this.max = max;
this.identifier = computeIdentifier();
this.is_relative = is_relative;
}
private final Component.Identifier computeIdentifier() {
if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP) {
return ((GenericDesktopUsage)usage_pair.getUsage()).getIdentifier();
} else if (usage_pair.getUsagePage() == UsagePage.BUTTON) {
return ((ButtonUsage)usage_pair.getUsage()).getIdentifier();
} else if (usage_pair.getUsagePage() == UsagePage.KEYBOARD_OR_KEYPAD) {
return ((KeyboardUsage)usage_pair.getUsage()).getIdentifier();
} else
return null;
}
final Component.Identifier getIdentifier() {
return identifier;
}
final long getCookie() {
return element_cookie;
}
final ElementType getType() {
return element_type;
}
final boolean isRelative() {
return is_relative && identifier instanceof Component.Identifier.Axis;
}
final boolean isAnalog() {
return identifier instanceof Component.Identifier.Axis && identifier != Component.Identifier.Axis.POV;
}
private UsagePair getUsagePair() {
return usage_pair;
}
final void getElementValue(OSXEvent event) throws IOException {
device.getElementValue(element_cookie, event);
}
final float convertValue(float value) {
if (identifier == Component.Identifier.Axis.POV) {
switch ((int)value) {
case 0:
return Component.POV.UP;
case 1:
return Component.POV.UP_RIGHT;
case 2:
return Component.POV.RIGHT;
case 3:
return Component.POV.DOWN_RIGHT;
case 4:
return Component.POV.DOWN;
case 5:
return Component.POV.DOWN_LEFT;
case 6:
return Component.POV.LEFT;
case 7:
return Component.POV.UP_LEFT;
case 8:
return Component.POV.OFF;
default:
return Component.POV.OFF;
}
} else if (identifier instanceof Component.Identifier.Axis && !is_relative) {
if (min == max)
return 0;
else if (value > max)
value = max;
else if (value < min)
value = min;
return 2*(value - min)/(max - min) - 1;
} else
return value;
}
}

View file

@ -0,0 +1,141 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
/**
* @author elias
* @version 1.0
*/
final class OSXHIDQueue {
private final Map map = new HashMap();
private final long queue_address;
private boolean released;
public OSXHIDQueue(long address, int queue_depth) throws IOException {
this.queue_address = address;
try {
createQueue(queue_depth);
} catch (IOException e) {
release();
throw e;
}
}
public final synchronized void setQueueDepth(int queue_depth) throws IOException {
checkReleased();
stop();
close();
createQueue(queue_depth);
}
private final void createQueue(int queue_depth) throws IOException {
open(queue_depth);
try {
start();
} catch (IOException e) {
close();
throw e;
}
}
public final OSXComponent mapEvent(OSXEvent event) {
return (OSXComponent)map.get(new Long(event.getCookie()));
}
private final void open(int queue_depth) throws IOException {
nOpen(queue_address, queue_depth);
}
private final static native void nOpen(long queue_address, int queue_depth) throws IOException;
private final void close() throws IOException {
nClose(queue_address);
}
private final static native void nClose(long queue_address) throws IOException;
private final void start() throws IOException {
nStart(queue_address);
}
private final static native void nStart(long queue_address) throws IOException;
private final void stop() throws IOException {
nStop(queue_address);
}
private final static native void nStop(long queue_address) throws IOException;
public final synchronized void release() throws IOException {
if (!released) {
released = true;
try {
stop();
close();
} finally {
nReleaseQueue(queue_address);
}
}
}
private final static native void nReleaseQueue(long queue_address) throws IOException;
public final void addElement(OSXHIDElement element, OSXComponent component) throws IOException {
nAddElement(queue_address, element.getCookie());
map.put(new Long(element.getCookie()), component);
}
private final static native void nAddElement(long queue_address, long cookie) throws IOException;
public final void removeElement(OSXHIDElement element) throws IOException {
nRemoveElement(queue_address, element.getCookie());
map.remove(new Long(element.getCookie()));
}
private final static native void nRemoveElement(long queue_address, long cookie) throws IOException;
public final synchronized boolean getNextEvent(OSXEvent event) throws IOException {
checkReleased();
return nGetNextEvent(queue_address, event);
}
private final static native boolean nGetNextEvent(long queue_address, OSXEvent event) throws IOException;
private final void checkReleased() throws IOException {
if (released)
throw new IOException("Queue is released");
}
}

View file

@ -0,0 +1,68 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
/** Represents an OSX Keyboard
* @author elias
* @version 1.0
*/
final class OSXKeyboard extends Keyboard {
private final PortType port;
private final OSXHIDQueue queue;
protected OSXKeyboard(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers) {
super(device.getProductName(), components, children, rumblers);
this.queue = queue;
this.port = device.getPortType();
}
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return OSXControllers.getNextDeviceEvent(event, queue);
}
protected final void setDeviceEventQueueSize(int size) throws IOException {
queue.setQueueDepth(size);
}
public final PortType getPortType() {
return port;
}
}

View file

@ -0,0 +1,68 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
/** Represents an OSX Mouse
* @author elias
* @version 1.0
*/
final class OSXMouse extends Mouse {
private final PortType port;
private final OSXHIDQueue queue;
protected OSXMouse(OSXHIDDevice device, OSXHIDQueue queue, Component[] components, Controller[] children, Rumbler[] rumblers) {
super(device.getProductName(), components, children, rumblers);
this.queue = queue;
this.port = device.getPortType();
}
protected final boolean getNextDeviceEvent(Event event) throws IOException {
return OSXControllers.getNextDeviceEvent(event, queue);
}
protected final void setDeviceEventQueueSize(int size) throws IOException {
queue.setQueueDepth(size);
}
public final PortType getPortType() {
return port;
}
}

View file

@ -0,0 +1,46 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
/** Generic Desktop Usages
* @author elias
* @version 1.0
*/
public interface Usage {
}

View file

@ -0,0 +1,114 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.lang.reflect.Method;
/** HID Usage pages
* @author elias
* @version 1.0
*/
final class UsagePage {
private final static UsagePage[] map = new UsagePage[0xFF];
public final static UsagePage UNDEFINED = new UsagePage(0x00);
public final static UsagePage GENERIC_DESKTOP = new UsagePage(0x01, GenericDesktopUsage.class);
public final static UsagePage SIMULATION = new UsagePage(0x02);
public final static UsagePage VR = new UsagePage(0x03);
public final static UsagePage SPORT = new UsagePage(0x04);
public final static UsagePage GAME = new UsagePage(0x05);
/* Reserved 0x06 */
public final static UsagePage KEYBOARD_OR_KEYPAD = new UsagePage(0x07, KeyboardUsage.class); /* USB Device Class Definition for Human Interface Devices (HID). Note: the usage type for all key codes is Selector (Sel). */
public final static UsagePage LEDS = new UsagePage(0x08);
public final static UsagePage BUTTON = new UsagePage(0x09, ButtonUsage.class);
public final static UsagePage ORDINAL = new UsagePage(0x0A);
public final static UsagePage TELEPHONY = new UsagePage(0x0B);
public final static UsagePage CONSUMER = new UsagePage(0x0C);
public final static UsagePage DIGITIZER = new UsagePage(0x0D);
/* Reserved 0x0E */
public final static UsagePage PID = new UsagePage(0x0F); /* USB Physical Interface Device definitions for force feedback and related devices. */
public final static UsagePage UNICODE = new UsagePage(0x10);
/* Reserved 0x11 - 0x13 */
public final static UsagePage ALPHANUMERIC_DISPLAY = new UsagePage(0x14);
/* Reserved 0x15 - 0x7F */
/* Monitor 0x80 - 0x83 USB Device Class Definition for Monitor Devices */
/* Power 0x84 - 0x87 USB Device Class Definition for Power Devices */
public final static UsagePage POWER_DEVICE = new UsagePage(0x84); /* Power Device Page */
public final static UsagePage BATTERY_SYSTEM = new UsagePage(0x85); /* Battery System Page */
/* Reserved 0x88 - 0x8B */
public final static UsagePage BAR_CODE_SCANNER = new UsagePage(0x8C); /* (Point of Sale) USB Device Class Definition for Bar Code Scanner Devices */
public final static UsagePage SCALE = new UsagePage(0x8D); /* (Point of Sale) USB Device Class Definition for Scale Devices */
/* ReservedPointofSalepages 0x8E - 0X8F */
public final static UsagePage CAMERACONTROL= new UsagePage(0x90); /* USB Device Class Definition for Image Class Devices */
public final static UsagePage ARCADE = new UsagePage(0x91); /* OAAF Definitions for arcade and coinop related Devices */
private final Class usage_class;
private final int usage_page_id;
public final static UsagePage map(int page_id) {
if (page_id < 0 || page_id >= map.length)
return null;
return map[page_id];
}
private UsagePage(int page_id, Class usage_class) {
map[page_id] = this;
this.usage_class = usage_class;
this.usage_page_id = page_id;
}
private UsagePage(int page_id) {
this(page_id, null);
}
public final String toString() {
return "UsagePage (0x" + Integer.toHexString(usage_page_id) + ")";
}
public final Usage mapUsage(int usage_id) {
if (usage_class == null)
return null;
try {
Method map_method = usage_class.getMethod("map", new Class[]{int.class});
Object result = map_method.invoke(null, new Object[]{new Integer(usage_id)});
return (Usage)result;
} catch (Exception e) {
throw new Error(e);
}
}
}

View file

@ -0,0 +1,76 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
/** Usage/Page pair
* @author elias
* @version 1.0
*/
class UsagePair {
private final UsagePage usage_page;
private final Usage usage;
public UsagePair(UsagePage usage_page, Usage usage) {
this.usage_page = usage_page;
this.usage = usage;
}
public final UsagePage getUsagePage() {
return usage_page;
}
public final Usage getUsage() {
return usage;
}
public final int hashCode() {
return usage.hashCode() ^ usage_page.hashCode();
}
public final boolean equals(Object other) {
if (!(other instanceof UsagePair))
return false;
UsagePair other_pair = (UsagePair)other;
return other_pair.usage.equals(usage) && other_pair.usage_page.equals(usage_page);
}
public final String toString() {
return "UsagePair: (page = " + usage_page + ", usage = " + usage + ")";
}
}

View file

@ -0,0 +1,3 @@
/net_java_games_input_OSXHIDDevice.h
/net_java_games_input_OSXHIDDeviceIterator.h
/net_java_games_input_OSXHIDQueue.h

View file

@ -0,0 +1,197 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
#include <CoreServices/CoreServices.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <jni.h>
#include "util.h"
#include "macosxutil.h"
typedef struct {
JNIEnv *env;
jobject map;
} dict_context_t;
typedef struct {
JNIEnv *env;
jobjectArray array;
jsize index;
} array_context_t;
static jobject createObjectFromCFObject(JNIEnv *env, CFTypeRef cfobject);
static jstring createStringFromCFString(JNIEnv *env, CFStringRef cfstring) {
CFIndex unicode_length = CFStringGetLength(cfstring);
CFIndex utf8_length = CFStringGetMaximumSizeForEncoding(unicode_length, kCFStringEncodingUTF8);
// Allocate buffer large enough, plus \0 terminator
char *buffer = (char *)malloc(utf8_length + 1);
if (buffer == NULL)
return NULL;
Boolean result = CFStringGetCString(cfstring, buffer, utf8_length + 1, kCFStringEncodingUTF8);
if (!result) {
free(buffer);
return NULL;
}
jstring str = (*env)->NewStringUTF(env, buffer);
free(buffer);
return str;
}
static jobject createDoubleObjectFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) {
double value;
Boolean result = CFNumberGetValue(cfnumber, kCFNumberDoubleType, &value);
if (!result)
return NULL;
return newJObject(env, "java/lang/Double", "(D)V", (jdouble)value);
}
static jobject createLongObjectFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) {
SInt64 value;
Boolean result = CFNumberGetValue(cfnumber, kCFNumberSInt64Type, &value);
if (!result)
return NULL;
return newJObject(env, "java/lang/Long", "(J)V", (jlong)value);
}
static jobject createNumberFromCFNumber(JNIEnv *env, CFNumberRef cfnumber) {
CFNumberType number_type = CFNumberGetType(cfnumber);
switch (number_type) {
case kCFNumberSInt8Type:
case kCFNumberSInt16Type:
case kCFNumberSInt32Type:
case kCFNumberSInt64Type:
case kCFNumberCharType:
case kCFNumberShortType:
case kCFNumberIntType:
case kCFNumberLongType:
case kCFNumberLongLongType:
case kCFNumberCFIndexType:
return createLongObjectFromCFNumber(env, cfnumber);
case kCFNumberFloat32Type:
case kCFNumberFloat64Type:
case kCFNumberFloatType:
case kCFNumberDoubleType:
return createDoubleObjectFromCFNumber(env, cfnumber);
default:
return NULL;
}
}
static void createArrayEntries(const void *value, void *context) {
array_context_t *array_context = (array_context_t *)context;
jobject jval = createObjectFromCFObject(array_context->env, value);
(*array_context->env)->SetObjectArrayElement(array_context->env, array_context->array, array_context->index++, jval);
(*array_context->env)->DeleteLocalRef(array_context->env, jval);
}
static jobject createArrayFromCFArray(JNIEnv *env, CFArrayRef cfarray) {
jclass Object_class = (*env)->FindClass(env, "java/lang/Object");
if (Object_class == NULL)
return NULL;
CFIndex size = CFArrayGetCount(cfarray);
CFRange range = {0, size};
jobjectArray array = (*env)->NewObjectArray(env, size, Object_class, NULL);
array_context_t array_context;
array_context.env = env;
array_context.array = array;
array_context.index = 0;
CFArrayApplyFunction(cfarray, range, createArrayEntries, &array_context);
return array;
}
static jobject createObjectFromCFObject(JNIEnv *env, CFTypeRef cfobject) {
CFTypeID type_id = CFGetTypeID(cfobject);
if (type_id == CFDictionaryGetTypeID()) {
return createMapFromCFDictionary(env, cfobject);
} else if (type_id == CFArrayGetTypeID()) {
return createArrayFromCFArray(env, cfobject);
} else if (type_id == CFStringGetTypeID()) {
return createStringFromCFString(env, cfobject);
} else if (type_id == CFNumberGetTypeID()) {
return createNumberFromCFNumber(env, cfobject);
} else {
return NULL;
}
}
static void createMapKeys(const void *key, const void *value, void *context) {
dict_context_t *dict_context = (dict_context_t *)context;
jclass Map_class = (*dict_context->env)->GetObjectClass(dict_context->env, dict_context->map);
if (Map_class == NULL)
return;
jmethodID map_put = (*dict_context->env)->GetMethodID(dict_context->env, Map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
if (map_put == NULL)
return;
jobject jkey = createObjectFromCFObject(dict_context->env, key);
jobject jvalue = createObjectFromCFObject(dict_context->env, value);
if (jkey == NULL || jvalue == NULL)
return;
(*dict_context->env)->CallObjectMethod(dict_context->env, dict_context->map, map_put, jkey, jvalue);
(*dict_context->env)->DeleteLocalRef(dict_context->env, jkey);
(*dict_context->env)->DeleteLocalRef(dict_context->env, jvalue);
}
jobject createMapFromCFDictionary(JNIEnv *env, CFDictionaryRef dict) {
jobject map = newJObject(env, "java/util/HashMap", "()V");
if (map == NULL)
return NULL;
dict_context_t dict_context;
dict_context.env = env;
dict_context.map = map;
CFDictionaryApplyFunction(dict, createMapKeys, &dict_context);
return map;
}
void copyEvent(JNIEnv *env, IOHIDEventStruct *event, jobject event_return) {
jclass OSXEvent_class = (*env)->GetObjectClass(env, event_return);
if (OSXEvent_class == NULL) {
return;
}
jmethodID OSXEvent_set = (*env)->GetMethodID(env, OSXEvent_class, "set", "(JJIJ)V");
if (OSXEvent_set == NULL) {
return;
}
Nanoseconds nanos = AbsoluteToNanoseconds(event->timestamp);
uint64_t nanos64= *((uint64_t *)&nanos);
(*env)->CallVoidMethod(env, event_return, OSXEvent_set, (jlong)event->type, (jlong)(intptr_t)event->elementCookie, (jint)event->value, (jlong)nanos64);
}

View file

@ -0,0 +1,48 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <jni.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/hid/IOHIDLib.h>
extern jobject createMapFromCFDictionary(JNIEnv *env, CFDictionaryRef dict);
extern void copyEvent(JNIEnv *env, IOHIDEventStruct *event, jobject event_return);

View file

@ -0,0 +1,118 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
#include <IOKit/IOTypes.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/hid/IOHIDLib.h>
#include <IOKit/hid/IOHIDKeys.h>
#include <CoreFoundation/CoreFoundation.h>
#include "net_java_games_input_OSXHIDDevice.h"
#include "util.h"
#include "macosxutil.h"
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nReleaseDevice(JNIEnv *env, jclass unused, jlong device_address, jlong interface_address) {
io_object_t hidDevice = (io_object_t)device_address;
IOHIDDeviceInterface **device_interface = (IOHIDDeviceInterface **)(intptr_t)interface_address;;
(*device_interface)->Release(device_interface);
IOObjectRelease(hidDevice);
}
JNIEXPORT jobject JNICALL Java_net_java_games_input_OSXHIDDevice_nGetDeviceProperties(JNIEnv *env, jclass unused, jlong device_address) {
io_object_t hidDevice = (io_object_t)device_address;
CFMutableDictionaryRef properties;
kern_return_t result = IORegistryEntryCreateCFProperties(hidDevice,
&properties,
kCFAllocatorDefault,
kNilOptions);
if (result != KERN_SUCCESS) {
throwIOException(env, "Failed to create properties for device (%ld)", result);
return NULL;
}
jobject map = createMapFromCFDictionary(env, properties);
CFRelease(properties);
return map;
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nOpen
(JNIEnv * env, jclass unused, jlong lpDevice) {
IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice;
IOReturn ioReturnValue = (*hidDeviceInterface)->open(hidDeviceInterface, 0);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Device open failed: %d", ioReturnValue);
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nClose
(JNIEnv * env, jclass unused, jlong lpDevice) {
IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice;
IOReturn ioReturnValue = (*hidDeviceInterface)->close(hidDeviceInterface);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Device close failed: %d", ioReturnValue);
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDevice_nGetElementValue
(JNIEnv * env, jclass unused, jlong lpDevice, jlong hidCookie, jobject event_return) {
IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)lpDevice;
IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)hidCookie;
IOHIDEventStruct event;
IOReturn ioReturnValue = (*hidDeviceInterface)->getElementValue(hidDeviceInterface, cookie, &event);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Device getElementValue failed: %d", ioReturnValue);
return;
}
copyEvent(env, &event, event_return);
if (event.longValue != NULL) {
free(event.longValue);
}
}
JNIEXPORT jlong JNICALL Java_net_java_games_input_OSXHIDDevice_nCreateQueue(JNIEnv *env, jclass unused, jlong device_address) {
IOHIDDeviceInterface **hidDeviceInterface = (IOHIDDeviceInterface **)(intptr_t)device_address;
IOHIDQueueInterface **queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface);
if (queue == NULL) {
throwIOException(env, "Could not allocate queue");
return 0;
}
return (jlong)(intptr_t)queue;
}

View file

@ -0,0 +1,143 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
#include <IOKit/IOTypes.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/hid/IOHIDLib.h>
#include <IOKit/hid/IOHIDKeys.h>
#include <CoreFoundation/CoreFoundation.h>
#include "net_java_games_input_OSXHIDDeviceIterator.h"
#include "util.h"
JNIEXPORT jlong JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nCreateIterator(JNIEnv *env, jclass unused) {
io_iterator_t hidObjectIterator;
// Set up a matching dictionary to search the I/O Registry by class
// name for all HID class devices
//
CFMutableDictionaryRef hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
// Now search I/O Registry for matching devices.
// IOServiceGetMatchingServices consumes a reference to the dictionary so we don't have to release it
IOReturn ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Failed to create iterator (%ld)\n", ioReturnValue);
return 0;
}
if (hidObjectIterator == IO_OBJECT_NULL) {
throwIOException(env, "Failed to create iterator\n");
return 0;
}
return (jlong)hidObjectIterator;
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nReleaseIterator(JNIEnv *env, jclass unused, jlong address) {
io_iterator_t iterator = (io_iterator_t)address;
IOObjectRelease(iterator);
}
static IOHIDDeviceInterface **createHIDDevice(JNIEnv *env, io_object_t hidDevice) {
// io_name_t className;
IOHIDDeviceInterface **hidDeviceInterface;
IOCFPlugInInterface **plugInInterface;
SInt32 score;
/* ioReturnValue = IOObjectGetClass(hidDevice, className);
if (ioReturnValue != kIOReturnSuccess) {
printfJava(env, "Failed to get IOObject class name.");
}
printfJava(env, "Found device type [%s]\n", className);
*/
IOReturn ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice,
kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID,
&plugInInterface,
&score);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Couldn't create plugin for device interface (%ld)\n", ioReturnValue);
return NULL;
}
//Call a method of the intermediate plug-in to create the device
//interface
//
HRESULT plugInResult = (*plugInInterface)->QueryInterface(plugInInterface,
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
(LPVOID)&hidDeviceInterface);
(*plugInInterface)->Release(plugInInterface);
if (plugInResult != S_OK) {
throwIOException(env, "Couldn't create HID class device interface (%ld)\n", plugInResult);
return NULL;
}
return hidDeviceInterface;
}
JNIEXPORT jobject JNICALL Java_net_java_games_input_OSXHIDDeviceIterator_nNext(JNIEnv *env, jclass unused, jlong address) {
io_iterator_t iterator = (io_iterator_t)address;
io_object_t hidDevice;
// io_string_t path;
// kern_return_t result;
hidDevice = IOIteratorNext(iterator);
if (hidDevice == MACH_PORT_NULL)
return NULL;
/* IOResult result = IORegistryEntryGetPath(hidDevice, kIOServicePlane, path);
if (result != KERN_SUCCESS) {
IOObjectRelease(hidDevice);
throwIOException("Failed to get device path (%ld)\n", result);
return NULL;
}
*/
IOHIDDeviceInterface **device_interface = createHIDDevice(env, hidDevice);
if (device_interface == NULL) {
IOObjectRelease(hidDevice);
return NULL;
}
jobject device_object = newJObject(env, "net/java/games/input/OSXHIDDevice", "(JJ)V", (jlong)hidDevice, (jlong)(intptr_t)device_interface);
if (device_object == NULL) {
(*device_interface)->Release(device_interface);
IOObjectRelease(hidDevice);
return NULL;
}
return device_object;
}

View file

@ -0,0 +1,135 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
#include <IOKit/IOTypes.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/hid/IOHIDLib.h>
#include <IOKit/hid/IOHIDKeys.h>
#include <CoreFoundation/CoreFoundation.h>
#include "net_java_games_input_OSXHIDQueue.h"
#include "util.h"
#include "macosxutil.h"
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nOpen(JNIEnv *env, jclass unused, jlong address, jint queue_depth) {
IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
IOReturn ioReturnValue = (*queue)->create(queue, 0, queue_depth);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Queue open failed: %d\n", ioReturnValue);
return;
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nStart(JNIEnv *env, jclass unused, jlong address) {
IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
IOReturn ioReturnValue = (*queue)->start(queue);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Queue start failed: %d\n", ioReturnValue);
return;
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nStop(JNIEnv *env, jclass unused, jlong address) {
IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
IOReturn ioReturnValue = (*queue)->stop(queue);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Queue stop failed: %d\n", ioReturnValue);
return;
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nClose(JNIEnv *env, jclass unused, jlong address) {
IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
IOReturn ioReturnValue = (*queue)->dispose(queue);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Queue dispose failed: %d\n", ioReturnValue);
return;
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nReleaseQueue(JNIEnv *env, jclass unused, jlong address) {
IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
IOReturn ioReturnValue = (*queue)->Release(queue);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Queue Release failed: %d\n", ioReturnValue);
return;
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nAddElement(JNIEnv *env, jclass unused, jlong address, jlong cookie_address) {
IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)cookie_address;
IOReturn ioReturnValue = (*queue)->addElement(queue, cookie, 0);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Queue addElement failed: %d\n", ioReturnValue);
return;
}
}
JNIEXPORT void JNICALL Java_net_java_games_input_OSXHIDQueue_nRemoveElement(JNIEnv *env, jclass unused, jlong address, jlong cookie_address) {
IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
IOHIDElementCookie cookie = (IOHIDElementCookie)(intptr_t)cookie_address;
IOReturn ioReturnValue = (*queue)->removeElement(queue, cookie);
if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Queue removeElement failed: %d\n", ioReturnValue);
return;
}
}
JNIEXPORT jboolean JNICALL Java_net_java_games_input_OSXHIDQueue_nGetNextEvent(JNIEnv *env, jclass unused, jlong address, jobject event_return) {
IOHIDQueueInterface **queue = (IOHIDQueueInterface **)(intptr_t)address;
IOHIDEventStruct event;
AbsoluteTime zeroTime = {0, 0};
IOReturn ioReturnValue = (*queue)->getNextEvent(queue, &event, zeroTime, 0);
if (ioReturnValue == kIOReturnUnderrun) {
return JNI_FALSE;
} else if (ioReturnValue != kIOReturnSuccess) {
throwIOException(env, "Queue getNextEvent failed: %d\n", ioReturnValue);
return JNI_FALSE;
}
copyEvent(env, &event, event_return);
if (event.longValue != NULL) {
free(event.longValue);
}
return JNI_TRUE;
}