| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtDBus module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 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.
|
|---|
| 27 | **
|
|---|
| 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.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qdbusargument_p.h"
|
|---|
| 43 | #include "qdbusmetatype_p.h"
|
|---|
| 44 | #include "qdbusutil_p.h"
|
|---|
| 45 |
|
|---|
| 46 | #ifndef QT_NO_DBUS
|
|---|
| 47 |
|
|---|
| 48 | QT_BEGIN_NAMESPACE
|
|---|
| 49 |
|
|---|
| 50 | static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
|
|---|
| 51 | {
|
|---|
| 52 | if (ba)
|
|---|
| 53 | *ba += char(type);
|
|---|
| 54 | else
|
|---|
| 55 | q_dbus_message_iter_append_basic(it, type, arg);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | QDBusMarshaller::~QDBusMarshaller()
|
|---|
| 59 | {
|
|---|
| 60 | close();
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | inline QString QDBusMarshaller::currentSignature()
|
|---|
| 64 | {
|
|---|
| 65 | if (message)
|
|---|
| 66 | return QString::fromUtf8(q_dbus_message_get_signature(message));
|
|---|
| 67 | return QString();
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | inline void QDBusMarshaller::append(uchar arg)
|
|---|
| 71 | {
|
|---|
| 72 | qIterAppend(&iterator, ba, DBUS_TYPE_BYTE, &arg);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | inline void QDBusMarshaller::append(bool arg)
|
|---|
| 76 | {
|
|---|
| 77 | dbus_bool_t cast = arg;
|
|---|
| 78 | qIterAppend(&iterator, ba, DBUS_TYPE_BOOLEAN, &cast);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | inline void QDBusMarshaller::append(short arg)
|
|---|
| 82 | {
|
|---|
| 83 | qIterAppend(&iterator, ba, DBUS_TYPE_INT16, &arg);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | inline void QDBusMarshaller::append(ushort arg)
|
|---|
| 87 | {
|
|---|
| 88 | qIterAppend(&iterator, ba, DBUS_TYPE_UINT16, &arg);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | inline void QDBusMarshaller::append(int arg)
|
|---|
| 92 | {
|
|---|
| 93 | qIterAppend(&iterator, ba, DBUS_TYPE_INT32, &arg);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | inline void QDBusMarshaller::append(uint arg)
|
|---|
| 97 | {
|
|---|
| 98 | qIterAppend(&iterator, ba, DBUS_TYPE_UINT32, &arg);
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | inline void QDBusMarshaller::append(qlonglong arg)
|
|---|
| 102 | {
|
|---|
| 103 | qIterAppend(&iterator, ba, DBUS_TYPE_INT64, &arg);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | inline void QDBusMarshaller::append(qulonglong arg)
|
|---|
| 107 | {
|
|---|
| 108 | qIterAppend(&iterator, ba, DBUS_TYPE_UINT64, &arg);
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | inline void QDBusMarshaller::append(double arg)
|
|---|
| 112 | {
|
|---|
| 113 | qIterAppend(&iterator, ba, DBUS_TYPE_DOUBLE, &arg);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | void QDBusMarshaller::append(const QString &arg)
|
|---|
| 117 | {
|
|---|
| 118 | QByteArray data = arg.toUtf8();
|
|---|
| 119 | const char *cdata = data.constData();
|
|---|
| 120 | qIterAppend(&iterator, ba, DBUS_TYPE_STRING, &cdata);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | inline void QDBusMarshaller::append(const QDBusObjectPath &arg)
|
|---|
| 124 | {
|
|---|
| 125 | QByteArray data = arg.path().toUtf8();
|
|---|
| 126 | if (!ba && data.isEmpty())
|
|---|
| 127 | error(QLatin1String("Invalid object path passed in arguments"));
|
|---|
| 128 | const char *cdata = data.constData();
|
|---|
| 129 | qIterAppend(&iterator, ba, DBUS_TYPE_OBJECT_PATH, &cdata);
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | inline void QDBusMarshaller::append(const QDBusSignature &arg)
|
|---|
| 133 | {
|
|---|
| 134 | QByteArray data = arg.signature().toUtf8();
|
|---|
| 135 | if (!ba && data.isEmpty())
|
|---|
| 136 | error(QLatin1String("Invalid signature passed in arguments"));
|
|---|
| 137 | const char *cdata = data.constData();
|
|---|
| 138 | qIterAppend(&iterator, ba, DBUS_TYPE_SIGNATURE, &cdata);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | inline void QDBusMarshaller::append(const QByteArray &arg)
|
|---|
| 142 | {
|
|---|
| 143 | if (ba) {
|
|---|
| 144 | *ba += DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
|
|---|
| 145 | return;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | const char* cdata = arg.constData();
|
|---|
| 149 | DBusMessageIter subiterator;
|
|---|
| 150 | q_dbus_message_iter_open_container(&iterator, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING,
|
|---|
| 151 | &subiterator);
|
|---|
| 152 | q_dbus_message_iter_append_fixed_array(&subiterator, DBUS_TYPE_BYTE, &cdata, arg.length());
|
|---|
| 153 | q_dbus_message_iter_close_container(&iterator, &subiterator);
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | inline bool QDBusMarshaller::append(const QDBusVariant &arg)
|
|---|
| 157 | {
|
|---|
| 158 | if (ba) {
|
|---|
| 159 | *ba += DBUS_TYPE_VARIANT_AS_STRING;
|
|---|
| 160 | return true;
|
|---|
|
|---|