Reformat ClientPinger

remotes/origin/HEAD
markuspg 6 years ago
parent c2d4f6024c
commit 385a42dedf

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
@ -19,45 +19,44 @@
#include "clientpinger.h"
lc::ClientPinger::ClientPinger( const QString &argIP,
const QString &argPingCommand, QObject *argParent ) :
QObject{ argParent },
lc::ClientPinger::ClientPinger(const QString &argIP,
const QString &argPingCommand,
QObject *argParent) :
QObject{argParent},
// Arguments: -c 1 (send 1 ECHO_REQUEST packet) -w 1 (timeout after 1 second) -q (quiet output)
pingArguments{ QStringList{} << "-c" << "1" << "-w" << "1" << "-q" << argIP },
pingCommand{ argPingCommand },
pingProcess{ new QProcess{ this } },
state{ state_t::UNINITIALIZED }
pingArguments{"-c", "1", "-w", "1", "-q", argIP},
pingCommand{argPingCommand},
pingProcess{std::make_unique<QProcess>()}
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
pingProcess->setProcessEnvironment(env);
pingProcess->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
// emit ping_string(new QString(*ping_command + " " + ping_arguments->join(" ")));
}
lc::ClientPinger::~ClientPinger() {
delete pingProcess;
}
void lc::ClientPinger::doPing() {
void lc::ClientPinger::doPing()
{
// Initialize the new state to be queried
state_t newState = state_t::UNINITIALIZED;
// Query the current state of the client
pingProcess->start( pingCommand, pingArguments );
if ( !pingProcess->waitForFinished( 2500 ) )
pingProcess->start(pingCommand, pingArguments);
if (!pingProcess->waitForFinished(2500)
|| pingProcess->exitStatus() != QProcess::NormalExit)
newState = state_t::ERROR;
else {
if ( pingProcess->exitCode() == 0 )
if (pingProcess->exitCode() == 0) {
newState = state_t::RESPONDING;
else
} else {
newState = state_t::NOT_RESPONDING;
}
}
if ( newState != state ) {
if (newState != state) {
state = newState;
emit PingFinished( newState );
emit PingFinished(state);
}
}
void lc::ClientPinger::setStateToZLEAF_RUNNING() {
void lc::ClientPinger::setStateToZLEAF_RUNNING()
{
state = state_t::ZLEAF_RUNNING;
}

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
@ -20,11 +20,14 @@
#ifndef CLIENTPINGER_H
#define CLIENTPINGER_H
#include "global.h"
#include <QObject>
#include <QProcess>
#include <QThread>
#include "global.h"
#include <memory>
class QProcess;
namespace lc {
@ -32,7 +35,8 @@ namespace lc {
/*!
This class is just used for executing repetitive pings.
*/
class ClientPinger : public QObject {
class ClientPinger : public QObject
{
Q_OBJECT
public:
@ -42,10 +46,8 @@ public:
@param argPingCommand The path were the command to be executed for pings resides
@param argParent The ClientPinger's parent owning this instance of it
*/
explicit ClientPinger( const QString &argIP, const QString &argPingCommand,
QObject *argParent = nullptr );
//! ClientPinger's destructor
~ClientPinger();
explicit ClientPinger(const QString &argIP, const QString &argPingCommand,
QObject *argParent = nullptr);
public slots:
//! This slot executes a ping when called.
@ -54,17 +56,21 @@ public slots:
void setStateToZLEAF_RUNNING();
private:
const QStringList pingArguments; //! The arguments for the 'ping' command
const QString pingCommand; //! The 'ping' command itself
QProcess * pingProcess; //! The 'ping' process which will be executed on every call of 'do_ping()'
state_t state; //! Stores the current state of the client
//! The arguments for the 'ping' command
const QStringList pingArguments;
//! The 'ping' command itself
const QString pingCommand;
//! The 'ping' process which will be executed on every call of 'do_ping()'
std::unique_ptr<QProcess> pingProcess;
//! Stores the current state of the client
state_t state = state_t::UNINITIALIZED;
signals:
//! This signal was just implemented for testing purposes
//! This signal is emitted if the ping finished and the state of the client changed
void PingFinished( state_t state );
void PingFinished(state_t state);
};
}
} // namespace lc
#endif // CLIENTPINGER_H

Loading…
Cancel
Save