Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
btsocketlistener.mm
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6#include "btutility_p.h"
7
8#include <QtCore/qdebug.h>
9
10QT_USE_NAMESPACE
11
12@implementation DarwinBTSocketListener
13{
14 IOBluetoothUserNotification *connectionNotification;
15 QT_PREPEND_NAMESPACE(DarwinBluetooth::SocketListener) *delegate;
16 quint16 port;
17}
18
19- (id)initWithListener:(DarwinBluetooth::SocketListener *)aDelegate
20{
21 Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
22 if (self = [super init]) {
23 connectionNotification = nil;
24 delegate = aDelegate;
25 port = 0;
26 }
27
28 return self;
29}
30
31- (void)dealloc
32{
33 [connectionNotification unregister];
34 [connectionNotification release];
35
36 [super dealloc];
37}
38
39- (bool)listenRFCOMMConnectionsWithChannelID:(BluetoothRFCOMMChannelID)channelID
40{
41 Q_ASSERT_X(!connectionNotification, Q_FUNC_INFO, "already listening");
42
43 connectionNotification = [IOBluetoothRFCOMMChannel registerForChannelOpenNotifications:self
44 selector:@selector(rfcommOpenNotification:channel:)
45 withChannelID:channelID
46 direction:kIOBluetoothUserNotificationChannelDirectionIncoming];
47 connectionNotification = [connectionNotification retain];
48 if (connectionNotification)
49 port = channelID;
50
51 return connectionNotification;
52}
53
54- (bool)listenL2CAPConnectionsWithPSM:(BluetoothL2CAPPSM)psm
55{
56 Q_ASSERT_X(!connectionNotification, Q_FUNC_INFO, "already listening");
57
58 connectionNotification = [IOBluetoothL2CAPChannel registerForChannelOpenNotifications:self
59 selector:@selector(l2capOpenNotification:channel:)
60 withPSM:psm
61 direction:kIOBluetoothUserNotificationChannelDirectionIncoming];
62 connectionNotification = [connectionNotification retain];
63 if (connectionNotification)
64 port = psm;
65
66 return connectionNotification;
67}
68
69- (void)rfcommOpenNotification:(IOBluetoothUserNotification *)notification
70 channel:(IOBluetoothRFCOMMChannel *)newChannel
71{
72 Q_UNUSED(notification);
73
74 Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
75 delegate->openNotifyRFCOMM(newChannel);
76}
77
78- (void)l2capOpenNotification:(IOBluetoothUserNotification *)notification
79 channel:(IOBluetoothL2CAPChannel *)newChannel
80{
81 Q_UNUSED(notification);
82
83 Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
84 delegate->openNotifyL2CAP(newChannel);
85}
86
87- (quint16)port
88{
89 return port;
90}
91
92@end