11#include <QtCore/qloggingcategory.h>
12#include <QtCore/qstring.h>
13#include <QtCore/qglobal.h>
14#include <QtCore/qdebug.h>
15#include <QtCore/qmap.h>
18#include <Foundation/Foundation.h>
20#include <IOBluetooth/IOBluetooth.h>
27 public DarwinBluetooth::ConnectionMonitor
47 BluetoothNumericValue)
override;
49 BluetoothPasskey passkey)
override;
50 void error(
void *pair, IOReturn errorCode)
override;
87 RetainPolicy::doInitialRetain);
88 if (!defaultController) {
89 qCCritical(QT_BT_DARWIN) <<
"failed to init a host controller object";
94 NSString *
const hciAddress = [defaultController addressAsString];
96 qCCritical(QT_BT_DARWIN) <<
"failed to obtain an address";
100 BluetoothDeviceAddress iobtAddress = {};
101 if (IOBluetoothNSStringToDeviceAddress(hciAddress, &iobtAddress) != kIOReturnSuccess) {
102 qCCritical(QT_BT_DARWIN) <<
"invalid local device's address";
107 qCCritical(QT_BT_DARWIN) <<
"invalid local device's address";
112 defaultController.swap(hostController);
121 [connectionMonitor stopMonitoring];
126 return hostController;
148 if (
pos != pairingRequests.
end()) {
153 IOBluetoothDevice *
const device = [
pos.value() targetDevice];
155 emitPairingFinished(
address, pairing,
true);
156 }
else if ([
pos.value()
start] != kIOReturnSuccess) {
157 qCCritical(QT_BT_DARWIN) <<
"failed to start a new pairing request";
169 qCCritical(QT_BT_DARWIN) <<
"failed to allocate a new pairing request";
176 if (
result != kIOReturnSuccess) {
178 qCCritical(QT_BT_DARWIN) <<
"failed to start a new pairing request";
193 RequestMap::const_iterator
it = pairingRequests.
find(
address);
194 if (
it != pairingRequests.
end()) {
196 IOBluetoothDevice *
const device = [
it.value() targetDevice];
250 "invalid target address");
257 if (!discoveredDevices.
contains(deviceAddress))
258 discoveredDevices.
append(deviceAddress);
267 discoveredDevices.
end(),
270 if (devicePos != discoveredDevices.
end())
271 discoveredDevices.
erase(devicePos);
287void QBluetoothLocalDevicePrivate::emitPairingFinished(
const QBluetoothAddress &deviceAddress,
305 "invalid target address");
338 if (NSString *
const nsn = [d_ptr->hostController nameAsString])
339 return QString::fromNSString(nsn);
351 if (NSString *
const nsa = [d_ptr->hostController addressAsString])
378 if (!
isValid() || ![d_ptr->hostController powerState])
391 NSArray *
const pairedDevices = [IOBluetoothDevice pairedDevices];
392 for (IOBluetoothDevice *
device in pairedDevices) {
393 if ([
device isConnected]) {
417 if (!defaultAdapter.
isValid() || defaultAdapter.
address().isNull()) {
426 localDevices.
append(deviceInfo);
IOBluetoothDevice * device
#define QT_BT_MAC_AUTORELEASEPOOL
void setAddress(const QBluetoothAddress &address)
Sets the Bluetooth address for this Bluetooth host info object.
void setName(const QString &name)
Sets the name of the host info object.
QBluetoothLocalDevice::Pairing Pairing
void pairingFinished(void *pair) override
QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *, const QBluetoothAddress &=QBluetoothAddress())
void error(void *pair, IOReturn errorCode) override
void passkeyNotification(void *pair, BluetoothPasskey passkey) override
~QBluetoothLocalDevicePrivate()
void requestPIN(void *pair) override
void deviceConnected(const QBluetoothAddress &deviceAddress) override
void deviceDisconnected(const QBluetoothAddress &deviceAddress) override
void requestUserConfirmation(void *pair, BluetoothNumericValue) override
Pairing pairingStatus(const QBluetoothAddress &address) const
void connecting(void *pair) override
void requestPairing(const QBluetoothAddress &address, Pairing pairing)
void powerOn()
Powers on the device after returning it to the hostMode() state, if it was powered off.
Pairing
This enum describes the pairing state between the two Bluetooth devices.
void errorOccurred(QBluetoothLocalDevice::Error error)
Signal emitted if there's an exceptional error while pairing.
void requestPairing(const QBluetoothAddress &address, Pairing pairing)
Set the pairing status with address.
HostMode
This enum describes the most of the local Bluetooth device.
HostMode hostMode() const
Returns the current host mode of this local Bluetooth device.
Error
This enum describes errors that maybe returned.
virtual ~QBluetoothLocalDevice()
Destroys the QBluetoothLocalDevice.
QList< QBluetoothAddress > connectedDevices() const
QBluetoothLocalDevice(QObject *parent=nullptr)
Constructs a QBluetoothLocalDevice with parent.
QString name() const
Returns the name assgined by the user to this Bluetooth device.
static QList< QBluetoothHostInfo > allDevices()
Returns a list of all available local Bluetooth devices.
Pairing pairingStatus(const QBluetoothAddress &address) const
Returns the current bluetooth pairing status of address, if it's unpaired, paired,...
QBluetoothAddress address() const
Returns the MAC address of this Bluetooth device.
void pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
Pairing or unpairing has completed with address.
void setHostMode(QBluetoothLocalDevice::HostMode mode)
Sets the host mode of this local Bluetooth device to mode.
iterator erase(const_iterator begin, const_iterator end)
void append(parameter_type t)
iterator insert(const Key &key, const T &value)
iterator erase(const_iterator it)
iterator find(const Key &key)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QSet< QString >::iterator it
quint64 getAddress(const unsigned char *&s, const ElfData &context)
QString qt_address(NSString *address)
void qt_test_iobluetooth_runloop()
ObjCStrongReference< IOBluetoothDevice > device_with_address(const QBluetoothAddress &address)
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE void registerQBluetoothLocalDeviceMetaType()
DBusConnection const char DBusError * error
#define qCCritical(category,...)
#define qCWarning(category,...)
#define Q_ARG(Type, data)
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
#define Q_ASSERT_X(cond, x, msg)
bool contains(const AT &t) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent