From 05109ff706b810eeb3ba5e2e6d093d9a50235f56 Mon Sep 17 00:00:00 2001 From: markuspg Date: Thu, 6 Oct 2016 16:44:23 +0200 Subject: [PATCH] Revert "Simplified ClientPinger by making the ping process a normal member" This reverts commit c73e1a6db6627cd99333139714e966ad48e3f8b3. --- src/Lib/clientpinger.cpp | 13 +++++++++---- src/Lib/clientpinger.h | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Lib/clientpinger.cpp b/src/Lib/clientpinger.cpp index 193b69d..5005c39 100644 --- a/src/Lib/clientpinger.cpp +++ b/src/Lib/clientpinger.cpp @@ -25,23 +25,28 @@ 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; diff --git a/src/Lib/clientpinger.h b/src/Lib/clientpinger.h index 40d9c94..ba8650d 100644 --- a/src/Lib/clientpinger.h +++ b/src/Lib/clientpinger.h @@ -44,6 +44,8 @@ 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. @@ -54,7 +56,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: