6 #include <QDBusConnection>
7 #include <QLatin1String>
20 namespace swift::core::context
22 CContextApplicationProxy::CContextApplicationProxy(
const QString &serviceName, QDBusConnection &connection,
28 this->relaySignals(serviceName, connection);
31 &CContextApplicationProxy::processRemoteHotkeyActionCall);
33 m_pingTimer.setObjectName(serviceName +
"::m_pingTimer");
34 connect(&m_pingTimer, &QTimer::timeout,
this, &CContextApplicationProxy::reRegisterApplications);
38 void CContextApplicationProxy::relaySignals(
const QString &serviceName, QDBusConnection &connection)
49 "hotkeyActionsRegistered",
this,
53 "remoteHotkeyAction",
this,
63 m_dBusInterface->
callDBus(QLatin1String(
"changeSettings"), settings, origin);
73 return m_dBusInterface->
callDBusRet<QStringList>(QLatin1String(
"getUnsavedSettingsKeys"));
80 for (
auto it = result.
begin(); it != result.
end(); ++it)
111 m_dBusInterface->
callDBus(QLatin1String(
"registerHotkeyActions"), actions, origin);
117 m_dBusInterface->
callDBus(QLatin1String(
"callHotkeyActionRemotely"), action, argument, origin);
122 m_proxyPingIdentifiers.insert(application);
123 if (m_pingTimer.isActive()) { m_pingTimer.start(); }
130 m_proxyPingIdentifiers.remove(application);
131 m_dBusInterface->
callDBus(QLatin1String(
"unregisterApplication"), application);
144 void CContextApplicationProxy::reRegisterApplications()
146 if (!m_dBusInterface) {
return; }
147 if (m_proxyPingIdentifiers.isEmpty()) {
return; }
148 const QSet<swift::misc::CIdentifier> identifiers = m_proxyPingIdentifiers;
155 if (!connected) {
return false; }
157 static const QString dBusName(
"contexttest");
163 const bool ok = (
id == pingId);
165 else { msg =
"Mismatch in proxy ping, context not ready."; }
170 void CContextApplicationProxy::processRemoteHotkeyActionCall(
const QString &action,
bool argument,
176 <<
"Calling function" << action <<
"from origin" << origin.
getMachineName();
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
CInputManager * getInputManager() const
The input manager, if available.
ContextMode
How to handle a given context.
@ Remote
context runs in a different process.
The class providing facades (the contexts) for all DBus relevant operations.
Application context proxy.
virtual void changeSettings(const swift::misc::CValueCachePacket &settings, const swift::misc::CIdentifier &origin)
Ratify some settings changed by another process.
virtual QStringList getUnsavedSettingsKeys() const
Get keys of all unsaved settings currently in core settings cache.
virtual swift::misc::CIdentifier getApplicationIdentifier() const
Identifier of application, remote side if distributed.
virtual swift::misc::CStatusMessage loadSettings()
Load core settings from disk.
virtual swift::misc::CStatusMessage saveSettings(const QString &keyPrefix={})
Save core settings to disk.
virtual void unregisterApplication(const swift::misc::CIdentifier &application)
Unregister application.
virtual void synchronizeLocalSettings()
Update local settings with settings from core.
virtual swift::core::context::CSettingsDictionary getUnsavedSettingsKeysDescribed() const
Get keys and descriptions of all unsaved settings currently in core settings cache.
virtual swift::misc::CStatusMessage saveSettingsByKey(const QStringList &keys)
Save core settings to disk.
static bool isContextResponsive(const QString &dbusAddress, QString &msg, int timeoutMs=1500)
Used to test if there is a core running?
virtual swift::misc::CIdentifier registerApplication(const swift::misc::CIdentifier &application)
Register application, can also be used for ping.
virtual swift::misc::CIdentifierList getRegisteredApplications() const
All registered applications.
virtual swift::misc::CValueCachePacket getAllSettings() const
Get all settings currently in core settings cache.
virtual void registerHotkeyActions(const QStringList &actions, const swift::misc::CIdentifier &origin)
Register hotkey action implemented by another process.
virtual void callHotkeyActionRemotely(const QString &action, bool argument, const swift::misc::CIdentifier &origin)
Call a hotkey action on a remote process.
Application context interface.
void remoteHotkeyAction(const QString &action, bool argument, const swift::misc::CIdentifier &origin)
Call a hotkey action on a remote process.
static const QString & ObjectPath()
Service path.
static const QString & InterfaceName()
Service name.
void registrationChanged()
A component changes.
void hotkeyActionsRegistered(const QStringList &actions, const swift::misc::CIdentifier &origin)
New action was registered.
static constexpr int PingIdentifiersMs
how often identifiers are pinged
void settingsChanged(const swift::misc::CValueCachePacket &settings, const swift::misc::CIdentifier &origin)
One or more settings were changed.
void relayBaseClassSignals(const QString &serviceName, QDBusConnection &connection, const QString &objectPath, const QString &interfaceName)
Relay signals from this class.
static void disconnectFromDBus(const QDBusConnection &connection, const QString &dBusAddress)
Disconnect from Bus/Peer to peer.
static QDBusConnection connectToDBus(const QString &dbusAddress, const QString &name={})
Connect to DBus.
static bool isDBusAvailable(const QString &host, int port, int timeoutMs=1500)
Is there a DBus server running at the given address?
static const QString & coreServiceName()
Default service name.
const Value value(const Key &key) const
Returns the value associated with the key.
iterator end()
Returns iterator at the end of the dictionary.
iterator begin()
Returns iterator at the beginning of the dictionary.
Used for hand written interface based on virtual methods.
void callDBus(QLatin1String method, Args &&...args)
Call DBus, no return value.
Ret callDBusRet(QLatin1String method, Args &&...args)
Call DBus with synchronous return value.
Value object encapsulating information identifying a component of a modular distributed swift process...
const QString & getMachineName() const
Machine name.
bool isFromLocalMachine() const
Check if originating from the same local machine.
static const CIdentifier & null()
Null (empty) identifier.
Value object encapsulating a list of object identifiers.
static const QString & contextSlot()
Context slots.
Class for emitting a log message.
Derived & debug()
Set the severity to debug.
static CSettingsCache * instance()
Return the singleton instance.
Streamable status message, e.g.
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...
QString getHumanReadableName(const QString &key) const
Return the human readable name of the given key, or the raw key string if there is none.
Value class used for signalling changed values in the cache.
Free functions in swift::misc.