Moved DateTime helper functions to service class
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <optional>
|
||||
#include <cstdint>
|
||||
|
||||
#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";
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
#include <utility>
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#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<FocusedMemoryRegion> focusedRegions;
|
||||
std::vector<ExcludedMemoryRegion> excludedRegions;
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <atomic>
|
||||
|
||||
#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)
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
#include <QDateTime>
|
||||
#include <QDate>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user