swift
context.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "core/context/context.h"
5 
6 #include "core/application.h"
7 #include "misc/dbusserver.h"
8 #include "misc/logcategories.h"
9 
10 using namespace swift::misc;
11 
12 namespace swift::core::context
13 {
14  const QStringList &IContext::getLogCategories()
15  {
16  static const QStringList cats { swift::misc::CLogCategories::context() };
17  return cats;
18  }
19 
20  IContext::IContext(CCoreFacadeConfig::ContextMode mode, QObject *parent)
21  : QObject(parent), m_mode(mode), m_contextId(QDateTime::currentMSecsSinceEpoch())
22  {
23  if (sApp && !sApp->isShuttingDown())
24  {
26  }
27  }
28 
30 
32 
34 
36 
38 
40  {
41  return this->getRuntime()->getIContextApplication();
42  }
43 
45 
47  {
48  return this->getRuntime()->getIContextOwnAircraft();
49  }
50 
52 
53  void IContext::setDebugEnabled(bool debug)
54  {
55  if (m_debugEnabled == debug) { return; }
56  emit this->changedLogOrDebugSettings();
57  }
58 
59  bool IContext::isDebugEnabled() const { return m_debugEnabled; }
60 
61  void IContext::relayBaseClassSignals(const QString &serviceName, QDBusConnection &connection,
62  const QString &objectPath, const QString &interfaceName)
63  {
64  bool s = connection.connect(serviceName, objectPath, interfaceName, "changedLogOrDebugSettings", this,
65  SIGNAL(changedLogOrDebugSettings()));
66  Q_ASSERT(s);
67  }
68 
70  {
71  return this->getRuntime()->getIContextSimulator();
72  }
73 
74  void IContext::registerWithDBus(const QString &objectPath, CDBusServer *server)
75  {
76  if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; }
77 
78  // remark that registers all SIGNALS, not only the interface ons
79  server->addObject(objectPath, this);
80  }
81 
83  {
84  static const CStatusMessage m(static_cast<IContext *>(nullptr), CStatusMessage::SeverityWarning,
85  u"empty context");
86  return m;
87  }
88 } // namespace swift::core::context
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
Definition: application.cpp:71
void aboutToShutdown()
About to shutdown.
bool isShuttingDown() const
Is application shutting down?
ContextMode
How to handle a given context.
@ LocalInDBusServer
context runs in same process.
context::IContextAudio * getIContextAudio()
Context for audio.
Definition: corefacade.cpp:439
context::IContextOwnAircraft * getIContextOwnAircraft()
Context for own aircraft.
Definition: corefacade.cpp:451
context::IContextApplication * getIContextApplication()
Context for application.
Definition: corefacade.cpp:437
context::IContextNetwork * getIContextNetwork()
Context for network.
Definition: corefacade.cpp:447
context::IContextSimulator * getIContextSimulator()
Context for simulator.
Definition: corefacade.cpp:457
Audio context interface.
Definition: contextaudio.h:61
Base for all context classes.
Definition: context.h:34
void changedLogOrDebugSettings()
Log or debug values changed.
void setDebugEnabled(bool debug)
Set debug flag.
Definition: context.cpp:53
CCoreFacade * getRuntime()
Runtime.
Definition: context.h:57
void relayBaseClassSignals(const QString &serviceName, QDBusConnection &connection, const QString &objectPath, const QString &interfaceName)
Relay signals from this class.
Definition: context.cpp:61
const IContextSimulator * getIContextSimulator() const
Context for simulator.
Definition: context.cpp:69
CCoreFacadeConfig::ContextMode getMode() const
Mode.
Definition: context.h:71
void registerWithDBus(const QString &objectPath, misc::CDBusServer *server)
Register myself in DBus.
Definition: context.cpp:74
virtual void onAboutToShutdown()
Called when shutdown is about to be called.
Definition: context.h:153
IContextNetwork * getIContextNetwork()
Context for network.
Definition: context.cpp:29
const IContextApplication * getIContextApplication() const
Context for application.
Definition: context.cpp:39
IContextAudio * getIContextAudio()
Context for network.
Definition: context.cpp:33
IContextOwnAircraft * getIContextOwnAircraft()
Context for own aircraft.
Definition: context.cpp:44
static const misc::CStatusMessage & statusMessageEmptyContext()
Standard message when status message is returned in empty context.
Definition: context.cpp:82
bool isDebugEnabled() const
Debug enabled?
Definition: context.cpp:59
Custom DBusServer.
Definition: dbusserver.h:34
void addObject(const QString &name, QObject *object)
Add a QObject to be exposed via DBus.
Definition: dbusserver.cpp:226
static const QString & context()
Contexts.
Definition: logcategories.h:66
Streamable status message, e.g.
constexpr static auto SeverityWarning
Status severities.
Free functions in swift::misc.