mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
refs #369, first version of IRenderedAircraftProvider in airspace monitor
(no aircraft parts yet)
This commit is contained in:
@@ -26,8 +26,9 @@ using namespace BlackMisc::PhysicalQuantities;
|
||||
namespace BlackCore
|
||||
{
|
||||
|
||||
CAirspaceMonitor::CAirspaceMonitor(QObject *parent, const BlackMisc::Simulation::IOwnAircraftProviderReadOnly *ownAircraft, INetwork *network, CVatsimBookingReader *bookings, CVatsimDataFileReader *dataFile)
|
||||
: QObject(parent), COwnAircraftProviderSupportReadOnly(ownAircraft), m_network(network), m_vatsimBookingReader(bookings), m_vatsimDataFileReader(dataFile),
|
||||
CAirspaceMonitor::CAirspaceMonitor(QObject *parent, const BlackMisc::Simulation::IOwnAircraftProviderReadOnly *ownAircraftProvider, INetwork *network, CVatsimBookingReader *bookings, CVatsimDataFileReader *dataFile)
|
||||
: QObject(parent), COwnAircraftProviderSupportReadOnly(ownAircraftProvider),
|
||||
m_network(network), m_vatsimBookingReader(bookings), m_vatsimDataFileReader(dataFile),
|
||||
m_atcWatchdog(this), m_aircraftWatchdog(this)
|
||||
{
|
||||
this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CAirspaceMonitor::ps_atcPositionUpdate);
|
||||
@@ -54,7 +55,29 @@ namespace BlackCore
|
||||
// ATC stations send updates every 25 s. Configure timeout after 50 s.
|
||||
this->m_atcWatchdog.setTimeout(CTime(50, CTimeUnit::s()));
|
||||
this->connect(&this->m_aircraftWatchdog, &CAirspaceWatchdog::timeout, this, &CAirspaceMonitor::ps_pilotDisconnected);
|
||||
this->connect(&this->m_atcWatchdog, &CAirspaceWatchdog::timeout, this, &CAirspaceMonitor::ps_atcControllerDisconnected);
|
||||
this->connect(&this->m_atcWatchdog, &CAirspaceWatchdog::timeout, this, &CAirspaceMonitor::ps_atcControllerDisconnected);
|
||||
}
|
||||
|
||||
bool CAirspaceMonitor::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const QString &originator)
|
||||
{
|
||||
CPropertyIndexVariantMap vm(CSimulatedAircraft::IndexEnabled, CVariant::fromValue(enabledForRedering));
|
||||
Q_UNUSED(originator);
|
||||
int c = m_aircraftInRange.applyIfCallsign(callsign, vm);
|
||||
return c > 0;
|
||||
}
|
||||
|
||||
bool CAirspaceMonitor::updateAircraftModel(const CCallsign &callsign, const CAircraftModel &model, const QString &originator)
|
||||
{
|
||||
Q_UNUSED(originator);
|
||||
CSimulatedAircraft aircraft = m_aircraftInRange.findFirstByCallsign(callsign);
|
||||
if (!aircraft.hasValidCallsign()) { return false; }
|
||||
|
||||
CAircraftModel newModel(model);
|
||||
aircraft.setModel(newModel); // this consolidates all common data such as callsign, ICAO ...
|
||||
|
||||
CPropertyIndexVariantMap vm(CSimulatedAircraft::IndexModel, aircraft.getModel().toCVariant());
|
||||
int c = m_aircraftInRange.applyIfCallsign(callsign, vm);
|
||||
return c > 0;
|
||||
}
|
||||
|
||||
CFlightPlan CAirspaceMonitor::loadFlightPlanFromNetwork(const CCallsign &callsign)
|
||||
@@ -213,12 +236,6 @@ namespace BlackCore
|
||||
return station;
|
||||
}
|
||||
|
||||
CAircraftSituationList CAirspaceMonitor::getAircraftSituations(const CCallsign &callsign) const
|
||||
{
|
||||
if (callsign.isEmpty()) { return this->m_aircraftSituations; }
|
||||
return this->m_aircraftSituations.findByCallsign(callsign);
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::requestDataUpdates()
|
||||
{
|
||||
if (!this->m_network->isConnected()) return;
|
||||
@@ -270,7 +287,7 @@ namespace BlackCore
|
||||
void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname)
|
||||
{
|
||||
Q_ASSERT(this->m_vatsimDataFileReader);
|
||||
if (realname.isEmpty()) return;
|
||||
if (realname.isEmpty()) { return; }
|
||||
CPropertyIndexVariantMap vm({CAtcStation::IndexController, CUser::IndexRealName}, realname);
|
||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
@@ -653,7 +670,7 @@ namespace BlackCore
|
||||
if (!exists)
|
||||
{
|
||||
// new aircraft
|
||||
CAircraft aircraft;
|
||||
CSimulatedAircraft aircraft;
|
||||
aircraft.setCallsign(callsign);
|
||||
aircraft.setSituation(situation);
|
||||
aircraft.setTransponder(transponder);
|
||||
@@ -681,9 +698,9 @@ namespace BlackCore
|
||||
this->m_otherClients.push_back(c); // initial, will be filled by data later
|
||||
}
|
||||
|
||||
// only if still connected
|
||||
if (this->m_network->isConnected())
|
||||
{
|
||||
// only if still connected
|
||||
// the order here makes some sense, as we hope to receive ICAO codes last, and everthing else already in place
|
||||
this->sendFsipirCustomPacket(callsign); // own aircraft model
|
||||
this->m_network->sendFrequencyQuery(callsign);
|
||||
@@ -702,12 +719,12 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
this->m_aircraftWatchdog.addCallsign(callsign);
|
||||
emit this->addedAircraft(callsign, situation);
|
||||
emit this->addedAircraft(aircraft);
|
||||
} // connected
|
||||
}
|
||||
else // not exists yet
|
||||
else
|
||||
{
|
||||
// update
|
||||
// update, aircraft already exists
|
||||
CLength distance = ownAircraft().calculateGreatCircleDistance(situation.getPosition());
|
||||
distance.switchUnit(CLengthUnit::NM());
|
||||
CPropertyIndexVariantMap vm;
|
||||
@@ -718,7 +735,6 @@ namespace BlackCore
|
||||
// here I expect always a changed value
|
||||
this->m_aircraftInRange.applyIfCallsign(callsign, vm);
|
||||
this->m_aircraftWatchdog.resetCallsign(callsign);
|
||||
emit this->changedAircraftSituation(callsign, situation);
|
||||
}
|
||||
|
||||
emit this->changedAircraftInRange();
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
#ifndef BLACKCORE_AIRSPACE_MONITOR_H
|
||||
#define BLACKCORE_AIRSPACE_MONITOR_H
|
||||
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/avatcstationlist.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/simulation/simdirectaccessownaircraft.h"
|
||||
#include "blackmisc/simulation/simdirectaccessrenderedaircraft.h"
|
||||
#include "blackmisc/avatcstationlist.h"
|
||||
#include "blackmisc/avaircraftsituationlist.h"
|
||||
#include "blackmisc/nwclientlist.h"
|
||||
#include "blackmisc/avflightplan.h"
|
||||
#include "blackmisc/nwuserlist.h"
|
||||
#include "blackmisc/avcallsignlist.h"
|
||||
#include "blackmisc/simulation/simdirectaccessownaircraft.h"
|
||||
#include "network.h"
|
||||
#include "vatsimbookingreader.h"
|
||||
#include "vatsimdatafilereader.h"
|
||||
@@ -34,7 +34,8 @@ namespace BlackCore
|
||||
*/
|
||||
class CAirspaceMonitor :
|
||||
public QObject,
|
||||
public BlackMisc::Simulation::COwnAircraftProviderSupportReadOnly
|
||||
public BlackMisc::Simulation::COwnAircraftProviderSupportReadOnly,
|
||||
public BlackMisc::Simulation::IRenderedAircraftProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -42,6 +43,24 @@ namespace BlackCore
|
||||
//! Constructor
|
||||
CAirspaceMonitor(QObject *parent, const BlackMisc::Simulation::IOwnAircraftProviderReadOnly *ownAircraft, INetwork *network, CVatsimBookingReader *bookings, CVatsimDataFileReader *dataFile);
|
||||
|
||||
//! \copydoc IRenderedAircraftProviderReadOnly::renderedAircraft
|
||||
virtual const BlackMisc::Simulation::CSimulatedAircraftList &renderedAircraft() const override { return m_aircraftInRange; }
|
||||
|
||||
//! \copydoc IRenderedAircraftProvider::renderedAircraft
|
||||
virtual BlackMisc::Simulation::CSimulatedAircraftList &renderedAircraft() override { return m_aircraftInRange; }
|
||||
|
||||
//! \copydoc IRenderedAircraftProvider::renderedAircraftSituations
|
||||
virtual const BlackMisc::Aviation::CAircraftSituationList &renderedAircraftSituations() const override { return m_aircraftSituations; }
|
||||
|
||||
//! \copydoc IRenderedAircraftProvider::renderedAircraftSituations
|
||||
virtual BlackMisc::Aviation::CAircraftSituationList &renderedAircraftSituations() override { return m_aircraftSituations; }
|
||||
|
||||
//! \copydoc IRenderedAircraftProvider::updateAircraftEnabled
|
||||
virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const QString &originator) override;
|
||||
|
||||
//! \copydoc IRenderedAircraftProvider::updateAircraftModel
|
||||
virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const QString &originator) override;
|
||||
|
||||
//! Returns the list of users we know about
|
||||
BlackMisc::Network::CUserList getUsers() const;
|
||||
|
||||
@@ -67,15 +86,9 @@ namespace BlackCore
|
||||
//! Returns the current booked ATC stations
|
||||
BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const { return m_atcStationsBooked; }
|
||||
|
||||
//! Returns the current aircraft in range
|
||||
BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const { return m_aircraftInRange; }
|
||||
|
||||
//! Returns the closest ATC station operating on the given frequency, if any
|
||||
BlackMisc::Aviation::CAtcStation getAtcStationForComUnit(const BlackMisc::Aviation::CComSystem &comSystem);
|
||||
|
||||
//! Aircraft situations, empty callsign means all
|
||||
BlackMisc::Aviation::CAircraftSituationList getAircraftSituations(const BlackMisc::Aviation::CCallsign &callsign = {}) const;
|
||||
|
||||
//! Request to update other clients' data from the network
|
||||
void requestDataUpdates();
|
||||
|
||||
@@ -99,16 +112,13 @@ namespace BlackCore
|
||||
void changedAircraftInRange();
|
||||
|
||||
//! A new aircraft appeared
|
||||
void addedAircraft(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &initialSituation);
|
||||
|
||||
//! An aircraft's situation was changed
|
||||
void changedAircraftSituation(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
void addedAircraft(const BlackMisc::Simulation::CSimulatedAircraft &renderedAircraft);
|
||||
|
||||
//! An aircraft disappeared
|
||||
void removedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! Read for model matching
|
||||
void readyForModelMatching(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft);
|
||||
void readyForModelMatching(const BlackMisc::Simulation::CSimulatedAircraft &renderedAircraft);
|
||||
|
||||
public:
|
||||
//! Clear the contents
|
||||
@@ -125,11 +135,11 @@ namespace BlackCore
|
||||
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CFlightPlan> m_flightPlanCache;
|
||||
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CAircraftIcao> m_icaoCodeCache;
|
||||
|
||||
INetwork *m_network = nullptr;
|
||||
INetwork *m_network = nullptr;
|
||||
CVatsimBookingReader *m_vatsimBookingReader = nullptr;
|
||||
CVatsimDataFileReader *m_vatsimDataFileReader = nullptr;
|
||||
CAirspaceWatchdog m_atcWatchdog;
|
||||
CAirspaceWatchdog m_aircraftWatchdog;
|
||||
CAirspaceWatchdog m_atcWatchdog;
|
||||
CAirspaceWatchdog m_aircraftWatchdog;
|
||||
|
||||
// TODO FIXME (MS) should be in INetwork
|
||||
void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &recipientCallsign) const;
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace BlackCore
|
||||
virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const override
|
||||
{
|
||||
BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
|
||||
return this->m_airspace->getAircraftInRange();
|
||||
return this->m_airspace->renderedAircraft();
|
||||
}
|
||||
|
||||
//! \copydoc IContextNetwork::connectToNetwork()
|
||||
|
||||
65
src/blackmisc/simulation/simdirectaccessrenderedaircraft.cpp
Normal file
65
src/blackmisc/simulation/simdirectaccessrenderedaircraft.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "simdirectaccessrenderedaircraft.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
const CSimulatedAircraftList &CRenderedAircraftProviderSupportReadOnly::renderedAircraft() const
|
||||
{
|
||||
Q_ASSERT_X(this->m_renderedAircraftProvider, "renderedAircraft", "No object available");
|
||||
return this->m_renderedAircraftProvider->renderedAircraft();
|
||||
}
|
||||
|
||||
const Aviation::CAircraftSituationList &CRenderedAircraftProviderSupportReadOnly::renderedAircraftSituations() const
|
||||
{
|
||||
Q_ASSERT_X(this->m_renderedAircraftProvider, "renderedAircraftSituations", "No object available");
|
||||
return this->m_renderedAircraftProvider->renderedAircraftSituations();
|
||||
}
|
||||
|
||||
const CSimulatedAircraftList &CRenderedAircraftProviderSupport::renderedAircraft() const
|
||||
{
|
||||
Q_ASSERT_X(this->m_renderedAircraftProvider, "renderedAircraft", "No object available");
|
||||
return this->m_renderedAircraftProvider->renderedAircraft();
|
||||
}
|
||||
|
||||
CSimulatedAircraftList &CRenderedAircraftProviderSupport::renderedAircraft()
|
||||
{
|
||||
Q_ASSERT_X(this->m_renderedAircraftProvider, "renderedAircraft", "No object available");
|
||||
return this->m_renderedAircraftProvider->renderedAircraft();
|
||||
}
|
||||
|
||||
const Aviation::CAircraftSituationList &CRenderedAircraftProviderSupport::renderedAircraftSituations() const
|
||||
{
|
||||
Q_ASSERT_X(this->m_renderedAircraftProvider, "renderedAircraftSituations", "No object available");
|
||||
return this->m_renderedAircraftProvider->renderedAircraftSituations();
|
||||
}
|
||||
|
||||
Aviation::CAircraftSituationList &CRenderedAircraftProviderSupport::renderedAircraftSituations()
|
||||
{
|
||||
Q_ASSERT_X(this->m_renderedAircraftProvider, "renderedAircraftSituations", "No object available");
|
||||
return this->m_renderedAircraftProvider->renderedAircraftSituations();
|
||||
}
|
||||
|
||||
bool CRenderedAircraftProviderSupport::providerUpdateAircraftModel(const Aviation::CCallsign &callsign, const CAircraftModel &model, const QString &originator)
|
||||
{
|
||||
Q_ASSERT_X(this->m_renderedAircraftProvider, "providerUpdateAircraftModel", "No object available");
|
||||
return this->m_renderedAircraftProvider->updateAircraftModel(callsign, model, originator);
|
||||
}
|
||||
|
||||
bool CRenderedAircraftProviderSupport::providerUpdateAircraftEnabled(const Aviation::CCallsign &callsign, bool enabledForRedering, const QString &originator)
|
||||
{
|
||||
Q_ASSERT_X(this->m_renderedAircraftProvider, "providerUpdateAircraftEnabled", "No object available");
|
||||
return this->m_renderedAircraftProvider->updateAircraftEnabled(callsign, enabledForRedering, originator);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
100
src/blackmisc/simulation/simdirectaccessrenderedaircraft.h
Normal file
100
src/blackmisc/simulation/simdirectaccessrenderedaircraft.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMDIRECTACCESSRENDEREDAIRCRAFT_H
|
||||
#define BLACKMISC_SIMDIRECTACCESSRENDEREDAIRCRAFT_H
|
||||
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/avaircraftsituationlist.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
//! Direct in memory access to rendered aircraft
|
||||
class IRenderedAircraftProviderReadOnly
|
||||
{
|
||||
public:
|
||||
//! All rendered aircraft
|
||||
virtual const CSimulatedAircraftList &renderedAircraft() const = 0;
|
||||
|
||||
//! All rendered aircraft
|
||||
virtual const BlackMisc::Aviation::CAircraftSituationList &renderedAircraftSituations() const = 0;
|
||||
|
||||
//! Destructor
|
||||
virtual ~IRenderedAircraftProviderReadOnly() {}
|
||||
};
|
||||
|
||||
//! Direct in memory access to own aircraft
|
||||
class IRenderedAircraftProvider : public IRenderedAircraftProviderReadOnly
|
||||
{
|
||||
public:
|
||||
//! All rendered aircraft
|
||||
virtual CSimulatedAircraftList &renderedAircraft() = 0;
|
||||
|
||||
//! Rendered aircraft situations (history)
|
||||
virtual BlackMisc::Aviation::CAircraftSituationList &renderedAircraftSituations() = 0;
|
||||
|
||||
//! Enable/disable rendering
|
||||
virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const QString &originator) = 0;
|
||||
|
||||
//! Change model string
|
||||
virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const QString &originator) = 0;
|
||||
};
|
||||
|
||||
//! Class which can be directly used providing access to such an interface
|
||||
class CRenderedAircraftProviderSupportReadOnly
|
||||
{
|
||||
public:
|
||||
//! \copydoc IRenderedAircraftProviderReadOnly::renderedAircraft
|
||||
virtual const CSimulatedAircraftList &renderedAircraft() const;
|
||||
|
||||
//!\copydoc IRenderedAircraftProviderReadOnly::renderedAircraftSituations
|
||||
virtual const BlackMisc::Aviation::CAircraftSituationList &renderedAircraftSituations() const = 0;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CRenderedAircraftProviderSupportReadOnly(const IRenderedAircraftProviderReadOnly *renderedAircraftProvider) : m_renderedAircraftProvider(renderedAircraftProvider) {}
|
||||
const IRenderedAircraftProviderReadOnly *m_renderedAircraftProvider = nullptr; //!< access to object
|
||||
};
|
||||
|
||||
//! Delegating class which can be directly used providing access to such an interface
|
||||
class CRenderedAircraftProviderSupport
|
||||
{
|
||||
public:
|
||||
//! \copydoc IRenderedAircraftProviderReadOnly::renderedAircraft
|
||||
virtual const CSimulatedAircraftList &renderedAircraft() const;
|
||||
|
||||
//! \copydoc IRenderedAircraftProvider::renderedAircraft
|
||||
virtual CSimulatedAircraftList &renderedAircraft();
|
||||
|
||||
//!\copydoc IRenderedAircraftProviderReadOnly::renderedAircraftSituations
|
||||
virtual const BlackMisc::Aviation::CAircraftSituationList &renderedAircraftSituations() const;
|
||||
|
||||
//!\copydoc IRenderedAircraftProvider::renderedAircraftSituations
|
||||
virtual Aviation::CAircraftSituationList &renderedAircraftSituations();
|
||||
|
||||
//! \copydoc IRenderedAircraftProvider::updateAircraftEnabled
|
||||
virtual bool providerUpdateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const QString &originator);
|
||||
|
||||
//! \copydoc IRenderedAircraftProvider::updateAircraftModel
|
||||
virtual bool providerUpdateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const QString &originator);
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CRenderedAircraftProviderSupport(IRenderedAircraftProvider *renderedAircraftProvider) : m_renderedAircraftProvider(renderedAircraftProvider) { Q_ASSERT(renderedAircraftProvider); }
|
||||
IRenderedAircraftProvider *m_renderedAircraftProvider = nullptr; //!< access to object
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user