[AFV] Ref T730, use callbacks for "connectTo", avoid EventLoop

* this is a pure asynchronous concept
* callbacks are called when network request "is done"
This commit is contained in:
Klaus Basan
2019-10-15 00:07:53 +02:00
parent 218c099456
commit a334b97ac6
5 changed files with 73 additions and 44 deletions

View File

@@ -132,30 +132,36 @@ namespace BlackCore
this->connectWithContexts();
this->setCallsign(callsign);
QVector<StationDto> aliasedStations;
// thread safe connect
{
// QMutexLocker lock(&m_mutexConnection);
m_connection->connectTo(cid, password, callsign);
aliasedStations = m_connection->getAllAliasedStations();
}
this->setAliasedStations(aliasedStations); // threadsafe
this->onTimerUpdate();
QMutexLocker lock(&m_mutexConnection);
const bool isConnected = this->isConnected(); // threadsafe
if (isConnected)
{
// restart timer, normally it should be started already, paranoia
// as I run in "my thread" starting timer should be OK
// async connection
m_connection->connectTo(cid, password, callsign, { this, [ = ](bool authenticated)
{
QMutexLocker lock(&m_mutex);
if (m_voiceServerTimer) { m_voiceServerTimer->start(PositionUpdatesMs); }
// this is the callback when the connection has been established
const QVector<StationDto> aliasedStations = m_connection->getAllAliasedStations();
this->setAliasedStations(aliasedStations); // threadsafe
this->onTimerUpdate();
// const bool isConnected = this->isConnected(); // threadsafe
if (authenticated)
{
// restart timer, normally it should be started already, paranoia
// as I run in "my thread" starting timer should be OK
{
QMutexLocker lock(&m_mutex);
if (m_voiceServerTimer) { m_voiceServerTimer->start(PositionUpdatesMs); }
}
emit this->connectionStatusChanged(Connected);
}
else
{
emit this->connectionStatusChanged(Disconnected);
}
}
emit this->connectionStatusChanged(Connected);
}
else
{
emit this->connectionStatusChanged(Disconnected);
});
}
}