5#include <QtCore/qcoreapplication.h>
6#include <QtCore/qsocketnotifier.h>
7#include <QtCore/qthread.h>
19 int nativeSocket = CFSocketGetNative(
s);
28 if (callbackType == kCFSocketConnectCallBack) {
36 }
else if (callbackType == kCFSocketReadCallBack) {
41 }
else if (callbackType == kCFSocketWriteCallBack) {
48 if (cfSocketNotifier->maybeCancelWaitForMoreEvents)
49 cfSocketNotifier->maybeCancelWaitForMoreEvents(cfSocketNotifier->eventDispatcher);
57 CFRunLoopSourceRef loopSource = CFSocketCreateRunLoopSource(kCFAllocatorDefault,
socket, 0);
61 CFRunLoopAddSource(CFRunLoopGetCurrent(), loopSource, kCFRunLoopCommonModes);
71 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop, kCFRunLoopCommonModes);
72 CFSocketDisableCallBacks(
socket, kCFSocketReadCallBack);
73 CFSocketDisableCallBacks(
socket, kCFSocketWriteCallBack);
78 , maybeCancelWaitForMoreEvents(0)
79 , enableNotifiersObserver(0)
91 eventDispatcher = hostEventDispacher;
96 maybeCancelWaitForMoreEvents = callBack;
102 int nativeSocket =
notifier->socket();
105 if (nativeSocket < 0 || nativeSocket > FD_SETSIZE) {
106 qWarning(
"QSocketNotifier: Internal error");
110 qWarning(
"QSocketNotifier: socket notifiers cannot be enabled from another thread");
116 qWarning(
"QSocketNotifier::Exception is not supported on iOS");
127 const int callbackTypes = kCFSocketConnectCallBack | kCFSocketReadCallBack | kCFSocketWriteCallBack;
128 CFSocketContext
context = {0,
this, 0, 0, 0};
130 if (CFSocketIsValid(socketInfo->
socket) ==
false) {
131 qWarning(
"QEventDispatcherMac::registerSocketNotifier: Failed to create CFSocket");
135 CFOptionFlags
flags = CFSocketGetSocketFlags(socketInfo->
socket);
137 flags &= ~kCFSocketCloseOnInvalidate;
139 flags &= ~(kCFSocketAutomaticallyReenableWriteCallBack | kCFSocketAutomaticallyReenableReadCallBack);
142 macSockets.
insert(nativeSocket, socketInfo);
155 if (!enableNotifiersObserver) {
158 CFRunLoopObserverContext
context = {};
160 enableNotifiersObserver = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeSources,
161 true, 0, enableSocketNotifiers, &
context);
163 CFRunLoopAddObserver(CFRunLoopGetCurrent(), enableNotifiersObserver, kCFRunLoopCommonModes);
170 int nativeSocket =
notifier->socket();
173 if (nativeSocket < 0 || nativeSocket > FD_SETSIZE) {
174 qWarning(
"QSocketNotifier: Internal error");
177 qWarning(
"QSocketNotifier: socket notifiers cannot be disabled from another thread");
183 qWarning(
"QSocketNotifier::Exception is not supported on iOS");
188 qWarning(
"QEventDispatcherMac::unregisterSocketNotifier: Tried to unregister a not registered notifier");
197 CFSocketDisableCallBacks(socketInfo->
socket, kCFSocketReadCallBack);
202 CFSocketDisableCallBacks(socketInfo->
socket, kCFSocketWriteCallBack);
207 unregisterSocketInfo(socketInfo);
209 macSockets.
remove(nativeSocket);
216 for (
MacSocketInfo *socketInfo : std::as_const(macSockets)) {
217 unregisterSocketInfo(socketInfo);
223 destroyRunLoopObserver();
226void QCFSocketNotifier::destroyRunLoopObserver()
228 if (!enableNotifiersObserver)
231 CFRunLoopObserverInvalidate(enableNotifiersObserver);
232 CFRelease(enableNotifiersObserver);
233 enableNotifiersObserver = 0;
236void QCFSocketNotifier::unregisterSocketInfo(
MacSocketInfo *socketInfo)
239 if (CFSocketIsValid(socketInfo->
socket))
241 CFRunLoopSourceInvalidate(socketInfo->
runloop);
242 CFRelease(socketInfo->
runloop);
244 CFSocketInvalidate(socketInfo->
socket);
245 CFRelease(socketInfo->
socket);
248void QCFSocketNotifier::enableSocketNotifiers(CFRunLoopObserverRef
ref, CFRunLoopActivity activity,
void *
info)
256 if (!CFSocketIsValid(socketInfo->
socket))
262 qWarning(
"QEventDispatcherMac::registerSocketNotifier: Failed to add CFSocket to runloop");
263 CFSocketInvalidate(socketInfo->
socket);
275 CFSocketDisableCallBacks(socketInfo->
socket, kCFSocketReadCallBack);
278 CFSocketDisableCallBacks(socketInfo->
socket, kCFSocketWriteCallBack);
284 CFSocketEnableCallBacks(socketInfo->
socket, kCFSocketReadCallBack);
288 CFSocketEnableCallBacks(socketInfo->
socket, kCFSocketWriteCallBack);
DarwinBluetooth::LECBManagerNotifier * notifier
void unregisterSocketNotifier(QSocketNotifier *notifier)
void removeSocketNotifiers()
void setMaybeCancelWaitForMoreEventsCallback(MaybeCancelWaitForMoreEventsFn callBack)
void registerSocketNotifier(QSocketNotifier *notifier)
void setHostEventDispatcher(QAbstractEventDispatcher *hostEventDispacher)
friend void qt_mac_socket_callback(CFSocketRef, CFSocketCallBackType, CFDataRef, const void *, void *)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool remove(const Key &key)
Removes the item that has the key from the hash.
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
QThread * thread() const
Returns the thread in which the object lives.
static QThread * currentThread()
Combined button and popup list for selecting options.
CFRunLoopSourceRef qt_mac_add_socket_to_runloop(const CFSocketRef socket)
void qt_mac_remove_socket_from_runloop(const CFSocketRef socket, CFRunLoopSourceRef runloop)
QT_BEGIN_NAMESPACE void qt_mac_socket_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef, const void *data, void *info)
void(* MaybeCancelWaitForMoreEventsFn)(QAbstractEventDispatcher *hostEventDispacher)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QFileInfo info(fileName)
[8]
CFRunLoopSourceRef runloop