void BtLocalDevice::serviceDiscovered(const QBluetoothServiceInfo &info) { QStringList classIds; foreach (const QBluetoothUuid &uuid, info.serviceClassUuids()) classIds.append(uuid.toString()); qDebug() << "$$ Found new service" << info.device().address().toString() << info.serviceUuid() << info.serviceName() << info.serviceDescription() << classIds; if (info.serviceUuid() == QBluetoothUuid(QString(TEST_SERVICE_UUID)) || info.serviceClassUuids().contains(QBluetoothUuid(QString(TEST_SERVICE_UUID)))) { //This is here to detect the test server for SPP testing later on bool alreadyKnown = false; foreach (const QBluetoothServiceInfo& found, foundTestServers) { if (found.device().address() == info.device().address()) { alreadyKnown = true; break; } } if (!alreadyKnown) { foundTestServers.append(info); qDebug() << "@@@@@@@@ Adding:" << info.device().address().toString(); } }
void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, OpenMode openMode) { Q_D(QBluetoothSocket); setSocketState(QBluetoothSocket::ServiceLookupState); qCDebug(QT_BT) << "Starting discovery"; if(d->discoveryAgent) { d->discoveryAgent->stop(); delete d->discoveryAgent; } d->discoveryAgent = new QBluetoothServiceDiscoveryAgent(this); d->discoveryAgent->setRemoteAddress(service.device().address()); //qDebug() << "Got agent"; connect(d->discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); connect(d->discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished())); d->openMode = openMode; if(!service.serviceUuid().isNull()) d->discoveryAgent->setUuidFilter(service.serviceUuid()); if(!service.serviceClassUuids().isEmpty()) d->discoveryAgent->setUuidFilter(service.serviceClassUuids()); // we have to ID the service somehow Q_ASSERT(!d->discoveryAgent->uuidFilter().isEmpty()); qCDebug(QT_BT) << "UUID filter" << d->discoveryAgent->uuidFilter(); d->discoveryAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery); }
void tst_QBluetoothServiceInfo::tst_serviceClassUuids() { QBluetoothServiceInfo info; QCOMPARE(info.serviceClassUuids().count(), 0); QBluetoothServiceInfo::Sequence classIds; classIds << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); QCOMPARE(classIds.count(), 1); QBluetoothUuid uuid(QString("e8e10f95-1a70-4b27-9ccf-02010264e9c8")); classIds.prepend(QVariant::fromValue(uuid)); QCOMPARE(classIds.count(), 2); QCOMPARE(classIds.at(0).value<QBluetoothUuid>(), uuid); info.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classIds); QList<QBluetoothUuid> svclids = info.serviceClassUuids(); QCOMPARE(svclids.count(), 2); QCOMPARE(svclids.at(0), uuid); QCOMPARE(svclids.at(1), QBluetoothUuid(QBluetoothUuid::SerialPort)); }
bool QBluetoothServiceDiscoveryAgentPrivate::isDuplicatedService( const QBluetoothServiceInfo &serviceInfo) const { //check the service is not already part of our known list for (int j = 0; j < discoveredServices.count(); j++) { const QBluetoothServiceInfo &info = discoveredServices.at(j); if (info.device() == serviceInfo.device() && info.serviceClassUuids() == serviceInfo.serviceClassUuids() && info.serviceUuid() == serviceInfo.serviceUuid()) { return true; } } return false; }
void tst_QBluetoothServiceInfo::tst_construction() { const QString serviceName("My Service"); const QString alternateServiceName("Another ServiceName"); const QBluetoothDeviceInfo deviceInfo(QBluetoothAddress("001122334455"), "Test Device", 0); const QBluetoothDeviceInfo alternatedeviceInfo(QBluetoothAddress("554433221100"), "Test Device2", 0); QList<QBluetoothUuid::ProtocolUuid> protUuids; //list taken from qbluetoothuuid.h protUuids << QBluetoothUuid::Sdp; protUuids << QBluetoothUuid::Udp; protUuids << QBluetoothUuid::Rfcomm; protUuids << QBluetoothUuid::Tcp; protUuids << QBluetoothUuid::TcsBin; protUuids << QBluetoothUuid::TcsAt; protUuids << QBluetoothUuid::Att; protUuids << QBluetoothUuid::Obex; protUuids << QBluetoothUuid::Ip; protUuids << QBluetoothUuid::Ftp; protUuids << QBluetoothUuid::Http; protUuids << QBluetoothUuid::Wsp; protUuids << QBluetoothUuid::Bnep; protUuids << QBluetoothUuid::Upnp; protUuids << QBluetoothUuid::Hidp; protUuids << QBluetoothUuid::HardcopyControlChannel; protUuids << QBluetoothUuid::HardcopyDataChannel; protUuids << QBluetoothUuid::HardcopyNotification; protUuids << QBluetoothUuid::Avctp; protUuids << QBluetoothUuid::Avdtp; protUuids << QBluetoothUuid::Cmtp; protUuids << QBluetoothUuid::UdiCPlain; protUuids << QBluetoothUuid::McapControlChannel; protUuids << QBluetoothUuid::McapDataChannel; protUuids << QBluetoothUuid::L2cap; { QBluetoothServiceInfo serviceInfo; QVERIFY(!serviceInfo.isValid()); QVERIFY(!serviceInfo.isComplete()); QVERIFY(!serviceInfo.isRegistered()); QCOMPARE(serviceInfo.serviceName(), QString()); QCOMPARE(serviceInfo.serviceDescription(), QString()); QCOMPARE(serviceInfo.serviceProvider(), QString()); QCOMPARE(serviceInfo.serviceUuid(), QBluetoothUuid()); QCOMPARE(serviceInfo.serviceClassUuids().count(), 0); QCOMPARE(serviceInfo.attributes().count(), 0); QCOMPARE(serviceInfo.serverChannel(), -1); QCOMPARE(serviceInfo.protocolServiceMultiplexer(), -1); foreach (QBluetoothUuid::ProtocolUuid u, protUuids) QCOMPARE(serviceInfo.protocolDescriptor(u).count(), 0); } { QBluetoothServiceInfo serviceInfo; serviceInfo.setServiceName(serviceName); serviceInfo.setDevice(deviceInfo); QVERIFY(serviceInfo.isValid()); QVERIFY(!serviceInfo.isComplete()); QVERIFY(!serviceInfo.isRegistered()); QCOMPARE(serviceInfo.serviceName(), serviceName); QCOMPARE(serviceInfo.device().address(), deviceInfo.address()); QBluetoothServiceInfo copyInfo(serviceInfo); QVERIFY(copyInfo.isValid()); QVERIFY(!copyInfo.isComplete()); QVERIFY(!copyInfo.isRegistered()); QCOMPARE(copyInfo.serviceName(), serviceName); QCOMPARE(copyInfo.device().address(), deviceInfo.address()); copyInfo.setAttribute(QBluetoothServiceInfo::ServiceName, alternateServiceName); copyInfo.setDevice(alternatedeviceInfo); QCOMPARE(copyInfo.serviceName(), alternateServiceName); QCOMPARE(copyInfo.attribute(QBluetoothServiceInfo::ServiceName).toString(), alternateServiceName); QCOMPARE(serviceInfo.serviceName(), alternateServiceName); QCOMPARE(copyInfo.device().address(), alternatedeviceInfo.address()); QCOMPARE(serviceInfo.device().address(), alternatedeviceInfo.address()); foreach (QBluetoothUuid::ProtocolUuid u, protUuids) QCOMPARE(serviceInfo.protocolDescriptor(u).count(), 0); foreach (QBluetoothUuid::ProtocolUuid u, protUuids) QCOMPARE(copyInfo.protocolDescriptor(u).count(), 0); } }