1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDBUSMESSAGE_H
5#define QDBUSMESSAGE_H
6
7#include <QtDBus/qtdbusglobal.h>
8#include <QtDBus/qdbuserror.h>
9#include <QtCore/qlist.h>
10#include <QtCore/qvariant.h>
11
12#if !defined(QT_NO_DBUS) && !defined(QT_BOOTSTRAPPED)
13
14#if defined(Q_OS_WIN) && defined(interface)
15# undef interface
16#endif
17
18QT_BEGIN_NAMESPACE
19
20class QDBusMessagePrivate;
21class Q_DBUS_EXPORT QDBusMessage
22{
23public:
24 enum MessageType {
25 InvalidMessage,
26 MethodCallMessage,
27 ReplyMessage,
28 ErrorMessage,
29 SignalMessage
30 };
31
32 QDBusMessage();
33 QDBusMessage(const QDBusMessage &other);
34 QDBusMessage &operator=(QDBusMessage &&other) noexcept { swap(other); return *this; }
35 QDBusMessage &operator=(const QDBusMessage &other);
36 ~QDBusMessage();
37
38 void swap(QDBusMessage &other) noexcept { qt_ptr_swap(lhs&: d_ptr, rhs&: other.d_ptr); }
39
40 static QDBusMessage createSignal(const QString &path, const QString &interface,
41 const QString &name);
42 static QDBusMessage createTargetedSignal(const QString &service, const QString &path,
43 const QString &interface, const QString &name);
44 static QDBusMessage createMethodCall(const QString &destination, const QString &path,
45 const QString &interface, const QString &method);
46 static QDBusMessage createError(const QString &name, const QString &msg);
47 static inline QDBusMessage createError(const QDBusError &err)
48 { return createError(name: err.name(), msg: err.message()); }
49 static inline QDBusMessage createError(QDBusError::ErrorType type, const QString &msg)
50 { return createError(name: QDBusError::errorString(error: type), msg); }
51
52 QDBusMessage createReply(const QList<QVariant> &arguments = QList<QVariant>()) const;
53 QDBusMessage createReply(const QVariant &argument) const;
54
55 QDBusMessage createErrorReply(const QString &name, const QString &msg) const;
56 inline QDBusMessage createErrorReply(const QDBusError &err) const
57 { return createErrorReply(name: err.name(), msg: err.message()); }
58 QDBusMessage createErrorReply(QDBusError::ErrorType type, const QString &msg) const;
59
60 // there are no setters; if this changes, see qdbusmessage_p.h
61 QString service() const;
62 QString path() const;
63 QString interface() const;
64 QString member() const;
65 QString errorName() const;
66 QString errorMessage() const;
67 MessageType type() const;
68 QString signature() const;
69
70 bool isReplyRequired() const;
71
72 void setDelayedReply(bool enable) const;
73 bool isDelayedReply() const;
74
75 void setAutoStartService(bool enable);
76 bool autoStartService() const;
77
78 void setInteractiveAuthorizationAllowed(bool enable);
79 bool isInteractiveAuthorizationAllowed() const;
80
81 void setArguments(const QList<QVariant> &arguments);
82 QList<QVariant> arguments() const;
83
84 QDBusMessage &operator<<(const QVariant &arg);
85
86private:
87 friend class QDBusMessagePrivate;
88 QDBusMessagePrivate *d_ptr;
89};
90Q_DECLARE_SHARED(QDBusMessage)
91
92#ifndef QT_NO_DEBUG_STREAM
93Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusMessage &);
94#endif
95
96QT_END_NAMESPACE
97
98QT_DECL_METATYPE_EXTERN(QDBusMessage, Q_DBUS_EXPORT)
99
100#else
101class Q_DBUS_EXPORT QDBusMessage {}; // dummy class for moc
102#endif // QT_NO_DBUS
103#endif
104
105

source code of qtbase/src/dbus/qdbusmessage.h