Ref T260, function to add an offset to received situations for testing

* "dot" command
* context function
* provider functions
This commit is contained in:
Klaus Basan
2018-04-18 04:51:51 +02:00
committed by Roland Winklmeier
parent 456cb5d1ea
commit eb0fa92e7e
12 changed files with 134 additions and 13 deletions

View File

@@ -11,6 +11,7 @@
#include "blackcore/application.h"
#include "blackcore/db/networkwatchdog.h"
#include "blackcore/context/contextnetwork.h"
#include "blackcore/context/contextsimulatorimpl.h"
#include "blackcore/context/contextapplication.h"
#include "blackcore/cookiemanager.h"
#include "blackcore/corefacade.h"
@@ -1277,6 +1278,13 @@ namespace BlackCore
return args.join(' ');
}
ISimulator *CApplication::getISimulator() const
{
if (!this->getCoreFacade()) { return nullptr; }
if (!this->getCoreFacade()->getCContextSimulator()) { return nullptr; }
return this->getCoreFacade()->getCContextSimulator()->simulator();
}
void CApplication::cmdLineHelpMessage()
{
m_parser.showHelp(); // terminates

View File

@@ -15,8 +15,8 @@
#include "blackcore/blackcoreexport.h"
#include "blackcore/cookiemanager.h"
#include "blackcore/corefacadeconfig.h"
#include "blackcore/data/globalsetup.h"
#include "blackcore/db/databasereaderconfig.h"
#include "blackcore/data/globalsetup.h"
#include "blackcore/application/applicationsettings.h"
#include "blackcore/webreaderflags.h"
#include "blackmisc/db/updateinfo.h"
@@ -64,6 +64,7 @@ namespace BlackCore
class CCoreFacade;
class CSetupReader;
class CWebDataServices;
class ISimulator;
namespace Context
{
class IContextApplication;
@@ -295,6 +296,11 @@ namespace BlackCore
virtual QString cmdLineArgumentsAsString(bool withExecutable = true);
//! @}
// ----------------------- simulator ----------------------------------------
//! The simulator plugin, if available
ISimulator *getISimulator() const;
// ----------------------- contexts ----------------------------------------
//! \name Context / core facade related

View File

@@ -307,6 +307,9 @@ namespace BlackCore
//! Request parts for callsign (from another client)
virtual void testRequestAircraftConfig(const BlackMisc::Aviation::CCallsign &callsign) = 0;
//! Add altitude offset for testing
virtual bool testAddAltitudeOffset(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CLength &offset = BlackMisc::PhysicalQuantities::CLength::null()) = 0;
public:
//! Raw FSD message receiver functor
using RawFsdMessageReceivedSlot = std::function<void(const BlackMisc::Network::CRawFsdMessage &)>;

View File

@@ -258,6 +258,15 @@ namespace BlackCore
logEmptyContextWarning(Q_FUNC_INFO);
}
//! \copydoc IContextNetwork::testAddAltitudeOffset
virtual bool testAddAltitudeOffset(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CLength &offset = BlackMisc::PhysicalQuantities::CLength::null()) override
{
Q_UNUSED(callsign);
Q_UNUSED(offset);
logEmptyContextWarning(Q_FUNC_INFO);
return false;
}
//! \copydoc IContextNetwork::parseCommandLine
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override
{

View File

@@ -234,7 +234,8 @@ namespace BlackCore
{
Q_UNUSED(originator;)
if (commandLine.isEmpty()) { return false; }
CSimpleCommandParser parser({ ".msg", ".m" });
static const QStringList cmds({ ".msg", ".m", ".altos", ".altoffset" });
CSimpleCommandParser parser(cmds);
parser.parse(commandLine);
if (!parser.isKnownCommand()) { return false; }
if (parser.matchesCommand(".msg", ".m"))
@@ -314,6 +315,33 @@ namespace BlackCore
this->sendTextMessages(tml);
return true;
}
else if (parser.matchesCommand(".altos", ".altoffet"))
{
if (!m_airspace) { return false; }
if (parser.countParts() < 2) { return false; }
const CCallsign cs(parser.part(1));
if (!m_airspace->isAircraftInRange(cs))
{
CLogMessage(this).validationError("Altitude offset unknown callsign");
return false;
}
CLength os(CLength::null());
if (parser.hasPart(2))
{
os.parseFromString(parser.part(2));
}
const bool added = this->testAddAltitudeOffset(cs, os);
if (added)
{
CLogMessage(this).info("Added altitude offset %1 for %2") << os.valueRoundedWithUnit(2) << cs.asString();
}
else
{
CLogMessage(this).info("Removed altitude offset %1") << cs.asString();
}
return true;
}
return false;
}
@@ -609,6 +637,12 @@ namespace BlackCore
return m_airspace->partsLastModified(callsign);
}
bool CContextNetwork::testAddAltitudeOffset(const CCallsign &callsign, const CLength &offset)
{
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
return m_airspace->testAddAltitudeOffset(callsign, offset);
}
CAtcStation CContextNetwork::getOnlineStationForCallsign(const CCallsign &callsign) const
{
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; }

View File

@@ -134,6 +134,7 @@ namespace BlackCore
virtual int aircraftPartsAdded() const override;
virtual qint64 situationsLastModified(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual qint64 partsLastModified(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual bool testAddAltitudeOffset(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CLength &offset = BlackMisc::PhysicalQuantities::CLength::null()) override;
//! @}
//! In transition state, e.g. connecting, disconnecting.
@@ -145,7 +146,8 @@ namespace BlackCore
//! \addtogroup swiftdotcommands
//! @{
//! <pre>
//! .m .msg message text
//! .m .msg message text
//! .altos .altoffset altitude offset for testing
//! </pre>
//! @}
//! \copydoc IContextNetwork::parseCommandLine
@@ -158,6 +160,7 @@ namespace BlackCore
BlackMisc::CSimpleCommandParser::registerCommand({".m", "alias: .msg"});
BlackMisc::CSimpleCommandParser::registerCommand({".m message <text>", "send text message"});
BlackMisc::CSimpleCommandParser::registerCommand({".m callsign message <text>", "send text message"});
BlackMisc::CSimpleCommandParser::registerCommand({".altos callsign offsetvalue", "set altitude offset value (testing)"});
}
//! \publicsection

View File

@@ -33,7 +33,7 @@ namespace BlackCore
CContextNetworkProxy::CContextNetworkProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextNetwork(mode, runtime), m_dBusInterface(nullptr)
{
m_dBusInterface = new CGenericDBusInterface(
serviceName , IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(),
serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(),
connection, this);
this->relaySignals(serviceName, connection);
}
@@ -290,6 +290,11 @@ namespace BlackCore
m_dBusInterface->callDBus(QLatin1String("testRequestAircraftConfig"), callsign);
}
bool CContextNetworkProxy::testAddAltitudeOffset(const CCallsign &callsign, const PhysicalQuantities::CLength &offset)
{
return m_dBusInterface->callDBusRet<bool>(QLatin1String("testAddAltitudeOffset"), callsign, offset);
}
CStatusMessage CContextNetworkProxy::connectToNetwork(const CServer &server, INetwork::LoginMode loginMode)
{
return m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1String("connectToNetwork"), server, loginMode);

View File

@@ -122,6 +122,7 @@ namespace BlackCore
virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) override;
virtual void testReceivedTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override;
virtual void testRequestAircraftConfig(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual bool testAddAltitudeOffset(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CLength &offset = BlackMisc::PhysicalQuantities::CLength::null()) override;
//! @}
public:

View File

@@ -12,9 +12,9 @@
#ifndef BLACKCORE_CONTEXT_CONTEXTSIMULATOR_IMPL_H
#define BLACKCORE_CONTEXT_CONTEXTSIMULATOR_IMPL_H
#include "blackcore/corefacadeconfig.h"
#include "blackcore/context/contextsimulator.h"
#include "blackcore/application/applicationsettings.h"
#include "blackcore/corefacadeconfig.h"
#include "blackcore/aircraftmatcher.h"
#include "blackcore/blackcoreexport.h"
#include "blackcore/weathermanager.h"
@@ -51,7 +51,6 @@ namespace BlackCore
{
class CCoreFacade;
class CPluginManagerSimulator;
class ISimulator;
namespace Context
{
@@ -125,7 +124,7 @@ namespace BlackCore
//! Gracefully shut down, e.g. for plugin unloading
void gracefulShutdown();
//! Simulator object
//! Access to simulator (i.e. the plugin)
ISimulator *simulator() const;
//! Register dot commands

View File

@@ -28,7 +28,7 @@ namespace BlackMisc
//! Constructor
CSimpleCommandParser(const QStringList &knownCommands);
//! Known command
//! Known command?
bool isKnownCommand() const { return m_knownCommand; }
//! Parse

View File

@@ -164,21 +164,26 @@ namespace BlackMisc
void CRemoteAircraftProvider::storeAircraftSituation(const CAircraftSituation &situation)
{
if (situation.getCallsign().isEmpty()) { return; }
const CCallsign cs = situation.getCallsign();
if (cs.isEmpty()) { return; }
const qint64 ts = QDateTime::currentMSecsSinceEpoch();
// for testing only
CAircraftSituation situationOs(situation);
this->testAddAltitudeOffsetToSituation(situationOs);
// list from new to old
QWriteLocker lock(&m_lockSituations);
m_situationsAdded++;
m_situationsLastModified[situation.getCallsign()] = ts;
CAircraftSituationList &situationList = m_situationsByCallsign[situation.getCallsign()];
m_situationsLastModified[cs] = ts;
CAircraftSituationList &situationList = m_situationsByCallsign[cs];
if (situationList.isEmpty())
{
situationList.prefillLatestAdjustedFirst(situation, IRemoteAircraftProvider::MaxSituationsPerCallsign);
situationList.prefillLatestAdjustedFirst(situationOs, IRemoteAircraftProvider::MaxSituationsPerCallsign);
}
else
{
situationList.push_frontKeepLatestFirstAdjustOffset(situation, IRemoteAircraftProvider::MaxSituationsPerCallsign);
situationList.push_frontKeepLatestFirstAdjustOffset(situationOs, IRemoteAircraftProvider::MaxSituationsPerCallsign);
}
// unify all inbound ground information
@@ -420,6 +425,28 @@ namespace BlackMisc
this->removeAllAircraft();
}
bool CRemoteAircraftProvider::hasTestAltitudeOffset(const CCallsign &callsign) const
{
if (callsign.isEmpty()) { return false; }
QReadLocker l(&m_lockSituations);
return m_testOffset.contains(callsign);
}
bool CRemoteAircraftProvider::testAddAltitudeOffsetToSituation(CAircraftSituation &situation) const
{
if (!this->hasTestAltitudeOffset(situation.getCallsign())) { return false; }
const CCallsign cs(situation.getCallsign());
CLength os;
{
QReadLocker l(&m_lockSituations);
os = m_testOffset.value(cs);
}
const CAltitude newAlt = situation.getAltitude().withOffset(os);
situation.setAltitude(newAlt);
return true;
}
CStatusMessageList CRemoteAircraftProvider::getAircraftPartsHistory(const CCallsign &callsign) const
{
QReadLocker l(&m_lockPartsHistory);
@@ -456,6 +483,20 @@ namespace BlackMisc
return m_partsLastModified.value(callsign, -1);
}
bool CRemoteAircraftProvider::testAddAltitudeOffset(const CCallsign &callsign, const CLength &offset)
{
const bool remove = offset.isNull() || offset.isZeroEpsilonConsidered();
QWriteLocker l(&m_lockSituations);
if (remove)
{
m_testOffset.remove(callsign);
return false;
}
m_testOffset[callsign] = offset;
return true;
}
int CRemoteAircraftProvider::aircraftPartsAdded() const
{
QReadLocker l(&m_lockParts);

View File

@@ -295,6 +295,14 @@ namespace BlackMisc
//! Clear all data
void clear();
// ------------------- testing ---------------
//! Has test offset value?
bool hasTestAltitudeOffset(const Aviation::CCallsign &callsign) const;
//! Offset for callsign
bool testAddAltitudeOffset(const Aviation::CCallsign &callsign, const PhysicalQuantities::CLength &offset);
signals:
//! A new aircraft appeared
void addedAircraft(const CSimulatedAircraft &remoteAircraft);
@@ -356,6 +364,9 @@ namespace BlackMisc
void storeAircraftParts(const Aviation::CCallsign &callsign, const QJsonObject &jsonObject, int currentOffset);
//! @}
//! Add an offset for testing
bool testAddAltitudeOffsetToSituation(Aviation::CAircraftSituation &situation) const;
private:
// hashs, because not sorted by key but keeping order
CSituationsPerCallsign m_situationsByCallsign; //!< situations, for performance reasons per callsign, thread safe access required
@@ -369,6 +380,7 @@ namespace BlackMisc
QMap<Aviation::CCallsign, CStatusMessageList> m_aircraftPartsHistory;
QMap<Aviation::CCallsign, qint64> m_situationsLastModified;
QMap<Aviation::CCallsign, qint64> m_partsLastModified;
QMap<Aviation::CCallsign, PhysicalQuantities::CLength> m_testOffset;
bool m_enableReverseLookupMsgs = false; //!< shall we log. information about the matching process
bool m_enableAircraftPartsHistory = true; //!< shall we keep a history of aircraft parts