Qt 4.8
Public Functions | Protected Variables | Private Slots | Friends | List of all members
QHostInfoLookupManager Class Reference

#include <qhostinfo_p.h>

Inheritance diagram for QHostInfoLookupManager:
QAbstractHostInfoLookupManager QObject

Public Functions

void abortLookup (int id)
 
void clear ()
 
void lookupFinished (QHostInfoRunnable *r)
 
 QHostInfoLookupManager ()
 
void scheduleLookup (QHostInfoRunnable *r)
 
bool wasAborted (int id)
 
void work ()
 
 ~QHostInfoLookupManager ()
 
- Public Functions inherited from QAbstractHostInfoLookupManager
 ~QAbstractHostInfoLookupManager ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Variables

QList< int > abortedLookups
 
QList< QHostInfoRunnable * > currentLookups
 
QList< QHostInfoRunnable * > finishedLookups
 
QMutex mutex
 
QList< QHostInfoRunnable * > postponedLookups
 
QQueue< QHostInfoRunnable * > scheduledLookups
 
QThreadPool threadPool
 
bool wasDeleted
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Private Slots

void waitForThreadPoolDone ()
 

Friends

class QHostInfoRunnable
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Public Variables inherited from QAbstractHostInfoLookupManager
QHostInfoCache cache
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QAbstractHostInfoLookupManager
 QAbstractHostInfoLookupManager ()
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Static Protected Functions inherited from QAbstractHostInfoLookupManager
static QAbstractHostInfoLookupManagerglobalInstance ()
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 194 of file qhostinfo_p.h.

Constructors and Destructors

◆ QHostInfoLookupManager()

QHostInfoLookupManager::QHostInfoLookupManager ( )

Definition at line 561 of file qhostinfo.cpp.

562 {
565  threadPool.setMaxThreadCount(5); // do 5 DNS lookups in parallel
566 }
#define SLOT(a)
Definition: qobjectdefs.h:226
QThreadPool threadPool
Definition: qhostinfo_p.h:220
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
static QThread * mainThread()
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
void setMaxThreadCount(int maxThreadCount)

◆ ~QHostInfoLookupManager()

QHostInfoLookupManager::~QHostInfoLookupManager ( )

Definition at line 568 of file qhostinfo.cpp.

569 {
570  wasDeleted = true;
571 
572  // don't qDeleteAll currentLookups, the QThreadPool has ownership
573  clear();
574 }

Functions

◆ abortLookup()

void QHostInfoLookupManager::abortLookup ( int  id)

Definition at line 675 of file qhostinfo.cpp.

676 {
677  if (wasDeleted)
678  return;
679 
680  QMutexLocker locker(&this->mutex);
681 
682  // is postponed? delete and return
683  for (int i = 0; i < postponedLookups.length(); i++) {
684  if (postponedLookups.at(i)->id == id) {
685  delete postponedLookups.takeAt(i);
686  return;
687  }
688  }
689 
690  // is scheduled? delete and return
691  for (int i = 0; i < scheduledLookups.length(); i++) {
692  if (scheduledLookups.at(i)->id == id) {
693  delete scheduledLookups.takeAt(i);
694  return;
695  }
696  }
697 
698  if (!abortedLookups.contains(id))
700 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< int > abortedLookups
Definition: qhostinfo_p.h:218
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int length() const
This function is identical to count().
Definition: qlist.h:281
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
QQueue< QHostInfoRunnable * > scheduledLookups
Definition: qhostinfo_p.h:216
QList< QHostInfoRunnable * > postponedLookups
Definition: qhostinfo_p.h:215

◆ clear()

void QHostInfoLookupManager::clear ( )
virtual

Implements QAbstractHostInfoLookupManager.

Definition at line 576 of file qhostinfo.cpp.

Referenced by ~QHostInfoLookupManager().

577 {
578  {
579  QMutexLocker locker(&mutex);
586  }
587 
589  cache.clear();
590 }
QThreadPool threadPool
Definition: qhostinfo_p.h:220
void waitForDone()
Waits for each thread to exit and removes all threads from the thread pool.
void clear()
Removes all items from the list.
Definition: qlist.h:764
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QList< QHostInfoRunnable * > finishedLookups
Definition: qhostinfo_p.h:217
QQueue< QHostInfoRunnable * > scheduledLookups
Definition: qhostinfo_p.h:216
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QList< QHostInfoRunnable * > postponedLookups
Definition: qhostinfo_p.h:215

◆ lookupFinished()

void QHostInfoLookupManager::lookupFinished ( QHostInfoRunnable r)

Definition at line 713 of file qhostinfo.cpp.

Referenced by QHostInfoRunnable::run().

714 {
715  if (wasDeleted)
716  return;
717 
718  QMutexLocker locker(&this->mutex);
721  work();
722 }
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QHostInfoRunnable * > currentLookups
Definition: qhostinfo_p.h:214
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QList< QHostInfoRunnable * > finishedLookups
Definition: qhostinfo_p.h:217

◆ scheduleLookup()

void QHostInfoLookupManager::scheduleLookup ( QHostInfoRunnable r)

Definition at line 664 of file qhostinfo.cpp.

Referenced by QHostInfo::lookupHost().

665 {
666  if (wasDeleted)
667  return;
668 
669  QMutexLocker locker(&this->mutex);
671  work();
672 }
void enqueue(const T &t)
Adds value t to the tail of the queue.
Definition: qqueue.h:60
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QQueue< QHostInfoRunnable * > scheduledLookups
Definition: qhostinfo_p.h:216

◆ waitForThreadPoolDone

void QHostInfoLookupManager::waitForThreadPoolDone ( )
inlineprivateslot

Definition at line 227 of file qhostinfo_p.h.

Referenced by QHostInfoLookupManager().

227 { threadPool.waitForDone(); }
QThreadPool threadPool
Definition: qhostinfo_p.h:220
void waitForDone()
Waits for each thread to exit and removes all threads from the thread pool.

◆ wasAborted()

bool QHostInfoLookupManager::wasAborted ( int  id)

Definition at line 703 of file qhostinfo.cpp.

Referenced by QHostInfoRunnable::run().

704 {
705  if (wasDeleted)
706  return true;
707 
708  QMutexLocker locker(&this->mutex);
709  return abortedLookups.contains(id);
710 }
QList< int > abortedLookups
Definition: qhostinfo_p.h:218
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ work()

void QHostInfoLookupManager::work ( )

Definition at line 592 of file qhostinfo.cpp.

Referenced by lookupFinished(), and scheduleLookup().

593 {
594  if (wasDeleted)
595  return;
596 
597  // goals of this function:
598  // - launch new lookups via the thread pool
599  // - make sure only one lookup per host/IP is in progress
600 
601  QMutexLocker locker(&mutex);
602 
603  if (!finishedLookups.isEmpty()) {
604  // remove ID from aborted if it is in there
605  for (int i = 0; i < finishedLookups.length(); i++) {
607  }
608 
610  }
611 
612  if (!postponedLookups.isEmpty()) {
613  // try to start the postponed ones
614 
615  QMutableListIterator<QHostInfoRunnable*> iterator(postponedLookups);
616  while (iterator.hasNext()) {
617  QHostInfoRunnable* postponed = iterator.next();
618 
619  // check if none of the postponed hostnames is currently running
620  bool alreadyRunning = false;
621  for (int i = 0; i < currentLookups.length(); i++) {
622  if (currentLookups.at(i)->toBeLookedUp == postponed->toBeLookedUp) {
623  alreadyRunning = true;
624  break;
625  }
626  }
627  if (!alreadyRunning) {
628  iterator.remove();
629  scheduledLookups.prepend(postponed); // prepend! we want to finish it ASAP
630  }
631  }
632  }
633 
634  if (!scheduledLookups.isEmpty()) {
635  // try to start the new ones
636  QMutableListIterator<QHostInfoRunnable*> iterator(scheduledLookups);
637  while (iterator.hasNext()) {
638  QHostInfoRunnable *scheduled = iterator.next();
639 
640  // check if a lookup for this host is already running, then postpone
641  for (int i = 0; i < currentLookups.size(); i++) {
642  if (currentLookups.at(i)->toBeLookedUp == scheduled->toBeLookedUp) {
643  iterator.remove();
644  postponedLookups.append(scheduled);
645  scheduled = 0;
646  break;
647  }
648  }
649 
650  if (scheduled && currentLookups.size() < threadPool.maxThreadCount()) {
651  // runnable now running in new thread, track this in currentLookups
652  threadPool.start(scheduled);
653  iterator.remove();
654  currentLookups.append(scheduled);
655  } else {
656  // was postponed, continue iterating
657  continue;
658  }
659  };
660  }
661 }
QThreadPool threadPool
Definition: qhostinfo_p.h:220
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< int > abortedLookups
Definition: qhostinfo_p.h:218
QString toBeLookedUp
Definition: qhostinfo_p.h:171
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void start(QRunnable *runnable, int priority=0)
Reserves a thread and uses it to run runnable, unless this thread will make the current thread count ...
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< QHostInfoRunnable * > currentLookups
Definition: qhostinfo_p.h:214
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int length() const
This function is identical to count().
Definition: qlist.h:281
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int maxThreadCount
This property represents the maximum number of threads used by the thread pool.
Definition: qthreadpool.h:63
QList< QHostInfoRunnable * > finishedLookups
Definition: qhostinfo_p.h:217
QQueue< QHostInfoRunnable * > scheduledLookups
Definition: qhostinfo_p.h:216
QList< QHostInfoRunnable * > postponedLookups
Definition: qhostinfo_p.h:215
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

Friends and Related Functions

◆ QHostInfoRunnable

friend class QHostInfoRunnable
friend

Definition at line 212 of file qhostinfo_p.h.

Properties

◆ abortedLookups

QList<int> QHostInfoLookupManager::abortedLookups
protected

Definition at line 218 of file qhostinfo_p.h.

Referenced by abortLookup(), wasAborted(), and work().

◆ currentLookups

QList<QHostInfoRunnable*> QHostInfoLookupManager::currentLookups
protected

Definition at line 214 of file qhostinfo_p.h.

Referenced by lookupFinished(), and work().

◆ finishedLookups

QList<QHostInfoRunnable*> QHostInfoLookupManager::finishedLookups
protected

Definition at line 217 of file qhostinfo_p.h.

Referenced by clear(), lookupFinished(), and work().

◆ mutex

QMutex QHostInfoLookupManager::mutex
protected

◆ postponedLookups

QList<QHostInfoRunnable*> QHostInfoLookupManager::postponedLookups
protected

Definition at line 215 of file qhostinfo_p.h.

Referenced by abortLookup(), clear(), QHostInfoRunnable::run(), and work().

◆ scheduledLookups

QQueue<QHostInfoRunnable*> QHostInfoLookupManager::scheduledLookups
protected

Definition at line 216 of file qhostinfo_p.h.

Referenced by abortLookup(), clear(), scheduleLookup(), and work().

◆ threadPool

QThreadPool QHostInfoLookupManager::threadPool
protected

Definition at line 220 of file qhostinfo_p.h.

Referenced by clear(), QHostInfoLookupManager(), and work().

◆ wasDeleted

bool QHostInfoLookupManager::wasDeleted
protected

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