src/joystick/darwin/SDL_sysjoystick.c
changeset 1409 ebc8b5855040
parent 1402 d910939febfa
child 1487 dc6b59e925a2
equal deleted inserted replaced
1408:ceb5c2fec4f1 1409:ebc8b5855040
   583  * on an unrecoverable fatal error.
   583  * on an unrecoverable fatal error.
   584  */
   584  */
   585 int SDL_SYS_JoystickInit(void)
   585 int SDL_SYS_JoystickInit(void)
   586 {
   586 {
   587 	IOReturn result = kIOReturnSuccess;
   587 	IOReturn result = kIOReturnSuccess;
   588 	mach_port_t masterPort = NULL;
   588 	mach_port_t masterPort = 0;
   589 	io_iterator_t hidObjectIterator = NULL;
   589 	io_iterator_t hidObjectIterator = 0;
   590 	CFMutableDictionaryRef hidMatchDictionary = NULL;
   590 	CFMutableDictionaryRef hidMatchDictionary = NULL;
   591 	recDevice *device, *lastDevice;
   591 	recDevice *device, *lastDevice;
   592 	io_object_t ioHIDDeviceObject = NULL;
   592 	io_object_t ioHIDDeviceObject = 0;
   593 	
   593 	
   594 	SDL_numjoysticks = 0;
   594 	SDL_numjoysticks = 0;
   595 	
   595 	
   596 	if (NULL != gpDeviceList)
   596 	if (!gpDeviceList)
   597 	{
   597 	{
   598 		SDL_SetError("Joystick: Device list already inited.");
   598 		SDL_SetError("Joystick: Device list already inited.");
   599 		return -1;
   599 		return -1;
   600 	}
   600 	}
   601 	
   601 	
   606 		return -1;
   606 		return -1;
   607 	}
   607 	}
   608 
   608 
   609 	/* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
   609 	/* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
   610 	hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey);
   610 	hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey);
   611 	if ((hidMatchDictionary != NULL))
   611 	if (hidMatchDictionary)
   612 	{
   612 	{
   613 		/* Add key for device type (joystick, in this case) to refine the matching dictionary. */
   613 		/* Add key for device type (joystick, in this case) to refine the matching dictionary. */
   614 		
   614 		
   615 		/* NOTE: we now perform this filtering later
   615 		/* NOTE: we now perform this filtering later
   616 		UInt32 usagePage = kHIDPage_GenericDesktop;
   616 		UInt32 usagePage = kHIDPage_GenericDesktop;
   635 	if (kIOReturnSuccess != result)
   635 	if (kIOReturnSuccess != result)
   636 	{
   636 	{
   637 		SDL_SetError("Joystick: Couldn't create a HID object iterator.");
   637 		SDL_SetError("Joystick: Couldn't create a HID object iterator.");
   638 		return -1;
   638 		return -1;
   639 	}
   639 	}
   640 	if (NULL == hidObjectIterator) /* there are no joysticks */
   640 	if (!hidObjectIterator) /* there are no joysticks */
   641 	{
   641 	{
   642 		gpDeviceList = NULL;
   642 		gpDeviceList = NULL;
   643 		SDL_numjoysticks = 0;
   643 		SDL_numjoysticks = 0;
   644 		return 0;
   644 		return 0;
   645 	}
   645 	}