Simplified ClientPinger by making the ping process a normal member

remotes/origin/HEAD
root 8 years ago
parent 2eeccd9987
commit c73e1a6db6

@ -25,28 +25,23 @@ lc::ClientPinger::ClientPinger( const QString &argIP,
// 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 }
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
pingProcess->setProcessEnvironment(env);
pingProcess.setProcessEnvironment(env);
// emit ping_string(new QString(*ping_command + " " + ping_arguments->join(" ")));
}
lc::ClientPinger::~ClientPinger() {
delete pingProcess;
}
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 ) )
newState = state_t::ERROR;
else {
if ( pingProcess->exitCode() == 0 )
if ( pingProcess.exitCode() == 0 )
newState = state_t::RESPONDING;
else
newState = state_t::NOT_RESPONDING;

@ -44,8 +44,6 @@ public:
*/
explicit ClientPinger( const QString &argIP, const QString &argPingCommand,
QObject *argParent = nullptr );
//! ClientPinger's destructor
~ClientPinger();
public slots:
//! This slot executes a ping when called.
@ -56,7 +54,7 @@ public slots:
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()'
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
signals:

Loading…
Cancel
Save