##// END OF EJS Templates
Amda provider (1)...
Alexandre Leroux -
r378:1e0772e9e7a5
parent child
Show More
@@ -13,7 +13,7 INCLUDE_DIRECTORIES(${RESOURCES_DIR})
13 #
13 #
14 # Find Qt modules
14 # Find Qt modules
15 #
15 #
16 SCIQLOP_FIND_QT(Core Widgets)
16 SCIQLOP_FIND_QT(Core Widgets Network)
17
17
18 #
18 #
19 # Find dependent libraries
19 # Find dependent libraries
@@ -68,7 +68,7 INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME}
68
68
69
69
70 TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES})
70 TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES})
71 qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets)
71 qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets Network)
72
72
73 add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME})
73 add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME})
74
74
@@ -26,6 +26,9 private:
26
26
27 class AmdaProviderPrivate;
27 class AmdaProviderPrivate;
28 spimpl::unique_impl_ptr<AmdaProviderPrivate> impl;
28 spimpl::unique_impl_ptr<AmdaProviderPrivate> impl;
29
30 private slots:
31 void httpFinished() noexcept;
29 };
32 };
30
33
31 #endif // SCIQLOP_AMDAPROVIDER_H
34 #endif // SCIQLOP_AMDAPROVIDER_H
@@ -1,8 +1,40
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include <Data/DataProviderParameters.h>
3
4 #include <QNetworkAccessManager>
5 #include <QNetworkReply>
2
6
3 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
7 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
4
8
9 namespace {
10
11 /// URL format for a request on AMDA server. The parameters are as follows:
12 /// - %1: start date
13 /// - %2: end date
14 /// - %3: parameter id
15 const auto AMDA_URL_FORMAT = QStringLiteral(
16 "http://amda.irap.omp.eu/php/rest/"
17 "getParameter.php?startTime=%1&stopTime=%2&parameterID=%3&sampling=60&outputFormat=ASCII&"
18 "timeFormat=ISO8601&gzip=0");
19
20 /// Dates format passed in the URL (e.g 2013-09-23T09:00)
21 const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:ss");
22
23 /// Formats a time to a date that can be passed in URL
24 QString dateFormat(double sqpDateTime) noexcept
25 {
26 auto dateTime = QDateTime::fromMSecsSinceEpoch(sqpDateTime * 1000.);
27 return dateTime.toString(AMDA_TIME_FORMAT);
28 }
29
30 } // namespace
31
5 struct AmdaProvider::AmdaProviderPrivate {
32 struct AmdaProvider::AmdaProviderPrivate {
33 DataProviderParameters m_Params{};
34 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
35 QNetworkReply *m_Reply{nullptr};
36 std::unique_ptr<QTemporaryFile> m_File{nullptr};
37 QUuid m_Token;
6 };
38 };
7
39
8 AmdaProvider::AmdaProvider() : impl{spimpl::make_unique_impl<AmdaProviderPrivate>()}
40 AmdaProvider::AmdaProvider() : impl{spimpl::make_unique_impl<AmdaProviderPrivate>()}
@@ -19,5 +51,28 void AmdaProvider::requestDataLoading(QUuid token, const QVector<SqpDateTime> &d
19
51
20 void AmdaProvider::retrieveData(QUuid token, const DataProviderParameters &parameters) const
52 void AmdaProvider::retrieveData(QUuid token, const DataProviderParameters &parameters) const
21 {
53 {
54 // /////////// //
55 // Creates URL //
56 // /////////// //
57
58 auto startDate = dateFormat(parameters.m_Time.m_TStart);
59 auto endDate = dateFormat(parameters.m_Time.m_TEnd);
60 auto productId = QStringLiteral("imf(0)");
61
62 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
63
64 // //////////////// //
65 // Executes request //
66 // //////////////// //
67
68 impl->m_Token = token;
69 impl->m_Params = parameters;
70 impl->m_AccessManager = std::make_unique<QNetworkAccessManager>();
71 impl->m_Reply = impl->m_AccessManager->get(QNetworkRequest{url});
72 connect(impl->m_Reply, &QNetworkReply::finished, this, &AmdaProvider::httpFinished);
73 }
74
75 void AmdaProvider::httpFinished() noexcept
76 {
22 /// @todo ALX
77 /// @todo ALX
23 }
78 }
General Comments 0
You need to be logged in to leave comments. Login now