From 9393d6b459d02a8508750a846bf97a69e48c97e2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 6 Mar 2006 14:29:39 +0000 Subject: 2006-03-06 Thiago Macieira * qt/*: * dbus/qdbus.h: Sync with KDE Subversion revision 516237. This represents the first feature-complete version of the Qt4 bindings since I took ove maintainership. --- qt/qdbusreply.h | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 qt/qdbusreply.h (limited to 'qt/qdbusreply.h') diff --git a/qt/qdbusreply.h b/qt/qdbusreply.h new file mode 100644 index 00000000..3d7a0085 --- /dev/null +++ b/qt/qdbusreply.h @@ -0,0 +1,110 @@ +/* qdbusreply.h QDBusReply object - a reply from D-Bus + * + * Copyright (C) 2006 Trolltech AS. All rights reserved. + * Author: Thiago Macieira + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef QDBUSREPLY_H +#define QDBUSREPLY_H + +#include +#include + +#include "qdbusmacros.h" +#include "qdbusmessage.h" +#include "qdbuserror.h" +#include "qdbusvariant.h" + +template +class QDBUS_EXPORT QDBusReply +{ + typedef T Type; +public: + + inline QDBusReply(const QDBusMessage &reply) + : m_error(reply) + { + if (isSuccess()) + m_data = qvariant_cast(reply.at(0)); + } + inline QDBusReply(const QDBusError &error) + : m_error(error) + { + } + + inline bool isError() const { return m_error.isValid(); } + inline bool isSuccess() const { return !m_error.isValid(); } + + inline const QDBusError& error() { return m_error; } + + inline Type value() + { + return m_data; + } + + inline operator Type () + { + return m_data; + } + + static QDBusReply fromVariant(const QDBusReply &variantReply) + { + QDBusReply retval; + retval.m_error = variantReply.m_error; + if (retval.isSuccess()) { + retval.m_data = qvariant_cast(variantReply.value); + if (!qVariantCanConvert(variantReply.value)) + retval.m_error = QDBusError(QLatin1String(DBUS_ERROR_INVALID_SIGNATURE), + QLatin1String("Unexpected reply signature")); + } + return retval; + } + +private: + QDBusError m_error; + Type m_data; +}; + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +// specialize for void: +template<> +class QDBUS_EXPORT QDBusReply +{ +public: + inline QDBusReply(const QDBusMessage &reply) + : m_error(reply) + { + } + inline QDBusReply(const QDBusError &error) + : m_error(error) + { + } + + inline bool isError() const { return m_error.isValid(); } + inline bool isSuccess() const { return !m_error.isValid(); } + + inline const QDBusError& error() { return m_error; } + +private: + QDBusError m_error; +}; +#endif + +#endif -- cgit