Skip to content

Commit

Permalink
nsyshid: more logging in release build
Browse files Browse the repository at this point in the history
  • Loading branch information
ssievert42 committed Sep 23, 2023
1 parent cee96af commit 9ec9ed3
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 100 deletions.
108 changes: 56 additions & 52 deletions src/Cafe/OS/libs/nsyshid/BackendLibusb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace nsyshid::backend::libusb
if (m_initReturnCode < 0)
{
m_ctx = nullptr;
cemuLog_logDebug(LogType::Force, "nsyshid::BackendLibusb: failed to initialize libusb with return code %i",
m_initReturnCode);
cemuLog_log(LogType::Force, "nsyshid::BackendLibusb: failed to initialize libusb with return code %i",
m_initReturnCode);
return;
}

Expand All @@ -34,13 +34,13 @@ namespace nsyshid::backend::libusb
&m_hotplugCallbackHandle);
if (ret != LIBUSB_SUCCESS)
{
cemuLog_logDebug(LogType::Force,
"nsyshid::BackendLibusb: failed to register hotplug callback with return code %i",
ret);
cemuLog_log(LogType::Force,
"nsyshid::BackendLibusb: failed to register hotplug callback with return code %i",
ret);
}
else
{
cemuLog_logDebug(LogType::Force, "nsyshid::BackendLibusb: registered hotplug callback");
cemuLog_log(LogType::Force, "nsyshid::BackendLibusb: registered hotplug callback");
m_callbackRegistered = true;
m_hotplugThread = std::thread([this] {
while (!m_hotplugThreadStop)
Expand All @@ -52,9 +52,9 @@ namespace nsyshid::backend::libusb
int ret = libusb_handle_events_timeout_completed(m_ctx, &timeout, nullptr);
if (ret != 0)
{
cemuLog_logDebug(LogType::Force,
"nsyshid::BackendLibusb: hotplug thread: error handling events: {}",
ret);
cemuLog_log(LogType::Force,
"nsyshid::BackendLibusb: hotplug thread: error handling events: {}",
ret);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
Expand All @@ -63,7 +63,7 @@ namespace nsyshid::backend::libusb
}
else
{
cemuLog_logDebug(LogType::Force, "nsyshid::BackendLibusb: hotplug not supported by this version of libusb");
cemuLog_log(LogType::Force, "nsyshid::BackendLibusb: hotplug not supported by this version of libusb");
}
}

Expand Down Expand Up @@ -130,17 +130,17 @@ namespace nsyshid::backend::libusb
int ret = libusb_get_device_descriptor(dev, &desc);
if (ret < 0)
{
cemuLog_logDebug(LogType::Force, "nsyshid::BackendLibusb::OnHotplug(): failed to get device descriptor");
cemuLog_log(LogType::Force, "nsyshid::BackendLibusb::OnHotplug(): failed to get device descriptor");
return 0;
}

switch (event)
{
case LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED:
{
cemuLog_logDebug(LogType::Force, "nsyshid::BackendLibusb::OnHotplug(): device arrived: {:04x}:{:04x}",
desc.idVendor,
desc.idProduct);
cemuLog_log(LogType::Force, "nsyshid::BackendLibusb::OnHotplug(): device arrived: {:04x}:{:04x}",
desc.idVendor,
desc.idProduct);
auto device = CheckAndCreateDevice(dev);
if (device != nullptr)
{
Expand All @@ -166,9 +166,9 @@ namespace nsyshid::backend::libusb
break;
case LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT:
{
cemuLog_logDebug(LogType::Force, "nsyshid::BackendLibusb::OnHotplug(): device left: {:04x}:{:04x}",
desc.idVendor,
desc.idProduct);
cemuLog_log(LogType::Force, "nsyshid::BackendLibusb::OnHotplug(): device left: {:04x}:{:04x}",
desc.idVendor,
desc.idProduct);
auto device = FindLibusbDevice(dev);
if (device != nullptr)
{
Expand Down Expand Up @@ -203,8 +203,8 @@ namespace nsyshid::backend::libusb
int ret = libusb_get_device_descriptor(dev, &desc);
if (ret < 0)
{
cemuLog_logDebug(LogType::Force,
"nsyshid::BackendLibusb::FindLibusbDevice(): failed to get device descriptor");
cemuLog_log(LogType::Force,
"nsyshid::BackendLibusb::FindLibusbDevice(): failed to get device descriptor");
return nullptr;
}
uint8 busNumber = libusb_get_bus_number(dev);
Expand Down Expand Up @@ -243,8 +243,8 @@ namespace nsyshid::backend::libusb
}
if (desc.idVendor == 0x0e6f && desc.idProduct == 0x0241)
{
cemuLog_logDebug(LogType::Force,
"nsyshid::BackendLibusb::CheckAndCreateDevice(): lego dimensions portal detected");
cemuLog_log(LogType::Force,
"nsyshid::BackendLibusb::CheckAndCreateDevice(): lego dimensions portal detected");
}
auto device = std::make_shared<DeviceLibusb>(m_ctx,
desc.idVendor,
Expand Down Expand Up @@ -420,24 +420,28 @@ namespace nsyshid::backend::libusb
}
if (libusb_kernel_driver_active(this->m_libusbHandle, 0) == 1)
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::open(): kernel driver active");
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::open(): kernel driver active");
if (libusb_detach_kernel_driver(this->m_libusbHandle, 0) == 0)
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::open(): kernel driver detached");
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::open(): kernel driver detached");
}
else
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::open(): failed to detach kernel driver");
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::open(): failed to detach kernel driver");
}
}
{
int ret = libusb_claim_interface(this->m_libusbHandle, 0);
if (ret != 0)
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::open(): cannot claim interface");
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::open(): cannot claim interface");
}
}
}
else
{
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::open(): failed to find device");
}

libusb_free_device_list(devices, 1);
return found != nullptr;
Expand Down Expand Up @@ -476,8 +480,8 @@ namespace nsyshid::backend::libusb
auto handleLock = AquireHandleLock();
if (!handleLock->IsValid())
{
cemuLog_logDebug(LogType::Force,
"nsyshid::DeviceLibusb::read(): cannot read from a non-opened device\n");
cemuLog_log(LogType::Force,
"nsyshid::DeviceLibusb::read(): cannot read from a non-opened device\n");
return ReadResult::Error;
}

Expand All @@ -498,15 +502,15 @@ namespace nsyshid::backend::libusb
if (ret == 0 || ret == LIBUSB_ERROR_TIMEOUT)
{
// success
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::read(): read {} of {} bytes",
actualLength,
length);
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::read(): read {} of {} bytes",
actualLength,
length);
bytesRead = actualLength;
return ReadResult::Success;
}
cemuLog_logDebug(LogType::Force,
"nsyshid::DeviceLibusb::read(): failed with error code: {}",
ret);
cemuLog_log(LogType::Force,
"nsyshid::DeviceLibusb::read(): failed with error code: {}",
ret);
return ReadResult::Error;
}

Expand All @@ -515,8 +519,8 @@ namespace nsyshid::backend::libusb
auto handleLock = AquireHandleLock();
if (!handleLock->IsValid())
{
cemuLog_logDebug(LogType::Force,
"nsyshid::DeviceLibusb::write(): cannot write to a non-opened device\n");
cemuLog_log(LogType::Force,
"nsyshid::DeviceLibusb::write(): cannot write to a non-opened device\n");
return WriteResult::Error;
}

Expand All @@ -533,15 +537,15 @@ namespace nsyshid::backend::libusb
{
// success
bytesWritten = actualLength;
cemuLog_logDebug(LogType::Force,
"nsyshid::DeviceLibusb::write(): wrote {} of {} bytes",
bytesWritten,
length);
cemuLog_log(LogType::Force,
"nsyshid::DeviceLibusb::write(): wrote {} of {} bytes",
bytesWritten,
length);
return WriteResult::Success;
}
cemuLog_logDebug(LogType::Force,
"nsyshid::DeviceLibusb::write(): failed with error code: {}",
ret);
cemuLog_log(LogType::Force,
"nsyshid::DeviceLibusb::write(): failed with error code: {}",
ret);
return WriteResult::Error;
}

Expand All @@ -554,7 +558,7 @@ namespace nsyshid::backend::libusb
auto handleLock = AquireHandleLock();
if (!handleLock->IsValid())
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::getDescriptor(): device is not opened");
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::getDescriptor(): device is not opened");
return false;
}

Expand Down Expand Up @@ -672,9 +676,9 @@ namespace nsyshid::backend::libusb
}
else
{
cemuLog_logDebug(LogType::Force,
"nsyshid::DeviceLibusb::getDescriptor(): failed to get config descriptor with error code: {}",
ret);
cemuLog_log(LogType::Force,
"nsyshid::DeviceLibusb::getDescriptor(): failed to get config descriptor with error code: {}",
ret);
return false;
}
}
Expand All @@ -690,7 +694,7 @@ namespace nsyshid::backend::libusb
auto handleLock = AquireHandleLock();
if (!handleLock->IsValid())
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetProtocol(): device is not opened");
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::SetProtocol(): device is not opened");
return false;
}

Expand All @@ -699,11 +703,11 @@ namespace nsyshid::backend::libusb
// is this correct? Discarding "ifIndex" seems like a bad idea
int ret = libusb_set_configuration(handleLock->getHandle(), protocol);
if (ret == 0) {
cemuLog_logDebug(LogType::Force,
cemuLog_log(LogType::Force,
"nsyshid::DeviceLibusb::setProtocol(): success");
return true;
}
cemuLog_logDebug(LogType::Force,
cemuLog_log(LogType::Force,
"nsyshid::DeviceLibusb::setProtocol(): failed with error code: {}",
ret);
return false;
Expand All @@ -719,13 +723,13 @@ namespace nsyshid::backend::libusb
auto handleLock = AquireHandleLock();
if (!handleLock->IsValid())
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetReport(): device is not opened");
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::SetReport(): device is not opened");
return false;
}

if (originalLength == 0)
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetReport(): refusing to do empty control transfer");
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::SetReport(): refusing to do empty control transfer");
return false;
}

Expand All @@ -749,7 +753,7 @@ namespace nsyshid::backend::libusb
while (ret != 0 && retryCount < 20);
if (ret != 0)
{
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetReport(): control transfer failed with error code: {}", ret);
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::SetReport(): control transfer failed with error code: {}", ret);
return false;
}
return true;
Expand Down
Loading

0 comments on commit 9ec9ed3

Please sign in to comment.