/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c Session1 -p generated/org_bluez_obex_session1 ../xml/org.bluez.obex.Session1.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/org_bluez_obex_session1.h"

/*
 * Implementation of interface class __Session1
 */

class __Session1Private
{
public:
   __Session1Private() = default;

    // begin member variables
    uchar Channel;
    QString Destination;
    QString Source;
    QString Target;

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

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

}

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

void __Session1::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("Channel"))
    {
        const uchar &Channel = qvariant_cast<uchar>(value);
        if (d_ptr->Channel != Channel)
        {
            d_ptr->Channel = Channel;
            Q_EMIT ChannelChanged(d_ptr->Channel);
        }
        return;
    }

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

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

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

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

uchar __Session1::channel()
{
    return qvariant_cast<uchar>(internalPropGet("Channel", &d_ptr->Channel));
}

QString __Session1::destination()
{
    return qvariant_cast<QString>(internalPropGet("Destination", &d_ptr->Destination));
}

QString __Session1::source()
{
    return qvariant_cast<QString>(internalPropGet("Source", &d_ptr->Source));
}

QString __Session1::target()
{
    return qvariant_cast<QString>(internalPropGet("Target", &d_ptr->Target));
}

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

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