@@ -26,6 +26,7 public: | |||||
26 | const std::shared_ptr<IDataProvider>& provider, |
|
26 | const std::shared_ptr<IDataProvider>& provider, | |
27 | const DateTimeRange &range); |
|
27 | const DateTimeRange &range); | |
28 |
|
28 | |||
|
29 | std::shared_ptr<Variable> cloneVariable(const std::shared_ptr<Variable>& variable); | |||
29 | void deleteVariable(const std::shared_ptr<Variable>& variable); |
|
30 | void deleteVariable(const std::shared_ptr<Variable>& variable); | |
30 | void changeRange(const std::shared_ptr<Variable>& variable, const DateTimeRange& r); |
|
31 | void changeRange(const std::shared_ptr<Variable>& variable, const DateTimeRange& r); | |
31 | void asyncChangeRange(const std::shared_ptr<Variable>& variable, const DateTimeRange& r); |
|
32 | void asyncChangeRange(const std::shared_ptr<Variable>& variable, const DateTimeRange& r); |
@@ -65,3 +65,62 public: | |||||
65 | signals: |
|
65 | signals: | |
66 | void transactionComplete(); |
|
66 | void transactionComplete(); | |
67 | }; |
|
67 | }; | |
|
68 | ||||
|
69 | class VCTransactionsQueues | |||
|
70 | { | |||
|
71 | QReadWriteLock _mutex{QReadWriteLock::Recursive}; | |||
|
72 | std::map<QUuid,std::optional<std::shared_ptr<VCTransaction>>> _nextTransactions; | |||
|
73 | std::map<QUuid,std::optional<std::shared_ptr<VCTransaction>>> _pendingTransactions; | |||
|
74 | public: | |||
|
75 | void addEntry(QUuid id) | |||
|
76 | { | |||
|
77 | QWriteLocker lock{&_mutex}; | |||
|
78 | _nextTransactions[id] = std::nullopt; | |||
|
79 | _pendingTransactions[id] = std::nullopt; | |||
|
80 | } | |||
|
81 | ||||
|
82 | void removeEntry(QUuid id) | |||
|
83 | { | |||
|
84 | QWriteLocker lock{&_mutex}; | |||
|
85 | _nextTransactions.erase(id); | |||
|
86 | _pendingTransactions.erase(id); | |||
|
87 | } | |||
|
88 | ||||
|
89 | std::map<QUuid,std::optional<std::shared_ptr<VCTransaction>>> pendingTransactions() | |||
|
90 | { | |||
|
91 | QReadLocker lock{&_mutex}; | |||
|
92 | return _pendingTransactions; | |||
|
93 | } | |||
|
94 | ||||
|
95 | std::map<QUuid,std::optional<std::shared_ptr<VCTransaction>>> nextTransactions() | |||
|
96 | { | |||
|
97 | QReadLocker lock{&_mutex}; | |||
|
98 | return _nextTransactions; | |||
|
99 | } | |||
|
100 | ||||
|
101 | std::optional<std::shared_ptr<VCTransaction>> start(QUuid id) | |||
|
102 | { | |||
|
103 | QWriteLocker lock{&_mutex}; | |||
|
104 | _pendingTransactions[id] = _nextTransactions[id]; | |||
|
105 | _nextTransactions[id] = std::nullopt; | |||
|
106 | return _pendingTransactions[id]; | |||
|
107 | } | |||
|
108 | ||||
|
109 | void enqueue(QUuid id, std::shared_ptr<VCTransaction> transaction) | |||
|
110 | { | |||
|
111 | QWriteLocker lock{&_mutex}; | |||
|
112 | _nextTransactions[id] = transaction; | |||
|
113 | } | |||
|
114 | ||||
|
115 | void complete(QUuid id) | |||
|
116 | { | |||
|
117 | QWriteLocker lock{&_mutex}; | |||
|
118 | _pendingTransactions[id] = std::nullopt; | |||
|
119 | } | |||
|
120 | ||||
|
121 | bool active(QUuid id) | |||
|
122 | { | |||
|
123 | QReadLocker lock{&_mutex}; | |||
|
124 | return _nextTransactions[id].has_value() || _pendingTransactions[id].has_value(); | |||
|
125 | } | |||
|
126 | }; |
@@ -14,64 +14,6 | |||||
14 | #include <Variable/private/VCTransaction.h> |
|
14 | #include <Variable/private/VCTransaction.h> | |
15 | #include <QCoreApplication> |
|
15 | #include <QCoreApplication> | |
16 |
|
16 | |||
17 | class Transactions |
|
|||
18 | { |
|
|||
19 | QReadWriteLock _mutex{QReadWriteLock::Recursive}; |
|
|||
20 | std::map<QUuid,std::optional<std::shared_ptr<VCTransaction>>> _nextTransactions; |
|
|||
21 | std::map<QUuid,std::optional<std::shared_ptr<VCTransaction>>> _pendingTransactions; |
|
|||
22 | public: |
|
|||
23 | void addEntry(QUuid id) |
|
|||
24 | { |
|
|||
25 | QWriteLocker lock{&_mutex}; |
|
|||
26 | _nextTransactions[id] = std::nullopt; |
|
|||
27 | _pendingTransactions[id] = std::nullopt; |
|
|||
28 | } |
|
|||
29 |
|
||||
30 | void removeEntry(QUuid id) |
|
|||
31 | { |
|
|||
32 | QWriteLocker lock{&_mutex}; |
|
|||
33 | _nextTransactions.erase(id); |
|
|||
34 | _pendingTransactions.erase(id); |
|
|||
35 | } |
|
|||
36 |
|
||||
37 | std::map<QUuid,std::optional<std::shared_ptr<VCTransaction>>> pendingTransactions() |
|
|||
38 | { |
|
|||
39 | QReadLocker lock{&_mutex}; |
|
|||
40 | return _pendingTransactions; |
|
|||
41 | } |
|
|||
42 |
|
||||
43 | std::map<QUuid,std::optional<std::shared_ptr<VCTransaction>>> nextTransactions() |
|
|||
44 | { |
|
|||
45 | QReadLocker lock{&_mutex}; |
|
|||
46 | return _nextTransactions; |
|
|||
47 | } |
|
|||
48 |
|
||||
49 | std::optional<std::shared_ptr<VCTransaction>> start(QUuid id) |
|
|||
50 | { |
|
|||
51 | QWriteLocker lock{&_mutex}; |
|
|||
52 | _pendingTransactions[id] = _nextTransactions[id]; |
|
|||
53 | _nextTransactions[id] = std::nullopt; |
|
|||
54 | return _pendingTransactions[id]; |
|
|||
55 | } |
|
|||
56 |
|
||||
57 | void enqueue(QUuid id, std::shared_ptr<VCTransaction> transaction) |
|
|||
58 | { |
|
|||
59 | QWriteLocker lock{&_mutex}; |
|
|||
60 | _nextTransactions[id] = transaction; |
|
|||
61 | } |
|
|||
62 |
|
||||
63 | void complete(QUuid id) |
|
|||
64 | { |
|
|||
65 | QWriteLocker lock{&_mutex}; |
|
|||
66 | _pendingTransactions[id] = std::nullopt; |
|
|||
67 | } |
|
|||
68 |
|
||||
69 | bool active(QUuid id) |
|
|||
70 | { |
|
|||
71 | QReadLocker lock{&_mutex}; |
|
|||
72 | return _nextTransactions[id].has_value() || _pendingTransactions[id].has_value(); |
|
|||
73 | } |
|
|||
74 | }; |
|
|||
75 |
|
17 | |||
76 |
|
18 | |||
77 | class VariableController2::VariableController2Private |
|
19 | class VariableController2::VariableController2Private | |
@@ -160,7 +102,7 class VariableController2::VariableController2Private | |||||
160 | QReadWriteLock _lock{QReadWriteLock::Recursive}; |
|
102 | QReadWriteLock _lock{QReadWriteLock::Recursive}; | |
161 | }_maps; |
|
103 | }_maps; | |
162 | QThreadPool _ThreadPool; |
|
104 | QThreadPool _ThreadPool; | |
163 | Transactions _transactions; |
|
105 | VCTransactionsQueues _transactions; | |
164 | std::unique_ptr<VariableCacheStrategy> _cacheStrategy; |
|
106 | std::unique_ptr<VariableCacheStrategy> _cacheStrategy; | |
165 |
|
107 | |||
166 | void _transactionComplete(QUuid group, std::shared_ptr<VCTransaction> transaction) |
|
108 | void _transactionComplete(QUuid group, std::shared_ptr<VCTransaction> transaction) | |
@@ -277,7 +219,7 public: | |||||
277 | /* |
|
219 | /* | |
278 | * This dtor has to like this even if this is ugly, because default dtor would rely on |
|
220 | * This dtor has to like this even if this is ugly, because default dtor would rely on | |
279 | * declaration order to destruct members and that would always lead to regressions when |
|
221 | * declaration order to destruct members and that would always lead to regressions when | |
280 |
* modifying |
|
222 | * modifying class members | |
281 | */ |
|
223 | */ | |
282 | ~VariableController2Private() |
|
224 | ~VariableController2Private() | |
283 | { |
|
225 | { | |
@@ -296,6 +238,15 public: | |||||
296 | return newVar; |
|
238 | return newVar; | |
297 | } |
|
239 | } | |
298 |
|
240 | |||
|
241 | std::shared_ptr<Variable> cloneVariable(const std::shared_ptr<Variable>& variable) | |||
|
242 | { | |||
|
243 | auto newVar = variable->clone(); | |||
|
244 | _maps.synchronize(newVar,std::nullopt); | |||
|
245 | _maps.addVariable(newVar,_maps.provider(*variable),_maps.group(*newVar)); | |||
|
246 | this->_transactions.addEntry(*_maps.group(*newVar)); | |||
|
247 | return newVar; | |||
|
248 | } | |||
|
249 | ||||
299 | bool hasPendingTransactions(const std::shared_ptr<Variable>& variable) |
|
250 | bool hasPendingTransactions(const std::shared_ptr<Variable>& variable) | |
300 | { |
|
251 | { | |
301 | return _transactions.active(*_maps.group(*variable)); |
|
252 | return _transactions.active(*_maps.group(*variable)); | |
@@ -303,10 +254,6 public: | |||||
303 |
|
254 | |||
304 | void deleteVariable(const std::shared_ptr<Variable>& variable) |
|
255 | void deleteVariable(const std::shared_ptr<Variable>& variable) | |
305 | { |
|
256 | { | |
306 | /* |
|
|||
307 | * Removing twice a var is ok but a var without provider has to be a hard error |
|
|||
308 | * this means we got the var controller in an inconsistent state |
|
|||
309 | */ |
|
|||
310 | _maps.removeVariable(variable); |
|
257 | _maps.removeVariable(variable); | |
311 | } |
|
258 | } | |
312 |
|
259 | |||
@@ -363,6 +310,11 std::shared_ptr<Variable> VariableController2::createVariable(const QString &nam | |||||
363 | return var; |
|
310 | return var; | |
364 | } |
|
311 | } | |
365 |
|
312 | |||
|
313 | std::shared_ptr<Variable> VariableController2::cloneVariable(const std::shared_ptr<Variable> &variable) | |||
|
314 | { | |||
|
315 | return impl->cloneVariable(variable); | |||
|
316 | } | |||
|
317 | ||||
366 | void VariableController2::deleteVariable(const std::shared_ptr<Variable>& variable) |
|
318 | void VariableController2::deleteVariable(const std::shared_ptr<Variable>& variable) | |
367 | { |
|
319 | { | |
368 | impl->deleteVariable(variable); |
|
320 | impl->deleteVariable(variable); |
@@ -20,8 +20,8 | |||||
20 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),\ |
|
20 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),\ | |
21 | QDate(2018,8,7),QTime(16,00));\ |
|
21 | QDate(2018,8,7),QTime(16,00));\ | |
22 | auto name1 = vc.createVariable("name1", {}, provider, range);\ |
|
22 | auto name1 = vc.createVariable("name1", {}, provider, range);\ | |
23 |
auto name2 = vc.c |
|
23 | auto name2 = vc.cloneVariable(name1);\ | |
24 |
auto name3 = vc.c |
|
24 | auto name3 = vc.cloneVariable(name2);\ | |
25 | vc.synchronize(name1,name2);\ |
|
25 | vc.synchronize(name1,name2);\ | |
26 |
|
26 | |||
27 |
|
27 |
General Comments 0
You need to be logged in to leave comments.
Login now