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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user