/*! Starts service discovery. \a mode specifies the type of service discovery to perform. On BlackBerry devices, device discovery may lead to pairing requests. \sa DiscoveryMode */ void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode) { Q_D(QBluetoothServiceDiscoveryAgent); if (d->discoveryState() == QBluetoothServiceDiscoveryAgentPrivate::Inactive) { d->setDiscoveryMode(mode); if (d->deviceAddress.isNull()) { d->startDeviceDiscovery(); } else { d->discoveredDevices << QBluetoothDeviceInfo(d->deviceAddress, QString(), 0); d->startServiceDiscovery(); } } }
/*! Starts service discovery. \a mode specifies the type of service discovery to perform. On BlackBerry devices, device discovery may lead to pairing requests. \sa DiscoveryMode */ void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode) { Q_D(QBluetoothServiceDiscoveryAgent); if (d->discoveryState() == QBluetoothServiceDiscoveryAgentPrivate::Inactive && d->error != InvalidBluetoothAdapterError) { #ifdef QT_BLUEZ_BLUETOOTH // done to avoid repeated parsing for adapter address // on Bluez5 d->foundHostAdapterPath.clear(); #endif d->setDiscoveryMode(mode); if (d->deviceAddress.isNull()) { d->startDeviceDiscovery(); } else { d->discoveredDevices << QBluetoothDeviceInfo(d->deviceAddress, QString(), 0); d->startServiceDiscovery(); } } }
void Tennis::nearFieldHandover() { qDebug() << "Connecting to NFC provided address" << m_handover->bluetoothAddress().toString(); QBluetoothDeviceInfo device = QBluetoothDeviceInfo(m_handover->bluetoothAddress(), QString(), QBluetoothDeviceInfo::ComputerDevice); QBluetoothServiceInfo service; service.setServiceUuid(QBluetoothUuid(serviceUuid)); service.setDevice(device); QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) << QVariant::fromValue(m_handover->serverPort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); client->startClient(service); board->setStatus(tr("Connecting: %1 %2").arg(m_handover->bluetoothAddress().toString()).arg(m_handover->serverPort()), 100, 25); }
void tst_QBluetoothDeviceInfo::tst_assignment() { QFETCH(QBluetoothAddress, address); QFETCH(QString, name); QFETCH(quint32, classOfDevice); QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses); QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass); QFETCH(quint8, minorDeviceClass); QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice); QVERIFY(deviceInfo.isValid()); { QBluetoothDeviceInfo copyInfo = deviceInfo; QVERIFY(copyInfo.isValid()); QCOMPARE(copyInfo.address(), address); QCOMPARE(copyInfo.name(), name); QCOMPARE(copyInfo.serviceClasses(), serviceClasses); QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass); } { QBluetoothDeviceInfo copyInfo; QVERIFY(!copyInfo.isValid()); copyInfo = deviceInfo; QVERIFY(copyInfo.isValid()); QCOMPARE(copyInfo.address(), address); QCOMPARE(copyInfo.name(), name); QCOMPARE(copyInfo.serviceClasses(), serviceClasses); QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass); } { QBluetoothDeviceInfo copyInfo1; QBluetoothDeviceInfo copyInfo2; QVERIFY(!copyInfo1.isValid()); QVERIFY(!copyInfo2.isValid()); copyInfo1 = copyInfo2 = deviceInfo; QVERIFY(copyInfo1.isValid()); QVERIFY(copyInfo2.isValid()); QVERIFY(!(QBluetoothDeviceInfo() == copyInfo1)); QCOMPARE(copyInfo1.address(), address); QCOMPARE(copyInfo2.address(), address); QCOMPARE(copyInfo1.name(), name); QCOMPARE(copyInfo2.name(), name); QCOMPARE(copyInfo1.serviceClasses(), serviceClasses); QCOMPARE(copyInfo2.serviceClasses(), serviceClasses); QCOMPARE(copyInfo1.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo2.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo1.minorDeviceClass(), minorDeviceClass); QCOMPARE(copyInfo2.minorDeviceClass(), minorDeviceClass); } { QBluetoothDeviceInfo testDeviceInfo; QVERIFY(testDeviceInfo == QBluetoothDeviceInfo()); } }
int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); RfCommClient client; QBluetoothLocalDevice localDevice; MyThread mythread; QObject::connect(&client, SIGNAL(done()), &app, SLOT(quit())); QString address; QString port; QStringList args = QCoreApplication::arguments(); if(args.length() >= 2){ address = args.at(1); if(args.length() >= 3){ port = args.at(2); } } // use previous value for client, stored earlier // if(address.isEmpty()){ // QSettings settings("QtDF", "bttennis"); // address = settings.value("lastclient").toString(); // } // hard-code address and port number if not provided if(address.isEmpty()){ address = "6C:9B:02:0C:91:D3"; // "J C7-2" port = QString("20"); } if(!address.isEmpty()){ qDebug() << "Connecting to" << address << port; QBluetoothDeviceInfo device = QBluetoothDeviceInfo(QBluetoothAddress(address), "", QBluetoothDeviceInfo::MiscellaneousDevice); QBluetoothServiceInfo service; if (!port.isEmpty()) { QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) << QVariant::fromValue(port.toUShort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); qDebug() << "port" << port.toUShort() << service.protocolServiceMultiplexer(); } else { service.setServiceUuid(QBluetoothUuid(serviceUuid)); } service.setDevice(device); // delay so that server is in waiting state qDebug() << "Starting sleep"; mythread.sleep(10); // seconds qDebug() << "Finished sleeping"; client.startClient(service); } else { qDebug() << "failed because address and/or port is missing " << address << port; } return app.exec(); }
void DeviceInfo::setDevice(const QBluetoothDeviceInfo &dev) { device = QBluetoothDeviceInfo(dev); Q_EMIT deviceChanged(); }
void tst_QBluetoothDeviceInfo::tst_assignment() { QFETCH(QBluetoothAddress, address); QFETCH(QString, name); QFETCH(quint32, classOfDevice); QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses); QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass); QFETCH(quint8, minorDeviceClass); QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration); QFETCH(QBluetoothUuid, deviceUuid); QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice); deviceInfo.setDeviceUuid(deviceUuid); deviceInfo.setCoreConfigurations(coreConfiguration); QVERIFY(deviceInfo.isValid()); { QBluetoothDeviceInfo copyInfo = deviceInfo; QVERIFY(copyInfo.isValid()); QCOMPARE(copyInfo.address(), address); QCOMPARE(copyInfo.name(), name); QCOMPARE(copyInfo.serviceClasses(), serviceClasses); QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass); QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration); QCOMPARE(copyInfo.deviceUuid(), deviceUuid); } { QBluetoothDeviceInfo copyInfo; QVERIFY(!copyInfo.isValid()); copyInfo = deviceInfo; QVERIFY(copyInfo.isValid()); QCOMPARE(copyInfo.address(), address); QCOMPARE(copyInfo.name(), name); QCOMPARE(copyInfo.serviceClasses(), serviceClasses); QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass); QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration); QCOMPARE(copyInfo.deviceUuid(), deviceUuid); } { QBluetoothDeviceInfo copyInfo1; QBluetoothDeviceInfo copyInfo2; QVERIFY(!copyInfo1.isValid()); QVERIFY(!copyInfo2.isValid()); copyInfo1 = copyInfo2 = deviceInfo; QVERIFY(copyInfo1.isValid()); QVERIFY(copyInfo2.isValid()); QVERIFY(QBluetoothDeviceInfo() != copyInfo1); QCOMPARE(copyInfo1.address(), address); QCOMPARE(copyInfo2.address(), address); QCOMPARE(copyInfo1.name(), name); QCOMPARE(copyInfo2.name(), name); QCOMPARE(copyInfo1.serviceClasses(), serviceClasses); QCOMPARE(copyInfo2.serviceClasses(), serviceClasses); QCOMPARE(copyInfo1.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo2.majorDeviceClass(), majorDeviceClass); QCOMPARE(copyInfo1.minorDeviceClass(), minorDeviceClass); QCOMPARE(copyInfo2.minorDeviceClass(), minorDeviceClass); QCOMPARE(copyInfo1.coreConfigurations(), coreConfiguration); QCOMPARE(copyInfo2.coreConfigurations(), coreConfiguration); QCOMPARE(copyInfo1.deviceUuid(), deviceUuid); QCOMPARE(copyInfo2.deviceUuid(), deviceUuid); } { QBluetoothDeviceInfo testDeviceInfo; QVERIFY(testDeviceInfo == QBluetoothDeviceInfo()); } }
Tennis::Tennis(QWidget *parent) : QDialog(parent), ui(new Ui_Tennis), board(new Board), controller(new Controller), socket(0), m_discoveryAgent(new QBluetoothServiceDiscoveryAgent), m_handover(0) { // start Bluetooth if not started QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); device->powerOn(); delete device; device = 0; //! [Construct UI] ui->setupUi(this); isClient = false; isConnected = false; quickDiscovery = true; #if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) setWindowState(Qt::WindowMaximized); #endif ui->pongView->setScene(board->getScene()); connect(ui->pongView, SIGNAL(mouseMove(int, int)), this, SLOT(mouseMove(int, int))); ui->pongView->setMouseTracking(false); connect(board, SIGNAL(ballCollision(Board::Edge)), controller, SLOT(ballCollision(Board::Edge))); connect(board, SIGNAL(scored(Board::Edge)), controller, SLOT(scored(Board::Edge))); connect(controller, SIGNAL(moveBall(int,int)), board, SLOT(setBall(int,int))); connect(this, SIGNAL(moveLeftPaddle(int)), board, SLOT(setLeftPaddle(int))); connect(this, SIGNAL(moveRightPaddle(int)), board, SLOT(setRightPaddle(int))); connect(controller, SIGNAL(score(int,int)), board, SLOT(setScore(int,int))); connect(controller, SIGNAL(fps(const QString&)), this, SLOT(fps(const QString&))); setFocusPolicy(Qt::WheelFocus); paddle_pos = (Board::Height-12)/2-Board::Paddle/2; endPaddlePos = paddle_pos; emit moveLeftPaddle(paddle_pos); board->setRightPaddle(paddle_pos); server = new TennisServer(this); connect(controller, SIGNAL(moveBall(int,int)), server, SLOT(moveBall(int,int))); connect(controller, SIGNAL(score(int,int)), server, SLOT(score(int,int))); connect(this, SIGNAL(moveLeftPaddle(int)), server, SLOT(moveLeftPaddle(int))); connect(server, SIGNAL(clientConnected(QString)), this, SLOT(serverConnected(QString))); connect(server, SIGNAL(clientDisconnected(QString)), this, SLOT(serverDisconnected())); connect(server, SIGNAL(moveRightPaddle(int)), board, SLOT(setRightPaddle(int))); connect(server, SIGNAL(lag(int)), this, SLOT(lagReport(int))); connect(server, SIGNAL(clientConnected(QString)), controller, SLOT(refresh())); server->startServer(); client = new TennisClient(this); connect(client, SIGNAL(moveBall(int,int)), board, SLOT(setBall(int,int))); connect(client, SIGNAL(moveLeftPaddle(int)), board, SLOT(setLeftPaddle(int))); connect(client, SIGNAL(connected(QString)), this, SLOT(clientConnected(QString))); connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); connect(this, SIGNAL(moveRightPaddle(int)), client, SLOT(moveRightPaddle(int))); connect(client, SIGNAL(score(int,int)), board, SLOT(setScore(int,int))); connect(client, SIGNAL(lag(int)), this, SLOT(lagReport(int))); connect(this, SIGNAL(moveLeftPaddle(int)), controller, SLOT(moveLeftPaddle(int))); connect(this, SIGNAL(moveRightPaddle(int)), controller, SLOT(moveRightPaddle(int))); connect(server, SIGNAL(moveRightPaddle(int)), controller, SLOT(moveRightPaddle(int))); // ui->pongView->setBackgroundBrush(QBrush(Qt::white)); ui->pongView->setCacheMode(QGraphicsView::CacheBackground); QNearFieldManager nearFieldManager; if (nearFieldManager.isAvailable()) { m_handover = new Handover(server->serverPort(), this); connect(m_handover, SIGNAL(bluetoothServiceChanged()), this, SLOT(nearFieldHandover())); connect(m_discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); connect(m_discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished())); } m_discoveryAgent->setUuidFilter(QBluetoothUuid(serviceUuid)); QString address; QString port; QStringList args = QCoreApplication::arguments(); if(args.length() >= 2){ address = args.at(1); if(args.length() >= 3){ port = args.at(2); } } if(address.isEmpty()){ QSettings settings("QtDF", "bttennis"); address = settings.value("lastclient").toString(); } if(!address.isEmpty()){ qDebug() << "Connect to" << address << port; QBluetoothDeviceInfo device = QBluetoothDeviceInfo(QBluetoothAddress(address), "", QBluetoothDeviceInfo::ComputerDevice); QBluetoothServiceInfo service; if (!port.isEmpty()) { QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) << QVariant::fromValue(port.toUShort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); qDebug() << "port" << port.toUShort() << service.protocolServiceMultiplexer(); } else { service.setServiceUuid(QBluetoothUuid(serviceUuid)); } service.setDevice(device); client->startClient(service); board->setStatus("Connecting", 100, 25); } else if (nearFieldManager.isAvailable()) { board->setStatus(tr("Touch to play"), 100, 25); } setEnabled(true); paddleAnimation = new QPropertyAnimation(this, "paddlePos", this); paddleAnimation->setEasingCurve(QEasingCurve::InOutQuad); ui->pongView->installEventFilter(this); }