Skip to content

Commit

Permalink
Move some leftover raw spdlog calls to macros
Browse files Browse the repository at this point in the history
Change-Id: I8900936d5aa5648ab75c15decab8099b98274809
Reviewed-on: https://codereview.kdab.com/c/kdab/kdutils/+/136228
Tested-by: Continuous Integration <[email protected]>
Reviewed-by: Sean Harmer <[email protected]>
  • Loading branch information
lemirep committed Jan 11, 2024
1 parent eea8e1e commit 20ef5a3
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 77 deletions.
42 changes: 21 additions & 21 deletions examples/gui_window/gui_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,47 @@ class ExampleWindow : public KDGui::Window
{
void mouseMoveEvent(KDGui::MouseMoveEvent *ev) override
{
spdlog::info("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons().toInt(),
ev->xPos(),
ev->yPos());
SPDLOG_INFO("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons().toInt(),
ev->xPos(),
ev->yPos());
}

void mousePressEvent(KDGui::MousePressEvent *ev) override
{
spdlog::info("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons().toInt(),
ev->xPos(),
ev->yPos());
SPDLOG_INFO("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons().toInt(),
ev->xPos(),
ev->yPos());
}

void mouseReleaseEvent(KDGui::MouseReleaseEvent *ev) override
{
spdlog::info("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons().toInt(),
ev->xPos(),
ev->yPos());
SPDLOG_INFO("{}() buttons = {} at pos = ({}, {})",
__FUNCTION__,
ev->buttons().toInt(),
ev->xPos(),
ev->yPos());
}

void mouseWheelEvent(KDGui::MouseWheelEvent *ev) override
{
spdlog::info("{}() xDelta = {} yDelta = {}",
__FUNCTION__,
ev->xDelta(),
ev->yDelta());
SPDLOG_INFO("{}() xDelta = {} yDelta = {}",
__FUNCTION__,
ev->xDelta(),
ev->yDelta());
}

void keyPressEvent(KDGui::KeyPressEvent *ev) override
{
spdlog::info("{}() key = {}", __FUNCTION__, ev->key());
SPDLOG_INFO("{}() key = {}", __FUNCTION__, ev->key());
}

void keyReleaseEvent(KDGui::KeyReleaseEvent *ev) override
{
spdlog::info("{}() key = {}", __FUNCTION__, ev->key());
SPDLOG_INFO("{}() key = {}", __FUNCTION__, ev->key());
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/KDFoundation/file_descriptor_notifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FileDescriptorNotifier::FileDescriptorNotifier(int fd, NotificationType type)
// Get hold of the event loop from the application
auto app = CoreApplication::instance();
if (!app) {
spdlog::warn("No application object exists yet. The notifier for fd {} will not be registered", m_fd);
SPDLOG_WARN("No application object exists yet. The notifier for fd {} will not be registered", m_fd);
return;
}

Expand All @@ -44,7 +44,7 @@ FileDescriptorNotifier::~FileDescriptorNotifier()
{
auto app = CoreApplication::instance();
if (!app) {
spdlog::warn("No application object exists yet we still have a notifier for fd {} alive", m_fd);
SPDLOG_WARN("No application object exists yet we still have a notifier for fd {} alive", m_fd);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void LinuxPlatformEventLoop::waitForEvents(int timeout)

// Let interested parties know if something happened.
if (!m_postman) {
spdlog::warn("No postman set. Cannot deliver events");
SPDLOG_WARN("No postman set. Cannot deliver events");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class KDFOUNDATION_API LinuxPlatformEventLoop : public AbstractPlatformEventLoop
case FileDescriptorNotifier::NotificationType::Exception:
return !hasNotifier(FileDescriptorNotifier::NotificationType::Read) && !hasNotifier(FileDescriptorNotifier::NotificationType::Write);
}
spdlog::critical("Error in determining if notifier set is empty");
SPDLOG_CRITICAL("Error in determining if notifier set is empty");
return false;
}

Expand Down
18 changes: 9 additions & 9 deletions src/KDFoundation/platform/win32/win32_platform_event_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ Win32PlatformEventLoop::Win32PlatformEventLoop()
{
m_wakeUpEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
if (!m_wakeUpEvent)
spdlog::critical("Failed to create wake up event");
SPDLOG_CRITICAL("Failed to create wake up event");

WNDCLASS wc = {};
wc.lpfnWndProc = messageWindowProc;
wc.lpszClassName = s_msgWindowClassName;

ATOM atom = RegisterClass(&wc);
if (!atom)
spdlog::critical("Failed to register message window class");
SPDLOG_CRITICAL("Failed to register message window class");

// The GetLastError() returns error code 6 ("The handle is invalid") here but
// the created message window is fine and works anyway. It's like that even
Expand All @@ -65,7 +65,7 @@ Win32PlatformEventLoop::Win32PlatformEventLoop()
0);

if (!m_msgWindow)
spdlog::critical("Failed to create window for socket events");
SPDLOG_CRITICAL("Failed to create window for socket events");
SetWindowLongPtr(m_msgWindow, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
}

Expand All @@ -76,7 +76,7 @@ Win32PlatformEventLoop::~Win32PlatformEventLoop()
if (m_msgWindow)
DestroyWindow(m_msgWindow);
if (!UnregisterClass(s_msgWindowClassName, GetModuleHandle(0)))
spdlog::warn("Failed to unregister message window class");
SPDLOG_WARN("Failed to unregister message window class");
}

void Win32PlatformEventLoop::waitForEvents(int timeout)
Expand Down Expand Up @@ -116,7 +116,7 @@ void Win32PlatformEventLoop::wakeUp()
{
if (m_wakeUpEvent) {
if (!SetEvent(m_wakeUpEvent))
spdlog::critical("Failed to signal wake up event");
SPDLOG_CRITICAL("Failed to signal wake up event");
}
}

Expand All @@ -126,7 +126,7 @@ bool Win32PlatformEventLoop::registerNotifier(FileDescriptorNotifier *notifier)
return false;

if (notifier->fileDescriptor() < 0) {
spdlog::warn("Attempting to register invalid notifier socket = {}", notifier->fileDescriptor());
SPDLOG_WARN("Attempting to register invalid notifier socket = {}", notifier->fileDescriptor());
return false;
}

Expand Down Expand Up @@ -187,12 +187,12 @@ void Win32PlatformEventLoop::handleSocketMessage(WPARAM wparam, LPARAM lparam)
const int op = WSAGETSELECTEVENT(lparam);

if (err) {
spdlog::warn("Error when receiving message on socket {}, Err = {}", sockId, err);
SPDLOG_WARN("Error when receiving message on socket {}, Err = {}", sockId, err);
return;
}

if (!m_postman) {
spdlog::warn("No postman set. Cannot deliver events");
SPDLOG_WARN("No postman set. Cannot deliver events");
return;
}

Expand Down Expand Up @@ -251,7 +251,7 @@ bool KDFoundation::Win32PlatformEventLoop::registerWithWSAAsyncSelect(int fd, co

const int result = WSAAsyncSelect(fd, m_msgWindow, WM_KD_SOCKETEVENT, eventsToSubscribe);
if (result != 0) {
spdlog::error("Failed to register notifier for socket = {}. Error = {}", fd, result);
SPDLOG_ERROR("Failed to register notifier for socket = {}. Error = {}", fd, result);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/KDGui/platform/cocoa/cocoa_platform_window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ - (void)keyUp:(NSEvent *)event
backing:NSBackingStoreBuffered
defer:NO];
if (m_nativeWindow == nil) {
spdlog::critical("Failed to create native window");
SPDLOG_CRITICAL("Failed to create native window");
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/KDGui/platform/win32/win32_gui_platform_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool Win32GuiPlatformIntegration::registerWindowClass(const std::wstring &classN

const auto atom = RegisterClassEx(&wc);
if (!atom) {
spdlog::critical("Failed to register window class: {}", windowsErrorMessage(GetLastError()));
SPDLOG_CRITICAL("Failed to register window class: {}", windowsErrorMessage(GetLastError()));
}

m_windowClasses.insert(className);
Expand All @@ -80,7 +80,7 @@ void Win32GuiPlatformIntegration::unregisterWindowClasses()

for (const auto &name : m_windowClasses) {
if (!UnregisterClass(name.c_str(), appInstance)) {
spdlog::critical("Failed to unregister class: {}", windowsErrorMessage(GetLastError()));
SPDLOG_CRITICAL("Failed to unregister class: {}", windowsErrorMessage(GetLastError()));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/KDGui/platform/win32/win32_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ std::wstring utf8StringToWide(std::string_view source)
{
const auto count = MultiByteToWideChar(CP_UTF8, 0, source.data(), static_cast<int>(source.size()), nullptr, 0);
if (!count) {
spdlog::warn("Failed to convert string from UTF-8");
SPDLOG_WARN("Failed to convert string from UTF-8");
return {};
}

std::wstring result(count, 0);
if (!MultiByteToWideChar(CP_UTF8, 0, source.data(), static_cast<int>(source.size()), result.data(), count)) {
spdlog::warn("Failed to convert string from UTF-8");
SPDLOG_WARN("Failed to convert string from UTF-8");
return {};
}

Expand All @@ -49,13 +49,13 @@ std::string wideStringToUtf8(std::wstring_view source)
{
const auto count = WideCharToMultiByte(CP_UTF8, 0, source.data(), static_cast<int>(source.size()), nullptr, 0, nullptr, nullptr);
if (!count) {
spdlog::warn("Failed to convert string to UTF-8");
SPDLOG_WARN("Failed to convert string to UTF-8");
return {};
}

std::string result(count, 0);
if (!WideCharToMultiByte(CP_UTF8, 0, source.data(), static_cast<int>(source.size()), result.data(), count, nullptr, nullptr)) {
spdlog::warn("Failed to convert string to UTF-8");
SPDLOG_WARN("Failed to convert string to UTF-8");
return {};
}

Expand Down
12 changes: 6 additions & 6 deletions tests/auto/foundation/core_application/tst_core_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,31 @@ TEST_CASE("Main event loop")
std::condition_variable cond;
bool ready = false;
auto quitTheApp = [&mutex, &cond, &ready, &app]() {
spdlog::info("Launched worker thread");
SPDLOG_INFO("Launched worker thread");
std::unique_lock lock(mutex);
cond.wait(lock, [&ready] { return ready == true; });
spdlog::info("Worker thread going to sleep before quitting the app event loop");
SPDLOG_INFO("Worker thread going to sleep before quitting the app event loop");

std::this_thread::sleep_for(std::chrono::milliseconds(500));
spdlog::info("Worker thread requesting the app to quit");
SPDLOG_INFO("Worker thread requesting the app to quit");
app.quit();
};
std::thread t1(quitTheApp);

{
spdlog::info("Waking up helper thread");
SPDLOG_INFO("Waking up helper thread");
std::unique_lock lock(mutex);
ready = true;
cond.notify_all();
}

const auto startTime = std::chrono::steady_clock::now();
spdlog::info("Main thread entering event loop");
SPDLOG_INFO("Main thread entering event loop");
app.exec();
const auto endTime = std::chrono::steady_clock::now();

auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
spdlog::info("elapsedTime = {}", elapsedTime);
SPDLOG_INFO("elapsedTime = {}", elapsedTime);
REQUIRE(elapsedTime < 1000);

t1.join();
Expand Down
Loading

0 comments on commit 20ef5a3

Please sign in to comment.