mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
CAtcListManager class
This commit is contained in:
39
src/blackcore/atclistmgr.cpp
Normal file
39
src/blackcore/atclistmgr.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "atclistmgr.h"
|
||||||
|
#include "network.h"
|
||||||
|
|
||||||
|
BlackCore::CAtcListManager::CAtcListManager(const BlackCoreTest::EnableTesting&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BlackCore::CAtcListManager::CAtcListManager()
|
||||||
|
{
|
||||||
|
INetwork *net = BlackMisc::IContext::getInstance().singleton<INetwork>();
|
||||||
|
|
||||||
|
connect(net, &INetwork::atcPositionUpdate, this, &CAtcListManager::update, Qt::QueuedConnection);
|
||||||
|
connect(net, &INetwork::atcDisconnected, this, &CAtcListManager::remove, Qt::QueuedConnection);
|
||||||
|
connect(net, &INetwork::connectionStatusDisconnected, this, &CAtcListManager::clear, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlackCore::CAtcListManager::update(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq,
|
||||||
|
const BlackMisc::Geo::CCoordinateGeodetic& pos, const BlackMisc::PhysicalQuantities::CLength& range)
|
||||||
|
{
|
||||||
|
m_list.insert(BlackMisc::CAtcListEntry(callsign, freq, pos, range));
|
||||||
|
emit listChanged(m_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlackCore::CAtcListManager::remove(const QString& callsign)
|
||||||
|
{
|
||||||
|
m_list.remove(callsign);
|
||||||
|
emit listChanged(m_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlackCore::CAtcListManager::clear()
|
||||||
|
{
|
||||||
|
m_list.clear();
|
||||||
|
emit listChanged(m_list);
|
||||||
|
}
|
||||||
95
src/blackcore/atclistmgr.h
Normal file
95
src/blackcore/atclistmgr.h
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLACKCORE_ATCLISTMGR_H
|
||||||
|
#define BLACKCORE_ATCLISTMGR_H
|
||||||
|
|
||||||
|
#include "blackmisc/atclist.h"
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace BlackCoreTest
|
||||||
|
{
|
||||||
|
class EnableTesting;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Abstract base class that manages and provides access to a list of available ATC stations.
|
||||||
|
*/
|
||||||
|
class IAtcListManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(BlackMisc::CAtcList list READ getList NOTIFY listChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
BLACK_INTERFACE(BlackCore::IAtcListManager)
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Virtual destructor.
|
||||||
|
*/
|
||||||
|
virtual ~IAtcListManager() {}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Immutable getter.
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
virtual const BlackMisc::CAtcList &getList() const = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/*!
|
||||||
|
* Emitted whenever there is a change in the ATC list.
|
||||||
|
* \param list The new list
|
||||||
|
*/
|
||||||
|
void listChanged(const BlackMisc::CAtcList &list);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Concrete ATC list manager. Implementation of IAtcListManager.
|
||||||
|
*
|
||||||
|
* Has a dependency on INetwork. An INetwork must be available through the IContext singleton.
|
||||||
|
*/
|
||||||
|
class CAtcListManager : public IAtcListManager
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
CAtcListManager();
|
||||||
|
|
||||||
|
virtual const BlackMisc::CAtcList& getList() const { return m_list; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/*!
|
||||||
|
* CAtcListManager is responsible for connecting these slots.
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
void update(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq,
|
||||||
|
const BlackMisc::Geo::CCoordinateGeodetic& pos, const BlackMisc::PhysicalQuantities::CLength& range);
|
||||||
|
void remove(const QString& callsign);
|
||||||
|
void clear();
|
||||||
|
/*! \} */
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* Constructor that does not connect INetwork signals to CAtcListManager slots.
|
||||||
|
* \warning Only used for testing purposes.
|
||||||
|
*/
|
||||||
|
explicit CAtcListManager(const BlackCoreTest::EnableTesting&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BlackMisc::CAtcList m_list;
|
||||||
|
};
|
||||||
|
|
||||||
|
}//namespace BlackCore
|
||||||
|
|
||||||
|
#endif //BLACKCORE_ATCLISTMGR_H
|
||||||
111
src/blackmisc/atclist.h
Normal file
111
src/blackmisc/atclist.h
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLACKMISC_ATCLIST_H
|
||||||
|
#define BLACKMISC_ATCLIST_H
|
||||||
|
|
||||||
|
#include "pqfrequency.h"
|
||||||
|
#include "pqlength.h"
|
||||||
|
#include "coordinategeodetic.h"
|
||||||
|
#include "context.h"
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Value object encapsulating information about an ATC station.
|
||||||
|
*/
|
||||||
|
class CAtcListEntry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
CAtcListEntry() {}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
CAtcListEntry(const QString &callsign, const BlackMisc::PhysicalQuantities::CFrequency &freq,
|
||||||
|
const BlackMisc::Geo::CCoordinateGeodetic &pos, const BlackMisc::PhysicalQuantities::CLength &range)
|
||||||
|
: m_callsign(callsign), m_freq(freq), m_pos(pos), m_range(range)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Get callsign.
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
const QString &getCallsign() const { return m_callsign; }
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Get frequency.
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_freq; }
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Get the position of the center of the controller's area of visibility.
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
const BlackMisc::Geo::CCoordinateGeodetic &getPosition() const { return m_pos; }
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Get the radius of the controller's area of visibility.
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
const BlackMisc::PhysicalQuantities::CLength &getAtcRange() const { return m_range; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_callsign;
|
||||||
|
BlackMisc::PhysicalQuantities::CFrequency m_freq;
|
||||||
|
BlackMisc::Geo::CCoordinateGeodetic m_pos;
|
||||||
|
BlackMisc::PhysicalQuantities::CLength m_range;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Value object encapsulating a list of ATC stations.
|
||||||
|
*/
|
||||||
|
class CAtcList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* Immutable getter for the internal map.
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
const QMap<QString, CAtcListEntry> &constMap() const { return m_map; }
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Insert an ATC station into the list.
|
||||||
|
* \param entry
|
||||||
|
*/
|
||||||
|
void insert(const CAtcListEntry &entry) { m_map.insert(entry.getCallsign(), entry); }
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Remove an ATC station from the list.
|
||||||
|
* \param callsign
|
||||||
|
*/
|
||||||
|
void remove(const QString &callsign) { m_map.remove(callsign); }
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Remove all ATC stations from the list.
|
||||||
|
*/
|
||||||
|
void clear() { m_map.clear(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMap<QString, CAtcListEntry> m_map;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace BlackMisc
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(BlackMisc::CAtcList)
|
||||||
|
|
||||||
|
#endif //BLACKMISC_ATCLIST_H
|
||||||
@@ -7,10 +7,18 @@
|
|||||||
#define BLACKCORETEST_H
|
#define BLACKCORETEST_H
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @namespace BlackCoreTest
|
* \namespace BlackCoreTest
|
||||||
* Unit tests for BlackCore. Unit tests do have their own namespace, so
|
* Unit tests for BlackCore. Unit tests do have their own namespace, so
|
||||||
* the regular namespace BlackCore is completely free of unit tests.
|
* the regular namespace BlackCore is completely free of unit tests.
|
||||||
* Add any new tests to TestMain::unitMain as shown there.
|
* Add any new tests to TestMain::unitMain as shown there.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace BlackCoreTest
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* An "option type" used to alter the construction of objects under test.
|
||||||
|
*/
|
||||||
|
class EnableTesting {};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "testblackcoremain.h"
|
#include "testblackcoremain.h"
|
||||||
#include "testinterpolator.h"
|
#include "testinterpolator.h"
|
||||||
|
#include "testnetmediators.h"
|
||||||
|
|
||||||
namespace BlackCoreTest
|
namespace BlackCoreTest
|
||||||
{
|
{
|
||||||
@@ -19,6 +20,10 @@ int CBlackCoreTestMain::unitMain(int argc, char *argv[])
|
|||||||
CTestInterpolator interpolatorTests;
|
CTestInterpolator interpolatorTests;
|
||||||
status |= QTest::qExec(&interpolatorTests, argc, argv);
|
status |= QTest::qExec(&interpolatorTests, argc, argv);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
CTestNetMediators mediatorTests;
|
||||||
|
status |= QTest::qExec(&mediatorTests, argc, argv);
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
44
tests/blackcore/testnetmediators.cpp
Normal file
44
tests/blackcore/testnetmediators.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "testnetmediators.h"
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace BlackCoreTest
|
||||||
|
{
|
||||||
|
|
||||||
|
using namespace BlackCore;
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
using namespace BlackMisc::Geo;
|
||||||
|
|
||||||
|
void CTestNetMediators::atcListManagerTest()
|
||||||
|
{
|
||||||
|
CAtcListManager mgr ( (EnableTesting()) ); //extra pair of parentheses to disambiguate most vexing parse
|
||||||
|
AtcListConsumer cons;
|
||||||
|
|
||||||
|
QObject::connect(&mgr, &IAtcListManager::listChanged, &cons, &AtcListConsumer::listChanged);
|
||||||
|
|
||||||
|
QVERIFY(cons.m_list.constMap().size() == 0);
|
||||||
|
mgr.update("EGLL_TWR", CFrequency(118.7, CFrequencyUnit::MHz()), CCoordinateGeodetic(51.4775, 0.46139, 0), CLength(50, CLengthUnit::m()));
|
||||||
|
QVERIFY(cons.m_list.constMap().size() == 1);
|
||||||
|
mgr.update("EGLL_GND", CFrequency(121.9, CFrequencyUnit::MHz()), CCoordinateGeodetic(51.4775, 0.46139, 0), CLength(20, CLengthUnit::m()));
|
||||||
|
QVERIFY(cons.m_list.constMap().size() == 2);
|
||||||
|
mgr.update("EGLL_TWR", CFrequency(118.5, CFrequencyUnit::MHz()), CCoordinateGeodetic(51.4775, 0.46139, 0), CLength(50, CLengthUnit::m()));
|
||||||
|
QVERIFY(cons.m_list.constMap().size() == 2);
|
||||||
|
mgr.remove("EGLL_TWR");
|
||||||
|
QVERIFY(cons.m_list.constMap().size() == 1);
|
||||||
|
mgr.clear();
|
||||||
|
QVERIFY(cons.m_list.constMap().size() == 0);
|
||||||
|
|
||||||
|
mgr.update("EGLL_TWR", CFrequency(118.5, CFrequencyUnit::MHz()), CCoordinateGeodetic(51.4775, 0.46139, 0), CLength(50, CLengthUnit::m()));
|
||||||
|
QVERIFY(cons.m_list.constMap().contains("EGLL_TWR"));
|
||||||
|
QVERIFY(cons.m_list.constMap()["EGLL_TWR"].getCallsign() == "EGLL_TWR");
|
||||||
|
QVERIFY(cons.m_list.constMap()["EGLL_TWR"].getFrequency() == CFrequency(118.5, CFrequencyUnit::MHz()));
|
||||||
|
QVERIFY(cons.m_list.constMap()["EGLL_TWR"].getPosition() == CCoordinateGeodetic(51.4775, 0.46139, 0));
|
||||||
|
QVERIFY(cons.m_list.constMap()["EGLL_TWR"].getAtcRange() == CLength(50, CLengthUnit::m()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace BlackCoreTest
|
||||||
61
tests/blackcore/testnetmediators.h
Normal file
61
tests/blackcore/testnetmediators.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef BLACKCORETEST_TESTNETMEDIATORS_H
|
||||||
|
#define BLACKCORETEST_TESTNETMEDIATORS_H
|
||||||
|
|
||||||
|
#include "blackcore/atclistmgr.h"
|
||||||
|
#include "blackcoretest.h"
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
namespace BlackCoreTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Network mediator classes tests
|
||||||
|
*/
|
||||||
|
class CTestNetMediators : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* Constructor.
|
||||||
|
* \param parent
|
||||||
|
*/
|
||||||
|
explicit CTestNetMediators(QObject *parent = 0) : QObject(parent) {}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
/*!
|
||||||
|
* Test CAtcListManager
|
||||||
|
*/
|
||||||
|
void atcListManagerTest();
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Helper class that connects to CAtcListManager signals
|
||||||
|
*/
|
||||||
|
class AtcListConsumer : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! List is updated by the slot
|
||||||
|
BlackMisc::CAtcList m_list;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/*!
|
||||||
|
* Slot updates the list
|
||||||
|
* \param list
|
||||||
|
*/
|
||||||
|
void listChanged(const BlackMisc::CAtcList &list)
|
||||||
|
{
|
||||||
|
m_list = list;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace BlackCoreTest
|
||||||
|
|
||||||
|
#endif //BLACKCORETEST_TESTNETMEDIATORS_H
|
||||||
Reference in New Issue
Block a user