From 38ea336cbb2d8f006b65b91dec77749e8dcf41b8 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 3 Mar 2017 05:00:04 +0100 Subject: [PATCH] refs #894, register dot commands for help (wherever dor commands are implemented) --- src/blackcore/context/contextnetworkimpl.cpp | 1 + src/blackcore/context/contextnetworkimpl.h | 10 +++++++++ .../context/contextownaircraftimpl.cpp | 1 + .../context/contextownaircraftimpl.h | 14 ++++++++++++ src/blackcore/simulator.cpp | 7 ++++++ src/blackcore/simulator.h | 15 +++++++++---- src/blackcore/simulatorcommon.cpp | 1 + src/blackcore/simulatorcommon.h | 22 ++++++++++++++----- src/blackmisc/simplecommandparser.cpp | 17 +++++++------- src/blackmisc/simplecommandparser.h | 1 - .../simulator/fscommon/simulatorfscommon.cpp | 4 +++- .../simulator/fscommon/simulatorfscommon.h | 10 ++++++++- 12 files changed, 83 insertions(+), 20 deletions(-) diff --git a/src/blackcore/context/contextnetworkimpl.cpp b/src/blackcore/context/contextnetworkimpl.cpp index dfdcdf273..a328b0432 100644 --- a/src/blackcore/context/contextnetworkimpl.cpp +++ b/src/blackcore/context/contextnetworkimpl.cpp @@ -62,6 +62,7 @@ namespace BlackCore Q_ASSERT(this->getRuntime()); Q_ASSERT(this->getIContextOwnAircraft()); Q_ASSERT(this->getIContextOwnAircraft()->isUsingImplementingObject()); + CContextNetwork::registerHelp(); // 1. Init by "network driver" this->m_network = new CNetworkVatlib(this->getRuntime()->getCContextOwnAircraft(), this); diff --git a/src/blackcore/context/contextnetworkimpl.h b/src/blackcore/context/contextnetworkimpl.h index ff7b59e4d..0beb96958 100644 --- a/src/blackcore/context/contextnetworkimpl.h +++ b/src/blackcore/context/contextnetworkimpl.h @@ -48,6 +48,7 @@ #include "blackmisc/statusmessage.h" #include "blackmisc/digestsignal.h" #include "blackmisc/identifier.h" +#include "blackmisc/simplecommandparser.h" class QTimer; @@ -141,6 +142,15 @@ namespace BlackCore //! \copydoc IContextNetwork::parseCommandLine virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + //! Register help + static void registerHelp() + { + if (BlackMisc::CSimpleCommandParser::registered("BlackCore::CContextNetwork")) { return; } + BlackMisc::CSimpleCommandParser::registerCommand({".m", "alias: .msg"}); + BlackMisc::CSimpleCommandParser::registerCommand({".m message ", "send text message"}); + BlackMisc::CSimpleCommandParser::registerCommand({".m callsign message ", "send text message"}); + } + //! \publicsection //! @{ virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override; diff --git a/src/blackcore/context/contextownaircraftimpl.cpp b/src/blackcore/context/contextownaircraftimpl.cpp index 6e6375dfa..7bc098a46 100644 --- a/src/blackcore/context/contextownaircraftimpl.cpp +++ b/src/blackcore/context/contextownaircraftimpl.cpp @@ -58,6 +58,7 @@ namespace BlackCore { Q_ASSERT(this->getRuntime()); this->setObjectName("CContextOwnAircraft"); + CContextOwnAircraft::registerHelp(); if (sApp && sApp->getWebDataServices()) { diff --git a/src/blackcore/context/contextownaircraftimpl.h b/src/blackcore/context/contextownaircraftimpl.h index c5ed0bc63..cf105984c 100644 --- a/src/blackcore/context/contextownaircraftimpl.h +++ b/src/blackcore/context/contextownaircraftimpl.h @@ -31,6 +31,7 @@ #include "blackmisc/settingscache.h" #include "blackmisc/identifiable.h" #include "blackmisc/identifier.h" +#include "blackmisc/simplecommandparser.h" #include #include @@ -141,6 +142,7 @@ namespace BlackCore //! @{ //!
             //! .x    .xpdr  code       set transponder code    BlackCore::Context::CContextOwnAircraft
+            //! .x    .xpdr  mode       set transponder mode    BlackCore::Context::CContextOwnAircraft
             //! .com1 .com2  frequency  set COM1/2 frequency    BlackCore::Context::CContextOwnAircraft
             //! .selcal      code       set SELCAL code         BlackCore::Context::CContextOwnAircraft
             //! 
@@ -148,6 +150,18 @@ namespace BlackCore //! \copydoc IContextOwnAircraft::parseCommandLine virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + //! Register help + static void registerHelp() + { + if (BlackMisc::CSimpleCommandParser::registered("BlackCore::Context::CContextOwnAircraft")) { return; } + BlackMisc::CSimpleCommandParser::registerCommand({".x", "alias: .xpdr"}); + BlackMisc::CSimpleCommandParser::registerCommand({".x code|mode", "set XPDR code or mode"}); + BlackMisc::CSimpleCommandParser::registerCommand({".selcal code", "set SELCAL code"}); + BlackMisc::CSimpleCommandParser::registerCommand({".com1", "alias .c1"}); + BlackMisc::CSimpleCommandParser::registerCommand({".com1 frequency", "set COM1 frequency"}); + BlackMisc::CSimpleCommandParser::registerCommand({".com2 frequency", "set COM2 frequency"}); + } + protected: //! Constructor, with link to runtime CContextOwnAircraft(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 6d495ab35..a5a579158 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -51,6 +51,13 @@ namespace BlackCore return static_cast(status); } + ISimulator::ISimulator(QObject *parent) : + QObject(parent), + BlackMisc::CIdentifiable(this) + { + ISimulator::registerHelp(); + } + void ISimulator::emitSimulatorCombinedStatus(int oldStatus) { int newStatus = getSimulatorStatus(); diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 457a8d4be..a05c045cd 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -25,6 +25,7 @@ #include "blackmisc/identifiable.h" #include "blackmisc/identifier.h" #include "blackmisc/pixmap.h" +#include "blackmisc/simplecommandparser.h" #include #include @@ -159,6 +160,15 @@ namespace BlackCore //! Parse command line virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0; + //! Register help + static void registerHelp() + { + if (BlackMisc::CSimpleCommandParser::registered("BlackCore::ISimulator")) { return; } + BlackMisc::CSimpleCommandParser::registerCommand({".drv", "alias: .driver .plugin"}); + BlackMisc::CSimpleCommandParser::registerCommand({".drv unload", "unload driver"}); + BlackMisc::CSimpleCommandParser::registerCommand({".drv fsuipc on|off", "enable/disable FSUIPC (if applicable)"}); + } + //! Status to string static QString statusToString(int status); @@ -188,10 +198,7 @@ namespace BlackCore protected: //! Default constructor - ISimulator(QObject *parent = nullptr) : - QObject(parent), - BlackMisc::CIdentifiable(this) - {} + ISimulator(QObject *parent = nullptr); //! Are we connected to the simulator? virtual bool isConnected() const = 0; diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index c428b417a..ce323ae05 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -53,6 +53,7 @@ namespace BlackCore m_simulatorPluginInfo(info) { this->setObjectName("Simulator: " + info.getIdentifier()); + CSimulatorCommon::registerHelp(); // provider signals, hook up with remote aircraft provider m_remoteAircraftProviderConnections.append( diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 9e550af36..b2f0abbc9 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -88,15 +88,27 @@ namespace BlackCore //! \addtogroup swiftdotcommands //! @{ //!
-        //! .plugin unload              unload plugin                           BlackCore::CSimulatorCommon
-        //! .plugin logint  callsign    log interpolator for callsign           BlackCore::CSimulatorCommon
-        //! .plugin logint  off         no log information for interpolator     BlackCore::CSimulatorCommon
-        //! .plugin logint  write       write interpolator log to file          BlackCore::CSimulatorCommon
-        //! .plugin logint  clear       clear current log                       BlackCore::CSimulatorCommon
+        //! .drv unload              unload plugin                           BlackCore::CSimulatorCommon
+        //! .drv logint  callsign    log interpolator for callsign           BlackCore::CSimulatorCommon
+        //! .drv logint  off         no log information for interpolator     BlackCore::CSimulatorCommon
+        //! .drv logint  write       write interpolator log to file          BlackCore::CSimulatorCommon
+        //! .drv logint  clear       clear current log                       BlackCore::CSimulatorCommon
         //! 
//! @} //! \copydoc ISimulator::parseCommandLine virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + + //! Register help + static void registerHelp() + { + if (BlackMisc::CSimpleCommandParser::registered("BlackCore::CSimulatorCommon")) { return; } + BlackMisc::CSimpleCommandParser::registerCommand({".drv", "alias: .driver .plugin"}); + BlackMisc::CSimpleCommandParser::registerCommand({".drv logint callsign", "log interpolator for callsign"}); + BlackMisc::CSimpleCommandParser::registerCommand({".drv logint off", "no log information for interpolator"}); + BlackMisc::CSimpleCommandParser::registerCommand({".drv logint write", "write interpolator log to file"}); + BlackMisc::CSimpleCommandParser::registerCommand({".drv logint clear", "clear current log"}); + } + // --------- ISimulator implementations ------------ protected slots: diff --git a/src/blackmisc/simplecommandparser.cpp b/src/blackmisc/simplecommandparser.cpp index 511dcd913..4961fbe72 100644 --- a/src/blackmisc/simplecommandparser.cpp +++ b/src/blackmisc/simplecommandparser.cpp @@ -12,6 +12,7 @@ #include "blackmisc/simplecommandparser.h" #include +#include #include #include @@ -19,8 +20,8 @@ using namespace BlackMisc::PhysicalQuantities; namespace BlackMisc { - QList CSimpleCommandParser::s_commands = QList(); - QSet CSimpleCommandParser::s_registered = QSet(); + QList CSimpleCommandParser::s_commands; + QSet CSimpleCommandParser::s_registered; CSimpleCommandParser::CSimpleCommandParser(const QStringList &knownCommands) { @@ -135,30 +136,30 @@ namespace BlackMisc void CSimpleCommandParser::registerCommand(const CSimpleCommandParser::CommandHtmlHelp &command) { - for (const CommandHtmlHelp &help : as_const(CSimpleCommandParser::s_commands)) + for (const CommandHtmlHelp &help : as_const(s_commands)) { // avoid duplicates if (help.command == command.command) { return; } } - CSimpleCommandParser::s_commands.append(command); + s_commands.append(command); } bool CSimpleCommandParser::registered(const QString &helpContext) { - if (CSimpleCommandParser::s_registered.contains(helpContext)) { return true; }; - CSimpleCommandParser::s_registered.insert(helpContext); + if (s_registered.contains(helpContext)) { return true; }; + s_registered.insert(helpContext); return false; } QString CSimpleCommandParser::commandsHtmlHelp() { - if (CSimpleCommandParser::s_commands.isEmpty()) { return ""; } + if (s_commands.isEmpty()) { return ""; } static const QString html("\n%1\n
"); static const QString row("%1%2"); QString rows; - QList cmds(CSimpleCommandParser::s_commands); + QList cmds(s_commands); qSort(cmds.begin(), cmds.end(), CommandHtmlHelp::less); for (int i = 0; i < cmds.size(); i++) { diff --git a/src/blackmisc/simplecommandparser.h b/src/blackmisc/simplecommandparser.h index e402e275b..7142dbb02 100644 --- a/src/blackmisc/simplecommandparser.h +++ b/src/blackmisc/simplecommandparser.h @@ -89,7 +89,6 @@ namespace BlackMisc //! Compare by command static bool less(const CommandHtmlHelp &a, const CommandHtmlHelp &b) { - // may want to check that the pointers aren't zero... return a.command < b.command; } }; diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.cpp b/src/plugins/simulator/fscommon/simulatorfscommon.cpp index aac2e6f58..1e2e5642f 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.cpp +++ b/src/plugins/simulator/fscommon/simulatorfscommon.cpp @@ -34,7 +34,9 @@ namespace BlackSimPlugin QObject *parent) : CSimulatorCommon(info, ownAircraftProvider, renderedAircraftProvider, weatherGridProvider, parent), m_fsuipc(new CFsuipc()) - { } + { + CSimulatorFsCommon::registerHelp(); + } CSimulatorFsCommon::~CSimulatorFsCommon() { } diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.h b/src/plugins/simulator/fscommon/simulatorfscommon.h index 5e2a1aa8a..f4a509d53 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.h +++ b/src/plugins/simulator/fscommon/simulatorfscommon.h @@ -65,11 +65,19 @@ namespace BlackSimPlugin //! \addtogroup swiftdotcommands //! @{ //!
-            //! .plugin fsuipc  on|off      FSUIPC on/off
+            //! .drv fsuipc  on|off      FSUIPC on/off
             //! 
//! @} virtual bool parseDetails(const BlackMisc::CSimpleCommandParser &parser) override; + //! Register help + static void registerHelp() + { + if (BlackMisc::CSimpleCommandParser::registered("BlackSimPlugin::FsCommon::CSimulatorFsCommon")) { return; } + BlackMisc::CSimpleCommandParser::registerCommand({".drv", "alias: .driver .plugin"}); + BlackMisc::CSimpleCommandParser::registerCommand({".drv fsuipc on|off", "FSUIPC on|off if applicable"}); + } + QString m_simulatorName; //!< name of simulator QString m_simulatorDetails; //!< describes version etc. QString m_simulatorVersion; //!< Simulator version