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:
Klaus Basan
2015-06-04 18:25:40 +02:00
parent e822c9f7d2
commit d603b28697
20 changed files with 124 additions and 159 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 };
};

View File

@@ -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

View File

@@ -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

View File

@@ -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()

View File

@@ -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