diff options
Diffstat (limited to 'src/bluetooth/osx/osxbtutility_p.h')
-rw-r--r-- | src/bluetooth/osx/osxbtutility_p.h | 171 |
1 files changed, 137 insertions, 34 deletions
diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h index c2a48e5f..18d8732a 100644 --- a/src/bluetooth/osx/osxbtutility_p.h +++ b/src/bluetooth/osx/osxbtutility_p.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtBluetooth module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -44,22 +36,14 @@ #include <QtCore/qloggingcategory.h> #include <QtCore/qscopedpointer.h> +#include <QtCore/qsysinfo.h> #include <QtCore/qglobal.h> #include <Foundation/Foundation.h> +// Only after Foundation.h! +#include "corebluetoothwrapper_p.h" -#ifndef QT_IOS_BLUETOOTH - -#include <IOBluetooth/Bluetooth.h> -#include <IOKit/IOReturn.h> - -@class IOBluetoothSDPUUID; - -#else - -#include <CoreBluetooth/CoreBluetooth.h> - -#endif +@class CBUUID; QT_BEGIN_NAMESPACE @@ -159,6 +143,14 @@ public: } } + void resetWithoutRetain(T *newVal) + { + if (m_ptr != newVal) { + [m_ptr release]; + m_ptr = newVal; + } + } + operator T *() const { return m_ptr; @@ -179,6 +171,97 @@ private: T *m_ptr; }; +// The type 'T' is some XXXRef from CoreFoundation and co. +// In principle, we can do a trick removing a pointer from a type +// when template is instantiated, but it's quite a lot of ugly pp-tokens +// like OSXBluetooth::CFStrongReference<OSXBluetooth::remove_pointer<CFUUIDRref> > strongReference; +// so instead we use 'T' everywhere, not 'T *' as can expected +// from a smart pointer. +template<class T> +class CFStrongReference { +public: + CFStrongReference() + : m_ptr(Q_NULLPTR) + { + } + + CFStrongReference(T obj, bool retain) + : m_ptr(obj) + { + if (m_ptr && retain) + CFRetain(m_ptr); + } + + CFStrongReference(const CFStrongReference &rhs) + { + if ((m_ptr = rhs.m_ptr)) + CFRetain(m_ptr); + } + + CFStrongReference &operator = (const CFStrongReference &rhs) + { + // "Old-style" implementation: + if (this != &rhs && m_ptr != rhs.m_ptr) { + if (m_ptr) + CFRelease(m_ptr); + if ((m_ptr = rhs.m_ptr)) + CFRetain(m_ptr); + } + + return *this; + } + +#ifdef Q_COMPILER_RVALUE_REFS + CFStrongReference(CFStrongReference &&xval) + { + m_ptr = xval.m_ptr; + xval.m_ptr = Q_NULLPTR; + } + + CFStrongReference &operator = (CFStrongReference &&xval) + { + m_ptr = xval.m_ptr; + xval.m_ptr = Q_NULLPTR; + return *this; + } +#endif + + ~CFStrongReference() + { + if (m_ptr) + CFRelease(m_ptr); + } + + void reset(T newVal) + { + if (m_ptr != newVal) { + if (m_ptr) + CFRelease(m_ptr); + if ((m_ptr = newVal)) + CFRetain(m_ptr); + } + } + + operator T() const + { + return m_ptr; + } + + T data() const + { + return m_ptr; + } + + T take() + { + T p = m_ptr; + m_ptr = Q_NULLPTR; + return p; + } +private: + T m_ptr; +}; + QString qt_address(NSString *address); #ifndef QT_IOS_BLUETOOTH @@ -192,6 +275,26 @@ QString qt_error_string(IOReturn errorCode); #endif +QBluetoothUuid qt_uuid(CBUUID *uuid); +CFStrongReference<CFUUIDRef> cf_uuid(const QBluetoothUuid &qtUuid); +ObjCStrongReference<CBUUID> cb_uuid(const QBluetoothUuid &qtUuid); +bool equal_uuids(const QBluetoothUuid &qtUuid, CBUUID *cbUuid); +bool equal_uuids(CBUUID *cbUuid, const QBluetoothUuid &qtUuid); +QByteArray qt_bytearray(NSData *data); +QByteArray qt_bytearray(NSObject *data); +ObjCStrongReference<NSData> data_from_bytearray(const QByteArray & qtData); + +inline QSysInfo::MacVersion qt_OS_limit(QSysInfo::MacVersion osxVersion, QSysInfo::MacVersion iosVersion) +{ +#ifdef Q_OS_OSX + Q_UNUSED(iosVersion) + return osxVersion; +#else + Q_UNUSED(osxVersion) + return iosVersion; +#endif +} + } // namespace OSXBluetooth // Logging category for both OS X and iOS. |