src/joystick/darwin/SDL_sysjoystick.c
changeset 9120 b186c0df3c18
parent 8986 1c81316ac642
child 9370 795d4866e4db
equal deleted inserted replaced
9118:8eeb0d759bc3 9120:b186c0df3c18
   362     }
   362     }
   363 
   363 
   364     return SDL_TRUE;
   364     return SDL_TRUE;
   365 }
   365 }
   366 
   366 
       
   367 static SDL_bool
       
   368 JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
       
   369 {
       
   370     recDevice *i;
       
   371     for (i = gpDeviceList; i != NULL; i = i->pNext) {
       
   372         if (i->deviceRef == ioHIDDeviceObject) {
       
   373             return SDL_TRUE;
       
   374         }
       
   375     }
       
   376     return SDL_FALSE;
       
   377 }
       
   378 
   367 
   379 
   368 static void
   380 static void
   369 JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
   381 JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
   370 {
   382 {
       
   383     recDevice *device;
       
   384 
   371     if (res != kIOReturnSuccess) {
   385     if (res != kIOReturnSuccess) {
   372         return;
   386         return;
   373     }
   387     }
   374 
   388 
   375     recDevice *device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
   389     if (JoystickAlreadyKnown(ioHIDDeviceObject)) {
       
   390         return;  /* IOKit sent us a duplicate. */
       
   391     }
       
   392 
       
   393     device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
   376 
   394 
   377     if (!device) {
   395     if (!device) {
   378         SDL_OutOfMemory();
   396         SDL_OutOfMemory();
   379         return;
   397         return;
   380     }
   398     }