Refactor Simulator connection status

* Removed obsolete and unused signals (ISimulator, CSimulatorContext)
* Removed ISimulator::ConnectionStatus enum
This commit is contained in:
Michał Garapich
2015-03-31 20:39:31 +02:00
committed by Roland Winklmeier
parent 9d37a0876d
commit c5a1a6048b
11 changed files with 48 additions and 53 deletions

View File

@@ -12,9 +12,6 @@ namespace BlackCore
{ {
void registerMetadata() void registerMetadata()
{ {
// for some reasons (ask RW) these are registered twice
qRegisterMetaType<ISimulator::ConnectionStatus>();
qRegisterMetaType<ISimulator::ConnectionStatus>("Status");
qRegisterMetaType<BlackCore::IVoiceChannel::ConnectionStatus>(); qRegisterMetaType<BlackCore::IVoiceChannel::ConnectionStatus>();
} }

View File

@@ -65,14 +65,11 @@ namespace BlackCore
virtual ~IContextSimulator() {} virtual ~IContextSimulator() {}
signals: signals:
//! Emitted when the simulator connection changes
void connectionChanged(bool connected);
//! Simulator started or stopped //! Simulator started or stopped
void startedChanged(bool startedChanged); void startedChanged(bool startedChanged);
//! Simulator combined status //! Simulator combined status
void simulatorStatusChanged(bool connected, bool running, bool paused); void simulatorStatusChanged(int status);
//! Only a limited number of aircraft displayed //! Only a limited number of aircraft displayed
void restrictedRenderingChanged(bool restricted); void restrictedRenderingChanged(bool restricted);

View File

@@ -249,6 +249,11 @@ namespace BlackCore
return true; return true;
} // already loaded } // already loaded
/* TODO Specify behaviour below */
if (simulatorInfo.isUnspecified()) {
return false;
}
// warning if we do not have any plugins // warning if we do not have any plugins
if (m_simulatorFactories.isEmpty()) { if (m_simulatorFactories.isEmpty()) {
CLogMessage(this).error("No simulator plugins"); CLogMessage(this).error("No simulator plugins");
@@ -283,8 +288,7 @@ namespace BlackCore
this->unloadSimulatorPlugin(); // old plugin unloaded this->unloadSimulatorPlugin(); // old plugin unloaded
m_simulator = newSimulator; m_simulator = newSimulator;
connect(m_simulator, &ISimulator::connectionStatusChanged, this, &CContextSimulator::ps_onConnectionStatusChanged); connect(m_simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged);
connect(m_simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::simulatorStatusChanged);
connect(m_simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged); connect(m_simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
connect(m_simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted); connect(m_simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted);
connect(m_simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged); connect(m_simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged);
@@ -438,7 +442,7 @@ namespace BlackCore
{ {
connected = false; connected = false;
} }
emit connectionChanged(connected); emit simulatorStatusChanged(status);
} }
void CContextSimulator::ps_textMessagesReceived(const Network::CTextMessageList &textMessages) void CContextSimulator::ps_textMessagesReceived(const Network::CTextMessageList &textMessages)
@@ -547,6 +551,7 @@ namespace BlackCore
void CContextSimulator::ps_simulatorStarted(CSimulatorInfo simulatorInfo) void CContextSimulator::ps_simulatorStarted(CSimulatorInfo simulatorInfo)
{ {
CLogMessage(this).info("Simulator %1 started.") << simulatorInfo.toQString(); CLogMessage(this).info("Simulator %1 started.") << simulatorInfo.toQString();
stopSimulatorListeners();
loadSimulatorPlugin(simulatorInfo); loadSimulatorPlugin(simulatorInfo);
} }
@@ -596,4 +601,11 @@ namespace BlackCore
} }
} }
void CContextSimulator::stopSimulatorListeners()
{
std::for_each(m_simulatorListeners.begin(), m_simulatorListeners.end(), [](ISimulatorListener* l) {
l->stop();
});
}
} // namespace } // namespace

View File

@@ -166,7 +166,7 @@ namespace BlackCore
void ps_removedRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign); void ps_removedRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign);
//! Handle new connection status of simulator //! Handle new connection status of simulator
void ps_onConnectionStatusChanged(ISimulator::ConnectionStatus status); void ps_onSimulatorStatusChanged(int status);
//! Text message received //! Text message received
void ps_textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages); void ps_textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages);
@@ -191,6 +191,9 @@ namespace BlackCore
//! \brief find and catalog all simulator plugins //! \brief find and catalog all simulator plugins
void findSimulatorPlugins(); void findSimulatorPlugins();
//! \brief call stop() on all loaded listeners
void stopSimulatorListeners();
BlackCore::ISimulator *m_simulator = nullptr; //!< simulator plugin BlackCore::ISimulator *m_simulator = nullptr; //!< simulator plugin
QDir m_pluginsDir; QDir m_pluginsDir;
QSet<ISimulatorFactory *> m_simulatorFactories; QSet<ISimulatorFactory *> m_simulatorFactories;

View File

@@ -34,13 +34,10 @@ namespace BlackCore
void CContextSimulatorProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) void CContextSimulatorProxy::relaySignals(const QString &serviceName, QDBusConnection &connection)
{ {
bool s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), bool s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"connectionChanged", this, SIGNAL(connectionChanged(bool))); "simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(int)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"startedChanged", this, SIGNAL(startedChanged(bool))); "simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(int)));
Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(bool, bool, bool)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"installedAircraftModelsChanged", this, SIGNAL(installedAircraftModelsChanged())); "installedAircraftModelsChanged", this, SIGNAL(installedAircraftModelsChanged()));

View File

@@ -21,7 +21,12 @@ namespace BlackCore
{ {
void ISimulator::emitSimulatorCombinedStatus() 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) ISimulatorListener::ISimulatorListener(QObject* parent) : QObject(parent)

View File

@@ -32,15 +32,13 @@ namespace BlackCore
class ISimulator : public QObject class ISimulator : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_ENUMS(ConnectionStatus)
public: public:
//! ISimulator connection //! ISimulator status
enum ConnectionStatus enum SimulatorStatus
{ {
Disconnected, Connected = 1 << 0, //!< Is the plugin connected to the simulator?
Connected, Running = 1 << 1, //!< Is the simulator actually simulating?
ConnectionFailed Paused = 1 << 2, //!< Is the simulator paused?
}; };
//! Render all aircraft //! Render all aircraft
@@ -177,24 +175,15 @@ namespace BlackCore
virtual bool isRenderingEnabled() const = 0; virtual bool isRenderingEnabled() const = 0;
signals: signals:
//! Emitted when the connection status has changed //! Simulator combined status
void connectionStatusChanged(ISimulator::ConnectionStatus status); void simulatorStatusChanged(quint8 status);
//! Emitted when own aircraft model has changed //! Emitted when own aircraft model has changed
void ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft); void ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft);
//! Simulator combined status
void simulatorStatusChanged(bool connected, bool running, bool paused);
//! Only a limited number of aircraft displayed //! Only a limited number of aircraft displayed
void restrictedRenderingChanged(bool restricted); void restrictedRenderingChanged(bool restricted);
//! Simulator started
void simulatorStarted();
//! Simulator stopped
void simulatorStopped();
//! A single model has been matched //! A single model has been matched
void modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft aircraft); void modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft aircraft);
@@ -363,6 +352,5 @@ namespace BlackCore
} // namespace } // namespace
Q_DECLARE_INTERFACE(BlackCore::ISimulatorFactory, "org.swift.pilotclient.BlackCore.SimulatorInterface") Q_DECLARE_INTERFACE(BlackCore::ISimulatorFactory, "org.swift.pilotclient.BlackCore.SimulatorInterface")
Q_DECLARE_METATYPE(BlackCore::ISimulator::ConnectionStatus)
#endif // guard #endif // guard

View File

@@ -13,6 +13,7 @@
#include "blackcore/context_network.h" #include "blackcore/context_network.h"
#include "blackcore/context_application.h" #include "blackcore/context_application.h"
#include "blackcore/context_audio.h" #include "blackcore/context_audio.h"
#include "blackcore/simulator.h"
#include "blackmisc/project.h" #include "blackmisc/project.h"
#include "blackmisc/icons.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); this->ui->led_Simulator->setOn(true);
} } else if (status & ISimulator::Connected) {
else if (connected)
{
this->ui->led_Simulator->setTriState(); this->ui->led_Simulator->setTriState();
} } else {
else
{
this->ui->led_Simulator->setOn(false); this->ui->led_Simulator->setOn(false);
} }
Q_UNUSED(paused);
} }
void CInfoBarStatusComponent::ps_onNetworkConnectionChanged(uint from, uint to) void CInfoBarStatusComponent::ps_onNetworkConnectionChanged(uint from, uint to)

View File

@@ -54,7 +54,7 @@ namespace BlackGui
private slots: private slots:
//! Simulator connection has been changed //! Simulator connection has been changed
void ps_onSimulatorStatusChanged(bool connected, bool running, bool paused); void ps_onSimulatorStatusChanged(quint8 status);
//! Network connection has been changed //! Network connection has been changed
void ps_onNetworkConnectionChanged(uint from, uint to); void ps_onNetworkConnectionChanged(uint from, uint to);

View File

@@ -12,6 +12,7 @@
#include "blackcore/context_settings.h" #include "blackcore/context_settings.h"
#include "blackcore/context_simulator.h" #include "blackcore/context_simulator.h"
#include "blackcore/context_ownaircraft.h" #include "blackcore/context_ownaircraft.h"
#include "blackcore/simulator.h"
#include "blackmisc/iconlist.h" #include "blackmisc/iconlist.h"
#include "blackmisc/avaircraft.h" #include "blackmisc/avaircraft.h"
@@ -101,7 +102,7 @@ namespace BlackGui
{ {
Q_ASSERT(this->getIContextSimulator()); Q_ASSERT(this->getIContextSimulator());
if (!this->getIContextSimulator()) return; 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()); this->setUpdateInterval(getUpdateIntervalMs());
if (!getIContextSimulator()->isConnected()) 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(); int intervalMs = getUpdateIntervalMs();
this->m_updateTimer->startTimer(intervalMs); this->m_updateTimer->startTimer(intervalMs);
} else { } else {

View File

@@ -72,8 +72,8 @@ namespace BlackGui
void runtimeHasBeenSet() override; void runtimeHasBeenSet() override;
private slots: private slots:
//! \copydoc ISimulator:: //! \copydoc ISimulator::simulatorStatusChanged
void ps_onSimulatorConnectionChanged(bool isAvailable); void ps_onSimulatorStatusChanged(int status);
private: private:
//! Update interval //! Update interval