##// END OF EJS Templates
Amda provider cleaning...
Alexandre Leroux -
r409:c01bd18b5f57
parent child
Show More
@@ -3,8 +3,6
3
3
4 #include "AmdaGlobal.h"
4 #include "AmdaGlobal.h"
5
5
6 #include <Common/spimpl.h>
7
8 #include <Data/IDataProvider.h>
6 #include <Data/IDataProvider.h>
9
7
10 #include <QLoggingCategory>
8 #include <QLoggingCategory>
@@ -25,14 +23,6 public:
25
23
26 private:
24 private:
27 void retrieveData(QUuid token, const SqpDateTime &dateTime);
25 void retrieveData(QUuid token, const SqpDateTime &dateTime);
28
29 class AmdaProviderPrivate;
30 spimpl::unique_impl_ptr<AmdaProviderPrivate> impl;
31
32 // private slots:
33 // void httpFinished(QNetworkReply *reply, QUuid dataId) noexcept;
34 // void httpDownloadFinished(QNetworkReply *reply, QUuid dataId) noexcept;
35 // void httpDownloadReadyRead(QNetworkReply *reply, QUuid dataId) noexcept;
36 };
26 };
37
27
38 #endif // SCIQLOP_AMDAPROVIDER_H
28 #endif // SCIQLOP_AMDAPROVIDER_H
@@ -34,18 +34,9 QString dateFormat(double sqpDateTime) noexcept
34 return dateTime.toString(AMDA_TIME_FORMAT);
34 return dateTime.toString(AMDA_TIME_FORMAT);
35 }
35 }
36
36
37
38 } // namespace
37 } // namespace
39
38
40 struct AmdaProvider::AmdaProviderPrivate {
39 AmdaProvider::AmdaProvider()
41 SqpDateTime m_DateTime{};
42 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
43 QNetworkReply *m_Reply{nullptr};
44 // std::unique_ptr<QTemporaryFile> m_File{nullptr};
45 QUuid m_Token;
46 };
47
48 AmdaProvider::AmdaProvider() : impl{spimpl::make_unique_impl<AmdaProviderPrivate>()}
49 {
40 {
50 qCDebug(LOG_NetworkController()) << tr("AmdaProvider::AmdaProvider")
41 qCDebug(LOG_NetworkController()) << tr("AmdaProvider::AmdaProvider")
51 << QThread::currentThread();
42 << QThread::currentThread();
@@ -79,30 +70,31 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime)
79
70
80 auto tempFile = std::make_shared<QTemporaryFile>();
71 auto tempFile = std::make_shared<QTemporaryFile>();
81
72
82
83 // LAMBDA
73 // LAMBDA
84 auto httpDownloadFinished = [this, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
74 auto httpDownloadFinished
85
75 = [this, dateTime, tempFile, token](QNetworkReply *reply, QUuid dataId) noexcept {
86 if (tempFile) {
76 Q_UNUSED(dataId);
87 auto replyReadAll = reply->readAll();
77
88 if (!replyReadAll.isEmpty()) {
78 if (tempFile) {
89 tempFile->write(replyReadAll);
79 auto replyReadAll = reply->readAll();
90 }
80 if (!replyReadAll.isEmpty()) {
91 tempFile->close();
81 tempFile->write(replyReadAll);
92
82 }
93 // Parse results file
83 tempFile->close();
94 if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) {
84
95 emit dataProvided(impl->m_Token, dataSeries, impl->m_DateTime);
85 // Parse results file
96 }
86 if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) {
97 else {
87 emit dataProvided(token, dataSeries, dateTime);
98 /// @todo ALX : debug
88 }
99 }
89 else {
100 }
90 /// @todo ALX : debug
101
91 }
102 // Deletes reply
92 }
103 reply->deleteLater();
93
104 reply = nullptr;
94 // Deletes reply
105 };
95 reply->deleteLater();
96 reply = nullptr;
97 };
106 auto httpFinishedLambda = [this, httpDownloadFinished, tempFile](QNetworkReply *reply,
98 auto httpFinishedLambda = [this, httpDownloadFinished, tempFile](QNetworkReply *reply,
107 QUuid dataId) noexcept {
99 QUuid dataId) noexcept {
108
100
@@ -122,8 +114,5 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime)
122 // //////////////// //
114 // //////////////// //
123 // Executes request //
115 // Executes request //
124 // //////////////// //
116 // //////////////// //
125
126 impl->m_Token = token;
127 impl->m_DateTime = dateTime;
128 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
117 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
129 }
118 }
General Comments 0
You need to be logged in to leave comments. Login now