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

/*
 * Implementation of interface class __Seat
 */

class __SeatPrivate
{
public:
   __SeatPrivate() = default;

    // begin member variables
    bool CanSwitch;
    bool HasGuestAccount;
    QList<QDBusObjectPath> Sessions;

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

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

}

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

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

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

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

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

bool __Seat::canSwitch()
{
    return qvariant_cast<bool>(internalPropGet("CanSwitch", &d_ptr->CanSwitch));
}

bool __Seat::hasGuestAccount()
{
    return qvariant_cast<bool>(internalPropGet("HasGuestAccount", &d_ptr->HasGuestAccount));
}

QList<QDBusObjectPath> __Seat::sessions()
{
    return qvariant_cast<QList<QDBusObjectPath>>(internalPropGet("Sessions", &d_ptr->Sessions));
}

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

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