From 0a15ce8a84ddc76f1042da25ec9d3b5bca66e0ca Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 26 Dec 2022 22:10:49 +0000 Subject: [PATCH] Moved DateTime helper functions to service class --- src/EventManager/Events/Event.hpp | 4 ++-- .../TargetMemoryInspectionPane/MemoryRegion.hpp | 8 +++++--- .../TargetMemoryInspectionPane/MemorySnapshot.hpp | 4 ++-- .../SnapshotManager/MemorySnapshotItem.cpp | 4 ++-- .../RegisterHistoryWidget/RegisterHistoryWidget.cpp | 1 - src/Logger/Logger.cpp | 4 +++- src/Logger/Logger.hpp | 4 ++-- .../DateTime.hpp => Services/DateTimeService.hpp} | 12 ++++++------ 8 files changed, 22 insertions(+), 19 deletions(-) rename src/{Helpers/DateTime.hpp => Services/DateTimeService.hpp} (77%) diff --git a/src/EventManager/Events/Event.hpp b/src/EventManager/Events/Event.hpp index 493b46de..bf4cce6c 100644 --- a/src/EventManager/Events/Event.hpp +++ b/src/EventManager/Events/Event.hpp @@ -6,7 +6,7 @@ #include #include -#include "src/Helpers/DateTime.hpp" +#include "src/Services/DateTimeService.hpp" namespace Bloom::Events { @@ -38,7 +38,7 @@ namespace Bloom::Events { public: int id = ++(Event::lastEventId); - QDateTime createdTimestamp = DateTime::currentDateTime(); + QDateTime createdTimestamp = Services::DateTimeService::currentDateTime(); static constexpr EventType type = EventType::GENERIC; static const inline std::string name = "GenericEvent"; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp index 5a3a9101..b9ba35eb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp @@ -7,10 +7,12 @@ #include #include "src/Targets/TargetMemory.hpp" -#include "src/Helpers/DateTime.hpp" -#include "src/Helpers/BiMap.hpp" #include "AddressType.hpp" +#include "src/Services/DateTimeService.hpp" + +#include "src/Helpers/BiMap.hpp" + namespace Bloom { enum class MemoryRegionType: std::uint8_t @@ -29,7 +31,7 @@ namespace Bloom { public: QString name; - QDateTime createdDate = DateTime::currentDateTime(); + QDateTime createdDate = Services::DateTimeService::currentDateTime(); Targets::TargetMemoryType memoryType; MemoryRegionType type; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp index 07f9c2af..4c50a02d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp @@ -8,7 +8,7 @@ #include #include "src/Targets/TargetMemory.hpp" -#include "src/Helpers/DateTime.hpp" +#include "src/Services/DateTimeService.hpp" #include "FocusedMemoryRegion.hpp" #include "ExcludedMemoryRegion.hpp" @@ -24,7 +24,7 @@ namespace Bloom Targets::TargetMemoryType memoryType; Targets::TargetMemoryBuffer data; Targets::TargetProgramCounter programCounter; - QDateTime createdDate = DateTime::currentDateTime(); + QDateTime createdDate = Services::DateTimeService::currentDateTime(); std::vector focusedRegions; std::vector excludedRegions; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.cpp index 7114ab00..a1d6b590 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.cpp @@ -1,6 +1,6 @@ #include "MemorySnapshotItem.hpp" -#include "src/Helpers/DateTime.hpp" +#include "src/Services/DateTimeService.hpp" namespace Bloom::Widgets { @@ -23,7 +23,7 @@ namespace Bloom::Widgets this->createdDateLabel->setText( memorySnapshot.createdDate.toString( - memorySnapshot.createdDate.date() == DateTime::currentDate() + memorySnapshot.createdDate.date() == Services::DateTimeService::currentDate() ? "hh:mm" : "dd/MM/yyyy hh:mm" ) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.cpp index e5de79f9..3163e8f9 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.cpp @@ -12,7 +12,6 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" #include "src/Services/PathService.hpp" -#include "src/Helpers/DateTime.hpp" #include "src/Exceptions/Exception.hpp" namespace Bloom::Widgets diff --git a/src/Logger/Logger.cpp b/src/Logger/Logger.cpp index 91f35656..cdc85289 100644 --- a/src/Logger/Logger.cpp +++ b/src/Logger/Logger.cpp @@ -19,7 +19,9 @@ namespace Bloom } void Logger::log(const LogEntry& logEntry) { - static auto timezoneAbbreviation = DateTime::getTimeZoneAbbreviation(logEntry.timestamp).toStdString(); + static auto timezoneAbbreviation = Services::DateTimeService::getTimeZoneAbbreviation( + logEntry.timestamp + ).toStdString(); const auto lock = std::unique_lock(Logger::printMutex); diff --git a/src/Logger/Logger.hpp b/src/Logger/Logger.hpp index e521504d..78689a06 100644 --- a/src/Logger/Logger.hpp +++ b/src/Logger/Logger.hpp @@ -6,7 +6,7 @@ #include #include "src/ProjectConfig.hpp" -#include "src/Helpers/DateTime.hpp" +#include "src/Services/DateTimeService.hpp" namespace Bloom { @@ -26,7 +26,7 @@ namespace Bloom std::uint32_t id = ++(LogEntry::lastLogId); std::string message; LogLevel logLevel; - QDateTime timestamp = DateTime::currentDateTime(); + QDateTime timestamp = Services::DateTimeService::currentDateTime(); std::string threadName; LogEntry(std::string message, LogLevel logLevel) diff --git a/src/Helpers/DateTime.hpp b/src/Services/DateTimeService.hpp similarity index 77% rename from src/Helpers/DateTime.hpp rename to src/Services/DateTimeService.hpp index 5b69afde..7a6b1644 100644 --- a/src/Helpers/DateTime.hpp +++ b/src/Services/DateTimeService.hpp @@ -4,13 +4,13 @@ #include #include -namespace Bloom +namespace Bloom::Services { /** * Some (maybe all) QDateTime static functions are not thread-safe and thus can result in data races. - * This trivial helper class wraps some of these functions and employs a mutex to prevent data races. + * This trivial service class wraps some of these functions and employs a mutex to prevent data races. */ - class DateTime + class DateTimeService { public: /** @@ -20,7 +20,7 @@ namespace Bloom * @return */ static QDateTime currentDateTime() { - const auto lock = std::unique_lock(DateTime::systemClockMutex); + const auto lock = std::unique_lock(DateTimeService::systemClockMutex); return QDateTime::currentDateTime(); } @@ -30,7 +30,7 @@ namespace Bloom * @return */ static QDate currentDate() { - const auto lock = std::unique_lock(DateTime::systemClockMutex); + const auto lock = std::unique_lock(DateTimeService::systemClockMutex); return QDateTime::currentDateTime().date(); } @@ -43,7 +43,7 @@ namespace Bloom * @return */ static QString getTimeZoneAbbreviation(const QDateTime& dateTime) { - const auto lock = std::unique_lock(DateTime::systemClockMutex); + const auto lock = std::unique_lock(DateTimeService::systemClockMutex); return dateTime.timeZoneAbbreviation(); }