Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+303
@@ -0,0 +1,303 @@
|
||||
/**
|
||||
* Handler for base download coordination
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, NLST, 15-03-2018
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QObject>
|
||||
#include <QSqlDatabase>
|
||||
#include <QTimer>
|
||||
|
||||
// db
|
||||
#include <AssetManagement/asm_db.h>
|
||||
#include <Evaluations/evl_db.h>
|
||||
#include <ExerciseManagement/exm_db.h>
|
||||
#include <FileManagement/flm_db.h>
|
||||
#include <InfrastructureManagement/ism_db.h>
|
||||
#include <Messaging/msg_db.h>
|
||||
#include <MarkerManagement/mrk_db.h>
|
||||
#include <EffectShowClient/esc_db.h>
|
||||
#include <FilterManagement/flt_db.h>
|
||||
#include <AreaEffectSimulation/aes_db.h>
|
||||
|
||||
#include <ParticipantManagement/ppm_db.h>
|
||||
#include <OperatorManagement/opm_db.h>
|
||||
#include <DBAdministration/exercise_table_generator.h>
|
||||
|
||||
// dds
|
||||
#include <OcBaseDownload/obd_fts.h>
|
||||
#include <ServiceManagement/scm_dtc.h>
|
||||
#include <ServiceManagement/scm_ftc.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
|
||||
namespace OcBaseDownload
|
||||
{
|
||||
class CopyDatabase;
|
||||
class DbDataEntry
|
||||
{
|
||||
public:
|
||||
virtual ~DbDataEntry() = default;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class DbData : public DbDataEntry
|
||||
{
|
||||
public:
|
||||
explicit DbData(std::vector<T> &&dataVec)
|
||||
: m_dataVec(std::move(dataVec))
|
||||
{}
|
||||
~DbData() = default;
|
||||
|
||||
const std::vector<T> &data() const { return m_dataVec; }
|
||||
|
||||
private:
|
||||
std::vector<T> m_dataVec;
|
||||
};
|
||||
|
||||
class MainHandler;
|
||||
class HandlerBaseDownload : public QObject
|
||||
, protected Interface::Fts::StartBaseDownloadRequestHandler
|
||||
, protected Interface::Fts::LifeUpdateRequestHandler
|
||||
, protected ServiceManagement::Interface::Ftc::RestartGroupReplyHandler
|
||||
, protected ServiceManagement::Interface::Ftc::StopGroupReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HandlerBaseDownload(MainHandler *mainHandler,
|
||||
QObject *parent = nullptr);
|
||||
~HandlerBaseDownload();
|
||||
|
||||
bool init();
|
||||
|
||||
// handling ErrorMessage
|
||||
void handleErrorMessage(const QString &err);
|
||||
|
||||
void receiveAsmData();
|
||||
void receiveExmData();
|
||||
void receiveIsmData();
|
||||
|
||||
void receivePpmEx0Data();
|
||||
|
||||
void receivePpmExNData();
|
||||
|
||||
void receiveOpmData();
|
||||
|
||||
void receiveFlmData();
|
||||
|
||||
|
||||
private slots:
|
||||
void updateBaseDownloadReply();
|
||||
|
||||
private:
|
||||
|
||||
enum State
|
||||
{
|
||||
NotStarted = 0,
|
||||
Finished = 0x8000,
|
||||
StepCount = 20, // Update if adding new steps ...
|
||||
SingleStepSize = 100 / StepCount,
|
||||
|
||||
ServicePortsInformationRequest = 1,
|
||||
ServicePortsInformationFinished = ServicePortsInformationRequest | Finished,
|
||||
|
||||
// Donwloads
|
||||
AsmDownloadRequest = 2,
|
||||
AsmDownloadFinished = AsmDownloadRequest | Finished,
|
||||
ExmDownloadRequest = 3,
|
||||
ExmDownloadFinished = ExmDownloadRequest | Finished,
|
||||
IsmDownloadRequest = 4,
|
||||
IsmDownloadFinished = IsmDownloadRequest | Finished,
|
||||
PpmDownloadEx0Request = 5,
|
||||
PpmDownloadEx0Finished = PpmDownloadEx0Request | Finished,
|
||||
PpmDownloadExNRequest = 6,
|
||||
PpmDownloadExNFinished = PpmDownloadExNRequest | Finished,
|
||||
OpmDownloadRequest = 7,
|
||||
OpmDownloadFinished = OpmDownloadRequest | Finished,
|
||||
FlmDownloadRequest = 8,
|
||||
FlmDownloadFinished = FlmDownloadRequest | Finished,
|
||||
|
||||
// removing old exercise
|
||||
DeletingOldExercise = 20,
|
||||
DeletingOldExerciseFinished = DeletingOldExercise | Finished,
|
||||
|
||||
// storing new db data
|
||||
InsertingAsmData = 21,
|
||||
InsertingAsmDataFinished = InsertingAsmData | Finished,
|
||||
InsertingPpmEx0Data = 22,
|
||||
InsertingPpmEx0DataFinished = InsertingPpmEx0Data | Finished,
|
||||
InsertingExmData = 23,
|
||||
InsertingExmDataFinished = InsertingExmData | Finished,
|
||||
InsertingIsmData = 24,
|
||||
InsertingIsmDataFinished = InsertingIsmData | Finished,
|
||||
InsertingPpmExNData = 25,
|
||||
InsertingPpmExNDataFinished = InsertingPpmExNData | Finished,
|
||||
InsertingOpmData = 26,
|
||||
InsertingOpmDataFinished = InsertingOpmData | Finished,
|
||||
InsertingFlmData = 27,
|
||||
InsertingFlmDataFinished = InsertingFlmData | Finished,
|
||||
|
||||
UpdatingLtsConfig = 28,
|
||||
UpdatingLtsConfigFinished = UpdatingLtsConfig | Finished,
|
||||
|
||||
CopyDatabaseRequest = 29,
|
||||
CopyDatabaseFinished = CopyDatabaseRequest | Finished,
|
||||
|
||||
DropOldDatabaseRequest = 30,
|
||||
DropOldDatabaseFinished = DropOldDatabaseRequest | Finished,
|
||||
|
||||
CopyDataRequest = 31,
|
||||
CopyDataFinished = CopyDataRequest | Finished,
|
||||
};
|
||||
|
||||
enum DbDataType
|
||||
{
|
||||
AsmTrainingArea = 1,
|
||||
AsmLocation = 2,
|
||||
AsmAsset = 3,
|
||||
AsmTechnicalArea = 4,
|
||||
|
||||
ExmExercise = 10,
|
||||
ExmExercisePhase = 11,
|
||||
ExmExerciseStateChange = 12,
|
||||
|
||||
IsmAsset = 20,
|
||||
IsmMainStructureElement = 21,
|
||||
IsmStructureElement = 23,
|
||||
IsmStructureElementFootprint = 24,
|
||||
IsmMountingPointAsset = 25,
|
||||
IsmMountingPointSchedule = 26,
|
||||
IsmMountingPointPlan = 27,
|
||||
IsmSpecialArea = 28,
|
||||
|
||||
PpmEquipmentType = 30,
|
||||
PpmType = 31,
|
||||
PpmParty = 32,
|
||||
PpmParticipant = 33,
|
||||
|
||||
OpmGroup = 40,
|
||||
OpmGroupGroup = 41,
|
||||
OpmOperator = 42,
|
||||
OpmOperatorExercise = 43,
|
||||
OpmSettings = 44,
|
||||
OpmAccessControlLevel = 45,
|
||||
OpmAclAllow = 46,
|
||||
OpmAclDeny = 47,
|
||||
|
||||
FlmFolder = 50,
|
||||
FlmFileContent = 51
|
||||
};
|
||||
|
||||
void onStartBaseDownloadRequest(const rti::core::SampleIdentity &cookie,
|
||||
const StartBaseDownloadRequest &request) override;
|
||||
|
||||
void onLifeUpdateRequest(const rti::core::SampleIdentity &cookie,
|
||||
const LiveUpdateRequest &request) override;
|
||||
|
||||
// state, connection, db and service handling
|
||||
void switchLog(State state, const std::string ¤tStep);
|
||||
void stateFinished();
|
||||
void switchState();
|
||||
void dropOldDatabase();
|
||||
void onDropOldDatabaseFailed();
|
||||
void onDropOldDatabaseFinished();
|
||||
void copyDatabase();
|
||||
void onCopyDbFailed();
|
||||
void onCopyDbFinished();
|
||||
bool openDbConnection(const QString &databaseName);
|
||||
bool openRemoteDbConnection(const QString &remoteDatabaseName);
|
||||
|
||||
QSqlDatabase openDb(const QString &databaseName, bool remote, bool *bOk);
|
||||
void closeDb(QSqlDatabase &dbConn);
|
||||
template <typename T>
|
||||
const std::vector<T> &getDbDataVec(DbDataType type) const;
|
||||
|
||||
// download completion checks
|
||||
void checkForAsmFinished();
|
||||
void checkForExmFinished();
|
||||
void checkForIsmFinished();
|
||||
void checkForPpmEx0Finished();
|
||||
void checkForPpmExNFinished();
|
||||
void checkForOpmFinished();
|
||||
void checkForFlmFinished();
|
||||
|
||||
// inserting new data
|
||||
void removeOldExercises();
|
||||
void replaceAsmDbData();
|
||||
void createNewExercise();
|
||||
void replaceExmDbData();
|
||||
void replaceIsmDbData();
|
||||
void replacePpmEx0DbData();
|
||||
void insertPpmExNDbData(bool live = false);
|
||||
void replaceOpmDbData();
|
||||
void replaceFlmDbData();
|
||||
|
||||
void cleanup(const Core::FtReplyState &replyState, const std::string &errStr = std::string());
|
||||
|
||||
void retryCurrentSelect();
|
||||
void copyFromOldDatabase();
|
||||
void copyOldOpmData(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut) const;
|
||||
void copyOldEvlData(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut) const;
|
||||
void copyOldMsgData(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut) const;
|
||||
void copyOldFlmData(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut) const;
|
||||
void copyOldMrkData(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut) const;
|
||||
void copyOldEscData(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut) const;
|
||||
void copyOldFltData(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut) const;
|
||||
void copyOldAesData(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut) const;
|
||||
bool copyTable(const QSqlDatabase &dbIn, const QSqlDatabase &dbOut, QString tableName);
|
||||
bool fixUpSequence(const QSqlDatabase &dbOut, const QString &tableName);
|
||||
|
||||
void updateLtsConfig();
|
||||
void onStopGroupReply(const Core::FunctionReplyObject &reply) override;
|
||||
void onRestartGroupReply(const Core::FunctionReplyObject &reply) override;
|
||||
void restartCoreGroup();
|
||||
|
||||
QString currentDatabaseName() const;
|
||||
QString nextDatabaseName() const;
|
||||
int getFolderId(const QVector<FileManagement::Database::FlmFolder> &dataVec, const QString &folderName, int exerciseId) const;
|
||||
void checkAliveTimer();
|
||||
|
||||
std::shared_ptr<Interface::Fts> m_fts;
|
||||
std::shared_ptr<ServiceManagement::Interface::Dtc> m_scmDtc;
|
||||
std::shared_ptr<ServiceManagement::Interface::Ftc> m_scmFtc;
|
||||
|
||||
// DB data vector
|
||||
QMap<DbDataType, DbDataEntry *> m_dataVecMap;
|
||||
template <typename T>
|
||||
void storeToDataVecMap(DbDataType type, std::vector<T> &&dataVec)
|
||||
{
|
||||
delete m_dataVecMap.take(type);
|
||||
m_dataVecMap[type] = new DbData<T>(std::move(dataVec));
|
||||
}
|
||||
|
||||
rti::core::SampleIdentity m_baseDownloadCookie;
|
||||
BaseDownloadReply m_reply;
|
||||
QTimer *m_baseDownloadReplyUpdateTimer;
|
||||
|
||||
MainHandler *m_mainHandler;
|
||||
int m_exerciseId;
|
||||
int m_operatorId;
|
||||
QString m_hostname;
|
||||
//int m_currentPort;
|
||||
State m_currentState;
|
||||
|
||||
QSqlDatabase m_dbConnection;
|
||||
QSqlDatabase m_remoteDbConnection;
|
||||
QElapsedTimer m_aliveTimer;
|
||||
//int m_webSocketRetryCounter;
|
||||
int m_remoteDbRetryCounter;
|
||||
|
||||
QSet<int> m_stopGroupIds;
|
||||
|
||||
QVector<QString> m_databasesToDrop;
|
||||
CopyDatabase *m_copyDatabase;
|
||||
DBAdministration::ExerciseTableGenerator *m_exTblGen;
|
||||
|
||||
LOGGER_T &m_logger;
|
||||
};
|
||||
} // namespace OcBaseDownload
|
||||
Reference in new issue
Block a user