Move global Fs9 variables into CSimulatorFs9Factory

Global variables are always a bad idea since the order of destruction
is unknown and can cause undefined behaviour. In this case the
global shared pointer can be destroyed before CSimulatorFs9Factory which
relies on it.

refs #546
This commit is contained in:
Roland Winklmeier
2015-12-15 13:08:08 +01:00
committed by Klaus Basan
parent 7779c65ab8
commit 9960431d01
2 changed files with 45 additions and 38 deletions

View File

@@ -40,6 +40,8 @@ namespace BlackSimPlugin
//! Constructor, parameters as in \sa BlackCore::ISimulatorFactory::create
CSimulatorFs9(
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
const QSharedPointer<CFs9Host> &fs9Host,
const QSharedPointer<CLobbyClient> &lobbyClient,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
BlackMisc::IPluginStorageProvider *pluginStorageProvider,
@@ -106,8 +108,9 @@ namespace BlackSimPlugin
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
QMetaObject::Connection m_connectionHostMessages;
int m_dispatchTimerId = -1;
bool m_simConnected = false; //!< Is simulator connected?
QSharedPointer<CFs9Host> m_fs9Host;
QSharedPointer<CLobbyClient> m_lobbyClient;
};
//! Listener for FS9
@@ -120,7 +123,9 @@ namespace BlackSimPlugin
public:
//! Constructor
CSimulatorFs9Listener(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
CSimulatorFs9Listener(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
const QSharedPointer<CFs9Host> &fs9Host,
const QSharedPointer<CLobbyClient> &lobbyClient);
public slots:
//! \copydoc BlackCore::ISimulatorListener::start
@@ -130,11 +135,11 @@ namespace BlackSimPlugin
virtual void stop() override;
private:
QTimer *m_timer = nullptr;
bool m_isConnecting = false;
bool m_isStarted = false;
QSharedPointer<CFs9Host> m_fs9Host;
QSharedPointer<CLobbyClient> m_lobbyClient;
};
//! Factory implementation to create CSimulatorFs9 instances
@@ -161,6 +166,9 @@ namespace BlackSimPlugin
//! \copydoc BlackCore::ISimulatorFactory::createListener
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info) override;
private:
QSharedPointer<CFs9Host> m_fs9Host;
QSharedPointer<CLobbyClient> m_lobbyClient;
};
} // namespace Fs9
} // namespace BlackCore