diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 4b6bafacd..e0c5df5e1 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -1577,6 +1577,11 @@ namespace BlackCore // Contexts // --------------------------------------------------------------------------------- + SharedState::CDataLinkDBus *CApplication::getDataLinkDBus() + { + return getCoreFacade()->getDataLinkDBus(); + } + bool CApplication::supportsContexts(bool ignoreShutdownTest) const { if (!ignoreShutdownTest && m_shutdown) { return false; } diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 41e48e20e..f99073a28 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -52,6 +52,10 @@ namespace BlackMisc { class CFileLogger; class CLogCategoryList; + namespace SharedState + { + class CDataLinkDBus; + } } namespace BlackCore @@ -346,6 +350,9 @@ namespace BlackCore // ----------------------- contexts ---------------------------------------- + //! Transport mechanism for sharing state between applications + BlackMisc::SharedState::CDataLinkDBus *getDataLinkDBus(); + //! \name Context / core facade related //! @{ diff --git a/src/blackcore/corefacade.cpp b/src/blackcore/corefacade.cpp index 7d8e904b1..75f186907 100644 --- a/src/blackcore/corefacade.cpp +++ b/src/blackcore/corefacade.cpp @@ -6,6 +6,7 @@ * or distributed except according to the terms contained in the LICENSE file. */ +#include "blackcore/corefacade.h" #include "blackcore/context/contextapplication.h" #include "blackcore/context/contextapplicationproxy.h" #include "blackcore/context/contextapplicationimpl.h" @@ -16,9 +17,9 @@ #include "blackcore/context/contextownaircraft.h" #include "blackcore/context/contextownaircraftimpl.h" #include "blackcore/context/contextsimulator.h" +#include "blackmisc/sharedstate/datalinkdbus.h" #include "blackcore/context/contextsimulatorimpl.h" #include "blackcore/data/launchersetup.h" -#include "blackcore/corefacade.h" #include "blackcore/corefacadeconfig.h" #include "blackcore/registermetadata.h" #include "blackcore/airspacemonitor.h" @@ -105,6 +106,23 @@ namespace BlackCore } times.insert("DBus", time.restart()); + // shared state infrastructure + m_dataLinkDBus = new SharedState::CDataLinkDBus(this); + switch (m_config.getModeApplication()) + { + case CCoreFacadeConfig::Local: + m_dataLinkDBus->initializeLocal(nullptr); + break; + case CCoreFacadeConfig::LocalInDBusServer: + m_dataLinkDBus->initializeLocal(m_dbusServer); + break; + case CCoreFacadeConfig::Remote: + m_dataLinkDBus->initializeRemote(m_dbusConnection, CDBusServer::coreServiceName(m_dbusConnection)); + break; + default: + qFatal("Invalid application context mode"); + } + // contexts if (m_contextApplication) { m_contextApplication->deleteLater(); } m_contextApplication = IContextApplication::create(this, m_config.getModeApplication(), m_dbusServer, m_dbusConnection); @@ -312,6 +330,10 @@ namespace BlackCore // disable all signals towards runtime disconnect(this); + // tear down shared state infrastructure + delete m_dataLinkDBus; + m_dataLinkDBus = nullptr; + // unregister all from DBus if (m_dbusServer) { m_dbusServer->removeAllObjects(); } diff --git a/src/blackcore/corefacade.h b/src/blackcore/corefacade.h index a1849fc17..7434c4114 100644 --- a/src/blackcore/corefacade.h +++ b/src/blackcore/corefacade.h @@ -23,7 +23,15 @@ #include #include -namespace BlackMisc { class CDBusServer; } +namespace BlackMisc +{ + class CDBusServer; + + namespace SharedState + { + class CDataLinkDBus; + } +} namespace BlackCore { namespace Context @@ -181,6 +189,9 @@ namespace BlackCore bool m_initDBusConnection = false; QDBusConnection m_dbusConnection { "default" }; + // shared state infrastructure + BlackMisc::SharedState::CDataLinkDBus *m_dataLinkDBus = nullptr; + // contexts: // There is a reason why we do not use smart pointers here. When the context is deleted // we need to use deleteLater to gracefully shut the context