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
91template<typename Fn>
92void loadSettingAsync(QObject* parent, const QString& name, Fn&& onValue)
93{
94 auto* watcher = new QDBusPendingCallWatcher(
95 daemonClient().asyncCall(Service::Interface::Settings, QStringLiteral("getSetting"), {name}), parent);
96 QObject::connect(watcher, &QDBusPendingCallWatcher::finished, parent,
97 [name, onValue = std::forward<Fn>(onValue)](QDBusPendingCallWatcher* w) {
98 w->deleteLater();
99 QDBusPendingReply<QVariant> reply = *w;
100 if (reply.isValid()) {
101 QVariant value = reply.value();
102 if (value.canConvert<QDBusVariant>()) {
103 value = value.value<QDBusVariant>().variant();
104 }
105 onValue(value);
106 qCDebug(lcPhosphorProtocol) << "Loaded" << name;
107 } else {
108 qCWarning(lcPhosphorProtocol)
109 << "loadSettingAsync: failed to load" << name << ":" << reply.error().message();
110 }
111 });
112}
113
114} // namespace ClientHelpers
115
116} // 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.
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:92
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
constexpr QLatin1String Settings("org.plasmazones.Settings")
constexpr int SyncCallTimeoutMs
Definition ServiceConstants.h:99
constexpr QLatin1String Name("org.plasmazones")
D-Bus service constants shared by all compositor plugins.
constexpr QLatin1String ObjectPath("/PlasmaZones")
D-Bus marshalling for the autotile value types (see AutotileTypes.h).
Definition AutotileMarshalling.h:16
PHOSPHORPROTOCOL_EXPORT const QLoggingCategory & lcPhosphorProtocol()
PhosphorDBus::Client daemonClient()
A PhosphorDBus::Client bound to the PlasmaZones daemon.
Definition ClientHelpers.h:36