7#include <QtCore/qelapsedtimer.h>
8#include <QtCore/qdebug.h>
13using namespace DarwinBluetooth;
15@implementation DarwinBTGCDTimer {
22 OperationTimeout timeoutType;
25 id<QT_MANGLE_NAMESPACE(GCDTimerDelegate)> timeoutHandler;
30- (instancetype)initWithDelegate:(id<QT_MANGLE_NAMESPACE(GCDTimerDelegate)>)delegate
32 if (self = [super init]) {
33 timeoutHandler = delegate;
36 objectUnderWatch = nil;
37 timeoutType = OperationTimeout::none;
43- (
void)watchAfter:(id)object withTimeoutType:(OperationTimeout)type
45 objectUnderWatch = object;
49- (
void)startWithTimeout:(qint64)ms step:(qint64)stepMS
51 Q_ASSERT(!timeoutMS && !timeoutStepMS);
54 if (!timeoutHandler) {
59 if (ms <= 0 || stepMS <= 0) {
60 qCWarning(QT_BT_DARWIN,
"Invalid timeout/step parameters");
65 timeoutStepMS = stepMS;
76 const qint64 elapsed = timer.elapsed();
77 if (elapsed >= timeoutMS) {
78 [timeoutHandler timeout:self];
81 dispatch_queue_t leQueue(qt_LE_queue());
83 const qint64 timeChunkMS = std::min(timeoutMS - elapsed, timeoutStepMS);
84 dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
85 int64_t(timeChunkMS / 1000. * NSEC_PER_SEC)),
97 objectUnderWatch = nil;
98 timeoutType = OperationTimeout::none;
101- (
id)objectUnderWatch
103 return objectUnderWatch;
106- (OperationTimeout)timeoutType