From be36d883265c4b2ca221979f792731c788723b19 2017-07-10 08:19:32 From: perrinel Date: 2017-07-10 08:19:32 Subject: [PATCH] Merge pull request #180 from SCIQLOP-Initialisation develop Develop --- diff --git a/app/ui/MainWindow.ui b/app/ui/MainWindow.ui index 30bc87a..44aecb5 100644 --- a/app/ui/MainWindow.ui +++ b/app/ui/MainWindow.ui @@ -11,7 +11,7 @@ - QLop + SciQlop v0.0.1 true @@ -126,7 +126,7 @@ 0 0 800 - 26 + 28 diff --git a/core/include/Data/IDataProvider.h b/core/include/Data/IDataProvider.h index 6f4b5b6..59799d2 100644 --- a/core/include/Data/IDataProvider.h +++ b/core/include/Data/IDataProvider.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -26,14 +27,11 @@ class IDataProvider : public QObject { public: virtual ~IDataProvider() noexcept = default; - virtual std::shared_ptr - retrieveData(const DataProviderParameters ¶meters) const = 0; - - - virtual void requestDataLoading(const QVector &dateTimeList) = 0; + virtual void requestDataLoading(QUuid token, const QVector &dateTimeList) = 0; signals: - void dataProvided(std::shared_ptr dateSerie, const SqpDateTime &dateTime); + void dataProvided(QUuid token, std::shared_ptr dateSerie, + const SqpDateTime &dateTime); }; // Required for using shared_ptr in signals/slots diff --git a/core/include/Network/NetworkController.h b/core/include/Network/NetworkController.h new file mode 100644 index 0000000..0e36901 --- /dev/null +++ b/core/include/Network/NetworkController.h @@ -0,0 +1,30 @@ +#ifndef SCIQLOP_NETWORKCONTROLLER_H +#define SCIQLOP_NETWORKCONTROLLER_H + +#include +#include + +#include + +Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController) + +/** + * @brief The NetworkController class aims to handle all network connection of SciQlop. + */ +class NetworkController : public QObject { + Q_OBJECT +public: + explicit NetworkController(QObject *parent = 0); + + + void initialize(); + void finalize(); + +private: + void waitForFinish(); + + class NetworkControllerPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_NETWORKCONTROLLER_H diff --git a/core/src/Network/NetworkController.cpp b/core/src/Network/NetworkController.cpp new file mode 100644 index 0000000..e015af4 --- /dev/null +++ b/core/src/Network/NetworkController.cpp @@ -0,0 +1,33 @@ +#include "Network/NetworkController.h" + +#include +#include + +Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController") + +struct NetworkController::NetworkControllerPrivate { + explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {} + QMutex m_WorkingMutex; +}; + +NetworkController::NetworkController(QObject *parent) + : QObject(parent), impl{spimpl::make_unique_impl(this)} +{ +} + +void NetworkController::initialize() +{ + qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread(); + impl->m_WorkingMutex.lock(); + qCDebug(LOG_NetworkController()) << tr("NetworkController init END"); +} + +void NetworkController::finalize() +{ + impl->m_WorkingMutex.unlock(); +} + +void NetworkController::waitForFinish() +{ + QMutexLocker locker{&impl->m_WorkingMutex}; +} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 0e58f7e..24bebc2 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -11,26 +11,13 @@ #include #include #include +#include #include #include Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") -namespace { - -/// @todo Generates default dataseries, according to the provider passed in parameter. This method -/// will be deleted when the timerange is recovered from SciQlop -std::shared_ptr generateDefaultDataSeries(const IDataProvider &provider, - const SqpDateTime &dateTime) noexcept -{ - auto parameters = DataProviderParameters{dateTime}; - - return provider.retrieveData(parameters); -} - -} // namespace - struct VariableController::VariableControllerPrivate { explicit VariableControllerPrivate(VariableController *parent) : m_WorkingMutex{}, @@ -51,6 +38,7 @@ struct VariableController::VariableControllerPrivate { std::unordered_map, std::shared_ptr > m_VariableToProviderMap; + std::unordered_map, QUuid> m_VariableToToken; }; VariableController::VariableController(QObject *parent) @@ -132,16 +120,21 @@ void VariableController::createVariable(const QString &name, /// in sciqlop auto dateTime = impl->m_TimeController->dateTime(); if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { + auto token = QUuid::createUuid(); // store the provider impl->m_VariableToProviderMap[newVariable] = provider; + impl->m_VariableToToken[newVariable] = token; auto addDateTimeAcquired = [ this, varW = std::weak_ptr{newVariable} ]( - auto dataSeriesAcquired, auto dateTimeToPutInCache) + QUuid token, auto dataSeriesAcquired, auto dateTimeToPutInCache) { if (auto variable = varW.lock()) { - impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); - variable->setDataSeries(dataSeriesAcquired); + auto varToken = impl->m_VariableToToken.at(variable); + if (varToken == token) { + impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); + variable->setDataSeries(dataSeriesAcquired); + } } }; @@ -180,8 +173,9 @@ void VariableController::onRequestDataLoading(std::shared_ptr variable if (!dateTimeListNotInCache.empty()) { // Ask the provider for each data on the dateTimeListNotInCache + auto token = impl->m_VariableToToken.at(variable); impl->m_VariableToProviderMap.at(variable)->requestDataLoading( - std::move(dateTimeListNotInCache)); + token, std::move(dateTimeListNotInCache)); } else { emit variable->updated(); diff --git a/gui/include/SqpApplication.h b/gui/include/SqpApplication.h index 87bc813..a23bd7f 100644 --- a/gui/include/SqpApplication.h +++ b/gui/include/SqpApplication.h @@ -16,6 +16,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication) #define sqpApp (static_cast(QCoreApplication::instance())) class DataSourceController; +class NetworkController; class TimeController; class VariableController; class VisualizationController; @@ -38,6 +39,7 @@ public: /// Accessors for the differents sciqlop controllers DataSourceController &dataSourceController() noexcept; + NetworkController &networkController() noexcept; TimeController &timeController() noexcept; VariableController &variableController() noexcept; VisualizationController &visualizationController() noexcept; diff --git a/gui/src/SqpApplication.cpp b/gui/src/SqpApplication.cpp index c79f0f7..a50fa86 100644 --- a/gui/src/SqpApplication.cpp +++ b/gui/src/SqpApplication.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include