From f8b472fda9180b3f812835e582bc37de0a91251a Mon Sep 17 00:00:00 2001 From: cathery Date: Mon, 7 Dec 2020 18:04:05 +0300 Subject: [PATCH] Add LOG macro --- source/Sysmodule/source/config_handler.cpp | 16 +++++++------- .../Sysmodule/source/controller_handler.cpp | 4 ++-- source/Sysmodule/source/log.cpp | 3 +-- source/Sysmodule/source/log.h | 2 ++ source/Sysmodule/source/main.cpp | 2 +- source/Sysmodule/source/usb_module.cpp | 22 +++++++++---------- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/source/Sysmodule/source/config_handler.cpp b/source/Sysmodule/source/config_handler.cpp index b02a287..d29bf1d 100644 --- a/source/Sysmodule/source/config_handler.cpp +++ b/source/Sysmodule/source/config_handler.cpp @@ -176,14 +176,14 @@ namespace syscon::config void ConfigChangedCheckThreadFunc(void *arg) { - WriteToLog("Starting config check thread!"); + LOG("Starting config check thread!"); do { if (R_SUCCEEDED(waitSingle(filecheckTimerWaiter, UINT64_MAX))) { if (config::CheckForFileChanges()) { - WriteToLog("File check succeeded! Loading configs..."); + LOG("File check succeeded! Loading configs..."); config::LoadAllConfigs(); } } @@ -203,19 +203,19 @@ namespace syscon::config LoadGlobalConfig(tempGlobalConfig); } else - WriteToLog("Failed to read from global config!"); + LOG("Failed to read from global config!"); if (R_SUCCEEDED(ReadFromConfig(XBOXCONFIG))) { XboxController::LoadConfig(&tempConfig); } else - WriteToLog("Failed to read from xbox orig config!"); + LOG("Failed to read from xbox orig config!"); if (R_SUCCEEDED(ReadFromConfig(XBOXONECONFIG))) XboxOneController::LoadConfig(&tempConfig); else - WriteToLog("Failed to read from xbox one config!"); + LOG("Failed to read from xbox one config!"); if (R_SUCCEEDED(ReadFromConfig(XBOX360CONFIG))) { @@ -223,17 +223,17 @@ namespace syscon::config Xbox360WirelessController::LoadConfig(&tempConfig); } else - WriteToLog("Failed to read from xbox 360 config!"); + LOG("Failed to read from xbox 360 config!"); if (R_SUCCEEDED(ReadFromConfig(DUALSHOCK3CONFIG))) Dualshock3Controller::LoadConfig(&tempConfig); else - WriteToLog("Failed to read from dualshock 3 config!"); + LOG("Failed to read from dualshock 3 config!"); if (R_SUCCEEDED(ReadFromConfig(DUALSHOCK4CONFIG))) Dualshock4Controller::LoadConfig(&tempConfig, tempColor); else - WriteToLog("Failed to read from dualshock 4 config!"); + LOG("Failed to read from dualshock 4 config!"); } bool CheckForFileChanges() diff --git a/source/Sysmodule/source/controller_handler.cpp b/source/Sysmodule/source/controller_handler.cpp index f275f59..146017f 100644 --- a/source/Sysmodule/source/controller_handler.cpp +++ b/source/Sysmodule/source/controller_handler.cpp @@ -28,12 +28,12 @@ namespace syscon::controllers if (UseAbstractedPad) { switchHandler = std::make_unique(std::move(controllerPtr)); - WriteToLog("Inserting controller as abstracted pad"); + LOG("Inserting controller as abstracted pad"); } else { switchHandler = std::make_unique(std::move(controllerPtr)); - WriteToLog("Inserting controller as HDLs"); + LOG("Inserting controller as HDLs"); } Result rc = switchHandler->Initialize(); diff --git a/source/Sysmodule/source/log.cpp b/source/Sysmodule/source/log.cpp index c44e17e..d040c26 100644 --- a/source/Sysmodule/source/log.cpp +++ b/source/Sysmodule/source/log.cpp @@ -25,7 +25,7 @@ void DiscardOldLogs() if (fileSize >= 0x20'000) { fsFsDeleteFile(fs, LOG_PATH); - WriteToLog("Deleted previous log file"); + LOG("Deleted previous log file"); } } @@ -46,7 +46,6 @@ void WriteToLog(const char *fmt, ...) vfprintf(fp, fmt, va); va_end(va); - fprintf(fp, "\n"); fclose(fp); } diff --git a/source/Sysmodule/source/log.h b/source/Sysmodule/source/log.h index df09311..afd386f 100644 --- a/source/Sysmodule/source/log.h +++ b/source/Sysmodule/source/log.h @@ -15,3 +15,5 @@ extern "C" #ifdef __cplusplus } #endif + +#define LOG(fmt, ...) WriteToLog(fmt "\n", ##__VA_ARGS__) diff --git a/source/Sysmodule/source/main.cpp b/source/Sysmodule/source/main.cpp index 7c43183..54a37e6 100644 --- a/source/Sysmodule/source/main.cpp +++ b/source/Sysmodule/source/main.cpp @@ -87,7 +87,7 @@ using namespace syscon; int main(int argc, char *argv[]) { - WriteToLog("\n\nNew sysmodule session started on version " APP_VERSION); + LOG("\n\nNew sysmodule session started on version " APP_VERSION); config::Initialize(); controllers::Initialize(); usb::Initialize(); diff --git a/source/Sysmodule/source/usb_module.cpp b/source/Sysmodule/source/usb_module.cpp index 5450684..d64950a 100644 --- a/source/Sysmodule/source/usb_module.cpp +++ b/source/Sysmodule/source/usb_module.cpp @@ -52,24 +52,24 @@ namespace syscon::usb { if (R_SUCCEEDED(eventWait(&g_usbCatchAllEvent, UINT64_MAX))) { - WriteToLog("Catch-all event went off"); + LOG("Catch-all event went off"); std::scoped_lock usbLock(usbMutex); if (!controllers::IsAtControllerLimit()) { s32 total_entries; if ((total_entries = QueryInterfaces(USB_CLASS_VENDOR_SPEC, 93, 1)) != 0) - WriteToLog("Initializing Xbox 360 controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); + LOG("Initializing Xbox 360 controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); if ((total_entries = QueryInterfaces(USB_CLASS_VENDOR_SPEC, 93, 129)) != 0) for (int i = 0; i != total_entries; ++i) - WriteToLog("Initializing Xbox 360 wireless controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces + i, 1)))); + LOG("Initializing Xbox 360 wireless controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces + i, 1)))); if ((total_entries = QueryInterfaces(0x58, 0x42, 0x00)) != 0) - WriteToLog("Initializing Xbox Original controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); + LOG("Initializing Xbox Original controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); if ((total_entries = QueryInterfaces(USB_CLASS_VENDOR_SPEC, 71, 208)) != 0) - WriteToLog("Initializing Xbox One controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); + LOG("Initializing Xbox One controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); } } } while (is_usb_event_thread_running); @@ -81,17 +81,17 @@ namespace syscon::usb { if (R_SUCCEEDED(eventWait(&g_usbSonyEvent, UINT64_MAX))) { - WriteToLog("Sony event went off"); + LOG("Sony event went off"); std::scoped_lock usbLock(usbMutex); if (!controllers::IsAtControllerLimit()) { s32 total_entries; if ((QueryVendorProduct(VENDOR_SONY, PRODUCT_DUALSHOCK3) != 0) && (total_entries = QueryInterfaces(USB_CLASS_HID, 0, 0)) != 0) - WriteToLog("Initializing Dualshock 3 controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); + LOG("Initializing Dualshock 3 controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); else if ((QueryVendorProduct(VENDOR_SONY, PRODUCT_DUALSHOCK4_1X) != 0 || QueryVendorProduct(VENDOR_SONY, PRODUCT_DUALSHOCK4_2X) != 0) && (total_entries = QueryInterfaces(USB_CLASS_HID, 0, 0)) != 0) - WriteToLog("Initializing Dualshock 4 controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); + LOG("Initializing Dualshock 4 controller: 0x%x", controllers::Insert(std::make_unique(std::make_unique(interfaces, total_entries)))); } } } while (is_usb_event_thread_running); @@ -104,7 +104,7 @@ namespace syscon::usb if (R_SUCCEEDED(eventWait(usbHsGetInterfaceStateChangeEvent(), UINT64_MAX))) { s32 total_entries; - WriteToLog("Interface state was changed"); + LOG("Interface state was changed"); std::scoped_lock usbLock(usbMutex); std::scoped_lock controllersLock(controllers::GetScopedLock()); @@ -133,9 +133,9 @@ namespace syscon::usb if (!found_flag) { - WriteToLog("Erasing controller"); + LOG("Erasing controller"); controllers::Get().erase(it--); - WriteToLog("Controller erased!"); + LOG("Controller erased!"); } } }