mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-13 20:01:46 -05:00
New time utility class using std::chrono
This commit is contained in:
parent
ad9758f541
commit
ec2bf7a57d
@ -81,6 +81,7 @@ set(sdrbase_SOURCES
|
|||||||
util/simpleserializer.cpp
|
util/simpleserializer.cpp
|
||||||
#util/spinlock.cpp
|
#util/spinlock.cpp
|
||||||
util/uid.cpp
|
util/uid.cpp
|
||||||
|
util/timeutil.cpp
|
||||||
|
|
||||||
plugin/plugininterface.cpp
|
plugin/plugininterface.cpp
|
||||||
plugin/pluginapi.cpp
|
plugin/pluginapi.cpp
|
||||||
@ -204,6 +205,7 @@ set(sdrbase_HEADERS
|
|||||||
util/simpleserializer.h
|
util/simpleserializer.h
|
||||||
#util/spinlock.h
|
#util/spinlock.h
|
||||||
util/uid.h
|
util/uid.h
|
||||||
|
util/timeutil.h
|
||||||
|
|
||||||
webapi/webapiadapterinterface.h
|
webapi/webapiadapterinterface.h
|
||||||
webapi/webapirequestmapper.h
|
webapi/webapirequestmapper.h
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "util/simpleserializer.h"
|
#include "util/simpleserializer.h"
|
||||||
|
#include "util/timeutil.h"
|
||||||
|
|
||||||
Command::Command() :
|
Command::Command() :
|
||||||
m_currentProcess(nullptr),
|
m_currentProcess(nullptr),
|
||||||
@ -200,7 +201,7 @@ void Command::run(const QString& apiAddress, int apiPort, int deviceSetIndex)
|
|||||||
connect(m_currentProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStateChanged(QProcess::ProcessState)));
|
connect(m_currentProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStateChanged(QProcess::ProcessState)));
|
||||||
|
|
||||||
m_currentProcess->setProcessChannelMode(QProcess::MergedChannels);
|
m_currentProcess->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
m_currentProcessStartTimeStampms = nowms();
|
m_currentProcessStartTimeStampms = TimeUtil::nowms();
|
||||||
m_currentProcess->start(m_currentProcessCommandLine);
|
m_currentProcess->start(m_currentProcessCommandLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +257,7 @@ void Command::processStateChanged(QProcess::ProcessState newState)
|
|||||||
void Command::processError(QProcess::ProcessError error)
|
void Command::processError(QProcess::ProcessError error)
|
||||||
{
|
{
|
||||||
//qDebug("Command::processError: %d state: %d", error, m_currentProcessState);
|
//qDebug("Command::processError: %d state: %d", error, m_currentProcessState);
|
||||||
m_currentProcessFinishTimeStampms = nowms();
|
m_currentProcessFinishTimeStampms = TimeUtil::nowms();
|
||||||
m_currentProcessError = error;
|
m_currentProcessError = error;
|
||||||
m_isInError = true;
|
m_isInError = true;
|
||||||
|
|
||||||
@ -280,7 +281,7 @@ void Command::processError(QProcess::ProcessError error)
|
|||||||
void Command::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
void Command::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
{
|
{
|
||||||
//qDebug("Command::processFinished: (%d) %d", exitCode, exitStatus);
|
//qDebug("Command::processFinished: (%d) %d", exitCode, exitStatus);
|
||||||
m_currentProcessFinishTimeStampms = nowms();
|
m_currentProcessFinishTimeStampms = TimeUtil::nowms();
|
||||||
m_currentProcessExitCode = exitCode;
|
m_currentProcessExitCode = exitCode;
|
||||||
m_currentProcessExitStatus = exitStatus;
|
m_currentProcessExitStatus = exitStatus;
|
||||||
m_hasExited = true;
|
m_hasExited = true;
|
||||||
@ -297,13 +298,3 @@ 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->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
|
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<std::chrono::milliseconds>(now);
|
|
||||||
auto epoch = now_ms.time_since_epoch();
|
|
||||||
auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
|
|
||||||
|
|
||||||
return value.count();
|
|
||||||
}
|
|
@ -91,8 +91,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t nowms(); //!< Get now time in milliseconds
|
|
||||||
|
|
||||||
QString m_group;
|
QString m_group;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
QString m_command;
|
QString m_command;
|
||||||
|
@ -122,6 +122,7 @@ SOURCES += audio/audiodevicemanager.cpp\
|
|||||||
util/samplesourceserializer.cpp\
|
util/samplesourceserializer.cpp\
|
||||||
util/simpleserializer.cpp\
|
util/simpleserializer.cpp\
|
||||||
util/uid.cpp\
|
util/uid.cpp\
|
||||||
|
util/timeutil.cpp\
|
||||||
plugin/plugininterface.cpp\
|
plugin/plugininterface.cpp\
|
||||||
plugin/pluginapi.cpp\
|
plugin/pluginapi.cpp\
|
||||||
plugin/pluginmanager.cpp\
|
plugin/pluginmanager.cpp\
|
||||||
@ -220,6 +221,7 @@ HEADERS += audio/audiodevicemanager.h\
|
|||||||
util/samplesourceserializer.h\
|
util/samplesourceserializer.h\
|
||||||
util/simpleserializer.h\
|
util/simpleserializer.h\
|
||||||
util/uid.h\
|
util/uid.h\
|
||||||
|
util/timeutil.h\
|
||||||
webapi/webapiadapterinterface.h\
|
webapi/webapiadapterinterface.h\
|
||||||
webapi/webapirequestmapper.h\
|
webapi/webapirequestmapper.h\
|
||||||
webapi/webapiserver.h\
|
webapi/webapiserver.h\
|
||||||
|
27
sdrbase/util/timeutil.cpp
Normal file
27
sdrbase/util/timeutil.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||||
|
// //
|
||||||
|
// This program is free software; you can redistribute it and/or modify //
|
||||||
|
// it under the terms of the GNU General Public License as published by //
|
||||||
|
// the Free Software Foundation as version 3 of the License, or //
|
||||||
|
// //
|
||||||
|
// This program is distributed in the hope that it will be useful, //
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||||
|
// GNU General Public License V3 for more details. //
|
||||||
|
// //
|
||||||
|
// You should have received a copy of the GNU General Public License //
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "timeutil.h"
|
||||||
|
|
||||||
|
uint64_t TimeUtil::nowms()
|
||||||
|
{
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
|
||||||
|
auto epoch = now_ms.time_since_epoch();
|
||||||
|
auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
|
||||||
|
|
||||||
|
return value.count();
|
||||||
|
}
|
26
sdrbase/util/timeutil.h
Normal file
26
sdrbase/util/timeutil.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||||
|
// //
|
||||||
|
// This program is free software; you can redistribute it and/or modify //
|
||||||
|
// it under the terms of the GNU General Public License as published by //
|
||||||
|
// the Free Software Foundation as version 3 of the License, or //
|
||||||
|
// //
|
||||||
|
// This program is distributed in the hope that it will be useful, //
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||||
|
// GNU General Public License V3 for more details. //
|
||||||
|
// //
|
||||||
|
// You should have received a copy of the GNU General Public License //
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "export.h"
|
||||||
|
|
||||||
|
class SDRBASE_API TimeUtil
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static uint64_t nowms(); //!< returns the current epoch in milliseconds
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user