MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / HIDAPI_AddDevice

Function HIDAPI_AddDevice

deps/SDL2/src/joystick/hidapi/SDL_hidapijoystick.c:649–768  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

647}
648
649static void
650HIDAPI_AddDevice(struct hid_device_info *info)
651{
652 SDL_HIDAPI_Device *device;
653 SDL_HIDAPI_Device *curr, *last = NULL;
654
655 for (curr = SDL_HIDAPI_devices, last = NULL; curr; last = curr, curr = curr->next) {
656 continue;
657 }
658
659 device = (SDL_HIDAPI_Device *)SDL_calloc(1, sizeof(*device));
660 if (!device) {
661 return;
662 }
663 device->path = SDL_strdup(info->path);
664 if (!device->path) {
665 SDL_free(device);
666 return;
667 }
668 device->seen = SDL_TRUE;
669 device->vendor_id = info->vendor_id;
670 device->product_id = info->product_id;
671 device->version = info->release_number;
672 device->interface_number = info->interface_number;
673 device->interface_class = info->interface_class;
674 device->interface_subclass = info->interface_subclass;
675 device->interface_protocol = info->interface_protocol;
676 device->usage_page = info->usage_page;
677 device->usage = info->usage;
678 {
679 /* FIXME: Is there any way to tell whether this is a Bluetooth device? */
680 const Uint16 vendor = device->vendor_id;
681 const Uint16 product = device->product_id;
682 const Uint16 version = device->version;
683 Uint16 *guid16 = (Uint16 *)device->guid.data;
684
685 *guid16++ = SDL_SwapLE16(SDL_HARDWARE_BUS_USB);
686 *guid16++ = 0;
687 *guid16++ = SDL_SwapLE16(vendor);
688 *guid16++ = 0;
689 *guid16++ = SDL_SwapLE16(product);
690 *guid16++ = 0;
691 *guid16++ = SDL_SwapLE16(version);
692 *guid16++ = 0;
693
694 /* Note that this is a HIDAPI device for special handling elsewhere */
695 device->guid.data[14] = 'h';
696 device->guid.data[15] = 0;
697 }
698 device->dev_lock = SDL_CreateMutex();
699
700 /* Need the device name before getting the driver to know whether to ignore this device */
701 if (!device->name) {
702 const char *name = SDL_GetCustomJoystickName(device->vendor_id, device->product_id);
703 if (name) {
704 device->name = SDL_strdup(name);
705 }
706 }

Callers 1

HIDAPI_UpdateDeviceListFunction · 0.85

Calls 15

SDL_callocFunction · 0.85
SDL_strdupFunction · 0.85
SDL_freeFunction · 0.85
SDL_iconv_stringFunction · 0.85
SDL_wcslenFunction · 0.85
SDL_strlenFunction · 0.85
SDL_mallocFunction · 0.85
SDL_strncasecmpFunction · 0.85
SDL_strlcpyFunction · 0.85
SDL_snprintfFunction · 0.85

Tested by

no test coverage detected