Beispiel #1
0
static void qDBusObjectPathKeyMapToIterator(DBusMessageIter* it,
                                            const QDBusData& var)
{
    DBusMessageIter sub;
    QCString sig;

    QDBusDataMap<QDBusObjectPath> map = var.toObjectPathKeyMap();

    sig += DBUS_DICT_ENTRY_BEGIN_CHAR;
    sig += qDBusTypeForQDBusType(map.keyType());

    if (map.hasContainerValueType())
        sig += map.containerValueType().buildDBusSignature();
    else
        sig += qDBusTypeForQDBusType(map.valueType());
    sig += DBUS_DICT_ENTRY_END_CHAR;

    dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, sig.data(), &sub);

    QDBusDataMap<QDBusObjectPath>::ConstIterator mit = map.begin();
    for (; mit != map.end(); ++mit)
    {
        DBusMessageIter itemIterator;
        dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY,
                                         0, &itemIterator);

        qAppendToMessage(&itemIterator, mit.key());
        qDBusDataToIterator(&itemIterator, mit.data());

        dbus_message_iter_close_container(&sub, &itemIterator);
    }

    dbus_message_iter_close_container(it, &sub);
}
Beispiel #2
0
QDBusDataList::QDBusDataList(const QDBusData &containerItemType) : d(new Private())
{
    d->type = containerItemType.type();

    switch(d->type)
    {
        case QDBusData::List:   // fall through
        case QDBusData::Struct: // fall through
        case QDBusData::Map:
            d->containerItem = containerItemType;
            break;

        default: // not a container
            break;
    }
}
Beispiel #3
0
static void qDBusDataToIterator(DBusMessageIter* it, const QDBusData& var)
{
    switch (var.type())
    {
        case QDBusData::Bool:
        {
            dbus_bool_t value = var.toBool();
            dbus_message_iter_append_basic(it, DBUS_TYPE_BOOLEAN, &value);
            break;
        }
        case QDBusData::Byte:
        {
            Q_UINT8 value = var.toByte();
            dbus_message_iter_append_basic(it, DBUS_TYPE_BYTE, &value);
            break;
        }
        case QDBusData::Int16: {
            Q_INT16 value = var.toInt16();
            dbus_message_iter_append_basic(it, DBUS_TYPE_INT16, &value);
            break;
        }
        case QDBusData::UInt16: {
            Q_UINT16 value = var.toUInt16();
            dbus_message_iter_append_basic(it, DBUS_TYPE_UINT16, &value);
            break;
        }
        case QDBusData::Int32: {
            Q_INT32 value = var.toInt32();
            dbus_message_iter_append_basic(it, DBUS_TYPE_INT32, &value);
            break;
        }
        case QDBusData::UInt32: {
            Q_UINT32 value = var.toUInt32();
            dbus_message_iter_append_basic(it, DBUS_TYPE_UINT32, &value);
            break;
        }
        case QDBusData::Int64: {
            Q_INT64 value = var.toInt64();
            dbus_message_iter_append_basic(it, DBUS_TYPE_INT64, &value);
            break;
        }
        case QDBusData::UInt64: {
            Q_UINT64 value = var.toUInt64();
            dbus_message_iter_append_basic(it, DBUS_TYPE_UINT64, &value);
            break;
        }
        case QDBusData::Double: {
            double value = var.toDouble();
            dbus_message_iter_append_basic(it, DBUS_TYPE_DOUBLE, &value);
            break;
        }
        case QDBusData::String:
            qAppendToMessage(it, var.toString());
            break;
        case QDBusData::ObjectPath:
            qAppendToMessage(it, var.toObjectPath());
            break;
        case QDBusData::List: {
            QDBusDataList list = var.toList();

            QCString signature = 0;
            if (list.hasContainerItemType())
                signature = list.containerItemType().buildDBusSignature();
            else
                signature = qDBusTypeForQDBusType(list.type());

            DBusMessageIter sub;
            dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY,
                                             signature.data(), &sub);

            const QValueList<QDBusData> valueList = var.toQValueList();
            QValueList<QDBusData>::ConstIterator listIt    = valueList.begin();
            QValueList<QDBusData>::ConstIterator listEndIt = valueList.end();
            for (; listIt != listEndIt; ++listIt)
            {
                qDBusDataToIterator(&sub, *listIt);
            }
            dbus_message_iter_close_container(it, &sub);
            break;
        }
        case QDBusData::Map: {
            switch (var.keyType()) {
                case QDBusData::Byte:
                    qDBusByteKeyMapToIterator(it, var);
                    break;
                case QDBusData::Int16:
                    qDBusInt16KeyMapToIterator(it, var);
                    break;
                case QDBusData::UInt16:
                    qDBusUInt16KeyMapToIterator(it, var);
                    break;
                case QDBusData::Int32:
                    qDBusInt32KeyMapToIterator(it, var);
                    break;
                case QDBusData::UInt32:
                    qDBusUInt32KeyMapToIterator(it, var);
                    break;
                case QDBusData::Int64:
                    qDBusInt64KeyMapToIterator(it, var);
                    break;
                case QDBusData::UInt64:
                    qDBusUInt64KeyMapToIterator(it, var);
                    break;
                case QDBusData::String:
                    qDBusStringKeyMapToIterator(it, var);
                    break;
                case QDBusData::ObjectPath:
                    qDBusObjectPathKeyMapToIterator(it, var);
                    break;
                default:
                    qWarning("QDBusMarshall: unhandled map key type %s "
                             "at marshalling",
                             QDBusData::typeName(var.keyType()));
                    break;
            }
            break;
        }
        case QDBusData::Variant: {
            QDBusVariant variant = var.toVariant();
            if (variant.signature.isEmpty() || !variant.value.isValid()) break;

            DBusMessageIter sub;
            dbus_message_iter_open_container(it, DBUS_TYPE_VARIANT,
                                             variant.signature.utf8(), &sub);

            qDBusDataToIterator(&sub, variant.value);

            dbus_message_iter_close_container(it, &sub);
            break;
        }
        case QDBusData::Struct: {
            QValueList<QDBusData> memberList = var.toStruct();
            if (memberList.isEmpty()) break;

            DBusMessageIter sub;
            dbus_message_iter_open_container(it, DBUS_TYPE_STRUCT, NULL, &sub);

            QValueList<QDBusData>::ConstIterator memberIt    = memberList.begin();
            QValueList<QDBusData>::ConstIterator memberEndIt = memberList.end();
            for (; memberIt != memberEndIt; ++memberIt)
            {
                qDBusDataToIterator(&sub, *memberIt);
            }

            dbus_message_iter_close_container(it, &sub);
        }
#if 0
        case QVariant::ByteArray: {
            const QByteArray array = var.toByteArray();
            const char* cdata = array.data();
                DBusMessageIter sub;
                dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &sub);
            dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &cdata, array.size());
                dbus_message_iter_close_container(it, &sub);
        break;
        }
#endif
        default:
            //qWarning("Don't know how to handle type %s", var.typeName());
            break;
    }
}
Beispiel #4
0
static QDBusData qFetchMap(DBusMessageIter *it, const QDBusData& prototype)
{
    if (dbus_message_iter_get_arg_type(it) == DBUS_TYPE_INVALID)
        return prototype;

    DBusMessageIter itemIter;
    dbus_message_iter_recurse(it, &itemIter);
    if (dbus_message_iter_get_arg_type(&itemIter) == DBUS_TYPE_INVALID)
        return prototype;

    switch (dbus_message_iter_get_arg_type(&itemIter)) {
        case DBUS_TYPE_BYTE: {
            QDBusDataMap<Q_UINT8> map = prototype.toByteKeyMap();
            do {
                qFetchByteKeyMapEntry(map, it);
            } while (dbus_message_iter_next(it));

            return QDBusData::fromByteKeyMap(map);
        }

        case DBUS_TYPE_INT16: {
            QDBusDataMap<Q_INT16> map = prototype.toInt16KeyMap();
            do {
                qFetchInt16KeyMapEntry(map, it);
            } while (dbus_message_iter_next(it));

            return QDBusData::fromInt16KeyMap(map);
        }

        case DBUS_TYPE_UINT16: {
            QDBusDataMap<Q_UINT16> map = prototype.toUInt16KeyMap();
            do {
                qFetchUInt16KeyMapEntry(map, it);
            } while (dbus_message_iter_next(it));

            return QDBusData::fromUInt16KeyMap(map);
        }

        case DBUS_TYPE_INT32: {
            QDBusDataMap<Q_INT32> map = prototype.toInt32KeyMap();
            do {
                qFetchInt32KeyMapEntry(map, it);
            } while (dbus_message_iter_next(it));

            return QDBusData::fromInt32KeyMap(map);
        }

        case DBUS_TYPE_UINT32: {
            QDBusDataMap<Q_UINT32> map = prototype.toUInt32KeyMap();
            do {
                qFetchUInt32KeyMapEntry(map, it);
            } while (dbus_message_iter_next(it));

            return QDBusData::fromUInt32KeyMap(map);
        }

        case DBUS_TYPE_INT64: {
            QDBusDataMap<Q_INT64> map = prototype.toInt64KeyMap();
            do {
                qFetchInt64KeyMapEntry(map, it);
            } while (dbus_message_iter_next(it));

            return QDBusData::fromInt64KeyMap(map);
        }

        case DBUS_TYPE_UINT64: {
            QDBusDataMap<Q_UINT64> map = prototype.toUInt64KeyMap();
            do {
                qFetchUInt64KeyMapEntry(map, it);
            } while (dbus_message_iter_next(it));

            return QDBusData::fromUInt64KeyMap(map);
        }

        case DBUS_TYPE_STRING:      // fall through
        case DBUS_TYPE_OBJECT_PATH: // fall through
        case DBUS_TYPE_SIGNATURE: {
            QDBusDataMap<QString> map = prototype.toStringKeyMap();
            do {
                qFetchStringKeyMapEntry(map, it);
            } while (dbus_message_iter_next(it));

            return QDBusData::fromStringKeyMap(map);
        }

        default:
            break;
    }

    return prototype;
}
Beispiel #5
0
bool QDBusData::operator==(const QDBusData& other) const
{
    if (&other == this) return true;

    if (d == other.d) return true;

    if (d->type == other.d->type)
    {
        switch (d->type)
        {
            case QDBusData::Invalid:
                return true;

            case QDBusData::Bool:
                return d->value.boolValue == other.d->value.boolValue;

            case QDBusData::Byte:
                return d->value.byteValue == other.d->value.byteValue;

            case QDBusData::Int16:
                return d->value.int16Value == other.d->value.int16Value;

            case QDBusData::UInt16:
                return d->value.uint16Value == other.d->value.uint16Value;

            case QDBusData::Int32:
                return d->value.int32Value == other.d->value.int32Value;

            case QDBusData::UInt32:
                return d->value.uint32Value == other.d->value.uint32Value;

            case QDBusData::Int64:
                return d->value.int64Value == other.d->value.int64Value;

            case QDBusData::UInt64:
                return d->value.uint64Value == other.d->value.uint64Value;

            case QDBusData::Double:
                // FIXME: should not compare doubles for equality like this
                return d->value.doubleValue == other.d->value.doubleValue;

            case QDBusData::String:
                return toString() == other.toString();

            case QDBusData::ObjectPath:
                return toObjectPath() == other.toObjectPath();

            case QDBusData::List:
                return toList() == other.toList();

            case QDBusData::Struct:
                return toStruct() == other.toStruct();

            case QDBusData::Variant:
                return toVariant() == other.toVariant();

            case QDBusData::Map:
                if (d->keyType != other.d->keyType) return false;

                switch (d->keyType)
                {
                    case QDBusData::Byte:
                        toByteKeyMap() == other.toByteKeyMap();
                        break;

                    case QDBusData::Int16:
                        toInt16KeyMap() == other.toInt16KeyMap();
                        break;

                    case QDBusData::UInt16:
                        toUInt16KeyMap() == other.toUInt16KeyMap();
                        break;

                    case QDBusData::Int32:
                        toInt32KeyMap() == other.toInt32KeyMap();
                        break;

                    case QDBusData::UInt32:
                        toUInt32KeyMap() == other.toUInt32KeyMap();
                        break;
                    case QDBusData::Int64:
                        toInt64KeyMap() == other.toInt64KeyMap();
                        break;

                    case QDBusData::UInt64:
                        toUInt64KeyMap() == other.toUInt64KeyMap();
                        break;

                    case QDBusData::String:
                        toStringKeyMap() == other.toStringKeyMap();
                        break;

                    case QDBusData::ObjectPath:
                        toObjectPathKeyMap() == other.toObjectPathKeyMap();
                        break;

                    default:
                        qFatal("QDBusData operator== unhandled map key type %d(%s)",
                               d->keyType, QDBusData::typeName(d->keyType));
                        break;
                }

                break;
        }
    }

    return false;
}