Ref T167, in swift GUI

* removed isContextNetworkAvailableCheck / isContextAudioAvailableCheck
* replaced those by displayDBusReconnectDialog
* using a counter to ignore some errors before showing re-connect dialog
This commit is contained in:
Klaus Basan
2017-09-28 21:10:40 +02:00
committed by Mathew Sutcliffe
parent ed51d3c5dd
commit 8b1ef20146
3 changed files with 52 additions and 32 deletions

View File

@@ -36,6 +36,7 @@
#include <QWidget>
#include <Qt>
#include <QtGlobal>
#include <QMessageBox>
class QCloseEvent;
class QEvent;
@@ -214,20 +215,6 @@ void SwiftGuiStd::ps_loginRequested()
}
}
bool SwiftGuiStd::isContextNetworkAvailableCheck()
{
if (m_contextNetworkAvailable) return true;
CLogMessage(this).error("Network context not available, no updates this time");
return false;
}
bool SwiftGuiStd::isContextAudioAvailableCheck()
{
if (m_contextAudioAvailable) return true;
CLogMessage(this).error("Audio context not available");
return false;
}
void SwiftGuiStd::ps_displayStatusMessageInGui(const CStatusMessage &statusMessage)
{
if (!m_init) { return; }
@@ -288,10 +275,8 @@ void SwiftGuiStd::ps_handleTimerBasedUpdates()
void SwiftGuiStd::setContextAvailability()
{
const bool corePreviouslyAvailable = m_coreAvailable;
if (sGui &&
sGui->getIContextApplication() &&
!sGui->isShuttingDown() &&
!sGui->getIContextApplication()->isEmptyObject())
const bool isShuttingDown = !sGui || sGui->isShuttingDown();
if (!isShuttingDown && sGui->getIContextApplication() && !sGui->getIContextApplication()->isEmptyObject())
{
// ping to check if core is still alive
m_coreAvailable = this->isMyIdentifier(sGui->getIContextApplication()->registerApplication(getCurrentTimestampIdentifier()));
@@ -300,7 +285,19 @@ void SwiftGuiStd::setContextAvailability()
{
m_coreAvailable = false;
}
if (isShuttingDown) { return; }
if (m_coreAvailable && m_coreFailures > 0)
{
m_coreFailures--;
}
else if (!m_coreAvailable && m_coreFailures < MaxCoreFailures)
{
m_coreFailures++;
}
else if (!m_coreAvailable && !m_displayingDBusReconnect)
{
this->displayDBusReconnectDialog();
}
m_contextNetworkAvailable = m_coreAvailable && sGui->getIContextNetwork() && !sGui->getIContextNetwork()->isEmptyObject();
m_contextAudioAvailable = m_coreAvailable && sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject();
@@ -443,3 +440,26 @@ void SwiftGuiStd::displayLog()
{
ui->comp_MainInfoArea->displayLog();
}
void SwiftGuiStd::displayDBusReconnectDialog()
{
if (!sGui || sGui->isShuttingDown()) { return; }
if (!sGui->getCoreFacade()) { return; }
if (m_displayingDBusReconnect) { return; }
m_displayingDBusReconnect = true;
QMessageBox msgBox(this);
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("swift core not reachable.");
msgBox.setInformativeText("Do you want to try to reconnect? 'Abort' will close the GUI.");
msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Abort);
msgBox.setDefaultButton(QMessageBox::Retry);
const int ret = msgBox.exec();
m_displayingDBusReconnect = false;
m_coreFailures = 0;
if (ret == QMessageBox::Abort)
{
this->close();
return;
}
sGui->getCoreFacade()->tryToReconnectWithDBus();
}

View File

@@ -111,10 +111,13 @@ private:
bool m_init = false;
// contexts
bool m_coreAvailable = false;
bool m_contextNetworkAvailable = false;
bool m_contextAudioAvailable = false;
QTimer *m_timerContextWatchdog = nullptr; //!< core available?
static constexpr int MaxCoreFailures = 5; //!< Failures counted before reconnecting
int m_coreFailures = 0; //!< failed access to core
bool m_coreAvailable = false; //!< core already available?
bool m_contextNetworkAvailable = false; //!< network context available?
bool m_contextAudioAvailable = false; //!< audio context available?
bool m_displayingDBusReconnect = false; //!< currently displaying reconnect dialog
QTimer *m_timerContextWatchdog = nullptr; //!< core available?
BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< own aircraft's state
//! GUI status update
@@ -138,12 +141,6 @@ private:
//! Graceful shutdown
void performGracefulShutdown();
//! Context network availability check, otherwise status message
bool isContextNetworkAvailableCheck();
//! Context voice availability check, otherwise status message
bool isContextAudioAvailableCheck();
//! Audio device lists
void setAudioDeviceLists();
@@ -173,6 +170,9 @@ private:
//! Display log
void displayLog();
//! Display a reconnect dialog
void displayDBusReconnectDialog();
private slots:
//
// Data received related slots
@@ -185,8 +185,8 @@ private slots:
void ps_displayStatusMessageInGui(const BlackMisc::CStatusMessage &statusMessage);
//! Connection status changed
//! \param from old status, as int so it is compliant with DBus
//! \param to new status, as int so it is compliant with DBus
//! \param from old status
//! \param to new status
void ps_onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to);
//

View File

@@ -34,7 +34,7 @@ using namespace BlackMisc::Audio;
bool SwiftGuiStd::ps_reloadOwnAircraft()
{
if (!this->isContextNetworkAvailableCheck()) { return false; }
if (!this->m_contextNetworkAvailable) { return false; }
// check for changed aircraft
bool changed = false;