Moved DateTime helper functions to service class

This commit is contained in:
Nav
2022-12-26 22:10:49 +00:00
parent 90ef72f686
commit 0a15ce8a84
8 changed files with 22 additions and 19 deletions

View File

@@ -6,7 +6,7 @@
#include <optional> #include <optional>
#include <cstdint> #include <cstdint>
#include "src/Helpers/DateTime.hpp" #include "src/Services/DateTimeService.hpp"
namespace Bloom::Events namespace Bloom::Events
{ {
@@ -38,7 +38,7 @@ namespace Bloom::Events
{ {
public: public:
int id = ++(Event::lastEventId); int id = ++(Event::lastEventId);
QDateTime createdTimestamp = DateTime::currentDateTime(); QDateTime createdTimestamp = Services::DateTimeService::currentDateTime();
static constexpr EventType type = EventType::GENERIC; static constexpr EventType type = EventType::GENERIC;
static const inline std::string name = "GenericEvent"; static const inline std::string name = "GenericEvent";

View File

@@ -7,10 +7,12 @@
#include <utility> #include <utility>
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Helpers/DateTime.hpp"
#include "src/Helpers/BiMap.hpp"
#include "AddressType.hpp" #include "AddressType.hpp"
#include "src/Services/DateTimeService.hpp"
#include "src/Helpers/BiMap.hpp"
namespace Bloom namespace Bloom
{ {
enum class MemoryRegionType: std::uint8_t enum class MemoryRegionType: std::uint8_t
@@ -29,7 +31,7 @@ namespace Bloom
{ {
public: public:
QString name; QString name;
QDateTime createdDate = DateTime::currentDateTime(); QDateTime createdDate = Services::DateTimeService::currentDateTime();
Targets::TargetMemoryType memoryType; Targets::TargetMemoryType memoryType;
MemoryRegionType type; MemoryRegionType type;

View File

@@ -8,7 +8,7 @@
#include <QJsonObject> #include <QJsonObject>
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Helpers/DateTime.hpp" #include "src/Services/DateTimeService.hpp"
#include "FocusedMemoryRegion.hpp" #include "FocusedMemoryRegion.hpp"
#include "ExcludedMemoryRegion.hpp" #include "ExcludedMemoryRegion.hpp"
@@ -24,7 +24,7 @@ namespace Bloom
Targets::TargetMemoryType memoryType; Targets::TargetMemoryType memoryType;
Targets::TargetMemoryBuffer data; Targets::TargetMemoryBuffer data;
Targets::TargetProgramCounter programCounter; Targets::TargetProgramCounter programCounter;
QDateTime createdDate = DateTime::currentDateTime(); QDateTime createdDate = Services::DateTimeService::currentDateTime();
std::vector<FocusedMemoryRegion> focusedRegions; std::vector<FocusedMemoryRegion> focusedRegions;
std::vector<ExcludedMemoryRegion> excludedRegions; std::vector<ExcludedMemoryRegion> excludedRegions;

View File

@@ -1,6 +1,6 @@
#include "MemorySnapshotItem.hpp" #include "MemorySnapshotItem.hpp"
#include "src/Helpers/DateTime.hpp" #include "src/Services/DateTimeService.hpp"
namespace Bloom::Widgets namespace Bloom::Widgets
{ {
@@ -23,7 +23,7 @@ namespace Bloom::Widgets
this->createdDateLabel->setText( this->createdDateLabel->setText(
memorySnapshot.createdDate.toString( memorySnapshot.createdDate.toString(
memorySnapshot.createdDate.date() == DateTime::currentDate() memorySnapshot.createdDate.date() == Services::DateTimeService::currentDate()
? "hh:mm" ? "hh:mm"
: "dd/MM/yyyy hh:mm" : "dd/MM/yyyy hh:mm"
) )

View File

@@ -12,7 +12,6 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
#include "src/Services/PathService.hpp" #include "src/Services/PathService.hpp"
#include "src/Helpers/DateTime.hpp"
#include "src/Exceptions/Exception.hpp" #include "src/Exceptions/Exception.hpp"
namespace Bloom::Widgets namespace Bloom::Widgets

View File

@@ -19,7 +19,9 @@ namespace Bloom
} }
void Logger::log(const LogEntry& logEntry) { 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); const auto lock = std::unique_lock(Logger::printMutex);

View File

@@ -6,7 +6,7 @@
#include <atomic> #include <atomic>
#include "src/ProjectConfig.hpp" #include "src/ProjectConfig.hpp"
#include "src/Helpers/DateTime.hpp" #include "src/Services/DateTimeService.hpp"
namespace Bloom namespace Bloom
{ {
@@ -26,7 +26,7 @@ namespace Bloom
std::uint32_t id = ++(LogEntry::lastLogId); std::uint32_t id = ++(LogEntry::lastLogId);
std::string message; std::string message;
LogLevel logLevel; LogLevel logLevel;
QDateTime timestamp = DateTime::currentDateTime(); QDateTime timestamp = Services::DateTimeService::currentDateTime();
std::string threadName; std::string threadName;
LogEntry(std::string message, LogLevel logLevel) LogEntry(std::string message, LogLevel logLevel)

View File

@@ -4,13 +4,13 @@
#include <QDateTime> #include <QDateTime>
#include <QDate> #include <QDate>
namespace Bloom namespace Bloom::Services
{ {
/** /**
* Some (maybe all) QDateTime static functions are not thread-safe and thus can result in data races. * 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: public:
/** /**
@@ -20,7 +20,7 @@ namespace Bloom
* @return * @return
*/ */
static QDateTime currentDateTime() { static QDateTime currentDateTime() {
const auto lock = std::unique_lock(DateTime::systemClockMutex); const auto lock = std::unique_lock(DateTimeService::systemClockMutex);
return QDateTime::currentDateTime(); return QDateTime::currentDateTime();
} }
@@ -30,7 +30,7 @@ namespace Bloom
* @return * @return
*/ */
static QDate currentDate() { static QDate currentDate() {
const auto lock = std::unique_lock(DateTime::systemClockMutex); const auto lock = std::unique_lock(DateTimeService::systemClockMutex);
return QDateTime::currentDateTime().date(); return QDateTime::currentDateTime().date();
} }
@@ -43,7 +43,7 @@ namespace Bloom
* @return * @return
*/ */
static QString getTimeZoneAbbreviation(const QDateTime& dateTime) { 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(); return dateTime.timeZoneAbbreviation();
} }