Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
DBusBridge.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3#pragma once
4
5#include <QObject>
6#include <QString>
7#include <QVariantList>
8#include <QtDBus/QDBusMessage>
9
10#include "phosphorcontrol_export.h"
11
12namespace PhosphorControl {
13
19inline constexpr int DefaultSyncTimeoutMs = 500;
20
41struct PHOSPHORCONTROL_EXPORT DBusEndpoint
42{
43 QString service;
44 QString objectPath;
47};
48
64class PHOSPHORCONTROL_EXPORT DBusBridge : public QObject
65{
66 Q_OBJECT
67
68public:
69 explicit DBusBridge(DBusEndpoint endpoint, QObject* parent = nullptr);
70 ~DBusBridge() override;
71
73
76 QDBusMessage call(const QString& method, const QVariantList& args = {}) const;
77
80 QDBusMessage callOn(const QString& interfaceName, const QString& method, const QVariantList& args = {}) const;
81
85 void asyncCall(const QString& method, const QVariantList& args = {});
86
89 void asyncCallOn(const QString& interfaceName, const QString& method, const QVariantList& args = {});
90
91private:
92 DBusEndpoint m_endpoint;
93 // Tracks in-flight QDBusPendingCallWatcher children so the soft-cap
94 // warning is O(1) and burst-safe. The previous shape did
95 // `findChildren<...>().size()` on every asyncCallOn (O(N) child
96 // scan on the hot path), and the breach check fired only on the
97 // exact transition count == cap, which two near-simultaneous calls
98 // could step over without ever satisfying. Incrementing under each
99 // watcher's creation + decrementing in its `finished` lambda
100 // (single-threaded; bridge is parented to the owning thread)
101 // keeps the count accurate without the scan.
102 int m_outstandingAsyncCalls = 0;
103 // One-shot latch so the soft-cap warning fires exactly once per
104 // process even if the queue oscillates around the cap. Without
105 // this, a steady-state count near 128 would re-warn every time
106 // the count crossed back up to the cap.
107 bool m_softCapWarned = false;
108};
109
110} // namespace PhosphorControl
void asyncCallOn(const QString &interfaceName, const QString &method, const QVariantList &args={})
Fire-and-forget call on a specified interface.
DBusBridge(DBusEndpoint endpoint, QObject *parent=nullptr)
void asyncCall(const QString &method, const QVariantList &args={})
Fire-and-forget call on the endpoint's default interface.
DBusEndpoint endpoint() const
QDBusMessage callOn(const QString &interfaceName, const QString &method, const QVariantList &args={}) const
Synchronous call on a specified interface (for services with multiple interfaces on the same object p...
QDBusMessage call(const QString &method, const QVariantList &args={}) const
Synchronous call on the endpoint's default interface, bounded by syncTimeoutMs.
Definition ApplicationController.h:21
constexpr int DefaultSyncTimeoutMs
Default bound for synchronous DBusBridge::call(): "definitely somethingis wrong" rather than expected...
Definition DBusBridge.h:19
Configured endpoint for a single D-Bus service the settings app talks to.
Definition DBusBridge.h:42
QString service
Definition DBusBridge.h:43
int syncTimeoutMs
Definition DBusBridge.h:46
QString objectPath
Definition DBusBridge.h:44
QString interfaceName
Definition DBusBridge.h:45