HueBridgeConnection::HueBridgeConnection(): m_nam(new QNetworkAccessManager(this)), m_discoveryError(false), m_bridgeStatus(BridgeStatusSearching), m_requestCounter(0) { m_discovery = new Discovery(this); connect(m_discovery, SIGNAL(error()), this, SLOT(onDiscoveryError())); connect(m_discovery, SIGNAL(foundBridge(QHostAddress, QString)), this, SLOT(onFoundBridge(QHostAddress, QString))); connect(m_discovery, SIGNAL(noBridgesFound()), this, SLOT(onNoBridgesFound())); m_discovery->findBridges(); }
void Discovery::onReadyRead() { while (hasPendingDatagrams()) { QByteArray datagram; datagram.resize(pendingDatagramSize()); QHostAddress sender; quint16 senderPort; readDatagram(datagram.data(), datagram.size(), &sender, &senderPort); // qDebug() << "got datagram" << datagram; if (!m_reportedBridges.contains(sender)) { m_reportedBridges << sender; emit foundBridge(sender); } } }