Qt 4.8
Public Functions | Public Variables | List of all members
QHostInfoRunnable Class Reference

#include <qhostinfo_p.h>

Inheritance diagram for QHostInfoRunnable:
QRunnable

Public Functions

 QHostInfoRunnable (QString hn, int i)
 
void run ()
 Implement this pure virtual function in your subclass. More...
 
- Public Functions inherited from QRunnable
bool autoDelete () const
 Returns true is auto-deletion is enabled; false otherwise. More...
 
 QRunnable ()
 Constructs a QRunnable. More...
 
void setAutoDelete (bool _autoDelete)
 Enables auto-deletion if autoDelete is true; otherwise auto-deletion is disabled. More...
 
virtual ~QRunnable ()
 QRunnable virtual destructor. More...
 

Public Variables

int id
 
QHostInfoResult resultEmitter
 
QString toBeLookedUp
 

Detailed Description

Definition at line 165 of file qhostinfo_p.h.

Constructors and Destructors

◆ QHostInfoRunnable()

QHostInfoRunnable::QHostInfoRunnable ( QString  hn,
int  i 
)

Definition at line 496 of file qhostinfo.cpp.

496  : toBeLookedUp(hn), id(i)
497 {
498  setAutoDelete(true);
499 }
void setAutoDelete(bool _autoDelete)
Enables auto-deletion if autoDelete is true; otherwise auto-deletion is disabled. ...
Definition: qrunnable.h:67
QString toBeLookedUp
Definition: qhostinfo_p.h:171

Functions

◆ run()

void QHostInfoRunnable::run ( void  )
virtual

Implement this pure virtual function in your subclass.

Implements QRunnable.

Definition at line 502 of file qhostinfo.cpp.

503 {
504  QHostInfoLookupManager *manager = theHostInfoLookupManager();
505  // check aborted
506  if (manager->wasAborted(id)) {
507  manager->lookupFinished(this);
508  return;
509  }
510 
511  QHostInfo hostInfo;
512 
513  // QHostInfo::lookupHost already checks the cache. However we need to check
514  // it here too because it might have been cache saved by another QHostInfoRunnable
515  // in the meanwhile while this QHostInfoRunnable was scheduled but not running
516  if (manager->cache.isEnabled()) {
517  // check the cache first
518  bool valid = false;
519  hostInfo = manager->cache.get(toBeLookedUp, &valid);
520  if (!valid) {
521  // not in cache, we need to do the lookup and store the result in the cache
523  manager->cache.put(toBeLookedUp, hostInfo);
524  }
525  } else {
526  // cache is not enabled, just do the lookup and continue
528  }
529 
530  // check aborted again
531  if (manager->wasAborted(id)) {
532  manager->lookupFinished(this);
533  return;
534  }
535 
536  // signal emission
537  hostInfo.setLookupId(id);
539 
540  // now also iterate through the postponed ones
541  {
542  QMutexLocker locker(&manager->mutex);
543  QMutableListIterator<QHostInfoRunnable*> iterator(manager->postponedLookups);
544  while (iterator.hasNext()) {
545  QHostInfoRunnable* postponed = iterator.next();
546  if (toBeLookedUp == postponed->toBeLookedUp) {
547  // we can now emit
548  iterator.remove();
549  hostInfo.setLookupId(postponed->id);
550  postponed->resultEmitter.emitResultsReady(hostInfo);
551  delete postponed;
552  }
553  }
554  }
555 
556  manager->lookupFinished(this);
557 
558  // thread goes back to QThreadPool
559 }
void emitResultsReady(const QHostInfo &info)
Definition: qhostinfo_p.h:89
bool isEnabled()
Definition: qhostinfo.cpp:772
void put(const QString &name, const QHostInfo &info)
Definition: qhostinfo.cpp:804
QString toBeLookedUp
Definition: qhostinfo_p.h:171
The QHostInfo class provides static functions for host name lookups.
Definition: qhostinfo.h:58
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
bool wasAborted(int id)
Definition: qhostinfo.cpp:703
QHostInfoResult resultEmitter
Definition: qhostinfo_p.h:173
static QHostInfo fromName(const QString &hostName)
void lookupFinished(QHostInfoRunnable *r)
Definition: qhostinfo.cpp:713
QHostInfo get(const QString &name, bool *valid)
Definition: qhostinfo.cpp:785
QList< QHostInfoRunnable * > postponedLookups
Definition: qhostinfo_p.h:215
void setLookupId(int id)
Sets the ID of this lookup to id.
Definition: qhostinfo.cpp:443

Properties

◆ id

int QHostInfoRunnable::id

◆ resultEmitter

QHostInfoResult QHostInfoRunnable::resultEmitter

Definition at line 173 of file qhostinfo_p.h.

Referenced by QHostInfo::lookupHost(), and run().

◆ toBeLookedUp

QString QHostInfoRunnable::toBeLookedUp

Definition at line 171 of file qhostinfo_p.h.

Referenced by run(), and QHostInfoLookupManager::work().


The documentation for this class was generated from the following files: