Ref T312, added checkImpl/check in simulator listeners

This commit is contained in:
Klaus Basan
2018-08-27 14:19:32 +02:00
parent 1d7b3bd180
commit 68beaa6d9d
8 changed files with 106 additions and 36 deletions

View File

@@ -342,7 +342,7 @@ namespace BlackSimPlugin
void CSimulatorEmulated::onSettingsChanged()
{
const CSwiftPluginSettings settings(m_settings.get());
const CSwiftPluginSettings settings(m_pluginSettings.get());
m_log = settings.isLoggingFunctionCalls();
const CSimulatorInfo simulator = settings.getEmulatedSimulator();
@@ -446,7 +446,7 @@ namespace BlackSimPlugin
const QPointer<CSimulatorEmulatedListener> guard(this);
QTimer::singleShot(2000, this, [ = ]
{
if (guard.isNull()) { return; }
if (!guard) { return; }
Q_ASSERT_X(this->getPluginInfo().isValid(), Q_FUNC_INFO, "Invalid plugin");
emit this->simulatorStarted(this->getPluginInfo());
});
@@ -454,5 +454,10 @@ namespace BlackSimPlugin
void CSimulatorEmulatedListener::stopImpl()
{ }
void CSimulatorEmulatedListener::checkImpl()
{
this->startImpl();
}
} // ns
} // ns

View File

@@ -168,7 +168,7 @@ namespace BlackSimPlugin
BlackMisc::Simulation::CSimulatedAircraftList m_renderedAircraft; //!< represents remote aircraft in simulator
QScopedPointer<CSimulatorEmulatedMonitorDialog> m_monitorWidget; //!< parent will be main window, so we need to destroy widget when destroyed
BlackMisc::CConnectionGuard m_connectionGuard; //!< connected with provider
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TSwiftPlugin> m_settings { this, &CSimulatorEmulated::onSettingsChanged };
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TSwiftPlugin> m_pluginSettings { this, &CSimulatorEmulated::onSettingsChanged };
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Simulation::CInterpolatorMultiWrapper> m_interpolators; //!< interpolators per callsign
};
@@ -187,6 +187,9 @@ namespace BlackSimPlugin
//! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void stopImpl() override;
//! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void checkImpl() override;
};
} // ns
} // ns

View File

@@ -32,7 +32,7 @@ using namespace BlackMisc::Network;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Simulation::FsCommon;
using namespace BlackMisc::Weather;
using namespace BlackSimPlugin::Fs9;
using namespace BlackCore;
using namespace BlackSimPlugin::FsCommon;
namespace BlackSimPlugin
@@ -86,9 +86,9 @@ namespace BlackSimPlugin
FS_PBH pbhstrct;
pbhstrct.pbh = positionVelocity.pbh;
int pitch = std::floor(pbhstrct.pitch / CFs9Sdk::pitchMultiplier());
int pitch = qRound(std::floor(pbhstrct.pitch / CFs9Sdk::pitchMultiplier()));
if (pitch < -90 || pitch > 89) { CLogMessage().warning("FS9: Pitch value out of limits: %1") << pitch; }
int bank = std::floor(pbhstrct.bank / CFs9Sdk::bankMultiplier());
int bank = qRound(std::floor(pbhstrct.bank / CFs9Sdk::bankMultiplier()));
// MSFS has inverted pitch and bank angles
pitch = ~pitch;
@@ -260,21 +260,21 @@ namespace BlackSimPlugin
return changed;
}
void CSimulatorFs9::displayStatusMessage(const BlackMisc::CStatusMessage &message) const
void CSimulatorFs9::displayStatusMessage(const CStatusMessage &message) const
{
// Avoid errors from CDirectPlayPeer as it may end in infinite loop
if (message.getSeverity() == BlackMisc::CStatusMessage::SeverityError && message.isFromClass<CDirectPlayPeer>())
if (message.getSeverity() == CStatusMessage::SeverityError && message.isFromClass<CDirectPlayPeer>())
{
return;
}
if (message.getSeverity() != BlackMisc::CStatusMessage::SeverityDebug)
if (message.getSeverity() != CStatusMessage::SeverityDebug)
{
QMetaObject::invokeMethod(m_fs9Host.data(), "sendTextMessage", Q_ARG(QString, message.toQString()));
}
}
void CSimulatorFs9::displayTextMessage(const BlackMisc::Network::CTextMessage &message) const
void CSimulatorFs9::displayTextMessage(const CTextMessage &message) const
{
this->displayStatusMessage(message.asStatusMessage(true, true));
}
@@ -385,7 +385,7 @@ namespace BlackSimPlugin
CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info,
const QSharedPointer<CFs9Host> &fs9Host,
const QSharedPointer<CLobbyClient> &lobbyClient) :
BlackCore::ISimulatorListener(info),
ISimulatorListener(info),
m_timer(new QTimer(this)),
m_fs9Host(fs9Host),
m_lobbyClient(lobbyClient)
@@ -395,26 +395,12 @@ namespace BlackSimPlugin
m_timer->setObjectName(this->objectName() + ":m_timer");
// Test whether we can lobby connect at all.
bool canLobbyConnect = m_lobbyClient->canLobbyConnect();
const bool canLobbyConnect = m_lobbyClient->canLobbyConnect();
connect(m_timer, &QTimer::timeout, [this, canLobbyConnect]()
// check connection
connect(m_timer, &QTimer::timeout, [ = ]()
{
if (m_fs9Host->getHostAddress().isEmpty()) { return; } // host not yet set up
if (canLobbyConnect)
{
if (m_isConnecting || m_lobbyClient->connectFs9ToHost(m_fs9Host->getHostAddress()) == S_OK)
{
m_isConnecting = true;
CLogMessage(this).info("swift is joining FS9 to the multiplayer session...");
}
}
if (!m_isStarted && m_fs9Host->isConnected())
{
emit simulatorStarted(getPluginInfo());
m_isStarted = true;
m_isConnecting = false;
}
this->checkConnection(canLobbyConnect);
});
}
@@ -429,6 +415,42 @@ namespace BlackSimPlugin
m_timer->stop();
}
void CSimulatorFs9Listener::checkImpl()
{
if (m_timer) { m_timer->start(); }
if (this->isShuttingDown()) { return; }
QPointer<CSimulatorFs9Listener> myself(this);
QTimer::singleShot(0, this, [ = ]
{
if (!myself) { return; }
const bool canLobbyConnect = m_lobbyClient->canLobbyConnect();
this->checkConnection(canLobbyConnect);
});
}
bool CSimulatorFs9Listener::checkConnection(bool canLobbyConnect)
{
if (m_fs9Host->getHostAddress().isEmpty()) { return false; } // host not yet set up
if (canLobbyConnect)
{
if (m_isConnecting || m_lobbyClient->connectFs9ToHost(m_fs9Host->getHostAddress()) == S_OK)
{
m_isConnecting = true;
CLogMessage(this).info("swift is joining FS9 to the multiplayer session...");
}
}
if (!m_isStarted && m_fs9Host->isConnected())
{
m_isStarted = true;
m_isConnecting = false;
emit this->simulatorStarted(this->getPluginInfo());
}
return m_isConnecting;
}
static void cleanupFs9Host(CFs9Host *host)
{
host->quitAndWait();

View File

@@ -49,7 +49,7 @@ namespace BlackSimPlugin
QObject *parent = nullptr);
//! Destructor
virtual ~CSimulatorFs9() = default;
virtual ~CSimulatorFs9() override = default;
//! \name Interface implementations
//! \@{
@@ -125,7 +125,13 @@ namespace BlackSimPlugin
//! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void stopImpl() override;
//! \copydoc BlackCore::ISimulatorListener::checkImpl
virtual void checkImpl() override;
private:
//! Check connection to FS9
bool checkConnection(bool canLobbyConnect);
QTimer *m_timer = nullptr;
bool m_isConnecting = false;
bool m_isStarted = false;
@@ -145,7 +151,7 @@ namespace BlackSimPlugin
CSimulatorFs9Factory(QObject *parent = nullptr);
//! Destructor
virtual ~CSimulatorFs9Factory();
virtual ~CSimulatorFs9Factory() override;
//! \copydoc BlackCore::ISimulatorFactory::create
virtual BlackCore::ISimulator *create(

View File

@@ -2101,6 +2101,20 @@ namespace BlackSimPlugin
m_timer.stop();
}
void CSimulatorFsxCommonListener::checkImpl()
{
if (!m_timer.isActive()) { return; }
if (this->isShuttingDown()) { return; }
m_timer.start(); // restart because we will check just now
QPointer<CSimulatorFsxCommonListener> myself(this);
QTimer::singleShot(0, this, [ = ]
{
if (!myself) { return; }
this->checkConnection();
});
}
QString CSimulatorFsxCommonListener::backendInfo() const
{
if (m_simulatorName.isEmpty()) { return ISimulatorListener::backendInfo(); }

View File

@@ -521,6 +521,9 @@ namespace BlackSimPlugin
//! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void stopImpl() override;
//! \copydoc BlackCore::ISimulatorListener::checkImpl
virtual void checkImpl() override;
//! Test if connection can be established
void checkConnection();
@@ -531,7 +534,7 @@ namespace BlackSimPlugin
bool checkSimConnectDll() const;
private:
QTimer m_timer { this }; //!< timer, "this" is needed otherwise warnings when move to new thread
QTimer m_timer { this }; //!< timer, "this" is needed otherwise I get warnings when move to new thread
QString m_simulatorVersion;
QString m_simConnectVersion;
QString m_simulatorName;

View File

@@ -1096,11 +1096,11 @@ namespace BlackSimPlugin
{
QString dbusAddress = m_xswiftbusServerSetting.getThreadLocal();
if (BlackMisc::CDBusServer::isSessionOrSystemAddress(dbusAddress))
if (CDBusServer::isSessionOrSystemAddress(dbusAddress))
{
checkConnectionViaBus(dbusAddress);
}
else if (BlackMisc::CDBusServer::isQtDBusAddress(dbusAddress))
else if (CDBusServer::isQtDBusAddress(dbusAddress))
{
m_timer.start();
}
@@ -1121,6 +1121,20 @@ namespace BlackSimPlugin
m_timer.stop();
}
void CSimulatorXPlaneListener::checkImpl()
{
if (!m_timer.isActive()) { return; }
if (this->isShuttingDown()) { return; }
m_timer.start(); // restart because we will check just now
QPointer<CSimulatorXPlaneListener> myself(this);
QTimer::singleShot(0, this, [ = ]
{
if (!myself) { return; }
this->checkConnectionViaPeer();
});
}
void CSimulatorXPlaneListener::checkConnectionViaBus(const QString &address)
{
if (m_watcher) { return; }
@@ -1148,7 +1162,7 @@ namespace BlackSimPlugin
void CSimulatorXPlaneListener::checkConnectionViaPeer()
{
m_conn = QDBusConnection::connectToPeer(m_xswiftbusServerSetting.getThreadLocal(), "xswiftbus");
if (! m_conn.isConnected())
if (!m_conn.isConnected())
{
// This is required to cleanup the connection in QtDBus
m_conn.disconnectFromPeer(m_conn.name());

View File

@@ -118,7 +118,7 @@ namespace BlackSimPlugin
QObject *parent = nullptr);
//! Dtor
virtual ~CSimulatorXPlane();
virtual ~CSimulatorXPlane() override;
//! \name ISimulator implementations
//! @{
@@ -273,6 +273,9 @@ namespace BlackSimPlugin
//! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void stopImpl() override;
//! \copydoc BlackCore::ISimulatorListener::checkImpl
virtual void checkImpl() override;
private:
//! Check if XSwiftBus service is already registered on the bus
void checkConnectionViaBus(const QString &address);