Qt 4.8
Public Functions | Friends | List of all members
QEventDispatcherMac Class Reference

#include <qeventdispatcher_mac_p.h>

Inheritance diagram for QEventDispatcherMac:
QAbstractEventDispatcher QObject

Public Functions

void flush ()
 Flushes the event queue. More...
 
bool hasPendingEvents ()
 Returns true if there is an event waiting; otherwise returns false. More...
 
void interrupt ()
 Interrupts event dispatching; i. More...
 
bool processEvents (QEventLoop::ProcessEventsFlags flags)
 Processes pending events that match flags until there are no more events to process. More...
 
 QEventDispatcherMac (QObject *parent=0)
 
QList< TimerInforegisteredTimers (QObject *object) const
 Returns a list of registered timers for object. More...
 
void registerSocketNotifier (QSocketNotifier *notifier)
 Registers notifier with the event loop. More...
 
void registerTimer (int timerId, int interval, QObject *object)
 Register a timer with the specified timerId and interval for the given object. More...
 
void unregisterSocketNotifier (QSocketNotifier *notifier)
 Unregisters notifier from the event dispatcher. More...
 
bool unregisterTimer (int timerId)
 Unregisters the timer with the given timerId. More...
 
bool unregisterTimers (QObject *object)
 Unregisters all the timers associated with the given object. More...
 
void wakeUp ()
 Wakes up the event loop. More...
 
 ~QEventDispatcherMac ()
 
- Public Functions inherited from QAbstractEventDispatcher
virtual void closingDown ()
 
bool filterEvent (void *message)
 Sends message through the event filter that was set by setEventFilter(). More...
 
 QAbstractEventDispatcher (QObject *parent=0)
 Constructs a new event dispatcher with the given parent. More...
 
int registerTimer (int interval, QObject *object)
 Registers a timer with the specified interval for the given object. More...
 
EventFilter setEventFilter (EventFilter filter)
 Replaces the event filter function for this QAbstractEventDispatcher with filter and returns the replaced event filter function. More...
 
virtual void startingUp ()
 
 ~QAbstractEventDispatcher ()
 Destroys the event dispatcher. More...
 
- 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...
 

Friends

class QApplicationPrivate
 
void qt_mac_select_timer_callbk (__EventLoopTimer *, void *)
 

Additional Inherited Members

- Public Types inherited from QAbstractEventDispatcher
typedef bool(* EventFilter) (void *message)
 Typedef for a function with the signature. More...
 
typedef QPair< int, int > TimerInfo
 Typedef for QPair<int, int>. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractEventDispatcher
void aboutToBlock ()
 This signal is emitted before the event loop calls a function that could block. More...
 
void awake ()
 This signal is emitted after the event loop returns from a function that could block. 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 QAbstractEventDispatcher
static QAbstractEventDispatcherinstance (QThread *thread=0)
 Returns a pointer to the event dispatcher object for the specified thread. 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)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QAbstractEventDispatcher
 QAbstractEventDispatcher (QAbstractEventDispatcherPrivate &, QObject *parent)
 
- 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...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 109 of file qeventdispatcher_mac_p.h.

Constructors and Destructors

◆ QEventDispatcherMac()

QEventDispatcherMac::QEventDispatcherMac ( QObject parent = 0)
explicit

Definition at line 982 of file qeventdispatcher_mac.mm.

984 {
986  CFRunLoopSourceContext context;
987  bzero(&context, sizeof(CFRunLoopSourceContext));
988  context.info = d;
991  d->postedEventsSource = CFRunLoopSourceCreate(0, 0, &context);
992  Q_ASSERT(d->postedEventsSource);
993  CFRunLoopAddSource(mainRunLoop(), d->postedEventsSource, kCFRunLoopCommonModes);
994 
995  CFRunLoopObserverContext observerContext;
996  bzero(&observerContext, sizeof(CFRunLoopObserverContext));
997  observerContext.info = this;
998  d->waitingObserver = CFRunLoopObserverCreate(kCFAllocatorDefault,
999  kCFRunLoopBeforeWaiting | kCFRunLoopAfterWaiting,
1000  true, 0,
1002  &observerContext);
1003  CFRunLoopAddObserver(mainRunLoop(), d->waitingObserver, kCFRunLoopCommonModes);
1004 
1005  /* The first cycle in the loop adds the source and the events of the source
1006  are not processed.
1007  We use an observer to process the posted events for the first
1008  execution of the loop. */
1009  CFRunLoopObserverContext firstTimeObserverContext;
1010  bzero(&firstTimeObserverContext, sizeof(CFRunLoopObserverContext));
1011  firstTimeObserverContext.info = d;
1012  d->firstTimeObserver = CFRunLoopObserverCreate(kCFAllocatorDefault,
1013  kCFRunLoopEntry,
1014  /* repeats = */ false,
1015  0,
1017  &firstTimeObserverContext);
1018  CFRunLoopAddObserver(mainRunLoop(), d->firstTimeObserver, kCFRunLoopCommonModes);
1019 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
static void postedEventsSourcePerformCallback(void *info)
static void waitingObserverCallback(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info)
static CFRunLoopRef mainRunLoop()
QAbstractEventDispatcher(QObject *parent=0)
Constructs a new event dispatcher with the given parent.
static void firstLoopEntry(CFRunLoopObserverRef ref, CFRunLoopActivity activity, void *info)
static Boolean postedEventSourceEqualCallback(const void *info1, const void *info2)

◆ ~QEventDispatcherMac()

QEventDispatcherMac::~QEventDispatcherMac ( )

Definition at line 1122 of file qeventdispatcher_mac.mm.

1123 {
1125  //timer cleanup
1128  MacTimerInfo *t = it.value();
1129  if (t->runLoopTimer) {
1130  CFRunLoopTimerInvalidate(t->runLoopTimer);
1131  CFRelease(t->runLoopTimer);
1132  }
1133  delete t;
1134  ++it;
1135  }
1137 
1138  // Remove CFSockets from the runloop.
1139  for (MacSocketHash::ConstIterator it = d->macSockets.constBegin(); it != d->macSockets.constEnd(); ++it) {
1140  MacSocketInfo *socketInfo = (*it);
1141  if (CFSocketIsValid(socketInfo->socket)) {
1142  qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop);
1143  CFRunLoopSourceInvalidate(socketInfo->runloop);
1144  CFRelease(socketInfo->runloop);
1145  CFSocketInvalidate(socketInfo->socket);
1146  CFRelease(socketInfo->socket);
1147  }
1148  }
1149  CFRunLoopRemoveSource(mainRunLoop(), d->postedEventsSource, kCFRunLoopCommonModes);
1150  CFRelease(d->postedEventsSource);
1151 
1152  CFRunLoopObserverInvalidate(d->waitingObserver);
1153  CFRelease(d->waitingObserver);
1154 
1155  CFRunLoopObserverInvalidate(d->firstTimeObserver);
1156  CFRelease(d->firstTimeObserver);
1157 }
double d
Definition: qnumeric_p.h:62
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
void clear()
Removes all items from the hash.
Definition: qhash.h:574
#define it(className, varName)
CFRunLoopTimerRef runLoopTimer
void qt_mac_remove_socket_from_runloop(const CFSocketRef socket, CFRunLoopSourceRef runloop)
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
#define Q_D(Class)
Definition: qglobal.h:2482
CFRunLoopSourceRef runloop
static CFRunLoopRef mainRunLoop()
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
static const KeyPair *const end

Functions

◆ flush()

void QEventDispatcherMac::flush ( )
virtual

Flushes the event queue.

This normally returns almost immediately. Does nothing on platforms other than X11.

Implements QAbstractEventDispatcher.

Definition at line 763 of file qeventdispatcher_mac.mm.

764 {
765  if(qApp) {
767  for(int i = 0; i < tlws.size(); i++) {
768  QWidget *tlw = tlws.at(i);
769  if(tlw->isVisible())
771  }
772  }
773 }
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
bool isVisible() const
Definition: qwidget.h:1005
void macWindowFlush(void *window)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define qApp
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ hasPendingEvents()

bool QEventDispatcherMac::hasPendingEvents ( )
virtual

Returns true if there is an event waiting; otherwise returns false.

Implements QAbstractEventDispatcher.

Definition at line 447 of file qeventdispatcher_mac.mm.

448 {
450  return qGlobalPostedEventsCount() || (qt_is_gui_used && GetNumEventsInQueue(GetMainEventQueue()));
451 }
bool qt_is_gui_used
unsigned int uint
Definition: qglobal.h:996
Q_CORE_EXPORT uint qGlobalPostedEventsCount()

◆ interrupt()

void QEventDispatcherMac::interrupt ( )
virtual

Interrupts event dispatching; i.

e. the event dispatcher will return from processEvents() as soon as possible.

Implements QAbstractEventDispatcher.

Definition at line 1102 of file qeventdispatcher_mac.mm.

1103 {
1105  d->interrupt = true;
1106  wakeUp();
1107 
1108 #ifndef QT_MAC_USE_COCOA
1109  CFRunLoopStop(mainRunLoop());
1110 #else
1111  // We do nothing more here than setting d->interrupt = true, and
1112  // poke the event loop if it is sleeping. Actually stopping
1113  // NSApp, or the current modal session, is done inside the send
1114  // posted events callback. We do this to ensure that all current pending
1115  // cocoa events gets delivered before we stop. Otherwise, if we now stop
1116  // the last event loop recursion, cocoa will just drop pending posted
1117  // events on the floor before we get a chance to reestablish a new session.
1118  d->cancelWaitForMoreEvents();
1119 #endif
1120 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void wakeUp()
Wakes up the event loop.
static CFRunLoopRef mainRunLoop()

◆ processEvents()

bool QEventDispatcherMac::processEvents ( QEventLoop::ProcessEventsFlags  flags)
virtual

Processes pending events that match flags until there are no more events to process.

Returns true if an event was processed; otherwise returns false.

This function is especially useful if you have a long running operation and want to show its progress without allowing user input; i.e. by using the QEventLoop::ExcludeUserInputEvents flag.

If the QEventLoop::WaitForMoreEvents flag is set in flags, the behavior of this function is as follows:

  • If events are available, this function returns after processing them.

  • If no events are available, this function will wait until more are available and return after processing newly available events.

If the QEventLoop::WaitForMoreEvents flag is not set in flags, and no events are available, this function will return immediately.

Note: This function does not process events continuously; it returns after all available events are processed.

See also
hasPendingEvents()

Implements QAbstractEventDispatcher.

Definition at line 549 of file qeventdispatcher_mac.mm.

550 {
552  d->interrupt = false;
553 
554 #ifdef QT_MAC_USE_COCOA
555  bool interruptLater = false;
556  QtMacInterruptDispatcherHelp::cancelInterruptLater();
557 #endif
558 
559  // In case we end up recursing while we now process events, make sure
560  // that we send remaining posted Qt events before this call returns:
561  wakeUp();
562  emit awake();
563 
564  bool excludeUserEvents = flags & QEventLoop::ExcludeUserInputEvents;
565  bool retVal = false;
566  forever {
567  if (d->interrupt)
568  break;
569 
570 #ifdef QT_MAC_USE_COCOA
572  NSEvent* event = 0;
573 
574  // First, send all previously excluded input events, if any:
575  if (!excludeUserEvents) {
576  while (!d->queuedUserInputEvents.isEmpty()) {
577  event = static_cast<NSEvent *>(d->queuedUserInputEvents.takeFirst());
578  if (!filterEvent(event)) {
579  qt_mac_send_event(flags, event, 0);
580  retVal = true;
581  }
582  [event release];
583  }
584  }
585 
586  // If Qt is used as a plugin, or as an extension in a native cocoa
587  // application, we should not run or stop NSApplication; This will be
588  // done from the application itself. And if processEvents is called
589  // manually (rather than from a QEventLoop), we cannot enter a tight
590  // loop and block this call, but instead we need to return after one flush.
591  // Finally, if we are to exclude user input events, we cannot call [NSApp run]
592  // as we then loose control over which events gets dispatched:
593  const bool canExec_3rdParty = d->nsAppRunCalledByQt || ![NSApp isRunning];
594  const bool canExec_Qt = !excludeUserEvents &&
596 
597  if (canExec_Qt && canExec_3rdParty) {
598  // We can use exec-mode, meaning that we can stay in a tight loop until
599  // interrupted. This is mostly an optimization, but it allow us to use
600  // [NSApp run], which is the normal code path for cocoa applications.
601  if (NSModalSession session = d->currentModalSession()) {
602  QBoolBlocker execGuard(d->currentExecIsNSAppRun, false);
603  while ([NSApp runModalSession:session] == NSRunContinuesResponse && !d->interrupt)
604  qt_mac_waitForMoreModalSessionEvents();
605 
606  if (!d->interrupt && session == d->currentModalSessionCached) {
607  // Someone called [NSApp stopModal:] from outside the event
608  // dispatcher (e.g to stop a native dialog). But that call wrongly stopped
609  // 'session' as well. As a result, we need to restart all internal sessions:
610  d->temporarilyStopAllModalSessions();
611  }
612  } else {
613  d->nsAppRunCalledByQt = true;
614  QBoolBlocker execGuard(d->currentExecIsNSAppRun, true);
615  [NSApp run];
616  }
617  retVal = true;
618  } else {
619  // We cannot block the thread (and run in a tight loop).
620  // Instead we will process all current pending events and return.
621  d->ensureNSAppInitialized();
622  if (NSModalSession session = d->currentModalSession()) {
623  // INVARIANT: a modal window is executing.
624  if (!excludeUserEvents) {
625  // Since we can dispatch all kinds of events, we choose
626  // to use cocoa's native way of running modal sessions:
627  if (flags & QEventLoop::WaitForMoreEvents)
628  qt_mac_waitForMoreModalSessionEvents();
629  NSInteger status = [NSApp runModalSession:session];
630  if (status != NSRunContinuesResponse && session == d->currentModalSessionCached) {
631  // INVARIANT: Someone called [NSApp stopModal:] from outside the event
632  // dispatcher (e.g to stop a native dialog). But that call wrongly stopped
633  // 'session' as well. As a result, we need to restart all internal sessions:
634  d->temporarilyStopAllModalSessions();
635  }
636  retVal = true;
637  } else do {
638  // Dispatch all non-user events (but que non-user events up for later). In
639  // this case, we need more control over which events gets dispatched, and
640  // cannot use [NSApp runModalSession:session]:
641  event = [NSApp nextEventMatchingMask:NSAnyEventMask
642  untilDate:nil
643  inMode:NSModalPanelRunLoopMode
644  dequeue: YES];
645 
646  if (event) {
647  if (IsMouseOrKeyEvent(event)) {
648  [event retain];
649  d->queuedUserInputEvents.append(event);
650  continue;
651  }
652  if (!filterEvent(event) && qt_mac_send_event(flags, event, 0))
653  retVal = true;
654  }
655  } while (!d->interrupt && event != nil);
656  } else do {
657  // INVARIANT: No modal window is executing.
658  event = [NSApp nextEventMatchingMask:NSAnyEventMask
659  untilDate:nil
660  inMode:NSDefaultRunLoopMode
661  dequeue: YES];
662 
663  if (event) {
664  if (flags & QEventLoop::ExcludeUserInputEvents) {
665  if (IsMouseOrKeyEvent(event)) {
666  [event retain];
667  d->queuedUserInputEvents.append(event);
668  continue;
669  }
670  }
671  if (!filterEvent(event) && qt_mac_send_event(flags, event, 0))
672  retVal = true;
673  }
674  } while (!d->interrupt && event != nil);
675 
676  // Be sure to flush the Qt posted events when not using exec mode
677  // (exec mode will always do this call from the event loop source):
678  if (!d->interrupt)
679  QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
680 
681  // Since the window that holds modality might have changed while processing
682  // events, we we need to interrupt when we return back the previous process
683  // event recursion to ensure that we spin the correct modal session.
684  // We do the interruptLater at the end of the function to ensure that we don't
685  // disturb the 'wait for more events' below (as deleteLater will post an event):
686  interruptLater = true;
687  }
688 #else
689  do {
690  EventRef event;
691  if (!(flags & QEventLoop::ExcludeUserInputEvents)
692  && !d->queuedUserInputEvents.isEmpty()) {
693  // process a pending user input event
694  event = static_cast<EventRef>(d->queuedUserInputEvents.takeFirst());
695  } else {
696  OSStatus err = ReceiveNextEvent(0,0, kEventDurationNoWait, true, &event);
697  if(err != noErr)
698  continue;
699  // else
700  if (flags & QEventLoop::ExcludeUserInputEvents) {
701  UInt32 ekind = GetEventKind(event),
702  eclass = GetEventClass(event);
703  switch(eclass) {
704  case kEventClassQt:
705  if(ekind != kEventQtRequestContext)
706  break;
707  // fall through
708  case kEventClassMouse:
709  case kEventClassKeyboard:
710  d->queuedUserInputEvents.append(event);
711  continue;
712  }
713  }
714  }
715 
716  if (!filterEvent(&event) && qt_mac_send_event(flags, event, 0))
717  retVal = true;
718  ReleaseEvent(event);
719  } while(!d->interrupt && GetNumEventsInQueue(GetMainEventQueue()) > 0);
720 
721 #endif
722 
723  bool canWait = (d->threadData->canWait
724  && !retVal
725  && !d->interrupt
726  && (flags & QEventLoop::WaitForMoreEvents));
727  if (canWait) {
728  // INVARIANT: We haven't processed any events yet. And we're told
729  // to stay inside this function until at least one event is processed.
731  flags &= ~QEventLoop::WaitForMoreEvents;
732  } else {
733  // Done with event processing for now.
734  // Leave the function:
735  break;
736  }
737  }
738 
739  // If we're interrupted, we need to interrupt the _current_
740  // recursion as well to check if it is still supposed to be
741  // executing. This way we wind down the stack until we land
742  // on a recursion that again calls processEvents (typically
743  // from QEventLoop), and set interrupt to false:
744  if (d->interrupt)
745  interrupt();
746 
747 #ifdef QT_MAC_USE_COCOA
748  if (interruptLater)
749  QtMacInterruptDispatcherHelp::interruptLater();
750 #endif
751 
752  return retVal;
753 }
double d
Definition: qnumeric_p.h:62
static bool qt_mac_send_event(QEventLoop::ProcessEventsFlags, OSEventRef event, OSWindowRef pt)
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data)
bool filterEvent(void *message)
Sends message through the event filter that was set by setEventFilter().
static void qt_mac_waitForMoreEvents()
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_D(Class)
Definition: qglobal.h:2482
void awake()
This signal is emitted after the event loop returns from a function that could block.
The QEventLoop class provides a means of entering and leaving an event loop.
Definition: qeventloop.h:55
#define emit
Definition: qobjectdefs.h:76
signed long OSStatus
struct OpaqueEventRef * EventRef
void wakeUp()
Wakes up the event loop.
const UInt32 kEventClassQt
Definition: qt_mac_p.h:92
void interrupt()
Interrupts event dispatching; i.
QFuture< T > run(Function function,...)
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ registeredTimers()

QList< QEventDispatcherMac::TimerInfo > QEventDispatcherMac::registeredTimers ( QObject object) const
virtual

Returns a list of registered timers for object.

The timer ID is the first member in each pair; the interval is the second.

Implements QAbstractEventDispatcher.

Definition at line 243 of file qeventdispatcher_mac.mm.

244 {
245  if (!object) {
246  qWarning("QEventDispatcherMac:registeredTimers: invalid argument");
247  return QList<TimerInfo>();
248  }
249 
250  QList<TimerInfo> list;
251 
253  while (it != QEventDispatcherMacPrivate::macTimerHash.constEnd()) {
254  MacTimerInfo *t = it.value();
255  if (t->obj == object)
256  list << TimerInfo(t->id, t->interval);
257  ++it;
258  }
259  return list;
260 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
QPair< int, int > TimerInfo
Typedef for QPair<int, int>.
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
Q_CORE_EXPORT void qWarning(const char *,...)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ registerSocketNotifier()

void QEventDispatcherMac::registerSocketNotifier ( QSocketNotifier notifier)
virtual

Registers notifier with the event loop.

Subclasses must implement this method to tie a socket notifier into another event loop.

Implements QAbstractEventDispatcher.

Definition at line 319 of file qeventdispatcher_mac.mm.

320 {
321  Q_ASSERT(notifier);
322  int nativeSocket = notifier->socket();
323  int type = notifier->type();
324 #ifndef QT_NO_DEBUG
325  if (nativeSocket < 0 || nativeSocket > FD_SETSIZE) {
326  qWarning("QSocketNotifier: Internal error");
327  return;
328  } else if (notifier->thread() != thread()
329  || thread() != QThread::currentThread()) {
330  qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread");
331  return;
332  }
333 #endif
334 
336 
337  if (type == QSocketNotifier::Exception) {
338  qWarning("QSocketNotifier::Exception is not supported on Mac OS X");
339  return;
340  }
341 
342  // Check if we have a CFSocket for the native socket, create one if not.
343  MacSocketInfo *socketInfo = d->macSockets.value(nativeSocket);
344  if (!socketInfo) {
345  socketInfo = new MacSocketInfo();
346 
347  // Create CFSocket, specify that we want both read and write callbacks (the callbacks
348  // are enabled/disabled later on).
349  const int callbackTypes = kCFSocketReadCallBack | kCFSocketWriteCallBack;
350  CFSocketContext context = {0, d, 0, 0, 0};
351  socketInfo->socket = CFSocketCreateWithNative(kCFAllocatorDefault, nativeSocket, callbackTypes, qt_mac_socket_callback, &context);
352  if (CFSocketIsValid(socketInfo->socket) == false) {
353  qWarning("QEventDispatcherMac::registerSocketNotifier: Failed to create CFSocket");
354  return;
355  }
356 
357  CFOptionFlags flags = CFSocketGetSocketFlags(socketInfo->socket);
358  flags |= kCFSocketAutomaticallyReenableWriteCallBack; //QSocketNotifier stays enabled after a write
359  flags &= ~kCFSocketCloseOnInvalidate; //QSocketNotifier doesn't close the socket upon destruction/invalidation
360  CFSocketSetSocketFlags(socketInfo->socket, flags);
361 
362  // Add CFSocket to runloop.
363  if(!(socketInfo->runloop = qt_mac_add_socket_to_runloop(socketInfo->socket))) {
364  qWarning("QEventDispatcherMac::registerSocketNotifier: Failed to add CFSocket to runloop");
365  CFSocketInvalidate(socketInfo->socket);
366  CFRelease(socketInfo->socket);
367  return;
368  }
369 
370  // Disable both callback types by default. This must be done after
371  // we add the CFSocket to the runloop, or else these calls will have
372  // no effect.
373  CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack);
374  CFSocketDisableCallBacks(socketInfo->socket, kCFSocketWriteCallBack);
375 
376  d->macSockets.insert(nativeSocket, socketInfo);
377  }
378 
379  // Increment read/write counters and select enable callbacks if necessary.
380  if (type == QSocketNotifier::Read) {
381  Q_ASSERT(socketInfo->readNotifier == 0);
382  socketInfo->readNotifier = notifier;
383  CFSocketEnableCallBacks(socketInfo->socket, kCFSocketReadCallBack);
384  } else if (type == QSocketNotifier::Write) {
385  Q_ASSERT(socketInfo->writeNotifier == 0);
386  socketInfo->writeNotifier = notifier;
387  CFSocketEnableCallBacks(socketInfo->socket, kCFSocketWriteCallBack);
388  }
389 }
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
Type type() const
Returns the socket event type specified to the constructor.
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
CFRunLoopSourceRef qt_mac_add_socket_to_runloop(const CFSocketRef socket)
CFRunLoopSourceRef runloop
Q_CORE_EXPORT void qWarning(const char *,...)
void qt_mac_socket_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef, const void *, void *info)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
int socket() const
Returns the socket identifier specified to the constructor.

◆ registerTimer()

void QEventDispatcherMac::registerTimer ( int  timerId,
int  interval,
QObject object 
)
virtual

Register a timer with the specified timerId and interval for the given object.

Implements QAbstractEventDispatcher.

Definition at line 154 of file qeventdispatcher_mac.mm.

155 {
156 #ifndef QT_NO_DEBUG
157  if (timerId < 1 || interval < 0 || !obj) {
158  qWarning("QEventDispatcherMac::registerTimer: invalid arguments");
159  return;
160  } else if (obj->thread() != thread() || thread() != QThread::currentThread()) {
161  qWarning("QObject::startTimer: timers cannot be started from another thread");
162  return;
163  }
164 #endif
165 
166  MacTimerInfo *t = new MacTimerInfo();
167  t->id = timerId;
168  t->interval = interval;
169  t->obj = obj;
170  t->runLoopTimer = 0;
171  t->pending = false;
172 
173  CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent();
174  CFTimeInterval cfinterval = qMax(CFTimeInterval(interval) / 1000, 0.0000001);
175  fireDate += cfinterval;
177  CFRunLoopTimerContext info = { 0, (void *)timerId, 0, 0, 0 };
178  t->runLoopTimer = CFRunLoopTimerCreate(0, fireDate, cfinterval, 0, 0,
180  if (t->runLoopTimer == 0) {
181  qFatal("QEventDispatcherMac::registerTimer: Cannot create timer");
182  }
183  CFRunLoopAddTimer(mainRunLoop(), t->runLoopTimer, kCFRunLoopCommonModes);
184 }
static mach_timebase_info_data_t info
CFRunLoopTimerRef runLoopTimer
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
static void activateTimer(CFRunLoopTimerRef, void *info)
Q_CORE_EXPORT void qFatal(const char *,...)
static CFRunLoopRef mainRunLoop()
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419

◆ unregisterSocketNotifier()

void QEventDispatcherMac::unregisterSocketNotifier ( QSocketNotifier notifier)
virtual

Unregisters notifier from the event dispatcher.

Subclasses must reimplement this method to tie a socket notifier into another event loop. Reimplementations must call the base implementation.

Implements QAbstractEventDispatcher.

Definition at line 396 of file qeventdispatcher_mac.mm.

397 {
398  Q_ASSERT(notifier);
399  int nativeSocket = notifier->socket();
400  int type = notifier->type();
401 #ifndef QT_NO_DEBUG
402  if (nativeSocket < 0 || nativeSocket > FD_SETSIZE) {
403  qWarning("QSocketNotifier: Internal error");
404  return;
405  } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
406  qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread");
407  return;
408  }
409 #endif
410 
412 
413  if (type == QSocketNotifier::Exception) {
414  qWarning("QSocketNotifier::Exception is not supported on Mac OS X");
415  return;
416  }
417  MacSocketInfo *socketInfo = d->macSockets.value(nativeSocket);
418  if (!socketInfo) {
419  qWarning("QEventDispatcherMac::unregisterSocketNotifier: Tried to unregister a not registered notifier");
420  return;
421  }
422 
423  // Decrement read/write counters and disable callbacks if necessary.
424  if (type == QSocketNotifier::Read) {
425  Q_ASSERT(notifier == socketInfo->readNotifier);
426  socketInfo->readNotifier = 0;
427  CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack);
428  } else if (type == QSocketNotifier::Write) {
429  Q_ASSERT(notifier == socketInfo->writeNotifier);
430  socketInfo->writeNotifier = 0;
431  CFSocketDisableCallBacks(socketInfo->socket, kCFSocketWriteCallBack);
432  }
433 
434  // Remove CFSocket from runloop if this was the last QSocketNotifier.
435  if (socketInfo->readNotifier == 0 && socketInfo->writeNotifier == 0) {
436  if (CFSocketIsValid(socketInfo->socket))
437  qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop);
438  CFRunLoopSourceInvalidate(socketInfo->runloop);
439  CFRelease(socketInfo->runloop);
440  CFSocketInvalidate(socketInfo->socket);
441  CFRelease(socketInfo->socket);
442  delete socketInfo;
443  d->macSockets.remove(nativeSocket);
444  }
445 }
double d
Definition: qnumeric_p.h:62
int type
Definition: qmetatype.cpp:239
void qt_mac_remove_socket_from_runloop(const CFSocketRef socket, CFRunLoopSourceRef runloop)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
Type type() const
Returns the socket event type specified to the constructor.
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
CFRunLoopSourceRef runloop
Q_CORE_EXPORT void qWarning(const char *,...)
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
int socket() const
Returns the socket identifier specified to the constructor.

◆ unregisterTimer()

bool QEventDispatcherMac::unregisterTimer ( int  timerId)
virtual

Unregisters the timer with the given timerId.

Returns true if successful; otherwise returns false.

See also
registerTimer(), unregisterTimers()

Implements QAbstractEventDispatcher.

Definition at line 186 of file qeventdispatcher_mac.mm.

187 {
188 #ifndef QT_NO_DEBUG
189  if (identifier < 1) {
190  qWarning("QEventDispatcherMac::unregisterTimer: invalid argument");
191  return false;
192  } else if (thread() != QThread::currentThread()) {
193  qWarning("QObject::killTimer: timers cannot be stopped from another thread");
194  return false;
195  }
196 #endif
197  if (identifier <= 0)
198  return false; // not init'd or invalid timer
199 
201  if (timerInfo == 0)
202  return false;
203 
204  if (!QObjectPrivate::get(timerInfo->obj)->inThreadChangeEvent)
206  CFRunLoopTimerInvalidate(timerInfo->runLoopTimer);
207  CFRelease(timerInfo->runLoopTimer);
208  delete timerInfo;
209 
210  return true;
211 }
CFRunLoopTimerRef runLoopTimer
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
uint inThreadChangeEvent
Definition: qobject.h:103
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419

◆ unregisterTimers()

bool QEventDispatcherMac::unregisterTimers ( QObject object)
virtual

Unregisters all the timers associated with the given object.

Returns true if all timers were successful removed; otherwise returns false.

See also
unregisterTimer(), registeredTimers()

Implements QAbstractEventDispatcher.

Definition at line 213 of file qeventdispatcher_mac.mm.

214 {
215 #ifndef QT_NO_DEBUG
216  if (!obj) {
217  qWarning("QEventDispatcherMac::unregisterTimers: invalid argument");
218  return false;
219  } else if (obj->thread() != thread() || thread() != QThread::currentThread()) {
220  qWarning("QObject::killTimers: timers cannot be stopped from another thread");
221  return false;
222  }
223 #endif
224 
227  MacTimerInfo *timerInfo = it.value();
228  if (timerInfo->obj != obj) {
229  ++it;
230  } else {
231  if (!QObjectPrivate::get(timerInfo->obj)->inThreadChangeEvent)
233  CFRunLoopTimerInvalidate(timerInfo->runLoopTimer);
234  CFRelease(timerInfo->runLoopTimer);
235  delete timerInfo;
237  }
238  }
239  return true;
240 }
#define it(className, varName)
CFRunLoopTimerRef runLoopTimer
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
Q_CORE_EXPORT void qWarning(const char *,...)
uint inThreadChangeEvent
Definition: qobject.h:103
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
static const KeyPair *const end
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827

◆ wakeUp()

void QEventDispatcherMac::wakeUp ( )
virtual

Wakes up the event loop.

Note
This class or function is threadsafe.
See also
awake()

Implements QAbstractEventDispatcher.

Definition at line 755 of file qeventdispatcher_mac.mm.

Referenced by interrupt().

756 {
758  d->serialNumber.ref();
759  CFRunLoopSourceSignal(d->postedEventsSource);
760  CFRunLoopWakeUp(mainRunLoop());
761 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static CFRunLoopRef mainRunLoop()

Friends and Related Functions

◆ QApplicationPrivate

friend class QApplicationPrivate
friend

Definition at line 135 of file qeventdispatcher_mac_p.h.

◆ qt_mac_select_timer_callbk

void qt_mac_select_timer_callbk ( __EventLoopTimer *  ,
void *   
)
friend

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