From 3ae93190ae166b84b65e3114db564770c467f37a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 9 Jun 2014 02:24:22 +0200 Subject: [PATCH] Round trip protection as described in (4) https://dev.vatsim-germany.org/boards/22/topics/1792?r=1801#message-1801 * Individual context id * Allows to connect >1 GUIs with core, works for cockpit so far --- samples/blackgui/mainwindow.cpp | 3 ++- samples/blackgui/mainwindow.h | 4 ++-- samples/blackgui/mainwindow_aircraft.cpp | 2 +- src/blackcore/context.h | 12 ++++++++++++ src/blackcore/context_application.h | 3 +++ src/blackcore/context_audio.h | 3 +++ src/blackcore/context_network.h | 3 +++ src/blackcore/context_settings.h | 3 +++ src/blackcore/context_simulator.h | 3 +++ src/blackgui/cockpitv1component.cpp | 2 +- 10 files changed, 33 insertions(+), 5 deletions(-) diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index 2a093df16..aa01b81fe 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -201,7 +201,8 @@ void MainWindow::toggleNetworkConnection() this->m_ownAircraft.setIcaoInfo(icao); // set latest aircraft - this->getIContextOwnAircraft()->updateOwnAircraft(this->m_ownAircraft, MainWindow::ownAircraftContextOriginator()); + this->getIContextOwnAircraft()->updateOwnAircraft(this->m_ownAircraft, MainWindow::sampleBlackGuiOriginator()); + // Login is based on setting current server INetwork::LoginMode mode = INetwork::LoginNormal; diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index 39bf9ada0..f1600c6a9 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -207,9 +207,9 @@ private: void setHotkeys(); //! Originator for aircraft context - static const QString &ownAircraftContextOriginator() + static const QString &sampleBlackGuiOriginator() { - static const QString o("GUISAMPLE1"); + static const QString o = QString("GUISAMPLE1:").append(QString::number(QDateTime::currentMSecsSinceEpoch())); return o; } diff --git a/samples/blackgui/mainwindow_aircraft.cpp b/samples/blackgui/mainwindow_aircraft.cpp index 19fc3108a..c3ed2ea15 100644 --- a/samples/blackgui/mainwindow_aircraft.cpp +++ b/samples/blackgui/mainwindow_aircraft.cpp @@ -45,5 +45,5 @@ void MainWindow::setTestPosition(const QString &wgsLatitude, const QString &wgsL this->m_ownAircraft.setPosition(coordinate); this->m_ownAircraft.setAltitude(altitude); - this->getIContextOwnAircraft()->updateOwnPosition(coordinate, altitude, MainWindow::ownAircraftContextOriginator()); + this->getIContextOwnAircraft()->updateOwnPosition(coordinate, altitude, MainWindow::sampleBlackGuiOriginator()); } diff --git a/src/blackcore/context.h b/src/blackcore/context.h index 9d71660f9..d4eb88d8f 100644 --- a/src/blackcore/context.h +++ b/src/blackcore/context.h @@ -83,6 +83,9 @@ namespace BlackCore //! Simulator IContextSimulator *getIContextSimulator(); + //! Id and path name for round trip protection + virtual QString getPathAndContextId() const = 0; + protected: //! Constructor CContext(CRuntimeConfig::ContextMode mode, QObject *parent) : @@ -91,6 +94,15 @@ namespace BlackCore CRuntimeConfig::ContextMode m_mode; //!< How context is used qint64 m_contextId; //!< unique identifer, avoid redirection rountrips + + //! Path and context id + QString buildPathAndContextId(const QString &path) const + { + return QString(path). + append(':'). + append(QString::number(this->getUniqueId())); + } + }; } #endif // guard diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index b61262b23..b7023cad8 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -66,6 +66,9 @@ namespace BlackCore return s; } + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + //! Destructor virtual ~IContextApplication() {} diff --git a/src/blackcore/context_audio.h b/src/blackcore/context_audio.h index 2f40c3d37..ab693ff41 100644 --- a/src/blackcore/context_audio.h +++ b/src/blackcore/context_audio.h @@ -47,6 +47,9 @@ namespace BlackCore return s; } + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + //! \brief Destructor virtual ~IContextAudio() {} diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index a7c3da356..7d9e1b3c5 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -43,6 +43,9 @@ namespace BlackCore return s; } + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + //! Destructor virtual ~IContextNetwork() {} diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index e367d3f33..3a558025e 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -62,6 +62,9 @@ namespace BlackCore return s; } + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + /*! * \brief Path for network settings * \remarks no to be confused with DBus paths diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 5ebd5dbc8..98332b1d9 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -42,6 +42,9 @@ namespace BlackCore return s; } + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + //! Destructor virtual ~IContextSimulator() {} diff --git a/src/blackgui/cockpitv1component.cpp b/src/blackgui/cockpitv1component.cpp index dfce6abff..043f65a08 100644 --- a/src/blackgui/cockpitv1component.cpp +++ b/src/blackgui/cockpitv1component.cpp @@ -131,7 +131,7 @@ namespace BlackGui const QString &CCockpitV1Component::cockpitOriginator() { - static const QString o("cockpit v1"); + static const QString o = QString("COCKPITV1:").append(QString::number(QDateTime::currentMSecsSinceEpoch())); return o; }