11#include <QtCore/QLoggingCategory>
12#include <QtCore/QSocketNotifier>
47 delete socketNotifier;
52void QBluetoothServerPrivate::_q_newConnection()
55 socketNotifier->setEnabled(
false);
60void QBluetoothServerPrivate::setSocketSecurityLevel(
61 QBluetooth::SecurityFlags requestedSecLevel,
int *errnoCode)
64 qCWarning(QT_BT_BLUEZ) <<
"Cannot set NoSecurity on server socket";
69 memset(&security, 0,
sizeof(security));
80 &security,
sizeof(security)) != 0) {
86QBluetooth::SecurityFlags QBluetoothServerPrivate::socketSecurityLevel()
const
89 memset(&security, 0,
sizeof(security));
90 socklen_t
length =
sizeof(security);
93 &security, &
length) != 0) {
98 switch (security.level) {
106 qCWarning(QT_BT_BLUEZ) <<
"Unknown server socket security level" << security.level;
115 delete d->socketNotifier;
116 d->socketNotifier =
nullptr;
126 qCWarning(QT_BT_BLUEZ) <<
"Socket already in listen mode, close server first";
132 qCWarning(QT_BT_BLUEZ) <<
"Device does not support Bluetooth or"
133 <<
address.toString() <<
"is not a valid local adapter";
143 qCWarning(QT_BT_BLUEZ) <<
"Bluetooth device is powered off";
147 int sock =
d->socket->socketDescriptor();
162 sock =
d->socket->socketDescriptor();
173 addr.rc_family = AF_BLUETOOTH;
182 if (errno == EADDRINUSE)
193 addr.l2_family = AF_BLUETOOTH;
208 d->setSocketSecurityLevel(
d->securityFlags,
nullptr);
218 if (!
d->socketNotifier) {
223 d->_q_newConnection();
235 d->maxPendingConnections = numConnections;
242 if (!
d || !
d->socketNotifier)
246 return !
d->socketNotifier->isEnabled();
260 pending = ::accept(
d->socket->socketDescriptor(),
261 reinterpret_cast<sockaddr *
>(&
addr), &
length);
265 pending = ::accept(
d->socket->socketDescriptor(),
266 reinterpret_cast<sockaddr *
>(&
addr), &
length);
270 QBluetoothSocket *newSocket = QBluetoothServerPrivate::createSocketForServer();
276 d->socketNotifier->setEnabled(
true);
280 d->socketNotifier->setEnabled(
true);
290 return d->socket->localAddress();
297 return d->socket->localPort();
306 d->securityFlags = security;
311 d->setSocketSecurityLevel(security, &errorCode);
313 qCWarning(QT_BT_BLUEZ) <<
"Failed to set socket option, closing socket for safety" << errorCode;
326 return d->securityFlags;
328 return d->socketSecurityLevel();
#define BT_SECURITY_MEDIUM
IOBluetoothDevice * device
HostMode
This enum describes the most of the local Bluetooth device.
QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol serverType, QBluetoothServer *parent)
~QBluetoothServerPrivate()
QBluetoothSocket * socket
bool hasPendingConnections() const
Returns true if a connection is pending, otherwise false.
void setSecurityFlags(QBluetooth::SecurityFlags security)
Sets the Bluetooth security flags to security.
@ ServiceAlreadyRegisteredError
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.
QBluetoothServiceInfo::Protocol serverType() const
Returns the type of the QBluetoothServer.
Protocol
This enum describes the socket protocol used by the service.
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType, SocketState socketState=SocketState::ConnectedState, OpenMode openMode=ReadWrite)
Sets the socket to use socketDescriptor with a type of socketType, which is in state socketState,...
int socketDescriptor() const
Returns the platform-specific socket descriptor, if available.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent, QPrivateSignal)
Combined button and popup list for selecting options.
static void convertAddress(const quint64 from, quint8(&to)[6])
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 * pending
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
#define qCWarning(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLenum GLuint GLenum GLsizei length
GLuint GLuint64EXT address
socketLayer bind(QHostAddress::Any, 4000)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent