mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
refs #395, integrated aircraft airspace snapshot / analyzer into remote provider
* added snapshot class * added snapshot in analyzer, signal for new snapshot * made all provider signals available in CSimulator * added finders in CSimulatedAircraftList * moved COwnAircraftProviderDummy into own file
This commit is contained in:
committed by
Mathew Sutcliffe
parent
6570a0c966
commit
018c5ae1bf
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "airspace_analyzer.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
@@ -17,7 +18,6 @@ using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
CAirspaceAnalyzer::CAirspaceAnalyzer(IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, INetwork *network, QObject *parent) :
|
||||
CContinuousWorker(parent, "CAirspaceAnalyzer"),
|
||||
COwnAircraftAware(ownAircraftProvider),
|
||||
@@ -25,8 +25,18 @@ namespace BlackCore
|
||||
{
|
||||
Q_ASSERT_X(network, Q_FUNC_INFO, "Network object required to connect");
|
||||
|
||||
// start in thread
|
||||
this->setObjectName("CAirspaceAnalyzer");
|
||||
|
||||
// all in new thread from here on
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setObjectName(this->objectName().append(":m_timer"));
|
||||
m_timer->start(5000);
|
||||
bool c = connect(m_timer, &QTimer::timeout, this, &CAirspaceAnalyzer::ps_timeout);
|
||||
Q_ASSERT(c);
|
||||
|
||||
// disconnect
|
||||
bool c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign);
|
||||
c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign);
|
||||
Q_ASSERT(c);
|
||||
c = connect(network, &INetwork::atcDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAtcCallsign);
|
||||
Q_ASSERT(c);
|
||||
@@ -38,9 +48,19 @@ namespace BlackCore
|
||||
Q_ASSERT(c);
|
||||
|
||||
// network
|
||||
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::ps_onConnectionStatusChanged);
|
||||
// If I do not explicitly set Qt::QueuedConnection here, I get a warning message when such a signal is sent:
|
||||
// "INetwork::NetworkConenctionStatus is not registered" (similar to https://forum.qt.io/topic/27083/signal-slot-between-threads-qt-5/9)
|
||||
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::ps_onConnectionStatusChanged, Qt::QueuedConnection);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
|
||||
this->start();
|
||||
}
|
||||
|
||||
CAirspaceAircraftSnapshot CAirspaceAnalyzer::getLatestAirspaceAircraftSnapshot() const
|
||||
{
|
||||
QReadLocker l(&m_lockSnapshot);
|
||||
return m_latestAircraftSnapshot;
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::ps_watchdogTouchAircraftCallsign(const CAircraftSituation &situation, const CTransponder &transponder)
|
||||
@@ -58,19 +78,31 @@ namespace BlackCore
|
||||
m_atcCallsignTimestamps[callsign] = QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::ps_onConnectionStatusChanged(INetwork::ConnectionStatus oldStatus, INetwork::ConnectionStatus newStatus)
|
||||
void CAirspaceAnalyzer::ps_onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus)
|
||||
{
|
||||
Q_UNUSED(oldStatus);
|
||||
if (newStatus == INetwork::Disconnected)
|
||||
{
|
||||
this->clear();
|
||||
this->m_timer->stop();
|
||||
}
|
||||
else if (newStatus == INetwork::Connected)
|
||||
{
|
||||
this->m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::ps_timeout()
|
||||
{
|
||||
this->analyzeAirspace();
|
||||
this->watchdogCheckTimeouts();
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::clear()
|
||||
{
|
||||
m_aircraftCallsignTimestamps.clear();
|
||||
m_atcCallsignTimestamps.clear();
|
||||
m_latestAircraftSnapshot = CAirspaceAircraftSnapshot();
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign(const CCallsign &callsign)
|
||||
@@ -85,9 +117,17 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceAnalyzer::watchdogCheckTimeouts()
|
||||
{
|
||||
qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch;
|
||||
qint64 callThresholdMs = m_timer->interval() * 1.5;
|
||||
m_lastWatchdogCallMsSinceEpoch = currentTimeMsEpoch;
|
||||
|
||||
// this is a trick to not remove everything while debugging
|
||||
if (callDiffMs > callThresholdMs) { return; }
|
||||
|
||||
qint64 aircraftTimeoutMs = m_timeoutAircraft.valueInteger(CTimeUnit::ms());
|
||||
qint64 atcTimeoutMs = m_timeoutAtc.valueInteger(CTimeUnit::ms());
|
||||
qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
qint64 timeoutAircraftEpochMs = currentTimeMsEpoch - aircraftTimeoutMs;
|
||||
qint64 timeoutAtcEpochMs = currentTimeMsEpoch - atcTimeoutMs;
|
||||
|
||||
@@ -107,4 +147,18 @@ namespace BlackCore
|
||||
emit timeoutAtc(callsign);
|
||||
}
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::analyzeAirspace()
|
||||
{
|
||||
CAirspaceAircraftSnapshot snapshot(getAircraftInRange()); // thread safe copy
|
||||
|
||||
// lock block
|
||||
{
|
||||
QWriteLocker l(&m_lockSnapshot);
|
||||
m_latestAircraftSnapshot = snapshot;
|
||||
}
|
||||
|
||||
emit airspaceAircraftSnapshot(snapshot);
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKCORE_AIRSPACE_ANALYZER_H
|
||||
|
||||
#include "blackcore/network.h"
|
||||
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
|
||||
#include "blackmisc/simulation/remoteaircraftprovider.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
#include "blackmisc/worker.h"
|
||||
@@ -23,7 +24,6 @@
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
//! Class monitoring and analyzing (closests aircraft, outdated aircraft / watchdog) airspace
|
||||
//! in background.
|
||||
//!
|
||||
@@ -47,6 +47,10 @@ namespace BlackCore
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
INetwork *network, QObject *parent);
|
||||
|
||||
//! Get the latest snapshot
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const;
|
||||
|
||||
public slots:
|
||||
//! Clear
|
||||
void clear();
|
||||
@@ -58,6 +62,9 @@ namespace BlackCore
|
||||
//! Callsign has timed out
|
||||
void timeoutAtc(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! New aircraft snapshot
|
||||
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
|
||||
|
||||
private slots:
|
||||
//! Remove callsign from watch list
|
||||
void ps_watchdogRemoveAircraftCallsign(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
@@ -73,17 +80,30 @@ namespace BlackCore
|
||||
const BlackMisc::Geo::CCoordinateGeodetic &pos, const BlackMisc::PhysicalQuantities::CLength &range);
|
||||
|
||||
//! Connection status of network changed
|
||||
void ps_onConnectionStatusChanged(INetwork::ConnectionStatus oldStatus, INetwork::ConnectionStatus newStatus);
|
||||
void ps_onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus);
|
||||
|
||||
//! Run a check
|
||||
void ps_timeout();
|
||||
|
||||
private:
|
||||
//! Check for time outs
|
||||
void watchdogCheckTimeouts();
|
||||
|
||||
CCallsignTimestampSet m_aircraftCallsignTimestamps;
|
||||
CCallsignTimestampSet m_atcCallsignTimestamps;
|
||||
//! Analyze the airspace
|
||||
void analyzeAirspace();
|
||||
|
||||
QTimer *m_timer = nullptr; //!< multi purpose timer for snapshots and watchdog
|
||||
|
||||
// watchdog
|
||||
CCallsignTimestampSet m_aircraftCallsignTimestamps; //!< for watchdog (pilots)
|
||||
CCallsignTimestampSet m_atcCallsignTimestamps; //!< for watchdog (ATC)
|
||||
BlackMisc::PhysicalQuantities::CTime m_timeoutAircraft = {15, BlackMisc::PhysicalQuantities::CTimeUnit::s() }; //!< Timeout value for watchdog functionality
|
||||
BlackMisc::PhysicalQuantities::CTime m_timeoutAtc = {50, BlackMisc::PhysicalQuantities::CTimeUnit::s() }; //!< Timeout value for watchdog functionality
|
||||
qint64 m_lastWatchdogCallMsSinceEpoch;
|
||||
|
||||
// snapshot
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot m_latestAircraftSnapshot;
|
||||
mutable QReadWriteLock m_lockSnapshot; //!< lock snapshot
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -81,6 +81,12 @@ namespace BlackCore
|
||||
return m_aircraftInRange.size();
|
||||
}
|
||||
|
||||
CAirspaceAircraftSnapshot CAirspaceMonitor::getLatestAirspaceAircraftSnapshot() const
|
||||
{
|
||||
Q_ASSERT_X(this->m_analyzer, Q_FUNC_INFO, "No analyzer");
|
||||
return this->m_analyzer->getLatestAirspaceAircraftSnapshot();
|
||||
}
|
||||
|
||||
CAircraftSituationList CAirspaceMonitor::remoteAircraftSituations(const CCallsign &callsign) const
|
||||
{
|
||||
QReadLocker l(&m_lockSituations);
|
||||
@@ -124,9 +130,11 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
bool CAirspaceMonitor::connectRemoteAircraftProviderSignals(
|
||||
std::function<void(const CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const CAircraftParts &)> partsSlot,
|
||||
std::function<void(const CCallsign &)> removedAircraftSlot)
|
||||
std::function<void(const CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const CAircraftParts &)> partsSlot,
|
||||
std::function<void(const CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
)
|
||||
{
|
||||
bool s1 = connect(this, &CAirspaceMonitor::addedAircraftSituation, situationSlot);
|
||||
Q_ASSERT(s1);
|
||||
@@ -134,7 +142,10 @@ namespace BlackCore
|
||||
Q_ASSERT(s2);
|
||||
bool s3 = connect(this, &CAirspaceMonitor::removedAircraft, removedAircraftSlot);
|
||||
Q_ASSERT(s3);
|
||||
return s1 && s2 && s3;
|
||||
bool s4 = connect(this->m_analyzer, &CAirspaceAnalyzer::airspaceAircraftSnapshot, aircraftSnapshotSlot);
|
||||
Q_ASSERT(s4);
|
||||
|
||||
return s1 && s2 && s3 && s4;
|
||||
}
|
||||
|
||||
bool CAirspaceMonitor::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const QString &originator)
|
||||
|
||||
@@ -56,6 +56,10 @@ namespace BlackCore
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual int getAircraftInRangeCount() const override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::getLatestAirspaceAircraftSnapshot
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::remoteAircraftSituations
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual BlackMisc::Aviation::CAircraftSituationList remoteAircraftSituations(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||
@@ -142,12 +146,12 @@ namespace BlackCore
|
||||
//! Test injected aircraft parts
|
||||
void testAddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts, bool incremental);
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::connectSignals
|
||||
//! \copydoc IRemoteAircraftProvider::connectSignals
|
||||
//! \copydoc IRemoteAircraftProvider::connectRemoteAircraftProviderSignals
|
||||
virtual bool connectRemoteAircraftProviderSignals(
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> partsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> addedSituationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> addedPartsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
) override;
|
||||
|
||||
//! Is interim position sending enabled?
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "blackcorefreefunctions.h"
|
||||
#include "voice_channel.h"
|
||||
#include "network.h"
|
||||
#include "simulator.h"
|
||||
#include <QThread>
|
||||
|
||||
@@ -13,12 +14,13 @@ namespace BlackCore
|
||||
void registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<BlackCore::IVoiceChannel::ConnectionStatus>();
|
||||
qRegisterMetaType<BlackCore::INetwork::ConnectionStatus>();
|
||||
}
|
||||
|
||||
bool isCurrentThreadCreatingThread(QObject *toBeTested)
|
||||
{
|
||||
if (!toBeTested) return false;
|
||||
if (!toBeTested->thread()) return false;
|
||||
if (!toBeTested) { return false; }
|
||||
if (!toBeTested->thread()) { return false; }
|
||||
return (QThread::currentThreadId() == toBeTested->thread()->currentThreadId());
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace BlackCore
|
||||
//! \note this is the function which relays CLogMessage via DBus
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::Event::COriginator &origin) { Q_UNUSED(message); Q_UNUSED(origin); }
|
||||
|
||||
//! \brief Ping a token, used to check if application is alive
|
||||
//! Ping a token, used to check if application is alive
|
||||
virtual qint64 ping(qint64 token) const = 0;
|
||||
|
||||
//! A component has changed its state
|
||||
|
||||
@@ -128,10 +128,11 @@ namespace BlackCore
|
||||
bool CContextNetwork::connectRemoteAircraftProviderSignals(
|
||||
std::function<void (const CAircraftSituation &)> situationSlot,
|
||||
std::function<void (const CAircraftParts &)> partsSlot,
|
||||
std::function<void (const CCallsign &)> removedAircraftSlot)
|
||||
std::function<void (const CCallsign &)> removedAircraftSlot,
|
||||
std::function<void (const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot)
|
||||
{
|
||||
Q_ASSERT(this->m_airspace);
|
||||
return this->m_airspace->connectRemoteAircraftProviderSignals(situationSlot, partsSlot, removedAircraftSlot);
|
||||
return this->m_airspace->connectRemoteAircraftProviderSignals(situationSlot, partsSlot, removedAircraftSlot, aircraftSnapshotSlot);
|
||||
}
|
||||
|
||||
void CContextNetwork::gracefulShutdown()
|
||||
@@ -580,6 +581,11 @@ namespace BlackCore
|
||||
this->m_airspace->updateMarkAllAsNotRendered(originator);
|
||||
}
|
||||
|
||||
CAirspaceAircraftSnapshot CContextNetwork::getLatestAirspaceAircraftSnapshot() const
|
||||
{
|
||||
return this->m_airspace->getLatestAirspaceAircraftSnapshot();
|
||||
}
|
||||
|
||||
bool CContextNetwork::isFastPositionSendingEnabled() const
|
||||
{
|
||||
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
|
||||
@@ -74,9 +74,10 @@ namespace BlackCore
|
||||
//! \copydoc IRemoteAircraftProvider::connectSignals
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual bool connectRemoteAircraftProviderSignals(
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> partsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftSituation &)> addedSituationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CAircraftParts &)> addedPartsSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
) override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::updateAircraftRendered
|
||||
@@ -87,6 +88,10 @@ namespace BlackCore
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual void updateMarkAllAsNotRendered(const QString &originator) override;
|
||||
|
||||
//! \copydoc IRemoteAircraftProvider::getLatestAirspaceAircraftSnapshot
|
||||
//! \ingroup remoteaircraftprovider
|
||||
virtual BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const override;
|
||||
|
||||
public slots:
|
||||
//! \copydoc IContextNetwork::updateAircraftEnabled
|
||||
//! \ingroup remoteaircraftprovider
|
||||
|
||||
@@ -64,16 +64,19 @@ namespace BlackCore
|
||||
//! Current interpolated situation
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
|
||||
const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc, bool isVtolAircraft, InterpolationStatus &status) const = 0;
|
||||
const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc,
|
||||
bool isVtolAircraft, InterpolationStatus &status) const = 0;
|
||||
|
||||
//! Parts before given offset time (aka pending parts)
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime(const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTime, PartsStatus &partsStatus);
|
||||
virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime(
|
||||
const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTime,
|
||||
PartsStatus &partsStatus);
|
||||
|
||||
//! Enable debug messages
|
||||
void enableDebugMessages(bool enabled);
|
||||
|
||||
static const qint64 TimeOffsetMs = 6000; //!< offset for interpolation
|
||||
static const qint64 TimeOffsetMs = 6000; //!< offset for interpolation
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace BlackCore
|
||||
{
|
||||
CAircraftSituation CInterpolatorLinear::getInterpolatedSituation(const CCallsign &callsign, qint64 currentTimeMsSinceEpoc, bool vtolAiracraft, InterpolationStatus &status) const
|
||||
{
|
||||
// has to be thread safe
|
||||
|
||||
static const CAircraftSituation empty;
|
||||
status.reset();
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ namespace BlackCore
|
||||
|
||||
//! Log category
|
||||
static QString getMessageCategory() { return "swift.interpolatorlinear"; }
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
|
||||
@@ -552,4 +552,6 @@ namespace BlackCore
|
||||
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::INetwork::ConnectionStatus)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -20,19 +20,6 @@ using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
void ISimulator::emitSimulatorCombinedStatus()
|
||||
{
|
||||
int status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
;
|
||||
emit simulatorStatusChanged(status);
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
CSimulatorCommon::CSimulatorCommon(const CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
@@ -44,12 +31,45 @@ namespace BlackCore
|
||||
{
|
||||
this->setObjectName(info.getIdentifier());
|
||||
m_oneSecondTimer = new QTimer(this);
|
||||
m_oneSecondTimer->setObjectName(this->objectName().append(":OneSecondTimer"));
|
||||
m_oneSecondTimer->setObjectName(this->objectName().append(":m_oneSecondTimer"));
|
||||
connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer);
|
||||
m_oneSecondTimer->start(1000);
|
||||
|
||||
// provider signals
|
||||
bool c = remoteAircraftProvider->connectRemoteAircraftProviderSignals(
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderAddAircraftSituation, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorCommon::ps_remoteProvideraddAircraftParts, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderRemovedAircraft, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderAircraftSnapshot, this, std::placeholders::_1)
|
||||
);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
|
||||
// info
|
||||
CLogMessage(this).info("Initialized simulator driver %1") << m_simulatorPluginInfo.toQString();
|
||||
}
|
||||
|
||||
void ISimulator::ps_remoteProviderAddAircraftSituation(const CAircraftSituation &situation)
|
||||
{ Q_UNUSED(situation); }
|
||||
|
||||
void ISimulator::ps_remoteProvideraddAircraftParts(const CAircraftParts &parts)
|
||||
{ Q_UNUSED(parts); }
|
||||
|
||||
void ISimulator::ps_remoteProviderRemovedAircraft(const CCallsign &callsign)
|
||||
{ Q_UNUSED(callsign); }
|
||||
|
||||
void ISimulator::ps_remoteProviderAircraftSnapshot(const CAirspaceAircraftSnapshot &aircraftSnapshot)
|
||||
{ Q_UNUSED(aircraftSnapshot); }
|
||||
|
||||
void ISimulator::emitSimulatorCombinedStatus()
|
||||
{
|
||||
int status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0));
|
||||
emit simulatorStatusChanged(status);
|
||||
}
|
||||
|
||||
void CSimulatorCommon::blinkHighlightedAircraft()
|
||||
{
|
||||
if (m_highlightedAircraft.isEmpty() || m_highlightEndTimeMsEpoch < 1) { return; }
|
||||
@@ -202,11 +222,10 @@ namespace BlackCore
|
||||
return !m_maxRenderedDistance.isNull();
|
||||
}
|
||||
|
||||
void CSimulatorCommon::enableDebugMessages(bool driver, bool interpolator)
|
||||
void CSimulatorCommon::enableDebugMessages(bool driverMessages, bool interpolatorMessages)
|
||||
{
|
||||
this->m_debugMessages = driver;
|
||||
Q_UNUSED(interpolator);
|
||||
|
||||
this->m_debugMessages = driverMessages;
|
||||
Q_UNUSED(interpolatorMessages);
|
||||
}
|
||||
|
||||
int CSimulatorCommon::getInstalledModelsCount() const
|
||||
@@ -239,16 +258,6 @@ namespace BlackCore
|
||||
return this->isMaxDistanceRestricted() || this->isMaxAircraftRestricted();
|
||||
}
|
||||
|
||||
const CSimulatorPluginInfo &CSimulatorCommon::getSimulatorPluginInfo() const
|
||||
{
|
||||
return m_simulatorPluginInfo;
|
||||
}
|
||||
|
||||
const CSimulatorSetup &CSimulatorCommon::getSimulatorSetup() const
|
||||
{
|
||||
return m_simulatorSetup;
|
||||
}
|
||||
|
||||
void CSimulatorCommon::deleteAllRenderingRestrictions()
|
||||
{
|
||||
if (!isRenderingEnabled()) { return; }
|
||||
@@ -269,4 +278,17 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
const CSimulatorPluginInfo &CSimulatorCommon::getSimulatorPluginInfo() const
|
||||
{
|
||||
return m_simulatorPluginInfo;
|
||||
}
|
||||
|
||||
const CSimulatorSetup &CSimulatorCommon::getSimulatorSetup() const
|
||||
{
|
||||
return m_simulatorSetup;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -194,6 +194,19 @@ namespace BlackCore
|
||||
//! Installed aircraft models ready or changed
|
||||
void installedAircraftModelsChanged();
|
||||
|
||||
protected slots:
|
||||
//! Provider added situation
|
||||
virtual void ps_remoteProviderAddAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Provider added parts
|
||||
virtual void ps_remoteProvideraddAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts);
|
||||
|
||||
//! Provider removed aircraft
|
||||
virtual void ps_remoteProviderRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! Provider aircraft snapshot
|
||||
virtual void ps_remoteProviderAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &aircraftSnapshot);
|
||||
|
||||
protected:
|
||||
//! Default constructor
|
||||
ISimulator(QObject *parent = nullptr) : QObject(parent) {}
|
||||
@@ -201,15 +214,11 @@ namespace BlackCore
|
||||
//! Emit the combined status
|
||||
//! \sa simulatorStatusChanged;
|
||||
void emitSimulatorCombinedStatus();
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
* Interface to a simulator listener.
|
||||
*
|
||||
* The simulator listener is responsible for letting the core know when
|
||||
* the corresponding simulator is started.
|
||||
*/
|
||||
//! Interface to a simulator listener.
|
||||
//! The simulator listener is responsible for letting the core know when
|
||||
//! the corresponding simulator is started.
|
||||
class BLACKCORE_EXPORT ISimulatorListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -246,14 +255,12 @@ namespace BlackCore
|
||||
//! ISimulatorVirtual destructor
|
||||
virtual ~ISimulatorFactory() {}
|
||||
|
||||
//!
|
||||
//! Create a new instance of a driver
|
||||
//! \param info metadata about simulator
|
||||
//! \param ownAircraftProvider in memory access to own aircraft data
|
||||
//! \param renderedAircraftProvider in memory access to rendered aircraft data such as situation history and aircraft itself
|
||||
//! \param parent QObject
|
||||
//! \return driver instance
|
||||
//!
|
||||
virtual ISimulator *create(
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
@@ -297,7 +304,7 @@ namespace BlackCore
|
||||
virtual bool isMaxDistanceRestricted() const override;
|
||||
|
||||
//! \copydoc ISimulator::enableDebuggingMessages
|
||||
virtual void enableDebugMessages(bool driver, bool interpolator) override;
|
||||
virtual void enableDebugMessages(bool driverMessages, bool interpolatorMessages) override;
|
||||
|
||||
//! \copydoc ISimulator::getInstalledModelsCount
|
||||
virtual int getInstalledModelsCount() const override;
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace BlackCore
|
||||
class BLACKCORE_EXPORT IVoiceChannel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(ConnectionStatus)
|
||||
|
||||
public:
|
||||
//! Com status
|
||||
@@ -37,7 +38,7 @@ namespace BlackCore
|
||||
DisconnectedError, //!< Disconnected due to socket error
|
||||
Connecting, //!< Connection initiated but not established
|
||||
Connected, //!< Connection established
|
||||
ConnectingFailed, //!< Failed to connect
|
||||
ConnectingFailed //!< Failed to connect
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
@@ -98,7 +99,7 @@ namespace BlackCore
|
||||
protected:
|
||||
|
||||
};
|
||||
}
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::IVoiceChannel::ConnectionStatus)
|
||||
|
||||
|
||||
@@ -139,8 +139,11 @@ namespace BlackCore
|
||||
else emit audioStopped();
|
||||
}
|
||||
|
||||
void CVoiceChannelVatlib::updateRoomStatus(VatVoiceChannel /* channel */, VatConnectionStatus /** oldVatStatus **/, VatConnectionStatus newVatStatus)
|
||||
void CVoiceChannelVatlib::updateRoomStatus(VatVoiceChannel channel, VatConnectionStatus oldVatStatus, VatConnectionStatus newVatStatus)
|
||||
{
|
||||
Q_UNUSED(channel);
|
||||
Q_UNUSED(oldVatStatus);
|
||||
|
||||
IVoiceChannel::ConnectionStatus oldStatus = m_roomStatus;
|
||||
switch (newVatStatus)
|
||||
{
|
||||
@@ -202,4 +205,4 @@ namespace BlackCore
|
||||
auto obj = cbvar_cast_voiceChannel(cbVar);
|
||||
obj->updateRoomStatus(channel, oldStatus, newStatus);
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace BlackCore
|
||||
void userJoinedVoiceRoom(VatVoiceChannel, int id, const char *name);
|
||||
void userLeftVoiceRoom(VatVoiceChannel, int id, const char *name);
|
||||
void transmissionChanged(VatVoiceChannel, VatVoiceTransmissionStatus status);
|
||||
void updateRoomStatus(VatVoiceChannel channel, VatConnectionStatus /** oldStatus **/, VatConnectionStatus newStatus);
|
||||
void updateRoomStatus(VatVoiceChannel channel, VatConnectionStatus oldStatus, VatConnectionStatus newStatus);
|
||||
|
||||
static void processUserJoined(VatVoiceChannel channel, int id, const char *name, void *cbVar);
|
||||
static void processUserLeft(VatVoiceChannel channel, int id, const char *name, void *cbVar);
|
||||
|
||||
Reference in New Issue
Block a user