KWallet

kwalletdbuscontext.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2022 Slava Aseev <nullptrnine@basealt.ru>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7#ifndef _KWALLETDBUSCONTEXT_H_
8#define _KWALLETDBUSCONTEXT_H_
9
10#include "qdbuserror.h"
11#include <QDBusConnection>
12#include <QDBusContext>
13#include <QDBusMessage>
14
15/* FDO_DBUS_CONTEXT macro will be replaced by KWalletDBusContextDummy during
16 * preprocessing if FDO_ENABLE_DUMMY_MESSAGE_CONNECTION was defined,
17 * otherwise we get QDBusContext.
18 *
19 * This is used for mocking QDBusContext in autotests.
20 *
21 * QDBusContext's connection() and message() member functions can't be called
22 * without a real connection context (this cause segfault).
23 * So we need to use KWalletDBusContextDummy in case some DBus-related
24 * member functions may call connection()/message().
25 *
26 * This header defines FDO_DBUS_CONTEXT macro that should be used instead of
27 * QDBusContext in all DBus-related which we want to use in autotests.
28 */
29
30#ifdef FDO_ENABLE_DUMMY_MESSAGE_CONNECTION
31
32class KWalletDBusContextDummy : public QDBusContext
33{
34public:
35 const QDBusMessage &message()
36 {
37 static auto msg = QDBusMessage::createSignal(QStringLiteral("dummy"), QStringLiteral("dummy"), QStringLiteral("dummy"));
38 return msg;
39 }
41 {
43 }
44};
45
46#define FDO_DBUS_CONTEXT KWalletDBusContextDummy
47
48#else
49
50#define FDO_DBUS_CONTEXT QDBusContext
51
52#endif
53
54#endif // _KWALLETDBUSCONTEXT_H_
QDBusConnection sessionBus()
QDBusConnection connection() const const
const QDBusMessage & message() const const
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.