9#include <QtCore/qdebug.h>
13@implementation DarwinBTConnectionMonitor
15 QT_PREPEND_NAMESPACE(DarwinBluetooth::ConnectionMonitor) *monitor;
16 IOBluetoothUserNotification *discoveryNotification;
17 NSMutableArray *foundConnections;
20- (id)initWithMonitor:(DarwinBluetooth::ConnectionMonitor *)aMonitor
22 Q_ASSERT_X(aMonitor,
"-initWithMonitor:",
"invalid monitor (null)");
24 if (self = [super init]) {
26 discoveryNotification = [[IOBluetoothDevice registerForConnectNotifications:self
27 selector:@selector(connectionNotification:withDevice:)] retain];
28 foundConnections = [[NSMutableArray alloc] init];
36 Q_ASSERT_X(!monitor,
"-dealloc",
37 "Connection monitor was not stopped, calling -stopMonitoring is required");
41- (
void)connectionNotification:(IOBluetoothUserNotification *)aNotification
42 withDevice:(IOBluetoothDevice *)device
44 Q_UNUSED(aNotification);
46 typedef IOBluetoothUserNotification Notification;
55 qCWarning(QT_BT_DARWIN,
56 "Connection notification received in a monitor that was cancelled");
64 const QBluetoothAddress deviceAddress(DarwinBluetooth::qt_address([device getAddress]));
65 if (deviceAddress.isNull())
68 if (foundConnections) {
69 Notification *
const notification = [device registerForDisconnectNotification:self
70 selector: @selector(connectionClosedNotification:withDevice:)];
72 [foundConnections addObject:notification];
75 Q_ASSERT_X(monitor,
"-connectionNotification:withDevice:",
"invalid monitor (null)");
76 monitor->deviceConnected(deviceAddress);
79- (
void)connectionClosedNotification:(IOBluetoothUserNotification *)notification
80 withDevice:(IOBluetoothDevice *)device
84 [notification unregister];
85 [foundConnections removeObject:notification];
87 const QBluetoothAddress deviceAddress(DarwinBluetooth::qt_address([device getAddress]));
88 if (deviceAddress.isNull())
91 Q_ASSERT_X(monitor,
"-connectionClosedNotification:withDevice:",
"invalid monitor (null)");
92 monitor->deviceDisconnected(deviceAddress);
98 [discoveryNotification unregister];
99 [discoveryNotification release];
100 discoveryNotification = nil;
102 for (IOBluetoothUserNotification *n in foundConnections)
105 [foundConnections release];
106 foundConnections = nil;
#define QT_BT_MAC_AUTORELEASEPOOL