Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9184 from lioncash/inputlog
InputCommon: Migrate logging over to fmt
  • Loading branch information
leoetlino committed Oct 23, 2020
2 parents 87e4a07 + a5e1415 commit ce6eda7
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 185 deletions.
Expand Up @@ -222,7 +222,7 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device
device->SetId(id);
}

NOTICE_LOG(SERIALINTERFACE, "Added device: %s", device->GetQualifiedName().c_str());
NOTICE_LOG_FMT(SERIALINTERFACE, "Added device: {}", device->GetQualifiedName());
m_devices.emplace_back(std::move(device));
}

Expand All @@ -237,7 +237,7 @@ void ControllerInterface::RemoveDevice(std::function<bool(const ciface::Core::De
auto it = std::remove_if(m_devices.begin(), m_devices.end(), [&callback](const auto& dev) {
if (callback(dev.get()))
{
NOTICE_LOG(SERIALINTERFACE, "Removed device: %s", dev->GetQualifiedName().c_str());
NOTICE_LOG_FMT(SERIALINTERFACE, "Removed device: {}", dev->GetQualifiedName());
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/InputCommon/ControllerInterface/DInput/DInput.cpp
Expand Up @@ -42,7 +42,7 @@ std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device)
}
else
{
ERROR_LOG(PAD, "GetProperty(DIPROP_PRODUCTNAME) failed.");
ERROR_LOG_FMT(PAD, "GetProperty(DIPROP_PRODUCTNAME) failed.");
}

return result;
Expand All @@ -58,7 +58,7 @@ void PopulateDevices(HWND hwnd)
if (FAILED(DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8,
(LPVOID*)&idi8, nullptr)))
{
ERROR_LOG(PAD, "DirectInput8Create failed.");
ERROR_LOG_FMT(PAD, "DirectInput8Create failed.");
return;
}

Expand Down
Expand Up @@ -59,7 +59,7 @@ void InitJoystick(IDirectInput8* const idi8, HWND hwnd)
if (FAILED(js_device->SetCooperativeLevel(GetAncestor(hwnd, GA_ROOT),
DISCL_BACKGROUND | DISCL_EXCLUSIVE)))
{
WARN_LOG(
WARN_LOG_FMT(
PAD,
"DInput: Failed to acquire device exclusively. Force feedback will be unavailable.");
// Fall back to non-exclusive mode, with no rumble
Expand Down Expand Up @@ -187,7 +187,7 @@ Joystick::~Joystick()
}
else
{
ERROR_LOG(PAD, "DInputJoystick: GetDeviceInfo failed.");
ERROR_LOG_FMT(PAD, "DInputJoystick: GetDeviceInfo failed.");
}

DeInitForceFeedback();
Expand Down
Expand Up @@ -215,7 +215,7 @@ static sf::Socket::Status ReceiveWithTimeout(sf::UdpSocket& socket, void* data,
static void HotplugThreadFunc()
{
Common::SetCurrentThreadName("DualShockUDPClient Hotplug Thread");
INFO_LOG(SERIALINTERFACE, "DualShockUDPClient hotplug thread started");
INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient hotplug thread started");

while (s_hotplug_thread_running.IsSet())
{
Expand All @@ -235,7 +235,7 @@ static void HotplugThreadFunc()
if (server.m_socket.send(&list_ports, sizeof list_ports, server.m_address, server.m_port) !=
sf::Socket::Status::Done)
{
ERROR_LOG(SERIALINTERFACE, "DualShockUDPClient HotplugThreadFunc send failed");
ERROR_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient HotplugThreadFunc send failed");
}
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ static void HotplugThreadFunc()
}
}
}
INFO_LOG(SERIALINTERFACE, "DualShockUDPClient hotplug thread stopped");
INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient hotplug thread stopped");
}

static void StartHotplugThread()
Expand Down Expand Up @@ -302,7 +302,7 @@ static void StopHotplugThread()

static void Restart()
{
INFO_LOG(SERIALINTERFACE, "DualShockUDPClient Restart");
INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient Restart");

StopHotplugThread();

Expand Down Expand Up @@ -384,7 +384,7 @@ void Init()

void PopulateDevices()
{
INFO_LOG(SERIALINTERFACE, "DualShockUDPClient PopulateDevices");
INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient PopulateDevices");

for (auto& server : s_servers)
{
Expand Down Expand Up @@ -496,7 +496,9 @@ void Device::UpdateInput()
msg.Finish();
if (m_socket.send(&data_req, sizeof(data_req), m_server_address, m_server_port) !=
sf::Socket::Status::Done)
ERROR_LOG(SERIALINTERFACE, "DualShockUDPClient UpdateInput send failed");
{
ERROR_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient UpdateInput send failed");
}
}

// Receive and handle controller data
Expand Down
Expand Up @@ -242,15 +242,16 @@ struct Message
template <class ToMsgType>
std::optional<ToMsgType> CheckAndCastTo()
{
u32 crc32_in_header = m_message.header.crc32;
const u32 crc32_in_header = m_message.header.crc32;
// zero out the crc32 in the packet once we got it since that's whats needed for calculation
m_message.header.crc32 = 0;
u32 crc32_calculated = CRC32(&m_message, sizeof(ToMsgType));
const u32 crc32_calculated = CRC32(&m_message, sizeof(ToMsgType));
if (crc32_in_header != crc32_calculated)
{
NOTICE_LOG(SERIALINTERFACE,
"DualShockUDPClient Received message with bad CRC in header: got %u, expected %u",
crc32_in_header, crc32_calculated);
NOTICE_LOG_FMT(
SERIALINTERFACE,
"DualShockUDPClient Received message with bad CRC in header: got {:08x}, expected {:08x}",
crc32_in_header, crc32_calculated);
return std::nullopt;
}
if (m_message.header.protocol_version > CEMUHOOK_PROTOCOL_VERSION)
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm
Expand Up @@ -178,11 +178,11 @@ void Init(void* window)

HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!HIDManager)
ERROR_LOG(SERIALINTERFACE, "Failed to create HID Manager reference");
ERROR_LOG_FMT(SERIALINTERFACE, "Failed to create HID Manager reference");

IOHIDManagerSetDeviceMatching(HIDManager, nullptr);
if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
ERROR_LOG(SERIALINTERFACE, "Failed to open HID Manager");
ERROR_LOG_FMT(SERIALINTERFACE, "Failed to open HID Manager");

// Callbacks for acquisition or loss of a matching device
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, DeviceMatchingCallback, nullptr);
Expand All @@ -198,15 +198,15 @@ void Init(void* window)
// Enable hotplugging
s_hotplug_thread = std::thread([] {
Common::SetCurrentThreadName("IOHIDManager Hotplug Thread");
NOTICE_LOG(SERIALINTERFACE, "IOHIDManager hotplug thread started");
NOTICE_LOG_FMT(SERIALINTERFACE, "IOHIDManager hotplug thread started");

IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop);
s_stopper.AddToRunLoop(CFRunLoopGetCurrent(), OurRunLoop);
CFRunLoopRunInMode(OurRunLoop, FOREVER, FALSE);
s_stopper.RemoveFromRunLoop(CFRunLoopGetCurrent(), OurRunLoop);
IOHIDManagerUnscheduleFromRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop);

NOTICE_LOG(SERIALINTERFACE, "IOHIDManager hotplug thread stopped");
NOTICE_LOG_FMT(SERIALINTERFACE, "IOHIDManager hotplug thread stopped");
});
}

Expand Down
Expand Up @@ -109,8 +109,8 @@
break;
}

NOTICE_LOG(SERIALINTERFACE, "Unknown IOHIDElement, ignoring (Usage: %x, Type: %x)\n", usage,
IOHIDElementGetType(e));
NOTICE_LOG_FMT(SERIALINTERFACE, "Unknown IOHIDElement, ignoring (Usage: {:x}, Type: {:x})",
usage, IOHIDElementGetType(e));

break;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp
Expand Up @@ -81,7 +81,7 @@ void Init()
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (SDL_Init(SDL_INIT_JOYSTICK) != 0)
ERROR_LOG(SERIALINTERFACE, "SDL failed to initialize");
ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to initialize");
return;
#else
s_hotplug_thread = std::thread([] {
Expand All @@ -95,14 +95,14 @@ void Init()

if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) != 0)
{
ERROR_LOG(SERIALINTERFACE, "SDL failed to initialize");
ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to initialize");
return;
}

const Uint32 custom_events_start = SDL_RegisterEvents(2);
if (custom_events_start == static_cast<Uint32>(-1))
{
ERROR_LOG(SERIALINTERFACE, "SDL failed to register custom events");
ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to register custom events");
return;
}
s_stop_event_type = custom_events_start;
Expand Down

0 comments on commit ce6eda7

Please sign in to comment.