swift
contextapplication.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 
5 
6 #include <algorithm>
7 
8 #include <QtDebug>
9 
10 #include "core/application.h"
14 #include "core/corefacade.h"
15 #include "core/inputmanager.h"
16 #include "misc/dbus.h"
17 #include "misc/dbusserver.h"
18 #include "misc/logcategories.h"
19 #include "misc/logmessage.h"
20 #include "misc/settingscache.h"
21 #include "misc/statusmessage.h"
22 
23 using namespace swift::core;
24 using namespace swift::core::context;
25 using namespace swift::misc;
26 
27 namespace swift::core::context
28 {
30  CDBusServer *server, QDBusConnection &connection)
31  {
32  switch (mode)
33  {
34  case CCoreFacadeConfig::Local: return new CContextApplication(mode, parent);
36  {
37  auto *context = new CContextApplication(mode, parent);
38  context->registerWithDBus(ObjectPath(), server);
39  return context;
40  }
42  return new CContextApplicationProxy(CDBusServer::coreServiceName(connection), connection, mode, parent);
44  default: return new CContextApplicationEmpty(parent);
45  }
46  }
47 
49  : IContext(mode, runtime)
50  {
51  if (mode == CCoreFacadeConfig::NotUsed) { return; }
52  QPointer<IContextApplication> myself(this);
53 
55  [=](const CValueCachePacket &settings) {
56  if (!myself) { return; }
57  this->changeSettings(settings, {});
58  });
59 
61  [](const CValueCachePacket &settings, const CIdentifier &origin) {
62  // Intentionally don't check for round trip here
64  });
65 
66  Q_ASSERT_X(sApp && sApp->getInputManager(), Q_FUNC_INFO, "Missing input manager");
68  [=](const QStringList &actions) {
69  if (!myself) { return; }
70  this->registerHotkeyActions(actions, {});
71  });
72  Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey action failed");
73  Q_UNUSED(s);
74 
76  [=](const QStringList &actions, const CIdentifier &origin) {
77  if (origin.hasApplicationProcessId()) { return; }
79  });
80  Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey actions failed");
81  Q_UNUSED(s);
82 
83  s = connect(
85  [=](const QString &action, bool argument) {
86  if (!myself) { return; }
87  this->callHotkeyActionRemotely(action, argument, {});
88  },
89  Qt::QueuedConnection);
90 
91  Q_ASSERT_X(s, Q_FUNC_INFO, "Connect remote action failed");
92  Q_UNUSED(s);
93 
94  // Enable event forwarding from GUI process to core
96  }
97 
98  void IContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin)
99  {
100  Q_UNUSED(settings);
101  Q_UNUSED(origin);
102  qFatal("Not implemented"); // avoid losing a change during context interface construction
103  }
104 
105  void IContextApplication::registerHotkeyActions(const QStringList &actions, const CIdentifier &origin)
106  {
107  Q_UNUSED(actions);
108  Q_UNUSED(origin);
109  qFatal("Not implemented"); // avoid losing a change during context interface construction
110  }
111 
112  void IContextApplication::callHotkeyActionRemotely(const QString &action, bool argument, const CIdentifier &origin)
113  {
114  Q_UNUSED(action);
115  Q_UNUSED(argument);
116  Q_UNUSED(origin);
117  }
118 
119  bool IContextApplication::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
120  {
121  if (!this->getRuntime()) { return false; }
122  return this->getRuntime()->parseCommandLine(commandLine, originator);
123  }
124 } // namespace swift::core::context
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
Definition: application.cpp:71
CInputManager * getInputManager() const
The input manager, if available.
Definition: application.h:302
ContextMode
How to handle a given context.
@ NotUsed
during shutdown or not used at all
@ Local
context runs in same process
@ Remote
context runs in a different process.
@ LocalInDBusServer
context runs in same process.
The class providing facades (the contexts) for all DBus relevant operations.
Definition: corefacade.h:57
bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator)
Parse command line in all contexts.
Definition: corefacade.cpp:184
void registerRemoteActions(const QStringList &actions)
Register remote actions.
void remoteActionFromLocal(const QString &action, bool argument)
Event hotkeyfunction occured.
void hotkeyActionRegistered(const QStringList &actions)
New hotkey action is registered.
void setForwarding(bool enabled)
Enable event forwarding to core.
Definition: inputmanager.h:81
bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator)
Forward to facade.
virtual void callHotkeyActionRemotely(const QString &action, bool argument, const misc::CIdentifier &origin)
Call a hotkey action on a remote process.
void hotkeyActionsRegistered(const QStringList &actions, const swift::misc::CIdentifier &origin)
New action was registered.
virtual void changeSettings(const misc::CValueCachePacket &settings, const misc::CIdentifier &origin)
Ratify some settings changed by another process.
IContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime)
Constructor.
void settingsChanged(const swift::misc::CValueCachePacket &settings, const swift::misc::CIdentifier &origin)
One or more settings were changed.
static IContextApplication * create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, swift::misc::CDBusServer *server, QDBusConnection &connection)
Factory method.
virtual void registerHotkeyActions(const QStringList &actions, const misc::CIdentifier &origin)
Register hotkey action implemented by another process.
Base for all context classes.
Definition: context.h:34
CCoreFacade * getRuntime()
Runtime.
Definition: context.h:57
Custom DBusServer.
Definition: dbusserver.h:34
static const QString & coreServiceName()
Default service name.
Definition: dbusserver.cpp:98
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition: identifier.h:29
static CSettingsCache * instance()
Return the singleton instance.
void changeValuesFromRemote(const swift::misc::CValueCachePacket &values, const swift::misc::CIdentifier &originator)
Notify this cache that values have been changed by one of the duplicate caches in the multi-process e...
void valuesChangedByLocal(const swift::misc::CValueCachePacket &values)
Emitted when values in the cache are changed by an object in this very process. The interprocess comm...
Value class used for signalling changed values in the cache.
Definition: valuecache.h:67
Backend services of the swift project, like dealing with the network or the simulators.
Definition: actionbind.cpp:7
Free functions in swift::misc.