~unity-team/libqtdbusmock/trunk

« back to all changes in this revision

Viewing changes to src/libqtdbusmock/MethodCall.cpp

  • Committer: Pete Woods
  • Date: 2013-11-15 15:51:22 UTC
  • mfrom: (25.1.4 trunk)
  • Revision ID: pete.woods@canonical.com-20131115155122-jkazscyb3k8zo0uk
Handle different mock interfaces on the same dbus name

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
        return argument;
72
72
}
73
73
 
 
74
static void transform(QVariantList &list);
 
75
 
74
76
static void transform(QVariantMap &map);
75
77
 
 
78
static QVariant transform(const QDBusArgument & value) {
 
79
        switch (value.currentType()) {
 
80
        case QDBusArgument::ArrayType: {
 
81
                value.beginArray();
 
82
                QVariantList list = transform(value).toList();
 
83
                value.endArray();
 
84
                return list;
 
85
        }
 
86
        case QDBusArgument::MapType: {
 
87
                QVariantMap map;
 
88
                value >> map;
 
89
                transform(map);
 
90
                return map;
 
91
        }
 
92
        case QDBusArgument::StructureType: {
 
93
                value.beginStructure();
 
94
                QVariantList list;
 
95
                while (!value.atEnd()) {
 
96
                        list << value.asVariant();
 
97
                }
 
98
                value.endStructure();
 
99
                return list;
 
100
                break;
 
101
        }
 
102
        default:
 
103
                qDebug() << "Unhandled type" << value.currentType()
 
104
                                << value.currentSignature();
 
105
        }
 
106
        return QVariant();
 
107
}
 
108
 
76
109
static void transform(QVariant &variant) {
77
 
        if (variant.canConvert<QDBusArgument>()) {
 
110
        if (variant.canConvert<QVariantList>()) {
 
111
                QVariantList list = variant.toList();
 
112
                transform(list);
 
113
                variant = list;
 
114
        } else if (variant.canConvert<QDBusArgument>()) {
78
115
                QDBusArgument value(variant.value<QDBusArgument>());
79
 
                if (value.currentType() == QDBusArgument::MapType) {
80
 
                        QVariantMap map;
81
 
                        value >> map;
82
 
                        transform(map);
83
 
                        variant = map;
84
 
                }
 
116
                variant = transform(value);
85
117
        }
86
118
}
87
119