summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-02-03 09:33:29 +0100
committerAlex Blasche <alexander.blasche@digia.com>2014-02-03 09:33:29 +0100
commit5685d3b02fb448e74f319de0053e97fff265483a (patch)
treedfd3f315bdbf633f6b3210aa07eea3ff51d56c89 /src
parent0f700c166e7369230763a4c6dbc10e86944669a1 (diff)
parent7d4f4c3083d565af00f1564ae80e5cbfbc338bd5 (diff)
Merge remote-tracking branch 'gerrit/stable' into dev
Conflicts: src/bluetooth/qbluetoothservicediscoveryagent.cpp Change-Id: I52831fc8c69062e90c003836fd9402f19d6a0ba5
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp3
-rw-r--r--src/bluetooth/qbluetoothserver_bluez.cpp8
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp53
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp61
-rw-r--r--src/bluetooth/qbluetoothsocket.cpp26
-rw-r--r--src/bluetooth/qbluetoothsocket_bluez.cpp42
-rw-r--r--src/bluetooth/qbluetoothsocket_p.h2
-rw-r--r--src/bluetooth/qbluetoothsocket_qnx.cpp25
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp5
-rw-r--r--src/nfc/qqmlndefrecord.cpp1
10 files changed, 138 insertions, 88 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index 40ee7024..69f09130 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -65,6 +65,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con
QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate()
{
delete manager;
+ delete adapter;
}
bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const
@@ -115,6 +116,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
propertiesReply.waitForFinished();
if(propertiesReply.isError()) {
errorString = propertiesReply.error().message();
+ delete adapter;
+ adapter = 0;
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "ERROR: " << errorString;
lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
Q_Q(QBluetoothDeviceDiscoveryAgent);
diff --git a/src/bluetooth/qbluetoothserver_bluez.cpp b/src/bluetooth/qbluetoothserver_bluez.cpp
index cf50d140..0b504d9a 100644
--- a/src/bluetooth/qbluetoothserver_bluez.cpp
+++ b/src/bluetooth/qbluetoothserver_bluez.cpp
@@ -257,7 +257,7 @@ void QBluetoothServer::setSecurityFlags(QBluetooth::SecurityFlags security)
if (setsockopt(d->socket->socketDescriptor(), SOL_RFCOMM, RFCOMM_LM, &lm, sizeof(lm)) < 0){
qCWarning(QT_BT_BLUEZ) << "Failed to set socket option, closing socket for safety" << errno;
- qCWarning(QT_BT_BLUEZ) << "Error: " << strerror(errno);
+ qCWarning(QT_BT_BLUEZ) << "Error: " << qt_error_string(errno);
d->m_lastError = InputOutputError;
emit error(d->m_lastError);
d->socket->close();
@@ -274,7 +274,7 @@ void QBluetoothServer::setSecurityFlags(QBluetooth::SecurityFlags security)
if (setsockopt(d->socket->socketDescriptor(), SOL_L2CAP, L2CAP_LM, &lm, sizeof(lm)) < 0){
qCWarning(QT_BT_BLUEZ) << "Failed to set socket option, closing socket for safety" << errno;
- qCWarning(QT_BT_BLUEZ) << "Error: " << strerror(errno);
+ qCWarning(QT_BT_BLUEZ) << "Error: " << qt_error_string(errno);
d->m_lastError = InputOutputError;
emit error(d->m_lastError);
d->socket->close();
@@ -293,7 +293,7 @@ QBluetooth::SecurityFlags QBluetoothServer::securityFlags() const
if (d->serverType == QBluetoothServiceInfo::RfcommProtocol) {
if (getsockopt(d->socket->socketDescriptor(), SOL_RFCOMM, RFCOMM_LM, &lm, (socklen_t *)&len) < 0) {
- qCWarning(QT_BT_BLUEZ) << "Failed to get security flags" << strerror(errno);
+ qCWarning(QT_BT_BLUEZ) << "Failed to get security flags" << qt_error_string(errno);
return QBluetooth::NoSecurity;
}
@@ -310,7 +310,7 @@ QBluetooth::SecurityFlags QBluetoothServer::securityFlags() const
security |= QBluetooth::Authorization;
} else {
if (getsockopt(d->socket->socketDescriptor(), SOL_L2CAP, L2CAP_LM, &lm, (socklen_t *)&len) < 0) {
- qCWarning(QT_BT_BLUEZ) << "Failed to get security flags" << strerror(errno);
+ qCWarning(QT_BT_BLUEZ) << "Failed to get security flags" << qt_error_string(errno);
return QBluetooth::NoSecurity;
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index 4ebe24b4..4df6a4ea 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -172,6 +172,13 @@ QBluetoothServiceDiscoveryAgent::~QBluetoothServiceDiscoveryAgent()
/*!
Returns the list of all discovered services.
+
+ This list of services accumulates newly discovered services from multiple calls
+ to \l start(). Unless \l clear() is called the list cannot decrease in size. This implies
+ that if a remote Bluetooth device moves out of range in between two subsequent calls
+ to \l start() the list may contain stale entries.
+
+ \sa clear()
*/
QList<QBluetoothServiceInfo> QBluetoothServiceDiscoveryAgent::discoveredServices() const
{
@@ -222,10 +229,15 @@ QList<QBluetoothUuid> QBluetoothServiceDiscoveryAgent::uuidFilter() const
}
/*!
- Sets remote device address to \a address. If \a address is null, services will be discovered
- on all contactable Bluetooth devices. A new remote address can only be set while there is
- no service discovery in progress; otherwise this function returns false.
+ Sets the remote device address to \a address. If \a address is default constructed,
+ services will be discovered on all contactable Bluetooth devices. A new remote
+ address can only be set while there is no service discovery in progress; otherwise
+ this function returns false.
+
+ On some platforms such as Blackberry the service discovery might lead to pairing requests.
+ Therefore it is not recommended to do service discoveries on all devices.
+ \sa remoteAddress()
*/
bool QBluetoothServiceDiscoveryAgent::setRemoteAddress(const QBluetoothAddress &address)
{
@@ -239,9 +251,10 @@ bool QBluetoothServiceDiscoveryAgent::setRemoteAddress(const QBluetoothAddress &
}
/*!
- Returns the remote device address. If setRemoteAddress is not called, the function
- will return default QBluetoothAddress.
+ Returns the remote device address. If \l setRemoteAddress() is not called, the function
+ will return a default constructed \l QBluetoothAddress.
+ \sa setRemoteAddress()
*/
QBluetoothAddress QBluetoothServiceDiscoveryAgent::remoteAddress() const
{
@@ -275,13 +288,14 @@ void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode)
}
/*!
- Stops service discovery.
+ Stops the service discovery process. The \l canceled() signal will be emitted once
+ the search has stopped.
*/
void QBluetoothServiceDiscoveryAgent::stop()
{
Q_D(QBluetoothServiceDiscoveryAgent);
- if (d->error == InvalidBluetoothAdapterError)
+ if (d->error == InvalidBluetoothAdapterError || !isActive())
return;
switch (d->discoveryState()) {
@@ -298,19 +312,27 @@ void QBluetoothServiceDiscoveryAgent::stop()
}
/*!
- Clears the results of a previous service discovery.
+ Clears the results of previous service discoveries and resets \l uuidFilter().
+ This function does nothing during an ongoing service discovery (see \l isActive()).
+
+ \sa discoveredServices()
*/
void QBluetoothServiceDiscoveryAgent::clear()
{
Q_D(QBluetoothServiceDiscoveryAgent);
+ //don't clear the list while the search is ongoing
+ if (isActive())
+ return;
+
d->discoveredDevices.clear();
d->discoveredServices.clear();
d->uuidFilter.clear();
}
/*!
- Returns true if service discovery is currently active, otherwise returns false.
+ Returns \c true if the service discovery is currently active; otherwise returns \c false.
+ An active discovery can be stopped by calling \l stop().
*/
bool QBluetoothServiceDiscoveryAgent::isActive() const
{
@@ -320,9 +342,9 @@ bool QBluetoothServiceDiscoveryAgent::isActive() const
}
/*!
- Returns the type of error that last occurred. If service discovery is done
- on a signle address it will return errors that occured while trying to discover
- services on that device. If the alternate constructor is used and devices are
+ Returns the type of error that last occurred. If the service discovery is done
+ for a single \l remoteAddress() it will return errors that occurred while trying to discover
+ services on that device. If the \l remoteAddress() is not set and devices are
discovered by a scan, errors during service discovery on individual
devices are not saved and no signals are emitted. In this case, errors are
fairly normal as some devices may not respond to discovery or
@@ -338,8 +360,8 @@ QBluetoothServiceDiscoveryAgent::Error QBluetoothServiceDiscoveryAgent::error()
}
/*!
- Returns a human-readable description of the last error that occurred during
- service discovery on a single device.
+ Returns a human-readable description of the last error that occurred during the
+ service discovery.
*/
QString QBluetoothServiceDiscoveryAgent::errorString() const
{
@@ -350,7 +372,8 @@ QString QBluetoothServiceDiscoveryAgent::errorString() const
/*!
\fn QBluetoothServiceDiscoveryAgent::canceled()
- Signals the cancellation of the service discovery.
+
+ This signal is triggered when the service discovery was canceled via a call to \l stop().
*/
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index 0d50628c..7cb53253 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -60,12 +60,16 @@ QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(c
{
qRegisterMetaType<ServiceMap>("ServiceMap");
qDBusRegisterMetaType<ServiceMap>();
+
+ manager = new OrgBluezManagerInterface(QLatin1String("org.bluez"), QLatin1String("/"),
+ QDBusConnection::systemBus());
}
QBluetoothServiceDiscoveryAgentPrivate::~QBluetoothServiceDiscoveryAgentPrivate()
{
delete device;
delete manager;
+ delete adapter;
}
void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &address)
@@ -74,8 +78,6 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
qCDebug(QT_BT_BLUEZ) << "Full discovery on: " << address.toString();
- manager = new OrgBluezManagerInterface(QLatin1String("org.bluez"), QLatin1String("/"),
- QDBusConnection::systemBus());
QDBusPendingReply<QDBusObjectPath> reply;
if (m_deviceAdapterAddress.isNull())
reply = manager->DefaultAdapter();
@@ -106,21 +108,33 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
void QBluetoothServiceDiscoveryAgentPrivate::stop()
{
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "Stop called";
- if(device){
+ if (device) {
+ //we are waiting for _q_discoveredServices() slot to be called
+ // adapter is already 0
QDBusPendingReply<> reply = device->CancelDiscovery();
reply.waitForFinished();
- discoveredDevices.clear();
- setDiscoveryState(Inactive);
- Q_Q(QBluetoothServiceDiscoveryAgent);
- emit q->canceled();
-
- qCDebug(QT_BT_BLUEZ) << "Stop done";
+ device->deleteLater();
+ device = 0;
+ Q_ASSERT(!adapter);
+ } else if (adapter) {
+ //we are waiting for _q_createdDevice() slot to be called
+ adapter->deleteLater();
+ adapter = 0;
+ Q_ASSERT(!device);
}
+
+ discoveredDevices.clear();
+ setDiscoveryState(Inactive);
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+ emit q->canceled();
}
void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWatcher *watcher)
{
+ if (!adapter)
+ return;
+
Q_Q(QBluetoothServiceDiscoveryAgent);
const QBluetoothAddress &address = watcher->property("_q_BTaddress").value<QBluetoothAddress>();
@@ -130,6 +144,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
QDBusPendingReply<QDBusObjectPath> deviceObjectPath = *watcher;
if (deviceObjectPath.isError()) {
if (deviceObjectPath.error().name() != QLatin1String("org.bluez.Error.AlreadyExists")) {
+ delete adapter;
+ adapter = 0;
_q_serviceDiscoveryFinished();
qCDebug(QT_BT_BLUEZ) << "Create device failed Error: " << error << deviceObjectPath.error().name();
return;
@@ -138,6 +154,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
deviceObjectPath = adapter->FindDevice(address.toString());
deviceObjectPath.waitForFinished();
if (deviceObjectPath.isError()) {
+ delete adapter;
+ adapter = 0;
if (singleDevice) {
error = QBluetoothServiceDiscoveryAgent::InputOutputError;
errorString = QBluetoothServiceDiscoveryAgent::tr("Unable to access device");
@@ -152,30 +170,27 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
device = new OrgBluezDeviceInterface(QLatin1String("org.bluez"),
deviceObjectPath.value().path(),
QDBusConnection::systemBus());
-
- QDBusPendingReply<QVariantMap> deviceReply = device->GetProperties();
- deviceReply.waitForFinished();
- if (deviceReply.isError()) {
- qCDebug(QT_BT_BLUEZ) << "GetProperties error: " << error << deviceObjectPath.error().name();
- return;
- }
- QVariantMap v = deviceReply.value();
- QStringList device_uuids = v.value(QLatin1String("UUIDs")).toStringList();
+ delete adapter;
+ adapter = 0;
QString pattern;
foreach (const QBluetoothUuid &uuid, uuidFilter)
pattern += uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}')) + QLatin1Char(' ');
- qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "Discover: " << pattern.trimmed();
- QDBusPendingReply<ServiceMap> discoverReply = device->DiscoverServices(pattern.trimmed());
+ pattern = pattern.trimmed();
+ qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "Discover restrictions:" << pattern;
+
+ QDBusPendingReply<ServiceMap> discoverReply = device->DiscoverServices(pattern);
watcher = new QDBusPendingCallWatcher(discoverReply, q);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
q, SLOT(_q_discoveredServices(QDBusPendingCallWatcher*)));
-
}
void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingCallWatcher *watcher)
{
+ if (!device)
+ return;
+
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO;
QDBusPendingReply<ServiceMap> reply = *watcher;
@@ -188,6 +203,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC
errorString = reply.error().message();
emit q->error(error);
}
+ delete device;
+ device = 0;
_q_serviceDiscoveryFinished();
return;
}
@@ -234,6 +251,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC
}
watcher->deleteLater();
+ delete device;
+ device = 0;
_q_serviceDiscoveryFinished();
}
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp
index 4b3cdd21..2f2660d0 100644
--- a/src/bluetooth/qbluetoothsocket.cpp
+++ b/src/bluetooth/qbluetoothsocket.cpp
@@ -169,19 +169,30 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_QNX)
\fn QString QBluetoothSocket::localName() const
Returns the name of the local device.
+
+ Although some platforms may differ the socket must generally be connected to guarantee
+ the return of a valid name. In particular, this is true when dealing with platforms
+ that support multiple local Bluetooth adapters.
*/
/*!
\fn QBluetoothAddress QBluetoothSocket::localAddress() const
Returns the address of the local device.
+
+ Although some platforms may differ the socket must generally be connected to guarantee
+ the return of a valid address. In particular, this is true when dealing with platforms
+ that support multiple local Bluetooth adapters.
*/
/*!
\fn quint16 QBluetoothSocket::localPort() const
Returns the port number of the local socket if available, otherwise returns 0.
- On BlackBerry, this feature is not supported and returns 0.
+ Although some platforms may differ the socket must generally be connected to guarantee
+ the return of a valid port number.
+
+ On BlackBerry, this feature is not supported at all and the function always returns 0.
*/
/*!
@@ -308,13 +319,15 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op
#else
if (service.protocolServiceMultiplexer() > 0) {
if (!d->ensureNativeSocket(QBluetoothServiceInfo::L2capProtocol)) {
- emit error(UnknownSocketError);
+ d->errorString = tr("Unknown socket error");
+ setSocketError(UnknownSocketError);
return;
}
d->connectToService(service.device().address(), service.protocolServiceMultiplexer(), openMode);
} else if (service.serverChannel() > 0) {
if (!d->ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) {
- emit error(UnknownSocketError);
+ d->errorString = tr("Unknown socket error");
+ setSocketError(UnknownSocketError);
return;
}
d->connectToService(service.device().address(), service.serverChannel(), openMode);
@@ -488,10 +501,12 @@ void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, O
qCDebug(QT_BT) << "Starting discovery";
if(d->discoveryAgent) {
+ d->discoveryAgent->stop();
delete d->discoveryAgent;
}
- d->discoveryAgent = new QBluetoothServiceDiscoveryAgent(service.device().address(),this);
+ d->discoveryAgent = new QBluetoothServiceDiscoveryAgent(this);
+ d->discoveryAgent->setRemoteAddress(service.device().address());
//qDebug() << "Got agent";
@@ -531,7 +546,8 @@ void QBluetoothSocket::discoveryFinished()
Q_D(QBluetoothSocket);
if (d->discoveryAgent){
qCDebug(QT_BT) << "Didn't find any";
- emit error(QBluetoothSocket::ServiceNotFoundError);
+ d->errorString = tr("Service cannot be found");
+ setSocketError(ServiceNotFoundError);
d->discoveryAgent->deleteLater();
d->discoveryAgent = 0;
}
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp
index 58662d5b..7b1046c4 100644
--- a/src/bluetooth/qbluetoothsocket_bluez.cpp
+++ b/src/bluetooth/qbluetoothsocket_bluez.cpp
@@ -67,6 +67,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
: socket(-1),
socketType(QBluetoothServiceInfo::UnknownProtocol),
state(QBluetoothSocket::UnconnectedState),
+ socketError(QBluetoothSocket::NoSocketError),
readNotifier(0),
connectWriteNotifier(0),
connecting(false),
@@ -165,7 +166,7 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
connecting = true;
q->setSocketState(QBluetoothSocket::ConnectingState);
} else {
- errorString = QString::fromLocal8Bit(strerror(errno));
+ errorString = qt_error_string(errno);
q->setSocketError(QBluetoothSocket::UnknownSocketError);
}
}
@@ -178,8 +179,8 @@ void QBluetoothSocketPrivate::_q_writeNotify()
len = sizeof(errorno);
::getsockopt(socket, SOL_SOCKET, SO_ERROR, &errorno, (socklen_t*)&len);
if(errorno) {
- errorString = QString::fromLocal8Bit(strerror(errorno));
- emit q->error(QBluetoothSocket::UnknownSocketError);
+ errorString = qt_error_string(errorno);
+ q->setSocketError(QBluetoothSocket::UnknownSocketError);
return;
}
@@ -196,13 +197,12 @@ void QBluetoothSocketPrivate::_q_writeNotify()
}
char buf[1024];
- Q_Q(QBluetoothSocket);
int size = txBuffer.read(buf, 1024);
if (::write(socket, buf, size) != size) {
- socketError = QBluetoothSocket::NetworkError;
- emit q->error(socketError);
+ errorString = QBluetoothSocket::tr("Network error");
+ q->setSocketError(QBluetoothSocket::NetworkError);
}
else {
emit q->bytesWritten(size);
@@ -230,12 +230,12 @@ void QBluetoothSocketPrivate::_q_readNotify()
int errsv = errno;
readNotifier->setEnabled(false);
connectWriteNotifier->setEnabled(false);
- errorString = QString::fromLocal8Bit(strerror(errsv));
+ errorString = qt_error_string(errsv);
qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << socket << "error:" << readFromDevice << errorString;
if(errsv == EHOSTDOWN)
- emit q->error(QBluetoothSocket::HostNotFoundError);
+ q->setSocketError(QBluetoothSocket::HostNotFoundError);
else
- emit q->error(QBluetoothSocket::UnknownSocketError);
+ q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->disconnectFromService();
q->setSocketState(QBluetoothSocket::UnconnectedState);
@@ -258,6 +258,7 @@ void QBluetoothSocketPrivate::abort()
// we don't call disconnectFromService or
// QBluetoothSocket::close
QT_CLOSE(socket);
+ socket = -1;
Q_Q(QBluetoothSocket);
emit q->disconnected();
@@ -265,9 +266,6 @@ void QBluetoothSocketPrivate::abort()
QString QBluetoothSocketPrivate::localName() const
{
- if (!m_localName.isEmpty())
- return m_localName;
-
const QBluetoothAddress address = localAddress();
if (address.isNull())
return QString();
@@ -288,9 +286,7 @@ QString QBluetoothSocketPrivate::localName() const
if (properties.isError())
return QString();
- m_localName = properties.value().value(QLatin1String("Name")).toString();
-
- return m_localName;
+ return properties.value().value(QLatin1String("Name")).toString();
}
QBluetoothAddress QBluetoothSocketPrivate::localAddress() const
@@ -339,9 +335,6 @@ quint16 QBluetoothSocketPrivate::localPort() const
QString QBluetoothSocketPrivate::peerName() const
{
- if (!m_peerName.isEmpty())
- return m_peerName;
-
quint64 bdaddr;
if (socketType == QBluetoothServiceInfo::RfcommProtocol) {
@@ -361,7 +354,7 @@ QString QBluetoothSocketPrivate::peerName() const
convertAddress(addr.l2_bdaddr.b, bdaddr);
} else {
- qCWarning(QT_BT_BLUEZ) << "peerName() called on socket of known type";
+ qCWarning(QT_BT_BLUEZ) << "peerName() called on socket of unknown type";
return QString();
}
@@ -399,9 +392,7 @@ QString QBluetoothSocketPrivate::peerName() const
if (properties.isError())
return QString();
- m_peerName = properties.value().value(QLatin1String("Alias")).toString();
-
- return m_peerName;
+ return properties.value().value(QLatin1String("Alias")).toString();
}
QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const
@@ -453,8 +444,8 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize)
Q_Q(QBluetoothSocket);
if (q->openMode() & QIODevice::Unbuffered) {
if (::write(socket, data, maxSize) != maxSize) {
- socketError = QBluetoothSocket::NetworkError;
- emit q->error(socketError);
+ errorString = QBluetoothSocket::tr("Network error");
+ q->setSocketError(QBluetoothSocket::NetworkError);
}
emit q->bytesWritten(maxSize);
@@ -510,7 +501,8 @@ void QBluetoothSocketPrivate::close()
// We are disconnected now, so go to unconnected.
q->setSocketState(QBluetoothSocket::UnconnectedState);
emit q->disconnected();
- ::close(socket);
+ QT_CLOSE(socket);
+ socket = -1;
}
}
diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h
index 92712911..08a6ec86 100644
--- a/src/bluetooth/qbluetoothsocket_p.h
+++ b/src/bluetooth/qbluetoothsocket_p.h
@@ -150,8 +150,6 @@ protected:
QBluetoothSocket *q_ptr;
private:
- mutable QString m_localName;
- mutable QString m_peerName;
#ifdef QT_QNX_BLUETOOTH
QBluetoothAddress m_peerAddress;
QBluetoothUuid m_uuid;
diff --git a/src/bluetooth/qbluetoothsocket_qnx.cpp b/src/bluetooth/qbluetoothsocket_qnx.cpp
index f242e4d9..fc609919 100644
--- a/src/bluetooth/qbluetoothsocket_qnx.cpp
+++ b/src/bluetooth/qbluetoothsocket_qnx.cpp
@@ -50,6 +50,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
: socket(-1),
socketType(QBluetoothServiceInfo::UnknownProtocol),
state(QBluetoothSocket::UnconnectedState),
+ socketError(QBluetoothSocket::NoSocketError),
readNotifier(0),
connectWriteNotifier(0),
connecting(false),
@@ -117,8 +118,8 @@ void QBluetoothSocketPrivate::_q_writeNotify()
int size = txBuffer.read(buf, 1024);
if (::write(socket, buf, size) != size) {
- socketError = QBluetoothSocket::NetworkError;
- emit q->error(socketError);
+ errorString = QBluetoothSocket::tr("Network Error");
+ q->setSocketError(QBluetoothSocket::NetworkError);
}
else {
emit q->bytesWritten(size);
@@ -143,9 +144,9 @@ void QBluetoothSocketPrivate::_q_readNotify()
int errsv = errno;
readNotifier->setEnabled(false);
connectWriteNotifier->setEnabled(false);
- errorString = QString::fromLocal8Bit(strerror(errsv));
qCWarning(QT_BT_QNX) << Q_FUNC_INFO << socket << " error:" << readFromDevice << errorString; //TODO Try if this actually works
- emit q->error(QBluetoothSocket::UnknownSocketError);
+ errorString = qt_error_string(errsv);
+ q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->disconnectFromService();
q->setSocketState(QBluetoothSocket::UnconnectedState);
@@ -194,7 +195,7 @@ quint16 QBluetoothSocketPrivate::localPort() const
QString QBluetoothSocketPrivate::peerName() const
{
- return m_peerName;
+ return QString();
}
QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const
@@ -212,9 +213,9 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize)
Q_Q(QBluetoothSocket);
if (q->openMode() & QIODevice::Unbuffered) {
if (::write(socket, data, maxSize) != maxSize) {
- socketError = QBluetoothSocket::NetworkError;
+ errorString = QBluetoothSocket::tr("Network Error");
+ q->setSocketError(QBluetoothSocket::NetworkError);
qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "Socket error";
- Q_EMIT q->error(socketError);
}
Q_EMIT q->bytesWritten(maxSize);
@@ -302,8 +303,7 @@ void QBluetoothSocketPrivate::controlReply(ppsResult result)
if (!result.errorMsg.isEmpty()) {
qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "Error connecting to service:" << result.errorMsg;
errorString = result.errorMsg;
- socketError = QBluetoothSocket::UnknownSocketError;
- emit q->error(QBluetoothSocket::UnknownSocketError);
+ q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
return;
} else {
@@ -318,17 +318,16 @@ void QBluetoothSocketPrivate::controlReply(ppsResult result)
if (!result.errorMsg.isEmpty()) {
qCWarning(QT_BT_QNX) << Q_FUNC_INFO << result.errorMsg;
errorString = result.errorMsg;
- socketError = QBluetoothSocket::UnknownSocketError;
- emit q->error(QBluetoothSocket::UnknownSocketError);
+ q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
return;
} else {
qCDebug(QT_BT_QNX) << "Mount point path is:" << path;
socket = ::open(path.toStdString().c_str(), O_RDWR);
if (socket == -1) {
- errorString = QString::fromLocal8Bit(strerror(errno));
+ errorString = qt_error_string(errno);
+ q->setSocketError(QBluetoothSocket::UnknownSocketError);
qCWarning(QT_BT_QNX) << Q_FUNC_INFO << socket << " error:" << errno << errorString; //TODO Try if this actually works
- emit q->error(QBluetoothSocket::UnknownSocketError);
q->disconnectFromService();
q->setSocketState(QBluetoothSocket::UnconnectedState);
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
index e39a26af..d0d6d7ee 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
@@ -372,11 +372,10 @@ void QDeclarativeBluetoothDiscoveryModel::setRunning(bool running)
d->m_running = running;
if (!running) {
- if (d->m_deviceAgent) {
+ if (d->m_deviceAgent)
d->m_deviceAgent->stop();
- } else if (d->m_serviceAgent) {
+ if (d->m_serviceAgent)
d->m_serviceAgent->stop();
- }
} else {
clearModel();
d->m_error = NoError;
diff --git a/src/nfc/qqmlndefrecord.cpp b/src/nfc/qqmlndefrecord.cpp
index 8a3f24d7..c94578eb 100644
--- a/src/nfc/qqmlndefrecord.cpp
+++ b/src/nfc/qqmlndefrecord.cpp
@@ -262,6 +262,7 @@ QQmlNdefRecord::QQmlNdefRecord(const QNdefRecord &record, QObject *parent)
\value Uri The NDEF record type follows the construct described in RFC 3986.
\value ExternalRtd The NDEF record type follows the construct for external type names
described the NFC RTD Specification.
+ \value Unknown The NDEF record type is unknown.
*/
/*!