Handling during shuttdown

* Do not start new event loop when shutting down
* FSX Listener end checking when shutting down
* in same step fixed: FSX driver can connect to P3D and FSX but not vice versa
This commit is contained in:
Klaus Basan
2017-07-14 03:42:09 +02:00
committed by Mathew Sutcliffe
parent b3186d6b91
commit 380da41544
2 changed files with 17 additions and 12 deletions

View File

@@ -626,9 +626,9 @@ namespace BlackCore
bool CApplication::isNetworkAccessible() const bool CApplication::isNetworkAccessible() const
{ {
if (!this->m_accessManager) return false; if (!this->m_accessManager) { return false; }
const QNetworkAccessManager::NetworkAccessibility a = this->m_accessManager->networkAccessible(); const QNetworkAccessManager::NetworkAccessibility a = this->m_accessManager->networkAccessible();
if (a == QNetworkAccessManager::Accessible) return true; if (a == QNetworkAccessManager::Accessible) { return true; }
// currently I also accept unknown // currently I also accept unknown
return a == QNetworkAccessManager::UnknownAccessibility; return a == QNetworkAccessManager::UnknownAccessibility;
@@ -658,6 +658,7 @@ namespace BlackCore
{ {
instance()->gracefulShutdown(); instance()->gracefulShutdown();
} }
// when the event loop is not running, this does nothing // when the event loop is not running, this does nothing
QCoreApplication::exit(retcode); QCoreApplication::exit(retcode);
} }
@@ -669,6 +670,7 @@ namespace BlackCore
void CApplication::processEventsFor(int milliseconds) void CApplication::processEventsFor(int milliseconds)
{ {
if (CApplication::instance()->isShuttingDown()) { return; }
QEventLoop eventLoop; QEventLoop eventLoop;
QTimer::singleShot(milliseconds, &eventLoop, &QEventLoop::quit); QTimer::singleShot(milliseconds, &eventLoop, &QEventLoop::quit);
eventLoop.exec(); eventLoop.exec();

View File

@@ -1503,13 +1503,13 @@ namespace BlackSimPlugin
bool check = false; bool check = false;
if (result == S_OK) if (result == S_OK)
{ {
for (int i = 0; !check && i < 3; i++) for (int i = 0; !check && i < 3 && !this->isShuttingDown(); i++)
{ {
// result not always in first dispatch // result not always in first dispatch as we first have to obtain simulator name
result = SimConnect_CallDispatch(hSimConnect, CSimulatorFsxCommonListener::SimConnectProc, this); result = SimConnect_CallDispatch(hSimConnect, CSimulatorFsxCommonListener::SimConnectProc, this);
if (result != S_OK) { break; } // means serious failure if (result != S_OK) { break; } // means serious failure
check = this->checkVersionAndSimulator(); check = this->checkVersionAndSimulator();
sApp->processEventsFor(500); if (!check) { sApp->processEventsFor(500); }
} }
} }
SimConnect_Close(hSimConnect); SimConnect_Close(hSimConnect);
@@ -1522,17 +1522,20 @@ namespace BlackSimPlugin
bool CSimulatorFsxCommonListener::checkVersionAndSimulator() const bool CSimulatorFsxCommonListener::checkVersionAndSimulator() const
{ {
const CSimulatorInfo sim(getPluginInfo().getIdentifier()); const CSimulatorInfo pluginSim(getPluginInfo().getIdentifier());
const QString simName = m_simulatorName.toLower().trimmed(); const QString connectedSimName = m_simulatorName.toLower().trimmed();
if (simName.isEmpty()) { return false; } if (connectedSimName.isEmpty()) { return false; }
if (sim.p3d()) if (pluginSim.p3d())
{ {
return simName.contains("lockheed") || simName.contains("martin") || simName.contains("p3d") || simName.contains("prepar"); // P3D drivers only work with P3D
return connectedSimName.contains("lockheed") || connectedSimName.contains("martin") || connectedSimName.contains("p3d") || connectedSimName.contains("prepar");
} }
else if (sim.fsx()) else if (pluginSim.fsx())
{ {
return simName.contains("fsx") || simName.contains("microsoft") || simName.contains("simulator x"); // FSX drivers works with P3D and FSX
return connectedSimName.contains("fsx") || connectedSimName.contains("microsoft") || connectedSimName.contains("simulator x") ||
connectedSimName.contains("lockheed") || connectedSimName.contains("martin") || connectedSimName.contains("p3d") || connectedSimName.contains("prepar");
} }
return false; return false;
} }