From 127178f44c7b84334b3aa7837af7f2269c5631c5 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 12 Nov 2018 15:05:14 +0100 Subject: [PATCH] Windows: MSVC2017: changes in sdrbase (1): fixed with std::chrono --- sdrbase/commands/command.cpp | 30 +++++++++++++++++++++--------- sdrbase/commands/command.h | 10 ++++++---- sdrbase/dsp/nullsink.cpp | 2 +- sdrgui/gui/commandoutputdialog.cpp | 12 +++++------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/sdrbase/commands/command.cpp b/sdrbase/commands/command.cpp index 097bb42da..d1d52c2d9 100644 --- a/sdrbase/commands/command.cpp +++ b/sdrbase/commands/command.cpp @@ -14,12 +14,14 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include "command.h" -#include "util/simpleserializer.h" +#include #include #include +#include "command.h" +#include "util/simpleserializer.h" + Command::Command() : m_currentProcess(nullptr), m_currentProcessState(QProcess::NotRunning), @@ -30,8 +32,8 @@ Command::Command() : m_currentProcessExitStatus(QProcess::NormalExit), m_currentProcessPid(0) { - m_currentProcessStartTimeStamp = 0; - m_currentProcessFinishTimeStamp = 0; + m_currentProcessStartTimeStampms = 0; + m_currentProcessFinishTimeStampms = 0; resetToDefaults(); } @@ -55,8 +57,8 @@ Command::Command(const Command& command) : m_currentProcessExitStatus(QProcess::NormalExit), m_currentProcessPid(0) { - m_currentProcessStartTimeStamp = 0; - m_currentProcessFinishTimeStamp = 0; + m_currentProcessStartTimeStampms = 0; + m_currentProcessFinishTimeStampms = 0; } Command::~Command() @@ -198,7 +200,7 @@ void Command::run(const QString& apiAddress, int apiPort, int deviceSetIndex) connect(m_currentProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStateChanged(QProcess::ProcessState))); m_currentProcess->setProcessChannelMode(QProcess::MergedChannels); - m_currentProcessStartTimeStamp = clock(); + m_currentProcessStartTimeStampms = nowms(); m_currentProcess->start(m_currentProcessCommandLine); } @@ -254,7 +256,7 @@ void Command::processStateChanged(QProcess::ProcessState newState) void Command::processError(QProcess::ProcessError error) { //qDebug("Command::processError: %d state: %d", error, m_currentProcessState); - m_currentProcessFinishTimeStamp = clock(); + m_currentProcessFinishTimeStampms = nowms(); m_currentProcessError = error; m_isInError = true; @@ -278,7 +280,7 @@ void Command::processError(QProcess::ProcessError error) void Command::processFinished(int exitCode, QProcess::ExitStatus exitStatus) { //qDebug("Command::processFinished: (%d) %d", exitCode, exitStatus); - m_currentProcessFinishTimeStamp = clock(); + m_currentProcessFinishTimeStampms = nowms(); m_currentProcessExitCode = exitCode; m_currentProcessExitStatus = exitStatus; m_hasExited = true; @@ -295,3 +297,13 @@ void Command::processFinished(int exitCode, QProcess::ExitStatus exitStatus) m_currentProcess->deleteLater(); // make sure other threads can still access it until all events have been processed m_currentProcess = nullptr; // for this thread it can assume it was deleted } + +uint64_t Command::nowms() +{ + auto now = std::chrono::system_clock::now(); + auto now_ms = std::chrono::time_point_cast(now); + auto epoch = now_ms.time_since_epoch(); + auto value = std::chrono::duration_cast(epoch); + + return value.count(); +} \ No newline at end of file diff --git a/sdrbase/commands/command.h b/sdrbase/commands/command.h index b61442ad1..92e628ead 100644 --- a/sdrbase/commands/command.h +++ b/sdrbase/commands/command.h @@ -63,8 +63,8 @@ public: bool getLastProcessError(QProcess::ProcessError& error) const; bool getLastProcessExit(int& exitCode, QProcess::ExitStatus& exitStatus) const; const QString& getLastProcessLog() const; - clock_t getLastProcessStartTimestamp() const { return m_currentProcessStartTimeStamp; } - clock_t getLastProcessFinishTimestamp() const { return m_currentProcessFinishTimeStamp; } + uint64_t getLastProcessStartTimestampms() const { return m_currentProcessStartTimeStampms; } + uint64_t getLastProcessFinishTimestampms() const { return m_currentProcessFinishTimeStampms; } const QString& getLastProcessCommandLine() const { return m_currentProcessCommandLine; } qint64 getLastProcessPid() const { return m_currentProcessPid; } @@ -91,6 +91,8 @@ public: } private: + uint64_t nowms(); //!< Get now time in milliseconds + QString m_group; QString m_description; QString m_command; @@ -107,8 +109,8 @@ private: int m_currentProcessExitCode; QProcess::ExitStatus m_currentProcessExitStatus; QString m_log; - clock_t m_currentProcessStartTimeStamp; - clock_t m_currentProcessFinishTimeStamp; + uint64_t m_currentProcessStartTimeStampms; + uint64_t m_currentProcessFinishTimeStampms; QString m_currentProcessCommandLine; qint64 m_currentProcessPid; diff --git a/sdrbase/dsp/nullsink.cpp b/sdrbase/dsp/nullsink.cpp index 5f1b7a3fa..b244dc15e 100644 --- a/sdrbase/dsp/nullsink.cpp +++ b/sdrbase/dsp/nullsink.cpp @@ -13,7 +13,7 @@ NullSink::~NullSink() bool NullSink::init(const Message& message) { - (void) message + (void) message; return false; } diff --git a/sdrgui/gui/commandoutputdialog.cpp b/sdrgui/gui/commandoutputdialog.cpp index 01bd3e2e7..0c9d2adf9 100644 --- a/sdrgui/gui/commandoutputdialog.cpp +++ b/sdrgui/gui/commandoutputdialog.cpp @@ -39,24 +39,22 @@ void CommandOutputDialog::refresh() ui->commandText->setText(m_command.getLastProcessCommandLine()); ui->processPid->setText(QString("%1").arg(m_command.getLastProcessPid())); - if (m_command.getLastProcessStartTimestamp() == 0) { + if (m_command.getLastProcessStartTimestampms() == 0) { ui->startTime->setText(("...")); } else { - clock_t tv = m_command.getLastProcessStartTimestamp(); - QDateTime dt = QDateTime::fromMSecsSinceEpoch((tv * 1000LL) / CLOCKS_PER_SEC); + QDateTime dt = QDateTime::fromMSecsSinceEpoch(m_command.getLastProcessStartTimestampms()); QString dateStr = dt.toString("yyyy-MM-dd HH:mm:ss.zzz"); ui->startTime->setText(dateStr); } - if (m_command.getLastProcessFinishTimestamp() == 0) { + if (m_command.getLastProcessFinishTimestampms() == 0) { ui->endTime->setText(("...")); } else { - clock_t tv = m_command.getLastProcessFinishTimestamp(); - QDateTime dt = QDateTime::fromMSecsSinceEpoch((tv * 1000LL) / CLOCKS_PER_SEC); + QDateTime dt = QDateTime::fromMSecsSinceEpoch(m_command.getLastProcessFinishTimestampms()); QString dateStr = dt.toString("yyyy-MM-dd HH:mm:ss.zzz"); ui->endTime->setText(dateStr); } @@ -64,7 +62,7 @@ void CommandOutputDialog::refresh() ui->runningState->setChecked(m_command.getLastProcessState() == QProcess::Running); QProcess::ProcessError processError; - if (m_command.getLastProcessStartTimestamp() == 0) // not started + if (m_command.getLastProcessStartTimestampms() == 0) // not started { ui->errorText->setText("..."); ui->exitCode->setText("-");