1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
7
** This file is part of the QtDBus module of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
10
** Licensees holding valid Qt Commercial licenses may use this file in
11
** accordance with the Qt Commercial License Agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Nokia.
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
** In addition, as a special exception, Nokia gives you certain
24
** additional rights. These rights are described in the Nokia Qt LGPL
25
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file. Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
54
static void copyArgument(void *to, int id, const QVariant &arg)
56
if (id == arg.userType()) {
59
*reinterpret_cast<bool *>(to) = arg.toBool();
62
case QMetaType::UChar:
63
*reinterpret_cast<uchar *>(to) = arg.value<uchar>();
66
case QMetaType::Short:
67
*reinterpret_cast<short *>(to) = arg.value<short>();
70
case QMetaType::UShort:
71
*reinterpret_cast<ushort *>(to) = arg.value<ushort>();
75
*reinterpret_cast<int *>(to) = arg.toInt();
79
*reinterpret_cast<uint *>(to) = arg.toUInt();
82
case QVariant::LongLong:
83
*reinterpret_cast<qlonglong *>(to) = arg.toLongLong();
86
case QVariant::ULongLong:
87
*reinterpret_cast<qulonglong *>(to) = arg.toULongLong();
90
case QVariant::Double:
91
*reinterpret_cast<double *>(to) = arg.toDouble();
94
case QVariant::String:
95
*reinterpret_cast<QString *>(to) = arg.toString();
98
case QVariant::ByteArray:
99
*reinterpret_cast<QByteArray *>(to) = arg.toByteArray();
102
case QVariant::StringList:
103
*reinterpret_cast<QStringList *>(to) = arg.toStringList();
107
if (id == QDBusMetaTypeId::variant) {
108
*reinterpret_cast<QDBusVariant *>(to) = arg.value<QDBusVariant>();
110
} else if (id == QDBusMetaTypeId::objectpath) {
111
*reinterpret_cast<QDBusObjectPath *>(to) = arg.value<QDBusObjectPath>();
113
} else if (id == QDBusMetaTypeId::signature) {
114
*reinterpret_cast<QDBusSignature *>(to) = arg.value<QDBusSignature>();
118
// those above are the only types possible
119
// the demarshaller code doesn't demarshall anything else
120
qFatal("Found a decoded basic type in a D-Bus reply that shouldn't be there");
123
// if we got here, it's either an un-dermarshalled type or a mismatch
124
if (arg.userType() != QDBusMetaTypeId::argument) {
130
// is this type registered?
131
const char *userSignature = QDBusMetaType::typeToSignature(id);
132
if (!userSignature || !*userSignature) {
133
// type not registered
138
// is it the same signature?
139
QDBusArgument dbarg = arg.value<QDBusArgument>();
140
if (dbarg.currentSignature() != QLatin1String(userSignature)) {
141
// not the same signature, another mismatch
147
QDBusMetaType::demarshall(dbarg, id, to);
54
150
QDBusInterfacePrivate::QDBusInterfacePrivate(const QString &serv, const QString &p,
55
151
const QString &iface, const QDBusConnection &con)
56
152
: QDBusAbstractInterfacePrivate(serv, p, iface, con, true), metaObject(0)
187
283
// we will assume that the input arguments were passed correctly
188
284
QVariantList args;
189
for (int i = 1; i <= inputTypesCount; ++i)
286
for ( ; i <= inputTypesCount; ++i)
190
287
args << QVariant(inputTypes[i], argv[i]);
193
QPointer<QDBusInterface> qq = q;
194
290
QDBusMessage reply = q->callWithArgumentList(QDBus::Block, methodName, args);
197
// we ignore return values
199
// access to "this" or to "q" below this point must check for "qq"
200
// we may have been deleted!
292
if (reply.type() == QDBusMessage::ReplyMessage) {
293
// attempt to demarshall the return values
294
args = reply.arguments();
295
QVariantList::ConstIterator it = args.constBegin();
296
const int *outputTypes = metaObject->outputTypesForMethod(id);
297
int outputTypesCount = *outputTypes++;
299
if (*mm.typeName()) {
300
// this method has a return type
301
if (argv[0] && it != args.constEnd())
302
copyArgument(argv[0], *outputTypes++, *it);
304
// skip this argument even if we didn't copy it
309
for (int j = 0; j < outputTypesCount && it != args.constEnd(); ++i, ++j, ++it) {
310
copyArgument(argv[i], outputTypes[j], *it);
208
} else if (c == QMetaObject::ReadProperty) {
209
// Qt doesn't support non-readable properties
210
// we have to re-check
211
QMetaProperty mp = metaObject->property(id + metaObject->propertyOffset());
212
if (!mp.isReadable())
213
return -1; // don't read
215
QVariant *value = reinterpret_cast<QVariant*>(argv[1]);
217
*value = property(mp);
219
return -1; // handled, error or not
220
} else if (c == QMetaObject::WriteProperty) {
221
// QMetaProperty::write has already checked that we're writable
222
// it has also checked that the type is right
223
QVariant *value = reinterpret_cast<QVariant *>(argv[1]);
224
QMetaProperty mp = metaObject->property(id + metaObject->propertyOffset());
226
setProperty(mp, *value);