9#include <QtCore/qloggingcategory.h>
10#include <QtCore/qdebug.h>
14@implementation DarwinBTL2CAPChannel
16 QT_PREPEND_NAMESPACE(DarwinBluetooth)::ChannelDelegate *delegate;
17 IOBluetoothDevice *device;
18 IOBluetoothL2CAPChannel *channel;
22- (
id)initWithDelegate:(DarwinBluetooth::ChannelDelegate *)aDelegate
24 Q_ASSERT_X(aDelegate, Q_FUNC_INFO,
"invalid delegate (null)");
26 if (self = [super init]) {
36- (
id)initWithDelegate:(QT_PREPEND_NAMESPACE(DarwinBluetooth::ChannelDelegate) *)aDelegate
37 channel:(IOBluetoothL2CAPChannel *)aChannel
41 Q_ASSERT_X(aDelegate, Q_FUNC_INFO,
"invalid delegate (null)");
42 Q_ASSERT_X(channel, Q_FUNC_INFO,
"invalid channel (nil)");
44 if (self = [super init]) {
46 channel = [aChannel retain];
47 [channel setDelegate:self];
48 device = [channel.device retain];
59 [channel setDelegate:nil];
64 [channel closeChannel];
73- (IOReturn)connectAsyncToDevice:(
const QBluetoothAddress &)address
74 withPSM:(BluetoothL2CAPChannelID)psm
76 if (address.isNull()) {
77 qCCritical(QT_BT_DARWIN) <<
"invalid peer address";
78 return kIOReturnNoDevice;
82 if (connected || device || channel) {
83 qCCritical(QT_BT_DARWIN) <<
"connection is already active";
84 return kIOReturnStillOpen;
89 const BluetoothDeviceAddress iobtAddress = DarwinBluetooth::iobluetooth_address(address);
90 device = [IOBluetoothDevice deviceWithAddress:&iobtAddress];
92 qCCritical(QT_BT_DARWIN) <<
"failed to create a device";
93 return kIOReturnNoDevice;
96 const IOReturn status = [device openL2CAPChannelAsync:&channel withPSM:psm delegate:self];
97 if (status != kIOReturnSuccess) {
98 qCCritical(QT_BT_DARWIN) <<
"failed to open L2CAP channel";
107 return kIOReturnSuccess;
112- (
void)l2capChannelData:(IOBluetoothL2CAPChannel*)l2capChannel
113 data:(
void *)dataPointer length:(size_t)dataLength
115 Q_UNUSED(l2capChannel);
117 Q_ASSERT_X(delegate, Q_FUNC_INFO,
"invalid delegate (null)");
119 if (dataPointer && dataLength)
120 delegate->readChannelData(dataPointer, dataLength);
123- (
void)l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*)
124 l2capChannel status:(IOReturn)error
126 Q_UNUSED(l2capChannel);
128 Q_ASSERT_X(delegate, Q_FUNC_INFO,
"invalid delegate (null)");
130 if (error != kIOReturnSuccess) {
131 delegate->setChannelError(error);
134 delegate->channelOpenComplete();
138- (
void)l2capChannelClosed:(IOBluetoothL2CAPChannel*)l2capChannel
140 Q_UNUSED(l2capChannel);
142 Q_ASSERT_X(delegate, Q_FUNC_INFO,
"invalid delegate (null)");
143 delegate->channelClosed();
147- (
void)l2capChannelReconfigured:(IOBluetoothL2CAPChannel*)l2capChannel
149 Q_UNUSED(l2capChannel);
152- (
void)l2capChannelWriteComplete:(IOBluetoothL2CAPChannel*)l2capChannel
153 refcon:(
void*)refcon status:(IOReturn)error
155 Q_UNUSED(l2capChannel);
158 Q_ASSERT_X(delegate, Q_FUNC_INFO,
"invalid delegate (null)");
160 if (error != kIOReturnSuccess)
161 delegate->setChannelError(error);
163 delegate->writeComplete();
166- (
void)l2capChannelQueueSpaceAvailable:(IOBluetoothL2CAPChannel*)l2capChannel
168 Q_UNUSED(l2capChannel);
172- (BluetoothL2CAPPSM)getPSM
180- (BluetoothDeviceAddress)peerAddress
182 const BluetoothDeviceAddress *
const addr = device ? [device getAddress]
187 return BluetoothDeviceAddress();
203- (IOReturn) writeSync:(
void*)data length:(UInt16)length
205 Q_ASSERT_X(data, Q_FUNC_INFO,
"invalid data (null)");
206 Q_ASSERT_X(length, Q_FUNC_INFO,
"invalid data size");
207 Q_ASSERT_X(connected && channel, Q_FUNC_INFO,
"invalid L2CAP channel");
209 return [channel writeSync:data length:length];
212- (IOReturn) writeAsync:(
void*)data length:(UInt16)length
214 Q_ASSERT_X(data, Q_FUNC_INFO,
"invalid data (null)");
215 Q_ASSERT_X(length, Q_FUNC_INFO,
"invalid data size");
216 Q_ASSERT_X(connected && channel, Q_FUNC_INFO,
"invalid L2CAP channel");
218 return [channel writeAsync:data length:length refcon:
nullptr];
#define QT_BT_MAC_AUTORELEASEPOOL
Q_FORWARD_DECLARE_OBJC_CLASS(NSString)