mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
Ref T118, formatting database writer and utility
This commit is contained in:
@@ -59,7 +59,7 @@ namespace BlackCore
|
||||
|
||||
if (this->isReplyOverdue())
|
||||
{
|
||||
bool killed = this->killPendingReply();
|
||||
const bool killed = this->killPendingReply();
|
||||
if (killed)
|
||||
{
|
||||
const CStatusMessage msg(CStatusMessage::SeverityWarning, "Aborted outdated pending reply");
|
||||
@@ -88,7 +88,7 @@ namespace BlackCore
|
||||
QNetworkRequest request(url);
|
||||
CNetworkUtils::ignoreSslVerification(request);
|
||||
const int logId = m_writeLog.addPendingUrl(url);
|
||||
m_pendingReply = sApp->postToNetwork(request, logId, multiPart, { this, &CDatabaseWriter::ps_postModelsResponse});
|
||||
m_pendingReply = sApp->postToNetwork(request, logId, multiPart, { this, &CDatabaseWriter::postedModelsResponse});
|
||||
m_replyPendingSince = QDateTime::currentMSecsSinceEpoch();
|
||||
return msgs;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace BlackCore
|
||||
return n;
|
||||
}
|
||||
|
||||
void CDatabaseWriter::ps_postModelsResponse(QNetworkReply *nwReplyPtr)
|
||||
void CDatabaseWriter::postedModelsResponse(QNetworkReply *nwReplyPtr)
|
||||
{
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::swiftDbWebservice()}));
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||
@@ -125,7 +125,7 @@ namespace BlackCore
|
||||
if (dataFileData.isEmpty())
|
||||
{
|
||||
const CStatusMessageList msgs({CStatusMessage(cats, CStatusMessage::SeverityError, "No response data from " + urlString)});
|
||||
emit publishedModels(CAircraftModelList(), CAircraftModelList(), msgs, false, false);
|
||||
emit this->publishedModels(CAircraftModelList(), CAircraftModelList(), msgs, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -134,14 +134,14 @@ namespace BlackCore
|
||||
CStatusMessageList msgs;
|
||||
bool directWrite;
|
||||
const bool sendingSuccessful = CDatastoreUtility::parseSwiftPublishResponse(dataFileData, modelsPublished, modelsSkipped, msgs, directWrite);
|
||||
emit publishedModels(modelsPublished, modelsSkipped, msgs, sendingSuccessful, directWrite);
|
||||
emit this->publishedModels(modelsPublished, modelsSkipped, msgs, sendingSuccessful, directWrite);
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString error = nwReply->errorString();
|
||||
nwReply->close(); // close asap
|
||||
const CStatusMessageList msgs( {CStatusMessage(cats, CStatusMessage::SeverityError, "HTTP error: " + error)});
|
||||
emit publishedModels(CAircraftModelList(), CAircraftModelList(), msgs, false, false);
|
||||
emit this->publishedModels(CAircraftModelList(), CAircraftModelList(), msgs, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,10 +62,6 @@ namespace BlackCore
|
||||
const BlackMisc::CStatusMessageList &messages,
|
||||
bool sendingSuccessful, bool directWrite);
|
||||
|
||||
private slots:
|
||||
//! Post response
|
||||
void ps_postModelsResponse(QNetworkReply *nwReplyPtr);
|
||||
|
||||
private:
|
||||
BlackMisc::Network::CUrlLogList m_writeLog;
|
||||
BlackMisc::Network::CUrl m_modelPublishUrl;
|
||||
@@ -73,6 +69,9 @@ namespace BlackCore
|
||||
qint64 m_replyPendingSince = -1;
|
||||
bool m_shutdown = false;
|
||||
|
||||
//! Post response
|
||||
void postedModelsResponse(QNetworkReply *nwReplyPtr);
|
||||
|
||||
//! Kill the pending reply
|
||||
bool killPendingReply();
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace BlackMisc
|
||||
|
||||
bool CDatastoreUtility::parseSwiftPublishResponse(const QString &jsonResponse, CAircraftModelList &publishedModels, CAircraftModelList &skippedModels, CStatusMessageList &messages, bool &directWrite)
|
||||
{
|
||||
static const CLogCategoryList cats({ CLogCategory::swiftDbWebservice()});
|
||||
static const CLogCategoryList cats({CLogCategory::swiftDbWebservice()});
|
||||
directWrite = false;
|
||||
|
||||
if (jsonResponse.isEmpty())
|
||||
@@ -92,7 +92,7 @@ namespace BlackMisc
|
||||
// array of messages only
|
||||
if (jsonDoc.isArray())
|
||||
{
|
||||
CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(jsonDoc.array()));
|
||||
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(jsonDoc.array()));
|
||||
messages.push_back(msgs);
|
||||
return true;
|
||||
}
|
||||
@@ -110,8 +110,8 @@ namespace BlackMisc
|
||||
bool hasData = false;
|
||||
if (json.contains("msgs"))
|
||||
{
|
||||
QJsonValue msgJson(json.take("msgs"));
|
||||
CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(msgJson.toArray()));
|
||||
const QJsonValue msgJson(json.take("msgs"));
|
||||
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(msgJson.toArray()));
|
||||
if (!msgs.isEmpty())
|
||||
{
|
||||
messages.push_back(msgs);
|
||||
@@ -122,14 +122,14 @@ namespace BlackMisc
|
||||
// direct write means models written, otherwise CRs
|
||||
if (json.contains("directWrite"))
|
||||
{
|
||||
QJsonValue dw(json.take("directWrite"));
|
||||
const QJsonValue dw(json.take("directWrite"));
|
||||
directWrite = dw.toBool(false);
|
||||
}
|
||||
|
||||
if (json.contains("publishedModels"))
|
||||
{
|
||||
QJsonValue publishedJson(json.take("publishedModels"));
|
||||
CAircraftModelList published = CAircraftModelList::fromDatabaseJson(publishedJson.toArray(), "");
|
||||
const QJsonValue publishedJson(json.take("publishedModels"));
|
||||
const CAircraftModelList published = CAircraftModelList::fromDatabaseJson(publishedJson.toArray(), "");
|
||||
if (!published.isEmpty())
|
||||
{
|
||||
publishedModels.push_back(published);
|
||||
@@ -139,8 +139,8 @@ namespace BlackMisc
|
||||
|
||||
if (json.contains("skippedModels"))
|
||||
{
|
||||
QJsonValue skippedJson(json.take("skippedModels"));
|
||||
CAircraftModelList skipped = CAircraftModelList::fromDatabaseJson(skippedJson.toArray(), "");
|
||||
const QJsonValue skippedJson(json.take("skippedModels"));
|
||||
const CAircraftModelList skipped = CAircraftModelList::fromDatabaseJson(skippedJson.toArray(), "");
|
||||
if (!skipped.isEmpty())
|
||||
{
|
||||
skippedModels.push_back(skipped);
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
namespace BlackMisc
|
||||
{
|
||||
class CStatusMessageList;
|
||||
namespace Simulation { class CAircraftModelList; }
|
||||
|
||||
namespace Simulation { class CAircraftModelList; }
|
||||
namespace Db
|
||||
{
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user