Wait until WiWo-S20 network appears.
This commit is contained in:
parent
6319fa237b
commit
6208514f70
37
server.cpp
37
server.cpp
|
@ -44,31 +44,35 @@ Server::Server ( std::vector<Socket*> *sockets_vector )
|
||||||
|
|
||||||
Server::Server(uint16_t port, QByteArray password)
|
Server::Server(uint16_t port, QByteArray password)
|
||||||
{
|
{
|
||||||
|
QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
|
||||||
QNetworkConfiguration *cfg = new QNetworkConfiguration;
|
QNetworkConfiguration *cfg = new QNetworkConfiguration;
|
||||||
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
|
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
|
||||||
QEventLoop *loop = new QEventLoop;
|
|
||||||
loop->connect(ncm, &QNetworkConfigurationManager::updateCompleted, loop, &QEventLoop::quit);
|
|
||||||
ncm->updateConfigurations();
|
ncm->updateConfigurations();
|
||||||
loop->exec();
|
*cfgInitial = ncm->defaultConfiguration();
|
||||||
delete loop;
|
QByteArray ssid = cfgInitial->name().toLocal8Bit();
|
||||||
*cfg = ncm->defaultConfiguration();
|
|
||||||
QByteArray ssid = cfg->name().toLocal8Bit();
|
|
||||||
|
|
||||||
auto nc = ncm->allConfigurations();
|
bool stop = false;
|
||||||
|
while ( !stop )
|
||||||
for (auto &x : nc)
|
|
||||||
{
|
{
|
||||||
if (x.bearerType() == QNetworkConfiguration::BearerWLAN)
|
QThread::sleep(1);
|
||||||
|
|
||||||
|
auto nc = ncm->allConfigurations();
|
||||||
|
|
||||||
|
for (auto &x : nc)
|
||||||
{
|
{
|
||||||
if (x.name() == "WiWo-S20")
|
if (x.bearerType() == QNetworkConfiguration::BearerWLAN)
|
||||||
{
|
{
|
||||||
std::cout << "Connecting to WiWo-S20 wireless" << std::endl;
|
if (x.name() == "WiWo-S20")
|
||||||
cfg = &x;
|
{
|
||||||
|
std::cout << "Connecting to WiWo-S20 wireless" << std::endl;
|
||||||
|
cfg = &x;
|
||||||
|
stop = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto session = new QNetworkSession(*cfg, this);
|
QNetworkSession *session = new QNetworkSession(*cfg, this);
|
||||||
session->open();
|
session->open();
|
||||||
std::cout << "Wait for connected!" << std::endl;
|
std::cout << "Wait for connected!" << std::endl;
|
||||||
if (session->waitForOpened())
|
if (session->waitForOpened())
|
||||||
|
@ -97,6 +101,11 @@ Server::Server(uint16_t port, QByteArray password)
|
||||||
session->close();
|
session->close();
|
||||||
// FIXME: discover the new socket
|
// FIXME: discover the new socket
|
||||||
std::cout << "Finished" << std::endl;
|
std::cout << "Finished" << std::endl;
|
||||||
|
session = new QNetworkSession(*cfgInitial, this);
|
||||||
|
session->open();
|
||||||
|
if (session->waitForOpened())
|
||||||
|
std::cout << "Connected!" << std::endl;
|
||||||
|
discoverSockets();
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
|
|
Loading…
Reference in New Issue