Log warnings when LibusbUtils::GetDeviceList fails

This commit is contained in:
Pokechu22 2022-06-08 12:17:37 -07:00
parent 91a7c4bdf2
commit 15cbb5c8f9
6 changed files with 25 additions and 13 deletions

View File

@ -84,7 +84,7 @@ std::optional<IPCReply> BluetoothRealDevice::Open(const OpenRequest& request)
return IPCReply(IPC_EACCES);
m_last_open_error.clear();
m_context.GetDeviceList([this](libusb_device* device) {
const int ret = m_context.GetDeviceList([this](libusb_device* device) {
libusb_device_descriptor device_descriptor;
libusb_get_device_descriptor(device, &device_descriptor);
auto config_descriptor = LibusbUtils::MakeConfigDescriptor(device);
@ -116,6 +116,11 @@ std::optional<IPCReply> BluetoothRealDevice::Open(const OpenRequest& request)
}
return true;
});
if (ret != LIBUSB_SUCCESS)
{
m_last_open_error =
Common::FmtFormatT("GetDeviceList failed: {0}", LibusbUtils::ErrorWrap(ret));
}
if (m_handle == nullptr)
{

View File

@ -121,7 +121,7 @@ bool USBHost::AddNewDevices(std::set<u64>& new_devices, DeviceChangeHooks& hooks
if (m_context.IsValid())
{
m_context.GetDeviceList([&](libusb_device* device) {
const int ret = m_context.GetDeviceList([&](libusb_device* device) {
libusb_device_descriptor descriptor;
libusb_get_device_descriptor(device, &descriptor);
if (whitelist.count({descriptor.idVendor, descriptor.idProduct}) == 0)
@ -137,6 +137,8 @@ bool USBHost::AddNewDevices(std::set<u64>& new_devices, DeviceChangeHooks& hooks
hooks.emplace(GetDeviceById(id), ChangeEvent::Inserted);
return true;
});
if (ret != LIBUSB_SUCCESS)
WARN_LOG_FMT(IOS_USB, "GetDeviceList failed: {}", LibusbUtils::ErrorWrap(ret));
}
#endif
return true;

View File

@ -47,16 +47,16 @@ public:
libusb_exit(m_context);
}
libusb_context* GetContext() { return m_context; }
libusb_context* GetContext() const { return m_context; }
bool GetDeviceList(GetDeviceListCallback callback)
int GetDeviceList(GetDeviceListCallback callback) const
{
std::lock_guard lock{m_device_list_mutex};
libusb_device** list;
ssize_t count = libusb_get_device_list(m_context, &list);
if (count < 0)
return false;
return static_cast<int>(count);
for (ssize_t i = 0; i < count; ++i)
{
@ -64,7 +64,7 @@ public:
break;
}
libusb_free_device_list(list, 1);
return true;
return LIBUSB_SUCCESS;
}
private:
@ -81,7 +81,7 @@ private:
}
libusb_context* m_context = nullptr;
std::mutex m_device_list_mutex;
mutable std::mutex m_device_list_mutex;
Common::Flag m_event_thread_running;
std::thread m_event_thread;
};
@ -89,8 +89,8 @@ private:
class Context::Impl
{
public:
libusb_context* GetContext() { return nullptr; }
bool GetDeviceList(GetDeviceListCallback callback) { return false; }
libusb_context* GetContext() const { return nullptr; }
int GetDeviceList(GetDeviceListCallback callback) const { return -1; }
};
#endif
@ -110,7 +110,7 @@ bool Context::IsValid() const
return m_impl->GetContext() != nullptr;
}
bool Context::GetDeviceList(GetDeviceListCallback callback)
int Context::GetDeviceList(GetDeviceListCallback callback) const
{
return m_impl->GetDeviceList(std::move(callback));
}

View File

@ -31,7 +31,7 @@ public:
bool IsValid() const;
// Only valid if the context is valid.
bool GetDeviceList(GetDeviceListCallback callback);
int GetDeviceList(GetDeviceListCallback callback) const;
private:
class Impl;

View File

@ -462,7 +462,7 @@ static void Setup()
s_controller_type.fill(ControllerType::None);
s_controller_rumble.fill(0);
s_libusb_context->GetDeviceList([](libusb_device* device) {
const int ret = s_libusb_context->GetDeviceList([](libusb_device* device) {
if (CheckDeviceAccess(device))
{
// Only connect to a single adapter in case the user has multiple connected
@ -471,6 +471,8 @@ static void Setup()
}
return true;
});
if (ret != LIBUSB_SUCCESS)
WARN_LOG_FMT(CONTROLLERINTERFACE, "Failed to get device list: {}", LibusbUtils::ErrorWrap(ret));
if (s_status != ADAPTER_DETECTED && prev_status != s_status && s_detect_callback != nullptr)
s_detect_callback();

View File

@ -11,6 +11,7 @@
#endif
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Core/LibusbUtils.h"
// Because opening and getting the device name from devices is slow, especially on Windows
@ -45,13 +46,15 @@ std::map<std::pair<u16, u16>, std::string> GetInsertedDevices()
if (!context.IsValid())
return devices;
context.GetDeviceList([&](libusb_device* device) {
const int ret = context.GetDeviceList([&](libusb_device* device) {
libusb_device_descriptor descr;
libusb_get_device_descriptor(device, &descr);
const std::pair<u16, u16> vid_pid{descr.idVendor, descr.idProduct};
devices[vid_pid] = GetDeviceName(vid_pid);
return true;
});
if (ret != LIBUSB_SUCCESS)
WARN_LOG_FMT(COMMON, "GetDeviceList failed: {}", LibusbUtils::ErrorWrap(ret));
#endif
return devices;