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

#include <qeventdispatcher_unix_p.h>

Inheritance diagram for QTimerInfoList:
QList< QTimerInfo *>

Public Functions

int activateTimers ()
 
 QTimerInfoList ()
 
QList< QPair< int, int > > registeredTimers (QObject *object) const
 
void registerTimer (int timerId, int interval, QObject *object)
 
void repairTimersIfNeeded ()
 
void timerInsert (QTimerInfo *)
 
void timerRepair (const timeval &)
 
bool timerWait (timeval &)
 
bool unregisterTimer (int timerId)
 
bool unregisterTimers (QObject *object)
 
timeval updateCurrentTime ()
 
- Public Functions inherited from QList< QTimerInfo *>
void append (const QTimerInfo * &t)
 Inserts value at the end of the list. More...
 
void append (const QList< QTimerInfo * > &t)
 Appends the items of the value list to this list. More...
 
const QTimerInfo * & at (int i) const
 Returns the item at index position i in the list. More...
 
QTimerInfo * & back ()
 This function is provided for STL compatibility. More...
 
const QTimerInfo * & back () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
iterator begin ()
 Returns an STL-style iterator pointing to the first item in the list. More...
 
const_iterator begin () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void clear ()
 Removes all items from the list. More...
 
const_iterator constBegin () const
 Returns a const STL-style iterator pointing to the first item in the list. More...
 
const_iterator constEnd () const
 Returns a const STL-style iterator pointing to the imaginary item after the last item in the list. More...
 
QBool contains (const QTimerInfo * &t) const
 Returns true if the list contains an occurrence of value; otherwise returns false. More...
 
int count (const QTimerInfo * &t) const
 Returns the number of occurrences of value in the list. More...
 
int count () const
 Returns the number of items in the list. More...
 
void detach ()
 
void detachShared ()
 This prevents needless mallocs, and makes QList more exception safe in case of cleanup work done in destructors on empty lists. More...
 
bool empty () const
 This function is provided for STL compatibility. More...
 
iterator end ()
 Returns an STL-style iterator pointing to the imaginary item after the last item in the list. More...
 
const_iterator end () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool endsWith (const QTimerInfo * &t) const
 Returns true if this list is not empty and its last item is equal to value; otherwise returns false. More...
 
iterator erase (iterator pos)
 Removes the item associated with the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()). More...
 
iterator erase (iterator first, iterator last)
 Removes all the items from begin up to (but not including) end. More...
 
QTimerInfo * & first ()
 Returns a reference to the first item in the list. More...
 
const QTimerInfo * & first () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QTimerInfo * & front ()
 This function is provided for STL compatibility. More...
 
const QTimerInfo * & front () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int indexOf (const QTimerInfo * &t, int from=0) const
 Returns the index position of the first occurrence of value in the list, searching forward from index position from. More...
 
void insert (int i, const QTimerInfo * &t)
 Inserts value at index position i in the list. More...
 
iterator insert (iterator before, const QTimerInfo * &t)
 Inserts value in front of the item pointed to by the iterator before. More...
 
bool isDetached () const
 
bool isEmpty () const
 Returns true if the list contains no items; otherwise returns false. More...
 
bool isSharedWith (const QList< QTimerInfo * > &other) const
 
QTimerInfo * & last ()
 Returns a reference to the last item in the list. More...
 
const QTimerInfo * & last () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int lastIndexOf (const QTimerInfo * &t, int from=-1) const
 Returns the index position of the last occurrence of value in the list, searching backward from index position from. More...
 
int length () const
 This function is identical to count(). More...
 
QList< QTimerInfo * > mid (int pos, int length=-1) const
 Returns a list whose elements are copied from this list, starting at position pos. More...
 
void move (int from, int to)
 Moves the item at index position from to index position to. More...
 
bool operator!= (const QList< QTimerInfo * > &l) const
 Returns true if other is not equal to this list; otherwise returns false. More...
 
QList< QTimerInfo * > operator+ (const QList< QTimerInfo * > &l) const
 Returns a list that contains all the items in this list followed by all the items in the other list. More...
 
QList< QTimerInfo * > & operator+= (const QList< QTimerInfo * > &l)
 Appends the items of the other list to this list and returns a reference to this list. More...
 
QList< QTimerInfo * > & operator+= (const QTimerInfo * &t)
 Appends value to the list. More...
 
QList< QTimerInfo * > & operator<< (const QList< QTimerInfo * > &l)
 Appends the items of the other list to this list and returns a reference to this list. More...
 
QList< QTimerInfo * > & operator<< (const QTimerInfo * &t)
 Appends value to the list. More...
 
QList< QTimerInfo * > & operator= (const QList< QTimerInfo * > &l)
 Assigns other to this list and returns a reference to this list. More...
 
bool operator== (const QList< QTimerInfo * > &l) const
 Returns true if other is equal to this list; otherwise returns false. More...
 
const QTimerInfo * & operator[] (int i) const
 Same as at(). More...
 
QTimerInfo * & operator[] (int i)
 Returns the item at index position i as a modifiable reference. More...
 
void pop_back ()
 This function is provided for STL compatibility. More...
 
void pop_front ()
 This function is provided for STL compatibility. More...
 
void prepend (const QTimerInfo * &t)
 Inserts value at the beginning of the list. More...
 
void push_back (const QTimerInfo * &t)
 This function is provided for STL compatibility. More...
 
void push_front (const QTimerInfo * &t)
 This function is provided for STL compatibility. More...
 
 QList ()
 Constructs an empty list. More...
 
 QList (const QList< QTimerInfo * > &l)
 Constructs a copy of other. More...
 
int removeAll (const QTimerInfo * &t)
 Removes all occurrences of value in the list and returns the number of entries removed. More...
 
void removeAt (int i)
 Removes the item at index position i. More...
 
void removeFirst ()
 Removes the first item in the list. More...
 
void removeLast ()
 Removes the last item in the list. More...
 
bool removeOne (const QTimerInfo * &t)
 Removes the first occurrence of value in the list and returns true on success; otherwise returns false. More...
 
void replace (int i, const QTimerInfo * &t)
 Replaces the item at index position i with value. More...
 
void reserve (int size)
 Reserve space for alloc elements. More...
 
void setSharable (bool sharable)
 
int size () const
 Returns the number of items in the list. More...
 
bool startsWith (const QTimerInfo * &t) const
 Returns true if this list is not empty and its first item is equal to value; otherwise returns false. More...
 
void swap (QList< QTimerInfo * > &other)
 Swaps list other with this list. More...
 
void swap (int i, int j)
 Exchange the item at index position i with the item at index position j. More...
 
QTimerInfotakeAt (int i)
 Removes the item at index position i and returns it. More...
 
QTimerInfotakeFirst ()
 Removes the first item in the list and returns it. More...
 
QTimerInfotakeLast ()
 Removes the last item in the list and returns it. More...
 
QSet< QTimerInfo * > toSet () const
 Returns a QSet object with the data contained in this QList. More...
 
std::list< QTimerInfo * > toStdList () const
 Returns a std::list object with the data contained in this QList. More...
 
QVector< QTimerInfo * > toVector () const
 Returns a QVector object with the data contained in this QList. More...
 
QTimerInfovalue (int i) const
 Returns the value at index position i in the list. More...
 
QTimerInfovalue (int i, const QTimerInfo * &defaultValue) const
 If the index i is out of bounds, the function returns defaultValue. More...
 
 ~QList ()
 Destroys the list. More...
 

Public Variables

timeval currentTime
 
- Public Variables inherited from QList< QTimerInfo *>
QListData::Datad
 
QListData p
 

Properties

QTimerInfofirstTimerInfo
 

Additional Inherited Members

- Public Types inherited from QList< QTimerInfo *>
typedef const value_typeconst_pointer
 Typedef for const T *. More...
 
typedef const value_typeconst_reference
 Typedef for const T &. More...
 
typedef const_iterator ConstIterator
 Qt-style synonym for QList::const_iterator. More...
 
typedef qptrdiff difference_type
 Typedef for ptrdiff_t. More...
 
typedef iterator Iterator
 Qt-style synonym for QList::iterator. More...
 
typedef value_typepointer
 Typedef for T *. More...
 
typedef value_typereference
 Typedef for T &. More...
 
typedef int size_type
 Typedef for int. More...
 
typedef QTimerInfovalue_type
 Typedef for T. More...
 
- Static Public Functions inherited from QList< QTimerInfo *>
static QList< QTimerInfo * > fromSet (const QSet< QTimerInfo * > &set)
 Returns a QList object with the data contained in set. More...
 
static QList< QTimerInfo * > fromStdList (const std::list< QTimerInfo * > &list)
 Returns a QList object with the data contained in list. More...
 
static QList< QTimerInfo * > fromVector (const QVector< QTimerInfo * > &vector)
 Returns a QList object with the data contained in vector. More...
 

Detailed Description

Definition at line 81 of file qeventdispatcher_unix_p.h.

Constructors and Destructors

◆ QTimerInfoList()

QTimerInfoList::QTimerInfoList ( )

Definition at line 328 of file qeventdispatcher_unix.cpp.

329 {
330 #if (_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC) && !defined(Q_OS_NACL)
332  // not using monotonic timers, initialize the timeChanged() machinery
333  previousTime = qt_gettime();
334 
335  tms unused;
336  previousTicks = times(&unused);
337 
338  ticksPerSecond = sysconf(_SC_CLK_TCK);
339  msPerTick = 1000/ticksPerSecond;
340  } else {
341  // detected monotonic timers
342  previousTime.tv_sec = previousTime.tv_usec = 0;
343  previousTicks = 0;
344  ticksPerSecond = 0;
345  msPerTick = 0;
346  }
347 #endif
348 
349  firstTimerInfo = 0;
350 }
static bool isMonotonic()
Returns true if this is a monotonic clock, false otherwise.
QTimerInfo * firstTimerInfo
timeval qt_gettime()

Functions

◆ activateTimers()

int QTimerInfoList::activateTimers ( )

Definition at line 565 of file qeventdispatcher_unix.cpp.

566 {
568  return 0; // nothing to do
569 
570  int n_act = 0, maxCount = 0;
571  firstTimerInfo = 0;
572 
573  timeval currentTime = updateCurrentTime();
575 
576 
577  // Find out how many timer have expired
579  if (currentTime < (*it)->timeout)
580  break;
581  maxCount++;
582  }
583 
584  //fire the timers.
585  while (maxCount--) {
586  if (isEmpty())
587  break;
588 
589  QTimerInfo *currentTimerInfo = first();
590  if (currentTime < currentTimerInfo->timeout)
591  break; // no timer has expired
592 
593  if (!firstTimerInfo) {
594  firstTimerInfo = currentTimerInfo;
595  } else if (firstTimerInfo == currentTimerInfo) {
596  // avoid sending the same timer multiple times
597  break;
598  } else if (currentTimerInfo->interval < firstTimerInfo->interval
599  || currentTimerInfo->interval == firstTimerInfo->interval) {
600  firstTimerInfo = currentTimerInfo;
601  }
602 
603  // remove from list
604  removeFirst();
605 
606  // determine next timeout time
607  currentTimerInfo->timeout += currentTimerInfo->interval;
608  if (currentTimerInfo->timeout < currentTime)
609  currentTimerInfo->timeout = currentTime + currentTimerInfo->interval;
610 
611  // reinsert timer
612  timerInsert(currentTimerInfo);
613  if (currentTimerInfo->interval.tv_usec > 0 || currentTimerInfo->interval.tv_sec > 0)
614  n_act++;
615 
616  if (!currentTimerInfo->activateRef) {
617  // send event, but don't allow it to recurse
618  currentTimerInfo->activateRef = &currentTimerInfo;
619 
620  QTimerEvent e(currentTimerInfo->id);
621  QCoreApplication::sendEvent(currentTimerInfo->obj, &e);
622 
623  if (currentTimerInfo)
624  currentTimerInfo->activateRef = 0;
625  }
626  }
627 
628  firstTimerInfo = 0;
629  return n_act;
630 }
#define it(className, varName)
void timerInsert(QTimerInfo *)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QTimerInfo * firstTimerInfo
Q_CORE_EXPORT bool qt_disable_lowpriority_timers
friend class const_iterator
Definition: qlist.h:264
QTimerInfo ** activateRef
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QTimerInfo * & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ registeredTimers()

QList< QPair< int, int > > QTimerInfoList::registeredTimers ( QObject object) const

Definition at line 551 of file qeventdispatcher_unix.cpp.

552 {
553  QList<QPair<int, int> > list;
554  for (int i = 0; i < count(); ++i) {
555  register const QTimerInfo * const t = at(i);
556  if (t->obj == object)
557  list << QPair<int, int>(t->id, t->interval.tv_sec * 1000 + t->interval.tv_usec / 1000);
558  }
559  return list;
560 }
const QTimerInfo * & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int count() const
Returns the number of items in the list.
Definition: qlist.h:280
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ registerTimer()

void QTimerInfoList::registerTimer ( int  timerId,
int  interval,
QObject object 
)

Definition at line 487 of file qeventdispatcher_unix.cpp.

488 {
489  QTimerInfo *t = new QTimerInfo;
490  t->id = timerId;
491  t->interval.tv_sec = interval / 1000;
492  t->interval.tv_usec = (interval % 1000) * 1000;
493  t->timeout = updateCurrentTime() + t->interval;
494  t->obj = object;
495  t->activateRef = 0;
496 
497  timerInsert(t);
498 }
void timerInsert(QTimerInfo *)
QTimerInfo ** activateRef

◆ repairTimersIfNeeded()

void QTimerInfoList::repairTimersIfNeeded ( )

Definition at line 422 of file qeventdispatcher_unix.cpp.

Referenced by updateCurrentTime().

423 {
424 }

◆ timerInsert()

void QTimerInfoList::timerInsert ( QTimerInfo ti)

Definition at line 431 of file qeventdispatcher_unix.cpp.

432 {
433  int index = size();
434  while (index--) {
435  register const QTimerInfo * const t = at(index);
436  if (!(ti->timeout < t->timeout))
437  break;
438  }
439  insert(index+1, ti);
440 }
void insert(int i, const QTimerInfo * &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
const QTimerInfo * & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index

◆ timerRepair()

void QTimerInfoList::timerRepair ( const timeval &  diff)

Definition at line 445 of file qeventdispatcher_unix.cpp.

446 {
447  // repair all timers
448  for (int i = 0; i < size(); ++i) {
449  register QTimerInfo *t = at(i);
450  t->timeout = t->timeout + diff;
451  }
452 }
const QTimerInfo * & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static Bigint * diff(Bigint *a, Bigint *b)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ timerWait()

bool QTimerInfoList::timerWait ( timeval &  tm)

Definition at line 458 of file qeventdispatcher_unix.cpp.

Referenced by timerSourcePrepareHelper().

459 {
460  timeval currentTime = updateCurrentTime();
462 
463  // Find first waiting timer not already active
464  QTimerInfo *t = 0;
466  if (!(*it)->activateRef) {
467  t = *it;
468  break;
469  }
470  }
471 
472  if (!t)
473  return false;
474 
475  if (currentTime < t->timeout) {
476  // time to wait
477  tm = t->timeout - currentTime;
478  } else {
479  // no time to wait
480  tm.tv_sec = 0;
481  tm.tv_usec = 0;
482  }
483 
484  return true;
485 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
friend class const_iterator
Definition: qlist.h:264
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ unregisterTimer()

bool QTimerInfoList::unregisterTimer ( int  timerId)

Definition at line 500 of file qeventdispatcher_unix.cpp.

501 {
502  // set timer inactive
503  for (int i = 0; i < count(); ++i) {
504  register QTimerInfo *t = at(i);
505  if (t->id == timerId) {
506  // found it
507  removeAt(i);
508  if (t == firstTimerInfo)
509  firstTimerInfo = 0;
510  if (t->activateRef)
511  *(t->activateRef) = 0;
512 
513  // release the timer id
516 
517  delete t;
518  return true;
519  }
520  }
521  // id not found
522  return false;
523 }
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
QTimerInfo * firstTimerInfo
QTimerInfo ** activateRef
const QTimerInfo * & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
uint inThreadChangeEvent
Definition: qobject.h:103
int count() const
Returns the number of items in the list.
Definition: qlist.h:280
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ unregisterTimers()

bool QTimerInfoList::unregisterTimers ( QObject object)

Definition at line 525 of file qeventdispatcher_unix.cpp.

526 {
527  if (isEmpty())
528  return false;
529  for (int i = 0; i < count(); ++i) {
530  register QTimerInfo *t = at(i);
531  if (t->obj == object) {
532  // object found
533  removeAt(i);
534  if (t == firstTimerInfo)
535  firstTimerInfo = 0;
536  if (t->activateRef)
537  *(t->activateRef) = 0;
538 
539  // release the timer id
542 
543  delete t;
544  // move back one so that we don't skip the new current item
545  --i;
546  }
547  }
548  return true;
549 }
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QTimerInfo * firstTimerInfo
QTimerInfo ** activateRef
const QTimerInfo * & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
uint inThreadChangeEvent
Definition: qobject.h:103
int count() const
Returns the number of items in the list.
Definition: qlist.h:280
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ updateCurrentTime()

timeval QTimerInfoList::updateCurrentTime ( )

Definition at line 352 of file qeventdispatcher_unix.cpp.

Referenced by QEventDispatcherUNIXPrivate::doSelect(), and timerSourceCheckHelper().

353 {
354  return (currentTime = qt_gettime());
355 }
timeval qt_gettime()

Properties

◆ currentTime

timeval QTimerInfoList::currentTime

Definition at line 98 of file qeventdispatcher_unix_p.h.

◆ firstTimerInfo

QTimerInfo* QTimerInfoList::firstTimerInfo
private

Definition at line 93 of file qeventdispatcher_unix_p.h.


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