From b6afcefd593fab58b2aac7e25c3a9ff69aa56855 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 28 May 2014 13:19:31 +0200 Subject: [PATCH] refs #242, adjusted network context * some formatting * own aircraft data used for voice room member resolution --- src/blackcore/context_network.h | 3 +++ src/blackcore/context_network_atc.cpp | 35 ++++++++++++++++++------- src/blackcore/context_network_impl.cpp | 10 ++++++- src/blackcore/context_network_proxy.cpp | 3 +++ src/blackcore/context_network_proxy.h | 18 +++++-------- 5 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index fd1ff8536..e04b020a8 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -53,6 +53,9 @@ namespace BlackCore //! ATC station (booked) list has been changed void changedAtcStationsBooked(); + //! Connection status changed for online station + void changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &atcStation, bool connected); + //! Aircraft list has been changed void changedAircraftsInRange(); diff --git a/src/blackcore/context_network_atc.cpp b/src/blackcore/context_network_atc.cpp index c5577a17d..9f4d20a96 100644 --- a/src/blackcore/context_network_atc.cpp +++ b/src/blackcore/context_network_atc.cpp @@ -145,8 +145,12 @@ namespace BlackCore CAtcStation s; CAtcStationList stations; - stations.push_back(stationsCom1.isEmpty() ? s : stationsCom1[0]); - stations.push_back(stationsCom2.isEmpty() ? s : stationsCom2[0]); + CAtcStation com1 = stationsCom1.isEmpty() ? s : stationsCom1[0]; + CAtcStation com2 = stationsCom2.isEmpty() ? s : stationsCom2[0]; + + stations.push_back(com1); + stations.push_back(com2); + return stations; } @@ -168,7 +172,6 @@ namespace BlackCore */ void CContextNetwork::psFsdAtcPositionUpdate(const CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range) { - // this->log(Q_FUNC_INFO, callsign.toQString(), frequency.toQString(), position.toQString(), range.toQString()); CAtcStationList stationsWithCallsign = this->m_atcStationsOnline.findByCallsign(callsign); if (stationsWithCallsign.isEmpty()) { @@ -182,14 +185,17 @@ namespace BlackCore station.calculcateDistanceToPlane(this->ownAircraft().getPosition()); this->m_vatsimDataFileReader->getAtcStations().updateFromVatsimDataFileStation(station); // prefill this->m_atcStationsOnline.push_back(station); - emit this->changedAtcStationsOnline(); if (this->isConnected()) { - emit this->m_network->sendAtisQuery(callsign); // request ATIS emit this->m_network->sendRealNameQuery(callsign); + emit this->m_network->sendAtisQuery(callsign); // request ATIS and voice rooms emit this->m_network->sendServerQuery(callsign); } + + emit this->changedAtcStationsOnline(); + // Remark: this->changedAtcStationOnlineConnectionStatus(station, true); + // will be sent in psFsdAtisVoiceRoomQueryReceived } else { @@ -208,8 +214,15 @@ namespace BlackCore */ void CContextNetwork::psFsdAtcControllerDisconnected(const CCallsign &callsign) { - this->m_atcStationsOnline.removeIf(&CAtcStation::getCallsign, callsign); - emit this->changedAtcStationsOnline(); + if (this->m_atcStationsOnline.contains(&CAtcStation::getCallsign, callsign)) + { + CAtcStation removeStation = this->m_atcStationsOnline.findByCallsign(callsign).front(); + this->m_atcStationsOnline.removeIf(&CAtcStation::getCallsign, callsign); + emit this->changedAtcStationsOnline(); + emit this->changedAtcStationOnlineConnectionStatus(removeStation, false); + } + + // booked this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, CIndexVariantMap(CAtcStation::IndexIsOnline, QVariant(false))); } @@ -235,7 +248,12 @@ namespace BlackCore CIndexVariantMap vm(CAtcStation::IndexVoiceRoomUrl, trimmedUrl); this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm); this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm); - if (this->m_atcStationsOnline.contains(&CAtcStation::getCallsign, callsign)) emit this->changedAtcStationsBooked(); + if (this->m_atcStationsOnline.contains(&CAtcStation::getCallsign, callsign)) + { + CAtcStation station = this->m_atcStationsOnline.findFirstByCallsign(callsign); + emit this->changedAtcStationsBooked(); + emit this->changedAtcStationOnlineConnectionStatus(station, true); + } if (this->m_atcStationsBooked.contains(&CAtcStation::getCallsign, callsign)) emit this->changedAtcStationsBooked(); } @@ -267,7 +285,6 @@ namespace BlackCore */ void CContextNetwork::psFsdMetarReceived(const QString &metarMessage) { - // this->log(Q_FUNC_INFO, metarMessage); if (metarMessage.length() < 10) return; // invalid const QString icaoCode = metarMessage.left(4).toUpper(); const QString icaoCodeTower = icaoCode + "_TWR"; diff --git a/src/blackcore/context_network_impl.cpp b/src/blackcore/context_network_impl.cpp index ca56df291..e06b5687b 100644 --- a/src/blackcore/context_network_impl.cpp +++ b/src/blackcore/context_network_impl.cpp @@ -314,6 +314,14 @@ namespace BlackCore if (callsigns.isEmpty()) return users; CCallsignList searchList(callsigns); + // myself, which is not in the lists below + CAircraft ownAircraft = this->getOwnAircraft(); + if (!ownAircraft.getCallsign().isEmpty() && searchList.contains(ownAircraft.getCallsign())) + { + searchList.remove(ownAircraft.getCallsign()); + users.push_back(ownAircraft.getPilot()); + } + // do aircrafts first, this will handle most callsigns foreach(CAircraft aircraft, this->m_aircraftsInRange) { @@ -408,7 +416,7 @@ namespace BlackCore } // send as message - QString m("connection status changed from %1 to %2"); + QString m("Connection status changed from %1 to %2"); m = m.arg(INetwork::connectionStatusToString(from), INetwork::connectionStatusToString(to)); if (!message.isEmpty()) m.append(" ").append(message); msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, diff --git a/src/blackcore/context_network_proxy.cpp b/src/blackcore/context_network_proxy.cpp index 470f65fc1..674e2d96a 100644 --- a/src/blackcore/context_network_proxy.cpp +++ b/src/blackcore/context_network_proxy.cpp @@ -37,6 +37,9 @@ namespace BlackCore s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), "changedAtcStationsOnline", this, SIGNAL(changedAtcStationsOnline())); Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedAtcStationOnlineConnectionStatus", this, SIGNAL(changedAtcStationOnlineConnectionStatus(BlackMisc::Aviation::CAtcStation,bool))); + Q_ASSERT(s); s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), "connectionTerminated", this, SIGNAL(connectionTerminated())); Q_ASSERT(s); diff --git a/src/blackcore/context_network_proxy.h b/src/blackcore/context_network_proxy.h index d6e638140..7b934854d 100644 --- a/src/blackcore/context_network_proxy.h +++ b/src/blackcore/context_network_proxy.h @@ -20,7 +20,7 @@ namespace BlackCore { - //! \brief Network context proxy + //! Network context proxy class CContextNetworkProxy : public IContextNetwork { Q_OBJECT @@ -34,14 +34,14 @@ namespace BlackCore private: BlackMisc::CGenericDBusInterface *m_dBusInterface; /*!< DBus interface */ - //! \brief Relay connection signals to local signals. + //! Relay connection signals to local signals. void relaySignals(const QString &serviceName, QDBusConnection &connection); protected: - //! \brief Constructor + //! Constructor CContextNetworkProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextNetwork(mode, runtime), m_dBusInterface(nullptr) {} - //! \brief DBus version constructor + //! DBus version constructor CContextNetworkProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime); public slots: // IContextNetwork overrides @@ -49,16 +49,10 @@ namespace BlackCore //! \copydoc IContextNetwork::readAtcBookingsFromSource() virtual void readAtcBookingsFromSource() const override; - /*! - * \copydoc IContextNetwork::getAtcStationsOnline() - * \todo If I make this &getAtcStations XML is not generated correctly, needs to be crosschecked with the latest version of Qt - */ + //! \copydoc IContextNetwork::getAtcStationsOnline() virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override; - /*! - * \copydoc IContextNetwork::getAtcStationsBooked() - * \todo If I make this &getAtcStations XML is not generated correctly - */ + //! \copydoc IContextNetwork::getAtcStationsBooked() virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override; //! \copydoc IContextNetwork::getAircraftsInRange()