| 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 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QDBUSERROR_H |
| 6 | #define QDBUSERROR_H |
| 7 | |
| 8 | #include <QtDBus/qtdbusglobal.h> |
| 9 | #include <QtCore/qobjectdefs.h> |
| 10 | #include <QtCore/qstring.h> |
| 11 | |
| 12 | #ifndef QT_NO_DBUS |
| 13 | |
| 14 | struct DBusError; |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | |
| 19 | class QDBusMessage; |
| 20 | |
| 21 | class Q_DBUS_EXPORT QDBusError |
| 22 | { |
| 23 | Q_GADGET |
| 24 | public: |
| 25 | enum ErrorType { |
| 26 | NoError = 0, |
| 27 | Other = 1, |
| 28 | Failed, |
| 29 | NoMemory, |
| 30 | ServiceUnknown, |
| 31 | NoReply, |
| 32 | BadAddress, |
| 33 | NotSupported, |
| 34 | LimitsExceeded, |
| 35 | AccessDenied, |
| 36 | NoServer, |
| 37 | Timeout, |
| 38 | NoNetwork, |
| 39 | AddressInUse, |
| 40 | Disconnected, |
| 41 | InvalidArgs, |
| 42 | UnknownMethod, |
| 43 | TimedOut, |
| 44 | InvalidSignature, |
| 45 | UnknownInterface, |
| 46 | UnknownObject, |
| 47 | UnknownProperty, |
| 48 | PropertyReadOnly, |
| 49 | InternalError, |
| 50 | InvalidService, |
| 51 | InvalidObjectPath, |
| 52 | InvalidInterface, |
| 53 | InvalidMember, |
| 54 | |
| 55 | #ifndef Q_QDOC |
| 56 | // don't use this one! |
| 57 | LastErrorType = InvalidMember |
| 58 | #endif |
| 59 | }; |
| 60 | Q_ENUM(ErrorType) |
| 61 | |
| 62 | QDBusError(); |
| 63 | #ifndef QT_BOOTSTRAPPED |
| 64 | explicit QDBusError(const DBusError *error); |
| 65 | Q_IMPLICIT QDBusError(const QDBusMessage& msg); |
| 66 | #endif |
| 67 | QDBusError(ErrorType error, const QString &message); |
| 68 | QDBusError(const QDBusError &other); |
| 69 | QDBusError(QDBusError &&other) noexcept |
| 70 | : code(other.code), msg(std::move(other.msg)), nm(std::move(other.nm)) |
| 71 | {} |
| 72 | QDBusError &operator=(QDBusError &&other) noexcept { swap(other); return *this; } |
| 73 | QDBusError &operator=(const QDBusError &other); |
| 74 | #ifndef QT_BOOTSTRAPPED |
| 75 | QDBusError &operator=(const QDBusMessage &msg); |
| 76 | #endif |
| 77 | |
| 78 | void swap(QDBusError &other) noexcept |
| 79 | { |
| 80 | std::swap(a&: code, b&: other.code); |
| 81 | msg.swap(other&: other.msg); |
| 82 | nm.swap(other&: other.nm); |
| 83 | } |
| 84 | |
| 85 | ErrorType type() const; |
| 86 | QString name() const; |
| 87 | QString message() const; |
| 88 | bool isValid() const; |
| 89 | |
| 90 | static QString errorString(ErrorType error); |
| 91 | |
| 92 | private: |
| 93 | ErrorType code; |
| 94 | QString msg; |
| 95 | QString nm; |
| 96 | // ### This class has an implicit (therefore inline) destructor |
| 97 | // so the following field cannot be used: |
| 98 | void *unused; |
| 99 | }; |
| 100 | Q_DECLARE_SHARED(QDBusError) |
| 101 | |
| 102 | #ifndef QT_NO_DEBUG_STREAM |
| 103 | Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusError &); |
| 104 | #endif |
| 105 | |
| 106 | QT_END_NAMESPACE |
| 107 | |
| 108 | QT_DECL_METATYPE_EXTERN(QDBusError, Q_DBUS_EXPORT) |
| 109 | #else |
| 110 | QT_BEGIN_NAMESPACE |
| 111 | class Q_DBUS_EXPORT QDBusError {}; // dummy class for moc |
| 112 | QT_END_NAMESPACE |
| 113 | #endif // QT_NO_DBUS |
| 114 | #endif |
| 115 | |