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