Skip to content

Commit

Permalink
refactor: Move common dbus function to IContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ltoenning committed Dec 30, 2024
1 parent 51ae580 commit 7fbf48c
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 52 deletions.
9 changes: 9 additions & 0 deletions src/core/context/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IContext *>(nullptr), CStatusMessage::SeverityWarning,
Expand Down
3 changes: 3 additions & 0 deletions src/core/context/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/core/context/contextapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions src/core/context/contextapplicationimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/core/context/contextapplicationimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/core/context/contextaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 0 additions & 8 deletions src/core/context/contextaudioimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 0 additions & 3 deletions src/core/context/contextaudioimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<misc::CIdentifier, misc::aviation::CCallsign> m_registeredCallsigns;
Expand Down
2 changes: 1 addition & 1 deletion src/core/context/contextnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions src/core/context/contextnetworkimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
3 changes: 0 additions & 3 deletions src/core/context/contextnetworkimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/core/context/contextownaircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions src/core/context/contextownaircraftimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 0 additions & 3 deletions src/core/context/contextownaircraftimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/context/contextsimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions src/core/context/contextsimulatorimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/core/context/contextsimulatorimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 7fbf48c

Please sign in to comment.