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

/*
 * Implementation of interface class __domain
 */

class __domainPrivate
{
public:
   __domainPrivate() = default;

    // begin member variables
    QString errorDetail;
    bool isDemandReboot;
    bool isDomainEnabled;
    bool isJoined;
    bool isProcessing;
    bool isServerValid;

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

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

}

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

void __domain::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("errorDetail"))
    {
        const QString &errorDetail = qvariant_cast<QString>(value);
        if (d_ptr->errorDetail != errorDetail)
        {
            d_ptr->errorDetail = errorDetail;
            Q_EMIT ErrorDetailChanged(d_ptr->errorDetail);
        }
        return;
    }

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

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

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

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

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

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

QString __domain::errorDetail()
{
    return qvariant_cast<QString>(internalPropGet("errorDetail", &d_ptr->errorDetail));
}

bool __domain::isDemandReboot()
{
    return qvariant_cast<bool>(internalPropGet("isDemandReboot", &d_ptr->isDemandReboot));
}

bool __domain::isDomainEnabled()
{
    return qvariant_cast<bool>(internalPropGet("isDomainEnabled", &d_ptr->isDomainEnabled));
}

void __domain::setIsDomainEnabled(bool value)
{

   internalPropSet("isDomainEnabled", QVariant::fromValue(value), &d_ptr->isDomainEnabled);
}

bool __domain::isJoined()
{
    return qvariant_cast<bool>(internalPropGet("isJoined", &d_ptr->isJoined));
}

bool __domain::isProcessing()
{
    return qvariant_cast<bool>(internalPropGet("isProcessing", &d_ptr->isProcessing));
}

bool __domain::isServerValid()
{
    return qvariant_cast<bool>(internalPropGet("isServerValid", &d_ptr->isServerValid));
}

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

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