/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -p /build/deepin-session-shell/src/dde-session-shell-snipe/src/global_util/dbus/selfinterface /build/deepin-session-shell/src/dde-session-shell-snipe/xml/snipe/org.freedesktop.login1.session.self.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-shell/src/dde-session-shell-snipe/src/global_util/dbus/selfinterface.h"

DCORE_USE_NAMESPACE
/*
 * Implementation of interface class __OrgFreedesktopLogin1SessionInterface
 */

class __OrgFreedesktopLogin1SessionInterfacePrivate
{
public:
   __OrgFreedesktopLogin1SessionInterfacePrivate() = default;

    // begin member variables
    bool Active;
    QString Desktop;
    QString Display;
    QString Id;
    QString Name;

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

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

}

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

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

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

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

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

bool __OrgFreedesktopLogin1SessionInterface::active()
{
    return qvariant_cast<bool>(internalPropGet("Active", &d_ptr->Active));
}

QString __OrgFreedesktopLogin1SessionInterface::desktop()
{
    return qvariant_cast<QString>(internalPropGet("Desktop", &d_ptr->Desktop));
}

QString __OrgFreedesktopLogin1SessionInterface::display()
{
    return qvariant_cast<QString>(internalPropGet("Display", &d_ptr->Display));
}

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

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

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

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