diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/osx/osxbtcentralmanager.mm | 4 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtcentralmanager_p.h | 12 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtgcdtimer.mm | 41 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtgcdtimer_p.h | 38 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtledeviceinquiry.mm | 4 |
5 files changed, 70 insertions, 29 deletions
diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index 9254bd98..75d9f5c0 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -197,8 +197,10 @@ QT_END_NAMESPACE timeoutType = OSXBluetooth::OperationTimeout::none; } -- (void)timeout +- (void)timeout:(id)sender { + Q_UNUSED(sender) + using namespace OSXBluetooth; Q_ASSERT(objectUnderWatch); diff --git a/src/bluetooth/osx/osxbtcentralmanager_p.h b/src/bluetooth/osx/osxbtcentralmanager_p.h index e172d874..a1d2db66 100644 --- a/src/bluetooth/osx/osxbtcentralmanager_p.h +++ b/src/bluetooth/osx/osxbtcentralmanager_p.h @@ -87,18 +87,6 @@ enum CentralManagerState CentralManagerDisconnecting }; -enum class OperationTimeout -{ - none, - serviceDiscovery, - includedServicesDiscovery, - characteristicsDiscovery, - characteristicRead, - descriptorsDiscovery, - descriptorRead, - characteristicWrite -}; - // 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 diff --git a/src/bluetooth/osx/osxbtgcdtimer.mm b/src/bluetooth/osx/osxbtgcdtimer.mm index 095f8680..9663ca93 100644 --- a/src/bluetooth/osx/osxbtgcdtimer.mm +++ b/src/bluetooth/osx/osxbtgcdtimer.mm @@ -44,7 +44,23 @@ #include <algorithm> -@implementation QT_MANGLE_NAMESPACE(OSXBTGCDTimer) +QT_USE_NAMESPACE +using namespace OSXBluetooth; + +@implementation QT_MANGLE_NAMESPACE(OSXBTGCDTimer) { +@private + qint64 timeoutMS; + qint64 timeoutStepMS; + + // Optional: + id objectUnderWatch; + OperationTimeout timeoutType; + + QElapsedTimer timer; + id<QT_MANGLE_NAMESPACE(GCDTimerDelegate)> timeoutHandler; + + bool cancelled; +} - (instancetype)initWithDelegate:(id<QT_MANGLE_NAMESPACE(GCDTimerDelegate)>)delegate { @@ -52,11 +68,19 @@ timeoutHandler = delegate; timeoutMS = 0; timeoutStepMS = 0; + objectUnderWatch = nil; + timeoutType = OperationTimeout::none; cancelled = false; } return self; } +- (void)watchAfter:(id)object withTimeoutType:(OperationTimeout)type +{ + objectUnderWatch = object; + timeoutType = type; +} + - (void)startWithTimeout:(qint64)ms step:(qint64)stepMS { Q_ASSERT(!timeoutMS && !timeoutStepMS); @@ -86,9 +110,8 @@ const qint64 elapsed = timer.elapsed(); if (elapsed >= timeoutMS) { - [timeoutHandler timeout]; + [timeoutHandler timeout:self]; } else { - using namespace QT_PREPEND_NAMESPACE(OSXBluetooth); // Re-schedule: dispatch_queue_t leQueue(qt_LE_queue()); Q_ASSERT(leQueue); @@ -106,6 +129,18 @@ { cancelled = true; timeoutHandler = nil; + objectUnderWatch = nil; + timeoutType = OperationTimeout::none; +} + +- (id)objectUnderWatch +{ + return objectUnderWatch; +} + +- (OperationTimeout)timeoutType +{ + return timeoutType; } @end diff --git a/src/bluetooth/osx/osxbtgcdtimer_p.h b/src/bluetooth/osx/osxbtgcdtimer_p.h index 007a004b..153e9033 100644 --- a/src/bluetooth/osx/osxbtgcdtimer_p.h +++ b/src/bluetooth/osx/osxbtgcdtimer_p.h @@ -58,25 +58,39 @@ #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; +- (void)timeout:(id)sender; @end -@interface QT_MANGLE_NAMESPACE(OSXBTGCDTimer) : NSObject { -@private - qint64 timeoutMS; - qint64 timeoutStepMS; - QT_PREPEND_NAMESPACE(QElapsedTimer) timer; - id<QT_MANGLE_NAMESPACE(GCDTimerDelegate)> timeoutHandler; - bool cancelled; -} - +@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 @@ -86,7 +100,7 @@ namespace OSXBluetooth { using GCDTimerObjC = QT_MANGLE_NAMESPACE(OSXBTGCDTimer); using GCDTimer = ObjCScopedPointer<GCDTimerObjC>; -} +} // namespace OSXBluetooth QT_END_NAMESPACE diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index e61968ed..c82cb31d 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -151,8 +151,10 @@ QT_USE_NAMESPACE [super dealloc]; } -- (void)timeout +- (void)timeout:(id)sender { + Q_UNUSED(sender) + if (internalState == InquiryActive) { [manager stopScan]; [manager setDelegate:nil]; |