39 using namespace swift::config;
42 using namespace swift::misc::physical_quantities;
43 using namespace swift::misc::aviation;
44 using namespace swift::misc::network;
45 using namespace swift::misc::simulation;
46 using namespace swift::misc::simulation::xplane;
47 using namespace swift::misc::geo;
48 using namespace swift::misc::weather;
49 using namespace swift::misc::simulation;
50 using namespace swift::misc::simulation::settings;
51 using namespace swift::misc::simulation::data;
52 using namespace std::chrono_literals;
54 namespace swift::core::context
59 this->setObjectName(
"CContextSimulator");
62 Q_ASSERT_X(
sApp, Q_FUNC_INFO,
"Need sApp");
63 MatchingLog logMatchingMessages =
64 CBuildConfig::isLocalDeveloperDebugBuild() ? MatchingLogAll : MatchingLogSimplified;
65 m_logMatchingMessages = logMatchingMessages;
67 this->restoreSimulatorPlugins();
70 connect(&CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance(),
74 const QPointer<CContextSimulator> myself(
this);
76 if (!myself) {
return; }
77 this->initByLastUsedModelSet();
78 m_aircraftMatcher.
setSetup(m_matchingSettings.
get());
90 Qt::QueuedConnection);
92 m_validator->start(QThread::LowestPriority);
93 m_validator->startUpdating(60);
98 void CContextSimulator::setValidator(
const CSimulatorInfo &simulator)
120 disconnect(m_validator);
122 m_validator->deleteLater();
123 m_validator =
nullptr;
125 this->stopSimulatorListeners();
127 this->unloadSimulatorPlugin();
131 m_listenersThread.quit();
132 m_listenersThread.wait(10 * 1000);
137 if (!m_plugins) {
return {}; }
144 if (!p.
isValid()) {
return {}; }
152 if (!
simulator.isSingleSimulator()) {
return false; }
154 if (simSettings == settings) {
return false; }
163 return this->listenForSimulator(simulatorInfo);
168 if (!m_simulatorPlugin.first.isUnspecified() && m_simulatorPlugin.first == simulatorInfo)
170 this->unloadSimulatorPlugin();
181 if (!m_plugins) {
return 0; }
189 return m_simulatorPlugin.second->getSimulatorStatus();
196 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return unspecified; }
197 if (m_simulatorPlugin.first.getSimulator().contains(
"emulated", Qt::CaseInsensitive))
199 return m_simulatorPlugin.second->getSimulatorPluginInfo();
201 return m_simulatorPlugin.first;
207 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return CSimulatorInternals(); }
208 return m_simulatorPlugin.second->getSimulatorInternals();
217 CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().synchronizeCache(
simulator);
218 return CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().getCachedModels(
simulator);
224 if (m_simulatorPlugin.second)
226 if (m_simulatorPlugin.second->isConnected())
228 if (m_simulatorPlugin.second->isEmulatedDriver())
233 return m_simulatorPlugin.first.getSimulatorInfo();
236 return m_modelSetSimulator.
get();
241 Q_ASSERT_X(
simulator.isSingleSimulator(), Q_FUNC_INFO,
"Need single simulator");
252 return CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().simulatorsWithInitializedCache();
263 u
"No model set so far, you need at least one model set. Hint: You can create a model set in the "
264 u
"mapping tool, or copy an existing set in the launcher."));
285 if (removeModels.
isEmpty()) {
return 0; }
287 if (!
simulator.isSingleSimulator()) {
return 0; }
289 CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().synchronizeCache(
simulator);
291 CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().getCachedModels(
simulator);
295 CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().setCachedModels(models,
simulator);
309 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return 0; }
316 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return; }
323 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return CAircraftModelList(); }
330 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return; }
337 if (!m_validator) {
return false; }
344 if (!m_validator) {
return false; }
345 const QString simDir =
356 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return CAircraftModelList(); }
364 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return m_renderSettings.
get(); }
365 return m_simulatorPlugin.second->getInterpolationSetupGlobal();
371 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return CInterpolationSetupList(); }
372 return m_simulatorPlugin.second->getInterpolationSetupsPerCallsign();
379 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified())
383 return m_simulatorPlugin.second->getInterpolationSetupPerCallsignOrDefault(callsign);
387 bool ignoreSameAsGlobal)
390 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return false; }
391 return m_simulatorPlugin.second->setInterpolationSetupsPerCallsign(setups, ignoreSameAsGlobal);
403 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return; }
404 m_simulatorPlugin.second->setInterpolationSetupGlobal(setup);
411 if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) {
return CStatusMessageList(); }
412 return m_simulatorPlugin.second->getInterpolationMessages(callsign);
423 if (!m_simulatorPlugin.first.isUnspecified())
430 if (!simulatorPluginInfo.
isValid())
437 Q_ASSERT_X(factory, Q_FUNC_INFO,
"no factory");
442 "Need implementing object");
448 factory->create(simulatorPluginInfo, ownAircraftProvider, renderedAircraftProvider, clientProvider);
449 Q_ASSERT_X(
simulator, Q_FUNC_INFO,
"no simulator driver can be created");
457 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"Invalid simulator from plugin");
462 u
"Emulated driver does NOT provide valid simulator, using default '%1', plugin: '%2'")
473 m_modelSetSimulator.
set(simInfo);
475 m_aircraftMatcher.
setModelSet(modelSetModels, simInfo,
true);
482 &CContextSimulator::onAddingRemoteAircraftFailed);
485 &CContextSimulator::onOwnSimulatorModelChanged);
514 &CContextSimulator::relayStatusMessageToSimulator);
517 &CContextSimulator::relayStatusMessageToSimulator);
522 m_initallyAddAircraft =
true;
523 m_wasSimulating =
false;
524 m_matchingMessages.clear();
525 m_failoverAddingCounts.clear();
528 const bool connected =
simulator->connectTo();
531 CLogMessage(
this).
error(u
"Simulator plugin connection to simulator '%1' failed")
537 m_simulatorPlugin.first = simulatorPluginInfo;
539 m_simulatorPlugin.second->setInterpolationSetupGlobal(m_renderSettings.
get());
542 QPointer<CContextSimulator> myself(
this);
545 if (m_simulatorPlugin.second)
547 CLogMessage(this).info(u
"Simulator plugin loaded: '%1' connected: %2")
548 << simulatorPluginInfo.toQString(true) << boolToYesNo(connected);
551 emit this->simulatorPluginChanged(m_simulatorPlugin.second->getSimulatorPluginInfo());
552 emit this->simulatorChanged(m_simulatorPlugin.second->getSimulatorInfo());
564 Q_ASSERT(m_simulatorPlugin.first.isUnspecified());
566 if (!m_listenersThread.isRunning())
568 m_listenersThread.setObjectName(
"CContextSimulator: Thread for listener " + simulatorInfo.
getIdentifier());
569 m_listenersThread.start(QThread::LowPriority);
573 if (!listener) {
return false; }
575 if (listener->thread() != &m_listenersThread)
577 Q_ASSERT_X(!listener->parent(), Q_FUNC_INFO,
"Objects with parent cannot be moved to thread");
580 &CContextSimulator::onSimulatorStarted, Qt::QueuedConnection);
586 listener->setProperty(
"isInitialized",
true);
587 listener->moveToThread(&m_listenersThread);
591 if (!listener->isRunning())
594 Q_ASSERT_X(s, Q_FUNC_INFO,
"cannot invoke method");
601 void CContextSimulator::listenForAllSimulators()
606 Q_ASSERT(!p.isUnspecified());
607 if (p.isValid()) { this->listenForSimulator(p); }
611 void CContextSimulator::unloadSimulatorPlugin()
613 if (!m_simulatorPlugin.first.isUnspecified())
615 ISimulator *
simulator = m_simulatorPlugin.second;
623 m_simulatorPlugin.second =
nullptr;
641 m_wasSimulating =
false;
645 void CContextSimulator::xCtxAddedRemoteAircraftReadyForModelMatching(
const CSimulatedAircraft &remoteAircraft)
651 if (callsign.
isEmpty()) {
return; }
656 MatchingLog whatToLog = m_logMatchingMessages;
658 CStatusMessageList *pMatchingMessages = m_logMatchingMessages > 0 ? &matchingMessages :
nullptr;
660 m_aircraftMatcher.
getClosestMatch(remoteAircraft, whatToLog, pMatchingMessages,
true);
661 Q_ASSERT_X(remoteAircraft.
getCallsign() == aircraftModel.
getCallsign(), Q_FUNC_INFO,
"Mismatching callsigns");
665 const CLength cgSim = m_simulatorPlugin.second->getSimulatorCGPerModelString(aircraftModel.
getModelString());
669 case CSimulatorSettings::CGFromSimulatorOnly: aircraftModel.
setCG(cgSim);
break;
670 case CSimulatorSettings::CGFromSimulatorFirst:
671 if (!cgSim.
isNull()) { aircraftModel.
setCG(cgSim); }
673 case CSimulatorSettings::CGFromDBFirst:
674 if (cgModel.
isNull()) { aircraftModel.
setCG(cgSim); }
681 m_simulatorPlugin.second->overriddenCGorDefault(CLength::null(), aircraftModel.
getModelString());
682 if (!overriddenCG.
isNull()) { aircraftModel.
setCG(overriddenCG); }
691 if (!aircraftAfterModelApplied.
hasCallsign()) {
return; }
702 brokenAircraft.setEnabled(
false);
703 brokenAircraft.setRendered(
false);
704 CCallsign::addLogDetailsToList(
705 pMatchingMessages, callsign,
706 QStringLiteral(
"Cannot add remote aircraft, no model string: '%1'").arg(brokenAircraft.toQString()));
712 m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied);
713 CCallsign::addLogDetailsToList(
714 pMatchingMessages, callsign,
715 QStringLiteral(
"Logically added remote aircraft: %1").arg(aircraftAfterModelApplied.
toQString()));
717 this->clearMatchingMessages(callsign);
718 this->addMatchingMessages(callsign, matchingMessages);
724 void CContextSimulator::xCtxRemovedRemoteAircraft(
const CCallsign &callsign)
727 m_simulatorPlugin.second->logicallyRemoveRemoteAircraft(callsign);
728 m_failoverAddingCounts.remove(callsign);
731 void CContextSimulator::onSimulatorStatusChanged(ISimulator::SimulatorStatus status)
738 Q_ASSERT_X(networkContext, Q_FUNC_INFO,
"Need context");
739 Q_ASSERT_X(networkContext->isLocalObject(), Q_FUNC_INFO,
"Need local object");
745 SWIFT_VERIFY_X(!simulatedAircraft.getCallsign().isEmpty(), Q_FUNC_INFO,
"Need callsign");
746 this->xCtxAddedRemoteAircraftReadyForModelMatching(simulatedAircraft);
748 m_initallyAddAircraft =
false;
755 this->unloadSimulatorPlugin();
756 this->restoreSimulatorPlugins();
759 m_wasSimulating =
false;
772 for (
const auto &tm : textMessages)
775 m_simulatorPlugin.second->displayTextMessage(tm);
779 void CContextSimulator::xCtxChangedRemoteAircraftModel(
const CSimulatedAircraft &aircraft,
784 m_simulatorPlugin.second->changeRemoteAircraftModel(aircraft);
787 void CContextSimulator::xCtxChangedOwnAircraftModel(
const CAircraftModel &aircraftModel,
796 void CContextSimulator::xCtxChangedRemoteAircraftEnabled(
const CSimulatedAircraft &aircraft)
799 m_simulatorPlugin.second->changeRemoteAircraftEnabled(aircraft);
802 void CContextSimulator::xCtxNetworkConnectionStatusChanged(
const CConnectionStatus &from,
807 if (to.
isConnected() && this->getIContextNetwork())
810 if (m_simulatorPlugin.second)
812 m_simulatorPlugin.second->setFlightNetworkConnected(
true);
817 m_networkSessionId.clear();
819 m_matchingMessages.clear();
820 m_failoverAddingCounts.clear();
822 if (m_simulatorPlugin.second)
824 m_simulatorPlugin.second->removeAllRemoteAircraft();
825 m_simulatorPlugin.second->setFlightNetworkConnected(
false);
830 void CContextSimulator::onAddingRemoteAircraftFailed(
const CSimulatedAircraft &remoteAircraft,
bool disabled,
839 bool failover = requestFailover;
845 const int trial = m_failoverAddingCounts.value(cs, 0);
846 if (trial < MaxModelAddedFailoverTrials)
848 m_failoverAddingCounts[cs] = trial + 1;
854 CLogMessage(
this).
warning(u
"Model for '%1' failed adding, tried %2 time(s) to resolve, giving up")
862 void CContextSimulator::xCtxUpdateSimulatorCockpitFromContext(
const CSimulatedAircraft &ownAircraft,
869 m_simulatorPlugin.second->updateOwnSimulatorCockpit(ownAircraft, originator);
872 void CContextSimulator::xCtxUpdateSimulatorSelcalFromContext(
const CSelcal &selcal,
const CIdentifier &originator)
878 m_simulatorPlugin.second->updateOwnSimulatorSelcal(selcal, originator);
881 void CContextSimulator::xCtxNetworkRequestedNewAircraft(
const CCallsign &callsign,
const QString &aircraftIcao,
882 const QString &airlineIcao,
const QString &livery)
884 if (m_networkSessionId.isEmpty()) {
return; }
895 m_simulatorPlugin.second->displayStatusMessage(message);
899 void CContextSimulator::changeEnabledSimulators()
902 const QStringList enabledSimulators = m_enabledSimulators.getThreadLocal();
907 unloadSimulatorPlugin();
910 restoreSimulatorPlugins();
913 void CContextSimulator::restoreSimulatorPlugins()
915 if (!m_simulatorPlugin.first.isUnspecified()) {
return; }
917 this->stopSimulatorListeners();
918 const QStringList enabledSimulators = m_enabledSimulators.getThreadLocal();
929 return m_matchingMessages[callsign];
935 return m_logMatchingMessages;
944 if (m_logMatchingMessages == enabled) {
return; }
945 m_logMatchingMessages = enabled;
973 return m_aircraftMatcher.
getSetup();
978 if (!m_simulatorPlugin.second || !m_simulatorPlugin.second->isConnected()) {
return false; }
982 m_simulatorPlugin.second->setTestMode(
true);
983 added = m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraft);
987 m_simulatorPlugin.second->logicallyRemoveRemoteAircraft(aircraft.
getCallsign());
988 m_simulatorPlugin.second->setTestMode(
false);
996 if (!m_simulatorPlugin.second || !m_simulatorPlugin.second->isConnected()) {
return false; }
999 return m_simulatorPlugin.second->testSendSituationAndParts(cs, s, parts);
1004 Q_UNUSED(originator)
1005 if (commandLine.isEmpty()) {
return false; }
1007 ".plugin",
".drv",
".driver",
1010 parser.
parse(commandLine);
1011 if (!parser.isKnownCommand()) {
return false; }
1012 if (parser.matchesCommand(
"ris"))
1015 const QString p1 = parser.part(1);
1016 if (!parser.hasPart(2)) {
return false; }
1020 else {
return false; }
1025 if (parser.matchesCommand(
"plugin") || parser.matchesCommand(
"drv") || parser.matchesCommand(
"driver"))
1027 if (!m_simulatorPlugin.second) {
return false; }
1028 return m_simulatorPlugin.second->parseCommandLine(commandLine, originator);
1036 return m_simulatorPlugin.second;
1042 if (!m_simulatorPlugin.second) {
return false; }
1043 return m_simulatorPlugin.second->followAircraft(callsign);
1049 if (!m_simulatorPlugin.second) {
return; }
1050 m_simulatorPlugin.second->recalculateAllAircraft();
1056 if (aircraft.
getCallsign() != callsign) {
return false; }
1059 m_simulatorPlugin.second->logicallyRemoveRemoteAircraft(callsign);
1061 QPointer<CContextSimulator> myself(
this);
1064 this->xCtxAddedRemoteAircraftReadyForModelMatching(aircraft);
1072 if (!m_simulatorPlugin.second || !m_simulatorPlugin.second->isConnected()) {
return false; }
1073 return m_simulatorPlugin.second->requestElevationBySituation(situation);
1084 if (!m_simulatorPlugin.second || !m_simulatorPlugin.second->isConnected()) {
return CElevationPlane::null(); }
1085 return m_simulatorPlugin.second->findClosestElevationWithinRange(reference, range);
1092 if (callsigns.
isEmpty()) {
return 0; }
1094 QPointer<CContextSimulator> myself(
this);
1099 this->doMatchingAgain(cs);
1103 return callsigns.
size();
1115 QPointer<CContextSimulator> myself(
this);
1122 resetAircraft.setEnabled(
true);
1123 this->xCtxAddedRemoteAircraftReadyForModelMatching(resetAircraft);
1130 this->stopSimulatorListeners();
1131 this->loadSimulatorPlugin(info);
1134 if (m_logMatchingMessages)
1136 const QPointer<CContextSimulator> myself(
this);
1138 if (!myself) {
return; }
1141 const MatchingLog log = CBuildConfig::isDebugBuild() ? MatchingLogAll : MatchingLogSimplified;
1142 this->enableMatchingMessages(log);
1148 void CContextSimulator::onOwnSimulatorModelChanged(
const CAircraftModel &model)
1151 if (!lookupModel.isLoadedFromDb()) { lookupModel = this->reverseLookupModel(model); }
1155 void CContextSimulator::stopSimulatorListeners()
1163 Q_ASSERT_X(s, Q_FUNC_INFO,
"Cannot invoke stop");
1171 if (callsign.
isEmpty()) {
return; }
1172 if (messages.
isEmpty()) {
return; }
1173 if (!m_logMatchingMessages) {
return; }
1174 if (m_matchingMessages.contains(callsign))
1179 else { m_matchingMessages.insert(callsign, messages); }
1182 void CContextSimulator::clearMatchingMessages(
const CCallsign &callsign)
1184 if (callsign.
isEmpty()) {
return; }
1185 m_matchingMessages.remove(callsign);
1190 bool modified =
false;
1192 CDatabaseUtils::consolidateOwnAircraftModelWithDbData(model,
false, &modified);
1193 return reverseModel;
1196 void CContextSimulator::initByLastUsedModelSet()
1200 CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().synchronizeCache(
simulator);
1202 CLogMessage(
this).
info(u
"Init aircraft matcher with %1 models from set for '%2'")
1203 << models.size() <<
simulator.toQString();
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
void setupChanged()
Setup changed.
void evaluateStatisticsEntry(const QString &sessionId, const swift::misc::aviation::CCallsign &callsign, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery)
Evaluate if a statistics entry makes sense and add it.
void clearMatchingStatistics()
Clear the statistics.
void setDefaultModel(const swift::misc::simulation::CAircraftModel &defaultModel)
Set default model, can be set by driver specific for simulator.
swift::misc::simulation::CAircraftMatcherSetup getSetup() const
Get the setup.
void addingRemoteModelFailed(const swift::misc::simulation::CSimulatedAircraft &remoteAircraft)
Adding a model failed.
virtual int getModelSetCount() const
Model set count.
int setModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator, bool forced)
Set the models we want to use.
const swift::misc::simulation::CMatchingStatistics & getCurrentStatistics() const
The current statistics.
swift::misc::simulation::CAircraftModelList getDisabledModelsForMatching() const
The disabled models for matching.
bool setSetup(const swift::misc::simulation::CAircraftMatcherSetup &setup)
Set the setup.
swift::misc::simulation::CAircraftModel getClosestMatch(const swift::misc::simulation::CSimulatedAircraft &remoteAircraft, swift::misc::simulation::MatchingLog whatToLog, swift::misc::CStatusMessageList *log, bool useMatchingScript) const
Get the closest matching aircraft model from set. Result depends on setup.
void disableModelsForMatching(const swift::misc::simulation::CAircraftModelList &removedModels, bool incremental)
Remove a model for matching.
void restoreDisabledModels()
Restore the models removed with CAircraftMatcher::disableModelForMatching.
bool isShuttingDown() const
Is application shutting down?
ContextMode
How to handle a given context.
The class providing facades (the contexts) for all DBus relevant operations.
context::CContextNetwork * getCContextNetwork()
Context for network.
context::CContextOwnAircraft * getCContextOwnAircraft()
Context for own aircraft.
Manages plugins for the simulator context.
virtual void collectPlugins()
Looks for all available plugins.
swift::misc::simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const
Get all simulator driver plugins.
ISimulatorListener * createListener(const QString &pluginId)
Create simulator listener from the plugin In case one is existing already, it is returned instead....
int checkAvailableListeners()
Check if simulator is connected.
ISimulatorFactory * getFactory(const QString &pluginId)
Get simulator factory from the plugin.
ISimulatorListener * getListener(const QString &pluginId)
Get previously created simulator listener from the plugin Returns nullptr if listener is not yet crea...
void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const swift::misc::physical_quantities::CLength &maxRenderedDistance)
Render restrictions have been changed.
void physicallyAddingRemoteModelFailed(const swift::misc::simulation::CSimulatedAircraft &remoteAircraft, bool disabled, bool requestFailover, const swift::misc::CStatusMessage &message)
Adding the remote model failed.
void ownAircraftModelChanged(const swift::misc::simulation::CAircraftModel &model)
Emitted when own aircraft model has changed.
void simulatorStatusChanged(swift::core::ISimulator::SimulatorStatus status)
Simulator combined status.
void insufficientFrameRateDetected(bool fatal)
Frame rate has fallen too far below the threshold to maintain consistent sim rate.
void autoPublishDataWritten(const swift::misc::simulation::CSimulatorInfo &simulator)
Auto publish data written for simulator.
void airspaceSnapshotHandled()
An airspace snapshot was handled.
@ Disconnected
not connected, and hence not simulating/paused
@ Simulating
Is the simulator actually simulating?
@ Connected
Is the plugin connected to the simulator?
@ Unspecified
unspecied, needed as default value
void aircraftRenderingChanged(const swift::misc::simulation::CSimulatedAircraft &aircraft)
Aircraft rendering changed.
void driverMessages(const swift::misc::CStatusMessageList &messages)
Relevant simulator messages to be explicitly displayed.
void interpolationAndRenderingSetupChanged()
Interpolation or rendering setup changed.
Interface to a simulator listener.
void simulatorStarted(const swift::misc::simulation::CSimulatorPluginInfo &info)
Emitted when the listener discovers the simulator running.
void start()
Start listening for the simulator to start.
void stop()
Stops listening.
virtual bool followAircraft(const swift::misc::aviation::CCallsign &callsign)
Follow aircraft im simulator view.
virtual bool setSimulatorSettings(const swift::misc::simulation::settings::CSimulatorSettings &settings, const swift::misc::simulation::CSimulatorInfo &simulator)
Set settings for give simulator.
virtual swift::misc::CStatusMessageList verifyPrerequisites() const
Verify prerequisites for simulation like an existing model set.
virtual bool resetToModelMatchingAircraft(const swift::misc::aviation::CCallsign &callsign)
Reset model by matching it again.
virtual ISimulator::SimulatorStatus getSimulatorStatus() const
Simulator combined status.
virtual void setInterpolationAndRenderingSetupGlobal(const swift::misc::simulation::CInterpolationAndRenderingSetupGlobal &setup)
Set the global setup.
virtual swift::misc::simulation::CAircraftMatcherSetup getMatchingSetup() const
Get matching setup.
virtual swift::misc::simulation::CAircraftModelList getModelSet() const
Installed models in simulator eco system.
virtual bool isKnownModelInSet(const QString &modelString) const
Known model?
virtual swift::misc::simulation::CInterpolationSetupList getInterpolationAndRenderingSetupsPerCallsign() const
Get all setups per callsign.
virtual swift::misc::simulation::CAircraftModelList getModelSetModelsStartingWith(const QString &modelString) const
Models for model string.
virtual swift::misc::geo::CElevationPlane findClosestElevationWithinRange(const swift::misc::geo::CCoordinateGeodetic &reference, const swift::misc::physical_quantities::CLength &range) const
Find closest elevation (or return NULL)
virtual bool startSimulatorPlugin(const swift::misc::simulation::CSimulatorPluginInfo &simulatorInfo)
Load and start specific simulator plugin.
virtual void disableModelsForMatching(const swift::misc::simulation::CAircraftModelList &removedModels, bool incremental)
Remove a model for matching.
virtual swift::misc::simulation::CSimulatorInternals getSimulatorInternals() const
Simulator setup.
virtual swift::misc::CStatusMessageList getMatchingMessages(const swift::misc::aviation::CCallsign &callsign) const
Get mapping messages.
virtual QStringList getModelSetCompleterStrings(bool sorted) const
Model set completer string.
virtual bool triggerModelSetValidation(const swift::misc::simulation::CSimulatorInfo &simulator)
Trigger model set validation.
virtual int removeModelsFromSet(const swift::misc::simulation::CAircraftModelList &removeModels)
Remove models from set.
static void registerHelp()
Register dot commands.
virtual bool testUpdateRemoteAircraft(const swift::misc::aviation::CCallsign &cs, const swift::misc::aviation::CAircraftSituation &situation, const swift::misc::aviation::CAircraftParts &parts)
Test update remote aircraft.
virtual void setModelSetLoaderSimulator(const swift::misc::simulation::CSimulatorInfo &simulator)
Set the model set loader simulator directly.
virtual void recalculateAllAircraft()
Recalculate all aircraft.
virtual swift::misc::simulation::CInterpolationAndRenderingSetupGlobal getInterpolationAndRenderingSetupGlobal() const
The global setup.
virtual bool testRemoteAircraft(const swift::misc::simulation::CSimulatedAircraft &aircraft, bool add)
Test a remote aircraft.
virtual bool doMatchingAgain(const swift::misc::aviation::CCallsign &callsign)
Repeat the matching callsign.
virtual bool requestElevationBySituation(const swift::misc::aviation::CAircraftSituation &situation)
Request elevation, there is no guarantee the requested elevation will be available in the provider.
virtual void restoreDisabledModels()
Restore the models removed with CAircraftMatcher::disableModelForMatching.
virtual swift::misc::simulation::CSimulatorInfo getModelSetLoaderSimulator() const
Get the model set loader simulator directly.
virtual int doMatchingsAgain()
Repeat all matchings.
virtual swift::misc::simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const
Return list of available simulator plugins.
void gracefulShutdown()
Gracefully shut down, e.g. for plugin unloading.
virtual swift::misc::simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const
Simulator info, currently loaded plugin.
virtual swift::misc::simulation::CSimulatorInfo simulatorsWithInitializedModelSet() const
Simulators which have an initialized model set.
virtual swift::misc::CStatusMessageList getInterpolationMessages(const swift::misc::aviation::CCallsign &callsign) const
Interpolation messages.
virtual swift::misc::simulation::settings::CSimulatorSettings getSimulatorSettings() const
Get the current simulator settings.
virtual void setMatchingSetup(const swift::misc::simulation::CAircraftMatcherSetup &setup)
Set matching setup.
virtual int checkListeners()
Check all listeners enabled if simulator is connected.
virtual swift::misc::simulation::CMatchingStatistics getCurrentMatchingStatistics(bool missingOnly) const
Current matching statistics.
virtual bool isValidationInProgress() const
Validation in progress.
QPointer< ISimulator > simulator() const
Access to simulator (i.e. the plugin)
virtual swift::misc::simulation::CInterpolationAndRenderingSetupPerCallsign getInterpolationAndRenderingSetupPerCallsignOrDefault(const swift::misc::aviation::CCallsign &callsign) const
Get the setup for callsign, if not existing the global setup.
virtual int getModelSetCount() const
Number of installed models in simulator eco system.
virtual swift::misc::simulation::MatchingLog isMatchingMessagesEnabled() const
Enabled mapping logging?
virtual void stopSimulatorPlugin(const swift::misc::simulation::CSimulatorPluginInfo &simulatorInfo)
Stop listener or unload the given plugin (if currently loaded)
virtual bool setInterpolationAndRenderingSetupsPerCallsign(const swift::misc::simulation::CInterpolationSetupList &setups, bool ignoreSameAsGlobal)
Set all setups per callsign.
virtual QStringList getModelSetStrings() const
Model strings.
virtual void enableMatchingMessages(swift::misc::simulation::MatchingLog enabled)
Enable mapping logging.
bool isSimulatorPluginAvailable() const
Simulator plugin available?
virtual ~CContextSimulator()
Destructor.
virtual swift::misc::simulation::CAircraftModelList getDisabledModelsForMatching() const
The disabled models for matching.
void changedLogOrDebugSettings()
Log or debug values changed.
CCoreFacade * getRuntime()
Runtime.
bool isUsingImplementingObject() const
Using local implementing object?
IContextNetwork * getIContextNetwork()
Context for network.
bool isLocalObject() const
Local or remote object?
const IContextApplication * getIContextApplication() const
Context for application.
IContextOwnAircraft * getIContextOwnAircraft()
Context for own aircraft.
bool isDebugEnabled() const
Debug enabled?
virtual swift::misc::network::CServer getConnectedServer() const =0
Server which is connected, if not connected empty default object.
virtual swift::misc::simulation::CSimulatedAircraft getOwnAircraft() const =0
Get own aircraft.
void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const swift::misc::physical_quantities::CLength &maxRenderedDistance)
Render restrictions have been changed.
void validatedModelSet(const swift::misc::simulation::CSimulatorInfo &simulator, const swift::misc::simulation::CAircraftModelList &valid, const swift::misc::simulation::CAircraftModelList &invalid, bool stopped, const swift::misc::CStatusMessageList &msgs)
Validated model set.
void addingRemoteModelFailed(const swift::misc::simulation::CSimulatedAircraft &aircraft, bool disabled, bool failover, const swift::misc::CStatusMessage &message)
Adding a remote aircraft failed.
static const QString & InterfaceName()
Service name.
void vitalityLost()
A formerly vital driver is no longer vital/responding.
bool isSimulatorAvailable() const
Simulator avialable (driver available)?
void interpolationAndRenderingSetupChanged()
Setup changed.
void autoPublishDataWritten(const swift::misc::simulation::CSimulatorInfo &simulator)
Auto publish data written for simulator.
void ownAircraftModelChanged(const swift::misc::simulation::CAircraftModel &model)
Emitted when own aircraft model changes.
void simulatorChanged(const swift::misc::simulation::CSimulatorInfo &simulator)
Same as simulatorPluginChanged, only with simulator signature.
void modelSetChanged(const swift::misc::simulation::CSimulatorInfo &simulator)
Model set ready or changed.
void simulatorPluginChanged(const swift::misc::simulation::CSimulatorPluginInfo &info)
Simulator plugin loaded / unloaded (default info)
void modelMatchingCompleted(const swift::misc::simulation::CSimulatedAircraft &aircraft)
A single model has been matched for given aircraft.
void matchingSetupChanged()
Matching setup changed.
void driverMessages(const swift::misc::CStatusMessageList &messages)
Relevant simulator messages to be explicitly displayed.
void simulatorStatusChanged(int status)
Simulator combined status.
void insufficientFrameRateDetected(bool fatal)
Frame rate has fallen too far below the threshold to maintain consistent sim rate.
void simulatorSettingsChanged()
Simulator settings have been changed.
void airspaceSnapshotHandled()
An airspace snapshot was handled.
void aircraftRenderingChanged(const swift::misc::simulation::CSimulatedAircraft &aircraft)
Aircraft rendering changed.
CStatusMessage setAndSave(const T &value, qint64 timestamp=0)
Write and save in the same step. Must be called from the thread in which the owner lives.
const T & getThreadLocal() const
Read the current value.
T get() const
Get a copy of the current value.
size_type size() const
Returns number of elements in the collection.
bool isEmpty() const
Synonym for empty.
void quitAndWait() noexcept final
Calls quit() and blocks until the thread is finished.
CStatusMessage set(const typename Trait::type &value, qint64 timestamp=0)
Write a new value. Must be called from the thread in which the owner lives.
Base class with a member CIdentifier to be inherited by a class which has an identity in the environm...
bool isMyIdentifier(const CIdentifier &otherIdentifier) const
My identifier?
const CIdentifier & identifier() const
Get identifier.
Value object encapsulating information identifying a component of a modular distributed swift process...
const QString & getName() const
Name.
static const QString & contextSlot()
Context slots.
static const QString & cmdLine()
Cmd.line parsing.
void localMessageLogged(const swift::misc::CStatusMessage &message)
Emitted when a message is logged in this process.
static CLogHandler * instance()
Return pointer to the CLogHandler singleton.
void remoteMessageLogged(const swift::misc::CStatusMessage &message)
Emitted when a log message is relayed from a different process.
Class for emitting a log message.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & debug()
Set the severity to debug.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
size_type size() const
Returns number of elements in the sequence.
void push_back(const T &value)
Appends an element at the end of the sequence.
bool isEmpty() const
Synonym for empty.
Utility methods for simple line parsing used with the command line.
void parse(const QString &commandLine)
Parse.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
static bool thisIsMainThread()
Is the current thread the application thread?
Value object encapsulating information of aircraft's parts.
Value object encapsulating information of an aircraft's situation.
void setCallsign(const CCallsign &callsign)
Corresponding callsign.
Value object encapsulating information of a callsign.
const QString & asString() const
Get callsign (normalized)
bool isEmpty() const
Is empty?
Value object for a set of callsigns.
QString convertToQString(bool i18n=false) const
Cast as QString.
Plane of same elevation, can be a single point or larger area (e.g. airport)
QString toQString(bool i18n=false) const
Cast as QString.
Value object encapsulating information about a connection status.
bool isConnected() const
Query status.
bool isDisconnected() const
Query status.
QString getServerSessionId(bool onlyConnected) const
Identifying a session, if not connected empty.
Value object encapsulating a list of text messages.
Direct in memory access to client (network client) data.
Physical unit length (length)
bool isNull() const
Is quantity null?
bool doModelAddFailover() const
Failover if model cannot be loaded.
Aircraft model (used by another pilot, my models on disk)
const aviation::CCallsign & getCallsign() const
Corresponding callsign if applicable.
const QString & getModelString() const
Model key, either queried or loaded from simulator model.
const physical_quantities::CLength & getCG() const
Get center of gravity.
void setCG(const physical_quantities::CLength &cg)
Get center of gravity.
Value object encapsulating a list of aircraft models.
QStringList getModelStringList(bool sort=true) const
Model strings.
QStringList toCompleterStrings(bool sorted=true, const CSimulatorInfo &simulator={ CSimulatorInfo::All }) const
Completer strings.
CAircraftModelList findModelsStartingWith(const QString &modelString, Qt::CaseSensitivity sensitivity=Qt::CaseInsensitive) const
Find models starting with.
int removeModelsWithString(const CAircraftModelList &models, Qt::CaseSensitivity sensitivity)
Remove those models with given model strings.
bool containsModelString(const QString &modelString, Qt::CaseSensitivity sensitivity=Qt::CaseInsensitive) const
Contains model string?
Validate model files from the sets and check if the model still exists.
bool isValidating() const
Validation in progress.
void setCurrentSimulator(const CSimulatorInfo &simulator, const QString &simDirectory, const QStringList &modelDirList)
Corresponding simulator.
bool triggerValidation(const CSimulatorInfo &simulator, const QString &simDirectory)
Trigger a validation, returns false if "work in progress".
void validated(const CSimulatorInfo &simulator, const CAircraftModelList &validModels, const CAircraftModelList &invalidModels, bool stopped, const CStatusMessageList &msgs)
Validated for simulator.
bool setEnabledAircraftParts(bool enabled)
Set enabled aircraft parts.
void setSimulatorDebuggingMessages(bool debug)
Debugging messages for simulation.
Value object for interpolator and rendering.
Value object for interpolator and rendering per callsign.
Value object for matching statistics.
CMatchingStatistics findMissingOnly() const
Find entires denoting missing entries only.
aviation::CCallsignSet getAircraftInRangeCallsigns() const
Unique callsigns for aircraft in range.
bool isAircraftInRange(const aviation::CCallsign &callsign) const
Is aircraft in range?
void updateMarkAllAsNotRendered()
Mark all as not rendered.
CSimulatedAircraft getAircraftInRangeForCallsign(const aviation::CCallsign &callsign) const
Aircraft for callsign.
void setRemoteAircraftProvider(IRemoteAircraftProvider *remoteAircraftProvider)
Set remote aircraft provider.
bool updateAircraftModel(const aviation::CCallsign &callsign, const CAircraftModel &model, const CIdentifier &originator)
Change model.
Comprehensive information of an aircraft.
bool hasModelString() const
Has model string?
void setModel(const CAircraftModel &model)
Set model.
const simulation::CAircraftModel & getNetworkModel() const
Get network model.
bool hasCallsign() const
Callsign not empty, no further checks.
const aviation::CCallsign & getCallsign() const
Get callsign.
bool resetToNetworkModel()
Reset to the newtork model.
Value object encapsulating a list of aircraft.
Simple hardcoded info about the corresponding simulator.
bool isSingleSimulator() const
Single simulator selected.
bool isNoSimulator() const
No simulator?
static const CSimulatorInfo & p3d()
Const simulator info objects.
Simulator internals for flight simulators. Those are obtained from a running simulator and represent ...
Describing a simulator plugin.
const QString & getIdentifier() const
Identifier.
const CSimulatorInfo & getSimulatorInfo() const
Simulator info object.
bool isUnspecified() const
Unspecified simulator.
bool isValid() const
Check if the provided plugin metadata is valid. Simulator plugin (driver) has to meet the following r...
Value object encapsulating a list of SimulatorInfo objects.
Direct threadsafe in memory access to own aircraft.
Direct thread safe in memory access to remote aircraft.
CStatusMessage setSettings(const CSimulatorSettings &settings, const CSimulatorInfo &simulator)
Set settings per simulator.
QStringList getModelDirectoriesOrDefault(const CSimulatorInfo &simulator) const
Model directory or default model path per simulator.
CSimulatorSettings getSettings(const CSimulatorInfo &simulator) const
Settings per simulator.
QString getSimulatorDirectoryOrDefault(const CSimulatorInfo &simulator) const
Simulator directory or default model path per simulator.
Settings regarding message handling. Driver independent part, related to network.
bool relayThisTextMessage(const network::CTextMessage &msg, const CSimulatedAircraft &aircraft) const
Relay given text message.
bool relayThisStatusMessage(const CStatusMessage &message) const
Relay this particular message.
Settings for simulator Driver independent parts (such as directories), also used in model loaders.
CGSource getCGSource() const
CG source.
virtual bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator)
Parse a given command line.
Classes interacting with the swift database (aka "datastore").
Free functions in swift::misc.
SWIFT_MISC_EXPORT bool stringToBool(const QString &boolString)
Convert string to bool.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.