Decouple QBluetoothSocket and QAbstractSocket, introduce scoped enums

QBluetoothSocket enum values were tied to QAbstractSocket enum values.
But there is no dependency, the coupling is not required. This patch
removes the coupling and changes to scoped enums for improved type
safety.

Task-number: QTBUG-62877
Change-Id: I206b1d438d74b976d3e0d32da5713d22b597dd90
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
Andreas Buhr 2021-03-02 12:36:01 +01:00
parent adc4619460
commit e009d67f4b
24 changed files with 369 additions and 366 deletions

View File

@ -115,12 +115,12 @@ void ChatClient::sendMessage(const QString &message)
void ChatClient::onSocketErrorOccurred(QBluetoothSocket::SocketError error)
{
if (error == QBluetoothSocket::NoSocketError)
if (error == QBluetoothSocket::SocketError::NoSocketError)
return;
QMetaEnum metaEnum = QMetaEnum::fromType<QBluetoothSocket::SocketError>();
QString errorString = socket->peerName() + QLatin1Char(' ')
+ metaEnum.valueToKey(error) + QLatin1String(" occurred");
+ metaEnum.valueToKey(static_cast<int>(error)) + QLatin1String(" occurred");
emit socketErrorOccurred(errorString);
}

View File

@ -59,6 +59,12 @@ QBluetoothTransferManager
- QBluetoothTransferManager, QBluetoothTransferRequest, and QBluetoothTransferReply have been removed
without replacement.
QBluetoothSocket
-------------------------
- QBluetoothSocket::SocketState and QBluetoothSocket::SocketError are now scoped enums. Usage of enum
items has to be adapted in user code.
QML Interface
-------------

View File

@ -269,7 +269,7 @@ bool QBluetoothServer::isListening() const
return d->isListening();
#endif
return d->socket->state() == QBluetoothSocket::ListeningState;
return d->socket->state() == QBluetoothSocket::SocketState::ListeningState;
}
/*!

View File

@ -157,7 +157,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
{
Q_D(QBluetoothServer);
if (d->socket->state() == QBluetoothSocket::ListeningState) {
if (d->socket->state() == QBluetoothSocket::SocketState::ListeningState) {
qCWarning(QT_BT_BLUEZ) << "Socket already in listen mode, close server first";
return false; //already listening, nothing to do
}
@ -248,7 +248,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
return false;
}
d->socket->setSocketState(QBluetoothSocket::ListeningState);
d->socket->setSocketState(QBluetoothSocket::SocketState::ListeningState);
if (!d->socketNotifier) {
d->socketNotifier = new QSocketNotifier(d->socket->socketDescriptor(),
@ -266,7 +266,7 @@ void QBluetoothServer::setMaxPendingConnections(int numConnections)
{
Q_D(QBluetoothServer);
if (d->socket->state() == QBluetoothSocket::UnconnectedState)
if (d->socket->state() == QBluetoothSocket::SocketState::UnconnectedState)
d->maxPendingConnections = numConnections;
}
@ -336,7 +336,7 @@ void QBluetoothServer::setSecurityFlags(QBluetooth::SecurityFlags security)
{
Q_D(QBluetoothServer);
if (d->socket->state() == QBluetoothSocket::UnconnectedState) {
if (d->socket->state() == QBluetoothSocket::SocketState::UnconnectedState) {
// nothing to set beyond the fact to remember the sec level for the next listen()
d->securityFlags = security;
return;
@ -357,7 +357,7 @@ QBluetooth::SecurityFlags QBluetoothServer::securityFlags() const
{
Q_D(const QBluetoothServer);
if (d->socket->state() == QBluetoothSocket::UnconnectedState)
if (d->socket->state() == QBluetoothSocket::SocketState::UnconnectedState)
return d->securityFlags;
return d->socketSecurityLevel();

View File

@ -97,7 +97,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
return false;
}
if (d->socket->state() == QBluetoothSocket::ListeningState) {
if (d->socket->state() == QBluetoothSocket::SocketState::ListeningState) {
qCWarning(QT_BT_WINDOWS) << "Socket already in listen mode, close server first";
return false;
}
@ -158,7 +158,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
return false;
}
d->socket->setSocketState(QBluetoothSocket::ListeningState);
d->socket->setSocketState(QBluetoothSocket::SocketState::ListeningState);
if (!d->socketNotifier) {
d->socketNotifier = new QSocketNotifier(d->socket->socketDescriptor(),

View File

@ -87,7 +87,7 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT)
the connected() signal when the connection is established.
If the \l {QBluetoothServiceInfo::Protocol}{Protocol} is not supported on a platform, calling
\l connectToService() will emit a \l {QBluetoothSocket::UnsupportedProtocolError}{UnsupportedProtocolError} error.
\l connectToService() will emit a \l {QBluetoothSocket::SocketError::UnsupportedProtocolError}{UnsupportedProtocolError} error.
\note QBluetoothSocket does not support synchronous read and write operations. Functions such
as \l waitForReadyRead() and \l waitForBytesWritten() are not implemented. I/O operations should be
@ -135,7 +135,7 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT)
This signal is emitted when a connection is established.
\sa QBluetoothSocket::ConnectedState, stateChanged()
\sa QBluetoothSocket::SocketState::ConnectedState, stateChanged()
*/
/*!
@ -143,7 +143,7 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT)
This signal is emitted when the socket is disconnected.
\sa QBluetoothSocket::UnconnectedState, stateChanged()
\sa QBluetoothSocket::SocketState::UnconnectedState, stateChanged()
*/
/*!
@ -439,7 +439,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const
At any point, the socket can emit error() to signal that an error occurred.
On Android and BlueZ (version 5.46 or above), a connection to a service can not be established using a port.
Calling this function will emit a \l {QBluetoothSocket::ServiceNotFoundError}{ServiceNotFoundError}.
Calling this function will emit a \l {QBluetoothSocket::SocketError::ServiceNotFoundError}{ServiceNotFoundError}.
Note that most platforms require a pairing prior to connecting to the remote device. Otherwise
the connection process may fail.
@ -567,14 +567,14 @@ void QBluetoothSocket::setSocketState(QBluetoothSocket::SocketState state)
d->state = state;
if(old != d->state)
emit stateChanged(state);
if (state == QBluetoothSocket::ConnectedState) {
if (state == QBluetoothSocket::SocketState::ConnectedState) {
emit connected();
} else if ((old == QBluetoothSocket::ConnectedState
|| old == QBluetoothSocket::ClosingState)
&& state == QBluetoothSocket::UnconnectedState) {
} else if ((old == QBluetoothSocket::SocketState::ConnectedState
|| old == QBluetoothSocket::SocketState::ClosingState)
&& state == QBluetoothSocket::SocketState::UnconnectedState) {
emit disconnected();
}
if(state == ListeningState){
if (state == SocketState::ListeningState){
#ifdef QT_OSX_BLUETOOTH
qCWarning(QT_BT) << "listening socket is not supported by IOBluetooth";
#endif
@ -616,7 +616,7 @@ void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, O
{
Q_D(QBluetoothSocketBase);
setSocketState(QBluetoothSocket::ServiceLookupState);
setSocketState(QBluetoothSocket::SocketState::ServiceLookupState);
qCDebug(QT_BT) << "Starting Bluetooth service discovery";
if(d->discoveryAgent) {
@ -678,8 +678,8 @@ void QBluetoothSocket::discoveryFinished()
if (d->discoveryAgent){
qCDebug(QT_BT) << "Didn't find any";
d->errorString = tr("Service cannot be found");
setSocketError(ServiceNotFoundError);
setSocketState(QBluetoothSocket::UnconnectedState);
setSocketError(SocketError::ServiceNotFoundError);
setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
d->discoveryAgent->deleteLater();
d->discoveryAgent = nullptr;
}
@ -687,19 +687,19 @@ void QBluetoothSocket::discoveryFinished()
void QBluetoothSocket::abort()
{
if (state() == UnconnectedState)
if (state() == SocketState::UnconnectedState)
return;
Q_D(QBluetoothSocketBase);
setOpenMode(QIODevice::NotOpen);
if (state() == ServiceLookupState && d->discoveryAgent) {
if (state() == SocketState::ServiceLookupState && d->discoveryAgent) {
d->discoveryAgent->disconnect();
d->discoveryAgent->stop();
d->discoveryAgent = nullptr;
}
setSocketState(ClosingState);
setSocketState(SocketState::ClosingState);
d->abort();
}
@ -750,7 +750,7 @@ qint64 QBluetoothSocket::writeData(const char *data, qint64 maxSize)
if (!data || maxSize <= 0) {
d_ptr->errorString = tr("Invalid data/data size");
setSocketError(QBluetoothSocket::OperationError);
setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -765,19 +765,19 @@ qint64 QBluetoothSocket::readData(char *data, qint64 maxSize)
void QBluetoothSocket::close()
{
if (state() == UnconnectedState)
if (state() == SocketState::UnconnectedState)
return;
Q_D(QBluetoothSocketBase);
setOpenMode(QIODevice::NotOpen);
if (state() == ServiceLookupState && d->discoveryAgent) {
if (state() == SocketState::ServiceLookupState && d->discoveryAgent) {
d->discoveryAgent->disconnect();
d->discoveryAgent->stop();
d->discoveryAgent = nullptr;
}
setSocketState(ClosingState);
setSocketState(SocketState::ClosingState);
d->close();
}
@ -814,23 +814,23 @@ int QBluetoothSocket::socketDescriptor() const
QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
{
switch (error) {
case QBluetoothSocket::UnknownSocketError:
debug << "QBluetoothSocket::UnknownSocketError";
case QBluetoothSocket::SocketError::UnknownSocketError:
debug << "QBluetoothSocket::SocketError::UnknownSocketError";
break;
case QBluetoothSocket::HostNotFoundError:
debug << "QBluetoothSocket::HostNotFoundError";
case QBluetoothSocket::SocketError::HostNotFoundError:
debug << "QBluetoothSocket::SocketError::HostNotFoundError";
break;
case QBluetoothSocket::RemoteHostClosedError:
debug << "QBluetoothSocket::RemoteHostClosedError";
case QBluetoothSocket::SocketError::RemoteHostClosedError:
debug << "QBluetoothSocket::SocketError::RemoteHostClosedError";
break;
case QBluetoothSocket::ServiceNotFoundError:
debug << "QBluetoothSocket::ServiceNotFoundError";
case QBluetoothSocket::SocketError::ServiceNotFoundError:
debug << "QBluetoothSocket::SocketError::ServiceNotFoundError";
break;
case QBluetoothSocket::NetworkError:
debug << "QBluetoothSocket::NetworkError";
case QBluetoothSocket::SocketError::NetworkError:
debug << "QBluetoothSocket::SocketError::NetworkError";
break;
case QBluetoothSocket::UnsupportedProtocolError:
debug << "QBluetoothSocket::UnsupportedProtocolError";
case QBluetoothSocket::SocketError::UnsupportedProtocolError:
debug << "QBluetoothSocket::SocketError::UnsupportedProtocolError";
break;
default:
debug << "QBluetoothSocket::SocketError(" << (int)error << ")";
@ -841,26 +841,26 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
QDebug operator<<(QDebug debug, QBluetoothSocket::SocketState state)
{
switch (state) {
case QBluetoothSocket::UnconnectedState:
debug << "QBluetoothSocket::UnconnectedState";
case QBluetoothSocket::SocketState::UnconnectedState:
debug << "QBluetoothSocket::SocketState::UnconnectedState";
break;
case QBluetoothSocket::ConnectingState:
debug << "QBluetoothSocket::ConnectingState";
case QBluetoothSocket::SocketState::ConnectingState:
debug << "QBluetoothSocket::SocketState::ConnectingState";
break;
case QBluetoothSocket::ConnectedState:
debug << "QBluetoothSocket::ConnectedState";
case QBluetoothSocket::SocketState::ConnectedState:
debug << "QBluetoothSocket::SocketState::ConnectedState";
break;
case QBluetoothSocket::BoundState:
debug << "QBluetoothSocket::BoundState";
case QBluetoothSocket::SocketState::BoundState:
debug << "QBluetoothSocket::SocketState::BoundState";
break;
case QBluetoothSocket::ClosingState:
debug << "QBluetoothSocket::ClosingState";
case QBluetoothSocket::SocketState::ClosingState:
debug << "QBluetoothSocket::SocketState::ClosingState";
break;
case QBluetoothSocket::ListeningState:
debug << "QBluetoothSocket::ListeningState";
case QBluetoothSocket::SocketState::ListeningState:
debug << "QBluetoothSocket::SocketState::ListeningState";
break;
case QBluetoothSocket::ServiceLookupState:
debug << "QBluetoothSocket::ServiceLookupState";
case QBluetoothSocket::SocketState::ServiceLookupState:
debug << "QBluetoothSocket::SocketState::ServiceLookupState";
break;
default:
debug << "QBluetoothSocket::SocketState(" << (int)state << ")";

View File

@ -48,7 +48,6 @@
#include <QtBluetooth/qbluetoothserviceinfo.h>
#include <QtCore/qiodevice.h>
#include <QtNetwork/qabstractsocket.h>
QT_BEGIN_NAMESPACE
@ -73,28 +72,26 @@ class Q_BLUETOOTH_EXPORT QBluetoothSocket : public QIODevice
public:
// TODO Decouple SocketState and SocketError enum values from QAbstractSocket in Qt 6
enum SocketState {
UnconnectedState = QAbstractSocket::UnconnectedState,
ServiceLookupState = QAbstractSocket::HostLookupState,
ConnectingState = QAbstractSocket::ConnectingState,
ConnectedState = QAbstractSocket::ConnectedState,
BoundState = QAbstractSocket::BoundState,
ClosingState = QAbstractSocket::ClosingState,
ListeningState = QAbstractSocket::ListeningState
enum class SocketState {
UnconnectedState,
ServiceLookupState,
ConnectingState,
ConnectedState,
BoundState,
ClosingState,
ListeningState
};
Q_ENUM(SocketState)
enum SocketError {
NoSocketError = -2,
UnknownSocketError = QAbstractSocket::UnknownSocketError, //-1
RemoteHostClosedError = QAbstractSocket::RemoteHostClosedError, //1
HostNotFoundError = QAbstractSocket::HostNotFoundError, //2
ServiceNotFoundError = QAbstractSocket::SocketAddressNotAvailableError, //9
NetworkError = QAbstractSocket::NetworkError, //7
UnsupportedProtocolError = 8,
OperationError = QAbstractSocket::OperationError //19
//New enums (independent of QAbstractSocket) should be added from 100 onwards
enum class SocketError {
NoSocketError,
UnknownSocketError,
RemoteHostClosedError,
HostNotFoundError,
ServiceNotFoundError,
NetworkError,
UnsupportedProtocolError,
OperationError
};
Q_ENUM(SocketError)
@ -139,7 +136,7 @@ public:
//void setReadBufferSize(qint64 size);
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
SocketState socketState = ConnectedState,
SocketState socketState = SocketState::ConnectedState,
OpenMode openMode = ReadWrite);
int socketDescriptor() const;

View File

@ -196,7 +196,7 @@ QBluetoothSocketPrivateAndroid::QBluetoothSocketPrivateAndroid()
QBluetoothSocketPrivateAndroid::~QBluetoothSocketPrivateAndroid()
{
if (state != QBluetoothSocket::UnconnectedState)
if (state != QBluetoothSocket::SocketState::UnconnectedState)
emit closeJavaSocket();
}
@ -367,8 +367,8 @@ bool QBluetoothSocketPrivateAndroid::fallBackReversedConnect(const QBluetoothUui
socketObject = remoteDevice = QAndroidJniObject();
errorString = QBluetoothSocket::tr("Cannot connect to %1",
"%1 = uuid").arg(reverse.toString());
q->setSocketError(QBluetoothSocket::ServiceNotFoundError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::ServiceNotFoundError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return false;
}
@ -407,13 +407,13 @@ void QBluetoothSocketPrivateAndroid::connectToServiceHelper(const QBluetoothAddr
qCDebug(QT_BT_ANDROID) << "connectToServiceHelper()" << address.toString() << uuid.toString();
q->setSocketState(QBluetoothSocket::ConnectingState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectingState);
if (!adapter.isValid()) {
qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth";
errorString = QBluetoothSocket::tr("Device does not support Bluetooth");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return;
}
@ -421,8 +421,8 @@ void QBluetoothSocketPrivateAndroid::connectToServiceHelper(const QBluetoothAddr
if (state != 12 ) { //BluetoothAdapter.STATE_ON
qCWarning(QT_BT_ANDROID) << "Bt device offline";
errorString = QBluetoothSocket::tr("Device is powered off");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return;
}
@ -436,8 +436,8 @@ void QBluetoothSocketPrivateAndroid::connectToServiceHelper(const QBluetoothAddr
env->ExceptionClear();
errorString = QBluetoothSocket::tr("Cannot access address %1", "%1 = Bt address e.g. 11:22:33:44:55:66").arg(address.toString());
q->setSocketError(QBluetoothSocket::HostNotFoundError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::HostNotFoundError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return;
}
@ -470,8 +470,8 @@ void QBluetoothSocketPrivateAndroid::connectToServiceHelper(const QBluetoothAddr
socketObject = remoteDevice = QAndroidJniObject();
errorString = QBluetoothSocket::tr("Cannot connect to %1 on %2",
"%1 = uuid, %2 = Bt address").arg(uuid.toString()).arg(address.toString());
q->setSocketError(QBluetoothSocket::ServiceNotFoundError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::ServiceNotFoundError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return;
}
@ -486,11 +486,11 @@ void QBluetoothSocketPrivateAndroid::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState
&& q->state() != QBluetoothSocket::ServiceLookupState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState
&& q->state() != QBluetoothSocket::SocketState::ServiceLookupState) {
qCWarning(QT_BT_ANDROID) << "QBluetoothSocketPrivateAndroid::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -522,7 +522,7 @@ void QBluetoothSocketPrivateAndroid::connectToService(
if (!ensureNativeSocket(protocol)) {
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
connectToServiceHelper(service.device().address(), service.serviceUuid(), openMode);
@ -534,10 +534,10 @@ void QBluetoothSocketPrivateAndroid::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_ANDROID) << "QBluetoothSocketPrivateAndroid::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -545,13 +545,13 @@ void QBluetoothSocketPrivateAndroid::connectToService(
qCWarning(QT_BT_ANDROID) << "QBluetoothSocketPrivateAndroid::connectToService cannot "
"connect with 'UnknownProtocol' (type provided by given service)";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
if (!ensureNativeSocket(q->socketType())) {
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
connectToServiceHelper(address, uuid, openMode);
@ -567,7 +567,7 @@ void QBluetoothSocketPrivateAndroid::connectToService(
Q_Q(QBluetoothSocket);
errorString = tr("Connecting to port is not supported");
q->setSocketError(QBluetoothSocket::ServiceNotFoundError);
q->setSocketError(QBluetoothSocket::SocketError::ServiceNotFoundError);
qCWarning(QT_BT_ANDROID) << "Connecting to port is not supported";
}
@ -598,8 +598,8 @@ void QBluetoothSocketPrivateAndroid::socketConnectSuccess(const QAndroidJniObjec
errorString = QBluetoothSocket::tr("Obtaining streams for service failed");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return;
}
@ -619,15 +619,15 @@ void QBluetoothSocketPrivateAndroid::socketConnectSuccess(const QAndroidJniObjec
inputThread = 0;
errorString = QBluetoothSocket::tr("Input stream thread cannot be started");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return;
}
// only unbuffered behavior supported at this stage
q->setOpenMode(QIODevice::ReadWrite|QIODevice::Unbuffered);
q->setSocketState(QBluetoothSocket::ConnectedState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectedState);
}
void QBluetoothSocketPrivateAndroid::defaultSocketConnectFailed(
@ -650,8 +650,8 @@ void QBluetoothSocketPrivateAndroid::defaultSocketConnectFailed(
if (!success) {
errorString = QBluetoothSocket::tr("Connection to service failed");
socketObject = remoteDevice = QAndroidJniObject();
q->setSocketError(QBluetoothSocket::ServiceNotFoundError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::ServiceNotFoundError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
QAndroidJniEnvironment env;
env->ExceptionClear(); // just in case
@ -674,13 +674,13 @@ void QBluetoothSocketPrivateAndroid::fallbackSocketConnectFailed(
errorString = QBluetoothSocket::tr("Connection to service failed");
socketObject = remoteDevice = QAndroidJniObject();
q->setSocketError(QBluetoothSocket::ServiceNotFoundError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::ServiceNotFoundError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
}
void QBluetoothSocketPrivateAndroid::abort()
{
if (state == QBluetoothSocket::UnconnectedState)
if (state == QBluetoothSocket::SocketState::UnconnectedState)
return;
if (socketObject.isValid()) {
@ -716,7 +716,7 @@ void QBluetoothSocketPrivateAndroid::abort()
// Unconnected (now) in advance
Q_Q(QBluetoothSocket);
q->setOpenMode(QIODevice::NotOpen);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
emit q->readChannelFinished();
}
}
@ -774,10 +774,10 @@ qint64 QBluetoothSocketPrivateAndroid::writeData(const char *data, qint64 maxSiz
{
//TODO implement buffered behavior (so far only unbuffered)
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState || !outputStream.isValid()) {
if (state != QBluetoothSocket::SocketState::ConnectedState || !outputStream.isValid()) {
qCWarning(QT_BT_ANDROID) << "Socket::writeData: " << state << outputStream.isValid();
errorString = QBluetoothSocket::tr("Cannot write while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -792,7 +792,7 @@ qint64 QBluetoothSocketPrivateAndroid::writeData(const char *data, qint64 maxSiz
env->ExceptionDescribe();
env->ExceptionClear();
errorString = QBluetoothSocket::tr("Error during write on socket.");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
return -1;
}
@ -803,10 +803,10 @@ qint64 QBluetoothSocketPrivateAndroid::writeData(const char *data, qint64 maxSiz
qint64 QBluetoothSocketPrivateAndroid::readData(char *data, qint64 maxSize)
{
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState || !inputThread) {
if (state != QBluetoothSocket::SocketState::ConnectedState || !inputThread) {
qCWarning(QT_BT_ANDROID) << "Socket::readData: " << state << inputThread ;
errorString = QBluetoothSocket::tr("Cannot read while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -819,7 +819,7 @@ void QBluetoothSocketPrivateAndroid::inputThreadError(int errorCode)
if (errorCode != -1) { //magic error which is expected and can be ignored
errorString = QBluetoothSocket::tr("Network error during read");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
}
//finally we can delete the InputStreamThread
@ -842,7 +842,7 @@ void QBluetoothSocketPrivateAndroid::inputThreadError(int errorCode)
}
q->setOpenMode(QIODevice::NotOpen);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
emit q->readChannelFinished();
}
@ -871,7 +871,7 @@ bool QBluetoothSocketPrivateAndroid::setSocketDescriptor(const QAndroidJniObject
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState || !socket.isValid())
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState || !socket.isValid())
return false;
if (!ensureNativeSocket(socketType_))
@ -898,8 +898,8 @@ bool QBluetoothSocketPrivateAndroid::setSocketDescriptor(const QAndroidJniObject
errorString = QBluetoothSocket::tr("Obtaining streams for service failed");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return false;
}

View File

@ -101,11 +101,11 @@ public:
qint64 readData(char *data, qint64 maxSize) override;
bool setSocketDescriptor(const QAndroidJniObject &socket, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override;
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override;
qint64 bytesAvailable() const override;

View File

@ -129,7 +129,7 @@ void QBluetoothSocketPrivateBluez::connectToServiceHelper(const QBluetoothAddres
if (socket == -1 && !ensureNativeSocket(socketType)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
@ -150,7 +150,7 @@ void QBluetoothSocketPrivateBluez::connectToServiceHelper(const QBluetoothAddres
qCWarning(QT_BT_BLUEZ) << "Failed to set socket option, closing socket for safety" << errno;
qCWarning(QT_BT_BLUEZ) << "Error: " << qt_error_string(errno);
errorString = QBluetoothSocket::tr("Cannot set connection security level");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
@ -199,11 +199,11 @@ void QBluetoothSocketPrivateBluez::connectToServiceHelper(const QBluetoothAddres
if (result >= 0 || (result == -1 && errno == EINPROGRESS)) {
connecting = true;
q->setSocketState(QBluetoothSocket::ConnectingState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectingState);
q->setOpenMode(openMode);
} else {
errorString = qt_error_string(errno);
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
}
}
@ -212,11 +212,11 @@ void QBluetoothSocketPrivateBluez::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState
&& q->state() != QBluetoothSocket::ServiceLookupState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState
&& q->state() != QBluetoothSocket::SocketState::ServiceLookupState) {
qCWarning(QT_BT_BLUEZ) << "QBluetoothSocketPrivateBluez::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -226,7 +226,7 @@ void QBluetoothSocketPrivateBluez::connectToService(
qCWarning(QT_BT_BLUEZ) << "QBluetoothSocket::connectToService cannot "
"connect with 'UnknownProtocol' (type provided by given service)";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
@ -235,7 +235,7 @@ void QBluetoothSocketPrivateBluez::connectToService(
if (!ensureNativeSocket(QBluetoothServiceInfo::L2capProtocol)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
connectToServiceHelper(service.device().address(), service.protocolServiceMultiplexer(),
@ -245,7 +245,7 @@ void QBluetoothSocketPrivateBluez::connectToService(
if (!ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
connectToServiceHelper(service.device().address(), service.serverChannel(), openMode);
@ -267,10 +267,10 @@ void QBluetoothSocketPrivateBluez::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_BLUEZ) << "QBluetoothSocketPrivateBluez::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -278,7 +278,7 @@ void QBluetoothSocketPrivateBluez::connectToService(
qCWarning(QT_BT_BLUEZ) << "QBluetoothSocketPrivateBluez::connectToService cannot "
"connect with 'UnknownProtocol' (type provided by given service)";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
@ -298,14 +298,14 @@ void QBluetoothSocketPrivateBluez::connectToService(
qCWarning(QT_BT_BLUEZ) << "QBluetoothSocketPrivateBluez::connectToService cannot "
"connect with 'UnknownProtocol' (type provided by given service)";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
if (q->state() != QBluetoothSocket::UnconnectedState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_BLUEZ) << "QBluetoothSocketPrivateBluez::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
connectToServiceHelper(address, port, openMode);
@ -314,17 +314,17 @@ void QBluetoothSocketPrivateBluez::connectToService(
void QBluetoothSocketPrivateBluez::_q_writeNotify()
{
Q_Q(QBluetoothSocket);
if(connecting && state == QBluetoothSocket::ConnectingState){
if (connecting && state == QBluetoothSocket::SocketState::ConnectingState){
int errorno, len;
len = sizeof(errorno);
::getsockopt(socket, SOL_SOCKET, SO_ERROR, &errorno, (socklen_t*)&len);
if(errorno) {
errorString = qt_error_string(errorno);
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
q->setSocketState(QBluetoothSocket::ConnectedState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectedState);
connectWriteNotifier->setEnabled(false);
connecting = false;
@ -348,7 +348,7 @@ void QBluetoothSocketPrivateBluez::_q_writeNotify()
default:
// every other case returns error
errorString = QBluetoothSocket::tr("Network Error: %1").arg(qt_error_string(errno)) ;
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
break;
}
} else {
@ -364,7 +364,7 @@ void QBluetoothSocketPrivateBluez::_q_writeNotify()
if (txBuffer.size()) {
connectWriteNotifier->setEnabled(true);
}
else if (state == QBluetoothSocket::ClosingState) {
else if (state == QBluetoothSocket::SocketState::ClosingState) {
connectWriteNotifier->setEnabled(false);
this->close();
}
@ -385,11 +385,11 @@ void QBluetoothSocketPrivateBluez::_q_readNotify()
errorString = qt_error_string(errsv);
qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << socket << "error:" << readFromDevice << errorString;
if (errsv == EHOSTDOWN)
q->setSocketError(QBluetoothSocket::HostNotFoundError);
q->setSocketError(QBluetoothSocket::SocketError::HostNotFoundError);
else if (errsv == ECONNRESET)
q->setSocketError(QBluetoothSocket::RemoteHostClosedError);
q->setSocketError(QBluetoothSocket::SocketError::RemoteHostClosedError);
else
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
q->disconnectFromService();
}
@ -414,7 +414,7 @@ void QBluetoothSocketPrivateBluez::abort()
Q_Q(QBluetoothSocket);
q->setOpenMode(QIODevice::NotOpen);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
emit q->readChannelFinished();
}
@ -596,9 +596,9 @@ qint64 QBluetoothSocketPrivateBluez::writeData(const char *data, qint64 maxSize)
{
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot write while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -611,7 +611,7 @@ qint64 QBluetoothSocketPrivateBluez::writeData(const char *data, qint64 maxSize)
break;
default:
errorString = QBluetoothSocket::tr("Network Error: %1").arg(qt_error_string(errno));
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
}
}
@ -641,9 +641,9 @@ qint64 QBluetoothSocketPrivateBluez::readData(char *data, qint64 maxSize)
{
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot read while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}

View File

@ -91,7 +91,7 @@ public:
qint64 readData(char *data, qint64 maxSize) override;
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override;
qint64 bytesAvailable() const override;

View File

@ -163,7 +163,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToServiceHelper(
if (profileContext) {
qCDebug(QT_BT_BLUEZ) << "Profile context still active. close socket first.";
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
@ -193,7 +193,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToServiceHelper(
profileContext = nullptr;
errorString = QBluetoothSocket::tr("Cannot export profile on DBus");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
@ -220,7 +220,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToServiceHelper(
QDBusConnection::systemBus().unregisterObject(profilePath);
errorString = QBluetoothSocket::tr("Cannot register profile on DBus");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
@ -231,7 +231,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToServiceHelper(
clearSocket();
errorString = QBluetoothSocket::tr("Cannot find remote device");
q->setSocketError(QBluetoothSocket::HostNotFoundError);
q->setSocketError(QBluetoothSocket::SocketError::HostNotFoundError);
return;
}
@ -243,7 +243,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToServiceHelper(
this, &QBluetoothSocketPrivateBluezDBus::connectToServiceReplyHandler);
q->setOpenMode(openMode);
q->setSocketState(QBluetoothSocket::ConnectingState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectingState);
}
void QBluetoothSocketPrivateBluezDBus::connectToServiceReplyHandler(
@ -258,7 +258,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToServiceReplyHandler(
clearSocket();
errorString = QBluetoothSocket::tr("Cannot connect to remote profile");
q->setSocketError(QBluetoothSocket::HostNotFoundError);
q->setSocketError(QBluetoothSocket::SocketError::HostNotFoundError);
}
watcher->deleteLater();
}
@ -280,7 +280,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToService(
qCWarning(QT_BT_BLUEZ) << "Cannot find appropriate serviceUuid"
<< "or SerialPort service class uuid";
errorString = QBluetoothSocket::tr("Missing serviceUuid or Serial Port service class uuid");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -295,7 +295,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToService(
if (address.isNull()) {
qCWarning(QT_BT_BLUEZ) << "Invalid address to remote address passed.";
errorString = QBluetoothSocket::tr("Invalid Bluetooth address passed to connectToService()");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -303,14 +303,14 @@ void QBluetoothSocketPrivateBluezDBus::connectToService(
qCWarning(QT_BT_BLUEZ) << "Cannot find appropriate serviceUuid"
<< "or SerialPort service class uuid";
errorString = QBluetoothSocket::tr("Missing serviceUuid or Serial Port service class uuid");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
if (q->state() != QBluetoothSocket::UnconnectedState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_BLUEZ) << "QBluetoothSocketPrivateBluezDBus::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -318,13 +318,13 @@ void QBluetoothSocketPrivateBluezDBus::connectToService(
qCWarning(QT_BT_BLUEZ) << "QBluetoothSocketPrivateBluezDBus::connectToService cannot "
"connect with 'UnknownProtocol' (type provided by given service)";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
if (!ensureNativeSocket(q->socketType())) {
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
connectToServiceHelper(address, uuid, openMode);
@ -340,7 +340,7 @@ void QBluetoothSocketPrivateBluezDBus::connectToService(
Q_Q(QBluetoothSocket);
errorString = tr("Connecting to port is not supported via Bluez DBus");
q->setSocketError(QBluetoothSocket::ServiceNotFoundError);
q->setSocketError(QBluetoothSocket::SocketError::ServiceNotFoundError);
qCWarning(QT_BT_BLUEZ) << "Connecting to port is not supported (Uuid required)";
}
@ -354,7 +354,7 @@ void QBluetoothSocketPrivateBluezDBus::abort()
clearSocket();
q->setOpenMode(QIODevice::NotOpen);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
emit q->readChannelFinished();
}
}
@ -462,9 +462,9 @@ qint64 QBluetoothSocketPrivateBluezDBus::writeData(const char *data, qint64 maxS
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot write while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -481,9 +481,9 @@ qint64 QBluetoothSocketPrivateBluezDBus::readData(char *data, qint64 maxSize)
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot read while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -541,7 +541,7 @@ void QBluetoothSocketPrivateBluezDBus::remoteConnected(const QDBusUnixFileDescri
bool success = localSocket->setSocketDescriptor(
descriptor, QLocalSocket::ConnectedState, q->openMode());
if (!success || !localSocket->isValid()) {
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
delete localSocket;
localSocket = nullptr;
} else {
@ -553,7 +553,7 @@ void QBluetoothSocketPrivateBluezDBus::remoteConnected(const QDBusUnixFileDescri
q, &QBluetoothSocket::bytesWritten);
socket = descriptor;
q->setSocketState(QBluetoothSocket::ConnectedState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectedState);
}
}
@ -563,12 +563,12 @@ void QBluetoothSocketPrivateBluezDBus::socketStateChanged(QLocalSocket::LocalSoc
switch (newState) {
case QLocalSocket::ClosingState:
q->setSocketState(QBluetoothSocket::ClosingState);
q->setSocketState(QBluetoothSocket::SocketState::ClosingState);
break;
case QLocalSocket::UnconnectedState:
clearSocket();
q->setOpenMode(QIODevice::NotOpen);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
emit q->readChannelFinished();
break;
default:
@ -595,7 +595,7 @@ void QBluetoothSocketPrivateBluezDBus::clearSocket()
socket = -1;
if (q->state() == QBluetoothSocket::ConnectedState) {
if (q->state() == QBluetoothSocket::SocketState::ConnectedState) {
OrgBluezDevice1Interface device(QStringLiteral("org.bluez"), remoteDevicePath,
QDBusConnection::systemBus());
auto reply = device.DisconnectProfile(profileUuid);

View File

@ -104,7 +104,7 @@ public:
qint64 readData(char *data, qint64 maxSize) override;
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override;
qint64 bytesAvailable() const override;

View File

@ -80,7 +80,7 @@ void QBluetoothSocketPrivateDummy::connectToService(
qWarning() << "Using non-functional QBluetoothSocketPrivateDummy";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
}
void QBluetoothSocketPrivateDummy::connectToService(
@ -94,7 +94,7 @@ void QBluetoothSocketPrivateDummy::connectToService(
qWarning() << "Using non-functional QBluetoothSocketPrivateDummy";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
}
void QBluetoothSocketPrivateDummy::connectToService(
@ -108,7 +108,7 @@ void QBluetoothSocketPrivateDummy::connectToService(
qWarning() << "Using non-functional QBluetoothSocketPrivateDummy";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
}
void QBluetoothSocketPrivateDummy::abort()
@ -152,9 +152,9 @@ qint64 QBluetoothSocketPrivateDummy::writeData(const char *data, qint64 maxSize)
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot write while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
return -1;
@ -167,9 +167,9 @@ qint64 QBluetoothSocketPrivateDummy::readData(char *data, qint64 maxSize)
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot read while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}

View File

@ -94,7 +94,7 @@ public:
qint64 readData(char *data, qint64 maxSize) override;
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override;
qint64 bytesAvailable() const override;

View File

@ -164,7 +164,7 @@ void QBluetoothSocketPrivate::abort()
Q_ASSERT(q_ptr);
q_ptr->setSocketState(QBluetoothSocket::UnconnectedState);
q_ptr->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
emit q_ptr->readChannelFinished();
}
@ -185,9 +185,9 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize)
Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)");
Q_ASSERT_X(maxSize > 0, Q_FUNC_INFO, "invalid data size");
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QCoreApplication::translate(SOCKET, SOC_NOWRITE);
q_ptr->setSocketError(QBluetoothSocket::OperationError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -208,9 +208,9 @@ qint64 QBluetoothSocketPrivate::readData(char *data, qint64 maxSize)
if (!data)
return 0;
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QCoreApplication::translate(SOCKET, SOC_NOREAD);
q_ptr->setSocketError(QBluetoothSocket::OperationError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -262,10 +262,10 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothServiceInfo &serv
DarwinBluetooth::qt_test_iobluetooth_runloop();
if (state!= QBluetoothSocket::UnconnectedState && state != QBluetoothSocket::ServiceLookupState) {
if (state!= QBluetoothSocket::SocketState::UnconnectedState && state != QBluetoothSocket::SocketState::ServiceLookupState) {
qCWarning(QT_BT_DARWIN) << "called on a busy socket";
errorString = QCoreApplication::translate(SOCKET, SOC_CONNECT_IN_PROGRESS);
q_ptr->setSocketError(QBluetoothSocket::OperationError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -273,7 +273,7 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothServiceInfo &serv
if (service.socketProtocol() == QBluetoothServiceInfo::UnknownProtocol) {
qCWarning(QT_BT_DARWIN) << Q_FUNC_INFO << "cannot connect with 'UnknownProtocol' type";
errorString = QCoreApplication::translate(SOCKET, SOC_NETWORK_ERROR);
q_ptr->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
@ -310,14 +310,14 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
if (socketType == QBluetoothServiceInfo::UnknownProtocol) {
qCWarning(QT_BT_DARWIN) << Q_FUNC_INFO << "cannot connect with 'UnknownProtocol' type";
errorString = QCoreApplication::translate(SOCKET, SOC_NETWORK_ERROR);
q_ptr->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
if (state != QBluetoothSocket::UnconnectedState) {
if (state != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_DARWIN) << "called on a busy socket";
errorString = QCoreApplication::translate(SOCKET, SOC_CONNECT_IN_PROGRESS);
q_ptr->setSocketError(QBluetoothSocket::OperationError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -338,16 +338,16 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
if (socketType == QBluetoothServiceInfo::UnknownProtocol) {
qCWarning(QT_BT_DARWIN) << Q_FUNC_INFO << "cannot connect with 'UnknownProtocol' type";
errorString = QCoreApplication::translate(SOCKET, SOC_NETWORK_ERROR);
q_ptr->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
Q_ASSERT_X(state == QBluetoothSocket::ServiceLookupState || state == QBluetoothSocket::UnconnectedState,
Q_ASSERT_X(state == QBluetoothSocket::SocketState::ServiceLookupState || state == QBluetoothSocket::SocketState::UnconnectedState,
Q_FUNC_INFO, "invalid state");
q_ptr->setOpenMode(mode);
socketError = QBluetoothSocket::NoSocketError;
socketError = QBluetoothSocket::SocketError::NoSocketError;
errorString.clear();
buffer.clear();
txBuffer.clear();
@ -358,7 +358,7 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
const QBluetoothSocket::SocketState oldState = state;
// To prevent other connectToService calls (from QBluetoothSocket):
// and also avoid signals in delegate callbacks.
state = QBluetoothSocket::ConnectingState;
state = QBluetoothSocket::SocketState::ConnectingState;
// We're still inside this function:
isConnecting = true;
@ -384,33 +384,33 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
// QBluetoothSocket will change the state and also emit
// a signal later if required.
if (status == kIOReturnSuccess && socketError == QBluetoothSocket::NoSocketError) {
if (state == QBluetoothSocket::ConnectedState) {
if (status == kIOReturnSuccess && socketError == QBluetoothSocket::SocketError::NoSocketError) {
if (state == QBluetoothSocket::SocketState::ConnectedState) {
// Callback 'channelOpenComplete' fired before
// connectToService finished:
state = oldState;
// Connected, setOpenMode on a QBluetoothSocket.
q_ptr->setOpenMode(openMode);
q_ptr->setSocketState(QBluetoothSocket::ConnectedState);
q_ptr->setSocketState(QBluetoothSocket::SocketState::ConnectedState);
emit q_ptr->connected();
if (buffer.size()) // We also have some data already ...
emit q_ptr->readyRead();
} else if (state == QBluetoothSocket::UnconnectedState) {
} else if (state == QBluetoothSocket::SocketState::UnconnectedState) {
// Even if we have some data, we can not read it if
// state != ConnectedState.
buffer.clear();
state = oldState;
q_ptr->setSocketError(QBluetoothSocket::UnknownSocketError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
} else {
// No error and we're connecting ...
state = oldState;
q_ptr->setSocketState(QBluetoothSocket::ConnectingState);
q_ptr->setSocketState(QBluetoothSocket::SocketState::ConnectingState);
}
} else {
state = oldState;
if (status != kIOReturnSuccess)
errorString = DarwinBluetooth::qt_error_string(status);
q_ptr->setSocketError(QBluetoothSocket::UnknownSocketError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
}
}
@ -437,14 +437,14 @@ void QBluetoothSocketPrivate::_q_writeNotify()
if (status != kIOReturnSuccess) {
errorString = QCoreApplication::translate(SOCKET, SOC_NETWORK_ERROR);
q_ptr->setSocketError(QBluetoothSocket::NetworkError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::NetworkError);
return;
} else {
emit q_ptr->bytesWritten(size);
}
}
if (!txBuffer.size() && state == QBluetoothSocket::ClosingState)
if (!txBuffer.size() && state == QBluetoothSocket::SocketState::ClosingState)
close();
}
@ -457,8 +457,8 @@ bool QBluetoothSocketPrivate::setRFCOMChannel(void *generic)
// a "socket" from such an external channel (reported by a notification).
auto channel = static_cast<IOBluetoothRFCOMMChannel *>(generic);
// It must be a newborn socket!
Q_ASSERT_X(socketError == QBluetoothSocket::NoSocketError
&& state == QBluetoothSocket::UnconnectedState && !rfcommChannel && !l2capChannel,
Q_ASSERT_X(socketError == QBluetoothSocket::SocketError::NoSocketError
&& state == QBluetoothSocket::SocketState::UnconnectedState && !rfcommChannel && !l2capChannel,
Q_FUNC_INFO, "unexpected socket state");
openMode = QIODevice::ReadWrite;
@ -466,7 +466,7 @@ bool QBluetoothSocketPrivate::setRFCOMChannel(void *generic)
RetainPolicy::noInitialRetain);
if (rfcommChannel) {// We do not handle errors, up to an external user.
q_ptr->setOpenMode(QIODevice::ReadWrite);
state = QBluetoothSocket::ConnectedState;
state = QBluetoothSocket::SocketState::ConnectedState;
socketType = QBluetoothServiceInfo::RfcommProtocol;
}
@ -483,15 +483,15 @@ bool QBluetoothSocketPrivate::setL2CAPChannel(void *generic)
auto channel = static_cast<IOBluetoothL2CAPChannel *>(generic);
// It must be a newborn socket!
Q_ASSERT_X(socketError == QBluetoothSocket::NoSocketError
&& state == QBluetoothSocket::UnconnectedState && !l2capChannel && !rfcommChannel,
Q_ASSERT_X(socketError == QBluetoothSocket::SocketError::NoSocketError
&& state == QBluetoothSocket::SocketState::UnconnectedState && !l2capChannel && !rfcommChannel,
Q_FUNC_INFO, "unexpected socket state");
openMode = QIODevice::ReadWrite;
l2capChannel.reset([[ObjCL2CAPChannel alloc] initWithDelegate:this channel:channel], RetainPolicy::noInitialRetain);
if (l2capChannel) {// We do not handle errors, up to an external user.
q_ptr->setOpenMode(QIODevice::ReadWrite);
state = QBluetoothSocket::ConnectedState;
state = QBluetoothSocket::SocketState::ConnectedState;
socketType = QBluetoothServiceInfo::L2capProtocol;
}
@ -507,9 +507,9 @@ void QBluetoothSocketPrivate::setChannelError(IOReturn errorCode)
if (isConnecting) {
// The delegate's method was called while we are still in
// connectToService ... will emit a moment later.
socketError = QBluetoothSocket::UnknownSocketError;
socketError = QBluetoothSocket::SocketError::UnknownSocketError;
} else {
q_ptr->setSocketError(QBluetoothSocket::UnknownSocketError);
q_ptr->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
}
}
@ -518,11 +518,11 @@ void QBluetoothSocketPrivate::channelOpenComplete()
Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
if (!isConnecting) {
q_ptr->setSocketState(QBluetoothSocket::ConnectedState);
q_ptr->setSocketState(QBluetoothSocket::SocketState::ConnectedState);
q_ptr->setOpenMode(openMode);
emit q_ptr->connected();
} else {
state = QBluetoothSocket::ConnectedState;
state = QBluetoothSocket::SocketState::ConnectedState;
// We are still in connectToService, it'll care
// about signals!
}
@ -536,12 +536,12 @@ void QBluetoothSocketPrivate::channelClosed()
// (thus close/abort probably will not work).
if (!isConnecting) {
q_ptr->setSocketState(QBluetoothSocket::UnconnectedState);
q_ptr->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
q_ptr->setOpenMode(QIODevice::NotOpen);
emit q_ptr->readChannelFinished();
emit q_ptr->disconnected();
} else {
state = QBluetoothSocket::UnconnectedState;
state = QBluetoothSocket::SocketState::UnconnectedState;
// We are still in connectToService and do not want
// to emit any signals yet.
}

View File

@ -80,7 +80,7 @@ bool QBluetoothSocketPrivateWin::ensureNativeSocket(QBluetoothServiceInfo::Proto
if (type != QBluetoothServiceInfo::RfcommProtocol) {
socket = int(INVALID_SOCKET);
errorString = QBluetoothSocket::tr("Unsupported protocol. Win32 only supports RFCOMM sockets");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return false;
}
@ -90,7 +90,7 @@ bool QBluetoothSocketPrivateWin::ensureNativeSocket(QBluetoothServiceInfo::Proto
const int error = ::WSAGetLastError();
qCWarning(QT_BT_WINDOWS) << "Failed to create socket:" << error << qt_error_string(error);
errorString = QBluetoothSocket::tr("Failed to create socket");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return false;
}
@ -121,7 +121,7 @@ void QBluetoothSocketPrivateWin::connectToServiceHelper(const QBluetoothAddress
break;
default:
errorString = QBluetoothSocket::tr("Socket type not handled: %1").arg(socketType);
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
@ -133,11 +133,11 @@ void QBluetoothSocketPrivateWin::connectToServiceHelper(const QBluetoothAddress
const int error = ::WSAGetLastError();
if (result != SOCKET_ERROR || error == WSAEWOULDBLOCK) {
q->setSocketState(QBluetoothSocket::ConnectingState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectingState);
q->setOpenMode(openMode);
} else {
errorString = qt_error_string(error);
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
}
}
@ -146,11 +146,11 @@ void QBluetoothSocketPrivateWin::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState
&& q->state() != QBluetoothSocket::ServiceLookupState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState
&& q->state() != QBluetoothSocket::SocketState::ServiceLookupState) {
//qCWarning(QT_BT_WINDOWS) << "QBluetoothSocketPrivateWIN::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -159,14 +159,14 @@ void QBluetoothSocketPrivateWin::connectToService(
if (service.socketProtocol() != QBluetoothServiceInfo::RfcommProtocol) {
qCWarning(QT_BT_WINDOWS) << "QBluetoothSocket::connectToService called with unsupported protocol";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
if (service.serverChannel() > 0) {
if (!ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
connectToServiceHelper(service.device().address(), service.serverChannel(), openMode);
@ -186,8 +186,8 @@ void QBluetoothSocketPrivateWin::_q_writeNotify()
{
Q_Q(QBluetoothSocket);
if (state == QBluetoothSocket::ConnectingState) {
q->setSocketState(QBluetoothSocket::ConnectedState);
if (state == QBluetoothSocket::SocketState::ConnectingState) {
q->setSocketState(QBluetoothSocket::SocketState::ConnectedState);
connectWriteNotifier->setEnabled(false);
} else {
if (txBuffer.isEmpty()) {
@ -202,7 +202,7 @@ void QBluetoothSocketPrivateWin::_q_writeNotify()
// every other case returns error
const int error = ::WSAGetLastError();
errorString = QBluetoothSocket::tr("Network Error: %1").arg(qt_error_string(error));
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
} else if (writtenBytes <= size) {
// add remainder back to buffer
const char *remainder = &buf[writtenBytes];
@ -211,12 +211,12 @@ void QBluetoothSocketPrivateWin::_q_writeNotify()
emit q->bytesWritten(writtenBytes);
} else {
errorString = QBluetoothSocket::tr("Logic error: more bytes sent than passed to ::send");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
}
if (!txBuffer.isEmpty()) {
connectWriteNotifier->setEnabled(true);
} else if (state == QBluetoothSocket::ClosingState) {
} else if (state == QBluetoothSocket::SocketState::ClosingState) {
connectWriteNotifier->setEnabled(false);
this->close();
}
@ -238,20 +238,20 @@ void QBluetoothSocketPrivateWin::_q_readNotify()
qCWarning(QT_BT_WINDOWS) << Q_FUNC_INFO << socket << "error:" << error << errorString;
switch (error) {
case WSAEHOSTDOWN:
q->setSocketError(QBluetoothSocket::HostNotFoundError);
q->setSocketError(QBluetoothSocket::SocketError::HostNotFoundError);
break;
case WSAECONNRESET:
q->setSocketError(QBluetoothSocket::RemoteHostClosedError);
q->setSocketError(QBluetoothSocket::SocketError::RemoteHostClosedError);
break;
default:
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
break;
}
q->disconnectFromService();
} else if (bytesRead == 0) {
q->setSocketError(QBluetoothSocket::RemoteHostClosedError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::RemoteHostClosedError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
} else {
const int unusedBytes = QPRIVATELINEARBUFFER_BUFFERSIZE - bytesRead;
buffer.chop(unusedBytes);
@ -266,9 +266,9 @@ void QBluetoothSocketPrivateWin::_q_exceptNotify()
const int error = ::WSAGetLastError();
errorString = qt_error_string(error);
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
if (state == QBluetoothSocket::ConnectingState)
if (state == QBluetoothSocket::SocketState::ConnectingState)
abort();
}
@ -278,10 +278,10 @@ void QBluetoothSocketPrivateWin::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_WINDOWS) << "QBluetoothSocketPrivateWin::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -289,7 +289,7 @@ void QBluetoothSocketPrivateWin::connectToService(
qCWarning(QT_BT_WINDOWS) << "QBluetoothSocketPrivateWin::connectToService cannot "
"connect with 'UnknownProtocol' (type provided by given service)";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
@ -309,14 +309,14 @@ void QBluetoothSocketPrivateWin::connectToService(
qCWarning(QT_BT_WINDOWS) << "QBluetoothSocketPrivateWin::connectToService cannot "
"connect with 'UnknownProtocol' (type provided by given service)";
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
if (q->state() != QBluetoothSocket::UnconnectedState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_WINDOWS) << "QBluetoothSocketPrivateWin::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -340,8 +340,8 @@ void QBluetoothSocketPrivateWin::abort()
Q_Q(QBluetoothSocket);
const bool wasConnected = q->state() == QBluetoothSocket::ConnectedState;
q->setSocketState(QBluetoothSocket::UnconnectedState);
const bool wasConnected = q->state() == QBluetoothSocket::SocketState::ConnectedState;
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
if (wasConnected) {
q->setOpenMode(QIODevice::NotOpen);
emit q->readChannelFinished();
@ -437,9 +437,9 @@ qint64 QBluetoothSocketPrivateWin::writeData(const char *data, qint64 maxSize)
{
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot write while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -449,7 +449,7 @@ qint64 QBluetoothSocketPrivateWin::writeData(const char *data, qint64 maxSize)
if (bytesWritten == SOCKET_ERROR) {
const int error = ::WSAGetLastError();
errorString = QBluetoothSocket::tr("Network Error: %1").arg(qt_error_string(error));
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
}
if (bytesWritten > 0)
@ -477,9 +477,9 @@ qint64 QBluetoothSocketPrivateWin::readData(char *data, qint64 maxSize)
{
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot read while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -511,7 +511,7 @@ bool QBluetoothSocketPrivateWin::setSocketDescriptor(int socketDescriptor,
return false;
q->setSocketState(socketState);
q->setOpenMode(openMode);
if (socketState == QBluetoothSocket::ConnectedState) {
if (socketState == QBluetoothSocket::SocketState::ConnectedState) {
connectWriteNotifier->setEnabled(true);
readNotifier->setEnabled(true);
exceptNotifier->setEnabled(true);
@ -545,7 +545,7 @@ bool QBluetoothSocketPrivateWin::createNotifiers()
if (result == SOCKET_ERROR) {
const int error = ::WSAGetLastError();
errorString = qt_error_string(error);
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
qCWarning(QT_BT_WINDOWS) << "Error setting socket to non-blocking" << error << errorString;
abort();
return false;
@ -575,7 +575,7 @@ bool QBluetoothSocketPrivateWin::configureSecurity()
qCWarning(QT_BT_WINDOWS) << "Failed to set socket option, closing socket for safety" << error;
qCWarning(QT_BT_WINDOWS) << "Error: " << qt_error_string(error);
errorString = QBluetoothSocket::tr("Cannot set connection security level");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return false;
}
}
@ -588,7 +588,7 @@ bool QBluetoothSocketPrivateWin::configureSecurity()
qCWarning(QT_BT_WINDOWS) << "Failed to set socket option, closing socket for safety" << error;
qCWarning(QT_BT_WINDOWS) << "Error: " << qt_error_string(error);
errorString = QBluetoothSocket::tr("Cannot set connection security level");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return false;
}
}

View File

@ -94,7 +94,7 @@ public:
qint64 readData(char *data, qint64 maxSize) override;
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override;
qint64 bytesAvailable() const override;

View File

@ -210,7 +210,7 @@ public:
// that the connection was closed. The socket cannot be closed here, as the subsequent read
// might fail then.
if (status == Error || status == Canceled) {
emit socketErrorOccured(QBluetoothSocket::NetworkError);
emit socketErrorOccured(QBluetoothSocket::SocketError::NetworkError);
return S_OK;
}
@ -218,7 +218,7 @@ public:
HRESULT hr = asyncInfo->GetResults(&buffer);
if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to get read results buffer");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
@ -226,7 +226,7 @@ public:
hr = buffer->get_Length(&bufferLength);
if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to get buffer length");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
// A zero sized buffer length signals, that the remote host closed the connection. The socket
@ -234,7 +234,7 @@ public:
// the closing of the socket won't be communicated to the caller. So only the error is set. The
// actual socket close happens inside of read.
if (!bufferLength) {
emit socketErrorOccured(QBluetoothSocket::RemoteHostClosedError);
emit socketErrorOccured(QBluetoothSocket::SocketError::RemoteHostClosedError);
return S_OK;
}
@ -242,14 +242,14 @@ public:
hr = buffer.As(&byteArrayAccess);
if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to get cast buffer");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
byte *data;
hr = byteArrayAccess->Buffer(&data);
if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to access buffer data");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
@ -265,7 +265,7 @@ public:
hr = m_socket->get_InputStream(&stream);
if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to obtain input stream");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
@ -273,26 +273,26 @@ public:
hr = buffer->get_Capacity(&readBufferLength);
if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to get buffer capacity");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
hr = buffer->put_Length(0);
if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to set buffer length");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
hr = stream->ReadAsync(buffer.Get(), readBufferLength, InputStreamOptions_Partial, &m_readOp);
if (FAILED(hr)) {
qErrnoWarning(hr, "onReadyRead(): Could not read into socket stream buffer.");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
hr = m_readOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &SocketWorker::onReadyRead).Get());
if (FAILED(hr)) {
qErrnoWarning(hr, "onReadyRead(): Failed to set socket read callback.");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
emit socketErrorOccured(QBluetoothSocket::SocketError::UnknownSocketError);
return S_OK;
}
return S_OK;
@ -359,7 +359,7 @@ void QBluetoothSocketPrivateWinRT::connectToService(Microsoft::WRL::ComPtr<IHost
if (socket == -1 && !ensureNativeSocket(socketType)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
@ -369,12 +369,12 @@ void QBluetoothSocketPrivateWinRT::connectToService(Microsoft::WRL::ComPtr<IHost
if (hr == E_ACCESSDENIED) {
qErrnoWarning(hr, "QBluetoothSocketPrivateWinRT::connectToService: Unable to connect to bluetooth socket."
"Please check your manifest capabilities.");
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return;
}
Q_ASSERT_SUCCEEDED(hr);
q->setSocketState(QBluetoothSocket::ConnectingState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectingState);
requestedOpenMode = openMode;
hr = m_connectOp->put_Completed(Callback<IAsyncActionCompletedHandler>(
this, &QBluetoothSocketPrivateWinRT::handleConnectOpFinished).Get());
@ -388,7 +388,7 @@ void QBluetoothSocketPrivateWinRT::connectToServiceHelper(const QBluetoothAddres
if (socket == -1 && !ensureNativeSocket(socketType)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
@ -410,11 +410,11 @@ void QBluetoothSocketPrivateWinRT::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState
&& q->state() != QBluetoothSocket::ServiceLookupState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState
&& q->state() != QBluetoothSocket::SocketState::ServiceLookupState) {
qCWarning(QT_BT_WINRT) << "QBluetoothSocket::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
@ -422,7 +422,7 @@ void QBluetoothSocketPrivateWinRT::connectToService(
// socketType will change in ensureNativeSocket()
if (service.socketProtocol() != QBluetoothServiceInfo::RfcommProtocol) {
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
@ -433,7 +433,7 @@ void QBluetoothSocketPrivateWinRT::connectToService(
if (!ensureNativeSocket(QBluetoothServiceInfo::L2capProtocol)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
connectToServiceHelper(service.device().address(),
@ -442,7 +442,7 @@ void QBluetoothSocketPrivateWinRT::connectToService(
Q_ASSERT(service.socketProtocol() == QBluetoothServiceInfo::RfcommProtocol);
if (!ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
HStringReference hostNameRef(reinterpret_cast<LPCWSTR>(connectionHostName.utf16()));
@ -458,7 +458,7 @@ void QBluetoothSocketPrivateWinRT::connectToService(
if (!ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
return;
}
connectToServiceHelper(service.device().address(), quint16(service.serverChannel()),
@ -480,16 +480,16 @@ void QBluetoothSocketPrivateWinRT::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_WINRT) << "QBluetoothSocketPrivateWinRT::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
if (q->socketType() != QBluetoothServiceInfo::RfcommProtocol) {
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
@ -505,16 +505,16 @@ void QBluetoothSocketPrivateWinRT::connectToService(
{
Q_Q(QBluetoothSocket);
if (q->state() != QBluetoothSocket::UnconnectedState) {
if (q->state() != QBluetoothSocket::SocketState::UnconnectedState) {
qCWarning(QT_BT_WINRT) << "QBluetoothSocketPrivateWinRT::connectToService called on busy socket";
errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return;
}
if (q->socketType() != QBluetoothServiceInfo::RfcommProtocol) {
errorString = QBluetoothSocket::tr("Socket type not supported");
q->setSocketError(QBluetoothSocket::UnsupportedProtocolError);
q->setSocketError(QBluetoothSocket::SocketError::UnsupportedProtocolError);
return;
}
@ -524,7 +524,7 @@ void QBluetoothSocketPrivateWinRT::connectToService(
void QBluetoothSocketPrivateWinRT::abort()
{
Q_Q(QBluetoothSocket);
if (state == QBluetoothSocket::UnconnectedState)
if (state == QBluetoothSocket::SocketState::UnconnectedState)
return;
disconnect(m_worker, &SocketWorker::newDataReceived,
@ -539,8 +539,8 @@ void QBluetoothSocketPrivateWinRT::abort()
socket = -1;
}
const bool wasConnected = q->state() == QBluetoothSocket::ConnectedState;
q->setSocketState(QBluetoothSocket::UnconnectedState);
const bool wasConnected = q->state() == QBluetoothSocket::SocketState::ConnectedState;
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
if (wasConnected) {
q->setOpenMode(QIODevice::NotOpen);
emit q->readChannelFinished();
@ -657,9 +657,9 @@ qint64 QBluetoothSocketPrivateWinRT::writeData(const char *data, qint64 maxSize)
{
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot write while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -672,7 +672,7 @@ qint64 QBluetoothSocketPrivateWinRT::writeData(const char *data, qint64 maxSize)
if (bytesWritten < 0) {
qCWarning(QT_BT_WINRT) << "Socket::writeData: " << state;
errorString = QBluetoothSocket::tr("Cannot read while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
}
emit q->bytesWritten(bytesWritten);
@ -683,9 +683,9 @@ qint64 QBluetoothSocketPrivateWinRT::readData(char *data, qint64 maxSize)
{
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState) {
if (state != QBluetoothSocket::SocketState::ConnectedState) {
errorString = QBluetoothSocket::tr("Cannot read while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
q->setSocketError(QBluetoothSocket::SocketError::OperationError);
return -1;
}
@ -725,7 +725,7 @@ bool QBluetoothSocketPrivateWinRT::setSocketDescriptor(ComPtr<IStreamSocket> soc
socket = qintptr(m_socketObject.Get());
m_worker->setSocket(m_socketObject);
q->setSocketState(socketState);
if (socketState == QBluetoothSocket::ConnectedState)
if (socketState == QBluetoothSocket::SocketState::ConnectedState)
m_worker->startReading();
q->setOpenMode(openMode);
return true;
@ -758,10 +758,10 @@ void QBluetoothSocketPrivateWinRT::handleError(QBluetoothSocket::SocketError err
{
Q_Q(QBluetoothSocket);
switch (error) {
case QBluetoothSocket::NetworkError:
case QBluetoothSocket::SocketError::NetworkError:
errorString = QBluetoothSocket::tr("Network error");
break;
case QBluetoothSocket::RemoteHostClosedError:
case QBluetoothSocket::SocketError::RemoteHostClosedError:
errorString = QBluetoothSocket::tr("Remote host closed connection");
break;
default:
@ -769,8 +769,8 @@ void QBluetoothSocketPrivateWinRT::handleError(QBluetoothSocket::SocketError err
}
q->setSocketError(error);
const bool wasConnected = q->state() == QBluetoothSocket::ConnectedState;
q->setSocketState(QBluetoothSocket::UnconnectedState);
const bool wasConnected = q->state() == QBluetoothSocket::SocketState::ConnectedState;
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
if (wasConnected) {
q->setOpenMode(QIODevice::NotOpen);
emit q->readChannelFinished();
@ -795,8 +795,8 @@ HRESULT QBluetoothSocketPrivateWinRT::handleConnectOpFinished(ABI::Windows::Foun
Q_Q(QBluetoothSocket);
if (status != Completed || !m_connectOp) { // Protect against a late callback
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return S_OK;
}
@ -807,26 +807,26 @@ HRESULT QBluetoothSocketPrivateWinRT::handleConnectOpFinished(ABI::Windows::Foun
// period of time, or established connection failed because connected host has failed to respond.
case HRESULT_FROM_WIN32(WSAETIMEDOUT):
errorString = QBluetoothSocket::tr("Connection timed out");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::NetworkError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return S_OK;
// A socket operation was attempted to an unreachable host.
case HRESULT_FROM_WIN32(WSAEHOSTUNREACH):
errorString = QBluetoothSocket::tr("Host not reachable");
q->setSocketError(QBluetoothSocket::HostNotFoundError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::HostNotFoundError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return S_OK;
// No connection could be made because the target machine actively refused it.
case HRESULT_FROM_WIN32(WSAECONNREFUSED):
errorString = QBluetoothSocket::tr("Host refused connection");
q->setSocketError(QBluetoothSocket::HostNotFoundError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::HostNotFoundError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return S_OK;
default:
if (FAILED(hr)) {
errorString = QBluetoothSocket::tr("Unknown socket error");
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
return S_OK;
}
}
@ -846,7 +846,7 @@ HRESULT QBluetoothSocketPrivateWinRT::handleConnectOpFinished(ABI::Windows::Foun
}
q->setOpenMode(requestedOpenMode);
q->setSocketState(QBluetoothSocket::ConnectedState);
q->setSocketState(QBluetoothSocket::SocketState::ConnectedState);
m_worker->startReading();
return S_OK;

View File

@ -110,11 +110,11 @@ public:
bool setSocketDescriptor(Microsoft::WRL::ComPtr<ABI::Windows::Networking::Sockets::IStreamSocket> socket,
QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override;
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) override;
qint64 bytesAvailable() const override;

View File

@ -118,7 +118,7 @@ public:
virtual qint64 bytesToWrite() const = 0;
virtual bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) = 0;
@ -138,12 +138,12 @@ public:
#ifdef QT_ANDROID_BLUETOOTH
virtual bool setSocketDescriptor(const QAndroidJniObject &socket, QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) = 0;
#elif defined(QT_WINRT_BLUETOOTH)
virtual bool setSocketDescriptor(Microsoft::WRL::ComPtr<ABI::Windows::Networking::Sockets::IStreamSocket> socket,
QBluetoothServiceInfo::Protocol socketType,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::ConnectedState,
QBluetoothSocket::SocketState socketState = QBluetoothSocket::SocketState::ConnectedState,
QBluetoothSocket::OpenMode openMode = QBluetoothSocket::ReadWrite) = 0;
#endif
@ -152,8 +152,8 @@ public:
QPrivateLinearBuffer txBuffer;
int socket = -1;
QBluetoothServiceInfo::Protocol socketType = QBluetoothServiceInfo::UnknownProtocol;
QBluetoothSocket::SocketState state = QBluetoothSocket::UnconnectedState;
QBluetoothSocket::SocketError socketError = QBluetoothSocket::NoSocketError;
QBluetoothSocket::SocketState state = QBluetoothSocket::SocketState::UnconnectedState;
QBluetoothSocket::SocketError socketError = QBluetoothSocket::SocketError::NoSocketError;
QSocketNotifier *readNotifier = nullptr;
QSocketNotifier *connectWriteNotifier = nullptr;
bool connecting = false;

View File

@ -764,22 +764,22 @@ void QLowEnergyControllerPrivateBluez::l2cpDisconnected()
void QLowEnergyControllerPrivateBluez::l2cpErrorChanged(QBluetoothSocket::SocketError e)
{
switch (e) {
case QBluetoothSocket::HostNotFoundError:
case QBluetoothSocket::SocketError::HostNotFoundError:
setError(QLowEnergyController::UnknownRemoteDeviceError);
qCDebug(QT_BT_BLUEZ) << "The passed remote device address cannot be found";
break;
case QBluetoothSocket::NetworkError:
case QBluetoothSocket::SocketError::NetworkError:
setError(QLowEnergyController::NetworkError);
qCDebug(QT_BT_BLUEZ) << "Network IO error while talking to LE device";
break;
case QBluetoothSocket::RemoteHostClosedError:
case QBluetoothSocket::SocketError::RemoteHostClosedError:
setError(QLowEnergyController::RemoteHostClosedError);
qCDebug(QT_BT_BLUEZ) << "Remote host closed the connection";
break;
case QBluetoothSocket::UnknownSocketError:
case QBluetoothSocket::UnsupportedProtocolError:
case QBluetoothSocket::OperationError:
case QBluetoothSocket::ServiceNotFoundError:
case QBluetoothSocket::SocketError::UnknownSocketError:
case QBluetoothSocket::SocketError::UnsupportedProtocolError:
case QBluetoothSocket::SocketError::OperationError:
case QBluetoothSocket::SocketError::ServiceNotFoundError:
default:
// these errors shouldn't happen -> as it means
// the code in this file has bugs
@ -3138,7 +3138,7 @@ void QLowEnergyControllerPrivateBluez::handleConnectionRequest()
l2cpSocket->d_ptr->lowEnergySocketType = addressType == QLowEnergyController::PublicAddress
? BDADDR_LE_PUBLIC : BDADDR_LE_RANDOM;
l2cpSocket->setSocketDescriptor(clientSocket, QBluetoothServiceInfo::L2capProtocol,
QBluetoothSocket::ConnectedState, QIODevice::ReadWrite | QIODevice::Unbuffered);
QBluetoothSocket::SocketState::ConnectedState, QIODevice::ReadWrite | QIODevice::Unbuffered);
restoreClientConfigurations();
loadSigningDataIfNecessary(RemoteSigningKey);

View File

@ -196,12 +196,12 @@ void tst_QBluetoothSocket::tst_construction()
QBluetoothSocket socket;
QCOMPARE(socket.socketType(), QBluetoothServiceInfo::UnknownProtocol);
QCOMPARE(socket.error(), QBluetoothSocket::NoSocketError);
QCOMPARE(socket.error(), QBluetoothSocket::SocketError::NoSocketError);
QCOMPARE(socket.errorString(), QString());
QCOMPARE(socket.peerAddress(), QBluetoothAddress());
QCOMPARE(socket.peerName(), QString());
QCOMPARE(socket.peerPort(), quint16(0));
QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState);
QCOMPARE(socket.socketDescriptor(), -1);
QCOMPARE(socket.bytesAvailable(), 0);
QCOMPARE(socket.bytesToWrite(), 0);
@ -240,7 +240,7 @@ void tst_QBluetoothSocket::tst_serviceConnection()
QSignalSpy stateSpy(&socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)));
QCOMPARE(socket.socketType(), QBluetoothServiceInfo::UnknownProtocol);
QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState);
/* Connection */
QSignalSpy connectedSpy(&socket, SIGNAL(connected()));
@ -254,8 +254,8 @@ void tst_QBluetoothSocket::tst_serviceConnection()
socket.connectToService(remoteServiceInfo);
QCOMPARE(stateSpy.count(), 1);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::ConnectingState);
QCOMPARE(socket.state(), QBluetoothSocket::ConnectingState);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::SocketState::ConnectingState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::ConnectingState);
stateSpy.clear();
@ -271,8 +271,8 @@ void tst_QBluetoothSocket::tst_serviceConnection()
}
QCOMPARE(connectedSpy.count(), 1);
QCOMPARE(stateSpy.count(), 1);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::ConnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::ConnectedState);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::SocketState::ConnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::ConnectedState);
QCOMPARE(socket.isWritable(), true);
QCOMPARE(socket.isReadable(), true);
@ -296,7 +296,7 @@ void tst_QBluetoothSocket::tst_serviceConnection()
QCOMPARE(socket.openMode(), QIODevice::NotOpen);
QVERIFY(stateSpy.count() >= 1);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::ClosingState);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::SocketState::ClosingState);
int disconnectTime = MaxConnectTime;
while (disconnectedSpy.count() == 0 && disconnectTime > 0) {
@ -306,7 +306,7 @@ void tst_QBluetoothSocket::tst_serviceConnection()
QCOMPARE(disconnectedSpy.count(), 1);
QCOMPARE(stateSpy.count(), 1);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::UnconnectedState);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::SocketState::UnconnectedState);
// The remote service needs time to close the connection and resume listening
QTest::qSleep(100);
@ -337,7 +337,7 @@ void tst_QBluetoothSocket::tst_clientCommunication()
QSignalSpy stateSpy(&socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)));
QCOMPARE(socket.socketType(), QBluetoothServiceInfo::RfcommProtocol);
QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState);
/* Connection */
QSignalSpy connectedSpy(&socket, SIGNAL(connected()));
@ -349,8 +349,8 @@ void tst_QBluetoothSocket::tst_clientCommunication()
socket.connectToService(remoteServiceInfo);
QCOMPARE(stateSpy.count(), 1);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::ConnectingState);
QCOMPARE(socket.state(), QBluetoothSocket::ConnectingState);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::SocketState::ConnectingState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::ConnectingState);
stateSpy.clear();
@ -366,8 +366,8 @@ void tst_QBluetoothSocket::tst_clientCommunication()
QCOMPARE(connectedSpy.count(), 1);
QCOMPARE(stateSpy.count(), 1);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::ConnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::ConnectedState);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::SocketState::ConnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::ConnectedState);
stateSpy.clear();
@ -479,8 +479,8 @@ void tst_QBluetoothSocket::tst_clientCommunication()
QCOMPARE(disconnectedSpy.count(), 1);
QCOMPARE(stateSpy.count(), 2);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::ClosingState);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::UnconnectedState);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::SocketState::ClosingState);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::SocketState::UnconnectedState);
// The remote service needs time to close the connection and resume listening
QTest::qSleep(100);
@ -493,7 +493,7 @@ void tst_QBluetoothSocket::tst_error()
QCOMPARE(errorSpy.count(), 0);
const QBluetoothSocket::SocketError e = socket.error();
QVERIFY(e == QBluetoothSocket::NoSocketError);
QVERIFY(e == QBluetoothSocket::SocketError::NoSocketError);
QVERIFY(socket.errorString() == QString());
}
@ -531,7 +531,7 @@ void tst_QBluetoothSocket::tst_unsupportedProtocolError()
// UnsupportedProtocolError.
QBluetoothSocket socket;
QCOMPARE(socket.socketType(), QBluetoothServiceInfo::UnknownProtocol);
QVERIFY(socket.error() == QBluetoothSocket::NoSocketError);
QVERIFY(socket.error() == QBluetoothSocket::SocketError::NoSocketError);
QVERIFY(socket.errorString() == QString());
QSignalSpy errorSpy(&socket, SIGNAL(error(QBluetoothSocket::SocketError)));
@ -541,9 +541,9 @@ void tst_QBluetoothSocket::tst_unsupportedProtocolError()
socket.connectToService(dummyServiceInfo, QIODevice::ReadWrite);
QTRY_COMPARE_WITH_TIMEOUT(errorSpy.size(), 1, 1000);
QCOMPARE(errorSpy.size(), 1);
QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::UnsupportedProtocolError));
QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::SocketError::UnsupportedProtocolError));
QVERIFY(socket.errorString().size() != 0);
QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState);
errorSpy.clear();
@ -551,9 +551,9 @@ void tst_QBluetoothSocket::tst_unsupportedProtocolError()
socket.connectToService(QBluetoothAddress(), 1, QIODevice::ReadWrite);
QTRY_COMPARE_WITH_TIMEOUT(errorSpy.size(), 1, 1000);
QCOMPARE(errorSpy.size(), 1);
QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::UnsupportedProtocolError));
QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::SocketError::UnsupportedProtocolError));
QVERIFY(socket.errorString().size() != 0);
QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState);
errorSpy.clear();
@ -561,9 +561,9 @@ void tst_QBluetoothSocket::tst_unsupportedProtocolError()
socket.connectToService(QBluetoothAddress(), QBluetoothUuid(), QIODevice::ReadWrite);
QTRY_COMPARE_WITH_TIMEOUT(errorSpy.size(), 1, 1000);
QCOMPARE(errorSpy.size(), 1);
QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::UnsupportedProtocolError));
QCOMPARE(errorSpy.takeFirst().at(0).toInt(), int(QBluetoothSocket::SocketError::UnsupportedProtocolError));
QVERIFY(socket.errorString().size() != 0);
QCOMPARE(socket.state(), QBluetoothSocket::UnconnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::SocketState::UnconnectedState);
}
QTEST_MAIN(tst_QBluetoothSocket)

View File

@ -514,13 +514,13 @@ void BtLocalDevice::dumpSocketInformation()
qDebug() << "socket bytesAvailable()" << socket->bytesAvailable();
QString tmp;
switch (socket->error()) {
case QBluetoothSocket::NoSocketError: tmp += "NoSocketError"; break;
case QBluetoothSocket::UnknownSocketError: tmp += "UnknownSocketError"; break;
case QBluetoothSocket::HostNotFoundError: tmp += "HostNotFoundError"; break;
case QBluetoothSocket::ServiceNotFoundError: tmp += "ServiceNotFound"; break;
case QBluetoothSocket::NetworkError: tmp += "NetworkError"; break;
//case QBluetoothSocket::OperationError: tmp+= "OperationError"; break;
case QBluetoothSocket::UnsupportedProtocolError: tmp += "UnsupportedProtocolError"; break;
case QBluetoothSocket::SocketError::NoSocketError: tmp += "NoSocketError"; break;
case QBluetoothSocket::SocketError::UnknownSocketError: tmp += "UnknownSocketError"; break;
case QBluetoothSocket::SocketError::HostNotFoundError: tmp += "HostNotFoundError"; break;
case QBluetoothSocket::SocketError::ServiceNotFoundError: tmp += "ServiceNotFound"; break;
case QBluetoothSocket::SocketError::NetworkError: tmp += "NetworkError"; break;
//case QBluetoothSocket::SocketError::OperationError: tmp+= "OperationError"; break;
case QBluetoothSocket::SocketError::UnsupportedProtocolError: tmp += "UnsupportedProtocolError"; break;
default: tmp+= "Undefined"; break;
}
@ -533,7 +533,7 @@ void BtLocalDevice::dumpSocketInformation()
void BtLocalDevice::writeData()
{
const char * testData = "ABCABC\n";
if (socket && socket->state() == QBluetoothSocket::ConnectedState) {
if (socket && socket->state() == QBluetoothSocket::SocketState::ConnectedState) {
socket->write(testData);
}
for (QBluetoothSocket* client : serverSockets) {
@ -756,13 +756,13 @@ void BtLocalDevice::dumpServerInformation()
qDebug() << "Pending bytes: " << client->bytesAvailable();
QString tmp;
switch (client->error()) {
case QBluetoothSocket::NoSocketError: tmp += "NoSocketError"; break;
case QBluetoothSocket::UnknownSocketError: tmp += "UnknownSocketError"; break;
case QBluetoothSocket::HostNotFoundError: tmp += "HostNotFoundError"; break;
case QBluetoothSocket::ServiceNotFoundError: tmp += "ServiceNotFound"; break;
case QBluetoothSocket::NetworkError: tmp += "NetworkError"; break;
case QBluetoothSocket::UnsupportedProtocolError: tmp += "UnsupportedProtocolError"; break;
//case QBluetoothSocket::OperationError: tmp+= "OperationError"; break;
case QBluetoothSocket::SocketError::NoSocketError: tmp += "NoSocketError"; break;
case QBluetoothSocket::SocketError::UnknownSocketError: tmp += "UnknownSocketError"; break;
case QBluetoothSocket::SocketError::HostNotFoundError: tmp += "HostNotFoundError"; break;
case QBluetoothSocket::SocketError::ServiceNotFoundError: tmp += "ServiceNotFound"; break;
case QBluetoothSocket::SocketError::NetworkError: tmp += "NetworkError"; break;
case QBluetoothSocket::SocketError::UnsupportedProtocolError: tmp += "UnsupportedProtocolError"; break;
//case QBluetoothSocket::SocketError::OperationError: tmp+= "OperationError"; break;
default: tmp += QString::number(static_cast<int>(client->error())); break;
}