mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 09:45:44 +08:00
Ref T259, Ref T243 client provider used with network classes
Also adds a dummy testing class
This commit is contained in:
@@ -45,18 +45,18 @@ using namespace BlackCore;
|
|||||||
using namespace BlackCore::Vatsim;
|
using namespace BlackCore::Vatsim;
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Simulation;
|
using namespace BlackMisc::Simulation;
|
||||||
|
using namespace BlackMisc::Network;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Geo;
|
using namespace BlackMisc::Geo;
|
||||||
|
|
||||||
namespace BlackSample
|
namespace BlackSample
|
||||||
{
|
{
|
||||||
|
|
||||||
Client::Client(QObject *parent)
|
Client::Client(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
COwnAircraftAware(COwnAircraftProviderDummy::instance()),
|
COwnAircraftAware(COwnAircraftProviderDummy::instance()),
|
||||||
CIdentifiable("samples:cmdClient"),
|
CIdentifiable("samples:cmdClient"),
|
||||||
m_net(new CNetworkVatlib(COwnAircraftProviderDummy::instance(), this))
|
m_net(new CNetworkVatlib(CClientProviderDummy::instance(), COwnAircraftProviderDummy::instance(), this))
|
||||||
{
|
{
|
||||||
connect(m_net, &INetwork::atcPositionUpdate, this, &Client::atcPositionUpdate);
|
connect(m_net, &INetwork::atcPositionUpdate, this, &Client::atcPositionUpdate);
|
||||||
connect(m_net, &INetwork::atcDisconnected, this, &Client::atcDisconnected);
|
connect(m_net, &INetwork::atcDisconnected, this, &Client::atcDisconnected);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace BlackCore
|
|||||||
CContextNetwork::registerHelp();
|
CContextNetwork::registerHelp();
|
||||||
|
|
||||||
// 1. Init by "network driver"
|
// 1. Init by "network driver"
|
||||||
m_network = new CNetworkVatlib(this->getRuntime()->getCContextOwnAircraft(), this);
|
m_network = new CNetworkVatlib(nullptr, this->getRuntime()->getCContextOwnAircraft(), this);
|
||||||
connect(m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::onFsdConnectionStatusChanged);
|
connect(m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::onFsdConnectionStatusChanged);
|
||||||
connect(m_network, &INetwork::kicked, this, &CContextNetwork::kicked);
|
connect(m_network, &INetwork::kicked, this, &CContextNetwork::kicked);
|
||||||
connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::textMessagesReceived);
|
connect(m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::textMessagesReceived);
|
||||||
@@ -80,6 +80,7 @@ namespace BlackCore
|
|||||||
// 3. Airspace contents
|
// 3. Airspace contents
|
||||||
Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local");
|
Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local");
|
||||||
m_airspace = new CAirspaceMonitor(this->getRuntime()->getCContextOwnAircraft(), m_network, this);
|
m_airspace = new CAirspaceMonitor(this->getRuntime()->getCContextOwnAircraft(), m_network, this);
|
||||||
|
m_network->setClientProvider(m_airspace);
|
||||||
connect(m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline);
|
connect(m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline);
|
||||||
connect(m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked);
|
connect(m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked);
|
||||||
connect(m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus);
|
connect(m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus);
|
||||||
@@ -146,6 +147,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
this->disconnect(); // all signals
|
this->disconnect(); // all signals
|
||||||
if (this->isConnected()) { this->disconnectFromNetwork(); }
|
if (this->isConnected()) { this->disconnectFromNetwork(); }
|
||||||
|
if (m_network) { m_network->setClientProvider(nullptr); }
|
||||||
if (m_airspace) { m_airspace->gracefulShutdown(); }
|
if (m_airspace) { m_airspace->gracefulShutdown(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,15 @@
|
|||||||
#include "blackmisc/simulation/simulationenvironmentprovider.h"
|
#include "blackmisc/simulation/simulationenvironmentprovider.h"
|
||||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||||
#include "blackmisc/geo/coordinategeodetic.h"
|
|
||||||
#include "blackmisc/network/rawfsdmessage.h"
|
#include "blackmisc/network/rawfsdmessage.h"
|
||||||
#include "blackmisc/network/serverlist.h"
|
#include "blackmisc/network/serverlist.h"
|
||||||
|
#include "blackmisc/network/clientprovider.h"
|
||||||
|
#include "blackmisc/network/clientlist.h"
|
||||||
#include "blackmisc/network/textmessagelist.h"
|
#include "blackmisc/network/textmessagelist.h"
|
||||||
#include "blackmisc/aviation/informationmessage.h"
|
#include "blackmisc/aviation/informationmessage.h"
|
||||||
#include "blackmisc/aviation/flightplan.h"
|
#include "blackmisc/aviation/flightplan.h"
|
||||||
#include "blackmisc/aviation/callsignset.h"
|
#include "blackmisc/aviation/callsignset.h"
|
||||||
|
#include "blackmisc/geo/coordinategeodetic.h"
|
||||||
#include "blackmisc/pq/frequency.h"
|
#include "blackmisc/pq/frequency.h"
|
||||||
#include "blackmisc/pq/length.h"
|
#include "blackmisc/pq/length.h"
|
||||||
#include "blackmisc/pq/time.h"
|
#include "blackmisc/pq/time.h"
|
||||||
@@ -57,6 +59,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
class BLACKCORE_EXPORT INetwork :
|
class BLACKCORE_EXPORT INetwork :
|
||||||
public QObject,
|
public QObject,
|
||||||
|
public BlackMisc::Network::CClientAware, // network vatlib consumes own aircraft data and sets ICAO/callsign data
|
||||||
public BlackMisc::Simulation::COwnAircraftAware, // network vatlib consumes own aircraft data and sets ICAO/callsign data
|
public BlackMisc::Simulation::COwnAircraftAware, // network vatlib consumes own aircraft data and sets ICAO/callsign data
|
||||||
public BlackMisc::Simulation::CSimulationEnvironmentAware // allows to consume ground elevations
|
public BlackMisc::Simulation::CSimulationEnvironmentAware // allows to consume ground elevations
|
||||||
{
|
{
|
||||||
@@ -66,9 +69,13 @@ namespace BlackCore
|
|||||||
/*!
|
/*!
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
INetwork(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, QObject *parent = nullptr) :
|
INetwork(
|
||||||
|
BlackMisc::Network::IClientProvider *clientProvider,
|
||||||
|
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||||
|
QObject *parent = nullptr) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
BlackMisc::Simulation::COwnAircraftAware(ownAircraft) {}
|
BlackMisc::Network::CClientAware(clientProvider),
|
||||||
|
BlackMisc::Simulation::COwnAircraftAware(ownAircraftProvider) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -83,8 +83,9 @@ namespace BlackCore
|
|||||||
return cats;
|
return cats;
|
||||||
}
|
}
|
||||||
|
|
||||||
CNetworkVatlib::CNetworkVatlib(IOwnAircraftProvider *ownAircraft, QObject *parent)
|
CNetworkVatlib::CNetworkVatlib(IClientProvider *clientProvider,
|
||||||
: INetwork(ownAircraft, parent),
|
IOwnAircraftProvider *ownAircraftProvider, QObject *parent)
|
||||||
|
: INetwork(clientProvider, ownAircraftProvider, parent),
|
||||||
m_loginMode(LoginNormal),
|
m_loginMode(LoginNormal),
|
||||||
m_status(vatStatusDisconnected),
|
m_status(vatStatusDisconnected),
|
||||||
m_tokenBucket(10, CTime(5, CTimeUnit::s()), 1)
|
m_tokenBucket(10, CTime(5, CTimeUnit::s()), 1)
|
||||||
|
|||||||
@@ -64,7 +64,10 @@ namespace BlackCore
|
|||||||
static const BlackMisc::CLogCategoryList &getLogCategories();
|
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CNetworkVatlib(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, QObject *parent = nullptr);
|
CNetworkVatlib(
|
||||||
|
BlackMisc::Network::IClientProvider *clientProvider,
|
||||||
|
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||||
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CNetworkVatlib();
|
virtual ~CNetworkVatlib();
|
||||||
|
|||||||
@@ -118,6 +118,12 @@ namespace BlackMisc
|
|||||||
if (m_clientProvider) { return m_clientProvider->removeClient(callsign); }
|
if (m_clientProvider) { return m_clientProvider->removeClient(callsign); }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CClientProviderDummy *CClientProviderDummy::instance()
|
||||||
|
{
|
||||||
|
static CClientProviderDummy *dummy = new CClientProviderDummy();
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// namespace
|
// namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -105,9 +105,17 @@ namespace BlackMisc
|
|||||||
CClientAware() {}
|
CClientAware() {}
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CClientAware(IClientProvider *clientProvider) : m_clientProvider(clientProvider) { Q_ASSERT(clientProvider); }
|
CClientAware(IClientProvider *clientProvider) : m_clientProvider(clientProvider) { }
|
||||||
IClientProvider *m_clientProvider = nullptr; //!< access to object
|
IClientProvider *m_clientProvider = nullptr; //!< access to object
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Client provider dummy for testing
|
||||||
|
class BLACKMISC_EXPORT CClientProviderDummy: public IClientProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Dummy instance
|
||||||
|
static CClientProviderDummy *instance();
|
||||||
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ using namespace BlackMisc::PhysicalQuantities;
|
|||||||
|
|
||||||
namespace BlackCoreTest
|
namespace BlackCoreTest
|
||||||
{
|
{
|
||||||
|
CTestNetwork::CTestNetwork(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_networkVatlib(CClientProviderDummy::instance(), COwnAircraftProviderDummy::instance(), parent)
|
||||||
|
{}
|
||||||
|
|
||||||
void CTestNetwork::networkTest(BlackCore::INetwork *net)
|
void CTestNetwork::networkTest(BlackCore::INetwork *net)
|
||||||
{
|
{
|
||||||
const CServer fsdServer = CServer::swiftFsdTestServer(true);
|
const CServer fsdServer = CServer::swiftFsdTestServer(true);
|
||||||
@@ -76,7 +81,7 @@ namespace BlackCoreTest
|
|||||||
|
|
||||||
EXPECT_UNIT(e)
|
EXPECT_UNIT(e)
|
||||||
.send(&INetwork::sendPing, "server")
|
.send(&INetwork::sendPing, "server")
|
||||||
.expect(&INetwork::pongReceived, [](const CCallsign &callsign, const PhysicalQuantities::CTime &elapsedTime)
|
.expect(&INetwork::pongReceived, [](const CCallsign & callsign, const PhysicalQuantities::CTime & elapsedTime)
|
||||||
{
|
{
|
||||||
qDebug() << "PONG" << callsign << elapsedTime;
|
qDebug() << "PONG" << callsign << elapsedTime;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -33,10 +33,7 @@ namespace BlackCoreTest
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
//! Constructor.
|
//! Constructor.
|
||||||
explicit CTestNetwork(QObject *parent = nullptr) :
|
explicit CTestNetwork(QObject *parent = nullptr);
|
||||||
QObject(parent),
|
|
||||||
m_networkVatlib(BlackMisc::Simulation::COwnAircraftProviderDummy::instance(), parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Test the vatlib
|
//! Test the vatlib
|
||||||
|
|||||||
Reference in New Issue
Block a user