158 lines
5.8 KiB
C++
Executable File
158 lines
5.8 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Provide Record/Replay functionality for dds topics in a service
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2016-07-07
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <map>
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QHash>
|
|
|
|
namespace DDSConnector
|
|
{
|
|
class DdsConnector;
|
|
}
|
|
|
|
class NSqlQuery;
|
|
namespace RecordReplay
|
|
{
|
|
class RecordReplayPlugin
|
|
{
|
|
public:
|
|
RecordReplayPlugin() = default;
|
|
virtual ~RecordReplayPlugin() = default;
|
|
|
|
virtual QString pluginName() const = 0;
|
|
|
|
/**
|
|
* @brief initialize all data topic clients for the topics to record (for record management)
|
|
* @return true on success
|
|
*/
|
|
virtual bool initDtc(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector,
|
|
int exerciseId) = 0;
|
|
/**
|
|
* @brief initialize all data topic server for the topics to replay (for situation replay)
|
|
* @return true on success
|
|
*/
|
|
virtual bool initDts(const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector,
|
|
int exerciseId,
|
|
bool bCanHandleSchemas,
|
|
NSqlQuery &query) = 0;
|
|
|
|
/**
|
|
* @brief initialize the plugin for copying data from one database to another
|
|
* @return true on success
|
|
*/
|
|
virtual bool initCopy(int exerciseId, bool bCanHandleSchemasRead, bool bCanHandleSchemasWrite) = 0;
|
|
|
|
/**
|
|
* @brief copy all recorded data from one database to another
|
|
* @param queryFrom a NSqlQuery which has a database connection to the database to read from
|
|
* @param queryToa NSqlQuery which has a database connection to the database to write to
|
|
* @param fromTime start time of the data to copy
|
|
* @param toTime end time of the data to copy
|
|
* @return true on success
|
|
*/
|
|
virtual bool copyData(NSqlQuery &queryFrom, NSqlQuery &queryTo, qint64 fromTime, qint64 toTime) = 0;
|
|
|
|
/**
|
|
* @brief get the service short name used in rec_snaphsot.svc_name)
|
|
*/
|
|
virtual QString svcShortName() const = 0;
|
|
|
|
// recording functions
|
|
/**
|
|
* @brief Read data from dds and save it to the corresponding tables
|
|
* @param query the NSqlQuery to use (speedup to not create a query on every call)
|
|
* @param minRecordSampleTime the minimum sample time seen during this call
|
|
* @return true on success (can only be false on wrong schema)
|
|
*/
|
|
virtual bool ddsTopicsToDatabase(NSqlQuery &query, QHash<QString, qint64> &minRecordSampleTimes) = 0;
|
|
// publishing functions
|
|
/**
|
|
* @brief Read all data to be able to publish all topics with the correct for the given start time
|
|
* @param query the NSqlQuery to use (speedup to not create a query on every call)
|
|
* @param startTime the timestamp for which the replay should be started
|
|
* @return true on success
|
|
*/
|
|
virtual bool setReplayStartTime(NSqlQuery &query, qint64 startTime) = 0;
|
|
/**
|
|
* @brief Read data from database and store it in internal buffers for a specific time stamp
|
|
* @param query the NSqlQuery to use (speedup to not create a query on every call)
|
|
* @param fromTime lower time for range to read (including)
|
|
* @param toTime higher time for range to read (excluding)
|
|
* @return true on success
|
|
*/
|
|
virtual bool ddsTopicsFromDatabase(NSqlQuery &query, qint64 fromTime, qint64 toTime) = 0;
|
|
/**
|
|
* @brief publish all data in the internal buffers to dds until the desired time is reached
|
|
* @param desiredTime last timestamp to publish data for
|
|
* @return true on success
|
|
*/
|
|
virtual bool publishData(qint64 desiredTime) = 0;
|
|
/**
|
|
* @brief wait for possible asnyc operations which must be finished for the given time and publish this data
|
|
* @param desiredTime last timestamp to publish data for
|
|
* @return true on success
|
|
*/
|
|
virtual bool waitForAsyncOperations(qint64 desiredTime) { Q_UNUSED(desiredTime); return true; }
|
|
/**
|
|
* @brief clear the internal buffer (filled by ddsTopicsFromDatabase()) - e.g. for a new starting point
|
|
* also remove the data from dds
|
|
*/
|
|
virtual void clearData() = 0;
|
|
|
|
// structure/functions for snapshot creation
|
|
struct RecSnapshot // see rec_db.h / RecSnapshot
|
|
{
|
|
qint64 timeStamp = 0;
|
|
std::map<int64_t, int64_t> recIdArray;
|
|
RecSnapshot() = default;
|
|
RecSnapshot(qint64 timeStamp_, const std::map<int64_t, int64_t> &recIdArray_)
|
|
: timeStamp(timeStamp_)
|
|
, recIdArray(recIdArray_)
|
|
{}
|
|
};
|
|
/**
|
|
* @brief Run through the given time range with the given interval and collect the latest database entries (id, key) for snapshot creation
|
|
* @param query the NSqlQuery to use (speedup to not create a query on every call)
|
|
* @param fromTime lower time for range to read (including)
|
|
* @param toTime higher time for range to read (excluding)
|
|
* @param interval sanpshot creation interval
|
|
* @return snapshots to create
|
|
*/
|
|
virtual std::map<QString, std::vector<RecSnapshot>> getSnapshotTimes(NSqlQuery &query,
|
|
qint64 toTime,
|
|
qint64 interval,
|
|
const QHash<QString, qint64> &minRecordedSampleTimes) = 0;
|
|
|
|
/**
|
|
* @brief Return all topics which are handled (= recorded/replayed) by this plugin
|
|
*/
|
|
virtual QVector<QString> getRecordTopicNames() const = 0;
|
|
|
|
/**
|
|
* @brief Return all record/replay tables
|
|
*/
|
|
virtual QVector<QString> getRecordTableNames() const = 0;
|
|
|
|
/**
|
|
* @brief "SELECT min(sample_time) FROM rec_<topic_name>"
|
|
* @param query the NSqlQuery to use (speedup to not create a query on every call)
|
|
* @param topicName the topic to get the minimum sample time for
|
|
* @param defaultValue the default value if no sample is found
|
|
* @return
|
|
*/
|
|
virtual qint64 getMinimumSampleTime(NSqlQuery &q, const QString &topicName, qint64 defaultValue) const = 0;
|
|
};
|
|
}
|
|
|
|
Q_DECLARE_INTERFACE(RecordReplay::RecordReplayPlugin, "special:3:recordreplay")
|