From 34234d13df5c44de44a924cd7ceff3c598e846e5 2017-09-21 08:57:56 From: mperrinel Date: 2017-09-21 08:57:56 Subject: [PATCH] request is now passed by shared pointer instead of const & --- diff --git a/core/include/Data/IDataProvider.h b/core/include/Data/IDataProvider.h index 55dd069..e84b974 100644 --- a/core/include/Data/IDataProvider.h +++ b/core/include/Data/IDataProvider.h @@ -65,7 +65,7 @@ signals: * @brief requestConstructed send a request for the data identified by acqIdentifier * @callback is the methode call by the reply of the request when it is finished. */ - void requestConstructed(const QNetworkRequest &request, QUuid acqIdentifier, + void requestConstructed(std::shared_ptr request, QUuid acqIdentifier, std::function callback); }; diff --git a/core/include/Network/NetworkController.h b/core/include/Network/NetworkController.h index 12b122c..da3a2c5 100644 --- a/core/include/Network/NetworkController.h +++ b/core/include/Network/NetworkController.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -29,14 +30,14 @@ public: public slots: /// Execute request and call callback when the reply is finished. Identifier is attached to the /// callback - void onProcessRequested(const QNetworkRequest &request, QUuid identifier, + void onProcessRequested(std::shared_ptr request, QUuid identifier, std::function callback); /// Cancel the request of identifier void onReplyCanceled(QUuid identifier); signals: void replyFinished(QNetworkReply *reply, QUuid identifier); - void replyDownloadProgress(QUuid identifier, const QNetworkRequest &networkRequest, + void replyDownloadProgress(QUuid identifier, std::shared_ptr networkRequest, double progress); private: @@ -46,4 +47,7 @@ private: spimpl::unique_impl_ptr impl; }; +SCIQLOP_REGISTER_META_TYPE(NETWORKREQUEST_REGISTRY, std::shared_ptr) + + #endif // SCIQLOP_NETWORKCONTROLLER_H diff --git a/core/src/Network/NetworkController.cpp b/core/src/Network/NetworkController.cpp index 0433ef9..fc9ff99 100644 --- a/core/src/Network/NetworkController.cpp +++ b/core/src/Network/NetworkController.cpp @@ -30,12 +30,13 @@ NetworkController::NetworkController(QObject *parent) { } -void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier, +void NetworkController::onProcessRequested(std::shared_ptr request, + QUuid identifier, std::function callback) { - qCDebug(LOG_NetworkController()) << tr("NetworkController registered") - << QThread::currentThread()->objectName(); - auto reply = impl->m_AccessManager->get(request); + qCDebug(LOG_NetworkController()) << tr("NetworkController onProcessRequested") + << QThread::currentThread()->objectName() << &request; + auto reply = impl->m_AccessManager->get(*request); // Store the couple reply id impl->lockWrite(); @@ -45,7 +46,7 @@ void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid auto onReplyFinished = [request, reply, this, identifier, callback]() { qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished") - << QThread::currentThread() << reply; + << QThread::currentThread() << request.get() << reply; impl->lockRead(); auto it = impl->m_NetworkReplyToVariableId.find(reply); impl->unlock(); @@ -56,8 +57,6 @@ void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid // Deletes reply callback(reply, identifier); reply->deleteLater(); - - emit this->replyDownloadProgress(identifier, request, 0); } qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END") @@ -68,7 +67,7 @@ void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid double progress = (bytesRead * 100.0) / totalBytes; qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress - << QThread::currentThread() << reply; + << QThread::currentThread() << request.get() << reply; impl->lockRead(); auto it = impl->m_NetworkReplyToVariableId.find(reply); impl->unlock(); diff --git a/core/src/Variable/VariableAcquisitionWorker.cpp b/core/src/Variable/VariableAcquisitionWorker.cpp index 3b66edd..5a3299b 100644 --- a/core/src/Variable/VariableAcquisitionWorker.cpp +++ b/core/src/Variable/VariableAcquisitionWorker.cpp @@ -117,20 +117,6 @@ void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdenti = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0; auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize; - qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: progress :") << progress; - qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress A:") - << aIdToARit->second.m_Progression - << aIdToARit->second.m_Size; - qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress B:") - << currentPartSize; - qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress C:") - << currentPartProgress; - qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress D:") - << currentAlreadyProgress; - qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress E:") - << currentAlreadyProgress + currentPartProgress - << "\n"; - auto finalProgression = currentAlreadyProgress + currentPartProgress; emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); @@ -145,8 +131,8 @@ void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr dataSeries, SqpRange dataRangeAcquired) { - qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ") - << acqIdentifier << dataRangeAcquired; + qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableDataAcquired on range ") + << acqIdentifier << dataRangeAcquired; impl->lockWrite(); auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { @@ -269,19 +255,3 @@ void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier); unlock(); } - -//void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) -//{ -// qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); -// impl->lockRead(); -// auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); -// if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { -// auto request = it->second; -// impl->unlock(); -// request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); -// } -// else { -// impl->unlock(); -// // TODO log no acqIdentifier recognized -// } -//} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 8565411..2510e13 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -322,8 +322,9 @@ void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) { - qCInfo(LOG_VariableController()) << "TORM: ariableController::onVariableRetrieveDataInProgress" - << QThread::currentThread()->objectName() << progress; + qCDebug(LOG_VariableController()) + << "TORM: variableController::onVariableRetrieveDataInProgress" + << QThread::currentThread()->objectName() << progress; if (auto var = impl->findVariable(identifier)) { impl->m_VariableModel->setDataProgress(var, progress); }