mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-24 07:55:35 +08:00
Refactor Simulator connection status
* Removed obsolete and unused signals (ISimulator, CSimulatorContext) * Removed ISimulator::ConnectionStatus enum
This commit is contained in:
committed by
Roland Winklmeier
parent
9d37a0876d
commit
c5a1a6048b
@@ -12,9 +12,6 @@ namespace BlackCore
|
||||
{
|
||||
void registerMetadata()
|
||||
{
|
||||
// for some reasons (ask RW) these are registered twice
|
||||
qRegisterMetaType<ISimulator::ConnectionStatus>();
|
||||
qRegisterMetaType<ISimulator::ConnectionStatus>("Status");
|
||||
qRegisterMetaType<BlackCore::IVoiceChannel::ConnectionStatus>();
|
||||
}
|
||||
|
||||
|
||||
@@ -65,14 +65,11 @@ namespace BlackCore
|
||||
virtual ~IContextSimulator() {}
|
||||
|
||||
signals:
|
||||
//! Emitted when the simulator connection changes
|
||||
void connectionChanged(bool connected);
|
||||
|
||||
//! Simulator started or stopped
|
||||
void startedChanged(bool startedChanged);
|
||||
|
||||
//! Simulator combined status
|
||||
void simulatorStatusChanged(bool connected, bool running, bool paused);
|
||||
void simulatorStatusChanged(int status);
|
||||
|
||||
//! Only a limited number of aircraft displayed
|
||||
void restrictedRenderingChanged(bool restricted);
|
||||
|
||||
@@ -248,6 +248,11 @@ namespace BlackCore
|
||||
if (this->m_simulator && this->m_simulator->getSimulatorInfo() == simulatorInfo) {
|
||||
return true;
|
||||
} // already loaded
|
||||
|
||||
/* TODO Specify behaviour below */
|
||||
if (simulatorInfo.isUnspecified()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// warning if we do not have any plugins
|
||||
if (m_simulatorFactories.isEmpty()) {
|
||||
@@ -283,8 +288,7 @@ namespace BlackCore
|
||||
this->unloadSimulatorPlugin(); // old plugin unloaded
|
||||
m_simulator = newSimulator;
|
||||
|
||||
connect(m_simulator, &ISimulator::connectionStatusChanged, this, &CContextSimulator::ps_onConnectionStatusChanged);
|
||||
connect(m_simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::simulatorStatusChanged);
|
||||
connect(m_simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged);
|
||||
connect(m_simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
|
||||
connect(m_simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted);
|
||||
connect(m_simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged);
|
||||
@@ -438,7 +442,7 @@ namespace BlackCore
|
||||
{
|
||||
connected = false;
|
||||
}
|
||||
emit connectionChanged(connected);
|
||||
emit simulatorStatusChanged(status);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_textMessagesReceived(const Network::CTextMessageList &textMessages)
|
||||
@@ -547,6 +551,7 @@ namespace BlackCore
|
||||
void CContextSimulator::ps_simulatorStarted(CSimulatorInfo simulatorInfo)
|
||||
{
|
||||
CLogMessage(this).info("Simulator %1 started.") << simulatorInfo.toQString();
|
||||
stopSimulatorListeners();
|
||||
loadSimulatorPlugin(simulatorInfo);
|
||||
}
|
||||
|
||||
@@ -595,5 +600,12 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::stopSimulatorListeners()
|
||||
{
|
||||
std::for_each(m_simulatorListeners.begin(), m_simulatorListeners.end(), [](ISimulatorListener* l) {
|
||||
l->stop();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace BlackCore
|
||||
void ps_removedRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! Handle new connection status of simulator
|
||||
void ps_onConnectionStatusChanged(ISimulator::ConnectionStatus status);
|
||||
void ps_onSimulatorStatusChanged(int status);
|
||||
|
||||
//! Text message received
|
||||
void ps_textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages);
|
||||
@@ -191,6 +191,9 @@ namespace BlackCore
|
||||
//! \brief find and catalog all simulator plugins
|
||||
void findSimulatorPlugins();
|
||||
|
||||
//! \brief call stop() on all loaded listeners
|
||||
void stopSimulatorListeners();
|
||||
|
||||
BlackCore::ISimulator *m_simulator = nullptr; //!< simulator plugin
|
||||
QDir m_pluginsDir;
|
||||
QSet<ISimulatorFactory *> m_simulatorFactories;
|
||||
|
||||
@@ -34,13 +34,10 @@ namespace BlackCore
|
||||
void CContextSimulatorProxy::relaySignals(const QString &serviceName, QDBusConnection &connection)
|
||||
{
|
||||
bool s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"connectionChanged", this, SIGNAL(connectionChanged(bool)));
|
||||
"simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(int)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"startedChanged", this, SIGNAL(startedChanged(bool)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(bool, bool, bool)));
|
||||
"simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(int)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"installedAircraftModelsChanged", this, SIGNAL(installedAircraftModelsChanged()));
|
||||
|
||||
@@ -21,7 +21,12 @@ namespace BlackCore
|
||||
{
|
||||
void ISimulator::emitSimulatorCombinedStatus()
|
||||
{
|
||||
emit simulatorStatusChanged(isConnected(), isSimulating(), isPaused());
|
||||
quint8 status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
;
|
||||
emit simulatorStatusChanged(status);
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(QObject* parent) : QObject(parent)
|
||||
|
||||
@@ -32,15 +32,13 @@ namespace BlackCore
|
||||
class ISimulator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(ConnectionStatus)
|
||||
|
||||
public:
|
||||
//! ISimulator connection
|
||||
enum ConnectionStatus
|
||||
//! ISimulator status
|
||||
enum SimulatorStatus
|
||||
{
|
||||
Disconnected,
|
||||
Connected,
|
||||
ConnectionFailed
|
||||
Connected = 1 << 0, //!< Is the plugin connected to the simulator?
|
||||
Running = 1 << 1, //!< Is the simulator actually simulating?
|
||||
Paused = 1 << 2, //!< Is the simulator paused?
|
||||
};
|
||||
|
||||
//! Render all aircraft
|
||||
@@ -177,24 +175,15 @@ namespace BlackCore
|
||||
virtual bool isRenderingEnabled() const = 0;
|
||||
|
||||
signals:
|
||||
//! Emitted when the connection status has changed
|
||||
void connectionStatusChanged(ISimulator::ConnectionStatus status);
|
||||
//! Simulator combined status
|
||||
void simulatorStatusChanged(quint8 status);
|
||||
|
||||
//! Emitted when own aircraft model has changed
|
||||
void ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft);
|
||||
|
||||
//! Simulator combined status
|
||||
void simulatorStatusChanged(bool connected, bool running, bool paused);
|
||||
|
||||
//! Only a limited number of aircraft displayed
|
||||
void restrictedRenderingChanged(bool restricted);
|
||||
|
||||
//! Simulator started
|
||||
void simulatorStarted();
|
||||
|
||||
//! Simulator stopped
|
||||
void simulatorStopped();
|
||||
|
||||
//! A single model has been matched
|
||||
void modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft aircraft);
|
||||
|
||||
@@ -363,6 +352,5 @@ namespace BlackCore
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_INTERFACE(BlackCore::ISimulatorFactory, "org.swift.pilotclient.BlackCore.SimulatorInterface")
|
||||
Q_DECLARE_METATYPE(BlackCore::ISimulator::ConnectionStatus)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "blackcore/context_network.h"
|
||||
#include "blackcore/context_application.h"
|
||||
#include "blackcore/context_audio.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include "blackmisc/icons.h"
|
||||
|
||||
@@ -97,21 +98,16 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoBarStatusComponent::ps_onSimulatorStatusChanged(bool connected, bool running, bool paused)
|
||||
void CInfoBarStatusComponent::ps_onSimulatorStatusChanged(quint8 status)
|
||||
{
|
||||
if (connected && running)
|
||||
{
|
||||
// if (connected && running)
|
||||
if (status & (ISimulator::Connected | ISimulator::Running)) {
|
||||
this->ui->led_Simulator->setOn(true);
|
||||
}
|
||||
else if (connected)
|
||||
{
|
||||
} else if (status & ISimulator::Connected) {
|
||||
this->ui->led_Simulator->setTriState();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this->ui->led_Simulator->setOn(false);
|
||||
}
|
||||
Q_UNUSED(paused);
|
||||
}
|
||||
|
||||
void CInfoBarStatusComponent::ps_onNetworkConnectionChanged(uint from, uint to)
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace BlackGui
|
||||
|
||||
private slots:
|
||||
//! Simulator connection has been changed
|
||||
void ps_onSimulatorStatusChanged(bool connected, bool running, bool paused);
|
||||
void ps_onSimulatorStatusChanged(quint8 status);
|
||||
|
||||
//! Network connection has been changed
|
||||
void ps_onNetworkConnectionChanged(uint from, uint to);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "blackcore/context_settings.h"
|
||||
#include "blackcore/context_simulator.h"
|
||||
#include "blackcore/context_ownaircraft.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackmisc/iconlist.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
|
||||
@@ -101,7 +102,7 @@ namespace BlackGui
|
||||
{
|
||||
Q_ASSERT(this->getIContextSimulator());
|
||||
if (!this->getIContextSimulator()) return;
|
||||
QObject::connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &CSimulatorComponent::ps_onSimulatorConnectionChanged);
|
||||
QObject::connect(this->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CSimulatorComponent::ps_onSimulatorStatusChanged);
|
||||
|
||||
this->setUpdateInterval(getUpdateIntervalMs());
|
||||
if (!getIContextSimulator()->isConnected())
|
||||
@@ -110,10 +111,9 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorComponent::ps_onSimulatorConnectionChanged(bool isAvailable)
|
||||
void CSimulatorComponent::ps_onSimulatorStatusChanged(int status)
|
||||
{
|
||||
if (isAvailable)
|
||||
{
|
||||
if (status & ISimulator::Connected) {
|
||||
int intervalMs = getUpdateIntervalMs();
|
||||
this->m_updateTimer->startTimer(intervalMs);
|
||||
} else {
|
||||
|
||||
@@ -72,8 +72,8 @@ namespace BlackGui
|
||||
void runtimeHasBeenSet() override;
|
||||
|
||||
private slots:
|
||||
//! \copydoc ISimulator::
|
||||
void ps_onSimulatorConnectionChanged(bool isAvailable);
|
||||
//! \copydoc ISimulator::simulatorStatusChanged
|
||||
void ps_onSimulatorStatusChanged(int status);
|
||||
|
||||
private:
|
||||
//! Update interval
|
||||
|
||||
Reference in New Issue
Block a user