mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #438, plugin loading testing session + meeting results
* simulator common, many members now private (info -> read only) * renamed printDirectPlayError -> logDirectPlayError * (re)added ASSERT for FS9 * removed parent from listener (with parent no moveToThread) * removed QFuture / QConcurrent as we have agreed to do * unloading a plugin no longer automatically restarts all listeners this allows a user to set one particualar simulator in the GUI and ony wait for that * stop listener from own signal
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "context_application.h"
|
||||
#include "context_network_impl.h"
|
||||
#include "context_runtime.h"
|
||||
#include "blackcore/blackcorefreefunctions.h"
|
||||
#include "blackmisc/propertyindexvariantmap.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
@@ -130,7 +131,7 @@ namespace BlackCore
|
||||
|
||||
void CContextSimulator::stopSimulatorPlugin()
|
||||
{
|
||||
this->unloadSimulatorPlugin(false);
|
||||
this->unloadSimulatorPlugin();
|
||||
}
|
||||
|
||||
int CContextSimulator::getSimulatorStatus() const
|
||||
@@ -355,6 +356,7 @@ namespace BlackCore
|
||||
Q_ASSERT(getIContextApplication());
|
||||
Q_ASSERT(getIContextApplication()->isUsingImplementingObject());
|
||||
Q_ASSERT(!simulatorInfo.isUnspecified());
|
||||
Q_ASSERT(BlackCore::isCurrentThreadApplicationThread()); // only run in main thread
|
||||
|
||||
// error if we do not have any plugins
|
||||
if (m_simulatorPlugins.isEmpty())
|
||||
@@ -364,12 +366,14 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
// Is the plugin already loaded?
|
||||
if (m_simulatorPlugin && m_simulatorPlugin->info == simulatorInfo)
|
||||
if (m_simulatorPlugin &&
|
||||
(m_simulatorPlugin->info == simulatorInfo || simulatorInfo.isAuto()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
unloadSimulatorPlugin(false); // old plugin unloaded
|
||||
stopSimulatorListeners(); // we make sure all listeners are stopped and restart those we need
|
||||
unloadSimulatorPlugin(); // old plugin unloaded
|
||||
|
||||
// now we have a state where no driver is loaded
|
||||
if (withListener)
|
||||
@@ -393,7 +397,7 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
ISimulatorFactory *factory = getSimulatorFactory(simulatorInfo);
|
||||
Q_ASSERT(factory);
|
||||
Q_ASSERT_X(factory, Q_FUNC_INFO, "no factory");
|
||||
|
||||
// We assume we run in the same process as the own aircraft context
|
||||
// Hence we pass in memory reference to own aircraft object
|
||||
@@ -428,7 +432,7 @@ namespace BlackCore
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
|
||||
// connect with network
|
||||
// use network to initally add aircraft
|
||||
IContextNetwork *networkContext = this->getIContextNetwork();
|
||||
Q_ASSERT(networkContext);
|
||||
Q_ASSERT(networkContext->isLocalObject());
|
||||
@@ -440,7 +444,7 @@ namespace BlackCore
|
||||
m_simulatorPlugin->simulator->logicallyAddRemoteAircraft(simulatedAircraft);
|
||||
}
|
||||
|
||||
// try to connect
|
||||
// try to connect to simulator
|
||||
m_simulatorPlugin->simulator->connectTo();
|
||||
emit simulatorPluginChanged(this->m_simulatorPlugin->info);
|
||||
CLogMessage(this).info("Simulator plugin loaded: %1") << this->m_simulatorPlugin->info.toQString(true);
|
||||
@@ -471,7 +475,7 @@ namespace BlackCore
|
||||
if (this->m_simulatorPlugin)
|
||||
{
|
||||
// wrong or disconnected plugin, we start from the scratch
|
||||
this->unloadSimulatorPlugin(false);
|
||||
this->unloadSimulatorPlugin();
|
||||
}
|
||||
|
||||
PluginData *plugin = findPlugin(simulatorInfo);
|
||||
@@ -483,31 +487,32 @@ namespace BlackCore
|
||||
|
||||
if (!plugin->listener)
|
||||
{
|
||||
ISimulatorFactory *factory = getSimulatorFactory(simulatorInfo);
|
||||
Q_ASSERT(factory);
|
||||
if (!m_listenersThread.isRunning())
|
||||
{
|
||||
m_listenersThread.setObjectName("CContextSimulator:Thread for listeners");
|
||||
m_listenersThread.start(QThread::LowPriority);
|
||||
}
|
||||
|
||||
plugin->listener = factory->createListener(simulatorInfo, this);
|
||||
ISimulatorFactory *factory = getSimulatorFactory(simulatorInfo);
|
||||
Q_ASSERT_X(factory, Q_FUNC_INFO, "No simulator factory");
|
||||
|
||||
plugin->listener = factory->createListener(simulatorInfo);
|
||||
bool c = connect(plugin->listener, &ISimulatorListener::simulatorStarted, this, &CContextSimulator::ps_simulatorStarted);
|
||||
if (!c)
|
||||
{
|
||||
CLogMessage(this).error("Unable to use '%1'") << simulatorInfo.toQString();
|
||||
return;
|
||||
}
|
||||
Q_ASSERT_X(!plugin->listener->parent(), Q_FUNC_INFO, "Objects with parent cannot be moved to thread");
|
||||
plugin->listener->moveToThread(&m_listenersThread);
|
||||
}
|
||||
|
||||
ISimulatorListener *listener = plugin->listener;
|
||||
Q_ASSERT_X(listener, Q_FUNC_INFO, "No listener");
|
||||
|
||||
if (!m_listenersThread.isRunning())
|
||||
{
|
||||
m_listenersThread.start(QThread::LowPriority);
|
||||
}
|
||||
|
||||
bool s = QMetaObject::invokeMethod(listener, "start");
|
||||
bool s = QMetaObject::invokeMethod(listener, "start", Qt::QueuedConnection);
|
||||
Q_ASSERT_X(s, Q_FUNC_INFO, "cannot invoke method");
|
||||
Q_UNUSED(s);
|
||||
CLogMessage(this).debug() << "Listening for simulator: " << simulatorInfo.toQString(true);
|
||||
}
|
||||
|
||||
void CContextSimulator::listenForAllSimulators()
|
||||
@@ -523,7 +528,7 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::unloadSimulatorPlugin(bool startListeners)
|
||||
void CContextSimulator::unloadSimulatorPlugin()
|
||||
{
|
||||
if (m_simulatorPlugin)
|
||||
{
|
||||
@@ -543,11 +548,6 @@ namespace BlackCore
|
||||
emit simulatorPluginChanged(CSimulatorPluginInfo());
|
||||
}
|
||||
}
|
||||
|
||||
if (startListeners)
|
||||
{
|
||||
this->listenForAllSimulators();
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_addRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
|
||||
@@ -587,14 +587,7 @@ namespace BlackCore
|
||||
if (!statusEnum.testFlag(ISimulator::Connected))
|
||||
{
|
||||
// we got disconnected, plugin no longer needed
|
||||
unloadSimulatorPlugin(false);
|
||||
|
||||
// do not immediately listen again, but allow some time for the simulator to shutdown
|
||||
// otherwise we risk reconnecting to a closing simulator
|
||||
BlackMisc::singleShot(1000, QThread::currentThread(), [ = ]()
|
||||
{
|
||||
listenForAllSimulators();
|
||||
});
|
||||
unloadSimulatorPlugin();
|
||||
}
|
||||
emit simulatorStatusChanged(status);
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace BlackCore
|
||||
bool loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo, bool withListeners);
|
||||
|
||||
//! Unload plugin, if desired restart listeners
|
||||
void unloadSimulatorPlugin(bool startListeners);
|
||||
void unloadSimulatorPlugin();
|
||||
|
||||
//! Find and catalog all simulator plugins
|
||||
void findSimulatorPlugins();
|
||||
|
||||
@@ -59,8 +59,15 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(const CSimulatorPluginInfo &info, QObject *parent) :
|
||||
QObject(parent), m_info(info)
|
||||
{ }
|
||||
ISimulatorListener::ISimulatorListener(const CSimulatorPluginInfo &info) :
|
||||
QObject(), m_info(info)
|
||||
{
|
||||
this->setObjectName("ISimulatorListener:" + info.toQString());
|
||||
|
||||
// stop listener after it reports simulator ready
|
||||
bool s = connect(this, &ISimulatorListener::simulatorStarted, this, &ISimulatorListener::stop, Qt::QueuedConnection);
|
||||
Q_ASSERT_X(s, Q_FUNC_INFO, "connect failed");
|
||||
Q_UNUSED(s)
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace BlackCore
|
||||
//! Constructor
|
||||
//! \sa ISimulatorFactory::createListener().
|
||||
//! \note msvc2015: use inherited constructor
|
||||
ISimulatorListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent);
|
||||
ISimulatorListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
|
||||
|
||||
//! Destructor
|
||||
virtual ~ISimulatorListener() = default;
|
||||
@@ -289,8 +289,7 @@ namespace BlackCore
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) = 0;
|
||||
|
||||
//! Simulator listener instance
|
||||
virtual ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent = nullptr) = 0;
|
||||
|
||||
virtual ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info) = 0;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -136,13 +136,16 @@ namespace BlackCore
|
||||
//! Override situation from current interpolator values, if any!
|
||||
bool setInitialAircraftSituation(BlackMisc::Simulation::CSimulatedAircraft &aircraft) const;
|
||||
|
||||
protected:
|
||||
IInterpolator *m_interpolator = nullptr; //!< interpolator instance
|
||||
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
||||
|
||||
private:
|
||||
bool m_debugMessages = false; //!< Display debug messages
|
||||
bool m_blinkCycle = false; //!< use for highlighting
|
||||
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
||||
IInterpolator *m_interpolator = nullptr; //!< interpolator instance
|
||||
qint64 m_highlightEndTimeMsEpoch = 0; //!< end highlighting
|
||||
int m_timerCounter = 0; //!< allows to calculate n seconds
|
||||
QTimer m_oneSecondTimer{this}; //!< timer
|
||||
QTimer m_oneSecondTimer {this}; //!< timer
|
||||
BlackMisc::Simulation::CSimulatorPluginInfo m_simulatorPluginInfo; //!< info object
|
||||
BlackMisc::Simulation::CSimulatorSetup m_simulatorSetup; //!< setup object
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_highlightedAircraft; //!< all other aircraft are to be ignored
|
||||
@@ -150,9 +153,7 @@ namespace BlackCore
|
||||
int m_maxRenderedAircraft = MaxAircraftInfinite; //!< max.rendered aircraft
|
||||
BlackMisc::PhysicalQuantities::CLength m_maxRenderedDistance { 0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; //!< max.distance for rendering
|
||||
QList<QMetaObject::Connection> m_remoteAircraftProviderConnections; //!< connected signal/slots
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user