Fix reply parent relationship for a clean shutdown
parent
6a13cedace
commit
2f7cd2f028
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io *
|
||||
* Copyright (C) 2017-2018 Simon Stürz <simon.stuerz@guh.io *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io *
|
||||
* Copyright (C) 2017-2018 Simon Stürz <simon.stuerz@guh.io *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
|
|
|
|||
|
|
@ -1,6 +1,30 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017-2018 Simon Stürz <simon.stuerz@guh.io *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; If not, see *
|
||||
* <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
#include "snapdconnection.h"
|
||||
#include "extern-plugininfo.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
|
||||
|
|
@ -15,9 +39,9 @@ SnapdConnection::SnapdConnection(QObject *parent) :
|
|||
connect(this, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(onError(QLocalSocket::LocalSocketError)));
|
||||
}
|
||||
|
||||
SnapdReply *SnapdConnection::get(const QString &path)
|
||||
SnapdReply *SnapdConnection::get(const QString &path, QObject *parent)
|
||||
{
|
||||
SnapdReply *reply = new SnapdReply(this);
|
||||
SnapdReply *reply = new SnapdReply(parent);
|
||||
reply->setRequestPath(path);
|
||||
reply->setRequestMethod("GET");
|
||||
reply->setRequestRawMessage(createRequestHeader("GET", path));
|
||||
|
|
@ -30,9 +54,9 @@ SnapdReply *SnapdConnection::get(const QString &path)
|
|||
return reply;
|
||||
}
|
||||
|
||||
SnapdReply *SnapdConnection::post(const QString &path, const QByteArray &payload)
|
||||
SnapdReply *SnapdConnection::post(const QString &path, const QByteArray &payload, QObject *parent)
|
||||
{
|
||||
SnapdReply *reply = new SnapdReply(this);
|
||||
SnapdReply *reply = new SnapdReply(parent);
|
||||
reply->setRequestPath(path);
|
||||
reply->setRequestMethod("POST");
|
||||
QByteArray header = createRequestHeader("POST", path, payload);
|
||||
|
|
@ -57,22 +81,28 @@ void SnapdConnection::setConnected(const bool &connected)
|
|||
return;
|
||||
|
||||
m_connected = connected;
|
||||
emit connectedChanged(m_connected);
|
||||
|
||||
// Clean up replies of disconnected
|
||||
if (!m_connected) {
|
||||
foreach (SnapdReply *reply, m_replyQueue) {
|
||||
reply->setFinished(false);
|
||||
}
|
||||
|
||||
if (m_currentReply) {
|
||||
m_currentReply->setFinished(false);
|
||||
m_currentReply = nullptr;
|
||||
}
|
||||
|
||||
m_replyQueue.clear();
|
||||
}
|
||||
while (!m_replyQueue.isEmpty()) {
|
||||
QPointer<SnapdReply> reply = m_replyQueue.dequeue();
|
||||
if (!reply.isNull()) {
|
||||
reply->setFinished(false);
|
||||
}
|
||||
}
|
||||
|
||||
emit connectedChanged(m_connected);
|
||||
} else {
|
||||
// Start with a clean parsing
|
||||
m_payload.clear();
|
||||
m_header.clear();
|
||||
m_chuncked = false;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray SnapdConnection::createRequestHeader(const QString &method, const QString &path, const QByteArray &payload)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,25 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017-2018 Simon Stürz <simon.stuerz@guh.io *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; If not, see *
|
||||
* <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef SNAPDCONNECTION_H
|
||||
#define SNAPDCONNECTION_H
|
||||
|
||||
|
|
@ -13,8 +35,8 @@ class SnapdConnection : public QLocalSocket
|
|||
public:
|
||||
explicit SnapdConnection(QObject *parent = nullptr);
|
||||
|
||||
SnapdReply *get(const QString &path);
|
||||
SnapdReply *post(const QString &path, const QByteArray &payload);
|
||||
SnapdReply *get(const QString &path, QObject *parent);
|
||||
SnapdReply *post(const QString &path, const QByteArray &payload, QObject *parent);
|
||||
|
||||
bool isConnected() const;
|
||||
|
||||
|
|
@ -39,6 +61,9 @@ private:
|
|||
void processData();
|
||||
void sendNextRequest();
|
||||
|
||||
signals:
|
||||
void connectedChanged(const bool &connected);
|
||||
|
||||
private slots:
|
||||
void onConnected();
|
||||
void onDisconnected();
|
||||
|
|
@ -46,9 +71,6 @@ private slots:
|
|||
void onStateChanged(const QLocalSocket::LocalSocketState &state);
|
||||
void onReadyRead();
|
||||
|
||||
signals:
|
||||
void connectedChanged(const bool &connected);
|
||||
|
||||
};
|
||||
|
||||
#endif // SNAPDCONNECTION_H
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io *
|
||||
* Copyright (C) 2017-2018 Simon Stürz <simon.stuerz@guh.io *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
|
|
@ -81,7 +81,7 @@ void SnapdControl::loadSystemInfo()
|
|||
if (!m_snapConnection->isConnected())
|
||||
return;
|
||||
|
||||
SnapdReply *reply = m_snapConnection->get("/v2/system-info");
|
||||
SnapdReply *reply = m_snapConnection->get("/v2/system-info", this);
|
||||
connect(reply, &SnapdReply::finished, this, &SnapdControl::onLoadSystemInfoFinished);
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ void SnapdControl::loadSnapList()
|
|||
if (!m_snapConnection->isConnected())
|
||||
return;
|
||||
|
||||
SnapdReply *reply = m_snapConnection->get("/v2/snaps");
|
||||
SnapdReply *reply = m_snapConnection->get("/v2/snaps", this);
|
||||
connect(reply, &SnapdReply::finished, this, &SnapdControl::onLoadSnapListFinished);
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ void SnapdControl::loadRunningChanges()
|
|||
if (!m_snapConnection->isConnected())
|
||||
return;
|
||||
|
||||
SnapdReply *reply = m_snapConnection->get("/v2/changes");
|
||||
SnapdReply *reply = m_snapConnection->get("/v2/changes", this);
|
||||
connect(reply, &SnapdReply::finished, this, &SnapdControl::onLoadRunningChangesFinished);
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ void SnapdControl::loadChange(const int &change)
|
|||
if (!m_snapConnection->isConnected())
|
||||
return;
|
||||
|
||||
SnapdReply *reply = m_snapConnection->get(QString("/v2/changes/%1").arg(QString::number(change)));
|
||||
SnapdReply *reply = m_snapConnection->get(QString("/v2/changes/%1").arg(QString::number(change)), this);
|
||||
connect(reply, &SnapdReply::finished, this, &SnapdControl::onLoadChangeFinished);
|
||||
}
|
||||
|
||||
|
|
@ -381,7 +381,7 @@ void SnapdControl::snapRefresh()
|
|||
request.insert("action", "refresh");
|
||||
|
||||
qCDebug(dcSnapd()) << "Refresh all snaps";
|
||||
SnapdReply *reply = m_snapConnection->post("/v2/snaps", QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact));
|
||||
SnapdReply *reply = m_snapConnection->post("/v2/snaps", QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact), this);
|
||||
connect(reply, &SnapdReply::finished, this, &SnapdControl::onSnapRefreshFinished);
|
||||
}
|
||||
|
||||
|
|
@ -398,7 +398,7 @@ void SnapdControl::changeSnapChannel(const QString &snapName, const QString &cha
|
|||
request.insert("channel", channel);
|
||||
|
||||
qCDebug(dcSnapd()) << "Refresh snap" << snapName << "to channel" << channel;
|
||||
SnapdReply *reply = m_snapConnection->post(QString("/v2/snaps/%1").arg(snapName), QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact));
|
||||
SnapdReply *reply = m_snapConnection->post(QString("/v2/snaps/%1").arg(snapName), QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact), this);
|
||||
connect(reply, &SnapdReply::finished, this, &SnapdControl::onChangeSnapChannelFinished);
|
||||
}
|
||||
|
||||
|
|
@ -410,7 +410,7 @@ void SnapdControl::checkForUpdates()
|
|||
if (!m_snapConnection->isConnected())
|
||||
return;
|
||||
|
||||
SnapdReply *reply = m_snapConnection->get("/v2/find?select=refresh");
|
||||
SnapdReply *reply = m_snapConnection->get("/v2/find?select=refresh", this);
|
||||
connect(reply, &SnapdReply::finished, this, &SnapdControl::onCheckForUpdatesFinished);
|
||||
}
|
||||
|
||||
|
|
@ -426,6 +426,6 @@ void SnapdControl::snapRevert(const QString &snapName)
|
|||
request.insert("action", "revert");
|
||||
|
||||
qCDebug(dcSnapd()) << "Revert snap" << snapName;
|
||||
SnapdReply *reply = m_snapConnection->post(QString("/v2/snaps/%1").arg(snapName), QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact));
|
||||
SnapdReply *reply = m_snapConnection->post(QString("/v2/snaps/%1").arg(snapName), QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact), this);
|
||||
connect(reply, &SnapdReply::finished, this, &SnapdControl::onSnapRevertFinished);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io *
|
||||
* Copyright (C) 2017-2018 Simon Stürz <simon.stuerz@guh.io *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
|
|
|
|||
|
|
@ -1,3 +1,25 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017-2018 Simon Stürz <simon.stuerz@guh.io *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; If not, see *
|
||||
* <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "snapdreply.h"
|
||||
|
||||
QString SnapdReply::requestPath() const
|
||||
|
|
|
|||
|
|
@ -1,3 +1,25 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2017-2018 Simon Stürz <simon.stuerz@guh.io *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; If not, see *
|
||||
* <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef SNAPDREPLY_H
|
||||
#define SNAPDREPLY_H
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue