QCoreWlanEngine: port away from Java-style iterators (and other fixes)
The main goal of this patch was to port away from Java-style iterators, to make QtBase QT_NO_JAVA_STYLE_ITERATORS-clean. And this the patch achieves. But I couldn't resist a few drive-by fixes, too, to wit: - Use qDeleteAll() instead of while(!isEmpty()) delete takeFirst() - Use QMap::last() instead of iterating to the end, remembering the last-seen value - Use QMap::contains() instead of QMap::keys().contains() - Use qExchange() instead of copy+clear - Make some functions const (requires the mutex member to be marked as mutable, which is common for mutex members) I am almost certain that getSsidFromNetworkName() cannot work correctly. But this patch does not attempt to change the algorithm. Change-Id: Ifa04d7837bdc0837036c3a7a73f8c51f4e681f42 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
d5f65d8814
commit
5342805920
@ -122,9 +122,9 @@ public:
|
||||
QString interfaceName;
|
||||
QMap<QString, QString> configurationInterface;
|
||||
void getUserConfigurations();
|
||||
QString getNetworkNameFromSsid(const QString &ssid);
|
||||
QString getSsidFromNetworkName(const QString &name);
|
||||
bool isKnownSsid(const QString &ssid);
|
||||
QString getNetworkNameFromSsid(const QString &ssid) const;
|
||||
QString getSsidFromNetworkName(const QString &name) const;
|
||||
bool isKnownSsid(const QString &ssid) const;
|
||||
QMap<QString, QMap<QString,QString> > userProfiles;
|
||||
|
||||
signals:
|
||||
@ -135,7 +135,7 @@ protected:
|
||||
|
||||
private:
|
||||
QList<QNetworkConfigurationPrivate *> fetchedConfigurations;
|
||||
QMutex mutex;
|
||||
mutable QMutex mutex;
|
||||
QStringList foundNetwork(const QString &id, const QString &ssid, const QNetworkConfiguration::StateFlags state, const QString &interfaceName, const QNetworkConfiguration::Purpose purpose);
|
||||
|
||||
};
|
||||
|
@ -203,9 +203,7 @@ void QScanThread::run()
|
||||
}
|
||||
}
|
||||
// add known configurations that are not around.
|
||||
QMapIterator<QString, QMap<QString,QString> > i(userProfiles);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
for (auto i = userProfiles.cbegin(), end = userProfiles.cend(); i != end; ++i) {
|
||||
|
||||
QString networkName = i.key();
|
||||
const QString id = QString::number(qHash(QLatin1String("corewlan:") + networkName));
|
||||
@ -215,11 +213,8 @@ void QScanThread::run()
|
||||
const QString ssidId = QString::number(qHash(QLatin1String("corewlan:") + networkSsid));
|
||||
QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined;
|
||||
QString interfaceName;
|
||||
QMapIterator<QString, QString> ij(i.value());
|
||||
while (ij.hasNext()) {
|
||||
ij.next();
|
||||
interfaceName = ij.value();
|
||||
}
|
||||
if (!i.value().isEmpty())
|
||||
interfaceName = i.value().last();
|
||||
|
||||
if (currentInterfaceServiceActive) {
|
||||
if (networkSsid == QString::fromNSString([currentInterface ssid])) {
|
||||
@ -269,11 +264,7 @@ QStringList QScanThread::foundNetwork(const QString &id, const QString &name, co
|
||||
QList<QNetworkConfigurationPrivate *> QScanThread::getConfigurations()
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
QList<QNetworkConfigurationPrivate *> foundConfigurations = fetchedConfigurations;
|
||||
fetchedConfigurations.clear();
|
||||
|
||||
return foundConfigurations;
|
||||
return qExchange(fetchedConfigurations, {});
|
||||
}
|
||||
|
||||
void QScanThread::getUserConfigurations()
|
||||
@ -363,17 +354,12 @@ void QScanThread::getUserConfigurations()
|
||||
}
|
||||
}
|
||||
|
||||
QString QScanThread::getSsidFromNetworkName(const QString &name)
|
||||
QString QScanThread::getSsidFromNetworkName(const QString &name) const
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
QMapIterator<QString, QMap<QString,QString> > i(userProfiles);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
QMap<QString,QString> map = i.value();
|
||||
QMapIterator<QString, QString> ij(i.value());
|
||||
while (ij.hasNext()) {
|
||||
ij.next();
|
||||
for (auto i = userProfiles.cbegin(), end = userProfiles.cend(); i != end; ++i) {
|
||||
for (auto ij = i.value().cbegin(), end = i.value().cend(); ij != end; ++ij) {
|
||||
const QString networkNameHash = QString::number(qHash(QLatin1String("corewlan:") +i.key()));
|
||||
if(name == i.key() || name == networkNameHash) {
|
||||
return ij.key();
|
||||
@ -383,36 +369,24 @@ QString QScanThread::getSsidFromNetworkName(const QString &name)
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QScanThread::getNetworkNameFromSsid(const QString &ssid)
|
||||
QString QScanThread::getNetworkNameFromSsid(const QString &ssid) const
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
QMapIterator<QString, QMap<QString,QString> > i(userProfiles);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
QMap<QString,QString> map = i.value();
|
||||
QMapIterator<QString, QString> ij(i.value());
|
||||
while (ij.hasNext()) {
|
||||
ij.next();
|
||||
if(ij.key() == ssid) {
|
||||
return i.key();
|
||||
}
|
||||
}
|
||||
for (auto i = userProfiles.cbegin(), end = userProfiles.cend(); i != end; ++i) {
|
||||
if (i.value().contains(ssid))
|
||||
return i.key();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool QScanThread::isKnownSsid(const QString &ssid)
|
||||
bool QScanThread::isKnownSsid(const QString &ssid) const
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
QMapIterator<QString, QMap<QString,QString> > i(userProfiles);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
QMap<QString,QString> map = i.value();
|
||||
if(map.keys().contains(ssid)) {
|
||||
for (auto i = userProfiles.cbegin(), end = userProfiles.cend(); i != end; ++i) {
|
||||
if (i.value().contains(ssid))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -430,8 +404,7 @@ QCoreWlanEngine::~QCoreWlanEngine()
|
||||
{
|
||||
scanThread->wait();
|
||||
|
||||
while (!foundConfigurations.isEmpty())
|
||||
delete foundConfigurations.takeFirst();
|
||||
qDeleteAll(qExchange(foundConfigurations, {}));
|
||||
[listener remove];
|
||||
[listener release];
|
||||
}
|
||||
@ -486,9 +459,7 @@ void QCoreWlanEngine::connectToId(const QString &id)
|
||||
const QString idHash2 = QString::number(qHash(QLatin1String("corewlan:") + scanThread->getNetworkNameFromSsid(ptr->name)));
|
||||
|
||||
QString wantedNetwork;
|
||||
QMapIterator<QString, QMap<QString, QString> > i(scanThread->userProfiles);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
for (auto i = scanThread->userProfiles.cbegin(), end = scanThread->userProfiles.cend(); i != end; ++i) {
|
||||
wantedNetwork = i.key();
|
||||
const QString networkNameHash = QString::number(qHash(QLatin1String("corewlan:") + wantedNetwork));
|
||||
if (id == networkNameHash) {
|
||||
|
Loading…
Reference in New Issue
Block a user