Compare commits

...

4 Commits

Author SHA1 Message Date
Roberto Viola
ee27acc050 Update project.pbxproj 2025-02-20 06:21:16 +01:00
Roberto Viola
0439d4bb3e Merge branch 'master' into fixing_ios_bluetooth_crash 2025-02-20 06:18:19 +01:00
Roberto Viola
e5c568eca4 fixing build 2025-02-19 13:42:06 +01:00
Roberto Viola
67d6213347 adding files 2025-02-19 13:33:18 +01:00
6 changed files with 781 additions and 6 deletions

View File

@@ -413,6 +413,7 @@
87958F1B27628D5400124B24 /* moc_elitesterzosmart.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 87958F1A27628D5400124B24 /* moc_elitesterzosmart.cpp */; };
8798C8872733E103003148B3 /* strydrunpowersensor.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 8798C8862733E103003148B3 /* strydrunpowersensor.cpp */; };
8798C8892733E10E003148B3 /* moc_strydrunpowersensor.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 8798C8882733E10E003148B3 /* moc_strydrunpowersensor.cpp */; };
8798FDC52D66075B00CF8EE8 /* OSXBtManagerInternal.mm in Compile Sources */ = {isa = PBXBuildFile; fileRef = 8798FDC32D66075B00CF8EE8 /* OSXBtManagerInternal.mm */; };
879A38C8281BD83300F78B2A /* characteristicnotifier2ad9.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 879A38C7281BD83300F78B2A /* characteristicnotifier2ad9.cpp */; };
879E5AA8289C057E00FEA38A /* proformwifitreadmill.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 879E5AA6289C057E00FEA38A /* proformwifitreadmill.cpp */; };
879E5AAA289C05A500FEA38A /* moc_proformwifitreadmill.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 879E5AA9289C05A500FEA38A /* moc_proformwifitreadmill.cpp */; };
@@ -1377,6 +1378,11 @@
8798C8852733E103003148B3 /* strydrunpowersensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = strydrunpowersensor.h; path = ../src/devices/strydrunpowersensor/strydrunpowersensor.h; sourceTree = "<group>"; };
8798C8862733E103003148B3 /* strydrunpowersensor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = strydrunpowersensor.cpp; path = ../src/devices/strydrunpowersensor/strydrunpowersensor.cpp; sourceTree = "<group>"; };
8798C8882733E10E003148B3 /* moc_strydrunpowersensor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = moc_strydrunpowersensor.cpp; sourceTree = "<group>"; };
8798FDC02D66075B00CF8EE8 /* osxbluetooth_p.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = osxbluetooth_p.h; path = ../src/ios/BluetoothPatch/osxbluetooth_p.h; sourceTree = SOURCE_ROOT; };
8798FDC12D66075B00CF8EE8 /* osxbtcentralmanager_p.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = osxbtcentralmanager_p.h; path = ../src/ios/BluetoothPatch/osxbtcentralmanager_p.h; sourceTree = SOURCE_ROOT; };
8798FDC22D66075B00CF8EE8 /* osxbtgcdtimer_p.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = osxbtgcdtimer_p.h; path = ../src/ios/BluetoothPatch/osxbtgcdtimer_p.h; sourceTree = SOURCE_ROOT; };
8798FDC32D66075B00CF8EE8 /* OSXBtManagerInternal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = OSXBtManagerInternal.mm; path = ../src/ios/BluetoothPatch/OSXBtManagerInternal.mm; sourceTree = SOURCE_ROOT; };
8798FDC42D66075B00CF8EE8 /* osxbtutility_p.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = osxbtutility_p.h; path = ../src/ios/BluetoothPatch/osxbtutility_p.h; sourceTree = SOURCE_ROOT; };
879A38C7281BD83300F78B2A /* characteristicnotifier2ad9.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = characteristicnotifier2ad9.cpp; path = ../src/characteristics/characteristicnotifier2ad9.cpp; sourceTree = "<group>"; };
879E5AA6289C057E00FEA38A /* proformwifitreadmill.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = proformwifitreadmill.cpp; path = ../src/devices/proformwifitreadmill/proformwifitreadmill.cpp; sourceTree = "<group>"; };
879E5AA7289C057E00FEA38A /* proformwifitreadmill.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = proformwifitreadmill.h; path = ../src/devices/proformwifitreadmill/proformwifitreadmill.h; sourceTree = "<group>"; };
@@ -2173,6 +2179,11 @@
2EB56BE3C2D93CDAB0C52E67 /* Sources */ = {
isa = PBXGroup;
children = (
8798FDC02D66075B00CF8EE8 /* osxbluetooth_p.h */,
8798FDC12D66075B00CF8EE8 /* osxbtcentralmanager_p.h */,
8798FDC22D66075B00CF8EE8 /* osxbtgcdtimer_p.h */,
8798FDC32D66075B00CF8EE8 /* OSXBtManagerInternal.mm */,
8798FDC42D66075B00CF8EE8 /* osxbtutility_p.h */,
87A33F1B2D611D9500BFFF29 /* logwriter.h */,
87A33F1C2D611D9500BFFF29 /* logwriter.cpp */,
87A33F192D611D8400BFFF29 /* moc_logwriter.cpp */,
@@ -3758,6 +3769,7 @@
872261F0289EA887006A6F75 /* moc_nordictrackelliptical.cpp in Compile Sources */,
873824E327E647A8004F1B46 /* bitmap.cpp in Compile Sources */,
87FE5BB12692F31E0056EFC8 /* moc_tacxneo2.cpp in Compile Sources */,
8798FDC52D66075B00CF8EE8 /* OSXBtManagerInternal.mm in Compile Sources */,
873824E827E647A8004F1B46 /* provider.cpp in Compile Sources */,
8791A8AA25C8603F003B50B2 /* moc_inspirebike.cpp in Compile Sources */,
03F49BBCF19B73B18385B13D /* FitMesgDefinition.mm in Compile Sources */,
@@ -4243,7 +4255,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1033;
CURRENT_PROJECT_VERSION = 1035;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = "ADB_HOST=1";
@@ -4437,7 +4449,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1033;
CURRENT_PROJECT_VERSION = 1035;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = NO;
@@ -4667,7 +4679,7 @@
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1033;
CURRENT_PROJECT_VERSION = 1035;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -4763,7 +4775,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1033;
CURRENT_PROJECT_VERSION = 1035;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = YES;
@@ -4855,7 +4867,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1033;
CURRENT_PROJECT_VERSION = 1035;
DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\"";
ENABLE_BITCODE = YES;
ENABLE_PREVIEWS = YES;
@@ -4971,7 +4983,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1033;
CURRENT_PROJECT_VERSION = 1035;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\"";
ENABLE_BITCODE = YES;

View File

@@ -0,0 +1,80 @@
#define QT_IOS_BLUETOOTH
#import "osxbtcentralmanager_p.h"
#import <objc/runtime.h>
QT_USE_NAMESPACE
// Definizione della struttura dei membri privati
@interface QT_MANGLE_NAMESPACE(OSXBTCentralManager) () {
@package // Rende i membri accessibili alla categoria
OSXBluetooth::CharHash charMap;
OSXBluetooth::DescHash descMap;
OSXBluetooth::ValueHash valuesToWrite;
}
@end
@implementation QT_MANGLE_NAMESPACE(OSXBTCentralManager) (SafeCache)
- (bool)cacheWriteValue:(const QByteArray &)value for:(NSObject *)obj
{
@try {
// Accesso alle variabili private tramite self
OSXBluetooth::CharHash &localCharMap = ((QT_MANGLE_NAMESPACE(OSXBTCentralManager) *)self)->charMap;
OSXBluetooth::DescHash &localDescMap = ((QT_MANGLE_NAMESPACE(OSXBTCentralManager) *)self)->descMap;
OSXBluetooth::ValueHash &localValuesToWrite = ((QT_MANGLE_NAMESPACE(OSXBTCentralManager) *)self)->valuesToWrite;
// Verifica validità oggetto
if (!obj) {
qDebug() << "Error: Invalid object (nil)";
return false;
}
// Verifica tipo oggetto
if ([obj isKindOfClass:[CBCharacteristic class]]) {
@try {
CBCharacteristic *const ch = (CBCharacteristic *)obj;
if (!localCharMap.key(ch)) {
qDebug() << "Error: Unexpected characteristic, no handle found";
return false;
}
} @catch (NSException *e) {
qDebug() << "Exception handling characteristic:" << e.reason;
return false;
}
} else if ([obj isKindOfClass:[CBDescriptor class]]) {
@try {
CBDescriptor *const d = (CBDescriptor *)obj;
if (!localDescMap.key(d)) {
qDebug() << "Error: Unexpected descriptor, no handle found";
return false;
}
} @catch (NSException *e) {
qDebug() << "Exception handling descriptor:" << e.reason;
return false;
}
} else {
qDebug() << "Error: Invalid object type, characteristic or descriptor required";
return false;
}
// Gestione cache esistente
@try {
if (localValuesToWrite.contains(obj)) {
qDebug() << "Warning: Already has a cached value for this object, the value will be replaced";
}
localValuesToWrite[obj] = value;
} @catch (NSException *e) {
qDebug() << "Exception during cache operation:" << e.reason;
return false;
}
return true;
} @catch (NSException *e) {
qDebug() << "Unexpected exception in cacheWriteValue:" << e.reason;
return false;
}
}
@end

View File

@@ -0,0 +1,63 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://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 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef OSXBLUETOOTH_P_H
#define OSXBLUETOOTH_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/qglobal.h>
#include <CoreBluetooth/CoreBluetooth.h>
#ifdef Q_OS_MACOS
#include <IOBluetooth/IOBluetooth.h>
#endif
#endif // OSXBLUETOOTH_P_H

View File

@@ -0,0 +1,176 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://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 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef OSXBTCENTRALMANAGER_P_H
#define OSXBTCENTRALMANAGER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "qlowenergycontroller.h"
#include "qlowenergyservice.h"
#include "osxbtgcdtimer_p.h"
#include "qbluetoothuuid.h"
#include "osxbtutility_p.h"
#include "osxbluetooth_p.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qglobal.h>
#include <QtCore/qqueue.h>
#include <QtCore/qhash.h>
#include <Foundation/Foundation.h>
@class QT_MANGLE_NAMESPACE(OSXBTCentralManager);
QT_BEGIN_NAMESPACE
class QLowEnergyServicePrivate;
namespace OSXBluetooth {
class LECBManagerNotifier;
enum CentralManagerState
{
// QLowEnergyController already has some of these states,
// but it's not enough and we need more special states here.
CentralManagerIdle,
// Required by CBCentralManager to avoid problems with dangled pointers.
CentralManagerUpdating,
CentralManagerConnecting,
CentralManagerDiscovering,
CentralManagerDisconnecting
};
// In Qt we work with handles and UUIDs. Core Bluetooth
// has NSArrays (and nested NSArrays inside servces/characteristics).
// To simplify a navigation, I need a simple way to map from a handle
// to a Core Bluetooth object. These are weak pointers,
// will probably require '__weak' with ARC.
typedef QHash<QLowEnergyHandle, CBService *> ServiceHash;
typedef QHash<QLowEnergyHandle, CBCharacteristic *> CharHash;
typedef QHash<QLowEnergyHandle, CBDescriptor *> DescHash;
// Descriptor/charactesirstic read/write requests
// - we have to serialize 'concurrent' requests.
struct LERequest {
enum RequestType {
CharRead,
CharWrite,
DescRead,
DescWrite,
ClientConfiguration,
Invalid
};
LERequest() : type(Invalid),
withResponse(false),
handle(0)
{}
RequestType type;
bool withResponse;
QLowEnergyHandle handle;
QByteArray value;
};
typedef QQueue<LERequest> RequestQueue;
// Core Bluetooth's write confirmation does not provide
// the updated value (characteristic or descriptor).
// But the Qt's Bluetooth API ('write with response')
// expects this updated value as a response, so we have
// to cache this write value and report it back.
// 'NSObject *' will require '__weak' with ARC.
typedef QHash<NSObject *, QByteArray> ValueHash;
}
QT_END_NAMESPACE
@interface QT_MANGLE_NAMESPACE(OSXBTCentralManager) : NSObject<CBCentralManagerDelegate,
CBPeripheralDelegate,
QT_MANGLE_NAMESPACE(GCDTimerDelegate)>
- (id)initWith:(QT_PREPEND_NAMESPACE(OSXBluetooth)::LECBManagerNotifier *)notifier;
- (void)dealloc;
- (CBPeripheral *)peripheral;
// IMPORTANT: _all_ these methods are to be executed on qt_LE_queue,
// when passing parameters - C++ objects _must_ be copied (see the controller's code).
- (void)connectToDevice:(const QT_PREPEND_NAMESPACE(QBluetoothUuid) &)aDeviceUuid;
- (void)disconnectFromDevice;
- (void)discoverServices;
- (void)discoverServiceDetails:(const QT_PREPEND_NAMESPACE(QBluetoothUuid) &)serviceUuid;
- (void)setNotifyValue:(const QT_PREPEND_NAMESPACE(QByteArray) &)value
forCharacteristic:(QT_PREPEND_NAMESPACE(QLowEnergyHandle))charHandle
onService:(const QT_PREPEND_NAMESPACE(QBluetoothUuid) &)serviceUuid;
- (void)readCharacteristic:(QT_PREPEND_NAMESPACE(QLowEnergyHandle))charHandle
onService:(const QT_PREPEND_NAMESPACE(QBluetoothUuid) &)serviceUuid;
- (void)write:(const QT_PREPEND_NAMESPACE(QByteArray) &)value
charHandle:(QT_PREPEND_NAMESPACE(QLowEnergyHandle))charHandle
onService:(const QT_PREPEND_NAMESPACE(QBluetoothUuid) &)serviceUuid
withResponse:(bool)writeWithResponse;
- (void)readDescriptor:(QT_PREPEND_NAMESPACE(QLowEnergyHandle))descHandle
onService:(const QT_PREPEND_NAMESPACE(QBluetoothUuid) &)serviceUuid;
- (void)write:(const QT_PREPEND_NAMESPACE(QByteArray) &)value
descHandle:(QT_PREPEND_NAMESPACE(QLowEnergyHandle))descHandle
onService:(const QT_PREPEND_NAMESPACE(QBluetoothUuid) &)serviceUuid;
- (void)detach;
@end
#endif

View File

@@ -0,0 +1,108 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://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 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef OSXBTGCDTIMER_P_H
#define OSXBTGCDTIMER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "osxbtutility_p.h"
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qglobal.h>
#include <Foundation/Foundation.h>
QT_BEGIN_NAMESPACE
namespace OSXBluetooth {
enum class OperationTimeout
{
none,
serviceDiscovery,
includedServicesDiscovery,
characteristicsDiscovery,
characteristicRead,
descriptorsDiscovery,
descriptorRead,
characteristicWrite
};
} // namespace OSXBluetooth
QT_END_NAMESPACE
@protocol QT_MANGLE_NAMESPACE(GCDTimerDelegate)
@required
- (void)timeout:(id)sender;
@end
@interface QT_MANGLE_NAMESPACE(OSXBTGCDTimer) : NSObject
- (instancetype)initWithDelegate:(id<QT_MANGLE_NAMESPACE(GCDTimerDelegate)>)delegate;
- (void)watchAfter:(id)object withTimeoutType:(QT_PREPEND_NAMESPACE(OSXBluetooth)::OperationTimeout)type;
- (void)startWithTimeout:(qint64)ms step:(qint64)stepMS;
- (void)handleTimeout;
- (void)cancelTimer;
- (id)objectUnderWatch;
- (QT_PREPEND_NAMESPACE(OSXBluetooth)::OperationTimeout)timeoutType;
@end
QT_BEGIN_NAMESPACE
namespace OSXBluetooth {
using GCDTimerObjC = QT_MANGLE_NAMESPACE(OSXBTGCDTimer);
using GCDTimer = ObjCStrongReference<GCDTimerObjC>;
} // namespace OSXBluetooth
QT_END_NAMESPACE
#endif // OSXBTGCDTIMER_P_H

View File

@@ -0,0 +1,336 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://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 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef OSXBTUTILITY_P_H
#define OSXBTUTILITY_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "osxbluetooth_p.h"
#include <QtCore/qloggingcategory.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qglobal.h>
#include <Foundation/Foundation.h>
QT_BEGIN_NAMESPACE
class QLowEnergyCharacteristicData;
class QBluetoothAddress;
class QBluetoothUuid;
namespace OSXBluetooth {
struct NSObjectDeleter {
static void cleanup(NSObject *obj)
{
[obj release];
}
};
template<class T>
class ObjCScopedPointer : public QScopedPointer<NSObject, NSObjectDeleter>
{
public:
// TODO: remove default argument, add 'retain' parameter,
// add a default ctor??? This will make the semantics more
// transparent + will simplify the future transition to ARC
// (if it will ever happen).
explicit ObjCScopedPointer(T *ptr = nullptr) : QScopedPointer(ptr){}
operator T*() const
{
return data();
}
T *data()const
{
return static_cast<T *>(QScopedPointer::data());
}
T *take()
{
return static_cast<T *>(QScopedPointer::take());
}
};
#define QT_BT_MAC_AUTORELEASEPOOL const QMacAutoReleasePool pool;
template<class T>
class ObjCStrongReference {
public:
ObjCStrongReference()
: m_ptr(nil)
{
}
ObjCStrongReference(T *obj, bool retain)
{
if (retain)
m_ptr = [obj retain];
else
m_ptr = obj; // For example, created with initWithXXXX.
}
ObjCStrongReference(const ObjCStrongReference &rhs)
{
m_ptr = [rhs.m_ptr retain];
}
ObjCStrongReference &operator = (const ObjCStrongReference &rhs)
{
// "Old-style" implementation:
if (this != &rhs && m_ptr != rhs.m_ptr) {
[m_ptr release];
m_ptr = [rhs.m_ptr retain];
}
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
ObjCStrongReference(ObjCStrongReference &&xval)
{
m_ptr = xval.m_ptr;
xval.m_ptr = nil;
}
ObjCStrongReference &operator = (ObjCStrongReference &&xval)
{
m_ptr = xval.m_ptr;
xval.m_ptr = nil;
return *this;
}
#endif
~ObjCStrongReference()
{
[m_ptr release];
}
void reset(T *newVal)
{
if (m_ptr != newVal) {
[m_ptr release];
m_ptr = [newVal retain];
}
}
void resetWithoutRetain(T *newVal)
{
if (m_ptr != newVal) {
[m_ptr release];
m_ptr = newVal;
}
}
operator T *() const
{
return m_ptr;
}
T *data() const
{
return m_ptr;
}
T *take()
{
T * p = m_ptr;
m_ptr = nil;
return p;
}
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(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 = nullptr;
}
CFStrongReference &operator = (CFStrongReference &&xval)
{
m_ptr = xval.m_ptr;
xval.m_ptr = 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 = nullptr;
return p;
}
private:
T m_ptr;
};
QString qt_address(NSString *address);
#ifndef QT_IOS_BLUETOOTH
QBluetoothAddress qt_address(const BluetoothDeviceAddress *address);
BluetoothDeviceAddress iobluetooth_address(const QBluetoothAddress &address);
ObjCStrongReference<IOBluetoothSDPUUID> iobluetooth_uuid(const QBluetoothUuid &uuid);
QBluetoothUuid qt_uuid(IOBluetoothSDPUUID *uuid);
QString qt_error_string(IOReturn errorCode);
void qt_test_iobluetooth_runloop();
#endif // !QT_IOS_BLUETOOTH
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);
ObjCStrongReference<NSMutableData> mutable_data_from_bytearray(const QByteArray &qtData);
dispatch_queue_t qt_LE_queue();
extern const int defaultLEScanTimeoutMS;
extern const int maxValueLength;
} // namespace OSXBluetooth
// Logging category for both OS X and iOS.
Q_DECLARE_LOGGING_CATEGORY(QT_BT_OSX)
QT_END_NAMESPACE
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(101300) && QT_MACOS_DEPLOYMENT_TARGET_BELOW(101300)
// In the macOS 10.13 SDK, the identifier property was moved from the CBPeripheral
// and CBCentral classes to a new CBPeer base class. Because CBPeer is only available
// on macOS 10.13 and above, the same is true for -[CBPeer identifier]. However,
// since we know that the derived classes have always had this property,
// we'll explicitly mark its availability here. This will not adversely affect
// using the identifier through the CBPeer base class, which will still require macOS 10.13.
@interface CBPeripheral (UnguardedWorkaround)
@property (readonly, nonatomic) NSUUID *identifier NS_AVAILABLE(10_7, 5_0);
@end
@interface CBCentral (UnguardedWorkaround)
@property (readonly, nonatomic) NSUUID *identifier NS_AVAILABLE(10_7, 5_0);
@end
#endif
#endif