/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c Transfer1 -p generated/org_bluez_obex_transfer1 ../xml/org.bluez.obex.Transfer1.xml
 *
 * qdbusxml2cpp-fix is Copyright (C) 2016 Deepin Technology Co., Ltd.
 *
 * This is an auto-generated file.
 * This file may have been hand-edited. Look for HAND-EDIT comments
 * before re-generating it.
 */

#include "generated/org_bluez_obex_transfer1.h"

/*
 * Implementation of interface class __Transfer1
 */

class __Transfer1Private
{
public:
   __Transfer1Private() = default;

    // begin member variables
    QString Filename;
    QString Name;
    QDBusObjectPath Session;
    qulonglong Size;
    QString Status;
    qulonglong Time;
    qulonglong Transferred;
    QString Type;

public:
    QMap<QString, QDBusPendingCallWatcher *> m_processingCalls;
    QMap<QString, QList<QVariant>> m_waittingCalls;
};

__Transfer1::__Transfer1(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
    : DBusExtendedAbstractInterface(service, path, staticInterfaceName(), connection, parent)
    , d_ptr(new __Transfer1Private)
{
    connect(this, &__Transfer1::propertyChanged, this, &__Transfer1::onPropertyChanged);

}

__Transfer1::~__Transfer1()
{
    qDeleteAll(d_ptr->m_processingCalls.values());
    delete d_ptr;
}

void __Transfer1::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("Filename"))
    {
        const QString &Filename = qvariant_cast<QString>(value);
        if (d_ptr->Filename != Filename)
        {
            d_ptr->Filename = Filename;
            Q_EMIT FilenameChanged(d_ptr->Filename);
        }
        return;
    }

    if (propName == QStringLiteral("Name"))
    {
        const QString &Name = qvariant_cast<QString>(value);
        if (d_ptr->Name != Name)
        {
            d_ptr->Name = Name;
            Q_EMIT NameChanged(d_ptr->Name);
        }
        return;
    }

    if (propName == QStringLiteral("Session"))
    {
        const QDBusObjectPath &Session = qvariant_cast<QDBusObjectPath>(value);
        if (d_ptr->Session != Session)
        {
            d_ptr->Session = Session;
            Q_EMIT SessionChanged(d_ptr->Session);
        }
        return;
    }

    if (propName == QStringLiteral("Size"))
    {
        const qulonglong &Size = qvariant_cast<qulonglong>(value);
        if (d_ptr->Size != Size)
        {
            d_ptr->Size = Size;
            Q_EMIT SizeChanged(d_ptr->Size);
        }
        return;
    }

    if (propName == QStringLiteral("Status"))
    {
        const QString &Status = qvariant_cast<QString>(value);
        if (d_ptr->Status != Status)
        {
            d_ptr->Status = Status;
            Q_EMIT StatusChanged(d_ptr->Status);
        }
        return;
    }

    if (propName == QStringLiteral("Time"))
    {
        const qulonglong &Time = qvariant_cast<qulonglong>(value);
        if (d_ptr->Time != Time)
        {
            d_ptr->Time = Time;
            Q_EMIT TimeChanged(d_ptr->Time);
        }
        return;
    }

    if (propName == QStringLiteral("Transferred"))
    {
        const qulonglong &Transferred = qvariant_cast<qulonglong>(value);
        if (d_ptr->Transferred != Transferred)
        {
            d_ptr->Transferred = Transferred;
            Q_EMIT TransferredChanged(d_ptr->Transferred);
        }
        return;
    }

    if (propName == QStringLiteral("Type"))
    {
        const QString &Type = qvariant_cast<QString>(value);
        if (d_ptr->Type != Type)
        {
            d_ptr->Type = Type;
            Q_EMIT TypeChanged(d_ptr->Type);
        }
        return;
    }

    qWarning() << "property not handle: " << propName;
    return;
}

QString __Transfer1::filename()
{
    return qvariant_cast<QString>(internalPropGet("Filename", &d_ptr->Filename));
}

QString __Transfer1::name()
{
    return qvariant_cast<QString>(internalPropGet("Name", &d_ptr->Name));
}

QDBusObjectPath __Transfer1::session()
{
    return qvariant_cast<QDBusObjectPath>(internalPropGet("Session", &d_ptr->Session));
}

qulonglong __Transfer1::size()
{
    return qvariant_cast<qulonglong>(internalPropGet("Size", &d_ptr->Size));
}

QString __Transfer1::status()
{
    return qvariant_cast<QString>(internalPropGet("Status", &d_ptr->Status));
}

qulonglong __Transfer1::time()
{
    return qvariant_cast<qulonglong>(internalPropGet("Time", &d_ptr->Time));
}

qulonglong __Transfer1::transferred()
{
    return qvariant_cast<qulonglong>(internalPropGet("Transferred", &d_ptr->Transferred));
}

QString __Transfer1::type()
{
    return qvariant_cast<QString>(internalPropGet("Type", &d_ptr->Type));
}

void __Transfer1::CallQueued(const QString &callName, const QList<QVariant> &args)
{
    if (d_ptr->m_waittingCalls.contains(callName))
    {
        d_ptr->m_waittingCalls[callName] = args;
        return;
    }
    if (d_ptr->m_processingCalls.contains(callName))
    {
        d_ptr->m_waittingCalls.insert(callName, args);
    } else {
        QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCallWithArgumentList(callName, args));
        connect(watcher, &QDBusPendingCallWatcher::finished, this, &__Transfer1::onPendingCallFinished);
        d_ptr->m_processingCalls.insert(callName, watcher);
    }
}

void __Transfer1::onPendingCallFinished(QDBusPendingCallWatcher *w)
{
    w->deleteLater();
    const auto callName = d_ptr->m_processingCalls.key(w);
    Q_ASSERT(!callName.isEmpty());
    if (callName.isEmpty())
        return;
    d_ptr->m_processingCalls.remove(callName);
    if (!d_ptr->m_waittingCalls.contains(callName))
        return;
    const auto args = d_ptr->m_waittingCalls.take(callName);
    CallQueued(callName, args);
}
