Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ClientHelpers.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include <PhosphorProtocol/phosphorprotocol_export.h>
8
10
11#include <QDBusConnection>
12#include <QDBusPendingCall>
13#include <QDBusPendingCallWatcher>
14#include <QDBusPendingReply>
15#include <QLoggingCategory>
16#include <QObject>
17#include <QVariant>
18
19#include <utility>
20
21namespace PhosphorProtocol {
22
23PHOSPHORPROTOCOL_EXPORT const QLoggingCategory& lcPhosphorProtocol();
24
37{
38 return PhosphorDBus::Client(QDBusConnection::sessionBus(), Service::Name, Service::ObjectPath,
40}
41
48namespace ClientHelpers {
49
52inline void fireAndForget(QObject* parent, const QString& interface, const QString& method, const QVariantList& args,
53 const QString& logContext = {})
54{
55 daemonClient().fireAndForget(parent, interface, method, args, logContext);
56}
57
60inline void sendOneWay(const QString& interface, const QString& method, const QVariantList& args = {})
61{
62 daemonClient().sendOneWay(interface, method, args);
63}
64
67inline QDBusPendingCall asyncCall(const QString& interface, const QString& method, const QVariantList& args = {})
68{
69 return daemonClient().asyncCall(interface, method, args);
70}
71
75inline QDBusMessage syncCall(const QString& interface, const QString& method, const QVariantList& args = {})
76{
77 return daemonClient().syncCall(interface, method, args, Service::SyncCallTimeoutMs);
78}
79
99inline void reloadDaemonSettings(QObject* parent, const QString& logContext = {})
100{
101 fireAndForget(parent, Service::Interface::Settings, QStringLiteral("reloadSettings"), {}, logContext);
102}
103
117{
118 syncCall(Service::Interface::Settings, QStringLiteral("reloadSettings"));
119}
120
132template<typename Fn>
133void loadSettingAsync(QObject* parent, const QString& name, Fn&& onValue)
134{
135 auto* watcher = new QDBusPendingCallWatcher(
136 daemonClient().asyncCall(Service::Interface::Settings, QStringLiteral("getSetting"), {name}), parent);
137 QObject::connect(watcher, &QDBusPendingCallWatcher::finished, parent,
138 [name, onValue = std::forward<Fn>(onValue)](QDBusPendingCallWatcher* w) {
139 w->deleteLater();
140 QDBusPendingReply<QVariant> reply = *w;
141 if (reply.isValid()) {
142 QVariant value = reply.value();
143 if (value.canConvert<QDBusVariant>()) {
144 value = value.value<QDBusVariant>().variant();
145 }
146 onValue(value);
147 qCDebug(lcPhosphorProtocol) << "Loaded" << name;
148 } else {
149 qCWarning(lcPhosphorProtocol)
150 << "loadSettingAsync: failed to load" << name << ":" << reply.error().message();
151 }
152 });
153}
154
155} // namespace ClientHelpers
156
157} // namespace PhosphorProtocol
A lightweight, service-agnostic D-Bus method-call client.
Definition Client.h:36
void sendOneWay(const QString &interface, const QString &method, const QVariantList &args={}) const
Send a one-way notification with no expected reply.
QDBusMessage syncCall(const QString &interface, const QString &method, const QVariantList &args={}, int timeoutMs=-1) const
Blocking method call with an explicit timeout.
QDBusPendingCall asyncCall(const QString &interface, const QString &method, const QVariantList &args={}) const
Issue an async method call and return the pending result.
void fireAndForget(QObject *parent, const QString &interface, const QString &method, const QVariantList &args, const QString &logContext={}) const
Fire-and-forget async call with error logging.
void reloadDaemonSettings(QObject *parent, const QString &logContext={})
Ask the daemon to reparse config.json from disk.
Definition ClientHelpers.h:99
QDBusPendingCall asyncCall(const QString &interface, const QString &method, const QVariantList &args={})
Async method call to the daemon; caller attaches its own watcher.
Definition ClientHelpers.h:67
void sendOneWay(const QString &interface, const QString &method, const QVariantList &args={})
One-way notification to the daemon with no expected reply.
Definition ClientHelpers.h:60
void loadSettingAsync(QObject *parent, const QString &name, Fn &&onValue)
Async helper for loading a single daemon setting.
Definition ClientHelpers.h:133
void fireAndForget(QObject *parent, const QString &interface, const QString &method, const QVariantList &args, const QString &logContext={})
Fire-and-forget async call to the daemon, with error logging.
Definition ClientHelpers.h:52
QDBusMessage syncCall(const QString &interface, const QString &method, const QVariantList &args={})
Blocking daemon call bounded by Service::SyncCallTimeoutMs.
Definition ClientHelpers.h:75
void reloadDaemonSettingsBlocking()
Blocking form of reloadDaemonSettings.
Definition ClientHelpers.h:116
constexpr QLatin1String Settings("org.plasmazones.Settings")
constexpr int SyncCallTimeoutMs
Definition ServiceConstants.h:337
constexpr QLatin1String Name("org.plasmazones")
D-Bus service constants shared by all compositor plugins.
constexpr QLatin1String ObjectPath("/PlasmaZones")
D-Bus marshalling for the shared tiling-family value types (see AutotileTypes.h; the file names preda...
Definition AutotileMarshalling.h:19
PHOSPHORPROTOCOL_EXPORT const QLoggingCategory & lcPhosphorProtocol()
PhosphorDBus::Client daemonClient()
A PhosphorDBus::Client bound to the Phosphor daemon.
Definition ClientHelpers.h:36