Ejemplo n.º 1
0
QT_BEGIN_NAMESPACE

static QDBusIntrospection::Annotations
parseAnnotations(const QDomElement& elem)
{
    QDBusIntrospection::Annotations retval;
    QDomNodeList list = elem.elementsByTagName(QLatin1String("annotation"));
    for (int i = 0; i < list.count(); ++i)
    {
        QDomElement ann = list.item(i).toElement();
        if (ann.isNull())
            continue;

        QString name = ann.attribute(QLatin1String("name")),
               value = ann.attribute(QLatin1String("value"));

        if (!QDBusUtil::isValidInterfaceName(name)) {
            qWarning("Invalid D-BUS annotation '%s' found while parsing introspection",
                     qPrintable(name));
            continue;
        }

        retval.insert(name, value);
    }

    return retval;
}
Ejemplo n.º 2
0
QDBusMetaObjectGenerator::Type
QDBusMetaObjectGenerator::findType(const QByteArray &signature,
                                   const QDBusIntrospection::Annotations &annotations,
                                   const char *direction, int id)
{
    Type result;
    result.id = QVariant::Invalid;

    int type = QDBusMetaType::signatureToType(signature);
    if (type == QVariant::Invalid && !qt_dbus_metaobject_skip_annotations) {
        // it's not a type normally handled by our meta type system
        // it must contain an annotation
        QString annotationName = QString::fromLatin1("com.trolltech.QtDBus.QtTypeName");
        if (id >= 0)
            annotationName += QString::fromLatin1(".%1%2")
                              .arg(QLatin1String(direction))
                              .arg(id);

        // extract from annotations:
        QByteArray typeName = annotations.value(annotationName).toLatin1();

        // verify that it's a valid one
        if (!typeName.isEmpty()) {
            // type name found
            type = QVariant::nameToType(typeName);
            if (type == QVariant::UserType)
                type = QMetaType::type(typeName);
        }

        if (type == QVariant::Invalid || signature != QDBusMetaType::typeToSignature(type)) {
            // type is still unknown or doesn't match back to the signature that it
            // was expected to, so synthesize a fake type
            type = QMetaType::VoidStar;
            typeName = "QDBusRawType<0x" + signature.toHex() + ">*";
        }

        result.name = typeName;
    } else if (type == QVariant::Invalid) {
        // this case is used only by the qdbus command-line tool
        // invalid, let's create an impossible type that contains the signature

        if (signature == "av") {
            result.name = "QVariantList";
            type = QVariant::List;
        } else if (signature == "a{sv}") {
            result.name = "QVariantMap";
            type = QVariant::Map;
        } else {
            result.name = "QDBusRawType::" + signature;
            type = -1;
        }
    } else {
        result.name = QVariant::typeToName( QVariant::Type(type) );
    }

    result.id = type;
    return result;              // success
}
Ejemplo n.º 3
0
QDBusMetaObjectGenerator::Type
QDBusMetaObjectGenerator::findType(const QByteArray &signature,
                                   const QDBusIntrospection::Annotations &annotations,
                                   const char *direction, int id)
{
    Type result;
    result.id = QVariant::Invalid;

    int type = QDBusMetaType::signatureToType(signature);
    if (type == QVariant::Invalid) {
        // it's not a type normally handled by our meta type system
        // it must contain an annotation
        QString annotationName = QString::fromLatin1("com.trolltech.QtDBus.QtTypeName");
        if (id >= 0)
            annotationName += QString::fromLatin1(".%1%2")
                              .arg(QLatin1String(direction))
                              .arg(id);

        // extract from annotations:
        QByteArray typeName = annotations.value(annotationName).toLatin1();

        // verify that it's a valid one
        if (typeName.isEmpty())
            return result;      // invalid

        type = QVariant::nameToType(typeName);
        if (type == QVariant::UserType)
            type = QMetaType::type(typeName);
        if (type == QVariant::Invalid || signature != QDBusMetaType::typeToSignature(type))
            return result;      // unknown type is invalid too

        result.name = typeName;
    } else {
        result.name = QVariant::typeToName( QVariant::Type(type) );
    }

    result.id = type;
    return result;              // success
}