diff options
Diffstat (limited to 'src/corelib/kernel/qcore_mac_p.h')
-rw-r--r-- | src/corelib/kernel/qcore_mac_p.h | 91 |
1 files changed, 72 insertions, 19 deletions
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index b87babc07a..9c6cef68b2 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -68,6 +68,7 @@ #endif #include "qstring.h" +#include "qscopedpointer.h" #if defined( __OBJC__) && defined(QT_NAMESPACE) #define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__) @compatibility_alias __KLASS__ QT_MANGLE_NAMESPACE(__KLASS__) @@ -76,6 +77,37 @@ #endif QT_BEGIN_NAMESPACE +template <typename T, typename U, U (*RetainFunction)(U), void (*ReleaseFunction)(U)> +class QAppleRefCounted +{ +public: + QAppleRefCounted(const T &t = T()) : value(t) {} + QAppleRefCounted(QAppleRefCounted &&other) : value(other.value) { other.value = T(); } + QAppleRefCounted(const QAppleRefCounted &other) : value(other.value) { if (value) RetainFunction(value); } + ~QAppleRefCounted() { if (value) ReleaseFunction(value); } + operator T() { return value; } + void swap(QAppleRefCounted &other) Q_DECL_NOEXCEPT_EXPR(noexcept(qSwap(value, other.value))) + { qSwap(value, other.value); } + QAppleRefCounted &operator=(const QAppleRefCounted &other) + { QAppleRefCounted copy(other); swap(copy); return *this; } + QAppleRefCounted &operator=(QAppleRefCounted &&other) + { QAppleRefCounted moved(std::move(other)); swap(moved); return *this; } + T *operator&() { return &value; } +protected: + T value; +}; + + +#ifdef Q_OS_MACOS +class QMacRootLevelAutoReleasePool +{ +public: + QMacRootLevelAutoReleasePool(); + ~QMacRootLevelAutoReleasePool(); +private: + QScopedPointer<QMacAutoReleasePool> pool; +}; +#endif /* Helper class that automates refernce counting for CFtypes. @@ -90,33 +122,17 @@ QT_BEGIN_NAMESPACE HIThemeGet*Shape functions, which in reality are "Copy" functions. */ template <typename T> -class Q_CORE_EXPORT QCFType +class QCFType : public QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease> { public: - inline QCFType(const T &t = 0) : type(t) {} - inline QCFType(const QCFType &helper) : type(helper.type) { if (type) CFRetain(type); } - inline ~QCFType() { if (type) CFRelease(type); } - inline operator T() { return type; } - inline QCFType operator =(const QCFType &helper) - { - if (helper.type) - CFRetain(helper.type); - CFTypeRef type2 = type; - type = helper.type; - if (type2) - CFRelease(type2); - return *this; - } - inline T *operator&() { return &type; } - template <typename X> X as() const { return reinterpret_cast<X>(type); } + using QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>::QAppleRefCounted; + template <typename X> X as() const { return reinterpret_cast<X>(this->value); } static QCFType constructFromGet(const T &t) { if (t) CFRetain(t); return QCFType<T>(t); } -protected: - T type; }; class Q_CORE_EXPORT QCFString : public QCFType<CFStringRef> @@ -137,6 +153,43 @@ Q_CORE_EXPORT QChar qt_mac_qtKey2CocoaKey(Qt::Key key); Q_CORE_EXPORT Qt::Key qt_mac_cocoaKey2QtKey(QChar keyCode); #endif +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug debug, const QMacAutoReleasePool *pool); +#endif + +Q_CORE_EXPORT void qt_apple_check_os_version(); + +// -------------------------------------------------------------------------- + +#if !defined(QT_BOOTSTRAPPED) && (QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_12) || !defined(Q_OS_MACOS)) +#define QT_USE_APPLE_UNIFIED_LOGGING + +QT_END_NAMESPACE +#include <os/log.h> + +// The compiler isn't smart enough to realize that we're calling these functions +// guarded by __builtin_available, so we need to also tag each function with the +// runtime requirements. +#include <os/availability.h> +#define OS_LOG_AVAILABILITY API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) +QT_BEGIN_NAMESPACE + +class Q_CORE_EXPORT AppleUnifiedLogger +{ +public: + static bool messageHandler(QtMsgType msgType, const QMessageLogContext &context, const QString &message, + const QString &subsystem = QString()) OS_LOG_AVAILABILITY; +private: + static os_log_type_t logTypeForMessageType(QtMsgType msgType) OS_LOG_AVAILABILITY; + static os_log_t cachedLog(const QString &subsystem, const QString &category) OS_LOG_AVAILABILITY; +}; + +#undef OS_LOG_AVAILABILITY + +#endif + +// -------------------------------------------------------------------------- + QT_END_NAMESPACE #endif // QCORE_MAC_P_H |