mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +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
|
||||
|
||||
@@ -22,21 +22,6 @@ namespace BlackMisc
|
||||
//! Describing a simulator plugin
|
||||
class BLACKMISC_EXPORT CSimulatorPluginInfo : public BlackMisc::CValueObject<CSimulatorPluginInfo>
|
||||
{
|
||||
//! The _identifier_ property identifies the plugin itself and must be uniqe.
|
||||
Q_PROPERTY(QString identifier READ getIdentifier)
|
||||
|
||||
//! The _name_ property is a human-readable plugin name.
|
||||
Q_PROPERTY(QString same READ getName)
|
||||
|
||||
//! The _simulator_ property specifies which simulator the plugin handles.
|
||||
//! There cannot be two plugins loaded for the same simulator.
|
||||
//! swift enables some features for particular simulators. Currently recognized are:
|
||||
//! fsx, fs9, xplane
|
||||
Q_PROPERTY(QString simulator READ getSimulator)
|
||||
|
||||
//! The _description_ property provides a short, human-readable description of the plugin.
|
||||
Q_PROPERTY(QString description READ getDescription)
|
||||
|
||||
public:
|
||||
//! Default constructor
|
||||
CSimulatorPluginInfo() = default;
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace BlackSimPlugin
|
||||
return positionSlewMode;
|
||||
}
|
||||
|
||||
HRESULT printDirectPlayError(HRESULT error)
|
||||
HRESULT logDirectPlayError(HRESULT error)
|
||||
{
|
||||
QString errorMessage;
|
||||
switch(error)
|
||||
@@ -210,7 +210,6 @@ namespace BlackSimPlugin
|
||||
|
||||
errorMessage = "DirectPlay: " + errorMessage;
|
||||
BlackMisc::CLogMessage("swift.fs9.freefunctions").error(errorMessage);
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace BlackSimPlugin
|
||||
MPPositionSlewMode aircraftSituationToFS9(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Print the direct play error
|
||||
HRESULT printDirectPlayError(HRESULT error);
|
||||
HRESULT logDirectPlayError(HRESULT error);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,11 +265,11 @@ namespace BlackSimPlugin
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_IDirectPlay8Address,
|
||||
reinterpret_cast<void **>(&m_deviceAddress))))
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
|
||||
// Set the SP for our Device Address
|
||||
if (FAILED(hr = m_deviceAddress->SetSP(&CLSID_DP8SP_TCPIP)))
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ namespace BlackSimPlugin
|
||||
IID_IDirectPlay8Address,
|
||||
reinterpret_cast<void **>(&m_hostAddress))))
|
||||
{
|
||||
printDirectPlayError(hr);
|
||||
logDirectPlayError(hr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (FAILED(hr = m_hostAddress->BuildFromURLA(hostAddress.toLatin1().data())))
|
||||
{
|
||||
printDirectPlayError(hr);
|
||||
logDirectPlayError(hr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ namespace BlackSimPlugin
|
||||
nullptr, // pAsyncHandle
|
||||
DPNENUMHOSTS_SYNC))) // dwFlags
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
@@ -147,13 +147,13 @@ namespace BlackSimPlugin
|
||||
IID_IDirectPlay8Address,
|
||||
reinterpret_cast<void **>(&m_hostAddress))))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// Set the SP for our Host Address
|
||||
if (FAILED(hr = m_hostAddress->SetSP(&CLSID_DP8SP_TCPIP)))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// FIXME: Test if this is also working via network or if we have to use the IP address
|
||||
@@ -164,7 +164,7 @@ namespace BlackSimPlugin
|
||||
2 * (wcslen(hostname) + 1), /*bytes*/
|
||||
DPNA_DATATYPE_STRING)))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
return hr;
|
||||
@@ -173,13 +173,11 @@ namespace BlackSimPlugin
|
||||
HRESULT CFs9Client::connectToSession(const CCallsign &callsign)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
if (m_clientStatus == Connected) return hr;
|
||||
if (m_clientStatus == Connected) { return hr; }
|
||||
|
||||
QMutexLocker locker(&m_mutexHostList);
|
||||
|
||||
QScopedArrayPointer<wchar_t> wszPlayername(new wchar_t[callsign.toQString().size() + 1]);
|
||||
|
||||
callsign.toQString().toWCharArray(wszPlayername.data());
|
||||
wszPlayername[callsign.toQString().size()] = 0;
|
||||
|
||||
@@ -197,7 +195,7 @@ namespace BlackSimPlugin
|
||||
m_player.pwszName = wszPlayername.data();
|
||||
if (FAILED(hr = m_directPlayPeer->SetPeerInfo(&m_player, nullptr, nullptr, DPNSETPEERINFO_SYNC)))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// Now set up the Application Description
|
||||
@@ -218,7 +216,7 @@ namespace BlackSimPlugin
|
||||
nullptr,
|
||||
DPNCONNECT_SYNC)))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
MPChangePlayerPlane mpChangePlayerPlane;
|
||||
@@ -246,12 +244,11 @@ namespace BlackSimPlugin
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
if (m_clientStatus == Disconnected) return hr;
|
||||
|
||||
if (m_clientStatus == Disconnected) { return hr; }
|
||||
BlackMisc::CLogMessage(this).debug() << "Closing DirectPlay connection for " << m_callsign;
|
||||
if (FAILED(hr = m_directPlayPeer->Close(0)))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
m_clientStatus = Disconnected;
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace BlackSimPlugin
|
||||
ZeroMemory( addresses.data(), dwNumAddresses * sizeof(LPDIRECTPLAY8ADDRESS) );
|
||||
if (FAILED (hr = m_directPlayPeer->GetLocalHostAddresses(addresses.data(), &dwNumAddresses, 0)))
|
||||
{
|
||||
printDirectPlayError(hr);
|
||||
logDirectPlayError(hr);
|
||||
return address;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace BlackSimPlugin
|
||||
player.pwszName = wszPlayername.data();
|
||||
if (FAILED(hr = m_directPlayPeer->SetPeerInfo(&player, nullptr, nullptr, DPNSETPEERINFO_SYNC)))
|
||||
{
|
||||
printDirectPlayError(hr);
|
||||
logDirectPlayError(hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace BlackSimPlugin
|
||||
nullptr, // Player Context
|
||||
0))) // dwFlags
|
||||
{
|
||||
printDirectPlayError(hr);
|
||||
logDirectPlayError(hr);
|
||||
return hr;
|
||||
}
|
||||
else
|
||||
@@ -177,12 +177,12 @@ namespace BlackSimPlugin
|
||||
BlackMisc::CLogMessage(this).info("Hosting terminated!");
|
||||
if (FAILED(hr = m_directPlayPeer->TerminateSession(nullptr, 0, 0)))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
if (FAILED(hr = m_directPlayPeer->Close(0)))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
m_hostStatus = Terminated;
|
||||
|
||||
@@ -64,14 +64,14 @@ namespace BlackSimPlugin
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_IDirectPlay8Peer,
|
||||
(LPVOID *) &m_directPlayPeer)))
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
|
||||
// Turn off parameter validation in release builds
|
||||
const DWORD dwInitFlags = 0;
|
||||
// const DWORD dwInitFlags = DPNINITIALIZE_DISABLEPARAMVAL;
|
||||
|
||||
if (FAILED(hr = m_directPlayPeer->Initialize(&m_callbackWrapper, m_callbackWrapper.messageHandler, dwInitFlags)))
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
|
||||
|
||||
// Create and init IDirectPlay8LobbyClient
|
||||
@@ -79,10 +79,10 @@ namespace BlackSimPlugin
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_IDirectPlay8LobbyClient,
|
||||
(LPVOID *) &m_dpLobbyClient)))
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
|
||||
if (FAILED(hr = m_dpLobbyClient->Initialize(&m_lobbyCallbackWrapper, m_lobbyCallbackWrapper.messageHandler, dwInitFlags)))
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -171,31 +171,31 @@ namespace BlackSimPlugin
|
||||
if (FAILED(hr = CoCreateInstance(CLSID_DirectPlay8Address, nullptr, CLSCTX_INPROC_SERVER,
|
||||
IID_IDirectPlay8Address, reinterpret_cast<void **>(&pHostAddress))))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// Set the SP to pHostAddress
|
||||
if (FAILED(hr = pHostAddress->SetSP(pSPGuid.data())))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// Create a device address to specify which device we are using
|
||||
if (FAILED(hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL, CLSCTX_INPROC_SERVER,
|
||||
IID_IDirectPlay8Address, reinterpret_cast<void **>(&pDeviceAddress))))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// Set the SP to pDeviceAddress
|
||||
if (FAILED(hr = pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP)))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
if (FAILED(hr = pHostAddress->BuildFromURLA(address.toLocal8Bit().data())))
|
||||
{
|
||||
return printDirectPlayError(hr);
|
||||
return logDirectPlayError(hr);
|
||||
}
|
||||
|
||||
// Setup the DPL_CONNECTION_SETTINGS
|
||||
|
||||
@@ -74,6 +74,7 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorFs9::connectTo()
|
||||
{
|
||||
Q_ASSERT_X(fs9Host, Q_FUNC_INFO, "No FS9 host");
|
||||
if (!fs9Host->isConnected()) { return false; } // host not available, we quit
|
||||
|
||||
Q_ASSERT_X(m_fsuipc, Q_FUNC_INFO, "No FSUIPC");
|
||||
@@ -327,21 +328,20 @@ namespace BlackSimPlugin
|
||||
return exclude;
|
||||
}
|
||||
|
||||
CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info, QObject *parent) :
|
||||
BlackCore::ISimulatorListener(info, parent),
|
||||
CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info) :
|
||||
BlackCore::ISimulatorListener(info),
|
||||
m_timer(new QTimer(this))
|
||||
{
|
||||
Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds
|
||||
const int QueryInterval = 5 * 1000; // 5 seconds
|
||||
m_timer->setInterval(QueryInterval);
|
||||
m_timer->setObjectName(this->objectName() + ":m_timer");
|
||||
|
||||
// Test whether we can lobby connect at all.
|
||||
bool canLobbyConnect = lobbyClient->canLobbyConnect();
|
||||
|
||||
connect(m_timer, &QTimer::timeout, [this, canLobbyConnect]()
|
||||
{
|
||||
if (fs9Host->getHostAddress().isEmpty()) // host not yet set up
|
||||
return;
|
||||
|
||||
if (fs9Host->getHostAddress().isEmpty()) { return; } // host not yet set up
|
||||
if (canLobbyConnect)
|
||||
{
|
||||
if (m_isConnecting || lobbyClient->connectFs9ToHost(fs9Host->getHostAddress()) == S_OK)
|
||||
@@ -402,9 +402,9 @@ namespace BlackSimPlugin
|
||||
return new CSimulatorFs9(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(const CSimulatorPluginInfo &info, QObject *parent)
|
||||
BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(const CSimulatorPluginInfo &info)
|
||||
{
|
||||
return new CSimulatorFs9Listener(info, parent);
|
||||
return new CSimulatorFs9Listener(info);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace BlackSimPlugin
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CSimulatorFs9Listener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent);
|
||||
CSimulatorFs9Listener(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
|
||||
|
||||
public slots:
|
||||
//! \copydoc BlackCore::ISimulatorListener::start
|
||||
@@ -167,7 +167,7 @@ namespace BlackSimPlugin
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::createListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent = nullptr) override;
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info) override;
|
||||
|
||||
};
|
||||
} // namespace Fs9
|
||||
|
||||
@@ -79,19 +79,23 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorFsx::connectTo()
|
||||
{
|
||||
connect(&m_watcherConnect, SIGNAL(finished()), this, SLOT(ps_connectToFinished()));
|
||||
|
||||
// simplified connect, timers and signals not in different thread
|
||||
auto asyncConnectFunc = [&]() -> bool
|
||||
if (this->isConnected()) { return true; }
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0)))
|
||||
{
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0))) { return false; }
|
||||
if (m_useFsuipc) { this->m_fsuipc->connect(); } // FSUIPC too
|
||||
return true;
|
||||
};
|
||||
|
||||
QFuture<bool> result = QtConcurrent::run(asyncConnectFunc);
|
||||
m_watcherConnect.setFuture(result);
|
||||
// reset state as expected for unconnected
|
||||
if (m_simconnectTimerId >= 0) { killTimer(m_simconnectTimerId); }
|
||||
m_simConnected = false;
|
||||
m_simSimulating = false;
|
||||
return false;
|
||||
}
|
||||
if (m_useFsuipc) { this->m_fsuipc->connect(); } // FSUIPC too
|
||||
|
||||
// set structures and move on
|
||||
initEvents();
|
||||
initDataDefinitionsWhenConnected();
|
||||
m_simconnectTimerId = startTimer(10);
|
||||
m_simConnected = true;
|
||||
emitSimulatorCombinedStatus();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -500,25 +504,6 @@ namespace BlackSimPlugin
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorFsx::ps_connectToFinished()
|
||||
{
|
||||
if (m_watcherConnect.result())
|
||||
{
|
||||
initEvents();
|
||||
initDataDefinitionsWhenConnected();
|
||||
m_simconnectTimerId = startTimer(10);
|
||||
m_simConnected = true;
|
||||
emitSimulatorCombinedStatus();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_simconnectTimerId >= 0) { killTimer(m_simconnectTimerId); }
|
||||
m_simConnected = false;
|
||||
m_simSimulating = false;
|
||||
emitSimulatorCombinedStatus();
|
||||
}
|
||||
}
|
||||
|
||||
bool CSimulatorFsx::physicallyRemoveRemoteAircraft(const CCallsign &callsign)
|
||||
{
|
||||
// only remove from sim
|
||||
@@ -860,22 +845,14 @@ namespace BlackSimPlugin
|
||||
return exclude;
|
||||
}
|
||||
|
||||
CSimulatorFsxListener::CSimulatorFsxListener(const CSimulatorPluginInfo &info, QObject *parent) :
|
||||
ISimulatorListener(info, parent),
|
||||
CSimulatorFsxListener::CSimulatorFsxListener(const CSimulatorPluginInfo &info) :
|
||||
ISimulatorListener(info),
|
||||
m_timer(new QTimer(this))
|
||||
{
|
||||
Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds
|
||||
m_timer->setInterval(QueryInterval);
|
||||
this->setObjectName("CSimulatorFsxListener");
|
||||
this->m_timer->setObjectName(this->objectName().append(":m_timer"));
|
||||
|
||||
connect(m_timer, &QTimer::timeout, [this]()
|
||||
{
|
||||
HANDLE hSimConnect;
|
||||
HRESULT result = SimConnect_Open(&hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0);
|
||||
SimConnect_Close(hSimConnect);
|
||||
if (result == S_OK) { emit simulatorStarted(this->getPluginInfo()); }
|
||||
});
|
||||
connect(m_timer, &QTimer::timeout, this, &CSimulatorFsxListener::ps_checkConnection);
|
||||
}
|
||||
|
||||
void CSimulatorFsxListener::start()
|
||||
@@ -888,5 +865,17 @@ namespace BlackSimPlugin
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
void CSimulatorFsxListener::ps_checkConnection()
|
||||
{
|
||||
Q_ASSERT_X(!BlackCore::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background");
|
||||
HANDLE hSimConnect;
|
||||
HRESULT result = SimConnect_Open(&hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0);
|
||||
SimConnect_Close(hSimConnect);
|
||||
if (result == S_OK)
|
||||
{
|
||||
emit simulatorStarted(this->getPluginInfo());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -141,9 +141,6 @@ namespace BlackSimPlugin
|
||||
//! Dispatch SimConnect messages
|
||||
void ps_dispatch();
|
||||
|
||||
//! Called when asynchronous connection to Simconnect has finished
|
||||
void ps_connectToFinished();
|
||||
|
||||
private:
|
||||
//! Called when sim has started
|
||||
void onSimRunning();
|
||||
@@ -202,7 +199,6 @@ namespace BlackSimPlugin
|
||||
int m_dispatchErrors = 0; //!< numer of dispatched failed, \sa ps_dispatch
|
||||
HANDLE m_hSimConnect = nullptr; //!< Handle to SimConnect object
|
||||
QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject> m_simConnectObjects;
|
||||
QFutureWatcher<bool> m_watcherConnect;
|
||||
|
||||
// statistics
|
||||
qint64 m_statsUpdateAircraftTimeTotal = 0;
|
||||
@@ -217,7 +213,7 @@ namespace BlackSimPlugin
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CSimulatorFsxListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent);
|
||||
CSimulatorFsxListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
|
||||
|
||||
public slots:
|
||||
//! \copydoc BlackCore::ISimulatorListener::start
|
||||
@@ -226,6 +222,10 @@ namespace BlackSimPlugin
|
||||
//! \copydoc BlackCore::ISimulatorListener::stop
|
||||
virtual void stop() override;
|
||||
|
||||
private slots:
|
||||
//! Test if connection can be established
|
||||
void ps_checkConnection();
|
||||
|
||||
private:
|
||||
QTimer *m_timer { nullptr };
|
||||
};
|
||||
|
||||
@@ -27,9 +27,9 @@ namespace BlackSimPlugin
|
||||
return new CSimulatorFsx(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
BlackCore::ISimulatorListener *CSimulatorFsxFactory::createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent)
|
||||
BlackCore::ISimulatorListener *CSimulatorFsxFactory::createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info)
|
||||
{
|
||||
return new CSimulatorFsxListener(info, parent);
|
||||
return new CSimulatorFsxListener(info);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace BlackSimPlugin
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::getListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent = nullptr) override;
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info) override;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -158,12 +158,7 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorXPlane::connectTo()
|
||||
{
|
||||
if (isConnected())
|
||||
{
|
||||
qWarning("X-Plane already connected");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isConnected()) { return true; }
|
||||
m_conn = QDBusConnection::sessionBus(); // TODO make this configurable
|
||||
m_service = new CXBusServiceProxy(m_conn, this);
|
||||
m_traffic = new CXBusTrafficProxy(m_conn, this);
|
||||
@@ -438,7 +433,7 @@ namespace BlackSimPlugin
|
||||
return new CSimulatorXPlane(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
CSimulatorXPlaneListener::CSimulatorXPlaneListener(const CSimulatorPluginInfo &info, QObject *parent): ISimulatorListener(info, parent)
|
||||
CSimulatorXPlaneListener::CSimulatorXPlaneListener(const CSimulatorPluginInfo &info): ISimulatorListener(info)
|
||||
{ }
|
||||
|
||||
void CSimulatorXPlaneListener::start()
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace BlackSimPlugin
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CSimulatorXPlaneListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent);
|
||||
CSimulatorXPlaneListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
|
||||
|
||||
public slots:
|
||||
//! \copydoc BlackCore::ISimulatorListener::start
|
||||
@@ -222,7 +222,7 @@ namespace BlackSimPlugin
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::createListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent = nullptr) override { return new CSimulatorXPlaneListener(info, parent); }
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info) override { return new CSimulatorXPlaneListener(info); }
|
||||
};
|
||||
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user