/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c ConnectionSession -p generated/com_deepin_daemon_network_connectionsession ../xml/com.deepin.daemon.Network.ConnectionSession.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_daemon_network_connectionsession.h"

/*
 * Implementation of interface class __ConnectionSession
 */

class __ConnectionSessionPrivate
{
public:
   __ConnectionSessionPrivate() = default;

    // begin member variables
    bool AllowDelete;
    bool AllowEditConnectionId;
    NetworkAvailableKeys AvailableKeys;
    QStringList AvailableSections;
    QStringList AvailableVirtualSections;
    QDBusObjectPath ConnectionPath;
    NetworkErrors Errors;
    QString Type;
    QString Uuid;

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

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

    if (QMetaType::type("NetworkAvailableKeys") == QMetaType::UnknownType)
        registerNetworkAvailableKeysMetaType();
    if (QMetaType::type("NetworkErrors") == QMetaType::UnknownType)
        registerNetworkErrorsMetaType();
    if (QMetaType::type("NetworkConnectionData") == QMetaType::UnknownType)
        registerNetworkConnectionDataMetaType();
}

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

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

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

    if (propName == QStringLiteral("AvailableKeys"))
    {
        const NetworkAvailableKeys &AvailableKeys = qvariant_cast<NetworkAvailableKeys>(value);
        if (d_ptr->AvailableKeys != AvailableKeys)
        {
            d_ptr->AvailableKeys = AvailableKeys;
            Q_EMIT AvailableKeysChanged(d_ptr->AvailableKeys);
        }
        return;
    }

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

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

    if (propName == QStringLiteral("ConnectionPath"))
    {
        const QDBusObjectPath &ConnectionPath = qvariant_cast<QDBusObjectPath>(value);
        if (d_ptr->ConnectionPath != ConnectionPath)
        {
            d_ptr->ConnectionPath = ConnectionPath;
            Q_EMIT ConnectionPathChanged(d_ptr->ConnectionPath);
        }
        return;
    }

    if (propName == QStringLiteral("Errors"))
    {
        const NetworkErrors &Errors = qvariant_cast<NetworkErrors>(value);
        if (d_ptr->Errors != Errors)
        {
            d_ptr->Errors = Errors;
            Q_EMIT ErrorsChanged(d_ptr->Errors);
        }
        return;
    }

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

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

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

bool __ConnectionSession::allowDelete()
{
    return qvariant_cast<bool>(internalPropGet("AllowDelete", &d_ptr->AllowDelete));
}

bool __ConnectionSession::allowEditConnectionId()
{
    return qvariant_cast<bool>(internalPropGet("AllowEditConnectionId", &d_ptr->AllowEditConnectionId));
}

NetworkAvailableKeys __ConnectionSession::availableKeys()
{
    return qvariant_cast<NetworkAvailableKeys>(internalPropGet("AvailableKeys", &d_ptr->AvailableKeys));
}

QStringList __ConnectionSession::availableSections()
{
    return qvariant_cast<QStringList>(internalPropGet("AvailableSections", &d_ptr->AvailableSections));
}

QStringList __ConnectionSession::availableVirtualSections()
{
    return qvariant_cast<QStringList>(internalPropGet("AvailableVirtualSections", &d_ptr->AvailableVirtualSections));
}

QDBusObjectPath __ConnectionSession::connectionPath()
{
    return qvariant_cast<QDBusObjectPath>(internalPropGet("ConnectionPath", &d_ptr->ConnectionPath));
}

NetworkErrors __ConnectionSession::errors()
{
    return qvariant_cast<NetworkErrors>(internalPropGet("Errors", &d_ptr->Errors));
}

QString __ConnectionSession::type()
{
    return qvariant_cast<QString>(internalPropGet("Type", &d_ptr->Type));
}

QString __ConnectionSession::uuid()
{
    return qvariant_cast<QString>(internalPropGet("Uuid", &d_ptr->Uuid));
}

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

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