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

/*
 * Implementation of interface class __deepinid
 */

class __deepinidPrivate
{
public:
   __deepinidPrivate() = default;

    // begin member variables
    bool DeviceUnlocked;
    QString HardwareID;
    bool IsLogin;
    QString MachineName;
    QVariantMap UserInfo;

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

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

    if (QMetaType::type("HardwareInfo") == QMetaType::UnknownType)
        registerHardwareInfoMetaType();
    if (QMetaType::type("QVariantMap") == QMetaType::UnknownType)
        registerQVariantMapMetaType();
}

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

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

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

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

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

    if (propName == QStringLiteral("UserInfo"))
    {
        const QVariantMap &UserInfo = qvariant_cast<QVariantMap>(value);
        if (d_ptr->UserInfo != UserInfo)
        {
            d_ptr->UserInfo = UserInfo;
            Q_EMIT UserInfoChanged(d_ptr->UserInfo);
        }
        return;
    }

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

bool __deepinid::deviceUnlocked()
{
    return qvariant_cast<bool>(internalPropGet("DeviceUnlocked", &d_ptr->DeviceUnlocked));
}

QString __deepinid::hardwareID()
{
    return qvariant_cast<QString>(internalPropGet("HardwareID", &d_ptr->HardwareID));
}

bool __deepinid::isLogin()
{
    return qvariant_cast<bool>(internalPropGet("IsLogin", &d_ptr->IsLogin));
}

QString __deepinid::machineName()
{
    return qvariant_cast<QString>(internalPropGet("MachineName", &d_ptr->MachineName));
}

QVariantMap __deepinid::userInfo()
{
    return qvariant_cast<QVariantMap>(internalPropGet("UserInfo", &d_ptr->UserInfo));
}

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

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