diff options
author | endolf <[email protected]> | 2003-10-29 22:36:31 +0000 |
---|---|---|
committer | endolf <[email protected]> | 2003-10-29 22:36:31 +0000 |
commit | c76a9122c20dd155b45d5d9b3dd2c25991afa134 (patch) | |
tree | c33b3547fca2d5f6ab4c959f97333b65d810071b /plugins/linux | |
parent | a5bbe6f39d743c92527925019748585527e204d1 (diff) |
Added the logger macros so I don't have to keep manually adding the
statements back in every time something breaks
Fixed a crash under linux if when it was thinking there was at least one
more joystick that it really had, funnily enough when it tried to get
data from this joystick, it all went bang.
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@56 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins/linux')
-rw-r--r-- | plugins/linux/src/native/JoystickDevice.cpp | 10 | ||||
-rw-r--r-- | plugins/linux/src/native/eventInterface.cpp | 10 | ||||
-rw-r--r-- | plugins/linux/src/native/jinput.cpp | 44 | ||||
-rw-r--r-- | plugins/linux/src/native/joystickInterface.cpp | 14 | ||||
-rw-r--r-- | plugins/linux/src/native/logger.h | 11 |
5 files changed, 72 insertions, 17 deletions
diff --git a/plugins/linux/src/native/JoystickDevice.cpp b/plugins/linux/src/native/JoystickDevice.cpp index c20fc22..8f6521f 100644 --- a/plugins/linux/src/native/JoystickDevice.cpp +++ b/plugins/linux/src/native/JoystickDevice.cpp @@ -35,10 +35,13 @@ #include <malloc.h> #include <errno.h> +#include "logger.h" + JoystickDevice::JoystickDevice(char *deviceFileName) { char tempName[Device::MAX_NAME_LENGTH-1] = "Unknown"; int i; + LOG_TRACE("Trying to open %s\n", deviceFileName); fd = open(deviceFileName, O_RDWR | O_NONBLOCK); /*if(fd<0) { char errorMessage[512]; @@ -47,7 +50,9 @@ JoystickDevice::JoystickDevice(char *deviceFileName) { }*/ if(fd>0){ + LOG_TRACE("Opened %s, trying to get device name\n", deviceFileName); if(ioctl(fd, JSIOCGNAME(sizeof(tempName)), tempName) < 0) { + LOG_TRACE("Failed to get device name for %s\n", deviceFileName); char errorMessage[512]; sprintf(errorMessage, "Error reading device %s\n", deviceFileName); perror(errorMessage); @@ -59,6 +64,7 @@ JoystickDevice::JoystickDevice(char *deviceFileName) { char tempNumButtons; char tempNumAxes; + LOG_TRACE("Getting button and axes information for %s\n", deviceFileName); ioctl (fd, JSIOCGBUTTONS, &tempNumButtons); ioctl (fd, JSIOCGAXES, &tempNumAxes); @@ -72,7 +78,11 @@ JoystickDevice::JoystickDevice(char *deviceFileName) { //absAxesData = (int *)malloc(numAbsAxes * sizeof(int)); absAxesData = new int[numAbsAxes]; + LOG_TRACE("Initialisation of %s completed\n", deviceFileName); inited = 1; + } else { + LOG_TRACE("Failed to open device %s\n", deviceFileName); + inited = 0; } } diff --git a/plugins/linux/src/native/eventInterface.cpp b/plugins/linux/src/native/eventInterface.cpp index 654a0bd..2c41cbd 100644 --- a/plugins/linux/src/native/eventInterface.cpp +++ b/plugins/linux/src/native/eventInterface.cpp @@ -81,15 +81,19 @@ int evInit() { } if ((fd = open(deviceFileNames[0], O_RDONLY)) <0) { - return -1; + evNumDevices=0; + evInited=1; + return 0; } if (ioctl(fd, EVIOCGVERSION, &eventInterfaceVersion)) { close(fd); - return -1; + evNumDevices=0; + evInited=1; + return 0; } - close(fd); + if(fd>=0) {close(fd);} Device *tempDeviceList[numDeviceFiles]; diff --git a/plugins/linux/src/native/jinput.cpp b/plugins/linux/src/native/jinput.cpp index 3ce6c6a..5f78535 100644 --- a/plugins/linux/src/native/jinput.cpp +++ b/plugins/linux/src/native/jinput.cpp @@ -39,6 +39,7 @@ #include "MixedDevice.h" #include "eventInterface.h" #include "joystickInterface.h" +#include "logger.h" Device **jinputDeviceList; int jinputNumDevices; @@ -51,22 +52,28 @@ int jinputNumDevices; JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_init (JNIEnv *, jobject) { + LOG_TRACE("Initing event interface\n"); if(evInit()!=0) { - fprintf(stderr, "Failed to init native event interface\n"); - return -1; + fprintf(stderr, "Could not find any working event devices\n"); +// return -1; } + LOG_TRACE("Initing joystick interface\n"); if(jsInit()!=0) { - fprintf(stderr, "Failed to init native joystick interface\n"); - return -1; + fprintf(stderr, "Could not find any working joystick devices\n"); +// return -1; } + LOG_TRACE("Getting the number of event devices\n"); int numEventDevices = evGetNumberDevices(); EventDevice *eventDevices[numEventDevices]; + LOG_TRACE("Getting %d event devices\n", numEventDevices); evGetDevices((Device **)eventDevices); + LOG_TRACE("Getting the number of joystick devices\n"); int numJoysticks = jsGetNumberDevices(); JoystickDevice *jsDevices[numJoysticks]; + LOG_TRACE("Getting %d joystick devices\n", numJoysticks); jsGetDevices((Device **)jsDevices); @@ -80,12 +87,14 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_init for(j=joystickPtr;j<numJoysticks;j++) { JoystickDevice *jsDevice = jsDevices[j]; + LOG_TRACE("Getting device information for event device %d and joystick %d\n", i, j); if((jsDevice->getNumberButtons() == eventDevice->getNumberButtons()) && (jsDevice->getNumberAbsAxes() == (eventDevice->getNumberAbsAxes() + eventDevice->getNumberRelAxes()))) { const char *jsName = jsDevice->getName(); const char *eventDeviceName = eventDevice->getName(); if(strcmp(jsName, eventDeviceName) == 0) { // The current event device is the curre joystick device too + LOG_TRACE("Creating a mixed device with id %d, combining event device %d and joystick device %d\n", jinputNumDevices, i, j); jinputDeviceList[jinputNumDevices] = new MixedDevice(jsDevice, eventDevice); jinputNumDevices++; joystickPtr = j; @@ -93,12 +102,12 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_init } } /*if(jinputNumDevices == deviceCountCache) { - //fprintf(stderr, "event device \"%s\" doesn't match js \"%s\"\n", eventDevice->getName(), jsDevice->getName()); - //fprintf(stderr, "event device has %d rel axes, %d abs axis and %d buttons\n", eventDevice->getNumberRelAxes(), eventDevice->getNumberAbsAxes(), eventDevice->getNumberButtons()); - //fprintf(stderr, "js device has %d axes and %d buttons\n", jsDevice->getNumberAbsAxes(), jsDevice->getNumberButtons()); + fprintf(stderr, "event device \"%s\" doesn't match js \"%s\"\n", eventDevice->getName(), jsDevice->getName()); + fprintf(stderr, "event device has %d rel axes, %d abs axis and %d buttons\n", eventDevice->getNumberRelAxes(), eventDevice->getNumberAbsAxes(), eventDevice->getNumberButtons()); + fprintf(stderr, "js device has %d axes and %d buttons\n", jsDevice->getNumberAbsAxes(), jsDevice->getNumberButtons()); } else { - //fprintf(stderr, "event device %s did match js %s\n", eventDevice->getName(), jsDevice->getName()); - } */ + fprintf(stderr, "event device %s did match js %s\n", eventDevice->getName(), jsDevice->getName()); + }*/ } @@ -122,6 +131,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_init JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getDeviceName (JNIEnv *env, jobject, jint deviceID) { + LOG_TRACE("Gettign device name for jinput device %d\n", deviceID); return env->NewStringUTF(jinputDeviceList[deviceID]->getName()); } @@ -133,6 +143,7 @@ JNIEXPORT jstring JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getDe JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumAbsAxes (JNIEnv *env, jobject, jint deviceID) { + LOG_TRACE("Gettign number of absolute axes for jinput device %d\n", deviceID); return jinputDeviceList[deviceID]->getNumberAbsAxes(); } @@ -144,6 +155,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumAb JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumRelAxes (JNIEnv *env, jobject, jint deviceID) { + LOG_TRACE("Gettign number of relative axes for jinput device %d\n", deviceID); return jinputDeviceList[deviceID]->getNumberRelAxes(); } @@ -155,6 +167,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumRe JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_getNumButtons (JNIEnv *, jobject, jint deviceID) { + LOG_TRACE("Gettign number of buttons for jinput device %d\n", deviceID); return jinputDeviceList[deviceID]->getNumberButtons(); } @@ -179,6 +192,7 @@ JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDevice_getNativeSupportedA jint *axisReturns = env->GetIntArrayElements(axesData, 0); + LOG_TRACE("Getting suported absolute axes for jinput device %d\n", deviceID); jinputDeviceList[deviceID]->getSupportedAbsAxes(axisReturns); env->ReleaseIntArrayElements(axesData, axisReturns, 0); @@ -194,6 +208,7 @@ JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDevice_getNativeSupportedR jint *axisReturns = env->GetIntArrayElements(axesData, 0); + LOG_TRACE("Getting suported relative axes for jinput device %d\n", deviceID); jinputDeviceList[deviceID]->getSupportedRelAxes(axisReturns); env->ReleaseIntArrayElements(axesData, axisReturns, 0); @@ -209,6 +224,7 @@ JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDevice_getNativeSupportedB jint *buttonDataElements = env->GetIntArrayElements(buttonData, 0); + LOG_TRACE("Getting suported buttons for jinput device %d\n", deviceID); jinputDeviceList[deviceID]->getSupportedButtons(buttonDataElements); env->ReleaseIntArrayElements(buttonData, buttonDataElements, 0); @@ -226,7 +242,9 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_nativePoll jint *relAxesElements = env->GetIntArrayElements(relAxes, 0); jint *absAxesElements = env->GetIntArrayElements(absAxes, 0); + LOG_POLL_TRACE("Polling jinput device %d\n", deviceID); int retval = jinputDeviceList[deviceID]->poll(); + LOG_POLL_TRACE("Getting polled data for device %d\n", deviceID); jinputDeviceList[deviceID]->getPolledData(relAxesElements, absAxesElements, buttonElements); env->ReleaseIntArrayElements(buttons, buttonElements, 0); @@ -244,6 +262,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_nativePoll JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativeAbsAxisFuzz (JNIEnv *, jobject, jint deviceID, jint axisID) { + LOG_TRACE("Getting fuzz data for axis %d on device %d\n", axisID, deviceID); return jinputDeviceList[deviceID]->getAbsAxisFuzz(axisID); } @@ -255,6 +274,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativeAbsAxisFuz JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativeAbsAxisMaximum (JNIEnv *, jobject, jint deviceID, jint axisID) { + LOG_TRACE("Getting absolute axes maximum value data for axis %d on device %d\n", axisID, deviceID); return jinputDeviceList[deviceID]->getAbsAxisMaximum(axisID); } @@ -267,6 +287,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativeAbsAxisMax JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativeAbsAxisMinimum (JNIEnv *, jobject, jint deviceID, jint axisID) { + LOG_TRACE("Getting absolute axes minimum value data for axis %d on device %d\n", axisID, deviceID); return jinputDeviceList[deviceID]->getAbsAxisMinimum(axisID); } @@ -278,6 +299,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativeAbsAxisMin JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativePortType (JNIEnv *, jobject, jint deviceID) { + LOG_TRACE("Getting bus type for device %d\n", deviceID); jinputDeviceList[deviceID]->getBusType(); } @@ -294,6 +316,7 @@ JNIEXPORT void JNICALL Java_net_java_games_input_LinuxKeyboard_getNativeSupporte jint *buttonDataElements = env->GetIntArrayElements(buttons, 0); + LOG_TRACE("Gettign number of buttons for jinput keyboard device %d\n", deviceID); jinputDeviceList[deviceID]->getSupportedButtons(buttonDataElements); env->ReleaseIntArrayElements(buttons, buttonDataElements, 0); @@ -311,7 +334,9 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxKeyboard_nativePoll jint *relAxesElements = env->GetIntArrayElements(relAxes, 0); jint *absAxesElements = env->GetIntArrayElements(absAxes, 0); + LOG_POLL_TRACE("Polling jinput keyboard device %d\n", deviceID); int retval = jinputDeviceList[deviceID]->poll(); + LOG_POLL_TRACE("Getting polled data for keyboard device %d\n", deviceID); jinputDeviceList[deviceID]->getPolledData(relAxesElements, absAxesElements, buttonElements); env->ReleaseIntArrayElements(buttons, buttonElements, 0); @@ -329,5 +354,6 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxKeyboard_nativePoll JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxKeyboard_getNativePortType (JNIEnv *, jobject, jint deviceID) { + LOG_TRACE("Getting bus type for keyboard device %d\n", deviceID); jinputDeviceList[deviceID]->getBusType(); } diff --git a/plugins/linux/src/native/joystickInterface.cpp b/plugins/linux/src/native/joystickInterface.cpp index bfa4231..dc4f274 100644 --- a/plugins/linux/src/native/joystickInterface.cpp +++ b/plugins/linux/src/native/joystickInterface.cpp @@ -81,15 +81,19 @@ int jsInit() { } if ((fd = open(deviceFileNames[0], O_RDONLY)) <0) { - return -1; + jsNumDevices = 0; + jsInited=1; + return 0; } if (ioctl(fd, JSIOCGVERSION, &joystickInterfaceVersion)) { close(fd); - return -1; + jsNumDevices = 0; + jsInited=1; + return 0; } - close(fd); + if(fd>=0) {close(fd);} Device *tempDeviceList[numDeviceFiles]; @@ -109,9 +113,9 @@ int jsInit() { for(i=0;i<jsNumDevices;i++) { while(tempDeviceList[jsTempDeviceCount] == NULL) { jsTempDeviceCount++; - } + } jsDeviceList[i] = tempDeviceList[jsTempDeviceCount]; - //printf("Copied joystick %d to %d\n", jsTempDeviceCount, i); + //printf("Copied joystick %d to %d\n", jsTempDeviceCount, i); jsTempDeviceCount++; } diff --git a/plugins/linux/src/native/logger.h b/plugins/linux/src/native/logger.h new file mode 100644 index 0000000..d832491 --- /dev/null +++ b/plugins/linux/src/native/logger.h @@ -0,0 +1,11 @@ +#ifdef LOGTRACE +#define LOG_TRACE(args...) printf(args) +#else +#define LOG_TRACE(args...) +#endif + +#ifdef LOGPOLLTRACE +#define LOG_POLL_TRACE(args...) LOG_TRACE(args...) +#else +#define LOG_POLL_TRACE(args...) +#endif |