Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcfsocketnotifier_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCFSOCKETNOTIFIER_P_H
5#define QCFSOCKETNOTIFIER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include <QtCore/qabstracteventdispatcher.h>
20#include <QtCore/qhash.h>
21
22#include <CoreFoundation/CoreFoundation.h>
23
24QT_BEGIN_NAMESPACE
25
26struct MacSocketInfo {
27 MacSocketInfo() : socket(0), runloop(0), readNotifier(0), writeNotifier(0),
28 readEnabled(false), writeEnabled(false) {}
29 CFSocketRef socket;
30 CFRunLoopSourceRef runloop;
31 QObject *readNotifier;
32 QObject *writeNotifier;
33 bool readEnabled;
34 bool writeEnabled;
35};
37
38typedef void (*MaybeCancelWaitForMoreEventsFn)(QAbstractEventDispatcher *hostEventDispacher);
39
40// The CoreFoundationSocketNotifier class implements socket notifiers support using
41// CFSocket for event dispatchers running on top of the Core Foundation run loop system.
42// (currently Mac and iOS)
43//
44// The principal functions are registerSocketNotifier() and unregisterSocketNotifier().
45//
46// setHostEventDispatcher() should be called at startup.
47// removeSocketNotifiers() should be called at shutdown.
48//
49class Q_CORE_EXPORT QCFSocketNotifier
50{
51public:
52 QCFSocketNotifier();
53 ~QCFSocketNotifier();
54 void setHostEventDispatcher(QAbstractEventDispatcher *hostEventDispacher);
55 void setMaybeCancelWaitForMoreEventsCallback(MaybeCancelWaitForMoreEventsFn callBack);
56 void registerSocketNotifier(QSocketNotifier *notifier);
57 void unregisterSocketNotifier(QSocketNotifier *notifier);
58 void removeSocketNotifiers();
59
60private:
61 void destroyRunLoopObserver();
62
63 static void unregisterSocketInfo(MacSocketInfo *socketInfo);
64 static void enableSocketNotifiers(CFRunLoopObserverRef ref, CFRunLoopActivity activity, void *info);
65
66 MacSocketHash macSockets;
67 QAbstractEventDispatcher *eventDispatcher;
68 MaybeCancelWaitForMoreEventsFn maybeCancelWaitForMoreEvents;
69 CFRunLoopObserverRef enableNotifiersObserver;
70
71 friend void qt_mac_socket_callback(CFSocketRef, CFSocketCallBackType, CFDataRef, const void *, void *);
72};
73
74QT_END_NAMESPACE
75
76#endif
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)
QHash< int, MacSocketInfo * > MacSocketHash