kopia lustrzana https://github.com/f4exb/sdrangel
				
				
				
			Windows: MSVC2017: changes in sdrbase (1): fixed with std::chrono
							rodzic
							
								
									6708a6b700
								
							
						
					
					
						commit
						127178f44c
					
				|  | @ -14,12 +14,14 @@ | |||
| // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | ||||
| ///////////////////////////////////////////////////////////////////////////////////
 | ||||
| 
 | ||||
| #include "command.h" | ||||
| #include "util/simpleserializer.h" | ||||
| #include <chrono> | ||||
| 
 | ||||
| #include <QKeySequence> | ||||
| #include <QProcess> | ||||
| 
 | ||||
| #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<std::chrono::milliseconds>(now); | ||||
|     auto epoch = now_ms.time_since_epoch(); | ||||
|     auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch); | ||||
| 
 | ||||
|     return value.count(); | ||||
| } | ||||
|  | @ -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; | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ NullSink::~NullSink() | |||
| 
 | ||||
| bool NullSink::init(const Message& message) | ||||
| { | ||||
|     (void) message | ||||
|     (void) message; | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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("-"); | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 f4exb
						f4exb