/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c Job -p generated/com_deepin_lastore_job ../xml/com.deepin.lastore.Job.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/com_deepin_lastore_job.h"

/*
 * Implementation of interface class __Job
 */

class __JobPrivate
{
public:
   __JobPrivate() = default;

    // begin member variables
    bool Cancelable;
    qlonglong CreateTime;
    QString Description;
    int ElapsedTime;
    QString Id;
    QString Name;
    QString PackageId;
    QStringList Packages;
    double Progress;
    qlonglong Speed;
    QString Status;
    QString Type;

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

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

}

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

void __Job::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("Cancelable"))
    {
        const bool &Cancelable = qvariant_cast<bool>(value);
        if (d_ptr->Cancelable != Cancelable)
        {
            d_ptr->Cancelable = Cancelable;
            Q_EMIT CancelableChanged(d_ptr->Cancelable);
        }
        return;
    }

    if (propName == QStringLiteral("CreateTime"))
    {
        const qlonglong &CreateTime = qvariant_cast<qlonglong>(value);
        if (d_ptr->CreateTime != CreateTime)
        {
            d_ptr->CreateTime = CreateTime;
            Q_EMIT CreateTimeChanged(d_ptr->CreateTime);
        }
        return;
    }

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

    if (propName == QStringLiteral("ElapsedTime"))
    {
        const int &ElapsedTime = qvariant_cast<int>(value);
        if (d_ptr->ElapsedTime != ElapsedTime)
        {
            d_ptr->ElapsedTime = ElapsedTime;
            Q_EMIT ElapsedTimeChanged(d_ptr->ElapsedTime);
        }
        return;
    }

    if (propName == QStringLiteral("Id"))
    {
        const QString &Id = qvariant_cast<QString>(value);
        if (d_ptr->Id != Id)
        {
            d_ptr->Id = Id;
            Q_EMIT IdChanged(d_ptr->Id);
        }
        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("PackageId"))
    {
        const QString &PackageId = qvariant_cast<QString>(value);
        if (d_ptr->PackageId != PackageId)
        {
            d_ptr->PackageId = PackageId;
            Q_EMIT PackageIdChanged(d_ptr->PackageId);
        }
        return;
    }

    if (propName == QStringLiteral("Packages"))
    {
        const QStringList &Packages = qvariant_cast<QStringList>(value);
        if (d_ptr->Packages != Packages)
        {
            d_ptr->Packages = Packages;
            Q_EMIT PackagesChanged(d_ptr->Packages);
        }
        return;
    }

    if (propName == QStringLiteral("Progress"))
    {
        const double &Progress = qvariant_cast<double>(value);
        if (d_ptr->Progress != Progress)
        {
            d_ptr->Progress = Progress;
            Q_EMIT ProgressChanged(d_ptr->Progress);
        }
        return;
    }

    if (propName == QStringLiteral("Speed"))
    {
        const qlonglong &Speed = qvariant_cast<qlonglong>(value);
        if (d_ptr->Speed != Speed)
        {
            d_ptr->Speed = Speed;
            Q_EMIT SpeedChanged(d_ptr->Speed);
        }
        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("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;
}

bool __Job::cancelable()
{
    return qvariant_cast<bool>(internalPropGet("Cancelable", &d_ptr->Cancelable));
}

qlonglong __Job::createTime()
{
    return qvariant_cast<qlonglong>(internalPropGet("CreateTime", &d_ptr->CreateTime));
}

QString __Job::description()
{
    return qvariant_cast<QString>(internalPropGet("Description", &d_ptr->Description));
}

int __Job::elapsedTime()
{
    return qvariant_cast<int>(internalPropGet("ElapsedTime", &d_ptr->ElapsedTime));
}

QString __Job::id()
{
    return qvariant_cast<QString>(internalPropGet("Id", &d_ptr->Id));
}

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

QString __Job::packageId()
{
    return qvariant_cast<QString>(internalPropGet("PackageId", &d_ptr->PackageId));
}

QStringList __Job::packages()
{
    return qvariant_cast<QStringList>(internalPropGet("Packages", &d_ptr->Packages));
}

double __Job::progress()
{
    return qvariant_cast<double>(internalPropGet("Progress", &d_ptr->Progress));
}

qlonglong __Job::speed()
{
    return qvariant_cast<qlonglong>(internalPropGet("Speed", &d_ptr->Speed));
}

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

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

void __Job::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, &__Job::onPendingCallFinished);
        d_ptr->m_processingCalls.insert(callName, watcher);
    }
}

void __Job::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);
}
