@@ -1,72 +1,73 | |||
|
1 | 1 | |
|
2 | 2 | if(BUILD_TESTS) |
|
3 | 3 | INCLUDE ("cmake/sciqlop_code_coverage.cmake") |
|
4 | 4 | APPEND_COVERAGE_COMPILER_FLAGS() |
|
5 | 5 | endif(BUILD_TESTS) |
|
6 | 6 | |
|
7 | 7 | # |
|
8 | 8 | # Compile the diffents modules |
|
9 | 9 | # |
|
10 | 10 | set(sciqlop-plugin_DIR "${CMAKE_SOURCE_DIR}/plugin/cmake") |
|
11 | 11 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-plugin_DIR}") |
|
12 | 12 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugin") |
|
13 | 13 | |
|
14 | 14 | set(sciqlop-core_DIR "${CMAKE_SOURCE_DIR}/core/cmake") |
|
15 | 15 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-core_DIR}") |
|
16 | 16 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/core") |
|
17 | 17 | |
|
18 | 18 | set(sciqlop-gui_DIR "${CMAKE_SOURCE_DIR}/gui/cmake") |
|
19 | 19 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-gui_DIR}") |
|
20 | 20 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/gui") |
|
21 | 21 | |
|
22 | 22 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/app") |
|
23 | 23 | |
|
24 | 24 | OPTION (BUILD_PLUGINS "Build the plugins" OFF) |
|
25 | 25 | IF(BUILD_PLUGINS) |
|
26 | 26 | set(sciqlop-mockplugin_DIR "${CMAKE_SOURCE_DIR}/plugins/mockplugin/cmake") |
|
27 | 27 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-mockplugin_DIR}") |
|
28 | 28 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugins/mockplugin") |
|
29 | 29 | |
|
30 | 30 | # Sets AMDA server that will be used during execution. |
|
31 | 31 | # Available values are: |
|
32 | 32 | # - "default": default AMDA server |
|
33 | 33 | # - "amdatest": AMDA test server |
|
34 | # - "hybrid": use both the default server and the test server (the server used is relative to each product, according to its "server" property in the JSON file) | |
|
34 | 35 | # Any other value will lead to the use of the default server |
|
35 |
ADD_DEFINITIONS(-DSCIQLOP_AMDA_SERVER="d |
|
|
36 | ADD_DEFINITIONS(-DSCIQLOP_AMDA_SERVER="hybrid") | |
|
36 | 37 | |
|
37 | 38 | set(sciqlop-amda_DIR "${CMAKE_SOURCE_DIR}/plugins/amda/cmake") |
|
38 | 39 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-amda_DIR}") |
|
39 | 40 | ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/plugins/amda") |
|
40 | 41 | |
|
41 | 42 | # Temporary target to copy to plugins dir |
|
42 | 43 | find_package(sciqlop-mockplugin) |
|
43 | 44 | find_package(sciqlop-amda) |
|
44 | 45 | ADD_CUSTOM_TARGET(plugins |
|
45 | 46 | COMMAND ${CMAKE_COMMAND} -E copy ${SCIQLOP-MOCKPLUGIN_LIBRARIES} "${LIBRARY_OUTPUT_PATH}/plugins/${SCIQLOP-MOCKPLUGIN_LIBRARIES_NAME}" |
|
46 | 47 | COMMAND ${CMAKE_COMMAND} -E copy ${SCIQLOP-AMDA_LIBRARIES} "${LIBRARY_OUTPUT_PATH}/plugins/${SCIQLOP-AMDA_LIBRARIES_NAME}" |
|
47 | 48 | ) |
|
48 | 49 | ENDIF(BUILD_PLUGINS) |
|
49 | 50 | |
|
50 | 51 | # LOGGER |
|
51 | 52 | set(QTLOGGING_INI_FILE "${CMAKE_SOURCE_DIR}/config/QtProject/qtlogging.ini") |
|
52 | 53 | FILE(COPY ${QTLOGGING_INI_FILE} DESTINATION ${CONFIG_OUTPUT_PATH}) |
|
53 | 54 | |
|
54 | 55 | |
|
55 | 56 | # |
|
56 | 57 | # Code formatting |
|
57 | 58 | # |
|
58 | 59 | # Vera++ exclusion files |
|
59 | 60 | LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/formatting/vera-exclusions/exclusions.txt) |
|
60 | 61 | #SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) |
|
61 | 62 | INCLUDE ("cmake/sciqlop_formatting.cmake") |
|
62 | 63 | |
|
63 | 64 | # |
|
64 | 65 | # Documentation generation |
|
65 | 66 | # |
|
66 | 67 | INCLUDE ("cmake/sciqlop_doxygen.cmake") |
|
67 | 68 | |
|
68 | 69 | # |
|
69 | 70 | # Source code analysis |
|
70 | 71 | # |
|
71 | 72 | INCLUDE ("cmake/sciqlop_code_analysis.cmake") |
|
72 | 73 | INCLUDE ("cmake/sciqlop_code_cppcheck.cmake") |
@@ -1,44 +1,45 | |||
|
1 | 1 | project('SciQLOP', 'cpp',default_options : ['cpp_std=c++14']) |
|
2 | 2 | |
|
3 | 3 | qt5 = import('qt5') |
|
4 | 4 | qt5core = dependency('qt5', modules : 'Core') |
|
5 | 5 | qt5widgets = dependency('qt5', modules : 'Widgets') |
|
6 | 6 | qt5gui = dependency('qt5', modules : 'Gui') |
|
7 | 7 | qt5svg = dependency('qt5', modules : 'Svg') |
|
8 | 8 | qt5xml = dependency('qt5', modules : 'Xml') |
|
9 | 9 | qt5network = dependency('qt5', modules : 'Network') |
|
10 | 10 | qt5printsupport = dependency('qt5', modules : 'PrintSupport') |
|
11 | 11 | qt5test = dependency('qt5', modules : 'Test') |
|
12 | 12 | |
|
13 | 13 | moc = find_program('moc-qt5','moc') |
|
14 | 14 | rcc = find_program('rcc-qt5','rcc') |
|
15 | 15 | |
|
16 | 16 | if build_machine.system()=='darwin' |
|
17 | 17 | add_global_link_arguments('-headerpad_max_install_names', language : 'cpp') |
|
18 | 18 | install_data('build_cfg/mac/sciqlopLOGO.icns', install_dir : 'Contents/Resources') |
|
19 | 19 | install_data('build_cfg/mac/Info.plist', install_dir : 'Contents') |
|
20 | 20 | meson.add_install_script('build_cfg/mac/install_script.sh') |
|
21 | 21 | elif host_machine.system()=='windows' |
|
22 | 22 | meson.add_install_script('build_cfg/windows/install_script.sh') |
|
23 | 23 | endif |
|
24 | 24 | |
|
25 | 25 | # Sets AMDA server that will be used during execution. |
|
26 | 26 | # Available values are: |
|
27 | 27 | # - "default": default AMDA server |
|
28 | 28 | # - "amdatest": AMDA test server |
|
29 | # - "hybrid": use both the default server and the test server (the server used is relative to each product, according to its "server" property in the JSON file) | |
|
29 | 30 | # Any other value will lead to the use of the default server |
|
30 |
add_project_arguments('-DSCIQLOP_AMDA_SERVER="d |
|
|
31 | add_project_arguments('-DSCIQLOP_AMDA_SERVER="hybrid"', language : 'cpp') | |
|
31 | 32 | |
|
32 | 33 | subdir('core') |
|
33 | 34 | subdir('gui') |
|
34 | 35 | subdir('app') |
|
35 | 36 | subdir('plugins') |
|
36 | 37 | |
|
37 | 38 | cppcheck = find_program('cppcheck', required : false) |
|
38 | 39 | |
|
39 | 40 | if cppcheck.found() |
|
40 | 41 | run_target('cppcheck', |
|
41 | 42 | command : [cppcheck, '--enable=all', |
|
42 | 43 | '--project=' + join_paths(meson.build_root(), 'compile_commands.json')] |
|
43 | 44 | ) |
|
44 | 45 | endif |
@@ -1,33 +1,35 | |||
|
1 | 1 | #ifndef SCIQLOP_AMDASERVER_H |
|
2 | 2 | #define SCIQLOP_AMDASERVER_H |
|
3 | 3 | |
|
4 | 4 | #include <QLoggingCategory> |
|
5 | 5 | |
|
6 | 6 | #include <memory> |
|
7 | 7 | |
|
8 | 8 | Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaServer) |
|
9 | 9 | |
|
10 | 10 | // Directive used to determine the active AMDA server |
|
11 | 11 | #ifndef SCIQLOP_AMDA_SERVER |
|
12 | 12 | #define SCIQLOP_AMDA_SERVER "default" |
|
13 | 13 | #endif |
|
14 | 14 | |
|
15 | 15 | /** |
|
16 | 16 | * @brief The AmdaServer class represents the server used to retrieve AMDA data (singleton). |
|
17 | 17 | * |
|
18 | 18 | * The server instance is initialized at compile time, as defined by the AMDA_SERVER value. |
|
19 | 19 | */ |
|
20 | 20 | class AmdaServer { |
|
21 | 21 | public: |
|
22 | 22 | /// @return the unique instance of the AMDA server |
|
23 | 23 | static AmdaServer &instance(); |
|
24 | 24 | |
|
25 | 25 | virtual ~AmdaServer() noexcept = default; |
|
26 | 26 | |
|
27 | 27 | /// @return the name of the server |
|
28 | 28 | virtual QString name() const = 0; |
|
29 | ||
|
30 | /// @param properties used to generate url | |
|
29 | 31 | /// @return the url of the server (used to retrieve data) |
|
30 | virtual QString url() const = 0; | |
|
32 | virtual QString url(const QVariantHash &properties = {}) const = 0; | |
|
31 | 33 | }; |
|
32 | 34 | |
|
33 | 35 | #endif // SCIQLOP_AMDASERVER_H |
@@ -1,287 +1,288 | |||
|
1 | 1 | #include "AmdaProvider.h" |
|
2 | 2 | #include "AmdaDefs.h" |
|
3 | 3 | #include "AmdaResultParser.h" |
|
4 | 4 | #include "AmdaServer.h" |
|
5 | 5 | |
|
6 | 6 | #include <Common/DateUtils.h> |
|
7 | 7 | #include <Data/DataProviderParameters.h> |
|
8 | 8 | #include <Network/NetworkController.h> |
|
9 | 9 | #include <SqpApplication.h> |
|
10 | 10 | #include <Variable/Variable.h> |
|
11 | 11 | |
|
12 | 12 | #include <QNetworkAccessManager> |
|
13 | 13 | #include <QNetworkReply> |
|
14 | 14 | #include <QTemporaryFile> |
|
15 | 15 | #include <QThread> |
|
16 | 16 | |
|
17 | 17 | Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") |
|
18 | 18 | |
|
19 | 19 | namespace { |
|
20 | 20 | |
|
21 | 21 | /// URL format for a request on AMDA server. The parameters are as follows: |
|
22 | 22 | /// - %1: server URL |
|
23 | 23 | /// - %2: start date |
|
24 | 24 | /// - %3: end date |
|
25 | 25 | /// - %4: parameter id |
|
26 | 26 | /// AMDA V2: http://amdatest.irap.omp.eu/php/rest/ |
|
27 | 27 | const auto AMDA_URL_FORMAT = QStringLiteral( |
|
28 | 28 | "http://%1/php/rest/" |
|
29 | 29 | "getParameter.php?startTime=%2&stopTime=%3¶meterID=%4&outputFormat=ASCII&" |
|
30 | 30 | "timeFormat=ISO8601&gzip=0"); |
|
31 | 31 | |
|
32 | 32 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) |
|
33 | 33 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); |
|
34 | 34 | |
|
35 | 35 | /// Formats a time to a date that can be passed in URL |
|
36 | 36 | QString dateFormat(double sqpRange) noexcept |
|
37 | 37 | { |
|
38 | 38 | auto dateTime = DateUtils::dateTime(sqpRange); |
|
39 | 39 | return dateTime.toString(AMDA_TIME_FORMAT); |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | AmdaResultParser::ValueType valueType(const QString &valueType) |
|
43 | 43 | { |
|
44 | 44 | if (valueType == QStringLiteral("scalar")) { |
|
45 | 45 | return AmdaResultParser::ValueType::SCALAR; |
|
46 | 46 | } |
|
47 | 47 | else if (valueType == QStringLiteral("spectrogram")) { |
|
48 | 48 | return AmdaResultParser::ValueType::SPECTROGRAM; |
|
49 | 49 | } |
|
50 | 50 | else if (valueType == QStringLiteral("vector")) { |
|
51 | 51 | return AmdaResultParser::ValueType::VECTOR; |
|
52 | 52 | } |
|
53 | 53 | else { |
|
54 | 54 | return AmdaResultParser::ValueType::UNKNOWN; |
|
55 | 55 | } |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | } // namespace |
|
59 | 59 | |
|
60 | 60 | AmdaProvider::AmdaProvider() |
|
61 | 61 | { |
|
62 | 62 | qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread(); |
|
63 | 63 | if (auto app = sqpApp) { |
|
64 | 64 | auto &networkController = app->networkController(); |
|
65 | 65 | connect(this, SIGNAL(requestConstructed(std::shared_ptr<QNetworkRequest>, QUuid, |
|
66 | 66 | std::function<void(QNetworkReply *, QUuid)>)), |
|
67 | 67 | &networkController, |
|
68 | 68 | SLOT(onProcessRequested(std::shared_ptr<QNetworkRequest>, QUuid, |
|
69 | 69 | std::function<void(QNetworkReply *, QUuid)>))); |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | connect(&sqpApp->networkController(), |
|
73 | 73 | SIGNAL(replyDownloadProgress(QUuid, std::shared_ptr<QNetworkRequest>, double)), |
|
74 | 74 | this, |
|
75 | 75 | SLOT(onReplyDownloadProgress(QUuid, std::shared_ptr<QNetworkRequest>, double))); |
|
76 | 76 | } |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | std::shared_ptr<IDataProvider> AmdaProvider::clone() const |
|
80 | 80 | { |
|
81 | 81 | // No copy is made in the clone |
|
82 | 82 | return std::make_shared<AmdaProvider>(); |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) |
|
86 | 86 | { |
|
87 | 87 | // NOTE: Try to use multithread if possible |
|
88 | 88 | const auto times = parameters.m_Times; |
|
89 | 89 | const auto data = parameters.m_Data; |
|
90 | 90 | for (const auto &dateTime : qAsConst(times)) { |
|
91 | 91 | qCDebug(LOG_AmdaProvider()) << tr("TORM AmdaProvider::requestDataLoading ") << acqIdentifier |
|
92 | 92 | << dateTime; |
|
93 | 93 | this->retrieveData(acqIdentifier, dateTime, data); |
|
94 | 94 | |
|
95 | 95 | |
|
96 | 96 | // TORM when AMDA will support quick asynchrone request |
|
97 | 97 | QThread::msleep(1000); |
|
98 | 98 | } |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | void AmdaProvider::requestDataAborting(QUuid acqIdentifier) |
|
102 | 102 | { |
|
103 | 103 | if (auto app = sqpApp) { |
|
104 | 104 | auto &networkController = app->networkController(); |
|
105 | 105 | networkController.onReplyCanceled(acqIdentifier); |
|
106 | 106 | } |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, |
|
110 | 110 | std::shared_ptr<QNetworkRequest> networkRequest, |
|
111 | 111 | double progress) |
|
112 | 112 | { |
|
113 | 113 | qCDebug(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << acqIdentifier |
|
114 | 114 | << networkRequest.get() << progress; |
|
115 | 115 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); |
|
116 | 116 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { |
|
117 | 117 | |
|
118 | 118 | // Update the progression for the current request |
|
119 | 119 | auto requestPtr = networkRequest; |
|
120 | 120 | auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; }; |
|
121 | 121 | |
|
122 | 122 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; |
|
123 | 123 | auto requestProgressMapEnd = requestProgressMap.end(); |
|
124 | 124 | auto requestProgressMapIt |
|
125 | 125 | = std::find_if(requestProgressMap.begin(), requestProgressMapEnd, findRequest); |
|
126 | 126 | |
|
127 | 127 | if (requestProgressMapIt != requestProgressMapEnd) { |
|
128 | 128 | requestProgressMapIt->second = progress; |
|
129 | 129 | } |
|
130 | 130 | else { |
|
131 | 131 | // This case can happened when a progression is send after the request has been |
|
132 | 132 | // finished. |
|
133 | 133 | // Generaly the case when aborting a request |
|
134 | 134 | qCDebug(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") << acqIdentifier |
|
135 | 135 | << networkRequest.get() << progress; |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | // Compute the current final progress and notify it |
|
139 | 139 | double finalProgress = 0.0; |
|
140 | 140 | |
|
141 | 141 | auto fraq = requestProgressMap.size(); |
|
142 | 142 | |
|
143 | 143 | for (auto requestProgress : requestProgressMap) { |
|
144 | 144 | finalProgress += requestProgress.second; |
|
145 | 145 | qCDebug(LOG_AmdaProvider()) << tr("Current final progress without fraq:") |
|
146 | 146 | << finalProgress << requestProgress.second; |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | if (fraq > 0) { |
|
150 | 150 | finalProgress = finalProgress / fraq; |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | qCDebug(LOG_AmdaProvider()) << tr("Current final progress: ") << fraq << finalProgress; |
|
154 | 154 | emit dataProvidedProgress(acqIdentifier, finalProgress); |
|
155 | 155 | } |
|
156 | 156 | else { |
|
157 | 157 | // This case can happened when a progression is send after the request has been finished. |
|
158 | 158 | // Generaly the case when aborting a request |
|
159 | 159 | emit dataProvidedProgress(acqIdentifier, 100.0); |
|
160 | 160 | } |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data) |
|
164 | 164 | { |
|
165 | 165 | // Retrieves product ID from data: if the value is invalid, no request is made |
|
166 | 166 | auto productId = data.value(AMDA_XML_ID_KEY).toString(); |
|
167 | 167 | if (productId.isNull()) { |
|
168 | 168 | qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id"); |
|
169 | 169 | return; |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | // Retrieves the data type that determines whether the expected format for the result file is |
|
173 | 173 | // scalar, vector... |
|
174 | 174 | auto productValueType = valueType(data.value(AMDA_DATA_TYPE_KEY).toString()); |
|
175 | 175 | |
|
176 | 176 | // /////////// // |
|
177 | 177 | // Creates URL // |
|
178 | 178 | // /////////// // |
|
179 | 179 | |
|
180 | 180 | auto startDate = dateFormat(dateTime.m_TStart); |
|
181 | 181 | auto endDate = dateFormat(dateTime.m_TEnd); |
|
182 | 182 | |
|
183 | auto url = QUrl{ | |
|
184 |
|
|
|
183 | QVariantHash urlProperties{{AMDA_SERVER_KEY, data.value(AMDA_SERVER_KEY)}}; | |
|
184 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(AmdaServer::instance().url(urlProperties), | |
|
185 | startDate, endDate, productId)}; | |
|
185 | 186 | qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url; |
|
186 | 187 | auto tempFile = std::make_shared<QTemporaryFile>(); |
|
187 | 188 | |
|
188 | 189 | // LAMBDA |
|
189 | 190 | auto httpDownloadFinished = [this, dateTime, tempFile, |
|
190 | 191 | productValueType](QNetworkReply *reply, QUuid dataId) noexcept { |
|
191 | 192 | |
|
192 | 193 | // Don't do anything if the reply was abort |
|
193 | 194 | if (reply->error() == QNetworkReply::NoError) { |
|
194 | 195 | |
|
195 | 196 | if (tempFile) { |
|
196 | 197 | auto replyReadAll = reply->readAll(); |
|
197 | 198 | if (!replyReadAll.isEmpty()) { |
|
198 | 199 | tempFile->write(replyReadAll); |
|
199 | 200 | } |
|
200 | 201 | tempFile->close(); |
|
201 | 202 | |
|
202 | 203 | // Parse results file |
|
203 | 204 | if (auto dataSeries |
|
204 | 205 | = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) { |
|
205 | 206 | emit dataProvided(dataId, dataSeries, dateTime); |
|
206 | 207 | } |
|
207 | 208 | else { |
|
208 | 209 | /// @todo ALX : debug |
|
209 | 210 | emit dataProvidedFailed(dataId); |
|
210 | 211 | } |
|
211 | 212 | } |
|
212 | 213 | m_AcqIdToRequestProgressMap.erase(dataId); |
|
213 | 214 | } |
|
214 | 215 | else { |
|
215 | 216 | qCCritical(LOG_AmdaProvider()) << tr("httpDownloadFinished ERROR"); |
|
216 | 217 | emit dataProvidedFailed(dataId); |
|
217 | 218 | } |
|
218 | 219 | |
|
219 | 220 | }; |
|
220 | 221 | auto httpFinishedLambda |
|
221 | 222 | = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { |
|
222 | 223 | |
|
223 | 224 | // Don't do anything if the reply was abort |
|
224 | 225 | if (reply->error() == QNetworkReply::NoError) { |
|
225 | 226 | auto downloadFileUrl = QUrl{QString{reply->readAll()}.trimmed()}; |
|
226 | 227 | |
|
227 | 228 | qCInfo(LOG_AmdaProvider()) |
|
228 | 229 | << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; |
|
229 | 230 | // Executes request for downloading file // |
|
230 | 231 | |
|
231 | 232 | // Creates destination file |
|
232 | 233 | if (tempFile->open()) { |
|
233 | 234 | // Executes request and store the request for progression |
|
234 | 235 | auto request = std::make_shared<QNetworkRequest>(downloadFileUrl); |
|
235 | 236 | updateRequestProgress(dataId, request, 0.0); |
|
236 | 237 | emit requestConstructed(request, dataId, httpDownloadFinished); |
|
237 | 238 | } |
|
238 | 239 | else { |
|
239 | 240 | emit dataProvidedFailed(dataId); |
|
240 | 241 | } |
|
241 | 242 | } |
|
242 | 243 | else { |
|
243 | 244 | qCCritical(LOG_AmdaProvider()) << tr("httpFinishedLambda ERROR"); |
|
244 | 245 | m_AcqIdToRequestProgressMap.erase(dataId); |
|
245 | 246 | emit dataProvidedFailed(dataId); |
|
246 | 247 | } |
|
247 | 248 | }; |
|
248 | 249 | |
|
249 | 250 | // //////////////// // |
|
250 | 251 | // Executes request // |
|
251 | 252 | // //////////////// // |
|
252 | 253 | |
|
253 | 254 | auto request = std::make_shared<QNetworkRequest>(url); |
|
254 | 255 | qCDebug(LOG_AmdaProvider()) << tr("First Request creation") << request.get(); |
|
255 | 256 | updateRequestProgress(token, request, 0.0); |
|
256 | 257 | |
|
257 | 258 | emit requestConstructed(request, token, httpFinishedLambda); |
|
258 | 259 | } |
|
259 | 260 | |
|
260 | 261 | void AmdaProvider::updateRequestProgress(QUuid acqIdentifier, |
|
261 | 262 | std::shared_ptr<QNetworkRequest> request, double progress) |
|
262 | 263 | { |
|
263 | 264 | qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress request") << request.get(); |
|
264 | 265 | auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); |
|
265 | 266 | if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { |
|
266 | 267 | auto &requestProgressMap = acqIdToRequestProgressMapIt->second; |
|
267 | 268 | auto requestProgressMapIt = requestProgressMap.find(request); |
|
268 | 269 | if (requestProgressMapIt != requestProgressMap.end()) { |
|
269 | 270 | requestProgressMapIt->second = progress; |
|
270 | 271 | qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new progress for request") |
|
271 | 272 | << acqIdentifier << request.get() << progress; |
|
272 | 273 | } |
|
273 | 274 | else { |
|
274 | 275 | qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new request") << acqIdentifier |
|
275 | 276 | << request.get() << progress; |
|
276 | 277 | acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress)); |
|
277 | 278 | } |
|
278 | 279 | } |
|
279 | 280 | else { |
|
280 | 281 | qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new acqIdentifier") |
|
281 | 282 | << acqIdentifier << request.get() << progress; |
|
282 | 283 | auto requestProgressMap = std::map<std::shared_ptr<QNetworkRequest>, double>{}; |
|
283 | 284 | requestProgressMap.insert(std::make_pair(request, progress)); |
|
284 | 285 | m_AcqIdToRequestProgressMap.insert( |
|
285 | 286 | std::make_pair(acqIdentifier, std::move(requestProgressMap))); |
|
286 | 287 | } |
|
287 | 288 | } |
@@ -1,45 +1,78 | |||
|
1 | 1 | #include "AmdaServer.h" |
|
2 | 2 | |
|
3 | #include "AmdaDefs.h" | |
|
4 | ||
|
3 | 5 | Q_LOGGING_CATEGORY(LOG_AmdaServer, "AmdaServer") |
|
4 | 6 | |
|
5 | 7 | namespace { |
|
6 | 8 | |
|
9 | /// URL of the default AMDA server | |
|
10 | const auto AMDA_DEFAULT_SERVER_URL = QStringLiteral("amda.irap.omp.eu"); | |
|
11 | ||
|
12 | /// URL of the AMDA test server | |
|
13 | const auto AMDA_TEST_SERVER_URL = QStringLiteral("amdatest.irap.omp.eu"); | |
|
14 | ||
|
7 | 15 | /// Default AMDA server |
|
8 | 16 | struct AmdaDefaultServer : public AmdaServer { |
|
9 | 17 | public: |
|
10 | 18 | QString name() const override { return QStringLiteral("AMDA (default)"); } |
|
11 | QString url() const override { return QStringLiteral("amda.irap.omp.eu"); } | |
|
19 | QString url(const QVariantHash &properties) const override | |
|
20 | { | |
|
21 | Q_UNUSED(properties); | |
|
22 | return AMDA_DEFAULT_SERVER_URL; | |
|
23 | } | |
|
12 | 24 | }; |
|
13 | 25 | |
|
14 | 26 | /// Alternative AMDA server (tests) |
|
15 | 27 | struct AmdaTestServer : public AmdaServer { |
|
16 | 28 | public: |
|
17 | 29 | QString name() const override { return QStringLiteral("AMDA (test)"); } |
|
18 | QString url() const override { return QStringLiteral("amdatest.irap.omp.eu"); } | |
|
30 | QString url(const QVariantHash &properties) const override | |
|
31 | { | |
|
32 | Q_UNUSED(properties); | |
|
33 | return AMDA_TEST_SERVER_URL; | |
|
34 | } | |
|
35 | }; | |
|
36 | ||
|
37 | /// Hybrid AMDA server: use both of default and test server. | |
|
38 | /// The server used is relative to each product for which to retrieve url, according to its "server" | |
|
39 | /// property | |
|
40 | struct AmdaHybridServer : public AmdaServer { | |
|
41 | public: | |
|
42 | QString name() const override { return QStringLiteral("AMDA (hybrid)"); } | |
|
43 | QString url(const QVariantHash &properties) const override | |
|
44 | { | |
|
45 | // Reads "server" property to determine which server url to use | |
|
46 | auto server = properties.value(AMDA_SERVER_KEY).toString(); | |
|
47 | return server == QString{"amdatest"} ? AMDA_TEST_SERVER_URL : AMDA_DEFAULT_SERVER_URL; | |
|
48 | } | |
|
19 | 49 | }; |
|
20 | 50 | |
|
21 | 51 | /// @return an AMDA server instance created from the name of the server passed in parameter. If the |
|
22 | 52 | /// name does not match any known server, a default server instance is created |
|
23 | 53 | std::unique_ptr<AmdaServer> createInstance(const QString &server) |
|
24 | 54 | { |
|
25 | 55 | if (server == QString{"amdatest"}) { |
|
26 | 56 | return std::make_unique<AmdaTestServer>(); |
|
27 | 57 | } |
|
58 | else if (server == QString{"hybrid"}) { | |
|
59 | return std::make_unique<AmdaHybridServer>(); | |
|
60 | } | |
|
28 | 61 | else { |
|
29 | 62 | if (server != QString{"default"}) { |
|
30 | 63 | qCWarning(LOG_AmdaServer()) |
|
31 | 64 | << QObject::tr("Unknown server '%1': default AMDA server will be used").arg(server); |
|
32 | 65 | } |
|
33 | 66 | |
|
34 | 67 | return std::make_unique<AmdaDefaultServer>(); |
|
35 | 68 | } |
|
36 | 69 | } |
|
37 | 70 | |
|
38 | 71 | } // namespace |
|
39 | 72 | |
|
40 | 73 | AmdaServer &AmdaServer::instance() |
|
41 | 74 | { |
|
42 | 75 | // Creates instance depending on the SCIQLOP_AMDA_SERVER value at compile time |
|
43 | 76 | static auto instance = createInstance(SCIQLOP_AMDA_SERVER); |
|
44 | 77 | return *instance; |
|
45 | 78 | } |
General Comments 0
You need to be logged in to leave comments.
Login now