mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Move libusb utilities to LibusbUtils
* Simplifies libusb context usage and allows us to set options for all contexts easily. Notably, this lets us enable usbdk support in libusb, which is now opt-in in the latest version. * Moves the libusb config descriptor wrapper class to LibusbUtils too since that could easily be reused. * Moves device listing to LibusbUtils too and add a lock around it as some libusb backends are not thread safe. * Consequences: only a single context and a single event handling thread is used now, which is more efficient.
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Core/LibusbUtils.h"
|
||||
#include "UICommon/USBUtils.h"
|
||||
|
||||
// Because opening and getting the device name from devices is slow, especially on Windows
|
||||
@ -34,21 +35,17 @@ std::map<std::pair<u16, u16>, std::string> GetInsertedDevices()
|
||||
std::map<std::pair<u16, u16>, std::string> devices;
|
||||
|
||||
#ifdef __LIBUSB__
|
||||
libusb_context* context = nullptr;
|
||||
if (libusb_init(&context) < 0)
|
||||
auto& context = LibusbUtils::GetContext();
|
||||
if (!context.IsValid())
|
||||
return devices;
|
||||
|
||||
libusb_device** list;
|
||||
const ssize_t cnt = libusb_get_device_list(context, &list);
|
||||
for (ssize_t i = 0; i < cnt; ++i)
|
||||
{
|
||||
context.GetDeviceList([&](libusb_device* device) {
|
||||
libusb_device_descriptor descr;
|
||||
libusb_get_device_descriptor(list[i], &descr);
|
||||
libusb_get_device_descriptor(device, &descr);
|
||||
const std::pair<u16, u16> vid_pid{descr.idVendor, descr.idProduct};
|
||||
devices[vid_pid] = GetDeviceName(vid_pid);
|
||||
}
|
||||
libusb_free_device_list(list, 1);
|
||||
libusb_exit(context);
|
||||
return true;
|
||||
});
|
||||
#endif
|
||||
|
||||
return devices;
|
||||
|
Reference in New Issue
Block a user