Revert "Simplified ClientPinger by making the ping process a normal member"

This reverts commit c73e1a6db6.
remotes/origin/HEAD
markuspg 10 years ago
parent 7660a47003
commit 05109ff706

@ -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) // 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 }, pingArguments{ QStringList{} << "-c" << "1" << "-w" << "1" << "-q" << argIP },
pingCommand{ argPingCommand }, pingCommand{ argPingCommand },
pingProcess{ new QProcess{ this } },
state{ state_t::UNINITIALIZED } state{ state_t::UNINITIALIZED }
{ {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
pingProcess.setProcessEnvironment(env); pingProcess->setProcessEnvironment(env);
// emit ping_string(new QString(*ping_command + " " + ping_arguments->join(" "))); // 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 // Initialize the new state to be queried
state_t newState = state_t::UNINITIALIZED; state_t newState = state_t::UNINITIALIZED;
// Query the current state of the client // Query the current state of the client
pingProcess.start( pingCommand, pingArguments ); pingProcess->start( pingCommand, pingArguments );
if ( !pingProcess.waitForFinished( 2500 ) ) if ( !pingProcess->waitForFinished( 2500 ) )
newState = state_t::ERROR; newState = state_t::ERROR;
else { else {
if ( pingProcess.exitCode() == 0 ) if ( pingProcess->exitCode() == 0 )
newState = state_t::RESPONDING; newState = state_t::RESPONDING;
else else
newState = state_t::NOT_RESPONDING; newState = state_t::NOT_RESPONDING;

@ -44,6 +44,8 @@ public:
*/ */
explicit ClientPinger( const QString &argIP, const QString &argPingCommand, explicit ClientPinger( const QString &argIP, const QString &argPingCommand,
QObject *argParent = nullptr ); QObject *argParent = nullptr );
//! ClientPinger's destructor
~ClientPinger();
public slots: public slots:
//! This slot executes a ping when called. //! This slot executes a ping when called.
@ -54,7 +56,7 @@ public slots:
private: private:
const QStringList pingArguments; //! The arguments for the 'ping' command const QStringList pingArguments; //! The arguments for the 'ping' command
const QString pingCommand; //! The 'ping' command itself 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 state_t state; //! Stores the current state of the client
signals: signals:

Loading…
Cancel
Save