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

/*
 * Implementation of interface class __ABRecovery
 */

class __ABRecoveryPrivate
{
public:
   __ABRecoveryPrivate() = default;

    // begin member variables
    bool BackingUp;
    qlonglong BackupTime;
    QString BackupVersion;
    bool ConfigValid;
    bool HasBackedUp;
    bool Restoring;

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

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

}

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

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

    if (propName == QStringLiteral("BackupTime"))
    {
        const qlonglong &BackupTime = qvariant_cast<qlonglong>(value);
        if (d_ptr->BackupTime != BackupTime)
        {
            d_ptr->BackupTime = BackupTime;
            Q_EMIT BackupTimeChanged(d_ptr->BackupTime);
        }
        return;
    }

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

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

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

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

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

bool __ABRecovery::backingUp()
{
    return qvariant_cast<bool>(internalPropGet("BackingUp", &d_ptr->BackingUp));
}

qlonglong __ABRecovery::backupTime()
{
    return qvariant_cast<qlonglong>(internalPropGet("BackupTime", &d_ptr->BackupTime));
}

QString __ABRecovery::backupVersion()
{
    return qvariant_cast<QString>(internalPropGet("BackupVersion", &d_ptr->BackupVersion));
}

bool __ABRecovery::configValid()
{
    return qvariant_cast<bool>(internalPropGet("ConfigValid", &d_ptr->ConfigValid));
}

bool __ABRecovery::hasBackedUp()
{
    return qvariant_cast<bool>(internalPropGet("HasBackedUp", &d_ptr->HasBackedUp));
}

bool __ABRecovery::restoring()
{
    return qvariant_cast<bool>(internalPropGet("Restoring", &d_ptr->Restoring));
}

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

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