swift
context.h
Go to the documentation of this file.
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 
5 
6 #ifndef SWIFT_CORE_CONTEXT_CONTEXT_H
7 #define SWIFT_CORE_CONTEXT_CONTEXT_H
8 
9 #include <QObject>
10 #include <QString>
11 #include <QtGlobal>
12 
13 #include "core/corefacade.h"
14 #include "core/corefacadeconfig.h"
15 #include "core/swiftcoreexport.h"
16 #include "misc/logcategories.h"
17 #include "misc/logmessage.h"
18 #include "misc/statusmessage.h"
19 
20 namespace swift::misc
21 {
22  class CLogCategoryList;
23 }
24 namespace swift::core::context
25 {
26  class IContextApplication;
27  class IContextAudio;
28  class IContextNetwork;
29  class IContextOwnAircraft;
30  class IContextSimulator;
31 
33  class SWIFT_CORE_EXPORT IContext : public QObject
34  {
35  Q_OBJECT
36 
37  public:
39  ~IContext() override = default;
40 
42  static const QStringList &getLogCategories();
43 
46  {
48  }
49 
51  bool isLocalObject() const { return isUsingImplementingObject() || m_mode == CCoreFacadeConfig::NotUsed; }
52 
54  bool isEmptyObject() const { return m_mode == CCoreFacadeConfig::NotUsed; }
55 
58  {
59  Q_ASSERT(this->parent());
60  return static_cast<CCoreFacade *>(this->parent());
61  }
62 
64  const CCoreFacade *getRuntime() const
65  {
66  Q_ASSERT(this->parent());
67  return static_cast<CCoreFacade *>(this->parent());
68  }
69 
71  CCoreFacadeConfig::ContextMode getMode() const { return this->m_mode; }
72 
74  qint64 getUniqueId() const { return this->m_contextId; }
75 
76  // ---------------------------------------------------------------
77  // cross context access
78  // ---------------------------------------------------------------
79 
81  const IContextApplication *getIContextApplication() const;
82 
84  IContextApplication *getIContextApplication();
85 
87  IContextAudio *getIContextAudio();
88 
90  const IContextAudio *getIContextAudio() const;
91 
93  IContextNetwork *getIContextNetwork();
94 
96  const IContextNetwork *getIContextNetwork() const;
97 
99  IContextOwnAircraft *getIContextOwnAircraft();
100 
102  const IContextOwnAircraft *getIContextOwnAircraft() const;
103 
105  const IContextSimulator *getIContextSimulator() const;
106 
108  IContextSimulator *getIContextSimulator();
109 
111  void setDebugEnabled(bool debug);
112 
114  bool isDebugEnabled() const;
115 
116  // ---------------------------------------------------------------
117  // All context must implement those functions
118  // ---------------------------------------------------------------
119 
121  virtual QString getPathAndContextId() const = 0;
122 
124  virtual bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator) = 0;
125 
126  signals:
129 
130  protected:
132  IContext(CCoreFacadeConfig::ContextMode mode, QObject *parent);
133 
135  QString buildPathAndContextId(const QString &path) const
136  {
137  return path % u':' % QString::number(this->getUniqueId());
138  }
139 
141  void relayBaseClassSignals(const QString &serviceName, QDBusConnection &connection, const QString &objectPath,
142  const QString &interfaceName);
143 
145  void logEmptyContextWarning(const QString &functionName) const
146  {
148  .warning(u"Empty context called, details: %1")
149  << functionName;
150  }
151 
153  virtual void onAboutToShutdown() {}
154 
156  void registerWithDBus(const QString &objectPath, misc::CDBusServer *server);
157 
159  static const misc::CStatusMessage &statusMessageEmptyContext();
160 
161  private:
163  qint64 m_contextId;
164  bool m_debugEnabled = false;
165  };
166 } // namespace swift::core::context
167 #endif // SWIFT_CORE_CONTEXT_CONTEXT_H
ContextMode
How to handle a given context.
@ NotUsed
during shutdown or not used at all
@ Local
context runs in same process
@ LocalInDBusServer
context runs in same process.
The class providing facades (the contexts) for all DBus relevant operations.
Definition: corefacade.h:57
Audio context interface.
Definition: contextaudio.h:61
Base for all context classes.
Definition: context.h:34
void changedLogOrDebugSettings()
Log or debug values changed.
const CCoreFacade * getRuntime() const
Const runtime.
Definition: context.h:64
CCoreFacade * getRuntime()
Runtime.
Definition: context.h:57
QString buildPathAndContextId(const QString &path) const
Path and context id.
Definition: context.h:135
void logEmptyContextWarning(const QString &functionName) const
Empty context called.
Definition: context.h:145
bool isUsingImplementingObject() const
Using local implementing object?
Definition: context.h:45
bool isEmptyObject() const
Empty object?
Definition: context.h:54
CCoreFacadeConfig::ContextMode getMode() const
Mode.
Definition: context.h:71
virtual void onAboutToShutdown()
Called when shutdown is about to be called.
Definition: context.h:153
bool isLocalObject() const
Local or remote object?
Definition: context.h:51
virtual bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator)=0
Parse a given command line.
virtual QString getPathAndContextId() const =0
Id and path name for round trip protection.
qint64 getUniqueId() const
Unique id.
Definition: context.h:74
~IContext()=default
Destructor.
Custom DBusServer.
Definition: dbusserver.h:34
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition: identifier.h:29
static const QString & contextSlot()
Context slots.
Definition: logcategories.h:87
Class for emitting a log message.
Definition: logmessage.h:27
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Streamable status message, e.g.
Free functions in swift::misc.
#define SWIFT_CORE_EXPORT
Export a class or function from the library.