Exemple #1
0
void DiscoverRouterSoapOp::onSoapFinished()
{
    if (!m_mac.isNull())
    {
        AsyncOp *op = qobject_cast<AsyncOp*>(sender());
        if (op)
        {
            int index = -1;
            for (int i = 0; i < m_opList.count(); i++)
            {
                if (m_opList.at(i) == op)
                {
                    index = i;
                    break;
                }
            }
            if (index >= 0)
            {
                QString mac = op->values().value(QLatin1String("newwlanmacaddress")).toString().toUpper();
                if (mac.compare(m_mac, Qt::CaseInsensitive) == 0)
                {
                    LOG_DEBUG(QString::fromUtf8("DiscoverRouterSoapOp fast path for %1 %2").arg(mac).arg(m_ls.at(index)));
                    for (int i = 0; i < m_opList.count(); i++)
                    {
                        AsyncOp *op = m_opList.at(i);
                        disconnect(op, SIGNAL(finished()), this, SLOT(onSoapFinished()));
                        op->abort();
                    }
                    QVariantMap varMap = op->values();
                    varMap.insert(QLatin1String("soapHostName"), m_ls.at(index));
                    QVariantList fullList;
                    fullList.push_back(varMap);
                    setValue("fullList", fullList);
                    setValue("matchIndex", 0);
                    return notifyFinished(NoError);
                }
            }
        }
    }

    if (m_count++ == m_opList.count())
    {
        process();
    }
}
Exemple #2
0
void DiscoverRouterSoapOp::process()
{
    QStringList ls1;
    QList<QVariantMap> ls2;
    for (int i = 0; i < m_opList.count(); i++)
    {
        AsyncOp *op = m_opList.at(i);
        if (op->isFinished() && op->result() == NoError)
        {
            ls1.append(m_ls.at(i));
            ls2.append(op->values());
        }
    }

    if (ls1.isEmpty())
    {
        LOG_DEBUG(QString::fromUtf8("No router found!"));
        notifyFinished(UnknownError);
        return;
    }

    QSet<QString> set1;
    int count = ls1.count();
    int i = 0;
    while (i < count)
    {
        const QVariantMap& varMap = ls2.at(i);
        QString mac = varMap.value(QLatin1String("newwlanmacaddress")).toString().toUpper();
        if (set1.find(mac) == set1.end())
        {
            set1.insert(mac);
            i++;
        }
        else
        {
            ls1.removeAt(i);
            ls2.removeAt(i);
            count--;
        }
    }

    int matchIndex = -1;
    QVariantList fullList;
    LOG_DEBUG(QString::fromUtf8("found %1 router(s)").arg(ls1.count()));
    for (int i = 0; i < ls1.count(); i++)
    {
        QString hostName = ls1.at(i);
        QVariantMap varMap = ls2.at(i);
        varMap.insert(QLatin1String("soapHostName"), hostName);
        QString mac = varMap.value(QLatin1String("newwlanmacaddress")).toString().toUpper();
        fullList.push_back(varMap);
        m_mac = mac;
        //if (!m_mac.isNull() && mac.compare(m_mac, Qt::CaseInsensitive) == 0) {
        matchIndex = i;
        //}
        LOG_DEBUG(QString::fromUtf8("%1 [%2]").arg(hostName).arg(mac));
    }

    setValue("fullList", fullList);
    setValue("matchIndex", matchIndex);
    notifyFinished(NoError);
}