18#include <QtCore/qloggingcategory.h>
19#include <QtCore/qvariant.h>
20#include <QtCore/qglobal.h>
21#include <QtCore/qmutex.h>
23#include <Foundation/Foundation.h>
25#include <IOBluetooth/IOBluetooth.h>
58 if (serverType == ServiceInfo::UnknownProtocol)
59 qCWarning(QT_BT_DARWIN) <<
"unknown protocol";
65 unregisterServer(
this);
68bool QBluetoothServerPrivate::startListener(
quint16 realPort)
72 if (
serverType == ServiceInfo::UnknownProtocol) {
73 qCWarning(QT_BT_DARWIN) <<
"invalid protocol";
94bool QBluetoothServerPrivate::isListening()
const
96 if (
serverType == ServiceInfo::UnknownProtocol)
103void QBluetoothServerPrivate::stopListener()
108void QBluetoothServerPrivate::openNotifyRFCOMM(
void *generic)
110 auto channel =
static_cast<IOBluetoothRFCOMMChannel *
>(
generic);
116 PendingConnection newConnection(
channel, RetainPolicy::doInitialRetain);
117 pendingConnections.append(newConnection);
122void QBluetoothServerPrivate::openNotifyL2CAP(
void *generic)
124 auto channel =
static_cast<IOBluetoothL2CAPChannel *
>(
generic);
130 PendingConnection newConnection(
channel, RetainPolicy::doInitialRetain);
131 pendingConnections.append(newConnection);
136QMutex &QBluetoothServerPrivate::channelMapMutex()
142bool QBluetoothServerPrivate::channelIsBusy(
quint16 channelID)
148quint16 QBluetoothServerPrivate::findFreeChannel()
159bool QBluetoothServerPrivate::psmIsBusy(
quint16 psm)
165quint16 QBluetoothServerPrivate::findFreePSM()
168 for (
quint16 i = 1,
e = std::numeric_limits<qint16>::max();
i <
e;
i += 2) {
181 const ServiceInfo::Protocol
type =
server->serverType;
182 if (
type == ServiceInfo::RfcommProtocol) {
185 }
else if (
type == ServiceInfo::L2capProtocol) {
189 qCWarning(QT_BT_DARWIN) <<
"can not register a server "
190 "with unknown protocol type";
197 if (protocol == ServiceInfo::RfcommProtocol) {
201 }
else if (protocol == ServiceInfo::L2capProtocol) {
206 qCWarning(QT_BT_DARWIN) <<
"invalid protocol";
215 const ServiceInfo::Protocol
type =
server->serverType;
218 if (
type == ServiceInfo::RfcommProtocol) {
223 qCWarning(QT_BT_DARWIN) <<
"server is not registered";
225 }
else if (
type == ServiceInfo::L2capProtocol) {
230 qCWarning(QT_BT_DARWIN) <<
"server is not registered";
233 qCWarning(QT_BT_DARWIN) <<
"invalid protocol";
239 d_ptr->listener.reset();
251 if (
d_ptr->listener) {
252 qCWarning(QT_BT_DARWIN) <<
"already in listen mode, close server first";
258 qCWarning(QT_BT_DARWIN) <<
"device does not support Bluetooth or"
260 <<
"is not a valid local adapter";
268 qCWarning(QT_BT_DARWIN) <<
"Bluetooth device is powered off";
276 if (
type == ServiceInfo::UnknownProtocol) {
277 qCWarning(QT_BT_DARWIN) <<
"invalid protocol";
289 if (
type == ServiceInfo::RfcommProtocol) {
292 <<
"already registered";
298 <<
"already registered";
303 type == ServiceInfo::RfcommProtocol ?
port =
d_ptr->findFreeChannel()
313 qCWarning(QT_BT_DARWIN) <<
"all ports are busy";
336 return d_ptr->pendingConnections.size();
341 if (!
d_ptr->pendingConnections.size())
344 std::unique_ptr<QBluetoothSocket> newSocket = std::make_unique<QBluetoothSocket>();
345 QBluetoothServerPrivate::PendingConnection
channel(
d_ptr->pendingConnections.front());
348 d_ptr->pendingConnections.pop_front();
351 if (!
static_cast<QBluetoothSocketPrivateDarwin *
>(newSocket->d_ptr)->setRFCOMChannel(
channel.getAs<IOBluetoothRFCOMMChannel>()))
354 if (!
static_cast<QBluetoothSocketPrivateDarwin *
>(newSocket->d_ptr)->setL2CAPChannel(
channel.getAs<IOBluetoothL2CAPChannel>()))
358 return newSocket.release();
IOBluetoothL2CAPChannel * channel
IOBluetoothDevice * device
HostMode
This enum describes the most of the local Bluetooth device.
QBluetoothAddress address() const
Returns the MAC address of this Bluetooth device.
QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol serverType, QBluetoothServer *parent)
QBluetoothServiceInfo::Protocol serverType
~QBluetoothServerPrivate()
int maxPendingConnections
bool hasPendingConnections() const
Returns true if a connection is pending, otherwise false.
void setSecurityFlags(QBluetooth::SecurityFlags security)
Sets the Bluetooth security flags to security.
@ UnsupportedProtocolError
@ ServiceAlreadyRegisteredError
QBluetoothServerPrivate * d_ptr
QBluetoothSocket * nextPendingConnection()
Returns a pointer to the QBluetoothSocket for the next pending connection.
bool listen(const QBluetoothAddress &address=QBluetoothAddress(), quint16 port=0)
Start listening for incoming connections to address on port.
void close()
Closes and resets the listening socket.
void errorOccurred(QBluetoothServer::Error error)
This signal is emitted when an error occurs.
quint16 serverPort() const
Returns the server port number.
QBluetoothAddress serverAddress() const
Returns the server address.
QBluetooth::SecurityFlags securityFlags() const
Returns the Bluetooth security flags.
void newConnection()
This signal is emitted when a new connection is available.
void setMaxPendingConnections(int numConnections)
Sets the maximum number of pending connections to numConnections.
Protocol
This enum describes the socket protocol used by the service.
QSet< QString >::iterator it
void qt_test_iobluetooth_runloop()
Combined button and popup list for selecting options.
QMap< quint16, QBluetoothServerPrivate * > & busyPSMs()
QMap< quint16, QBluetoothServerPrivate * > & busyChannels()
QMap< quint16, QBluetoothServerPrivate * >::iterator ServerMapIterator
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
#define qCWarning(category,...)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLuint GLuint64EXT address
#define Q_ASSERT_X(cond, x, msg)
#define Q_UNIMPLEMENTED()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent