X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2FCommon%2Ffreeglut_joystick.c;h=bf5bf95b7c138a73cb9c8c5485b7da450596aa03;hb=e511ea0b35c08dd69bf1d8b898b68187c6fdd2ee;hp=17eeb00dc3413672ff1c77bd008fcb017ea9349f;hpb=d2f7ea29ea6d946f455f4363c3f058ff2bdfba35;p=freeglut diff --git a/src/Common/freeglut_joystick.c b/src/Common/freeglut_joystick.c index 17eeb00..bf5bf95 100644 --- a/src/Common/freeglut_joystick.c +++ b/src/Common/freeglut_joystick.c @@ -455,12 +455,60 @@ static void fghJoystickAddHatElement ( SFG_Joystick* joy, CFDictionaryRef hat ); #endif +/* External function declarations (mostly platform-specific) */ +extern void fgPlatformJoystickClose ( int ident ); + /* * The static joystick structure pointer */ #define MAX_NUM_JOYSTICKS 2 static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ]; +/* + * Platform-Specific Code + */ + +#if TARGET_HOST_MACINTOSH +void fgPlatformJoystickClose ( int ident ) +{ + ISpSuspend( ); + ISpStop( ); + ISpShutdown( ); +} +#endif + +#if TARGET_HOST_MAC_OSX +void fgPlatformJoystickClose ( int ident ) +{ + ( *( fgJoystick[ ident ]->hidDev ) )-> + close( fgJoystick[ ident ]->hidDev ); +} +#endif + +#if TARGET_HOST_POSIX_X11 +void fgPlatformJoystickClose ( int ident ) +{ +#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ ) + if( fgJoystick[ident]->os ) + { + if( ! fgJoystick[ ident ]->error ) + close( fgJoystick[ ident ]->os->fd ); +#ifdef HAVE_USB_JS + if( fgJoystick[ ident ]->os->hids ) + free (fgJoystick[ ident ]->os->hids); + if( fgJoystick[ ident ]->os->hid_data_buf ) + free( fgJoystick[ ident ]->os->hid_data_buf ); +#endif + free( fgJoystick[ident]->os ); + } +#endif + + if( ! fgJoystick[ident]->error ) + close( fgJoystick[ ident ]->fd ); +} +#endif + + /* * Read the raw joystick data @@ -1616,9 +1664,7 @@ void fgInitialiseJoysticks ( void ) } } -/* - * - */ + void fgJoystickClose( void ) { int ident ; @@ -1626,41 +1672,7 @@ void fgJoystickClose( void ) { if( fgJoystick[ ident ] ) { - -#if TARGET_HOST_MACINTOSH - ISpSuspend( ); - ISpStop( ); - ISpShutdown( ); -#endif - -#if TARGET_HOST_MAC_OSX - ( *( fgJoystick[ ident ]->hidDev ) )-> - close( fgJoystick[ ident ]->hidDev ); -#endif - -#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) - /* Do nothing special */ -#endif - -#if TARGET_HOST_POSIX_X11 -#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ ) - if( fgJoystick[ident]->os ) - { - if( ! fgJoystick[ ident ]->error ) - close( fgJoystick[ ident ]->os->fd ); -#ifdef HAVE_USB_JS - if( fgJoystick[ ident ]->os->hids ) - free (fgJoystick[ ident ]->os->hids); - if( fgJoystick[ ident ]->os->hid_data_buf ) - free( fgJoystick[ ident ]->os->hid_data_buf ); -#endif - free( fgJoystick[ident]->os ); - } -#endif - - if( ! fgJoystick[ident]->error ) - close( fgJoystick[ ident ]->fd ); -#endif + fgPlatformJoystickClose ( ident ); free( fgJoystick[ ident ] ); fgJoystick[ ident ] = NULL;