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

/*
 * Implementation of interface class __daemonservice
 */

class __daemonservicePrivate
{
public:
   __daemonservicePrivate() = default;

    // begin member variables
    int MaturityDay;
    int Safetygrade;
    QStringList ScanningUsbPaths;

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

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

}

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

void __daemonservice::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("MaturityDay"))
    {
        const int &MaturityDay = qvariant_cast<int>(value);
        if (d_ptr->MaturityDay != MaturityDay)
        {
            d_ptr->MaturityDay = MaturityDay;
            Q_EMIT MaturityDayChanged(d_ptr->MaturityDay);
        }
        return;
    }

    if (propName == QStringLiteral("Safetygrade"))
    {
        const int &Safetygrade = qvariant_cast<int>(value);
        if (d_ptr->Safetygrade != Safetygrade)
        {
            d_ptr->Safetygrade = Safetygrade;
            Q_EMIT SafetygradeChanged(d_ptr->Safetygrade);
        }
        return;
    }

    if (propName == QStringLiteral("ScanningUsbPaths"))
    {
        const QStringList &ScanningUsbPaths = qvariant_cast<QStringList>(value);
        if (d_ptr->ScanningUsbPaths != ScanningUsbPaths)
        {
            d_ptr->ScanningUsbPaths = ScanningUsbPaths;
            Q_EMIT ScanningUsbPathsChanged(d_ptr->ScanningUsbPaths);
        }
        return;
    }

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

int __daemonservice::maturityDay()
{
    return qvariant_cast<int>(internalPropGet("MaturityDay", &d_ptr->MaturityDay));
}

void __daemonservice::setMaturityDay(int value)
{

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

int __daemonservice::safetygrade()
{
    return qvariant_cast<int>(internalPropGet("Safetygrade", &d_ptr->Safetygrade));
}

void __daemonservice::setSafetygrade(int value)
{

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

QStringList __daemonservice::scanningUsbPaths()
{
    return qvariant_cast<QStringList>(internalPropGet("ScanningUsbPaths", &d_ptr->ScanningUsbPaths));
}

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

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