refs #789, added signal when adding models fails

Signatures in context and simulator
This commit is contained in:
Klaus Basan
2016-10-25 04:34:30 +02:00
parent 42737faf2c
commit df60474510
9 changed files with 37 additions and 13 deletions

View File

@@ -65,6 +65,5 @@ namespace BlackCore
if (!isSimulatorAvailable() || !getSimulatorStatusEnum().testFlag(ISimulator::Simulating)) { return false; } if (!isSimulatorAvailable() || !getSimulatorStatusEnum().testFlag(ISimulator::Simulating)) { return false; }
return true; return true;
} }
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -96,6 +96,9 @@ namespace BlackCore
//! A single model has been matched for given aircraft //! A single model has been matched for given aircraft
void modelMatchingCompleted(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); void modelMatchingCompleted(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Adding a remote aircraft failed
void addingRemoteModelFailed(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CStatusMessage &message);
//! Aircraft rendering changed //! Aircraft rendering changed
void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);

View File

@@ -357,6 +357,8 @@ namespace BlackCore
bool c = connect(simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged); bool c = connect(simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged);
Q_ASSERT(c); Q_ASSERT(c);
c = connect(simulator, &ISimulator::physicallyAddingRemoteModelFailed, this, &CContextSimulator::ps_addingRemoteAircraftFailed);
Q_ASSERT(c);
c = connect(simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged); c = connect(simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
Q_ASSERT(c); Q_ASSERT(c);
c = connect(simulator, &ISimulator::aircraftRenderingChanged, this, &IContextSimulator::aircraftRenderingChanged); c = connect(simulator, &ISimulator::aircraftRenderingChanged, this, &IContextSimulator::aircraftRenderingChanged);
@@ -483,13 +485,13 @@ namespace BlackCore
const CCallsign callsign = remoteAircraft.getCallsign(); const CCallsign callsign = remoteAircraft.getCallsign();
CStatusMessageList matchingMessages; CStatusMessageList matchingMessages;
CStatusMessageList *pMatchingMessages = m_enableMatchingMessages ? &matchingMessages : nullptr; CStatusMessageList *pMatchingMessages = m_enableMatchingMessages ? &matchingMessages : nullptr;
CMatchingUtils::addLogDetailsToList(pMatchingMessages, callsign, QString("Matching remote Aircraft"));
const CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(remoteAircraft, pMatchingMessages); const CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(remoteAircraft, pMatchingMessages);
addMatchingMessages(callsign, matchingMessages);
Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns"); Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns");
updateAircraftModel(callsign, aircraftModel, identifier()); updateAircraftModel(callsign, aircraftModel, identifier());
const CSimulatedAircraft aircraftAfterModelApplied = getAircraftInRangeForCallsign(remoteAircraft.getCallsign()); const CSimulatedAircraft aircraftAfterModelApplied = getAircraftInRangeForCallsign(remoteAircraft.getCallsign());
m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied); m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied);
CMatchingUtils::addLogDetailsToList(pMatchingMessages, callsign, QString("Logically added remote aircraft: %1").arg(aircraftAfterModelApplied.toQString()));
addMatchingMessages(callsign, matchingMessages);
emit modelMatchingCompleted(remoteAircraft); emit modelMatchingCompleted(remoteAircraft);
} }
@@ -560,6 +562,12 @@ namespace BlackCore
m_simulatorPlugin.second->changeRemoteAircraftEnabled(aircraft); m_simulatorPlugin.second->changeRemoteAircraftEnabled(aircraft);
} }
void CContextSimulator::ps_addingRemoteAircraftFailed(const CSimulatedAircraft &remoteAircraft, const CStatusMessage &message)
{
if (!isSimulatorSimulating()) { return; }
emit addingRemoteModelFailed(remoteAircraft, message);
}
void CContextSimulator::ps_updateSimulatorCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator) void CContextSimulator::ps_updateSimulatorCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator)
{ {
if (!isSimulatorSimulating()) { return; } if (!isSimulatorSimulating()) { return; }

View File

@@ -140,6 +140,9 @@ namespace BlackCore
//! Enable / disable aircraft //! Enable / disable aircraft
void ps_changedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); void ps_changedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Failed adding remote aircraft
void ps_addingRemoteAircraftFailed(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::CStatusMessage &message);
//! Update simulator cockpit from context, because someone else has changed cockpit (e.g. GUI, 3rd party) //! Update simulator cockpit from context, because someone else has changed cockpit (e.g. GUI, 3rd party)
//! \remarks set by runtime, only to be used locally (not via DBus) //! \remarks set by runtime, only to be used locally (not via DBus)
void ps_updateSimulatorCockpitFromContext(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft, const BlackMisc::CIdentifier &originator); void ps_updateSimulatorCockpitFromContext(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft, const BlackMisc::CIdentifier &originator);

View File

@@ -62,6 +62,9 @@ namespace BlackCore
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"weatherGridReceived", this, SIGNAL(weatherGridReceived(BlackMisc::Weather::CWeatherGrid, BlackMisc::CIdentifier))); "weatherGridReceived", this, SIGNAL(weatherGridReceived(BlackMisc::Weather::CWeatherGrid, BlackMisc::CIdentifier)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"addingRemoteModelFailed", this, SIGNAL(addingRemoteModelFailed(BlackMisc::Simulation::CSimulatedAircraft,BlackMisc::CStatusMessage&)));
Q_ASSERT(s);
Q_UNUSED(s); Q_UNUSED(s);
this->relayBaseClassSignals(serviceName, connection, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName()); this->relayBaseClassSignals(serviceName, connection, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName());
} }

View File

@@ -191,6 +191,9 @@ namespace BlackCore
//! Aircraft rendering changed //! Aircraft rendering changed
void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Adding the remote model failed
void physicallyAddingRemoteModelFailed(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::CStatusMessage &message);
//! An airspace snapshot was handled //! An airspace snapshot was handled
void airspaceSnapshotHandled(); void airspaceSnapshotHandled();

View File

@@ -73,7 +73,6 @@ namespace BlackSimPlugin
//! Set own model //! Set own model
void setOwnAircraftModel(const QString &modelName); void setOwnAircraftModel(const QString &modelName);
}; };
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -158,13 +158,13 @@ namespace BlackSimPlugin
// create AI // create AI
bool adding = false; bool adding = false;
const CAircraftModel aircraftModel = newRemoteAircraft.getModel(); const CAircraftModel aircraftModel = newRemoteAircraft.getModel();
CSimulatedAircraft remoteAircraftCopy(newRemoteAircraft); CSimulatedAircraft addedAircraft(newRemoteAircraft);
if (isConnected()) if (isConnected())
{ {
// initial position // initial position
setInitialAircraftSituation(remoteAircraftCopy); // set interpolated data/parts if available setInitialAircraftSituation(addedAircraft); // set interpolated data/parts if available
SIMCONNECT_DATA_INITPOSITION initialPosition = aircraftSituationToFsxInitPosition(remoteAircraftCopy.getSituation()); SIMCONNECT_DATA_INITPOSITION initialPosition = aircraftSituationToFsxInitPosition(addedAircraft.getSituation());
const QByteArray m = aircraftModel.getModelString().toLocal8Bit(); const QByteArray m = aircraftModel.getModelString().toLocal8Bit();
const int requestId = m_requestId; const int requestId = m_requestId;
@@ -172,7 +172,9 @@ namespace BlackSimPlugin
HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, m.constData(), qPrintable(callsign.toQString().left(12)), initialPosition, static_cast<SIMCONNECT_DATA_REQUEST_ID>(requestId)); HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, m.constData(), qPrintable(callsign.toQString().left(12)), initialPosition, static_cast<SIMCONNECT_DATA_REQUEST_ID>(requestId));
if (hr != S_OK) if (hr != S_OK)
{ {
CLogMessage(this).error("SimConnect, can not create AI traffic: '%1' '%2'") << callsign.toQString() << aircraftModel.getModelString(); const CStatusMessage msg = CStatusMessage(this).error("SimConnect, can not create AI traffic: '%1' '%2'") << callsign.toQString() << aircraftModel.getModelString();
CLogMessage::preformatted(msg);
emit physicallyAddingRemoteModelFailed(addedAircraft, msg);
} }
else else
{ {
@@ -304,7 +306,10 @@ namespace BlackSimPlugin
CCallsignSet CSimulatorFsx::physicallyRenderedAircraft() const CCallsignSet CSimulatorFsx::physicallyRenderedAircraft() const
{ {
return CCollection<CCallsign>(this->m_simConnectObjects.keys()); CCallsignSet callsigns(this->m_simConnectObjects.keys());
callsigns.push_back(m_aircraftToAddAgainWhenRemoved.getCallsigns()); // not really rendered right now, but very soon
callsigns.push_back(m_outOfRealityBubble.getCallsigns()); // not really rendered, but for the logic it should look like it is
return CCallsignSet(this->m_simConnectObjects.keys());
} }
void CSimulatorFsx::setSimConnected() void CSimulatorFsx::setSimConnected()
@@ -950,6 +955,5 @@ namespace BlackSimPlugin
emit simulatorStarted(this->getPluginInfo()); emit simulatorStarted(this->getPluginInfo());
} }
} }
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -141,12 +141,15 @@ namespace BlackSimPlugin
case SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID: case SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID:
{ {
SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *event = static_cast<SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *>(pData); SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *event = static_cast<SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *>(pData);
DWORD requestID = event->dwRequestID; const DWORD requestID = event->dwRequestID;
DWORD objectID = event->dwObjectID; const DWORD objectID = event->dwObjectID;
const bool success = simulatorFsx->aiAircraftWasAddedInSimulator(requestID, objectID); const bool success = simulatorFsx->aiAircraftWasAddedInSimulator(requestID, objectID);
if (!success) if (!success)
{ {
CLogMessage(simulatorFsx).warning("Cannot find CSimConnectObject for request %1") << requestID; CLogMessage(simulatorFsx).warning("Cannot find CSimConnectObject for request %1") << requestID;
const CSimulatedAircraft remoteAircraft(simulatorFsx->getSimObjectForObjectId(objectID).getAircraft());
const QString msg("Object id for request " + QString::number(requestID) + " not avialable");
emit simulatorFsx->physicallyAddingRemoteModelFailed(remoteAircraft, CStatusMessage(simulatorFsx, CStatusMessage::SeverityError, msg));
} }
break; break;
} }
@@ -246,6 +249,5 @@ namespace BlackSimPlugin
} // main switch } // main switch
} // method } // method
} // namespace } // namespace
} // namespace } // namespace