@@ -0,0 +1,68 | |||||
|
1 | #ifndef SCIQLOP_VARIABLESYNCHRONIZER_H | |||
|
2 | #define SCIQLOP_VARIABLESYNCHRONIZER_H | |||
|
3 | ||||
|
4 | #include "CoreGlobal.h" | |||
|
5 | ||||
|
6 | #include <Common/spimpl.h> | |||
|
7 | ||||
|
8 | #include <QLoggingCategory> | |||
|
9 | #include <QUuid> | |||
|
10 | ||||
|
11 | #include <memory> | |||
|
12 | #include <set> | |||
|
13 | ||||
|
14 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableSynchronizer) | |||
|
15 | ||||
|
16 | class Variable; | |||
|
17 | ||||
|
18 | /** | |||
|
19 | * @brief The VariableAcquisitionWorker class handles synchronization between variables | |||
|
20 | */ | |||
|
21 | class SCIQLOP_CORE_EXPORT VariableSynchronizer : public QObject { | |||
|
22 | Q_OBJECT | |||
|
23 | public: | |||
|
24 | using GroupId = QUuid; | |||
|
25 | ||||
|
26 | explicit VariableSynchronizer(QObject *parent = 0); | |||
|
27 | ||||
|
28 | /** | |||
|
29 | * Adds a synchronization group under the identifier passed as a parameter. If a group with this | |||
|
30 | * identifier already exists, the method does nothing. | |||
|
31 | * @param groupId the group identifier | |||
|
32 | */ | |||
|
33 | void addGroup(GroupId groupId) noexcept; | |||
|
34 | ||||
|
35 | /** | |||
|
36 | * Adds a variable to a synchronization group. If the variable is already registered under | |||
|
37 | * another group, or the synchronization doesn't exist, the method does nothing | |||
|
38 | * @param variable the variable to synchronize | |||
|
39 | * @param groupId the synchronization group identifier | |||
|
40 | */ | |||
|
41 | void addVariable(std::shared_ptr<Variable> variable, GroupId groupId) noexcept; | |||
|
42 | ||||
|
43 | /** | |||
|
44 | * Removes the synchronization group under the identifier passed as a parameter. If no group | |||
|
45 | * exists with this identifier, the method does nothing. | |||
|
46 | * @param groupId the group identifier | |||
|
47 | */ | |||
|
48 | void removeGroup(GroupId groupId) noexcept; | |||
|
49 | ||||
|
50 | /** | |||
|
51 | * Removes a variable from a synchronization group. If the synchronization group doesn't exist | |||
|
52 | * or if the variable isn't in it, the method does nothing | |||
|
53 | * @param variable the variable to desynchronize | |||
|
54 | * @param groupId the synchronization group identifier | |||
|
55 | */ | |||
|
56 | void removeVariable(std::shared_ptr<Variable> variable, GroupId groupId) noexcept; | |||
|
57 | ||||
|
58 | /// @return the variables in the same group than the variable passed as a parameter (including | |||
|
59 | /// the variable) | |||
|
60 | std::set<std::shared_ptr<Variable> > | |||
|
61 | synchronizedVariables(std::shared_ptr<Variable> variable) const noexcept; | |||
|
62 | ||||
|
63 | private: | |||
|
64 | class VariableSynchronizerPrivate; | |||
|
65 | spimpl::unique_impl_ptr<VariableSynchronizerPrivate> impl; | |||
|
66 | }; | |||
|
67 | ||||
|
68 | #endif // SCIQLOP_VARIABLESYNCHRONIZER_H |
@@ -0,0 +1,105 | |||||
|
1 | #include "Variable/VariableSynchronizer.h" | |||
|
2 | ||||
|
3 | #include "Variable/Variable.h" | |||
|
4 | ||||
|
5 | Q_LOGGING_CATEGORY(LOG_VariableSynchronizer, "VariableSynchronizer") | |||
|
6 | ||||
|
7 | namespace { | |||
|
8 | ||||
|
9 | using GroupId = VariableSynchronizer::GroupId; | |||
|
10 | using Group = std::set<std::shared_ptr<Variable> >; | |||
|
11 | ||||
|
12 | } // namespace | |||
|
13 | ||||
|
14 | struct VariableSynchronizer::VariableSynchronizerPrivate { | |||
|
15 | std::map<GroupId, Group> m_Groups; | |||
|
16 | std::map<std::shared_ptr<Variable>, Group *> m_GroupsIndex; | |||
|
17 | }; | |||
|
18 | ||||
|
19 | VariableSynchronizer::VariableSynchronizer(QObject *parent) | |||
|
20 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableSynchronizerPrivate>()} | |||
|
21 | { | |||
|
22 | } | |||
|
23 | ||||
|
24 | void VariableSynchronizer::addGroup(GroupId groupId) noexcept | |||
|
25 | { | |||
|
26 | if (impl->m_Groups.count(groupId) == 1) { | |||
|
27 | qCWarning(LOG_VariableSynchronizer()) | |||
|
28 | << tr("Can't create new synchronization group: a " | |||
|
29 | "group already exists under the passed identifier"); | |||
|
30 | return; | |||
|
31 | } | |||
|
32 | ||||
|
33 | impl->m_Groups.insert(std::make_pair(groupId, Group{})); | |||
|
34 | } | |||
|
35 | ||||
|
36 | void VariableSynchronizer::addVariable(std::shared_ptr<Variable> variable, GroupId groupId) noexcept | |||
|
37 | { | |||
|
38 | if (impl->m_GroupsIndex.count(variable) == 1) { | |||
|
39 | qCWarning(LOG_VariableSynchronizer()) | |||
|
40 | << tr("Can't add variable to a new synchronization group: the variable is already in a " | |||
|
41 | "synchronization group"); | |||
|
42 | return; | |||
|
43 | } | |||
|
44 | ||||
|
45 | auto groupIt = impl->m_Groups.find(groupId); | |||
|
46 | ||||
|
47 | if (groupIt == impl->m_Groups.end()) { | |||
|
48 | qCWarning(LOG_VariableSynchronizer()) | |||
|
49 | << tr("Can't add variable to the synchronization group: no group exists under the " | |||
|
50 | "passed identifier"); | |||
|
51 | return; | |||
|
52 | } | |||
|
53 | ||||
|
54 | // Registers variable | |||
|
55 | groupIt->second.insert(variable); | |||
|
56 | ||||
|
57 | // Creates index for variable | |||
|
58 | impl->m_GroupsIndex.insert(std::make_pair(variable, &groupIt->second)); | |||
|
59 | } | |||
|
60 | ||||
|
61 | void VariableSynchronizer::removeGroup(GroupId groupId) noexcept | |||
|
62 | { | |||
|
63 | auto groupIt = impl->m_Groups.find(groupId); | |||
|
64 | ||||
|
65 | if (groupIt == impl->m_Groups.end()) { | |||
|
66 | qCWarning(LOG_VariableSynchronizer()) << tr( | |||
|
67 | "Can't remove synchronization group: no group exists under the passed identifier"); | |||
|
68 | return; | |||
|
69 | } | |||
|
70 | ||||
|
71 | // Removes indexes | |||
|
72 | for (const auto &variable : groupIt->second) { | |||
|
73 | impl->m_GroupsIndex.erase(variable); | |||
|
74 | } | |||
|
75 | ||||
|
76 | // Removes group | |||
|
77 | impl->m_Groups.erase(groupIt); | |||
|
78 | } | |||
|
79 | ||||
|
80 | void VariableSynchronizer::removeVariable(std::shared_ptr<Variable> variable, | |||
|
81 | GroupId groupId) noexcept | |||
|
82 | { | |||
|
83 | auto groupIt = impl->m_Groups.find(groupId); | |||
|
84 | ||||
|
85 | if (groupIt == impl->m_Groups.end()) { | |||
|
86 | qCWarning(LOG_VariableSynchronizer()) | |||
|
87 | << tr("Can't remove variable from synchronization group: no group exists under the " | |||
|
88 | "passed identifier"); | |||
|
89 | return; | |||
|
90 | } | |||
|
91 | ||||
|
92 | // Removes variable index | |||
|
93 | impl->m_GroupsIndex.erase(variable); | |||
|
94 | ||||
|
95 | // Removes variable from group | |||
|
96 | groupIt->second.erase(variable); | |||
|
97 | } | |||
|
98 | ||||
|
99 | std::set<std::shared_ptr<Variable> > | |||
|
100 | VariableSynchronizer::synchronizedVariables(std::shared_ptr<Variable> variable) const noexcept | |||
|
101 | { | |||
|
102 | auto groupIndexIt = impl->m_GroupsIndex.find(variable); | |||
|
103 | return groupIndexIt != impl->m_GroupsIndex.end() ? *groupIndexIt->second | |||
|
104 | : std::set<std::shared_ptr<Variable> >{}; | |||
|
105 | } |
@@ -1,88 +1,86 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the QLop Software |
|
2 | -- This file is a part of the QLop Software | |
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include "MainWindow.h" |
|
22 | #include "MainWindow.h" | |
23 | #include <QProcessEnvironment> |
|
23 | #include <QProcessEnvironment> | |
24 | #include <QThread> |
|
24 | #include <QThread> | |
25 | #include <SqpApplication.h> |
|
25 | #include <SqpApplication.h> | |
26 | #include <qglobal.h> |
|
26 | #include <qglobal.h> | |
27 |
|
27 | |||
28 | #include <Plugin/PluginManager.h> |
|
28 | #include <Plugin/PluginManager.h> | |
29 | #include <QDir> |
|
29 | #include <QDir> | |
30 |
|
30 | |||
31 | #include <QLoggingCategory> |
|
31 | #include <QLoggingCategory> | |
32 |
|
32 | |||
33 | Q_LOGGING_CATEGORY(LOG_Main, "Main") |
|
33 | Q_LOGGING_CATEGORY(LOG_Main, "Main") | |
34 |
|
34 | |||
35 | namespace { |
|
35 | namespace { | |
36 |
|
36 | |||
37 | const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); |
|
37 | const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | } // namespace |
|
40 | } // namespace | |
41 |
|
41 | |||
42 | int main(int argc, char *argv[]) |
|
42 | int main(int argc, char *argv[]) | |
43 | { |
|
43 | { | |
44 |
|
|
44 | QLoggingCategory::setFilterRules( | |
45 |
|
|
45 | "*.warning=false\n" | |
46 |
|
|
46 | "*.info=false\n" | |
47 |
|
|
47 | "*.debug=false\n" | |
48 |
|
|
48 | "VariableController.info=true\n"); | |
49 | // "NetworkController.info=true\n" |
|
|||
50 | // "VariableAcquisitionWorker.info=true\n"); |
|
|||
51 |
|
49 | |||
52 | SqpApplication a{argc, argv}; |
|
50 | SqpApplication a{argc, argv}; | |
53 | SqpApplication::setOrganizationName("LPP"); |
|
51 | SqpApplication::setOrganizationName("LPP"); | |
54 | SqpApplication::setOrganizationDomain("lpp.fr"); |
|
52 | SqpApplication::setOrganizationDomain("lpp.fr"); | |
55 | SqpApplication::setApplicationName("SciQLop"); |
|
53 | SqpApplication::setApplicationName("SciQLop"); | |
56 | MainWindow w; |
|
54 | MainWindow w; | |
57 | w.show(); |
|
55 | w.show(); | |
58 |
|
56 | |||
59 | // Loads plugins |
|
57 | // Loads plugins | |
60 | auto pluginDir = QDir{a.applicationDirPath()}; |
|
58 | auto pluginDir = QDir{a.applicationDirPath()}; | |
61 | auto pluginLookupPath = { |
|
59 | auto pluginLookupPath = { | |
62 | a.applicationDirPath(), |
|
60 | a.applicationDirPath(), | |
63 | a.applicationDirPath() + "/" + PLUGIN_DIRECTORY_NAME, |
|
61 | a.applicationDirPath() + "/" + PLUGIN_DIRECTORY_NAME, | |
64 | a.applicationDirPath() + "/../lib64/SciQlop", |
|
62 | a.applicationDirPath() + "/../lib64/SciQlop", | |
65 | a.applicationDirPath() + "/../lib64/sciqlop", |
|
63 | a.applicationDirPath() + "/../lib64/sciqlop", | |
66 | a.applicationDirPath() + "/../lib/SciQlop", |
|
64 | a.applicationDirPath() + "/../lib/SciQlop", | |
67 | a.applicationDirPath() + "/../lib/sciqlop", |
|
65 | a.applicationDirPath() + "/../lib/sciqlop", | |
68 | a.applicationDirPath() + "/../plugins", |
|
66 | a.applicationDirPath() + "/../plugins", | |
69 | }; |
|
67 | }; | |
70 |
|
68 | |||
71 | #if _WIN32 || _WIN64 |
|
69 | #if _WIN32 || _WIN64 | |
72 | pluginDir.mkdir(PLUGIN_DIRECTORY_NAME); |
|
70 | pluginDir.mkdir(PLUGIN_DIRECTORY_NAME); | |
73 | pluginDir.cd(PLUGIN_DIRECTORY_NAME); |
|
71 | pluginDir.cd(PLUGIN_DIRECTORY_NAME); | |
74 | #endif |
|
72 | #endif | |
75 |
|
73 | |||
76 | PluginManager pluginManager{}; |
|
74 | PluginManager pluginManager{}; | |
77 |
|
75 | |||
78 | for (auto &&path : pluginLookupPath) { |
|
76 | for (auto &&path : pluginLookupPath) { | |
79 | QDir directory{path}; |
|
77 | QDir directory{path}; | |
80 | if (directory.exists()) { |
|
78 | if (directory.exists()) { | |
81 | qCDebug(LOG_Main()) |
|
79 | qCDebug(LOG_Main()) | |
82 | << QObject::tr("Plugin directory: %1").arg(directory.absolutePath()); |
|
80 | << QObject::tr("Plugin directory: %1").arg(directory.absolutePath()); | |
83 | pluginManager.loadPlugins(directory); |
|
81 | pluginManager.loadPlugins(directory); | |
84 | } |
|
82 | } | |
85 | } |
|
83 | } | |
86 |
|
84 | |||
87 | return a.exec(); |
|
85 | return a.exec(); | |
88 | } |
|
86 | } |
@@ -1,40 +1,40 | |||||
1 | #ifndef SCIQLOP_ACQUISITIONREQUEST_H |
|
1 | #ifndef SCIQLOP_ACQUISITIONREQUEST_H | |
2 | #define SCIQLOP_ACQUISITIONREQUEST_H |
|
2 | #define SCIQLOP_ACQUISITIONREQUEST_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 |
|
5 | |||
6 | #include <QUuid> |
|
6 | #include <QUuid> | |
7 |
|
7 | |||
8 | #include <Common/DateUtils.h> |
|
8 | #include <Common/DateUtils.h> | |
9 | #include <Common/MetaTypes.h> |
|
9 | #include <Common/MetaTypes.h> | |
10 | #include <Data/AcquisitionDataPacket.h> |
|
10 | #include <Data/AcquisitionDataPacket.h> | |
11 | #include <Data/DataProviderParameters.h> |
|
11 | #include <Data/DataProviderParameters.h> | |
12 | #include <Data/IDataProvider.h> |
|
12 | #include <Data/IDataProvider.h> | |
13 | #include <Data/SqpRange.h> |
|
13 | #include <Data/SqpRange.h> | |
14 |
|
14 | |||
15 | #include <memory> |
|
15 | #include <memory> | |
16 |
|
16 | |||
17 | /** |
|
17 | /** | |
18 | * @brief The AcquisitionRequest struct holds the information of an variable request |
|
18 | * @brief The AcquisitionRequest struct holds the information of an variable request | |
19 | */ |
|
19 | */ | |
20 |
struct Acquisition |
|
20 | struct Acquisition { | |
21 |
Acquisition |
|
21 | Acquisition() | |
22 | { |
|
22 | { | |
23 | m_AcqIdentifier = QUuid::createUuid(); |
|
23 | m_AcqIdentifier = QUuid::createUuid(); | |
24 | m_Size = 0; |
|
24 | m_Size = 0; | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | QUuid m_VarRequestId; |
|
27 | QUuid m_VarRequestId; | |
28 | QUuid m_AcqIdentifier; |
|
28 | QUuid m_AcqIdentifier; | |
29 | QUuid m_vIdentifier; |
|
29 | QUuid m_vIdentifier; | |
30 | DataProviderParameters m_DataProviderParameters; |
|
30 | DataProviderParameters m_DataProviderParameters; | |
31 | SqpRange m_RangeRequested; |
|
31 | SqpRange m_RangeRequested; | |
32 | SqpRange m_CacheRangeRequested; |
|
32 | SqpRange m_CacheRangeRequested; | |
33 | int m_Size; |
|
33 | int m_Size; | |
34 | std::shared_ptr<IDataProvider> m_Provider; |
|
34 | std::shared_ptr<IDataProvider> m_Provider; | |
35 | QVector<AcquisitionDataPacket> m_DataPackets; |
|
35 | QVector<AcquisitionDataPacket> m_DataPackets; | |
36 | }; |
|
36 | }; | |
37 |
|
37 | |||
38 | SCIQLOP_REGISTER_META_TYPE(ACQUISITIONREQUEST_REGISTRY, AcquisitionRequest) |
|
38 | SCIQLOP_REGISTER_META_TYPE(ACQUISITIONREQUEST_REGISTRY, AcquisitionRequest) | |
39 |
|
39 | |||
40 | #endif // SCIQLOP_ACQUISITIONREQUEST_H |
|
40 | #endif // SCIQLOP_ACQUISITIONREQUEST_H |
@@ -1,26 +1,49 | |||||
1 | #ifndef SCIQLOP_VARIABLEREQUEST_H |
|
1 | #ifndef SCIQLOP_VARIABLEREQUEST_H | |
2 | #define SCIQLOP_VARIABLEREQUEST_H |
|
2 | #define SCIQLOP_VARIABLEREQUEST_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 |
|
5 | |||
6 | #include <QUuid> |
|
6 | #include <QUuid> | |
7 |
|
7 | |||
8 | #include <Common/MetaTypes.h> |
|
8 | #include <Common/MetaTypes.h> | |
|
9 | #include <Data/DataProviderParameters.h> | |||
9 | #include <Data/IDataSeries.h> |
|
10 | #include <Data/IDataSeries.h> | |
10 | #include <Data/SqpRange.h> |
|
11 | #include <Data/SqpRange.h> | |
11 |
|
12 | |||
12 | #include <memory> |
|
13 | #include <memory> | |
13 |
|
14 | |||
|
15 | class DataProviderParameters; | |||
|
16 | class IDataProvider; | |||
|
17 | ||||
14 | /** |
|
18 | /** | |
15 | * @brief The VariableRequest struct holds the information of an acquisition request |
|
19 | * @brief The VariableRequest struct holds the information of an acquisition request | |
16 | */ |
|
20 | */ | |
17 | struct VariableRequest { |
|
21 | struct VariableRequest { | |
|
22 | void addResult(std::shared_ptr<IDataSeries> dataSeries) | |||
|
23 | { | |||
|
24 | if (!m_Result) { | |||
|
25 | m_Result = dataSeries->clone(); | |||
|
26 | } | |||
|
27 | else { | |||
|
28 | m_Result->merge(dataSeries.get()); | |||
|
29 | } | |||
|
30 | ||||
|
31 | ++m_ExecCount; | |||
|
32 | } | |||
|
33 | ||||
|
34 | bool isFinished() const { return m_ProviderParameters.m_Times.size() == m_ExecCount; } | |||
|
35 | ||||
|
36 | // Parameters | |||
18 | SqpRange m_RangeRequested{INVALID_RANGE}; |
|
37 | SqpRange m_RangeRequested{INVALID_RANGE}; | |
19 | SqpRange m_CacheRangeRequested{INVALID_RANGE}; |
|
38 | SqpRange m_CacheRangeRequested{INVALID_RANGE}; | |
20 |
std::shared_ptr<IData |
|
39 | std::shared_ptr<IDataProvider> m_Provider{nullptr}; | |
21 | bool m_CanUpdate{false}; |
|
40 | DataProviderParameters m_ProviderParameters{}; | |
|
41 | ||||
|
42 | // Results | |||
|
43 | std::shared_ptr<IDataSeries> m_Result{nullptr}; | |||
|
44 | int m_ExecCount{0}; | |||
22 | }; |
|
45 | }; | |
23 |
|
46 | |||
24 | SCIQLOP_REGISTER_META_TYPE(VARIABLEREQUEST_REGISTRY, VariableRequest) |
|
47 | SCIQLOP_REGISTER_META_TYPE(VARIABLEREQUEST_REGISTRY, VariableRequest) | |
25 |
|
48 | |||
26 | #endif // SCIQLOP_VARIABLEREQUEST_H |
|
49 | #endif // SCIQLOP_VARIABLEREQUEST_H |
@@ -1,62 +1,58 | |||||
1 | #ifndef SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
1 | #ifndef SCIQLOP_VARIABLEACQUISITIONWORKER_H | |
2 | #define SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
2 | #define SCIQLOP_VARIABLEACQUISITIONWORKER_H | |
3 |
|
3 | |||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
8 | #include <QObject> |
|
8 | #include <QObject> | |
9 | #include <QUuid> |
|
9 | #include <QUuid> | |
10 |
|
10 | |||
11 | #include <Data/AcquisitionDataPacket.h> |
|
11 | #include <Data/AcquisitionDataPacket.h> | |
12 | #include <Data/IDataSeries.h> |
|
12 | #include <Data/IDataSeries.h> | |
13 | #include <Data/SqpRange.h> |
|
13 | #include <Data/SqpRange.h> | |
|
14 | #include <Data/VariableRequest.h> | |||
14 |
|
15 | |||
15 | #include <QLoggingCategory> |
|
16 | #include <QLoggingCategory> | |
16 |
|
17 | |||
17 | #include <Common/spimpl.h> |
|
18 | #include <Common/spimpl.h> | |
18 |
|
19 | |||
19 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker) |
|
20 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker) | |
20 |
|
21 | |||
21 | class Variable; |
|
22 | class Variable; | |
22 | class IDataProvider; |
|
23 | class IDataProvider; | |
23 |
|
24 | |||
24 | /// This class aims to handle all acquisition request |
|
25 | /// This class aims to handle all acquisition request | |
25 | class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject { |
|
26 | class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject { | |
26 | Q_OBJECT |
|
27 | Q_OBJECT | |
27 | public: |
|
28 | public: | |
28 | explicit VariableAcquisitionWorker(QObject *parent = 0); |
|
29 | explicit VariableAcquisitionWorker(QObject *parent = 0); | |
29 | virtual ~VariableAcquisitionWorker(); |
|
30 | virtual ~VariableAcquisitionWorker(); | |
30 |
|
31 | |||
31 | QUuid pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, SqpRange rangeRequested, |
|
32 | void pushVariableRequest(std::shared_ptr<Variable> variable, VariableRequest request); | |
32 | SqpRange cacheRangeRequested, DataProviderParameters parameters, |
|
|||
33 | std::shared_ptr<IDataProvider> provider); |
|
|||
34 |
|
33 | |||
35 | void abortProgressRequested(QUuid vIdentifier); |
|
34 | void abortProgressRequested(QUuid vIdentifier); | |
36 |
|
35 | |||
37 | void initialize(); |
|
36 | void initialize(); | |
38 | void finalize(); |
|
37 | void finalize(); | |
39 | signals: |
|
38 | signals: | |
40 | void dataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
39 | void dataProvided(std::shared_ptr<Variable> variable, VariableRequest request); | |
41 | const SqpRange &cacheRangeRequested, |
|
|||
42 | QVector<AcquisitionDataPacket> dataAcquired); |
|
|||
43 |
|
||||
44 | void variableRequestInProgress(QUuid vIdentifier, double progress); |
|
40 | void variableRequestInProgress(QUuid vIdentifier, double progress); | |
45 |
|
41 | |||
46 | public slots: |
|
42 | public slots: | |
47 |
void on |
|
43 | void onDataAcquired(QUuid acquisitionId, std::shared_ptr<IDataSeries> dataSeries, | |
48 |
|
|
44 | SqpRange range); | |
49 | void onVariableAcquisitionCanceled(QUuid acqIdentifier); |
|
45 | void onVariableAcquisitionCanceled(QUuid acqIdentifier); | |
50 | void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress); |
|
46 | void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress); | |
51 |
|
47 | |||
52 | private: |
|
48 | private: | |
53 | void waitForFinish(); |
|
49 | void waitForFinish(); | |
54 |
|
50 | |||
55 | class VariableAcquisitionWorkerPrivate; |
|
51 | class VariableAcquisitionWorkerPrivate; | |
56 | spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl; |
|
52 | spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl; | |
57 |
|
53 | |||
58 | private slots: |
|
54 | private slots: | |
59 |
void |
|
55 | void executeAcquisition(QUuid acquisitionId); | |
60 | }; |
|
56 | }; | |
61 |
|
57 | |||
62 | #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H |
|
58 | #endif // SCIQLOP_VARIABLEACQUISITIONWORKER_H |
@@ -1,125 +1,123 | |||||
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECONTROLLER_H | |
3 |
|
3 | |||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/AcquisitionDataPacket.h> |
|
6 | #include <Data/AcquisitionDataPacket.h> | |
7 | #include <Data/SqpRange.h> |
|
7 | #include <Data/SqpRange.h> | |
8 |
|
8 | |||
9 | #include <QLoggingCategory> |
|
9 | #include <QLoggingCategory> | |
10 | #include <QObject> |
|
10 | #include <QObject> | |
11 | #include <QUuid> |
|
11 | #include <QUuid> | |
12 |
|
12 | |||
13 | #include <Common/spimpl.h> |
|
13 | #include <Common/spimpl.h> | |
14 |
|
14 | |||
15 | class IDataProvider; |
|
15 | class IDataProvider; | |
16 | class QItemSelectionModel; |
|
16 | class QItemSelectionModel; | |
17 | class TimeController; |
|
17 | class TimeController; | |
18 | class Variable; |
|
18 | class Variable; | |
19 | class VariableModel; |
|
19 | class VariableModel; | |
|
20 | class VariableRequest; | |||
20 |
|
21 | |||
21 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
22 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) | |
22 |
|
23 | |||
23 | /** |
|
24 | /** | |
24 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
25 | * @brief The VariableController class aims to handle the variables in SciQlop. | |
25 | */ |
|
26 | */ | |
26 | class SCIQLOP_CORE_EXPORT VariableController : public QObject { |
|
27 | class SCIQLOP_CORE_EXPORT VariableController : public QObject { | |
27 | Q_OBJECT |
|
28 | Q_OBJECT | |
28 | public: |
|
29 | public: | |
29 | explicit VariableController(QObject *parent = 0); |
|
30 | explicit VariableController(QObject *parent = 0); | |
30 | virtual ~VariableController(); |
|
31 | virtual ~VariableController(); | |
31 |
|
32 | |||
32 | VariableModel *variableModel() noexcept; |
|
33 | VariableModel *variableModel() noexcept; | |
33 | QItemSelectionModel *variableSelectionModel() noexcept; |
|
34 | QItemSelectionModel *variableSelectionModel() noexcept; | |
34 |
|
35 | |||
35 | void setTimeController(TimeController *timeController) noexcept; |
|
36 | void setTimeController(TimeController *timeController) noexcept; | |
36 |
|
37 | |||
37 | /** |
|
38 | /** | |
38 | * Clones the variable passed in parameter and adds the duplicate to the controller |
|
39 | * Clones the variable passed in parameter and adds the duplicate to the controller | |
39 | * @param variable the variable to duplicate |
|
40 | * @param variable the variable to duplicate | |
40 | * @return the duplicate created, nullptr if the variable couldn't be created |
|
41 | * @return the duplicate created, nullptr if the variable couldn't be created | |
41 | */ |
|
42 | */ | |
42 | std::shared_ptr<Variable> cloneVariable(std::shared_ptr<Variable> variable) noexcept; |
|
43 | std::shared_ptr<Variable> cloneVariable(std::shared_ptr<Variable> variable) noexcept; | |
43 |
|
44 | |||
44 | /** |
|
45 | /** | |
45 | * Deletes from the controller the variable passed in parameter. |
|
46 | * Deletes from the controller the variable passed in parameter. | |
46 | * |
|
47 | * | |
47 | * Delete a variable includes: |
|
48 | * Delete a variable includes: | |
48 | * - the deletion of the various references to the variable in SciQlop |
|
49 | * - the deletion of the various references to the variable in SciQlop | |
49 | * - the deletion of the model variable |
|
50 | * - the deletion of the model variable | |
50 | * - the deletion of the provider associated with the variable |
|
51 | * - the deletion of the provider associated with the variable | |
51 | * - removing the cache associated with the variable |
|
52 | * - removing the cache associated with the variable | |
52 | * |
|
53 | * | |
53 | * @param variable the variable to delete from the controller. |
|
54 | * @param variable the variable to delete from the controller. | |
54 | */ |
|
55 | */ | |
55 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; |
|
56 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; | |
56 |
|
57 | |||
57 | /** |
|
58 | /** | |
58 | * Deletes from the controller the variables passed in parameter. |
|
59 | * Deletes from the controller the variables passed in parameter. | |
59 | * @param variables the variables to delete from the controller. |
|
60 | * @param variables the variables to delete from the controller. | |
60 | * @sa deleteVariable() |
|
61 | * @sa deleteVariable() | |
61 | */ |
|
62 | */ | |
62 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; |
|
63 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; | |
63 |
|
64 | |||
64 | /** |
|
65 | /** | |
65 | * @brief abort the variable retrieve data progression |
|
66 | * @brief abort the variable retrieve data progression | |
66 | */ |
|
67 | */ | |
67 | void abortProgress(std::shared_ptr<Variable> variable); |
|
68 | void abortProgress(std::shared_ptr<Variable> variable); | |
68 |
|
69 | |||
69 | signals: |
|
70 | signals: | |
70 | /// Signal emitted when a variable is about to be deleted from the controller |
|
71 | /// Signal emitted when a variable is about to be deleted from the controller | |
71 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); |
|
72 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); | |
72 |
|
73 | |||
73 | /// Signal emitted when a data acquisition is requested on a range for a variable |
|
74 | /// Signal emitted when a data acquisition is requested on a range for a variable | |
74 | void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
75 | void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range); | |
75 |
|
76 | |||
76 | /// Signal emitted when a sub range of the cacheRange of the variable can be displayed |
|
77 | /// Signal emitted when a sub range of the cacheRange of the variable can be displayed | |
77 | void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
78 | void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); | |
78 |
|
79 | |||
79 | public slots: |
|
80 | public slots: | |
80 | /// Request the data loading of the variable whithin range |
|
81 | /// Request the data loading of the variable whithin range | |
81 |
void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, |
|
82 | void onRequestDataLoading(const QVector<std::shared_ptr<Variable> > &variables, | |
82 | const SqpRange &oldRange, bool synchronise); |
|
83 | const SqpRange &range, const SqpRange &oldRange, bool synchronise); | |
83 | /** |
|
84 | /** | |
84 | * Creates a new variable and adds it to the model |
|
85 | * Creates a new variable and adds it to the model | |
85 | * @param name the name of the new variable |
|
86 | * @param name the name of the new variable | |
86 | * @param metadata the metadata of the new variable |
|
87 | * @param metadata the metadata of the new variable | |
87 | * @param provider the data provider for the new variable |
|
88 | * @param provider the data provider for the new variable | |
88 | * @return the pointer to the new variable or nullptr if the creation failed |
|
89 | * @return the pointer to the new variable or nullptr if the creation failed | |
89 | */ |
|
90 | */ | |
90 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, |
|
91 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, | |
91 | std::shared_ptr<IDataProvider> provider) noexcept; |
|
92 | std::shared_ptr<IDataProvider> provider) noexcept; | |
92 |
|
93 | |||
93 | /// Update the temporal parameters of every selected variable to dateTime |
|
94 | /// Update the temporal parameters of every selected variable to dateTime | |
94 | void onDateTimeOnSelection(const SqpRange &dateTime); |
|
95 | void onDateTimeOnSelection(const SqpRange &dateTime); | |
95 |
|
96 | |||
96 |
|
97 | void onDataProvided(std::shared_ptr<Variable> variable, VariableRequest request); | ||
97 | void onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
|||
98 | const SqpRange &cacheRangeRequested, |
|
|||
99 | QVector<AcquisitionDataPacket> dataAcquired); |
|
|||
100 |
|
98 | |||
101 | void onVariableRetrieveDataInProgress(QUuid identifier, double progress); |
|
99 | void onVariableRetrieveDataInProgress(QUuid identifier, double progress); | |
102 |
|
100 | |||
103 | /// Cancel the current request for the variable |
|
101 | /// Cancel the current request for the variable | |
104 | void onAbortProgressRequested(std::shared_ptr<Variable> variable); |
|
102 | void onAbortProgressRequested(std::shared_ptr<Variable> variable); | |
105 |
|
103 | |||
106 | // synchronization group methods |
|
104 | // synchronization group methods | |
107 | void onAddSynchronizationGroupId(QUuid synchronizationGroupId); |
|
105 | void onAddSynchronizationGroupId(QUuid synchronizationGroupId); | |
108 | void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId); |
|
106 | void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId); | |
109 | void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); |
|
107 | void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); | |
110 |
|
108 | |||
111 | /// Desynchronizes the variable of the group whose identifier is passed in parameter |
|
109 | /// Desynchronizes the variable of the group whose identifier is passed in parameter | |
112 | /// @remarks the method does nothing if the variable is not part of the group |
|
110 | /// @remarks the method does nothing if the variable is not part of the group | |
113 | void desynchronize(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); |
|
111 | void desynchronize(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); | |
114 |
|
112 | |||
115 | void initialize(); |
|
113 | void initialize(); | |
116 | void finalize(); |
|
114 | void finalize(); | |
117 |
|
115 | |||
118 | private: |
|
116 | private: | |
119 | void waitForFinish(); |
|
117 | void waitForFinish(); | |
120 |
|
118 | |||
121 | class VariableControllerPrivate; |
|
119 | class VariableControllerPrivate; | |
122 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
120 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; | |
123 | }; |
|
121 | }; | |
124 |
|
122 | |||
125 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
|
123 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,225 +1,189 | |||||
1 | #include "Variable/VariableAcquisitionWorker.h" |
|
1 | #include "Variable/VariableAcquisitionWorker.h" | |
2 |
|
2 | |||
3 | #include "Variable/Variable.h" |
|
3 | #include "Variable/Variable.h" | |
4 |
|
4 | |||
5 | #include <Data/AcquisitionRequest.h> |
|
5 | #include <Data/IDataProvider.h> | |
6 | #include <Data/SqpRange.h> |
|
6 | #include <Data/SqpRange.h> | |
7 |
|
||||
8 | #include <unordered_map> |
|
7 | #include <unordered_map> | |
9 | #include <utility> |
|
8 | #include <utility> | |
10 |
|
9 | |||
11 | #include <QMutex> |
|
10 | #include <QMutex> | |
12 | #include <QReadWriteLock> |
|
11 | #include <QReadWriteLock> | |
13 | #include <QThread> |
|
12 | #include <QThread> | |
14 | #include <QtConcurrent/QtConcurrent> |
|
13 | #include <QtConcurrent/QtConcurrent> | |
15 |
|
14 | |||
16 | Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker") |
|
15 | Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker") | |
17 |
|
16 | |||
18 | namespace { |
|
17 | namespace { | |
19 |
|
18 | |||
20 | using AcquisitionId = QUuid; |
|
19 | using AcquisitionId = QUuid; | |
21 | using VariableId = QUuid; |
|
20 | using VariableId = QUuid; | |
22 |
|
21 | |||
|
22 | struct Acquisition { | |||
|
23 | std::shared_ptr<Variable> m_Variable{nullptr}; | |||
|
24 | VariableRequest m_Request{}; | |||
|
25 | AcquisitionId m_Id{QUuid::createUuid()}; | |||
|
26 | }; | |||
|
27 | ||||
23 | } // namespace |
|
28 | } // namespace | |
24 |
|
29 | |||
25 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { |
|
30 | struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { | |
26 |
|
31 | |||
27 | explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {} |
|
32 | explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {} | |
28 |
|
33 | |||
29 | void lockRead() { m_Lock.lockForRead(); } |
|
34 | void lockRead() { m_Lock.lockForRead(); } | |
30 | void lockWrite() { m_Lock.lockForWrite(); } |
|
35 | void lockWrite() { m_Lock.lockForWrite(); } | |
31 | void unlock() { m_Lock.unlock(); } |
|
36 | void unlock() { m_Lock.unlock(); } | |
32 |
|
37 | |||
33 |
void erase |
|
38 | void eraseAcquisition(AcquisitionId id) | |
34 | std::map<AcquisitionId, AcquisitionRequest>::iterator insertRequest(AcquisitionId id, |
|
39 | { | |
35 | AcquisitionRequest request); |
|
40 | auto it = m_Acquisitions.find(id); | |
|
41 | if (it != m_Acquisitions.end()) { | |||
|
42 | // Removes from index | |||
|
43 | m_AcquisitionsIndex.erase(it->second.m_Variable); | |||
36 |
|
44 | |||
37 | void removeVariableRequest(QUuid vIdentifier); |
|
45 | // Removes request | |
|
46 | m_Acquisitions.erase(it); | |||
|
47 | } | |||
|
48 | } | |||
|
49 | ||||
|
50 | std::map<AcquisitionId, Acquisition>::iterator insertAcquisition(Acquisition acquisition) | |||
|
51 | { | |||
|
52 | auto variable = acquisition.m_Variable; | |||
|
53 | ||||
|
54 | // Inserts acquisition | |||
|
55 | auto result | |||
|
56 | = m_Acquisitions.insert(std::make_pair(acquisition.m_Id, std::move(acquisition))); | |||
|
57 | if (result.second) { | |||
|
58 | // Inserts index | |||
|
59 | m_AcquisitionsIndex[variable] = &result.first->second; | |||
|
60 | return result.first; | |||
|
61 | } | |||
|
62 | else { | |||
|
63 | return m_Acquisitions.end(); | |||
|
64 | } | |||
|
65 | } | |||
38 |
|
66 | |||
39 | QMutex m_WorkingMutex; |
|
67 | QMutex m_WorkingMutex; | |
40 | QReadWriteLock m_Lock; |
|
68 | QReadWriteLock m_Lock; | |
41 |
|
69 | |||
42 | /// Current acquisitions (by variable) |
|
70 | std::map<AcquisitionId, Acquisition> m_Acquisitions; | |
43 | std::map<AcquisitionId, AcquisitionRequest> m_Requests; |
|
71 | std::map<std::shared_ptr<Variable>, Acquisition *> m_AcquisitionsIndex; | |
44 | std::map<VariableId, AcquisitionRequest *> m_RequestsIndex; |
|
|||
45 | }; |
|
72 | }; | |
46 |
|
73 | |||
47 |
|
||||
48 | VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent) |
|
74 | VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent) | |
49 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()} |
|
75 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()} | |
50 | { |
|
76 | { | |
51 | } |
|
77 | } | |
52 |
|
78 | |||
53 | VariableAcquisitionWorker::~VariableAcquisitionWorker() |
|
79 | VariableAcquisitionWorker::~VariableAcquisitionWorker() | |
54 | { |
|
80 | { | |
55 | qCInfo(LOG_VariableAcquisitionWorker()) |
|
81 | qCInfo(LOG_VariableAcquisitionWorker()) | |
56 | << tr("VariableAcquisitionWorker destruction") << QThread::currentThread(); |
|
82 | << tr("VariableAcquisitionWorker destruction") << QThread::currentThread(); | |
57 | this->waitForFinish(); |
|
83 | this->waitForFinish(); | |
58 | } |
|
84 | } | |
59 |
|
85 | |||
60 |
|
86 | void VariableAcquisitionWorker::pushVariableRequest(std::shared_ptr<Variable> variable, | ||
61 | QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, |
|
87 | VariableRequest request) | |
62 | SqpRange rangeRequested, |
|
|||
63 | SqpRange cacheRangeRequested, |
|
|||
64 | DataProviderParameters parameters, |
|
|||
65 | std::shared_ptr<IDataProvider> provider) |
|
|||
66 | { |
|
88 | { | |
67 | qCDebug(LOG_VariableAcquisitionWorker()) |
|
|||
68 | << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested; |
|
|||
69 | auto varRequestIdCanceled = QUuid(); |
|
|||
70 |
|
||||
71 | // Request creation |
|
|||
72 | auto acqRequest = AcquisitionRequest{}; |
|
|||
73 | acqRequest.m_VarRequestId = varRequestId; |
|
|||
74 | acqRequest.m_vIdentifier = vIdentifier; |
|
|||
75 | acqRequest.m_DataProviderParameters = parameters; |
|
|||
76 | acqRequest.m_RangeRequested = rangeRequested; |
|
|||
77 | acqRequest.m_CacheRangeRequested = cacheRangeRequested; |
|
|||
78 | acqRequest.m_Size = parameters.m_Times.size(); |
|
|||
79 | acqRequest.m_Provider = provider; |
|
|||
80 |
|
||||
81 | impl->lockWrite(); |
|
89 | impl->lockWrite(); | |
82 |
|
90 | |||
83 |
// Checks if there is a current |
|
91 | // Checks if there is a current request for variable | |
84 |
auto |
|
92 | auto oldAcquisitionIt = impl->m_AcquisitionsIndex.find(variable); | |
85 |
if ( |
|
93 | if (oldAcquisitionIt != impl->m_AcquisitionsIndex.cend()) { | |
86 |
auto |
|
94 | auto &oldAcquisition = *oldAcquisitionIt->second; | |
87 | QtConcurrent::run( |
|
95 | /// @todo ALX | |
88 | [ provider = request->m_Provider, acqIdentifier = request->m_AcqIdentifier ]() { |
|
96 | // QtConcurrent::run( | |
89 | provider->requestDataAborting(acqIdentifier); |
|
97 | // [ provider = request->m_Provider, acqIdentifier = request->m_AcqIdentifier ]() | |
90 |
|
|
98 | // { | |
91 | varRequestIdCanceled = request->m_VarRequestId; |
|
99 | // provider->requestDataAborting(acqIdentifier); | |
92 |
|
100 | // }); | ||
93 | impl->eraseRequest(request->m_AcqIdentifier); |
|
101 | ||
|
102 | impl->eraseAcquisition(oldAcquisition.m_Id); | |||
94 | } |
|
103 | } | |
95 |
|
104 | |||
96 | // Sets the new acquisition request as the current request for the variable |
|
105 | // Sets request for variable | |
97 | auto newRequestIt = impl->insertRequest(acqRequest.m_AcqIdentifier, std::move(acqRequest)); |
|
106 | Acquisition newAcquisition{variable, std::move(request)}; | |
98 | if (newRequestIt != impl->m_Requests.end()) { |
|
107 | auto newAcquisitionIt = impl->insertAcquisition(std::move(newAcquisition)); | |
99 | qCInfo(LOG_VariableAcquisitionWorker()) << "EXECUTE REQUEST" << acqRequest.m_AcqIdentifier; |
|
108 | if (newAcquisitionIt != impl->m_Acquisitions.end()) { | |
100 | QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, |
|
109 | impl->unlock(); | |
101 | Q_ARG(QUuid, newRequestIt->first)); |
|
110 | ||
|
111 | QMetaObject::invokeMethod(this, "executeAcquisition", Qt::QueuedConnection, | |||
|
112 | Q_ARG(QUuid, newAcquisitionIt->first)); | |||
102 | } |
|
113 | } | |
103 | else { |
|
114 | else { | |
104 | /// @todo ALX : log |
|
115 | impl->unlock(); | |
105 | } |
|
116 | } | |
106 |
|
||||
107 | impl->unlock(); |
|
|||
108 |
|
||||
109 | return varRequestIdCanceled; |
|
|||
110 | } |
|
117 | } | |
111 |
|
118 | |||
112 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) |
|
119 | void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) | |
113 | { |
|
120 | { | |
114 | // TODO |
|
121 | // TODO | |
115 | } |
|
122 | } | |
116 |
|
123 | |||
117 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, |
|
124 | void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier, | |
118 | double progress) |
|
125 | double progress) | |
119 | { |
|
126 | { | |
120 | // TODO |
|
127 | // TODO | |
121 | } |
|
128 | } | |
122 |
|
129 | |||
123 |
void VariableAcquisitionWorker::on |
|
130 | void VariableAcquisitionWorker::onDataAcquired(QUuid acquisitionId, | |
124 |
|
|
131 | std::shared_ptr<IDataSeries> dataSeries, | |
125 |
|
|
132 | SqpRange range) | |
126 | { |
|
133 | { | |
127 | qCDebug(LOG_VariableAcquisitionWorker()) |
|
|||
128 | << tr("onVariableDataAcquired on range ") << acqIdentifier << dataRangeAcquired; |
|
|||
129 | impl->lockWrite(); |
|
134 | impl->lockWrite(); | |
130 |
|
135 | |||
131 |
auto it = impl->m_ |
|
136 | auto it = impl->m_Acquisitions.find(acquisitionId); | |
132 |
if (it != impl->m_ |
|
137 | if (it != impl->m_Acquisitions.cend()) { | |
133 |
auto & |
|
138 | auto &acquisition = it->second; | |
|
139 | auto &request = acquisition.m_Request; | |||
|
140 | ||||
|
141 | qInfo(LOG_VariableAcquisitionWorker()) << "Data acquired for " << printRange(range); | |||
134 |
|
142 | |||
135 | // Store the result |
|
143 | // Store the result | |
136 | auto dataPacket = AcquisitionDataPacket{dataSeries, dataRangeAcquired}; |
|
144 | request.addResult(dataSeries); | |
137 | request.m_DataPackets.push_back(dataPacket); |
|
145 | ||
138 | request.m_Size = request.m_Size - 1; |
|
146 | if (request.isFinished()) { | |
139 |
|
147 | emit dataProvided(acquisition.m_Variable, std::move(request)); | ||
140 | if (request.m_Size == 0) { |
|
148 | impl->eraseAcquisition(acquisitionId); | |
141 | emit dataProvided(request.m_vIdentifier, request.m_RangeRequested, |
|
|||
142 | request.m_CacheRangeRequested, request.m_DataPackets); |
|
|||
143 | impl->eraseRequest(acqIdentifier); |
|
|||
144 | } |
|
149 | } | |
145 | } |
|
150 | } | |
146 | impl->unlock(); |
|
151 | impl->unlock(); | |
147 | } |
|
152 | } | |
148 |
|
153 | |||
149 | void VariableAcquisitionWorker::onVariableAcquisitionCanceled(QUuid acqIdentifier) |
|
154 | void VariableAcquisitionWorker::onVariableAcquisitionCanceled(QUuid acqIdentifier) | |
150 | { |
|
155 | { | |
151 | impl->lockWrite(); |
|
|||
152 | impl->unlock(); |
|
|||
153 | } |
|
156 | } | |
154 |
|
157 | |||
155 | void VariableAcquisitionWorker::initialize() |
|
158 | void VariableAcquisitionWorker::initialize() | |
156 | { |
|
159 | { | |
157 | qCDebug(LOG_VariableAcquisitionWorker()) |
|
160 | qCDebug(LOG_VariableAcquisitionWorker()) | |
158 | << tr("VariableAcquisitionWorker init") << QThread::currentThread(); |
|
161 | << tr("VariableAcquisitionWorker init") << QThread::currentThread(); | |
159 | impl->m_WorkingMutex.lock(); |
|
162 | impl->m_WorkingMutex.lock(); | |
160 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END"); |
|
163 | qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END"); | |
161 | } |
|
164 | } | |
162 |
|
165 | |||
163 | void VariableAcquisitionWorker::finalize() |
|
166 | void VariableAcquisitionWorker::finalize() | |
164 | { |
|
167 | { | |
165 | impl->m_WorkingMutex.unlock(); |
|
168 | impl->m_WorkingMutex.unlock(); | |
166 | } |
|
169 | } | |
167 |
|
170 | |||
168 | void VariableAcquisitionWorker::waitForFinish() |
|
171 | void VariableAcquisitionWorker::waitForFinish() | |
169 | { |
|
172 | { | |
170 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
173 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
171 | } |
|
174 | } | |
172 |
|
175 | |||
173 |
|
176 | void VariableAcquisitionWorker::executeAcquisition(QUuid acquisitionId) | ||
174 | void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::eraseRequest(AcquisitionId id) |
|
|||
175 | { |
|
|||
176 | auto it = m_Requests.find(id); |
|
|||
177 | if (it != m_Requests.end()) { |
|
|||
178 | // Removes from index |
|
|||
179 | m_RequestsIndex.erase(it->second.m_vIdentifier); |
|
|||
180 |
|
||||
181 | // Removes request |
|
|||
182 | m_Requests.erase(it); |
|
|||
183 | } |
|
|||
184 | } |
|
|||
185 |
|
||||
186 | std::map<AcquisitionId, AcquisitionRequest>::iterator |
|
|||
187 | VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::insertRequest( |
|
|||
188 | AcquisitionId id, AcquisitionRequest request) |
|
|||
189 | { |
|
|||
190 | // Inserts request |
|
|||
191 | auto variableId = request.m_vIdentifier; |
|
|||
192 | auto result = m_Requests.insert(std::make_pair(id, std::move(request))); |
|
|||
193 |
|
||||
194 | if (result.second) { |
|
|||
195 | // Inserts index |
|
|||
196 | m_RequestsIndex[variableId] = &result.first->second; |
|
|||
197 |
|
||||
198 | return result.first; |
|
|||
199 | } |
|
|||
200 | else { |
|
|||
201 | return m_Requests.end(); |
|
|||
202 | } |
|
|||
203 | } |
|
|||
204 |
|
||||
205 | void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest( |
|
|||
206 | QUuid vIdentifier) |
|
|||
207 | { |
|
|||
208 | /// @todo ALX |
|
|||
209 | // m_Acquisitions.erase(vIdentifier); |
|
|||
210 | } |
|
|||
211 |
|
||||
212 | void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) |
|
|||
213 | { |
|
177 | { | |
214 | impl->lockRead(); |
|
178 | impl->lockRead(); | |
215 |
auto it = impl->m_ |
|
179 | auto it = impl->m_Acquisitions.find(acquisitionId); | |
216 |
if (it != impl->m_ |
|
180 | if (it != impl->m_Acquisitions.cend()) { | |
217 | auto &request = it->second; |
|
181 | auto &request = it->second.m_Request; | |
218 | impl->unlock(); |
|
182 | impl->unlock(); | |
219 |
request.m_Provider->requestDataLoading(acq |
|
183 | request.m_Provider->requestDataLoading(acquisitionId, request.m_ProviderParameters); | |
220 | } |
|
184 | } | |
221 | else { |
|
185 | else { | |
222 | impl->unlock(); |
|
186 | impl->unlock(); | |
223 | // TODO log no acqIdentifier recognized |
|
187 | // TODO log no acqIdentifier recognized | |
224 | } |
|
188 | } | |
225 | } |
|
189 | } |
@@ -1,702 +1,434 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableAcquisitionWorker.h> |
|
2 | #include <Variable/VariableAcquisitionWorker.h> | |
3 | #include <Variable/VariableCacheStrategy.h> |
|
3 | #include <Variable/VariableCacheStrategy.h> | |
4 | #include <Variable/VariableController.h> |
|
4 | #include <Variable/VariableController.h> | |
5 | #include <Variable/VariableModel.h> |
|
5 | #include <Variable/VariableModel.h> | |
6 |
#include <Variable/VariableSynchroniz |
|
6 | #include <Variable/VariableSynchronizer.h> | |
7 |
|
7 | |||
8 | #include <Data/AcquisitionUtils.h> |
|
8 | #include <Data/AcquisitionUtils.h> | |
9 | #include <Data/DataProviderParameters.h> |
|
9 | #include <Data/DataProviderParameters.h> | |
10 | #include <Data/IDataProvider.h> |
|
10 | #include <Data/IDataProvider.h> | |
11 | #include <Data/IDataSeries.h> |
|
11 | #include <Data/IDataSeries.h> | |
12 | #include <Data/VariableRequest.h> |
|
12 | #include <Data/VariableRequest.h> | |
13 | #include <Time/TimeController.h> |
|
13 | #include <Time/TimeController.h> | |
14 |
|
14 | |||
15 | #include <QMutex> |
|
15 | #include <QMutex> | |
16 | #include <QThread> |
|
16 | #include <QThread> | |
17 | #include <QUuid> |
|
17 | #include <QUuid> | |
18 | #include <QtCore/QItemSelectionModel> |
|
18 | #include <QtCore/QItemSelectionModel> | |
19 |
|
19 | |||
20 | #include <deque> |
|
|||
21 | #include <set> |
|
|||
22 | #include <unordered_map> |
|
20 | #include <unordered_map> | |
23 |
|
21 | |||
24 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
22 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
25 |
|
23 | |||
26 | namespace { |
|
24 | namespace { | |
27 |
|
25 | |||
28 | SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, |
|
26 | SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, | |
29 | const SqpRange &oldGraphRange) |
|
27 | const SqpRange &oldGraphRange) | |
30 | { |
|
28 | { | |
31 | auto zoomType = AcquisitionUtils::getZoomType(graphRange, oldGraphRange); |
|
29 | auto zoomType = AcquisitionUtils::getZoomType(graphRange, oldGraphRange); | |
32 |
|
30 | |||
33 | auto varRangeRequested = varRange; |
|
31 | auto varRangeRequested = varRange; | |
34 | switch (zoomType) { |
|
32 | switch (zoomType) { | |
35 | case AcquisitionZoomType::ZoomIn: { |
|
33 | case AcquisitionZoomType::ZoomIn: { | |
36 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
34 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
37 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
35 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
38 | varRangeRequested.m_TStart += deltaLeft; |
|
36 | varRangeRequested.m_TStart += deltaLeft; | |
39 | varRangeRequested.m_TEnd -= deltaRight; |
|
37 | varRangeRequested.m_TEnd -= deltaRight; | |
40 | break; |
|
38 | break; | |
41 | } |
|
39 | } | |
42 |
|
40 | |||
43 | case AcquisitionZoomType::ZoomOut: { |
|
41 | case AcquisitionZoomType::ZoomOut: { | |
44 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
42 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
45 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
43 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
46 | varRangeRequested.m_TStart -= deltaLeft; |
|
44 | varRangeRequested.m_TStart -= deltaLeft; | |
47 | varRangeRequested.m_TEnd += deltaRight; |
|
45 | varRangeRequested.m_TEnd += deltaRight; | |
48 | break; |
|
46 | break; | |
49 | } |
|
47 | } | |
50 | case AcquisitionZoomType::PanRight: { |
|
48 | case AcquisitionZoomType::PanRight: { | |
51 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
49 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
52 | varRangeRequested.m_TStart += deltaRight; |
|
50 | varRangeRequested.m_TStart += deltaRight; | |
53 | varRangeRequested.m_TEnd += deltaRight; |
|
51 | varRangeRequested.m_TEnd += deltaRight; | |
54 | break; |
|
52 | break; | |
55 | } |
|
53 | } | |
56 | case AcquisitionZoomType::PanLeft: { |
|
54 | case AcquisitionZoomType::PanLeft: { | |
57 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
55 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
58 | varRangeRequested.m_TStart -= deltaLeft; |
|
56 | varRangeRequested.m_TStart -= deltaLeft; | |
59 | varRangeRequested.m_TEnd -= deltaLeft; |
|
57 | varRangeRequested.m_TEnd -= deltaLeft; | |
60 | break; |
|
58 | break; | |
61 | } |
|
59 | } | |
62 | case AcquisitionZoomType::Unknown: { |
|
60 | case AcquisitionZoomType::Unknown: { | |
63 | qCCritical(LOG_VariableController()) |
|
61 | qCCritical(LOG_VariableController()) | |
64 | << VariableController::tr("Impossible to synchronize: zoom type unknown"); |
|
62 | << VariableController::tr("Impossible to synchronize: zoom type unknown"); | |
65 | break; |
|
63 | break; | |
66 | } |
|
64 | } | |
67 | default: |
|
65 | default: | |
68 | qCCritical(LOG_VariableController()) << VariableController::tr( |
|
66 | qCCritical(LOG_VariableController()) << VariableController::tr( | |
69 | "Impossible to synchronize: zoom type not take into account"); |
|
67 | "Impossible to synchronize: zoom type not take into account"); | |
70 | // No action |
|
68 | // No action | |
71 | break; |
|
69 | break; | |
72 | } |
|
70 | } | |
73 |
|
71 | |||
74 | return varRangeRequested; |
|
72 | return varRangeRequested; | |
75 | } |
|
73 | } | |
76 | } // namespace |
|
74 | } // namespace | |
77 |
|
75 | |||
78 | struct VariableController::VariableControllerPrivate { |
|
76 | struct VariableController::VariableControllerPrivate { | |
79 | explicit VariableControllerPrivate(VariableController *parent) |
|
77 | explicit VariableControllerPrivate(VariableController *parent) | |
80 | : m_WorkingMutex{}, |
|
78 | : m_WorkingMutex{}, | |
81 | m_VariableModel{new VariableModel{parent}}, |
|
79 | m_VariableModel{new VariableModel{parent}}, | |
82 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
80 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
83 | m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()}, |
|
81 | m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()}, | |
84 | m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()}, |
|
82 | m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()}, | |
|
83 | m_VariableSynchronizer{std::make_unique<VariableSynchronizer>()}, | |||
85 | q{parent} |
|
84 | q{parent} | |
86 | { |
|
85 | { | |
87 | m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); |
|
86 | m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); | |
88 | m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); |
|
87 | m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); | |
89 | } |
|
88 | } | |
90 |
|
89 | |||
91 | virtual ~VariableControllerPrivate() |
|
90 | virtual ~VariableControllerPrivate() | |
92 | { |
|
91 | { | |
93 | qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); |
|
92 | qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); | |
94 | m_VariableAcquisitionWorkerThread.quit(); |
|
93 | m_VariableAcquisitionWorkerThread.quit(); | |
95 | m_VariableAcquisitionWorkerThread.wait(); |
|
94 | m_VariableAcquisitionWorkerThread.wait(); | |
96 | } |
|
95 | } | |
97 |
|
96 | |||
98 | void processRequest(std::shared_ptr<Variable> variable, const SqpRange &rangeRequested) |
|
97 | void processRequest(std::shared_ptr<Variable> variable, const SqpRange &rangeRequested) | |
99 | { |
|
98 | { | |
100 | Q_ASSERT(variable != nullptr); |
|
99 | Q_ASSERT(variable != nullptr); | |
101 |
|
100 | |||
102 | if (!m_VariableModel->containsVariable(variable)) { |
|
101 | if (!m_VariableModel->containsVariable(variable)) { | |
103 | qCCritical(LOG_VariableController()) |
|
102 | qCCritical(LOG_VariableController()) | |
104 | << QObject::tr("Can't process request for variable %1: variable is not registered") |
|
103 | << QObject::tr("Can't process request for variable %1: variable is not registered") | |
105 | .arg(variable->name()); |
|
104 | .arg(variable->name()); | |
106 | return; |
|
105 | return; | |
107 | } |
|
106 | } | |
108 |
|
107 | |||
|
108 | variable->setRange(rangeRequested); | |||
|
109 | ||||
109 | // Gets ranges in/out of variable range |
|
110 | // Gets ranges in/out of variable range | |
110 | auto requestRange |
|
111 | auto requestRange | |
111 | = m_VariableCacheStrategy->computeStrategyRanges(variable->range(), rangeRequested); |
|
112 | = m_VariableCacheStrategy->computeStrategyRanges(variable->range(), rangeRequested); | |
112 | auto notInCacheRanges = variable->provideNotInCacheRangeList(requestRange.second); |
|
113 | auto notInCacheRanges = variable->provideNotInCacheRangeList(requestRange.second); | |
113 | auto inCacheRanges = variable->provideInCacheRangeList(requestRange.second); |
|
|||
114 |
|
114 | |||
115 | // Creates request for out-of-cache ranges |
|
115 | // Creates request for out-of-cache ranges | |
116 | if (!notInCacheRanges.isEmpty()) { |
|
116 | if (!notInCacheRanges.isEmpty()) { | |
117 | // Gets provider for request |
|
117 | // Gets provider for request | |
118 | if (auto provider = m_Providers.at(variable)) { |
|
118 | if (auto provider = m_Providers.at(variable)) { | |
119 | VariableRequest request{requestRange.first, requestRange.second}; |
|
119 | DataProviderParameters providerParameters{std::move(notInCacheRanges), | |
120 | // m_VariableAcquisitionWorker->pushVariableRequest(); |
|
120 | variable->metadata()}; | |
|
121 | VariableRequest request{requestRange.first, requestRange.second, provider, | |||
|
122 | std::move(providerParameters)}; | |||
|
123 | m_VariableAcquisitionWorker->pushVariableRequest(variable, std::move(request)); | |||
121 | } |
|
124 | } | |
122 | } |
|
|||
123 |
|
||||
124 | // Calls UI update for in-cache range |
|
|||
125 | if (!inCacheRanges.isEmpty()) { |
|
|||
126 | emit q->updateVarDisplaying(variable, inCacheRanges.first()); |
|
|||
127 | } |
|
|||
128 | } |
|
|||
129 |
|
125 | |||
130 | std::shared_ptr<Variable> findVariable(QUuid vIdentifier) |
|
126 | // Calls UI update for in-cache range | |
131 | { |
|
127 | auto inCacheRanges = variable->provideInCacheRangeList(requestRange.second); | |
132 | /// @todo ALX |
|
128 | if (!inCacheRanges.isEmpty()) { | |
133 | std::shared_ptr<Variable> var; |
|
129 | emit q->updateVarDisplaying(variable, inCacheRanges.first()); | |
134 | auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; |
|
130 | } | |
135 |
|
||||
136 | auto end = m_VariableToIdentifierMap.cend(); |
|
|||
137 | auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); |
|
|||
138 | if (it != end) { |
|
|||
139 | var = it->first; |
|
|||
140 | } |
|
131 | } | |
141 | else { |
|
132 | else { | |
142 | qCCritical(LOG_VariableController()) |
|
133 | // No request to make: we simply update variable ranges | |
143 | << tr("Impossible to find the variable with the identifier: ") << vIdentifier; |
|
134 | variable->setCacheRange(requestRange.second); | |
144 | } |
|
135 | emit variable->updated(); | |
145 |
|
||||
146 | return var; |
|
|||
147 | } |
|
|||
148 | std::shared_ptr<IDataSeries> |
|
|||
149 | retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector) |
|
|||
150 | { |
|
|||
151 | /// @todo ALX |
|
|||
152 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") |
|
|||
153 | << acqDataPacketVector.size(); |
|
|||
154 | std::shared_ptr<IDataSeries> dataSeries; |
|
|||
155 | if (!acqDataPacketVector.isEmpty()) { |
|
|||
156 | dataSeries = acqDataPacketVector[0].m_DateSeries; |
|
|||
157 | for (int i = 1; i < acqDataPacketVector.size(); ++i) { |
|
|||
158 | dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); |
|
|||
159 | } |
|
|||
160 | } |
|
136 | } | |
161 | qCDebug(LOG_VariableController()) |
|
|||
162 | << tr("TORM: retrieveDataSeries acqDataPacketVector size END") |
|
|||
163 | << acqDataPacketVector.size(); |
|
|||
164 | return dataSeries; |
|
|||
165 | } |
|
137 | } | |
166 |
|
138 | |||
167 | void registerProvider(std::shared_ptr<IDataProvider> provider) |
|
139 | void registerProvider(std::shared_ptr<IDataProvider> provider) | |
168 | { |
|
140 | { | |
169 | Q_ASSERT(provider != nullptr); |
|
141 | Q_ASSERT(provider != nullptr); | |
170 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), |
|
142 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), | |
171 |
&VariableAcquisitionWorker::on |
|
143 | &VariableAcquisitionWorker::onDataAcquired); | |
172 | connect(provider.get(), &IDataProvider::dataProvidedProgress, |
|
144 | connect(provider.get(), &IDataProvider::dataProvidedProgress, | |
173 | m_VariableAcquisitionWorker.get(), |
|
145 | m_VariableAcquisitionWorker.get(), | |
174 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); |
|
146 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); | |
175 | } |
|
147 | } | |
176 |
|
148 | |||
177 | QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries) |
|
|||
178 | { |
|
|||
179 | /// @todo ALX |
|
|||
180 | QUuid varRequestId; |
|
|||
181 | // auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); |
|
|||
182 | // if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) { |
|
|||
183 | // auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; |
|
|||
184 | // varRequestId = varRequestIdQueue.front(); |
|
|||
185 | // auto varRequestIdToVarIdVarRequestMapIt |
|
|||
186 | // = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); |
|
|||
187 | // if (varRequestIdToVarIdVarRequestMapIt != |
|
|||
188 | // m_VarRequestIdToVarIdVarRequestMap.cend()) { |
|
|||
189 | // auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; |
|
|||
190 | // auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId); |
|
|||
191 | // if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) { |
|
|||
192 | // qCDebug(LOG_VariableController()) << tr("acceptVariableRequest"); |
|
|||
193 | // auto &varRequest = varIdToVarRequestMapIt->second; |
|
|||
194 | // varRequest.m_DataSeries = dataSeries; |
|
|||
195 | // varRequest.m_CanUpdate = true; |
|
|||
196 | // } |
|
|||
197 | // else { |
|
|||
198 | // qCDebug(LOG_VariableController()) << tr("Impossible to |
|
|||
199 | // acceptVariableRequest " |
|
|||
200 | // "of a unknown variable id |
|
|||
201 | // attached " |
|
|||
202 | // "to a variableRequestId") |
|
|||
203 | // << varRequestId << varId; |
|
|||
204 | // } |
|
|||
205 | // } |
|
|||
206 | // else { |
|
|||
207 | // qCCritical(LOG_VariableController()) |
|
|||
208 | // << tr("Impossible to acceptVariableRequest of a unknown |
|
|||
209 | // variableRequestId") |
|
|||
210 | // << varRequestId; |
|
|||
211 | // } |
|
|||
212 |
|
||||
213 | // qCDebug(LOG_VariableController()) |
|
|||
214 | // << tr("1: erase REQUEST in QUEUE ?") << varRequestIdQueue.size(); |
|
|||
215 | // varRequestIdQueue.pop_front(); |
|
|||
216 | // qCDebug(LOG_VariableController()) |
|
|||
217 | // << tr("2: erase REQUEST in QUEUE ?") << varRequestIdQueue.size(); |
|
|||
218 | // if (varRequestIdQueue.empty()) { |
|
|||
219 | // m_VarIdToVarRequestIdQueueMap.erase(varId); |
|
|||
220 | // } |
|
|||
221 | // } |
|
|||
222 | // else { |
|
|||
223 | // qCCritical(LOG_VariableController()) |
|
|||
224 | // << tr("Impossible to acceptVariableRequest of a unknown variable id") << |
|
|||
225 | // varId; |
|
|||
226 | // } |
|
|||
227 |
|
||||
228 | return varRequestId; |
|
|||
229 | } |
|
|||
230 | void updateVariableRequest(QUuid varRequestId) |
|
|||
231 | { |
|
|||
232 | /// @todo ALX |
|
|||
233 | // auto varRequestIdToVarIdVarRequestMapIt |
|
|||
234 | // = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); |
|
|||
235 | // if (varRequestIdToVarIdVarRequestMapIt != |
|
|||
236 | // m_VarRequestIdToVarIdVarRequestMap.cend()) { |
|
|||
237 | // bool processVariableUpdate = true; |
|
|||
238 | // auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; |
|
|||
239 | // for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); |
|
|||
240 | // (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && |
|
|||
241 | // processVariableUpdate; |
|
|||
242 | // ++varIdToVarRequestMapIt) { |
|
|||
243 | // processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate; |
|
|||
244 | // qCDebug(LOG_VariableController()) |
|
|||
245 | // << tr("updateVariableRequest") << processVariableUpdate; |
|
|||
246 | // } |
|
|||
247 |
|
||||
248 | // if (processVariableUpdate) { |
|
|||
249 | // for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin(); |
|
|||
250 | // varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); |
|
|||
251 | // ++varIdToVarRequestMapIt) { |
|
|||
252 | // if (auto var = findVariable(varIdToVarRequestMapIt->first)) { |
|
|||
253 | // auto &varRequest = varIdToVarRequestMapIt->second; |
|
|||
254 | // var->setRange(varRequest.m_RangeRequested); |
|
|||
255 | // var->setCacheRange(varRequest.m_CacheRangeRequested); |
|
|||
256 | // qCDebug(LOG_VariableController()) |
|
|||
257 | // << tr("1: onDataProvided") << varRequest.m_RangeRequested; |
|
|||
258 | // qCDebug(LOG_VariableController()) |
|
|||
259 | // << tr("2: onDataProvided") << |
|
|||
260 | // varRequest.m_CacheRangeRequested; |
|
|||
261 | // var->mergeDataSeries(varRequest.m_DataSeries); |
|
|||
262 | // qCDebug(LOG_VariableController()) |
|
|||
263 | // << tr("3: onDataProvided") << |
|
|||
264 | // varRequest.m_DataSeries->range(); |
|
|||
265 | // qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); |
|
|||
266 |
|
||||
267 | // /// @todo MPL: confirm |
|
|||
268 | // // Variable update is notified only if there is no pending request |
|
|||
269 | // for it |
|
|||
270 | // if |
|
|||
271 | // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first) |
|
|||
272 | // == 0) { |
|
|||
273 | // emit var->updated(); |
|
|||
274 | // } |
|
|||
275 | // } |
|
|||
276 | // else { |
|
|||
277 | // qCCritical(LOG_VariableController()) |
|
|||
278 | // << tr("Impossible to update data to a null variable"); |
|
|||
279 | // } |
|
|||
280 | // } |
|
|||
281 |
|
||||
282 | // // cleaning varRequestId |
|
|||
283 | // qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?") |
|
|||
284 | // << |
|
|||
285 | // m_VarRequestIdToVarIdVarRequestMap.size(); |
|
|||
286 | // m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); |
|
|||
287 | // qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?") |
|
|||
288 | // << |
|
|||
289 | // m_VarRequestIdToVarIdVarRequestMap.size(); |
|
|||
290 | // } |
|
|||
291 | // } |
|
|||
292 | // else { |
|
|||
293 | // qCCritical(LOG_VariableController()) |
|
|||
294 | // << tr("Cannot updateVariableRequest for a unknow varRequestId") << |
|
|||
295 | // varRequestId; |
|
|||
296 | // } |
|
|||
297 | } |
|
|||
298 |
|
||||
299 | void cancelVariableRequest(QUuid varRequestId) |
|
|||
300 | { |
|
|||
301 | /// @todo ALX |
|
|||
302 | // // cleaning varRequestId |
|
|||
303 | // m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); |
|
|||
304 |
|
||||
305 | // for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin(); |
|
|||
306 | // varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) { |
|
|||
307 | // auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; |
|
|||
308 | // varRequestIdQueue.erase( |
|
|||
309 | // std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), |
|
|||
310 | // varRequestId), |
|
|||
311 | // varRequestIdQueue.end()); |
|
|||
312 | // if (varRequestIdQueue.empty()) { |
|
|||
313 | // varIdToVarRequestIdQueueMapIt |
|
|||
314 | // = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt); |
|
|||
315 | // } |
|
|||
316 | // else { |
|
|||
317 | // ++varIdToVarRequestIdQueueMapIt; |
|
|||
318 | // } |
|
|||
319 | // } |
|
|||
320 | } |
|
|||
321 |
|
||||
322 | QMutex m_WorkingMutex; |
|
149 | QMutex m_WorkingMutex; | |
323 | /// Variable model. The VariableController has the ownership |
|
150 | /// Variable model. The VariableController has the ownership | |
324 | VariableModel *m_VariableModel; |
|
151 | VariableModel *m_VariableModel; | |
325 | QItemSelectionModel *m_VariableSelectionModel; |
|
152 | QItemSelectionModel *m_VariableSelectionModel; | |
326 |
|
153 | |||
327 | TimeController *m_TimeController{nullptr}; |
|
154 | TimeController *m_TimeController{nullptr}; | |
328 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; |
|
155 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; | |
329 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; |
|
156 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; | |
330 | QThread m_VariableAcquisitionWorkerThread; |
|
157 | QThread m_VariableAcquisitionWorkerThread; | |
331 |
|
158 | |||
|
159 | /// Handler for variables synchronization | |||
|
160 | std::unique_ptr<VariableSynchronizer> m_VariableSynchronizer; | |||
|
161 | ||||
332 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > m_Providers; |
|
162 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > m_Providers; | |
333 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; |
|
|||
334 | std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> > |
|
|||
335 | m_GroupIdToVariableSynchronizationGroupMap; |
|
|||
336 | std::map<QUuid, QUuid> m_VariableIdGroupIdMap; |
|
|||
337 |
|
163 | |||
338 | VariableController *q; |
|
164 | VariableController *q; | |
339 | }; |
|
165 | }; | |
340 |
|
166 | |||
341 | VariableController::VariableController(QObject *parent) |
|
167 | VariableController::VariableController(QObject *parent) | |
342 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
168 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
343 | { |
|
169 | { | |
344 | qCDebug(LOG_VariableController()) |
|
170 | qCDebug(LOG_VariableController()) | |
345 | << tr("VariableController construction") << QThread::currentThread(); |
|
171 | << tr("VariableController construction") << QThread::currentThread(); | |
346 |
|
172 | |||
347 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, |
|
173 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, | |
348 | &VariableController::onAbortProgressRequested); |
|
174 | &VariableController::onAbortProgressRequested); | |
349 |
|
175 | |||
350 | connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this, |
|
176 | connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this, | |
351 | &VariableController::onDataProvided); |
|
177 | &VariableController::onDataProvided); | |
352 | connect(impl->m_VariableAcquisitionWorker.get(), |
|
178 | connect(impl->m_VariableAcquisitionWorker.get(), | |
353 | &VariableAcquisitionWorker::variableRequestInProgress, this, |
|
179 | &VariableAcquisitionWorker::variableRequestInProgress, this, | |
354 | &VariableController::onVariableRetrieveDataInProgress); |
|
180 | &VariableController::onVariableRetrieveDataInProgress); | |
355 |
|
181 | |||
356 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started, |
|
182 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started, | |
357 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize); |
|
183 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize); | |
358 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished, |
|
184 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished, | |
359 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize); |
|
185 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize); | |
360 |
|
186 | |||
361 |
|
187 | |||
362 | impl->m_VariableAcquisitionWorkerThread.start(); |
|
188 | impl->m_VariableAcquisitionWorkerThread.start(); | |
363 | } |
|
189 | } | |
364 |
|
190 | |||
365 | VariableController::~VariableController() |
|
191 | VariableController::~VariableController() | |
366 | { |
|
192 | { | |
367 | qCDebug(LOG_VariableController()) |
|
193 | qCDebug(LOG_VariableController()) | |
368 | << tr("VariableController destruction") << QThread::currentThread(); |
|
194 | << tr("VariableController destruction") << QThread::currentThread(); | |
369 | this->waitForFinish(); |
|
195 | this->waitForFinish(); | |
370 | } |
|
196 | } | |
371 |
|
197 | |||
372 | VariableModel *VariableController::variableModel() noexcept |
|
198 | VariableModel *VariableController::variableModel() noexcept | |
373 | { |
|
199 | { | |
374 | return impl->m_VariableModel; |
|
200 | return impl->m_VariableModel; | |
375 | } |
|
201 | } | |
376 |
|
202 | |||
377 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
203 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
378 | { |
|
204 | { | |
379 | return impl->m_VariableSelectionModel; |
|
205 | return impl->m_VariableSelectionModel; | |
380 | } |
|
206 | } | |
381 |
|
207 | |||
382 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
208 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
383 | { |
|
209 | { | |
384 | impl->m_TimeController = timeController; |
|
210 | impl->m_TimeController = timeController; | |
385 | } |
|
211 | } | |
386 |
|
212 | |||
387 | std::shared_ptr<Variable> |
|
213 | std::shared_ptr<Variable> | |
388 | VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept |
|
214 | VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept | |
389 | { |
|
215 | { | |
390 | if (impl->m_VariableModel->containsVariable(variable)) { |
|
216 | if (impl->m_VariableModel->containsVariable(variable)) { | |
391 | // Clones variable |
|
217 | // Clones variable | |
392 | auto duplicate = variable->clone(); |
|
218 | auto duplicate = variable->clone(); | |
393 |
|
219 | |||
394 | // Adds clone to model |
|
220 | // Adds clone to model | |
395 | impl->m_VariableModel->addVariable(duplicate); |
|
221 | impl->m_VariableModel->addVariable(duplicate); | |
396 |
|
222 | |||
397 | // Generates clone identifier |
|
|||
398 | impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid(); |
|
|||
399 |
|
||||
400 | // Registers provider |
|
223 | // Registers provider | |
401 | auto variableProvider = impl->m_Providers.at(variable); |
|
224 | auto variableProvider = impl->m_Providers.at(variable); | |
402 | auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr; |
|
225 | auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr; | |
403 |
|
226 | |||
404 | impl->m_Providers[duplicate] = duplicateProvider; |
|
227 | impl->m_Providers[duplicate] = duplicateProvider; | |
405 | if (duplicateProvider) { |
|
228 | if (duplicateProvider) { | |
406 | impl->registerProvider(duplicateProvider); |
|
229 | impl->registerProvider(duplicateProvider); | |
407 | } |
|
230 | } | |
408 |
|
231 | |||
409 | return duplicate; |
|
232 | return duplicate; | |
410 | } |
|
233 | } | |
411 | else { |
|
234 | else { | |
412 | qCCritical(LOG_VariableController()) |
|
235 | qCCritical(LOG_VariableController()) | |
413 | << tr("Can't create duplicate of variable %1: variable not registered in the model") |
|
236 | << tr("Can't create duplicate of variable %1: variable not registered in the model") | |
414 | .arg(variable->name()); |
|
237 | .arg(variable->name()); | |
415 | return nullptr; |
|
238 | return nullptr; | |
416 | } |
|
239 | } | |
417 | } |
|
240 | } | |
418 |
|
241 | |||
419 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
242 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
420 | { |
|
243 | { | |
421 | if (!variable) { |
|
244 | if (!variable) { | |
422 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
245 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
423 | return; |
|
246 | return; | |
424 | } |
|
247 | } | |
425 |
|
248 | |||
426 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
249 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
427 | // make some treatments before the deletion |
|
250 | // make some treatments before the deletion | |
428 | emit variableAboutToBeDeleted(variable); |
|
251 | emit variableAboutToBeDeleted(variable); | |
429 |
|
252 | |||
430 | // Deletes identifier |
|
|||
431 | impl->m_VariableToIdentifierMap.erase(variable); |
|
|||
432 |
|
||||
433 | // Deletes provider |
|
253 | // Deletes provider | |
434 | auto nbProvidersDeleted = impl->m_Providers.erase(variable); |
|
254 | auto nbProvidersDeleted = impl->m_Providers.erase(variable); | |
435 | qCDebug(LOG_VariableController()) |
|
255 | qCDebug(LOG_VariableController()) | |
436 | << tr("Number of providers deleted for variable %1: %2") |
|
256 | << tr("Number of providers deleted for variable %1: %2") | |
437 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
257 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
438 |
|
258 | |||
439 |
|
259 | |||
440 | // Deletes from model |
|
260 | // Deletes from model | |
441 | impl->m_VariableModel->deleteVariable(variable); |
|
261 | impl->m_VariableModel->deleteVariable(variable); | |
442 | } |
|
262 | } | |
443 |
|
263 | |||
444 | void VariableController::deleteVariables( |
|
264 | void VariableController::deleteVariables( | |
445 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
265 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
446 | { |
|
266 | { | |
447 | for (auto variable : qAsConst(variables)) { |
|
267 | for (auto variable : qAsConst(variables)) { | |
448 | deleteVariable(variable); |
|
268 | deleteVariable(variable); | |
449 | } |
|
269 | } | |
450 | } |
|
270 | } | |
451 |
|
271 | |||
452 | void VariableController::abortProgress(std::shared_ptr<Variable> variable) |
|
272 | void VariableController::abortProgress(std::shared_ptr<Variable> variable) | |
453 | { |
|
273 | { | |
454 | } |
|
274 | } | |
455 |
|
275 | |||
456 | std::shared_ptr<Variable> |
|
276 | std::shared_ptr<Variable> | |
457 | VariableController::createVariable(const QString &name, const QVariantHash &metadata, |
|
277 | VariableController::createVariable(const QString &name, const QVariantHash &metadata, | |
458 | std::shared_ptr<IDataProvider> provider) noexcept |
|
278 | std::shared_ptr<IDataProvider> provider) noexcept | |
459 | { |
|
279 | { | |
460 | if (!impl->m_TimeController) { |
|
280 | if (!impl->m_TimeController) { | |
461 | qCCritical(LOG_VariableController()) |
|
281 | qCCritical(LOG_VariableController()) | |
462 | << tr("Impossible to create variable: The time controller is null"); |
|
282 | << tr("Impossible to create variable: The time controller is null"); | |
463 | return nullptr; |
|
283 | return nullptr; | |
464 | } |
|
284 | } | |
465 |
|
285 | |||
466 | auto range = impl->m_TimeController->dateTime(); |
|
286 | auto range = impl->m_TimeController->dateTime(); | |
467 |
|
287 | |||
468 | if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) { |
|
288 | if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) { | |
469 | auto identifier = QUuid::createUuid(); |
|
|||
470 |
|
||||
471 | // store the provider |
|
|||
472 | impl->registerProvider(provider); |
|
|||
473 |
|
||||
474 | // Associate the provider |
|
289 | // Associate the provider | |
475 | impl->m_Providers[newVariable] = provider; |
|
290 | auto newVariableProvider = provider != nullptr ? provider->clone() : nullptr; | |
476 |
impl->m_ |
|
291 | impl->m_Providers[newVariable] = newVariableProvider; | |
|
292 | if (newVariableProvider) { | |||
|
293 | impl->registerProvider(newVariableProvider); | |||
|
294 | } | |||
477 |
|
295 | |||
478 | impl->processRequest(newVariable, range); |
|
296 | impl->processRequest(newVariable, range); | |
479 | /// @todo ALX |
|
|||
480 | // impl->updateVariableRequest(varRequestId); |
|
|||
481 |
|
297 | |||
482 | return newVariable; |
|
298 | return newVariable; | |
483 | } |
|
299 | } | |
484 | } |
|
300 | } | |
485 |
|
301 | |||
486 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) |
|
302 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) | |
487 | { |
|
303 | { | |
488 | // TODO check synchronisation and Rescale |
|
304 | // TODO check synchronisation and Rescale | |
489 | qCDebug(LOG_VariableController()) |
|
305 | qCDebug(LOG_VariableController()) | |
490 | << "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName(); |
|
306 | << "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName(); | |
491 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
307 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
492 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
308 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
493 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
309 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
494 | selectedVariable->setRange(dateTime); |
|
310 | selectedVariable->setRange(dateTime); | |
495 | impl->processRequest(selectedVariable, dateTime); |
|
311 | impl->processRequest(selectedVariable, dateTime); | |
496 |
|
312 | |||
497 | // notify that rescale operation has to be done |
|
313 | // notify that rescale operation has to be done | |
498 | emit rangeChanged(selectedVariable, dateTime); |
|
314 | emit rangeChanged(selectedVariable, dateTime); | |
499 | } |
|
315 | } | |
500 | } |
|
316 | } | |
501 |
|
||||
502 | /// @todo ALX |
|
|||
503 | // impl->updateVariableRequest(varRequestId); |
|
|||
504 | } |
|
317 | } | |
505 |
|
318 | |||
506 |
void VariableController::onDataProvided( |
|
319 | void VariableController::onDataProvided(std::shared_ptr<Variable> variable, VariableRequest request) | |
507 | const SqpRange &cacheRangeRequested, |
|
|||
508 | QVector<AcquisitionDataPacket> dataAcquired) |
|
|||
509 | { |
|
320 | { | |
510 | qCInfo(LOG_VariableController()) << "VariableController::onDataProvided"; |
|
321 | Q_ASSERT(variable != nullptr); | |
511 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); |
|
322 | ||
512 | auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries); |
|
323 | if (!impl->m_VariableModel->containsVariable(variable)) { | |
513 | if (!varRequestId.isNull()) { |
|
324 | qCCritical(LOG_VariableController()) | |
514 | impl->updateVariableRequest(varRequestId); |
|
325 | << QObject::tr("Can't update date of variable %1: variable is not registered (anymore)") | |
|
326 | .arg(variable->name()); | |||
|
327 | return; | |||
515 | } |
|
328 | } | |
|
329 | ||||
|
330 | variable->setCacheRange(request.m_CacheRangeRequested); | |||
|
331 | variable->mergeDataSeries(request.m_Result); | |||
|
332 | emit variable->updated(); | |||
516 | } |
|
333 | } | |
517 |
|
334 | |||
518 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
335 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
519 | { |
|
336 | { | |
520 | if (auto var = impl->findVariable(identifier)) { |
|
337 | /// @todo ALX | |
521 | impl->m_VariableModel->setDataProgress(var, progress); |
|
338 | // if (auto var = impl->findVariable(identifier)) { | |
522 | } |
|
339 | // impl->m_VariableModel->setDataProgress(var, progress); | |
523 | else { |
|
340 | // } | |
524 | qCCritical(LOG_VariableController()) |
|
341 | // else { | |
525 | << tr("Impossible to notify progression of a null variable"); |
|
342 | // qCCritical(LOG_VariableController()) | |
526 | } |
|
343 | // << tr("Impossible to notify progression of a null variable"); | |
|
344 | // } | |||
527 | } |
|
345 | } | |
528 |
|
346 | |||
529 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) |
|
347 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) | |
530 | { |
|
348 | { | |
531 | /// @todo ALX |
|
349 | /// @todo ALX | |
532 | // qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" |
|
350 | // qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested" | |
533 | // << QThread::currentThread()->objectName(); |
|
351 | // << QThread::currentThread()->objectName(); | |
534 |
|
352 | |||
535 | // auto it = impl->m_VariableToIdentifierMap.find(variable); |
|
353 | // auto it = impl->m_VariableToIdentifierMap.find(variable); | |
536 | // if (it != impl->m_VariableToIdentifierMap.cend()) { |
|
354 | // if (it != impl->m_VariableToIdentifierMap.cend()) { | |
537 | // impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); |
|
355 | // impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second); | |
538 | // } |
|
356 | // } | |
539 | // else { |
|
357 | // else { | |
540 | // qCWarning(LOG_VariableController()) |
|
358 | // qCWarning(LOG_VariableController()) | |
541 | // << tr("Aborting progression of inexistant variable detected !!!") |
|
359 | // << tr("Aborting progression of inexistant variable detected !!!") | |
542 | // << QThread::currentThread()->objectName(); |
|
360 | // << QThread::currentThread()->objectName(); | |
543 | // } |
|
361 | // } | |
544 | } |
|
362 | } | |
545 |
|
363 | |||
546 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) |
|
364 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) | |
547 | { |
|
365 | { | |
548 | qCDebug(LOG_VariableController()) |
|
366 | impl->m_VariableSynchronizer->addGroup(synchronizationGroupId); | |
549 | << "TORM: VariableController::onAddSynchronizationGroupId" |
|
|||
550 | << QThread::currentThread()->objectName() << synchronizationGroupId; |
|
|||
551 | auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>(); |
|
|||
552 | impl->m_GroupIdToVariableSynchronizationGroupMap.insert( |
|
|||
553 | std::make_pair(synchronizationGroupId, vSynchroGroup)); |
|
|||
554 | } |
|
367 | } | |
555 |
|
368 | |||
556 | void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId) |
|
369 | void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId) | |
557 | { |
|
370 | { | |
558 |
impl->m_ |
|
371 | impl->m_VariableSynchronizer->removeGroup(synchronizationGroupId); | |
559 | } |
|
372 | } | |
560 |
|
373 | |||
561 | void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, |
|
374 | void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, | |
562 | QUuid synchronizationGroupId) |
|
375 | QUuid synchronizationGroupId) | |
563 |
|
||||
564 | { |
|
376 | { | |
565 | qCDebug(LOG_VariableController()) |
|
377 | impl->m_VariableSynchronizer->addVariable(variable, synchronizationGroupId); | |
566 | << "TORM: VariableController::onAddSynchronized" << synchronizationGroupId; |
|
|||
567 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); |
|
|||
568 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { |
|
|||
569 | auto groupIdToVSGIt |
|
|||
570 | = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); |
|
|||
571 | if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { |
|
|||
572 | impl->m_VariableIdGroupIdMap.insert( |
|
|||
573 | std::make_pair(varToVarIdIt->second, synchronizationGroupId)); |
|
|||
574 | groupIdToVSGIt->second->addVariableId(varToVarIdIt->second); |
|
|||
575 | } |
|
|||
576 | else { |
|
|||
577 | qCCritical(LOG_VariableController()) |
|
|||
578 | << tr("Impossible to synchronize a variable with an unknown sycnhronization group") |
|
|||
579 | << variable->name(); |
|
|||
580 | } |
|
|||
581 | } |
|
|||
582 | else { |
|
|||
583 | qCCritical(LOG_VariableController()) |
|
|||
584 | << tr("Impossible to synchronize a variable with no identifier") << variable->name(); |
|
|||
585 | } |
|
|||
586 | } |
|
378 | } | |
587 |
|
379 | |||
588 | void VariableController::desynchronize(std::shared_ptr<Variable> variable, |
|
380 | void VariableController::desynchronize(std::shared_ptr<Variable> variable, | |
589 | QUuid synchronizationGroupId) |
|
381 | QUuid synchronizationGroupId) | |
590 | { |
|
382 | { | |
591 | // Gets variable id |
|
383 | impl->m_VariableSynchronizer->removeVariable(variable, synchronizationGroupId); | |
592 | auto variableIt = impl->m_VariableToIdentifierMap.find(variable); |
|
|||
593 | if (variableIt == impl->m_VariableToIdentifierMap.cend()) { |
|
|||
594 | qCCritical(LOG_VariableController()) |
|
|||
595 | << tr("Can't desynchronize variable %1: variable identifier not found") |
|
|||
596 | .arg(variable->name()); |
|
|||
597 | return; |
|
|||
598 | } |
|
|||
599 |
|
||||
600 | // Gets synchronization group |
|
|||
601 | auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); |
|
|||
602 | if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { |
|
|||
603 | qCCritical(LOG_VariableController()) |
|
|||
604 | << tr("Can't desynchronize variable %1: unknown synchronization group") |
|
|||
605 | .arg(variable->name()); |
|
|||
606 | return; |
|
|||
607 | } |
|
|||
608 |
|
||||
609 | auto variableId = variableIt->second; |
|
|||
610 |
|
||||
611 | // Removes variable from synchronization group |
|
|||
612 | auto synchronizationGroup = groupIt->second; |
|
|||
613 | synchronizationGroup->removeVariableId(variableId); |
|
|||
614 |
|
||||
615 | // Removes link between variable and synchronization group |
|
|||
616 | impl->m_VariableIdGroupIdMap.erase(variableId); |
|
|||
617 | } |
|
384 | } | |
618 |
|
385 | |||
619 | void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, |
|
386 | void VariableController::onRequestDataLoading(const QVector<std::shared_ptr<Variable> > &variables, | |
620 | const SqpRange &range, const SqpRange &oldRange, |
|
387 | const SqpRange &range, const SqpRange &oldRange, | |
621 | bool synchronise) |
|
388 | bool synchronise) | |
622 | { |
|
389 | { | |
623 | // NOTE: oldRange isn't really necessary since oldRange == variable->range(). |
|
390 | // Set of variables that have been processed | |
|
391 | std::set<std::shared_ptr<Variable> > processedVariables; | |||
|
392 | std::map<std::shared_ptr<Variable>, SqpRange> oldRanges; | |||
624 |
|
393 | |||
625 | // we want to load data of the variable for the dateTime. |
|
394 | // Process requests for all variables | |
626 | // First we check if the cache contains some of them. |
|
|||
627 | // For the other, we ask the provider to give them. |
|
|||
628 | for (const auto &var : variables) { |
|
395 | for (const auto &var : variables) { | |
629 | impl->processRequest(var, range); |
|
396 | impl->processRequest(var, range); | |
|
397 | processedVariables.insert(var); | |||
630 | } |
|
398 | } | |
631 |
|
399 | |||
|
400 | // Handles synchronisation | |||
632 | if (synchronise) { |
|
401 | if (synchronise) { | |
633 | // Get the group ids |
|
402 | for (const auto &variable : variables) { | |
634 | qCDebug(LOG_VariableController()) |
|
403 | // Finds the variables in the same synchronization group | |
635 | << "TORM VariableController::onRequestDataLoading for synchro var ENABLE"; |
|
404 | auto synchronizedVariables | |
636 | auto groupIds = std::set<QUuid>{}; |
|
405 | = impl->m_VariableSynchronizer->synchronizedVariables(variable); | |
637 | auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{}; |
|
406 | for (const auto &synchronizedVariable : synchronizedVariables) { | |
638 | for (const auto &var : variables) { |
|
407 | // Processes variable (if it hasn't been already processed) | |
639 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var); |
|
408 | if (processedVariables.count(synchronizedVariable) == 0) { | |
640 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { |
|
409 | auto rangeRequested = computeSynchroRangeRequested( | |
641 | auto vId = varToVarIdIt->second; |
|
410 | synchronizedVariable->range(), range, oldRange); | |
642 | auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); |
|
411 | impl->processRequest(synchronizedVariable, rangeRequested); | |
643 | if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { |
|
412 | processedVariables.insert(synchronizedVariable); | |
644 | auto gId = varIdToGroupIdIt->second; |
|
|||
645 | groupIdToOldRangeMap.insert(std::make_pair(gId, var->range())); |
|
|||
646 | if (groupIds.find(gId) == groupIds.cend()) { |
|
|||
647 | qCDebug(LOG_VariableController()) << "Synchro detect group " << gId; |
|
|||
648 | groupIds.insert(gId); |
|
|||
649 | } |
|
|||
650 | } |
|
|||
651 | } |
|
|||
652 | } |
|
|||
653 |
|
||||
654 | // We assume here all group ids exist |
|
|||
655 | for (const auto &gId : groupIds) { |
|
|||
656 | auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId); |
|
|||
657 | auto vSyncIds = vSynchronizationGroup->getIds(); |
|
|||
658 | qCDebug(LOG_VariableController()) << "Var in synchro group "; |
|
|||
659 | for (auto vId : vSyncIds) { |
|
|||
660 | auto var = impl->findVariable(vId); |
|
|||
661 |
|
||||
662 | // Don't process already processed var |
|
|||
663 | if (!variables.contains(var)) { |
|
|||
664 | if (var != nullptr) { |
|
|||
665 | qCDebug(LOG_VariableController()) |
|
|||
666 | << "processRequest synchro for" << var->name(); |
|
|||
667 | auto vSyncRangeRequested = computeSynchroRangeRequested( |
|
|||
668 | var->range(), range, groupIdToOldRangeMap.at(gId)); |
|
|||
669 | qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; |
|
|||
670 | impl->processRequest(var, vSyncRangeRequested); |
|
|||
671 | } |
|
|||
672 | else { |
|
|||
673 | qCCritical(LOG_VariableController()) |
|
|||
674 |
|
||||
675 | << tr("Impossible to synchronize a null variable"); |
|
|||
676 | } |
|
|||
677 | } |
|
413 | } | |
678 | } |
|
414 | } | |
679 | } |
|
415 | } | |
680 | } |
|
416 | } | |
681 |
|
||||
682 | /// @todo ALX |
|
|||
683 | // impl->updateVariableRequest(varRequestId); |
|
|||
684 | } |
|
417 | } | |
685 |
|
418 | |||
686 |
|
||||
687 | void VariableController::initialize() |
|
419 | void VariableController::initialize() | |
688 | { |
|
420 | { | |
689 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
421 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
690 | impl->m_WorkingMutex.lock(); |
|
422 | impl->m_WorkingMutex.lock(); | |
691 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
423 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
692 | } |
|
424 | } | |
693 |
|
425 | |||
694 | void VariableController::finalize() |
|
426 | void VariableController::finalize() | |
695 | { |
|
427 | { | |
696 | impl->m_WorkingMutex.unlock(); |
|
428 | impl->m_WorkingMutex.unlock(); | |
697 | } |
|
429 | } | |
698 |
|
430 | |||
699 | void VariableController::waitForFinish() |
|
431 | void VariableController::waitForFinish() | |
700 | { |
|
432 | { | |
701 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
433 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
702 | } |
|
434 | } |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (775 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now