##// END OF EJS Templates
Mostly working Spectrograms...
Mostly working Spectrograms Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r73:68c01155acd2
r84:483146a07a5f
Show More
VCTransaction.h
148 lines | 3.6 KiB | text/x-c | CLexer
Basic asynchronous variable update, still a lot to do...
r17 #include "Variable/VariableSynchronizationGroup2.h"
Switched to new TS impl, but quite broken!...
r67
Basic asynchronous variable update, still a lot to do...
r17 #include <Common/containers.h>
#include <Common/debug.h>
#include <Data/DataProviderParameters.h>
#include <Data/DateTimeRange.h>
Switched to new TS impl, but quite broken!...
r67 #include <Data/DateTimeRangeHelper.h>
Basic asynchronous variable update, still a lot to do...
r17 #include <Data/IDataProvider.h>
Switched to new TS impl, but quite broken!...
r67 #include <QObject>
#include <QReadWriteLock>
#include <QRunnable>
#include <QThreadPool>
#include <TimeSeries.h>
#include <Variable/Variable2.h>
Basic asynchronous variable update, still a lot to do...
r17
struct VCTransaction
{
Switched to new TS impl, but quite broken!...
r67 VCTransaction(QUuid refVar, DateTimeRange range, int varCount)
: refVar{refVar}, range{range}, _remainingVars{varCount}
{}
Moved all maps in VC2 to a dedicated struct to ease thread safety more...
r19
Switched to new TS impl, but quite broken!...
r67 QUuid refVar;
DateTimeRange range;
bool ready()
{
QReadLocker lock{&_lock};
return _remainingVars == 0;
}
bool done()
{
QWriteLocker lock{&_lock};
_remainingVars -= 1;
return _remainingVars == 0;
}
Moved all maps in VC2 to a dedicated struct to ease thread safety more...
r19
private:
Switched to new TS impl, but quite broken!...
r67 QReadWriteLock _lock;
int _remainingVars;
Basic asynchronous variable update, still a lot to do...
r17 };
Switched to new TS impl, but quite broken!...
r67 class TransactionExe : public QObject, public QRunnable
Basic asynchronous variable update, still a lot to do...
r17 {
Switched to new TS impl, but quite broken!...
r67 Q_OBJECT
std::shared_ptr<Variable2> _variable;
std::shared_ptr<IDataProvider> _provider;
std::vector<DateTimeRange> _ranges;
DateTimeRange _range;
bool _overwrite;
Basic asynchronous variable update, still a lot to do...
r17 public:
Switched to new TS impl, but quite broken!...
r67 TransactionExe(const std::shared_ptr<Variable2>& variable,
const std::shared_ptr<IDataProvider>& provider,
const std::vector<DateTimeRange>& ranges, DateTimeRange range,
bool overwrite = true)
: _variable{variable}, _provider{provider}, _ranges{ranges},
_range{range}, _overwrite{overwrite}
{
setAutoDelete(true);
}
void run() override
{
std::vector<TimeSeries::ITimeSerie*> data;
for(auto range : _ranges)
Basic asynchronous variable update, still a lot to do...
r17 {
Switched to new TS impl, but quite broken!...
r67 auto ds = _provider->getData(
DataProviderParameters{{range}, _variable->metadata()});
if(ds) data.push_back(ds);
Basic asynchronous variable update, still a lot to do...
r17 }
Switched to new TS impl, but quite broken!...
r67 if(_overwrite)
_variable->setData(data, _range, true);
else
Basic asynchronous variable update, still a lot to do...
r17 {
Fixed all tests \o/ with new TS impl...
r68 data.push_back(_variable->data().get());
Switched to new TS impl, but quite broken!...
r67 _variable->setData(data, _range, true);
Basic asynchronous variable update, still a lot to do...
r17 }
Few minor tweaks and removed memory leak.....
r73 std::for_each(std::begin(data), std::end(data),
[](TimeSeries::ITimeSerie* ts) { delete ts; });
Switched to new TS impl, but quite broken!...
r67 emit transactionComplete();
}
Basic asynchronous variable update, still a lot to do...
r17 signals:
Switched to new TS impl, but quite broken!...
r67 void transactionComplete();
Basic asynchronous variable update, still a lot to do...
r17 };
Implemented variable duplication and some code move...
r20
class VCTransactionsQueues
{
Switched to new TS impl, but quite broken!...
r67 QReadWriteLock _mutex{QReadWriteLock::Recursive};
std::map<QUuid, std::optional<std::shared_ptr<VCTransaction>>>
_nextTransactions;
std::map<QUuid, std::optional<std::shared_ptr<VCTransaction>>>
_pendingTransactions;
Implemented variable duplication and some code move...
r20 public:
Switched to new TS impl, but quite broken!...
r67 void addEntry(QUuid id)
{
QWriteLocker lock{&_mutex};
_nextTransactions[id] = std::nullopt;
_pendingTransactions[id] = std::nullopt;
}
Implemented variable duplication and some code move...
r20
Switched to new TS impl, but quite broken!...
r67 void removeEntry(QUuid id)
{
QWriteLocker lock{&_mutex};
_nextTransactions.erase(id);
_pendingTransactions.erase(id);
}
Implemented variable duplication and some code move...
r20
Switched to new TS impl, but quite broken!...
r67 std::map<QUuid, std::optional<std::shared_ptr<VCTransaction>>>
pendingTransactions()
{
QReadLocker lock{&_mutex};
return _pendingTransactions;
}
Implemented variable duplication and some code move...
r20
Switched to new TS impl, but quite broken!...
r67 std::map<QUuid, std::optional<std::shared_ptr<VCTransaction>>>
nextTransactions()
{
QReadLocker lock{&_mutex};
return _nextTransactions;
}
Implemented variable duplication and some code move...
r20
Switched to new TS impl, but quite broken!...
r67 std::optional<std::shared_ptr<VCTransaction>> start(QUuid id)
{
QWriteLocker lock{&_mutex};
_pendingTransactions[id] = _nextTransactions[id];
_nextTransactions[id] = std::nullopt;
return _pendingTransactions[id];
}
Implemented variable duplication and some code move...
r20
Switched to new TS impl, but quite broken!...
r67 void enqueue(QUuid id, std::shared_ptr<VCTransaction> transaction)
{
QWriteLocker lock{&_mutex};
_nextTransactions[id] = transaction;
}
Implemented variable duplication and some code move...
r20
Switched to new TS impl, but quite broken!...
r67 void complete(QUuid id)
{
QWriteLocker lock{&_mutex};
_pendingTransactions[id] = std::nullopt;
}
Implemented variable duplication and some code move...
r20
Switched to new TS impl, but quite broken!...
r67 bool active(QUuid id)
{
QReadLocker lock{&_mutex};
return _nextTransactions[id].has_value() ||
_pendingTransactions[id].has_value();
}
Implemented variable duplication and some code move...
r20 };