static void SteamControllerDisconnectedCallback(int device_instance) { SDL_joylist_item *item; SDL_joylist_item *prev = NULL; for (item = SDL_joylist; item != NULL; item = item->next) { /* found it, remove it. */ if (item->device_instance == device_instance) { if (item->hwdata) { item->hwdata->item = NULL; } if (prev != NULL) { prev->next = item->next; } else { SDL_assert(SDL_joylist == item); SDL_joylist = item->next; } if (item == SDL_joylist_tail) { SDL_joylist_tail = prev; } /* Need to decrement the joystick count before we post the event */ --numjoysticks; SDL_PrivateJoystickRemoved(item->device_instance); SDL_free(item->name); SDL_free(item); return; } prev = item; } }
static void JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender) { recDevice *device = (recDevice *) ctx; device->removed = SDL_TRUE; device->deviceRef = NULL; // deviceRef was invalidated due to the remove #if SDL_HAPTIC_IOKIT MacHaptic_MaybeRemoveDevice(device->ffservice); #endif SDL_PrivateJoystickRemoved(device->instance_id); }
int Android_RemoveJoystick(int device_id) { SDL_joylist_item *item = SDL_joylist; SDL_joylist_item *prev = NULL; /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */ while (item != NULL) { if (item->device_id == device_id) { break; } prev = item; item = item->next; } if (item == NULL) { return -1; } if (item->joystick) { item->joystick->hwdata = NULL; } if (prev != NULL) { prev->next = item->next; } else { SDL_assert(SDL_joylist == item); SDL_joylist = item->next; } if (item == SDL_joylist_tail) { SDL_joylist_tail = prev; } /* Need to decrement the joystick count before we post the event */ --numjoysticks; SDL_PrivateJoystickRemoved(item->device_instance); #ifdef DEBUG_JOYSTICK SDL_Log("Removed joystick with device_id %d", device_id); #endif SDL_free(item->name); SDL_free(item); return numjoysticks; }
static EM_BOOL Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData) { SDL_joylist_item *item = SDL_joylist; SDL_joylist_item *prev = NULL; while (item != NULL) { if (item->index == gamepadEvent->index) { break; } prev = item; item = item->next; } if (item == NULL) { return 1; } if (item->joystick) { item->joystick->hwdata = NULL; } if (prev != NULL) { prev->next = item->next; } else { SDL_assert(SDL_joylist == item); SDL_joylist = item->next; } if (item == SDL_joylist_tail) { SDL_joylist_tail = prev; } /* Need to decrement the joystick count before we post the event */ --numjoysticks; SDL_PrivateJoystickRemoved(item->device_instance); #ifdef DEBUG_JOYSTICK SDL_Log("Removed joystick with id %d", item->device_instance); #endif SDL_free(item->name); SDL_free(item->mapping); SDL_free(item); return 1; }
/* !!! FIXME: I would love to dump this code and use libudev instead. */ static int MaybeRemoveDevice(const char *path) { SDL_joylist_item *item; SDL_joylist_item *prev = NULL; if (path == NULL) { return -1; } for (item = SDL_joylist; item != NULL; item = item->next) { /* found it, remove it. */ if (SDL_strcmp(path, item->path) == 0) { const int retval = item->device_instance; if (item->hwdata) { item->hwdata->item = NULL; } if (prev != NULL) { prev->next = item->next; } else { SDL_assert(SDL_joylist == item); SDL_joylist = item->next; } if (item == SDL_joylist_tail) { SDL_joylist_tail = prev; } /* Need to decrement the joystick count before we post the event */ --numjoysticks; SDL_PrivateJoystickRemoved(item->device_instance); SDL_free(item->path); SDL_free(item->name); SDL_free(item); return retval; } prev = item; } return -1; }