Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/dbus/qdbusinterface.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtDBus module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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
    26 ** package.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4242#include "qdbusinterface.h"
    4343
    44 #include <qdbus_symbols_p.h>
     44#include "qdbus_symbols_p.h"
    4545#include <QtCore/qpointer.h>
    4646#include <QtCore/qstringlist.h>
     
    5252QT_BEGIN_NAMESPACE
    5353
     54static void copyArgument(void *to, int id, const QVariant &arg)
     55{
     56    if (id == arg.userType()) {
     57        switch (id) {
     58        case QVariant::Bool:
     59            *reinterpret_cast<bool *>(to) = arg.toBool();
     60            return;
     61
     62        case QMetaType::UChar:
     63            *reinterpret_cast<uchar *>(to) = arg.value<uchar>();
     64            return;
     65
     66        case QMetaType::Short:
     67            *reinterpret_cast<short *>(to) = arg.value<short>();
     68            return;
     69
     70        case QMetaType::UShort:
     71            *reinterpret_cast<ushort *>(to) = arg.value<ushort>();
     72            return;
     73
     74        case QVariant::Int:
     75            *reinterpret_cast<int *>(to) = arg.toInt();
     76            return;
     77
     78        case QVariant::UInt:
     79            *reinterpret_cast<uint *>(to) = arg.toUInt();
     80            return;
     81
     82        case QVariant::LongLong:
     83            *reinterpret_cast<qlonglong *>(to) = arg.toLongLong();
     84            return;
     85
     86        case QVariant::ULongLong:
     87            *reinterpret_cast<qulonglong *>(to) = arg.toULongLong();
     88            return;
     89
     90        case QVariant::Double:
     91            *reinterpret_cast<double *>(to) = arg.toDouble();
     92            return;
     93
     94        case QVariant::String:
     95            *reinterpret_cast<QString *>(to) = arg.toString();
     96            return;
     97
     98        case QVariant::ByteArray:
     99            *reinterpret_cast<QByteArray *>(to) = arg.toByteArray();
     100            return;
     101
     102        case QVariant::StringList:
     103            *reinterpret_cast<QStringList *>(to) = arg.toStringList();
     104            return;
     105        }
     106
     107        if (id == QDBusMetaTypeId::variant) {
     108            *reinterpret_cast<QDBusVariant *>(to) = arg.value<QDBusVariant>();
     109            return;
     110        } else if (id == QDBusMetaTypeId::objectpath) {
     111            *reinterpret_cast<QDBusObjectPath *>(to) = arg.value<QDBusObjectPath>();
     112            return;
     113        } else if (id == QDBusMetaTypeId::signature) {
     114            *reinterpret_cast<QDBusSignature *>(to) = arg.value<QDBusSignature>();
     115            return;
     116        }
     117
     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");
     121    }
     122
     123    // if we got here, it's either an un-dermarshalled type or a mismatch
     124    if (arg.userType() != QDBusMetaTypeId::argument) {
     125        // it's a mismatch
     126        //qWarning?
     127        return;
     128    }
     129
     130    // is this type registered?
     131    const char *userSignature = QDBusMetaType::typeToSignature(id);
     132    if (!userSignature || !*userSignature) {
     133        // type not registered
     134        //qWarning?
     135        return;
     136    }
     137
     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
     142        //qWarning?
     143        return;
     144    }
     145
     146    // we can demarshall
     147    QDBusMetaType::demarshall(dbarg, id, to);
     148}
     149
    54150QDBusInterfacePrivate::QDBusInterfacePrivate(const QString &serv, const QString &p,
    55151                                             const QString &iface, const QDBusConnection &con)
     
    62158        if (!metaObject) {
    63159            // creation failed, somehow
    64             isValid = false;
     160            // most common causes are that the service doesn't exist or doesn't support introspection
     161            // those are not fatal errors, so we continue working
     162
    65163            if (!lastError.isValid())
    66164                lastError = QDBusError(QDBusError::InternalError, QLatin1String("Unknown error"));
     
    137235const QMetaObject *QDBusInterface::metaObject() const
    138236{
    139     return d_func()->isValid ? d_func()->metaObject : &QDBusAbstractInterface::staticMetaObject;
     237    return d_func()->metaObject ? d_func()->metaObject : &QDBusAbstractInterface::staticMetaObject;
    140238}
    141239
     
    187285            // we will assume that the input arguments were passed correctly
    188286            QVariantList args;
    189             for (int i = 1; i <= inputTypesCount; ++i)
     287            int i = 1;
     288            for ( ; i <= inputTypesCount; ++i)
    190289                args << QVariant(inputTypes[i], argv[i]);
    191290
    192291            // make the call
    193             QPointer<QDBusInterface> qq = q;
    194292            QDBusMessage reply = q->callWithArgumentList(QDBus::Block, methodName, args);
    195             args.clear();
    196 
    197             // we ignore return values
    198 
    199             // access to "this" or to "q" below this point must check for "qq"
    200             // we may have been deleted!
    201 
    202             if (!qq.isNull())
    203                 lastError = reply;
     293
     294            if (reply.type() == QDBusMessage::ReplyMessage) {
     295                // attempt to demarshall the return values
     296                args = reply.arguments();
     297                QVariantList::ConstIterator it = args.constBegin();
     298                const int *outputTypes = metaObject->outputTypesForMethod(id);
     299                int outputTypesCount = *outputTypes++;
     300
     301                if (*mm.typeName()) {
     302                    // this method has a return type
     303                    if (argv[0] && it != args.constEnd())
     304                        copyArgument(argv[0], *outputTypes++, *it);
     305
     306                    // skip this argument even if we didn't copy it
     307                    --outputTypesCount;
     308                    ++it;
     309                }
     310
     311                for (int j = 0; j < outputTypesCount && it != args.constEnd(); ++i, ++j, ++it) {
     312                    copyArgument(argv[i], outputTypes[j], *it);
     313                }
     314            }
    204315
    205316            // done
     317            lastError = reply;
    206318            return -1;
    207319        }
    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
    214 
    215         QVariant *value = reinterpret_cast<QVariant*>(argv[1]);
    216         argv[1] = 0;
    217         *value = property(mp);
    218 
    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());
    225 
    226         setProperty(mp, *value);
    227         return -1;
    228320    }
    229321    return id;
Note: See TracChangeset for help on using the changeset viewer.