Source Code (Use browser search to find items of interest.)

Class Index

libsearch'KPing (./kdenetwork/libsearch/kping.h:9)

class KPing : public QObject {

  Q_OBJECT

public:
  KPing() {}
  ~KPing();

  void start( QString _host );
  void stop();

signals:
  void speed( QString _host, float speed );
  void error( QString host );

protected slots:
  void slotPingOutput(KProcess *, char *, int);
  void slotProcessDead(KProcess *);

protected:
  void processOutput();

private:
  QString host;

  KProcess childProcess;
  QString buf;
};



libsearch'KPing::~KPing() (./kdenetwork/libsearch/kping.cpp:48)

KPing::~KPing() {
  if (childProcess.isRunning()) {
    childProcess.kill(15);
  }
}



libsearch'KPing::start() (./kdenetwork/libsearch/kping.cpp:55)

void KPing::start( QString _host ) {

  host = _host;

  connect(&childProcess, SIGNAL(processExited(KProcess *)), 
	  SLOT(slotProcessDead(KProcess *)));
  connect(&childProcess, SIGNAL(receivedStdout(KProcess *, char *, int)), 
	  this, SLOT(slotPingOutput(KProcess *, char *, int)));
  connect(&childProcess, SIGNAL(receivedStderr(KProcess *, char *, int)), 
	  this, SLOT(slotPingOutput(KProcess *, char *, int)));

  childProcess.setExecutable( "ping" );
  childProcess << host;

  if (!childProcess.start(KProcess::NotifyOnExit, KProcess::All)){
    kDebugInfo( 7012, "Ping not started");
    emit error( host );
  }
}



libsearch'KPing::slotProcessDead() (./kdenetwork/libsearch/kping.cpp:76)

void KPing::slotProcessDead( KProcess* ) {
  // disconnect KProcess
  disconnect(&childProcess, SIGNAL(receivedStdout(KProcess *, char *, int)), 
	     this, SLOT(slotPingOutput(KProcess *, char *, int)));
  disconnect(&childProcess, SIGNAL(receivedStderr(KProcess *, char *, int)), 
	     this, SLOT(slotPingOutput(KProcess *, char *, int)));
  disconnect(&childProcess, SIGNAL(processExited(KProcess *)), 
	     this, SLOT(slotProcessDead(KProcess *)));
}



libsearch'KPing::slotPingOutput() (./kdenetwork/libsearch/kping.cpp:87)

void KPing::slotPingOutput( KProcess*, char* buffer, int buflen ) {
  QString newstuff = buffer;
  newstuff.truncate( buflen );

  buf += newstuff;
  processOutput();
}



libsearch'KPing::processOutput() (./kdenetwork/libsearch/kping.cpp:96)

void KPing::processOutput() {
  int pos;

  while ( (pos = buf.find('\n')) != -1) {
    QString item = buf.left(pos);
    if (!item.isEmpty()) {
  
      int start = item.find( "time=" );
      int end = item.find( " ms" );

      QString spd  = item.mid( start+5, end );

      if ( spd.length() > 0 )
	emit speed( host, spd.toFloat() );
      else {
	emit error( host );
	slotProcessDead( 0L );
      }

    }
    buf = buf.right(buf.length()-pos-1);
  }
}



libsearch'KPing::stop() (./kdenetwork/libsearch/kping.cpp:121)

void KPing::stop() {
  kDebugInfo( 7013, "Ping interrupted");
  childProcess.kill( SIGKILL );

  // no need to emit anything ( because we called stop() programatically )
}