5#include "darwin/btservicerecord_p.h"
9#include "darwin/btutility_p.h"
11#include <QtCore/qloggingcategory.h>
12#include <QtCore/qvariant.h>
13#include <QtCore/qglobal.h>
14#include <QtCore/qmutex.h>
15#include <QtCore/qmap.h>
16#include <QtCore/qurl.h>
18#include <Foundation/Foundation.h>
20#include <IOBluetooth/IOBluetooth.h>
27using ServiceInfo = QBluetoothServiceInfo;
33 ServiceInfo::Sequence parameters = privateInfo.protocolDescriptor(QBluetoothUuid::ProtocolUuid::Rfcomm);
34 if (!parameters.isEmpty())
35 return ServiceInfo::RfcommProtocol;
37 parameters = privateInfo.protocolDescriptor(QBluetoothUuid::ProtocolUuid::L2cap);
38 if (!parameters.isEmpty())
39 return ServiceInfo::L2capProtocol;
41 return ServiceInfo::UnknownProtocol;
46 const auto parameters = privateInfo.protocolDescriptor(uuid);
47 if (parameters.isEmpty())
49 else if (parameters.size() == 1)
52 return parameters.at(1).toInt();
67 Q_UNUSED(localAddress);
80 ObjCStrongReference<NSMutableDictionary> serviceDict(iobluetooth_service_dictionary(info));
82 qCWarning(QT_BT_DARWIN) <<
"failed to create a service dictionary";
86 Q_ASSERT(!registered);
87 Q_ASSERT_X(!serviceRecord, Q_FUNC_INFO,
"not registered, but serviceRecord is not nil");
90 newRecord.reset([IOBluetoothSDPServiceRecord
91 publishedServiceRecordWithDictionary:serviceDict], RetainPolicy::doInitialRetain);
93 qCWarning(QT_BT_DARWIN) <<
"failed to register a service record";
97 BluetoothSDPServiceRecordHandle newRecordHandle = 0;
98 auto *ioSDPRecord = newRecord.getAs<IOBluetoothSDPServiceRecord>();
99 if ([ioSDPRecord getServiceRecordHandle:&newRecordHandle] != kIOReturnSuccess) {
100 qCWarning(QT_BT_DARWIN) <<
"failed to register a service record";
101 [ioSDPRecord removeServiceRecord];
105 const ServiceInfo::Protocol type = info.socketProtocol();
106 quint16 realPort = 0;
107 QBluetoothServerPrivate *server =
nullptr;
108 bool configured =
false;
110 if (type == QBluetoothServiceInfo::L2capProtocol) {
111 BluetoothL2CAPPSM psm = 0;
112 server = QBluetoothServerPrivate::registeredServer(info.protocolServiceMultiplexer(), type);
113 if ([ioSDPRecord getL2CAPPSM:&psm] == kIOReturnSuccess) {
117 }
else if (type == QBluetoothServiceInfo::RfcommProtocol) {
118 BluetoothRFCOMMChannelID channelID = 0;
119 server = QBluetoothServerPrivate::registeredServer(info.serverChannel(), type);
120 if ([ioSDPRecord getRFCOMMChannelID:&channelID] == kIOReturnSuccess) {
122 realPort = channelID;
127 [ioSDPRecord removeServiceRecord];
128 qCWarning(QT_BT_DARWIN) <<
"failed to register a service record";
133 serviceRecord.swap(newRecord);
134 serviceRecordHandle = newRecordHandle;
137 server->startListener(realPort);
142bool QBluetoothServiceInfoPrivate::isRegistered()
const
147bool QBluetoothServiceInfoPrivate::unregisterService()
152 Q_ASSERT_X(serviceRecord, Q_FUNC_INFO,
"service registered, but serviceRecord is nil");
154 auto *nativeRecord = serviceRecord.getAs<IOBluetoothSDPServiceRecord>();
155 [nativeRecord removeServiceRecord];
156 serviceRecord.reset();
158 const ServiceInfo::Protocol type = socket_protocol(*
this);
159 QBluetoothServerPrivate *server =
nullptr;
161 const QMutexLocker lock(&QBluetoothServerPrivate::channelMapMutex());
162 if (type == ServiceInfo::RfcommProtocol)
163 server = QBluetoothServerPrivate::registeredServer(channel_or_psm(*
this, QBluetoothUuid::ProtocolUuid::Rfcomm), type);
164 else if (type == ServiceInfo::L2capProtocol)
165 server = QBluetoothServerPrivate::registeredServer(channel_or_psm(*
this, QBluetoothUuid::ProtocolUuid::L2cap), type);
168 server->stopListener();
171 serviceRecordHandle = 0;
bool registerService(const QBluetoothAddress &localAdapter=QBluetoothAddress())
bool isRegistered() const
~QBluetoothServiceInfoPrivate()
Combined button and popup list for selecting options.
ServiceInfo::Protocol socket_protocol(const QBluetoothServiceInfoPrivate &privateInfo)
int channel_or_psm(const QBluetoothServiceInfoPrivate &privateInfo, QBluetoothUuid::ProtocolUuid uuid)