1 /* qdbusreply.h QDBusReply object - a reply from D-Bus
3 * Copyright (C) 2006 Trolltech AS. All rights reserved.
4 * Author: Thiago Macieira <thiago.macieira@trolltech.com>
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <QtCore/qglobal.h>
28 #include <QtCore/qvariant.h>
30 #include "qdbusmacros.h"
31 #include "qdbusmessage.h"
32 #include "qdbuserror.h"
34 #include "qdbustypehelper_p.h"
41 inline QDBusReply(const QDBusMessage &reply)
46 inline QDBusReply& operator=(const QDBusMessage& reply)
50 m_data = QDBusTypeHelper<Type>::fromVariant(reply.at(0));
56 inline QDBusReply(const QDBusError &error = QDBusError())
57 : m_error(error), m_data(Type())
60 inline QDBusReply& operator=(const QDBusError& error)
67 inline QDBusReply& operator=(const QDBusReply& other)
69 m_error = other.m_error;
70 m_data = other.m_data;
74 inline bool isError() const { return m_error.isValid(); }
75 inline bool isSuccess() const { return !m_error.isValid(); }
77 inline const QDBusError& error() { return m_error; }
84 inline operator Type ()
89 static QDBusReply<T> fromVariant(const QDBusReply<QVariant> &variantReply)
92 retval.m_error = variantReply.m_error;
93 if (retval.isSuccess()) {
94 retval.m_data = qvariant_cast<Type>(variantReply.m_data);
95 if (!qVariantCanConvert<Type>(variantReply.m_data))
96 retval.m_error = QDBusError(QDBusError::InvalidSignature,
97 QLatin1String("Unexpected reply signature"));
108 // specialize for void:
110 class QDBUS_EXPORT QDBusReply<void>
113 inline QDBusReply(const QDBusMessage &reply)
117 inline QDBusReply(const QDBusError &error)
122 inline bool isError() const { return m_error.isValid(); }
123 inline bool isSuccess() const { return !m_error.isValid(); }
125 inline const QDBusError& error() { return m_error; }