Qt 4.8
qdbusreply.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDBus module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QDBUSREPLY_H
43 #define QDBUSREPLY_H
44 
45 #include <QtCore/qglobal.h>
46 #include <QtCore/qvariant.h>
47 
48 #include <QtDBus/qdbusmacros.h>
49 #include <QtDBus/qdbusmessage.h>
50 #include <QtDBus/qdbuserror.h>
51 #include <QtDBus/qdbusextratypes.h>
52 #include <QtDBus/qdbuspendingreply.h>
53 
54 #ifndef QT_NO_DBUS
55 
57 
59 
60 QT_MODULE(DBus)
61 
63 
64 template<typename T>
66 {
67  typedef T Type;
68 public:
69  inline QDBusReply(const QDBusMessage &reply)
70  {
71  *this = reply;
72  }
73  inline QDBusReply& operator=(const QDBusMessage &reply)
74  {
75  QVariant data(qMetaTypeId(&m_data), reinterpret_cast<void*>(0));
76  qDBusReplyFill(reply, m_error, data);
77  m_data = qvariant_cast<Type>(data);
78  return *this;
79  }
80 
81  inline QDBusReply(const QDBusPendingCall &pcall)
82  {
83  *this = pcall;
84  }
85  inline QDBusReply &operator=(const QDBusPendingCall &pcall)
86  {
87  QDBusPendingCall other(pcall);
88  other.waitForFinished();
89  return *this = other.reply();
90  }
91  inline QDBusReply(const QDBusPendingReply<T> &reply)
92  {
93  *this = static_cast<QDBusPendingCall>(reply);
94  }
95 
96  inline QDBusReply(const QDBusError &dbusError = QDBusError())
97  : m_error(dbusError), m_data(Type())
98  {
99  }
100  inline QDBusReply& operator=(const QDBusError& dbusError)
101  {
102  m_error = dbusError;
103  m_data = Type();
104  return *this;
105  }
106 
107  inline QDBusReply& operator=(const QDBusReply& other)
108  {
109  m_error = other.m_error;
110  m_data = other.m_data;
111  return *this;
112  }
113 
114  inline bool isValid() const { return !m_error.isValid(); }
115 
116  inline const QDBusError& error() { return m_error; }
117 
118  inline Type value() const
119  {
120  return m_data;
121  }
122 
123  inline operator Type () const
124  {
125  return m_data;
126  }
127 
128 private:
130  Type m_data;
131 };
132 
133 # ifndef Q_QDOC
134 // specialize for QVariant:
135 template<> inline QDBusReply<QVariant>&
137 {
138  void *null = 0;
139  QVariant data(qMetaTypeId<QDBusVariant>(), null);
140  qDBusReplyFill(reply, m_error, data);
142  return *this;
143 }
144 
145 // specialize for void:
146 template<>
147 class QDBusReply<void>
148 {
149 public:
150  inline QDBusReply(const QDBusMessage &reply)
151  : m_error(reply)
152  {
153  }
154  inline QDBusReply& operator=(const QDBusMessage &reply)
155  {
156  m_error = reply;
157  return *this;
158  }
159  inline QDBusReply(const QDBusError &dbusError = QDBusError())
160  : m_error(dbusError)
161  {
162  }
163  inline QDBusReply(const QDBusPendingCall &pcall)
164  {
165  *this = pcall;
166  }
167  inline QDBusReply &operator=(const QDBusPendingCall &pcall)
168  {
169  QDBusPendingCall other(pcall);
170  other.waitForFinished();
171  return *this = other.reply();
172  }
173  inline QDBusReply& operator=(const QDBusError& dbusError)
174  {
175  m_error = dbusError;
176  return *this;
177  }
178 
179  inline QDBusReply& operator=(const QDBusReply& other)
180  {
181  m_error = other.m_error;
182  return *this;
183  }
184 
185  inline bool isValid() const { return !m_error.isValid(); }
186 
187  inline const QDBusError& error() { return m_error; }
188 
189 private:
191 };
192 # endif
193 
195 
197 
198 #endif // QT_NO_DBUS
199 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isValid() const
Returns true if this is a valid error condition (i.e., if there was an error), otherwise false...
Definition: qdbuserror.cpp:356
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
QDBusReply & operator=(const QDBusPendingCall &pcall)
Makes this object contain the reply specified by the pending asynchronous call pcall.
Definition: qdbusreply.h:85
#define error(msg)
The QDBusReply class stores the reply for a method call to a remote object.
Definition: qdbusreply.h:65
QDBusReply & operator=(const QDBusError &dbusError)
Sets this object to contain the error code given by error.
Definition: qdbusreply.h:100
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
The QDBusPendingCall class refers to one pending asynchronous call.
int qMetaTypeId()
Definition: qmetatype.h:224
QDBusReply(const QDBusError &dbusError=QDBusError())
Constructs an error reply from the D-Bus error code given by error.
Definition: qdbusreply.h:96
QDBusReply(const QDBusMessage &reply)
Automatically construct a QDBusReply object from the reply message reply, extracting the first return...
Definition: qdbusreply.h:69
QDBusReply(const QDBusPendingCall &pcall)
Automatically construct a QDBusReply object from the asynchronous pending call pcall.
Definition: qdbusreply.h:81
bool isValid() const
Returns true if no error occurred; otherwise, returns false.
Definition: qdbusreply.h:114
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDBusReply & operator=(const QDBusReply &other)
Makes this object be a copy of the object other.
Definition: qdbusreply.h:107
Q_DBUS_EXPORT void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data)
Fills in the QDBusReply data error and data from the reply message reply.
Definition: qdbusreply.cpp:229
Type m_data
Definition: qdbusreply.h:130
const QDBusError & error()
Returns the error code that was returned from the remote function call.
Definition: qdbusreply.h:116
static const char * data(const QByteArray &arr)
#define Q_DBUS_EXPORT
Definition: qglobal.h:1463
QDBusError m_error
Definition: qdbusreply.h:129
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
QDBusReply & operator=(const QDBusMessage &reply)
Makes this object contain the reply specified by message message.
Definition: qdbusreply.h:73
QDBusReply(const QDBusPendingReply< T > &reply)
Constructs a QDBusReply object from the pending reply message, reply.
Definition: qdbusreply.h:91
const char * variant
The QDBusPendingReply class contains the reply to an asynchronous method call.
#define QT_END_HEADER
Definition: qglobal.h:137
Type value() const
Returns the remote function&#39;s calls return value.
Definition: qdbusreply.h:118
The QDBusVariant class enables the programmer to identify the variant type provided by the D-Bus type...