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

/*
 * Implementation of interface class __JobManager
 */

class __JobManagerPrivate
{
public:
   __JobManagerPrivate() = default;

    // begin member variables
    bool AutoClean;
    QList<QDBusObjectPath> JobList;
    QStringList SystemArchitectures;
    bool SystemOnChanging;
    qulonglong UpdateMode;
    QStringList UpgradableApps;

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

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

}

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

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

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

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

    if (propName == QStringLiteral("SystemOnChanging"))
    {
        const bool &SystemOnChanging = qvariant_cast<bool>(value);
        if (d_ptr->SystemOnChanging != SystemOnChanging)
        {
            d_ptr->SystemOnChanging = SystemOnChanging;
            Q_EMIT SystemOnChangingChanged(d_ptr->SystemOnChanging);
        }
        return;
    }

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

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

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

bool __JobManager::autoClean()
{
    return qvariant_cast<bool>(internalPropGet("AutoClean", &d_ptr->AutoClean));
}

QList<QDBusObjectPath> __JobManager::jobList()
{
    return qvariant_cast<QList<QDBusObjectPath>>(internalPropGet("JobList", &d_ptr->JobList));
}

QStringList __JobManager::systemArchitectures()
{
    return qvariant_cast<QStringList>(internalPropGet("SystemArchitectures", &d_ptr->SystemArchitectures));
}

bool __JobManager::systemOnChanging()
{
    return qvariant_cast<bool>(internalPropGet("SystemOnChanging", &d_ptr->SystemOnChanging));
}

qulonglong __JobManager::updateMode()
{
    return qvariant_cast<qulonglong>(internalPropGet("UpdateMode", &d_ptr->UpdateMode));
}

void __JobManager::setUpdateMode(qulonglong value)
{

   internalPropSet("UpdateMode", QVariant::fromValue(value), &d_ptr->UpdateMode);
}

QStringList __JobManager::upgradableApps()
{
    return qvariant_cast<QStringList>(internalPropGet("UpgradableApps", &d_ptr->UpgradableApps));
}

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

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