mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user