Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:36

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QSOCKETNOTIFIER_H
0005 #define QSOCKETNOTIFIER_H
0006 
0007 #include <QtCore/qobject.h>
0008 
0009 QT_BEGIN_NAMESPACE
0010 
0011 class QSocketDescriptor;
0012 class QSocketNotifierPrivate;
0013 class Q_CORE_EXPORT QSocketNotifier : public QObject
0014 {
0015     Q_OBJECT
0016     Q_DECLARE_PRIVATE(QSocketNotifier)
0017 
0018 public:
0019     enum Type { Read, Write, Exception };
0020 
0021     explicit QSocketNotifier(Type, QObject *parent = nullptr);
0022     QSocketNotifier(qintptr socket, Type, QObject *parent = nullptr);
0023     ~QSocketNotifier();
0024 
0025     void setSocket(qintptr socket);
0026     qintptr socket() const;
0027     Type type() const;
0028 
0029     bool isValid() const;
0030     bool isEnabled() const;
0031 
0032 public Q_SLOTS:
0033     void setEnabled(bool);
0034 
0035 Q_SIGNALS:
0036 #if defined(Q_MOC_RUN)
0037     // Add default arguments during Q_MOC_RUN which makes moc generate "signals" which takes less
0038     // parameters, but we won't actually allow emitting without all 3. This lets users use the
0039     // string-based connect without specifying QSocketNotifier::Type as one of the parameters.
0040     void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent = Read,
0041                    QPrivateSignal = {});
0042 #else
0043     void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent, QPrivateSignal);
0044 #endif
0045 
0046     // ### Qt7: consider removing it.
0047     // The old signal is compiled internally, but hidden outside of this class.
0048     // This means the PMF-based connect(..) will automatically, on recompile, pick up the new
0049     // version while the old-style connect(..) can query the metaobject system for this version.
0050 #if defined(Q_MOC_RUN) || defined(BUILDING_QSOCKETNOTIFIER) || defined(Q_QDOC)
0051     QT_MOC_COMPAT void activated(int socket, QPrivateSignal);
0052 #endif
0053 
0054 protected:
0055     bool event(QEvent *) override;
0056 
0057 private:
0058     Q_DISABLE_COPY(QSocketNotifier)
0059 };
0060 
0061 class QSocketDescriptor
0062 {
0063 public:
0064 #if defined(Q_OS_WIN) || defined(Q_QDOC)
0065     using DescriptorType = Qt::HANDLE;
0066 #define Q_DECL_CONSTEXPR_NOT_WIN
0067 #else
0068     using DescriptorType = int;
0069 #define Q_DECL_CONSTEXPR_NOT_WIN Q_DECL_CONSTEXPR
0070 #endif
0071 
0072     Q_DECL_CONSTEXPR_NOT_WIN Q_IMPLICIT
0073     QSocketDescriptor(DescriptorType descriptor = DescriptorType(-1)) noexcept : sockfd(descriptor)
0074     {
0075     }
0076 
0077 #if defined(Q_OS_WIN) || defined(Q_QDOC)
0078     Q_IMPLICIT QSocketDescriptor(qintptr desc) noexcept : sockfd(DescriptorType(desc)) {}
0079     Q_IMPLICIT operator qintptr() const noexcept { return qintptr(sockfd); }
0080     Q_DECL_CONSTEXPR Qt::HANDLE winHandle() const noexcept { return sockfd; }
0081 #endif
0082     Q_DECL_CONSTEXPR operator DescriptorType() const noexcept { return sockfd; }
0083 
0084     Q_DECL_CONSTEXPR_NOT_WIN bool isValid() const noexcept { return *this != QSocketDescriptor(); }
0085 
0086     friend Q_DECL_CONSTEXPR_NOT_WIN bool operator==(QSocketDescriptor lhs,
0087                                                     QSocketDescriptor rhs) noexcept
0088     {
0089         return lhs.sockfd == rhs.sockfd;
0090     }
0091     friend Q_DECL_CONSTEXPR_NOT_WIN bool operator!=(QSocketDescriptor lhs,
0092                                                     QSocketDescriptor rhs) noexcept
0093     {
0094         return lhs.sockfd != rhs.sockfd;
0095     }
0096 
0097 #undef Q_DECL_CONSTEXPR_NOT_WIN
0098 
0099 private:
0100     DescriptorType sockfd;
0101 };
0102 
0103 QT_END_NAMESPACE
0104 
0105 QT_DECL_METATYPE_EXTERN_TAGGED(QSocketNotifier::Type, QSocketNotifier_Type, Q_CORE_EXPORT)
0106 QT_DECL_METATYPE_EXTERN(QSocketDescriptor, Q_CORE_EXPORT)
0107 
0108 #endif // QSOCKETNOTIFIER_H