File indexing completed on 2024-04-28 04:44:21

0001 /*
0002    SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
0003 
0004    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #include "upnpcontrolabstractservicereply.h"
0008 
0009 #include <KDSoapClient/KDSoapPendingCall>
0010 #include <KDSoapClient/KDSoapPendingCallWatcher>
0011 
0012 class UpnpControlAbstractServiceReplyPrivate
0013 {
0014 public:
0015     explicit UpnpControlAbstractServiceReplyPrivate(const KDSoapPendingCall &soapAnswer)
0016         : mAnswer(soapAnswer)
0017         , mWatcher(mAnswer)
0018     {
0019     }
0020 
0021     KDSoapPendingCall mAnswer;
0022 
0023     KDSoapPendingCallWatcher mWatcher;
0024 
0025     QVariantMap mResult;
0026 };
0027 
0028 UpnpControlAbstractServiceReply::UpnpControlAbstractServiceReply(const KDSoapPendingCall &soapAnswer, QObject *parent)
0029     : QObject(parent)
0030     , d(std::make_unique<UpnpControlAbstractServiceReplyPrivate>(soapAnswer))
0031 {
0032     connect(&d->mWatcher, &KDSoapPendingCallWatcher::finished, this, &UpnpControlAbstractServiceReply::callFinished);
0033 }
0034 
0035 UpnpControlAbstractServiceReply::~UpnpControlAbstractServiceReply() = default;
0036 
0037 bool UpnpControlAbstractServiceReply::success() const
0038 {
0039     return d->mAnswer.isFinished() && !d->mWatcher.returnMessage().isFault();
0040 }
0041 
0042 QVariantMap UpnpControlAbstractServiceReply::result() const
0043 {
0044     return d->mResult;
0045 }
0046 
0047 QString UpnpControlAbstractServiceReply::error() const
0048 {
0049     return d->mWatcher.returnMessage().faultAsString();
0050 }
0051 
0052 void UpnpControlAbstractServiceReply::callFinished()
0053 {
0054     parseAnswer();
0055 
0056     Q_EMIT finished(this);
0057 }
0058 
0059 void UpnpControlAbstractServiceReply::parseAnswer()
0060 {
0061     if (!d->mAnswer.isFinished()) {
0062         return;
0063     }
0064 
0065     const auto &returnedValues = d->mAnswer.returnMessage().childValues();
0066 
0067     for (const KDSoapValue &oneValue : returnedValues) {
0068         d->mResult[oneValue.name()] = oneValue.value();
0069     }
0070 }
0071 
0072 #include "moc_upnpcontrolabstractservicereply.cpp"