swift
Loading...
Searching...
No Matches
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
23using namespace swift::core;
24using namespace swift::core::context;
25using namespace swift::misc;
26
27namespace swift::core::context
28{
30 CDBusServer *server, QDBusConnection &connection)
31 {
32 switch (mode)
33 {
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 {
52 {
53 return;
54 }
56
58 [=, this](const CValueCachePacket &settings) {
59 if (!myself)
60 {
61 return;
62 }
63 this->changeSettings(settings, {});
64 });
65
67 [](const CValueCachePacket &settings, const CIdentifier &origin) {
68 // Intentionally don't check for round trip here
70 });
71
72 Q_ASSERT_X(sApp && sApp->getInputManager(), Q_FUNC_INFO, "Missing input manager");
73 bool s = connect(sApp->getInputManager(), &CInputManager::hotkeyActionRegistered, this,
74 [=, this](const QStringList &actions) {
75 if (!myself)
76 {
77 return;
78 }
79 this->registerHotkeyActions(actions, {});
80 });
81 Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey action failed");
82 Q_UNUSED(s);
83
84 s = connect(this, &IContextApplication::hotkeyActionsRegistered, sApp->getInputManager(),
85 [=](const QStringList &actions, const CIdentifier &origin) {
86 if (origin.hasApplicationProcessId())
87 {
88 return;
89 }
90 sApp->getInputManager()->registerRemoteActions(actions);
91 });
92 Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey actions failed");
93 Q_UNUSED(s);
94
95 s = connect(
96 sApp->getInputManager(), &CInputManager::remoteActionFromLocal, this,
97 [=, this](const QString &action, bool argument) {
98 if (!myself)
99 {
100 return;
101 }
102 this->callHotkeyActionRemotely(action, argument, {});
103 },
105
106 Q_ASSERT_X(s, Q_FUNC_INFO, "Connect remote action failed");
107 Q_UNUSED(s);
108
109 // Enable event forwarding from GUI process to core
110 sApp->getInputManager()->setForwarding(true);
111 }
112
114 {
115 Q_UNUSED(settings);
116 Q_UNUSED(origin);
117 qFatal("Not implemented"); // avoid losing a change during context interface construction
118 }
119
121 {
122 Q_UNUSED(actions);
123 Q_UNUSED(origin);
124 qFatal("Not implemented"); // avoid losing a change during context interface construction
125 }
126
127 void IContextApplication::callHotkeyActionRemotely(const QString &action, bool argument, const CIdentifier &origin)
128 {
129 Q_UNUSED(action);
130 Q_UNUSED(argument);
131 Q_UNUSED(origin);
132 }
133
134 bool IContextApplication::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
135 {
136 if (!this->getRuntime())
137 {
138 return false;
139 }
140 return this->getRuntime()->parseCommandLine(commandLine, originator);
141 }
142} // namespace swift::core::context
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
void remoteActionFromLocal(const QString &action, bool argument)
Event hotkeyfunction occured.
void hotkeyActionRegistered(const QStringList &actions)
New hotkey action is registered.
bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator)
Forward to facade.
static const QString & ObjectPath()
Service path.
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.
IContext(CCoreFacadeConfig::ContextMode mode, QObject *parent)
Constructor.
Definition context.cpp:20
CCoreFacade * getRuntime()
Runtime.
Definition context.h:57
Custom DBusServer.
Definition dbusserver.h:34
static const QString & coreServiceName()
Default service name.
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.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QueuedConnection