refs #227, added support for client/aircraft model in contexts

* Simulator
* Network
This commit is contained in:
Klaus Basan
2014-05-06 13:33:05 +02:00
parent 9d2b96c218
commit 66023d2d87
11 changed files with 243 additions and 63 deletions

View File

@@ -12,6 +12,7 @@
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/nwtextmessagelist.h"
#include "blackmisc/nwuserlist.h"
#include "blackmisc/nwclientlist.h"
#include "blackmisc/voiceroomlist.h"
#include "blackcore/network.h"
@@ -100,6 +101,12 @@ namespace BlackCore
//! Get own aircraft
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const = 0;
//! Information about other clients
virtual BlackMisc::Network::CClientList getOtherClients() const = 0;
//! Clients for given callsign, e.g. to test direct model
virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const = 0;
/*!
* \brief Connect to Network
* \return messages gererated during connecting

View File

@@ -163,69 +163,6 @@ namespace BlackCore
return rooms;
}
/*
* All users
*/
CUserList CContextNetwork::getUsers() const
{
CUserList users;
foreach(CAtcStation station, this->m_atcStationsOnline)
{
CUser user = station.getController();
users.push_back(user);
}
foreach(CAircraft aircraft, this->m_aircraftsInRange)
{
CUser user = aircraft.getPilot();
users.push_back(user);
}
return users;
}
/*
* Users with callsigns
*/
CUserList CContextNetwork::getUsersForCallsigns(const CCallsignList &callsigns) const
{
CUserList users;
if (callsigns.isEmpty()) return users;
CCallsignList searchList(callsigns);
// do aircrafts first, this will handle most callsigns
foreach(CAircraft aircraft, this->m_aircraftsInRange)
{
if (searchList.isEmpty()) break;
CCallsign callsign = aircraft.getCallsign();
if (searchList.contains(callsign))
{
CUser user = aircraft.getPilot();
users.push_back(user);
searchList.remove(callsign);
}
}
foreach(CAtcStation station, this->m_atcStationsOnline)
{
if (searchList.isEmpty()) break;
CCallsign callsign = station.getCallsign();
if (searchList.contains(callsign))
{
CUser user = station.getController();
users.push_back(user);
searchList.remove(callsign);
}
}
// we might have unresolved callsigns
foreach(CCallsign callsign, searchList)
{
CUser user;
user.setCallsign(callsign);
users.push_back(user);
}
return users;
}
/*
* ATC Position update
*/

View File

@@ -7,6 +7,7 @@
#include "context_runtime.h"
#include "context_settings.h"
#include "context_application.h"
#include "context_simulator.h"
#include "network_vatlib.h"
#include "vatsimbookingreader.h"
#include "vatsimdatafilereader.h"
@@ -72,6 +73,9 @@ namespace BlackCore
this->connect(this->m_network, &INetwork::aircraftPositionUpdate, this, &CContextNetwork::psFsdAircraftUpdateReceived);
this->connect(this->m_network, &INetwork::frequencyReplyReceived, this, &CContextNetwork::psFsdFrequencyReceived);
this->connect(this->m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::psFsdTextMessageReceived);
this->connect(this->m_network, &INetwork::capabilitiesReplyReceived, this, &CContextNetwork::psFsdCapabilitiesReplyReceived);
this->connect(this->m_network, &INetwork::customPacketReceived, this, &CContextNetwork::psFsdCustomPackageReceived);
this->connect(this->m_network, &INetwork::serverReplyReceived, this, &CContextNetwork::psFsdServerReplyReceived);
if (this->getIContextApplication()) this->connect(this->m_network, &INetwork::statusMessage, this->getIContextApplication(), &IContextApplication::sendStatusMessage);
}
@@ -121,6 +125,10 @@ namespace BlackCore
{
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid user credentials"));
}
else if (!this->m_ownAircraft.getIcaoInfo().hasAircraftAndAirlineDsignator())
{
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid ICAO data for own aircraft"));
}
else if (this->m_network->isConnected())
{
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already connected"));
@@ -164,6 +172,7 @@ namespace BlackCore
this->m_aircraftsInRange.clear();
this->m_atcStationsBooked.clear();
this->m_atcStationsOnline.clear();
this->m_otherClients.clear();
this->m_metarCache.clear();
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, "Connection terminating"));
}
@@ -276,6 +285,95 @@ namespace BlackCore
this->m_network->sendFlightPlan(flightPlan);
}
/*
* All users
*/
CUserList CContextNetwork::getUsers() const
{
CUserList users;
foreach(CAtcStation station, this->m_atcStationsOnline)
{
CUser user = station.getController();
users.push_back(user);
}
foreach(CAircraft aircraft, this->m_aircraftsInRange)
{
CUser user = aircraft.getPilot();
users.push_back(user);
}
return users;
}
/*
* Users with callsigns
*/
CUserList CContextNetwork::getUsersForCallsigns(const CCallsignList &callsigns) const
{
CUserList users;
if (callsigns.isEmpty()) return users;
CCallsignList searchList(callsigns);
// do aircrafts first, this will handle most callsigns
foreach(CAircraft aircraft, this->m_aircraftsInRange)
{
if (searchList.isEmpty()) break;
CCallsign callsign = aircraft.getCallsign();
if (searchList.contains(callsign))
{
CUser user = aircraft.getPilot();
users.push_back(user);
searchList.remove(callsign);
}
}
foreach(CAtcStation station, this->m_atcStationsOnline)
{
if (searchList.isEmpty()) break;
CCallsign callsign = station.getCallsign();
if (searchList.contains(callsign))
{
CUser user = station.getController();
users.push_back(user);
searchList.remove(callsign);
}
}
// we might have unresolved callsigns
foreach(CCallsign callsign, searchList)
{
CUser user;
user.setCallsign(callsign);
users.push_back(user);
}
return users;
}
/*
* Other clients
*/
CClientList CContextNetwork::getOtherClients() const
{
return this->m_otherClients;
}
/*
* Other clients
*/
CClientList CContextNetwork::getOtherClientsForCallsigns(const CCallsignList &callsigns) const
{
CClientList clients;
if (callsigns.isEmpty()) return clients;
foreach(CCallsign callsign, callsigns)
{
CClientList clientsForCallsign = this->m_otherClients.findBy(&CClient::getCallsign, callsign);
foreach(CClient c, clientsForCallsign)
{
clients.push_back(c);
}
}
return clients;
}
/*
* Connection status changed
*/
@@ -316,6 +414,9 @@ namespace BlackCore
vm = CIndexVariantMap(CAircraft::IndexPilotRealName, realname);
this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm);
vm = CIndexVariantMap(CClient::IndexRealName, realname);
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
/*
@@ -337,4 +438,80 @@ namespace BlackCore
this->textMessagesReceived(messages); // relay
}
/*
* Capabilities
*/
void CContextNetwork::psFsdCapabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags)
{
if (callsign.isEmpty()) return;
CIndexVariantMap capabilities;
capabilities.addValue(CClient::FsdAtisCanBeReceived, (flags & CNetworkVatlib::AcceptsAtisResponses));
capabilities.addValue(CClient::FsdWithInterimPositions, (flags & CNetworkVatlib::SupportsInterimPosUpdates));
capabilities.addValue(CClient::FsdWithModelDescription, (flags & CNetworkVatlib::SupportsModelDescriptions));
CIndexVariantMap vm(CClient::IndexCapabilities, capabilities.toQVariant());
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
/*
* Custom packages
*/
void CContextNetwork::psFsdCustomPackageReceived(const CCallsign &callsign, const QString &package, const QStringList &data)
{
if (callsign.isEmpty() || data.isEmpty()) return;
if (package.startsWith("FSIPIR", Qt::CaseInsensitive))
{
// Request of other client, I can get the other's model from that
// FsInn response is usually my model
QString model = data.last();
if (model.isEmpty()) return;
CIndexVariantMap vm(CClient::IndexQueriedModelString, QVariant(model));
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign))
{
// with custom packages it can happen,
//the package is received before any other package
this->m_otherClients.push_back(CClient(callsign));
}
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
this->sendFsipiCustomPackage(callsign); // response
}
}
/*
* Host
*/
void CContextNetwork::psFsdServerReplyReceived(const CCallsign &callsign, const QString &host)
{
if (callsign.isEmpty() || host.isEmpty()) return;
CIndexVariantMap vm(CClient::IndexHost, QVariant(host));
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
void CContextNetwork::sendFsipiCustomPackage(const CCallsign &recipientCallsign) const
{
QStringList data = this->createFsipiCustomPackageData();
this->m_network->sendCustomPacket(recipientCallsign.asString(), "FSIPI", data);
}
void CContextNetwork::sendFsipirCustomPackage(const CCallsign &recipientCallsign) const
{
QStringList data = this->createFsipiCustomPackageData();
this->m_network->sendCustomPacket(recipientCallsign.asString(), "FSIPIR", data);
}
QStringList CContextNetwork::createFsipiCustomPackageData() const
{
CAircraft me = this->getOwnAircraft();
CAircraftIcao icao = me.getIcaoInfo();
QString modelString;
if (this->getIContextSimulator())
{
if (this->getIContextSimulator()->isConnected()) modelString = this->getIContextSimulator()->getOwnAircraftModel().getQueriedModelString();
}
if (modelString.isEmpty()) modelString = CProject::systemNameAndVersion();
QStringList data = CNetworkVatlib::createFsipiCustomPackageData(
"0", icao.getAirlineDesignator(), icao.getAircraftDesignator(),
"", "", "", "",
icao.getAircraftCombinedType(), modelString);
return data;
}
} // namespace

View File

@@ -13,6 +13,7 @@
#include "blackcore/network.h"
#include "blackmisc/avatcstationlist.h"
#include "blackmisc/setnetwork.h"
#include "blackmisc/nwclientlist.h"
#include <QMap>
@@ -105,6 +106,12 @@ namespace BlackCore
//! \copydoc IContextNetwork::getUsersForCallsigns
virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const override;
//! \copydoc IContextNetwork::getOtherClients
virtual BlackMisc::Network::CClientList getOtherClients() const override;
//! \copydoc IContextNetwork::getOtherClientForCallsigns
virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const override;
//! \copydoc IContextNetwork::requestDataUpdates
virtual void requestDataUpdates()override;
@@ -127,6 +134,7 @@ namespace BlackCore
BlackMisc::Aviation::CAtcStationList m_atcStationsOnline;
BlackMisc::Aviation::CAtcStationList m_atcStationsBooked;
BlackMisc::Aviation::CAircraftList m_aircraftsInRange;
BlackMisc::Network::CClientList m_otherClients;
BlackCore::INetwork *m_network;
BlackMisc::Aviation::CAircraft m_ownAircraft;
QMap<QString, BlackMisc::Aviation::CInformationMessage> m_metarCache /*!< Keep METARs for a while */;
@@ -225,6 +233,16 @@ namespace BlackCore
//! Radio text messages received
void psFsdTextMessageReceived(const BlackMisc::Network::CTextMessageList &messages);
//! Capabilities received
void psFsdCapabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
//! Custom package
void psFsdCustomPackageReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &package, const QStringList &data);
//! Server reply received
void psFsdServerReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &host);
};
}

View File

@@ -93,6 +93,16 @@ namespace BlackCore
return this->m_dBusInterface->callDBusRet<BlackMisc::Network::CUserList>(QLatin1Literal("getUsersForCallsigns"), callsigns);
}
BlackMisc::Network::CClientList CContextNetworkProxy::getOtherClients() const
{
return this->m_dBusInterface->callDBusRet<BlackMisc::Network::CClientList>(QLatin1Literal("getOtherClients"));
}
BlackMisc::Network::CClientList CContextNetworkProxy::getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const
{
return this->m_dBusInterface->callDBusRet<BlackMisc::Network::CClientList>(QLatin1Literal("getOtherClientsForCallsigns"), callsigns);
}
BlackMisc::Audio::CVoiceRoomList CContextNetworkProxy::getSelectedVoiceRooms() const
{
return this->m_dBusInterface->callDBusRet<BlackMisc::Audio::CVoiceRoomList>(QLatin1Literal("getSelectedVoiceRooms"));

View File

@@ -119,6 +119,12 @@ namespace BlackCore
//! \copydoc IContextNetwork::getUsersForCallsigns
virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const override;
//! \copydoc IContextNetwork::getOtherClients
virtual BlackMisc::Network::CClientList getOtherClients() const override;
//! \copydoc IContextNetwork::getOtherClientForCallsigns
virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const override;
//! \copydoc IContextNetwork::requestDataUpdates
virtual void requestDataUpdates()override;

View File

@@ -12,6 +12,7 @@
#include "context.h"
#include "blackcore/dbus_server.h"
#include "blackcore/context_runtime.h"
#include "blackmisc/nwaircraftmodel.h"
#include "blackmisc/avaircraft.h"
#include "blacksim/simulatorinfo.h"
#include "blacksim/simulatorinfolist.h"
@@ -74,6 +75,9 @@ namespace BlackCore
//! Simulator info
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const = 0;
//! Aircraft model
virtual BlackMisc::Network::CAircraftModel getOwnAircraftModel() const = 0;
//! Load specific simulator plugin
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) = 0;

View File

@@ -91,6 +91,11 @@ namespace BlackCore
return m_simulator->getSimulatorInfo();
}
Network::CAircraftModel CContextSimulator::getOwnAircraftModel() const
{
return this->m_aircraftModel;
}
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorInfo &simulatorInfo)
{
ISimulatorFactory *factory = nullptr;

View File

@@ -32,6 +32,9 @@ namespace BlackCore
//! \brief Destructor
virtual ~CContextSimulator();
//! Model name, e.g. as used with FSX "Cessna C172 Skyhawk"
void setModelName(const QString &modelName) { this->m_aircraftModel.setQueriedModelString(modelName); }
public slots:
//! \copydoc IContextSimulator::getSimulatorPluginList()
@@ -58,6 +61,9 @@ namespace BlackCore
//! \copydoc IContextSimulator::getSimulatorInfo()
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
//! \copydoc IContextSimulator::getAircraftModel()
virtual BlackMisc::Network::CAircraftModel getOwnAircraftModel() const override;
//! \copydoc IContextSimulator::loadSimulatorPlugin()
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override;
@@ -88,7 +94,9 @@ namespace BlackCore
void findSimulatorPlugins();
BlackMisc::Aviation::CAircraft m_ownAircraft;
BlackMisc::Network::CAircraftModel m_aircraftModel;
BlackCore::ISimulator *m_simulator;
QTimer *m_updateTimer;
QDir m_pluginsDir;
QSet<ISimulatorFactory *> m_simulatorFactories;

View File

@@ -63,6 +63,11 @@ namespace BlackCore
return m_dBusInterface->callDBusRet<BlackMisc::Aviation::CAircraft>(QLatin1Literal("getOwnAircraft"));
}
BlackMisc::Network::CAircraftModel CContextSimulatorProxy::getOwnAircraftModel() const
{
return m_dBusInterface->callDBusRet<BlackMisc::Network::CAircraftModel>(QLatin1Literal("getOwnAircraftModel"));
}
BlackSim::CSimulatorInfo CContextSimulatorProxy::getSimulatorInfo() const
{
return m_dBusInterface->callDBusRet<BlackSim::CSimulatorInfo>(QLatin1Literal("getSimulatorInfo"));

View File

@@ -57,6 +57,9 @@ namespace BlackCore
//! \copydoc IContextSimulator::getOwnAircraft()
virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override;
//! \copydoc IContextSimulator::getAircraftModel()
virtual BlackMisc::Network::CAircraftModel getOwnAircraftModel() const override;
//! \copydoc IContextSimulator::getSimulatorInfo
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;