refs #288, adjusted network context

* new login method
* signals for booking / data file read
This commit is contained in:
Klaus Basan
2014-11-15 01:50:12 +01:00
committed by Roland Winklmeier
parent 2a831f8252
commit 9a84376b5d
6 changed files with 42 additions and 28 deletions

View File

@@ -95,6 +95,12 @@ namespace BlackCore
//! Terminated connection //! Terminated connection
void connectionTerminated(); void connectionTerminated();
//! VATSIM data file was read
void vatsimDataFileRead();
//! Bookings read
void vatsimBookingsRead();
/*! /*!
* Connection status changed * Connection status changed
* \param from old status * \param from old status
@@ -151,7 +157,7 @@ namespace BlackCore
* \return messages gererated during connecting * \return messages gererated during connecting
* \see INetwork::LoginMode * \see INetwork::LoginMode
*/ */
virtual BlackMisc::CStatusMessage connectToNetwork(uint loginMode) = 0; virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint loginMode) = 0;
/*! /*!
* Disconnect from network * Disconnect from network

View File

@@ -60,10 +60,11 @@ namespace BlackCore
return BlackMisc::Aviation::CAircraftList(); return BlackMisc::Aviation::CAircraftList();
} }
//! \copydoc IContextNetwork::connectToNetwork() //! \copydoc IContextNetwork::connectToNetwork
virtual BlackMisc::CStatusMessage connectToNetwork(uint mode) override virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint mode) override
{ {
Q_UNUSED(mode); Q_UNUSED(mode);
Q_UNUSED(server);
logEmptyContextWarning(Q_FUNC_INFO); logEmptyContextWarning(Q_FUNC_INFO);
return statusMessageEmptyContext(); return statusMessageEmptyContext();
} }

View File

@@ -46,36 +46,36 @@ namespace BlackCore
// 1. Init by "network driver" // 1. Init by "network driver"
this->m_network = new CNetworkVatlib(this); this->m_network = new CNetworkVatlib(this);
this->connect(this->m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::ps_fsdConnectionStatusChanged); connect(this->m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::ps_fsdConnectionStatusChanged);
this->connect(this->m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::ps_fsdTextMessageReceived); connect(this->m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::ps_fsdTextMessageReceived);
// 2. VATSIM bookings // 2. VATSIM bookings
this->m_vatsimBookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this); this->m_vatsimBookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this);
this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CContextNetwork::ps_receivedBookings); connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CContextNetwork::ps_receivedBookings);
this->m_vatsimBookingReader->read(); // first read this->m_vatsimBookingReader->read(); // first read
this->m_vatsimBookingReader->setInterval(180 * 1000); this->m_vatsimBookingReader->setInterval(180 * 1000);
// 3. VATSIM data file // 3. VATSIM data file
const QStringList dataFileUrls = { "http://info.vroute.net/vatsim-data.txt" }; const QStringList dataFileUrls = { "http://info.vroute.net/vatsim-data.txt" };
this->m_vatsimDataFileReader = new CVatsimDataFileReader(dataFileUrls, this); this->m_vatsimDataFileReader = new CVatsimDataFileReader(dataFileUrls, this);
this->connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataRead, this, &CContextNetwork::ps_dataFileRead); connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataRead, this, &CContextNetwork::ps_dataFileRead);
this->m_vatsimDataFileReader->read(); // first read this->m_vatsimDataFileReader->read(); // first read
this->m_vatsimDataFileReader->setInterval(90 * 1000); this->m_vatsimDataFileReader->setInterval(90 * 1000);
// 4. Update timer for data (network data such as frequency) // 4. Update timer for data (network data such as frequency)
this->m_dataUpdateTimer = new QTimer(this); this->m_dataUpdateTimer = new QTimer(this);
this->connect(this->m_dataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates); connect(this->m_dataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates);
this->m_dataUpdateTimer->start(30 * 1000); this->m_dataUpdateTimer->start(30 * 1000);
// 5. Airspace contents // 5. Airspace contents
this->m_airspace = new CAirspaceMonitor(this, this->m_network, this->m_vatsimBookingReader, this->m_vatsimDataFileReader); this->m_airspace = new CAirspaceMonitor(this, this->m_network, this->m_vatsimBookingReader, this->m_vatsimDataFileReader);
this->connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline);
this->connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked);
this->connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus);
this->connect(this->m_airspace, &CAirspaceMonitor::changedAircraftsInRange, this, &CContextNetwork::changedAircraftsInRange); connect(this->m_airspace, &CAirspaceMonitor::changedAircraftsInRange, this, &CContextNetwork::changedAircraftsInRange);
this->connect(this->m_airspace, &CAirspaceMonitor::changedAircraftSituation, this, &CContextNetwork::changedAircraftSituation); connect(this->m_airspace, &CAirspaceMonitor::changedAircraftSituation, this, &CContextNetwork::changedAircraftSituation);
this->connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraft, this->m_airspace, &CAirspaceMonitor::setOwnAircraft); connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraft, this->m_airspace, &CAirspaceMonitor::setOwnAircraft);
this->connect(this->getIContextSimulator(), &IContextSimulator::ownAircraftModelChanged, this->m_airspace, &CAirspaceMonitor::setOwnAircraftModel); connect(this->getIContextSimulator(), &IContextSimulator::ownAircraftModelChanged, this->m_airspace, &CAirspaceMonitor::setOwnAircraftModel);
} }
/* /*
@@ -99,13 +99,11 @@ namespace BlackCore
/* /*
* Connect to network * Connect to network
*/ */
CStatusMessage CContextNetwork::connectToNetwork(uint loginMode) CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, uint loginMode)
{ {
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
CServer currentServer = this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer();
QString msg; QString msg;
if (!currentServer.getUser().isValid()) if (!server.getUser().isValid())
{ {
return CLogMessage(this).error("Invalid user credentials"); return CLogMessage(this).error("Invalid user credentials");
} }
@@ -113,7 +111,7 @@ namespace BlackCore
{ {
return CLogMessage(this).error("Invalid ICAO data for own aircraft"); return CLogMessage(this).error("Invalid ICAO data for own aircraft");
} }
else if (!CNetworkUtils::canConnect(currentServer, msg, 2000)) else if (!CNetworkUtils::canConnect(server, msg, 2000))
{ {
return CLogMessage(this).error(msg); return CLogMessage(this).error(msg);
} }
@@ -129,15 +127,15 @@ namespace BlackCore
{ {
this->m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect this->m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect
INetwork::LoginMode mode = static_cast<INetwork::LoginMode>(loginMode); INetwork::LoginMode mode = static_cast<INetwork::LoginMode>(loginMode);
this->getIContextOwnAircraft()->updatePilot(currentServer.getUser(), this->getPathAndContextId()); this->getIContextOwnAircraft()->updatePilot(server.getUser(), this->getPathAndContextId());
const CAircraft ownAircraft = this->ownAircraft(); const CAircraft ownAircraft = this->ownAircraft();
this->m_network->presetServer(currentServer); this->m_network->presetServer(server);
this->m_network->presetLoginMode(mode); this->m_network->presetLoginMode(mode);
this->m_network->presetCallsign(ownAircraft.getCallsign()); this->m_network->presetCallsign(ownAircraft.getCallsign());
this->m_network->presetIcaoCodes(ownAircraft.getIcaoInfo()); this->m_network->presetIcaoCodes(ownAircraft.getIcaoInfo());
this->m_network->setOwnAircraft(ownAircraft); this->m_network->setOwnAircraft(ownAircraft);
this->m_network->initiateConnection(); this->m_network->initiateConnection();
return CLogMessage(this).info("Connection pending %1 %2") << currentServer.getAddress() << currentServer.getPort(); return CLogMessage(this).info("Connection pending %1 %2") << server.getAddress() << server.getPort();
} }
} }
@@ -328,6 +326,7 @@ namespace BlackCore
{ {
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Read VATSIM data file"); CLogMessage(this).info("Read VATSIM data file");
emit vatsimDataFileRead();
} }
/* /*
@@ -367,7 +366,9 @@ namespace BlackCore
*/ */
void CContextNetwork::ps_receivedBookings(const CAtcStationList &) void CContextNetwork::ps_receivedBookings(const CAtcStationList &)
{ {
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Read bookings from network"); CLogMessage(this).info("Read bookings from network");
emit vatsimBookingsRead();
} }
/* /*

View File

@@ -75,7 +75,7 @@ namespace BlackCore
} }
//! \copydoc IContextNetwork::connectToNetwork() //! \copydoc IContextNetwork::connectToNetwork()
virtual BlackMisc::CStatusMessage connectToNetwork(uint mode) override; virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint mode) override;
//! \copydoc IContextNetwork::disconnectFromNetwork() //! \copydoc IContextNetwork::disconnectFromNetwork()
virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; virtual BlackMisc::CStatusMessage disconnectFromNetwork() override;

View File

@@ -58,6 +58,12 @@ namespace BlackCore
s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(),
"textMessagesReceived", this, SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList))); "textMessagesReceived", this, SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(),
"vatsimDataFileRead", this, SIGNAL(vatsimDataFileRead()));
Q_ASSERT(s);
s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(),
"vatsimBookingsRead", this, SIGNAL(vatsimBookingsRead()));
Q_ASSERT(s);
Q_UNUSED(s); Q_UNUSED(s);
} }
@@ -141,9 +147,9 @@ namespace BlackCore
this->m_dBusInterface->callDBus(QLatin1Literal("testCreateDummyOnlineAtcStations"), number); this->m_dBusInterface->callDBus(QLatin1Literal("testCreateDummyOnlineAtcStations"), number);
} }
BlackMisc::CStatusMessage CContextNetworkProxy::connectToNetwork(uint loginMode) BlackMisc::CStatusMessage CContextNetworkProxy::connectToNetwork(const Network::CServer &server, uint loginMode)
{ {
return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1Literal("connectToNetwork"), loginMode); return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1Literal("connectToNetwork"), server, loginMode);
} }
BlackMisc::CStatusMessage CContextNetworkProxy::disconnectFromNetwork() BlackMisc::CStatusMessage CContextNetworkProxy::disconnectFromNetwork()

View File

@@ -65,8 +65,8 @@ namespace BlackCore
//! \copydoc IContextNetwork::getAircraftsInRange() //! \copydoc IContextNetwork::getAircraftsInRange()
virtual const BlackMisc::Aviation::CAircraftList getAircraftsInRange() const override; virtual const BlackMisc::Aviation::CAircraftList getAircraftsInRange() const override;
//! \copydoc IContextNetwork::connectToNetwork() //! \copydoc IContextNetwork::connectToNetwork
virtual BlackMisc::CStatusMessage connectToNetwork(uint mode) override; virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint mode) override;
//! \copydoc IContextNetwork::disconnectFromNetwork() //! \copydoc IContextNetwork::disconnectFromNetwork()
virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; virtual BlackMisc::CStatusMessage disconnectFromNetwork() override;