/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c Systemd1Job -p /build/deepin-session/src/dde-session/dbusinterface/org_freedesktop_systemd1_Job /build/deepin-session/src/dde-session/dbus/interface/org.freedesktop.systemd1.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 "/build/deepin-session/src/dde-session/dbusinterface/org_freedesktop_systemd1_Job.h"

DCORE_USE_NAMESPACE
/*
 * Implementation of interface class __Systemd1Job
 */

class __Systemd1JobPrivate
{
public:
   __Systemd1JobPrivate() = default;

    // begin member variables
    uint Id;
    QString JobType;
    QString State;

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

__Systemd1Job::__Systemd1Job(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
    : DDBusExtendedAbstractInterface(service, path, staticInterfaceName(), connection, parent)
    , d_ptr(new __Systemd1JobPrivate)
{
    connect(this, &__Systemd1Job::propertyChanged, this, &__Systemd1Job::onPropertyChanged);

}

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

void __Systemd1Job::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("Id"))
    {
        const uint &Id = qvariant_cast<uint>(value);
        if (d_ptr->Id != Id)
        {
            d_ptr->Id = Id;
            Q_EMIT IdChanged(d_ptr->Id);
        }
        return;
    }

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

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

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

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

QString __Systemd1Job::jobType()
{
    return qvariant_cast<QString>(internalPropGet("JobType", &d_ptr->JobType));
}

QString __Systemd1Job::state()
{
    return qvariant_cast<QString>(internalPropGet("State", &d_ptr->State));
}

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

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