/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c Sink -p /build/deepin-session/src/dde-session/dbusinterface/org_deepin_dde_Audio1_Sink /build/deepin-session/src/dde-session/dbus/interface/org.deepin.dde.Audio1.Sink.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 "/build/deepin-session/src/dde-session/dbusinterface/org_deepin_dde_Audio1_Sink.h"

DCORE_USE_NAMESPACE
/*
 * Implementation of interface class __Sink
 */

class __SinkPrivate
{
public:
   __SinkPrivate() = default;

    // begin member variables
    double Balance;
    double BaseVolume;
    uint Card;
    QString Description;
    double Fade;
    bool Mute;
    QString Name;
    bool SupportBalance;
    double Volume;

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

__Sink::__Sink(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
    : DDBusExtendedAbstractInterface(service, path, staticInterfaceName(), connection, parent)
    , d_ptr(new __SinkPrivate)
{
    connect(this, &__Sink::propertyChanged, this, &__Sink::onPropertyChanged);

}

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

void __Sink::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("Balance"))
    {
        const double &Balance = qvariant_cast<double>(value);
        if (d_ptr->Balance != Balance)
        {
            d_ptr->Balance = Balance;
            Q_EMIT BalanceChanged(d_ptr->Balance);
        }
        return;
    }

    if (propName == QStringLiteral("BaseVolume"))
    {
        const double &BaseVolume = qvariant_cast<double>(value);
        if (d_ptr->BaseVolume != BaseVolume)
        {
            d_ptr->BaseVolume = BaseVolume;
            Q_EMIT BaseVolumeChanged(d_ptr->BaseVolume);
        }
        return;
    }

    if (propName == QStringLiteral("Card"))
    {
        const uint &Card = qvariant_cast<uint>(value);
        if (d_ptr->Card != Card)
        {
            d_ptr->Card = Card;
            Q_EMIT CardChanged(d_ptr->Card);
        }
        return;
    }

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

    if (propName == QStringLiteral("Fade"))
    {
        const double &Fade = qvariant_cast<double>(value);
        if (d_ptr->Fade != Fade)
        {
            d_ptr->Fade = Fade;
            Q_EMIT FadeChanged(d_ptr->Fade);
        }
        return;
    }

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

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

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

    if (propName == QStringLiteral("Volume"))
    {
        const double &Volume = qvariant_cast<double>(value);
        if (d_ptr->Volume != Volume)
        {
            d_ptr->Volume = Volume;
            Q_EMIT VolumeChanged(d_ptr->Volume);
        }
        return;
    }

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

double __Sink::balance()
{
    return qvariant_cast<double>(internalPropGet("Balance", &d_ptr->Balance));
}

double __Sink::baseVolume()
{
    return qvariant_cast<double>(internalPropGet("BaseVolume", &d_ptr->BaseVolume));
}

uint __Sink::card()
{
    return qvariant_cast<uint>(internalPropGet("Card", &d_ptr->Card));
}

QString __Sink::description()
{
    return qvariant_cast<QString>(internalPropGet("Description", &d_ptr->Description));
}

double __Sink::fade()
{
    return qvariant_cast<double>(internalPropGet("Fade", &d_ptr->Fade));
}

bool __Sink::mute()
{
    return qvariant_cast<bool>(internalPropGet("Mute", &d_ptr->Mute));
}

QString __Sink::name()
{
    return qvariant_cast<QString>(internalPropGet("Name", &d_ptr->Name));
}

bool __Sink::supportBalance()
{
    return qvariant_cast<bool>(internalPropGet("SupportBalance", &d_ptr->SupportBalance));
}

double __Sink::volume()
{
    return qvariant_cast<double>(internalPropGet("Volume", &d_ptr->Volume));
}

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

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