Make simulator listeners safe against multiple starts

refs #909
This commit is contained in:
Roland Winklmeier
2017-03-25 18:57:57 +01:00
committed by Mathew Sutcliffe
parent 0eaab1753d
commit aafe211b5c
8 changed files with 45 additions and 23 deletions

View File

@@ -83,4 +83,18 @@ namespace BlackCore
return m_info.toQString(); return m_info.toQString();
} }
void ISimulatorListener::start()
{
if (m_isRunning) { return; }
m_isRunning = true;
startImpl();
}
void ISimulatorListener::stop()
{
if(!m_isRunning) { return; }
stopImpl();
m_isRunning = false;
}
} // namespace } // namespace

View File

@@ -255,17 +255,25 @@ namespace BlackCore
public slots: public slots:
//! Start listening for the simulator to start. //! Start listening for the simulator to start.
virtual void start() = 0; void start();
//! Stops listening. //! Stops listening.
virtual void stop() = 0; void stop();
signals: signals:
//! Emitted when the listener discovers the simulator running. //! Emitted when the listener discovers the simulator running.
void simulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info); void simulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
protected:
//! Plugin specific implementation to start listener
virtual void startImpl() = 0;
//! Plugin specific implementation to stop listener
virtual void stopImpl() = 0;
private: private:
BlackMisc::Simulation::CSimulatorPluginInfo m_info; BlackMisc::Simulation::CSimulatorPluginInfo m_info;
bool m_isRunning = false;
}; };
//! Factory pattern class to create instances of ISimulator //! Factory pattern class to create instances of ISimulator

View File

@@ -448,13 +448,13 @@ namespace BlackSimPlugin
}); });
} }
void CSimulatorFs9Listener::start() void CSimulatorFs9Listener::startImpl()
{ {
m_isStarted = false; m_isStarted = false;
m_timer->start(); m_timer->start();
} }
void CSimulatorFs9Listener::stop() void CSimulatorFs9Listener::stopImpl()
{ {
m_timer->stop(); m_timer->stop();
} }

View File

@@ -117,12 +117,12 @@ namespace BlackSimPlugin
const QSharedPointer<CFs9Host> &fs9Host, const QSharedPointer<CFs9Host> &fs9Host,
const QSharedPointer<CLobbyClient> &lobbyClient); const QSharedPointer<CLobbyClient> &lobbyClient);
public slots: protected:
//! \copydoc BlackCore::ISimulatorListener::start //! \copydoc BlackCore::ISimulatorListener::startImpl
virtual void start() override; virtual void startImpl() override;
//! \copydoc BlackCore::ISimulatorListener::stop //! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void stop() override; virtual void stopImpl() override;
private: private:
QTimer *m_timer = nullptr; QTimer *m_timer = nullptr;

View File

@@ -1334,7 +1334,7 @@ namespace BlackSimPlugin
connect(m_timer, &QTimer::timeout, this, &CSimulatorFsxCommonListener::checkConnection); connect(m_timer, &QTimer::timeout, this, &CSimulatorFsxCommonListener::checkConnection);
} }
void CSimulatorFsxCommonListener::start() void CSimulatorFsxCommonListener::startImpl()
{ {
m_simulatorVersion.clear(); m_simulatorVersion.clear();
m_simConnectVersion.clear(); m_simConnectVersion.clear();
@@ -1343,7 +1343,7 @@ namespace BlackSimPlugin
m_timer->start(); m_timer->start();
} }
void CSimulatorFsxCommonListener::stop() void CSimulatorFsxCommonListener::stopImpl()
{ {
m_timer->stop(); m_timer->stop();
} }

View File

@@ -295,12 +295,12 @@ namespace BlackSimPlugin
//! \copydoc BlackCore::ISimulatorListener::backendInfo //! \copydoc BlackCore::ISimulatorListener::backendInfo
virtual QString backendInfo() const override; virtual QString backendInfo() const override;
public slots: protected:
//! \copydoc BlackCore::ISimulatorListener::start //! \copydoc BlackCore::ISimulatorListener::startImpl
virtual void start() override; virtual void startImpl() override;
//! \copydoc BlackCore::ISimulatorListener::stop //! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void stop() override; virtual void stopImpl() override;
protected: protected:
//! Test if connection can be established //! Test if connection can be established

View File

@@ -707,7 +707,7 @@ namespace BlackSimPlugin
CSimulatorXPlaneListener::CSimulatorXPlaneListener(const CSimulatorPluginInfo &info): ISimulatorListener(info) CSimulatorXPlaneListener::CSimulatorXPlaneListener(const CSimulatorPluginInfo &info): ISimulatorListener(info)
{ } { }
void CSimulatorXPlaneListener::start() void CSimulatorXPlaneListener::startImpl()
{ {
if (m_watcher) { return; } // already started if (m_watcher) { return; } // already started
if (isXBusRunning()) if (isXBusRunning())
@@ -723,7 +723,7 @@ namespace BlackSimPlugin
} }
} }
void CSimulatorXPlaneListener::stop() void CSimulatorXPlaneListener::stopImpl()
{ {
if (m_watcher) if (m_watcher)
{ {

View File

@@ -204,12 +204,12 @@ namespace BlackSimPlugin
//! Constructor //! Constructor
CSimulatorXPlaneListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info); CSimulatorXPlaneListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
public slots: protected:
//! \copydoc BlackCore::ISimulatorListener::start //! \copydoc BlackCore::ISimulatorListener::startImpl
virtual void start() override; virtual void startImpl() override;
//! \copydoc BlackCore::ISimulatorListener::stop //! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void stop() override; virtual void stopImpl() override;
private: private:
//! \brief Check if XBus service is already registered //! \brief Check if XBus service is already registered