From 7fbf48ca3aed203a97b7809e1c0fbc15f4490249 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Mon, 30 Dec 2024 09:33:57 +0100 Subject: [PATCH] refactor: Move common dbus function to IContext --- src/core/context/context.cpp | 9 +++++++++ src/core/context/context.h | 3 +++ src/core/context/contextapplication.cpp | 2 +- src/core/context/contextapplicationimpl.cpp | 6 ------ src/core/context/contextapplicationimpl.h | 3 --- src/core/context/contextaudio.cpp | 2 +- src/core/context/contextaudioimpl.cpp | 8 -------- src/core/context/contextaudioimpl.h | 3 --- src/core/context/contextnetwork.cpp | 2 +- src/core/context/contextnetworkimpl.cpp | 6 ------ src/core/context/contextnetworkimpl.h | 3 --- src/core/context/contextownaircraft.cpp | 2 +- src/core/context/contextownaircraftimpl.cpp | 6 ------ src/core/context/contextownaircraftimpl.h | 3 --- src/core/context/contextsimulator.cpp | 2 +- src/core/context/contextsimulatorimpl.cpp | 6 ------ src/core/context/contextsimulatorimpl.h | 3 --- 17 files changed, 17 insertions(+), 52 deletions(-) diff --git a/src/core/context/context.cpp b/src/core/context/context.cpp index 57d66b22e..993805fc1 100644 --- a/src/core/context/context.cpp +++ b/src/core/context/context.cpp @@ -4,6 +4,7 @@ #include "core/context/context.h" #include "core/application.h" +#include "misc/dbusserver.h" #include "misc/logcategories.h" using namespace swift::misc; @@ -70,6 +71,14 @@ namespace swift::core::context return this->getRuntime()->getIContextSimulator(); } + void IContext::registerWithDBus(const QString &objectPath, CDBusServer *server) + { + if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; } + + // remark that registers all SIGNALS, not only the interface ons + server->addObject(objectPath, this); + } + const CStatusMessage &IContext::statusMessageEmptyContext() { static const CStatusMessage m(static_cast(nullptr), CStatusMessage::SeverityWarning, diff --git a/src/core/context/context.h b/src/core/context/context.h index 117f61741..2622fb562 100644 --- a/src/core/context/context.h +++ b/src/core/context/context.h @@ -152,6 +152,9 @@ namespace swift::core::context //! Called when shutdown is about to be called virtual void onAboutToShutdown() {} + //! Register myself in DBus + void registerWithDBus(const QString &objectPath, misc::CDBusServer *server); + //! Standard message when status message is returned in empty context static const misc::CStatusMessage &statusMessageEmptyContext(); diff --git a/src/core/context/contextapplication.cpp b/src/core/context/contextapplication.cpp index 3b1a6f7a6..e59ef6c4b 100644 --- a/src/core/context/contextapplication.cpp +++ b/src/core/context/contextapplication.cpp @@ -35,7 +35,7 @@ namespace swift::core::context case CCoreFacadeConfig::LocalInDBusServer: { auto *context = new CContextApplication(mode, parent); - context->registerWithDBus(server); + context->registerWithDBus(ObjectPath(), server); return context; } case CCoreFacadeConfig::Remote: diff --git a/src/core/context/contextapplicationimpl.cpp b/src/core/context/contextapplicationimpl.cpp index 607c6d7ad..5cf0aa36c 100644 --- a/src/core/context/contextapplicationimpl.cpp +++ b/src/core/context/contextapplicationimpl.cpp @@ -25,12 +25,6 @@ namespace swift::core::context : IContextApplication(mode, runtime), CIdentifiable(this) {} - void CContextApplication::registerWithDBus(swift::misc::CDBusServer *server) - { - if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; } - server->addObject(IContextApplication::ObjectPath(), this); - } - void CContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin) { // Intentionally don't check for round trip here diff --git a/src/core/context/contextapplicationimpl.h b/src/core/context/contextapplicationimpl.h index fb08ccb5f..15daa2fc4 100644 --- a/src/core/context/contextapplicationimpl.h +++ b/src/core/context/contextapplicationimpl.h @@ -88,9 +88,6 @@ namespace swift::core //! Constructor CContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - //! Register myself in DBus, fail safe - void registerWithDBus(swift::misc::CDBusServer *server); - private: swift::misc::CIdentifierList m_registeredApplications; diff --git a/src/core/context/contextaudio.cpp b/src/core/context/contextaudio.cpp index 6fac73d3b..37379661c 100644 --- a/src/core/context/contextaudio.cpp +++ b/src/core/context/contextaudio.cpp @@ -64,7 +64,7 @@ namespace swift::core::context case CCoreFacadeConfig::LocalInDBusServer: { auto *context = new CContextAudio(mode, runtime); - context->registerWithDBus(server); + context->registerWithDBus(ObjectPath(), server); return context; } case CCoreFacadeConfig::Remote: diff --git a/src/core/context/contextaudioimpl.cpp b/src/core/context/contextaudioimpl.cpp index baf74a13a..abb7c20a7 100644 --- a/src/core/context/contextaudioimpl.cpp +++ b/src/core/context/contextaudioimpl.cpp @@ -24,14 +24,6 @@ namespace swift::core::context Qt::QueuedConnection); } - void CContextAudio::registerWithDBus(CDBusServer *server) - { - if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; } - - // remark that registers all SIGNALS, not only the interface ons - server->addObject(IContextAudio::ObjectPath(), this); - } - void CContextAudio::registerDevices(const CAudioDeviceInfoList &devices) { if (devices.isEmpty()) { return; } diff --git a/src/core/context/contextaudioimpl.h b/src/core/context/contextaudioimpl.h index f65fa3cd8..ae80f6ba1 100644 --- a/src/core/context/contextaudioimpl.h +++ b/src/core/context/contextaudioimpl.h @@ -59,9 +59,6 @@ namespace swift::core //! Constructor CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - //! Register myself in DBus - void registerWithDBus(misc::CDBusServer *server); - private: misc::audio::CAudioDeviceInfoList m_registeredDevices; QMap m_registeredCallsigns; diff --git a/src/core/context/contextnetwork.cpp b/src/core/context/contextnetwork.cpp index 2f289f7c7..346aebcb0 100644 --- a/src/core/context/contextnetwork.cpp +++ b/src/core/context/contextnetwork.cpp @@ -25,7 +25,7 @@ namespace swift::core::context case CCoreFacadeConfig::LocalInDBusServer: { auto *context = new CContextNetwork(mode, runtime); - context->registerWithDBus(server); + context->registerWithDBus(ObjectPath(), server); return context; } case CCoreFacadeConfig::Remote: diff --git a/src/core/context/contextnetworkimpl.cpp b/src/core/context/contextnetworkimpl.cpp index 2911ed207..41cfda541 100644 --- a/src/core/context/contextnetworkimpl.cpp +++ b/src/core/context/contextnetworkimpl.cpp @@ -120,12 +120,6 @@ namespace swift::core::context Qt::QueuedConnection); } - void CContextNetwork::registerWithDBus(swift::misc::CDBusServer *server) - { - if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; }; - server->addObject(IContextNetwork::ObjectPath(), this); - } - void CContextNetwork::setSimulationEnvironmentProvider(ISimulationEnvironmentProvider *provider) { if (this->canUseAirspaceMonitor()) { m_airspace->setSimulationEnvironmentProvider(provider); } diff --git a/src/core/context/contextnetworkimpl.h b/src/core/context/contextnetworkimpl.h index 8aad6ea84..7e7d72081 100644 --- a/src/core/context/contextnetworkimpl.h +++ b/src/core/context/contextnetworkimpl.h @@ -461,9 +461,6 @@ namespace swift::core //! Constructor, with link to runtime CContextNetwork(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); - //! Register myself in DBus - void registerWithDBus(swift::misc::CDBusServer *server); - //! Set the provider void setSimulationEnvironmentProvider(swift::misc::simulation::ISimulationEnvironmentProvider *provider); diff --git a/src/core/context/contextownaircraft.cpp b/src/core/context/contextownaircraft.cpp index dc6da8c5c..846fabead 100644 --- a/src/core/context/contextownaircraft.cpp +++ b/src/core/context/contextownaircraft.cpp @@ -28,7 +28,7 @@ namespace swift::core::context case CCoreFacadeConfig::LocalInDBusServer: { auto *context = new CContextOwnAircraft(mode, parent); - context->registerWithDBus(server); + context->registerWithDBus(ObjectPath(), server); return context; } case CCoreFacadeConfig::Remote: diff --git a/src/core/context/contextownaircraftimpl.cpp b/src/core/context/contextownaircraftimpl.cpp index 5fef0bd85..14b02040a 100644 --- a/src/core/context/contextownaircraftimpl.cpp +++ b/src/core/context/contextownaircraftimpl.cpp @@ -72,12 +72,6 @@ namespace swift::core::context CContextOwnAircraft::~CContextOwnAircraft() {} - void CContextOwnAircraft::registerWithDBus(CDBusServer *server) - { - if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; } - server->addObject(IContextOwnAircraft::ObjectPath(), this); - } - CSimulatedAircraft CContextOwnAircraft::getOwnAircraft() const { if (isDebugEnabled()) { CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO; } diff --git a/src/core/context/contextownaircraftimpl.h b/src/core/context/contextownaircraftimpl.h index db10c8f36..b88cc730d 100644 --- a/src/core/context/contextownaircraftimpl.h +++ b/src/core/context/contextownaircraftimpl.h @@ -215,9 +215,6 @@ namespace swift::core //! Constructor, with link to runtime CContextOwnAircraft(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); - //! Register myself in DBus - void registerWithDBus(swift::misc::CDBusServer *server); - private: swift::misc::simulation::CSimulatedAircraft m_ownAircraft; //!< my aircraft mutable QReadWriteLock m_lockAircraft; //!< lock aircraft diff --git a/src/core/context/contextsimulator.cpp b/src/core/context/contextsimulator.cpp index c0692773b..6c5ac459a 100644 --- a/src/core/context/contextsimulator.cpp +++ b/src/core/context/contextsimulator.cpp @@ -39,7 +39,7 @@ namespace swift::core::context case CCoreFacadeConfig::LocalInDBusServer: { auto *context = new CContextSimulator(mode, parent); - context->registerWithDBus(server); + context->registerWithDBus(ObjectPath(), server); return context; } case CCoreFacadeConfig::Remote: diff --git a/src/core/context/contextsimulatorimpl.cpp b/src/core/context/contextsimulatorimpl.cpp index 35fe01b37..20177750e 100644 --- a/src/core/context/contextsimulatorimpl.cpp +++ b/src/core/context/contextsimulatorimpl.cpp @@ -106,12 +106,6 @@ namespace swift::core::context else { m_validator->setCurrentSimulator(CSimulatorInfo::None, {}, {}); } } - void CContextSimulator::registerWithDBus(CDBusServer *server) - { - if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; } - server->addObject(CContextSimulator::ObjectPath(), this); - } - bool CContextSimulator::isSimulatorPluginAvailable() const { return m_simulatorPlugin.second && IContextSimulator::isSimulatorAvailable(); diff --git a/src/core/context/contextsimulatorimpl.h b/src/core/context/contextsimulatorimpl.h index 95c371e30..c4a630b7a 100644 --- a/src/core/context/contextsimulatorimpl.h +++ b/src/core/context/contextsimulatorimpl.h @@ -273,9 +273,6 @@ namespace swift::core //! Constructor CContextSimulator(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); - //! Register myself in DBus - void registerWithDBus(swift::misc::CDBusServer *server); - //! Simulator plugin available? bool isSimulatorPluginAvailable() const;