/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c PolicyKit1 -p generated/org_freedesktop_policykit1 ../xml/org.freedesktop.PolicyKit1.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_freedesktop_policykit1.h"

/*
 * Implementation of interface class __PolicyKit1
 */

class __PolicyKit1Private
{
public:
   __PolicyKit1Private() = default;

    // begin member variables
    uint BackendFeatures;
    QString BackendName;
    QString BackendVersion;

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

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

    if (QMetaType::type("PolicyDetails") == QMetaType::UnknownType)
        registerPolicyDetailsMetaType();
    if (QMetaType::type("PolicyResult") == QMetaType::UnknownType)
        registerPolicyResultMetaType();
    if (QMetaType::type("PolicySubject") == QMetaType::UnknownType)
        registerPolicySubjectMetaType();
}

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

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

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

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

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

uint __PolicyKit1::backendFeatures()
{
    return qvariant_cast<uint>(internalPropGet("BackendFeatures", &d_ptr->BackendFeatures));
}

QString __PolicyKit1::backendName()
{
    return qvariant_cast<QString>(internalPropGet("BackendName", &d_ptr->BackendName));
}

QString __PolicyKit1::backendVersion()
{
    return qvariant_cast<QString>(internalPropGet("BackendVersion", &d_ptr->BackendVersion));
}

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

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