Qt 4.8
qdbuscontext.cpp
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 #include "qdbusmessage.h"
43 #include "qdbusconnection.h"
44 #include "qdbusabstractadaptor.h"
45 
46 #include "qdbuscontext.h"
47 #include "qdbuscontext_p.h"
48 
49 #ifndef QT_NO_DBUS
50 
52 
54 {
55  // determine if this is an adaptor or not
56  if (qobject_cast<QDBusAbstractAdaptor *>(obj))
57  obj = obj->parent();
58 
59  Q_ASSERT(obj);
60 
61  void *ptr = obj->qt_metacast("QDBusContext");
62  QDBusContext *q_ptr = reinterpret_cast<QDBusContext *>(ptr);
63  if (q_ptr) {
64  QDBusContextPrivate *old = q_ptr->d_ptr;
65  q_ptr->d_ptr = newContext;
66  return old;
67  }
68 
69  return 0;
70 }
71 
111  : d_ptr(0)
112 {
113 }
114 
119 {
120 }
121 
131 {
132  return d_ptr;
133 }
134 
139 {
140  return d_ptr->connection;
141 }
142 
147 {
148  return d_ptr->message;
149 }
150 
157 {
158  return message().isDelayedReply();
159 }
160 
176 void QDBusContext::setDelayedReply(bool enable) const
177 {
178  message().setDelayedReply(enable);
179 }
180 
188 void QDBusContext::sendErrorReply(const QString &name, const QString &msg) const
189 {
190  setDelayedReply(true);
191  connection().send(message().createErrorReply(name, msg));
192 }
193 
206 {
207  setDelayedReply(true);
208  connection().send(message().createErrorReply(type, msg));
209 }
210 
212 
213 #endif // QT_NO_DBUS
int type
Definition: qmetatype.cpp:239
const QDBusMessage & message() const
Returns the message that generated this call.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool send(const QDBusMessage &message) const
Sends the message over this connection, without waiting for a reply.
bool isDelayedReply() const
Returns true if this call will have a delayed reply.
The QDBusContext class allows slots to determine the D-Bus context of the calls.
Definition: qdbuscontext.h:60
void setDelayedReply(bool enable) const
Sets whether the message will be replied later (if enable is true) or if an automatic reply should be...
The QString class provides a Unicode character string.
Definition: qstring.h:83
~QDBusContext()
An empty destructor.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
ErrorType
In order to facilitate verification of the most common D-Bus errors generated by the D-Bus implementa...
Definition: qdbuserror.h:63
bool calledFromDBus() const
Returns true if we are processing a D-Bus call.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDBusConnection connection
const char * name
const T * ptr(const T &t)
void sendErrorReply(const QString &name, const QString &msg=QString()) const
Sends an error name as a reply to the caller.
bool isDelayedReply() const
Returns the delayed reply flag, as set by setDelayedReply().
The QDBusConnection class represents a connection to the D-Bus bus daemon.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static QDBusContextPrivate * set(QObject *obj, QDBusContextPrivate *newContext)
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
void setDelayedReply(bool enable) const
Sets whether this call will have a delayed reply or not.
QDBusContext()
Constructs an empty QDBusContext.
const QDBusMessage & message
QDBusConnection connection() const
Returns the connection from which this call was received.
QDBusContextPrivate * d_ptr
Definition: qdbuscontext.h:78