Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
Executable
+427
@@ -0,0 +1,427 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVector>
|
||||
|
||||
#include <dds/core/xtypes/EnumType.hpp>
|
||||
|
||||
#include "codegen_export.h"
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
class QDomElement;
|
||||
|
||||
namespace CodeGen
|
||||
{
|
||||
|
||||
enum ExerciseDependency
|
||||
{
|
||||
Undefined = 0,
|
||||
Global = 0x1,
|
||||
Exercise = 0x2,
|
||||
GlobalAndExercise = 0x3
|
||||
};
|
||||
|
||||
struct EnumKeyValuePair
|
||||
{
|
||||
QString key;
|
||||
int value = 0;
|
||||
};
|
||||
|
||||
struct EnumInformation
|
||||
{
|
||||
QString enumName;
|
||||
QString tableName;
|
||||
QString serviceName;
|
||||
QVector<EnumKeyValuePair> values;
|
||||
|
||||
bool isValid() const { return !enumName.isEmpty(); }
|
||||
};
|
||||
|
||||
struct ColumnInformation
|
||||
{
|
||||
QString columnName;
|
||||
QString datatype;
|
||||
QString comment;
|
||||
QString defaultValue;
|
||||
bool isPrimaryKey = false;
|
||||
bool isAssignmentForPrimaryTablePk = false;
|
||||
bool isForeignKey = false;
|
||||
bool generateSelectRemove = false;
|
||||
bool canBeNull = true;
|
||||
bool hasSequence = false;
|
||||
bool isOptional = false;
|
||||
int sequenceStart = 0;
|
||||
int sequenceIncrement = 0;
|
||||
};
|
||||
|
||||
struct IdlColumnInformation
|
||||
{
|
||||
QString name;
|
||||
QString type;
|
||||
QString comment;
|
||||
bool isKey = false;
|
||||
bool isOptional = false;
|
||||
bool isTranslatable = false;
|
||||
};
|
||||
|
||||
|
||||
struct ForeignKeyInformation
|
||||
{
|
||||
struct Endpoint
|
||||
{
|
||||
QString service;
|
||||
QString serviceAbbr;
|
||||
QString schema;
|
||||
QString tableName;
|
||||
QString columnName;
|
||||
};
|
||||
|
||||
QString name;
|
||||
Endpoint source;
|
||||
Endpoint destination;
|
||||
enum class OnDeleteAction
|
||||
{
|
||||
NoAction,
|
||||
Cascade,
|
||||
Restrict,
|
||||
SetNull,
|
||||
SetDefault
|
||||
} deleteAction = OnDeleteAction::Cascade;
|
||||
};
|
||||
|
||||
struct CustomServiceFunctionInformation
|
||||
{
|
||||
QString methodName;
|
||||
QString returnValue;
|
||||
QString signature;
|
||||
bool isConst = false;
|
||||
QVector<QString> paramTypes;
|
||||
QVector<QString> paramNames;
|
||||
enum class Type
|
||||
{
|
||||
Db,
|
||||
DbNotify,
|
||||
Dtc
|
||||
} type = Type::Db;
|
||||
};
|
||||
|
||||
struct DbNotifcationInformation : public CustomServiceFunctionInformation
|
||||
{
|
||||
DbNotifcationInformation() = default;
|
||||
explicit DbNotifcationInformation(const CustomServiceFunctionInformation &d)
|
||||
: CustomServiceFunctionInformation(d)
|
||||
{}
|
||||
enum class NotificationType
|
||||
{
|
||||
BeforeInsert,
|
||||
AfterInsert,
|
||||
BeforeUpdate,
|
||||
AfterUpdate,
|
||||
BeforeDelete,
|
||||
AfterDelete
|
||||
};
|
||||
QVector<NotificationType> notificationType;
|
||||
};
|
||||
|
||||
struct ConstraintInformation
|
||||
{
|
||||
enum struct Type
|
||||
{
|
||||
unknown = 0x00,
|
||||
unique = 0x01,
|
||||
index = 0x02
|
||||
} type = Type::unknown;
|
||||
QString name;
|
||||
QStringList affectedColumns;
|
||||
};
|
||||
|
||||
struct TableInformation
|
||||
{
|
||||
QString name;
|
||||
QString structName;
|
||||
QString comment;
|
||||
QVector<ColumnInformation> plainColumns;
|
||||
QVector<QSharedPointer<ForeignKeyInformation> > foreignKeys;
|
||||
QVector<ConstraintInformation> constraints;
|
||||
ExerciseDependency exerciseDependency = ExerciseDependency::Undefined;
|
||||
|
||||
QSharedPointer<ForeignKeyInformation> fkInformationForColumn(const QString &tableName,
|
||||
const QString &columnName) const
|
||||
{
|
||||
for (const QSharedPointer<ForeignKeyInformation> &fki : foreignKeys)
|
||||
{
|
||||
if (fki->source.columnName == columnName &&
|
||||
fki->source.tableName == tableName)
|
||||
return fki;
|
||||
}
|
||||
return QSharedPointer<ForeignKeyInformation>();
|
||||
}
|
||||
};
|
||||
|
||||
struct ViewInformation
|
||||
{
|
||||
QString name;
|
||||
QString comment;
|
||||
QString structName;
|
||||
QString baseTable;
|
||||
QString baseSchema;
|
||||
QString filter;
|
||||
ExerciseDependency exerciseDependency = ExerciseDependency::Undefined;
|
||||
};
|
||||
|
||||
struct ServiceStructInformation
|
||||
{
|
||||
QString name;
|
||||
QString primaryTable;
|
||||
bool hasStaticContent = false;
|
||||
|
||||
bool operator<(const ServiceStructInformation &o) const
|
||||
{
|
||||
if (hasStaticContent != o.hasStaticContent)
|
||||
return hasStaticContent < o.hasStaticContent;
|
||||
if (name != o.name)
|
||||
return name < o.name;
|
||||
return primaryTable < o.primaryTable;
|
||||
}
|
||||
QVector<DbNotifcationInformation> dbNotifications;
|
||||
};
|
||||
|
||||
struct TopicTypeInformationBase
|
||||
{
|
||||
TopicTypeInformationBase() = default;
|
||||
virtual ~TopicTypeInformationBase() = default;
|
||||
|
||||
QString name;
|
||||
QString baseValueType;
|
||||
QString comment;
|
||||
bool isDataObject = false;
|
||||
bool dtsAutogen = true;
|
||||
bool dtcAutogen = true;
|
||||
bool recordTopic = false;
|
||||
bool routeToClient = true;
|
||||
bool routeToServer = false;
|
||||
bool routeInReplay = true;
|
||||
bool autosubscribe = true;
|
||||
|
||||
dds::core::xtypes::ExtensibilityKind extensibility = dds::core::xtypes::ExtensibilityKind::EXTENSIBLE;
|
||||
|
||||
virtual bool isValid() const { return !name.isEmpty(); }
|
||||
|
||||
bool operator<(const TopicTypeInformationBase &o) const
|
||||
{
|
||||
if (name != o.name)
|
||||
return name < o.name;
|
||||
return baseValueType < o.baseValueType;
|
||||
}
|
||||
};
|
||||
|
||||
struct TopicTypeInformation : public TopicTypeInformationBase
|
||||
{
|
||||
QVector<IdlColumnInformation> columns;
|
||||
};
|
||||
|
||||
struct FunctionTopic
|
||||
{
|
||||
QString name;
|
||||
QString requestTopicType;
|
||||
QString replyTopicType;
|
||||
QString requestTopicName;
|
||||
QString replyTopicName;
|
||||
bool routeInReplay = false;
|
||||
};
|
||||
|
||||
|
||||
class CODEGEN_BASE_EXPORT XmlReader final
|
||||
{
|
||||
public:
|
||||
XmlReader();
|
||||
|
||||
bool readServiceFile(const QString &svcFile,
|
||||
const QString &idlServiceInfoFile = QString(),
|
||||
const XmlReader *parent = nullptr);
|
||||
QString errorString() const
|
||||
{
|
||||
return m_errorString;
|
||||
}
|
||||
|
||||
QString getServiceNamespace() const { return m_svcNamespace; }
|
||||
QString getServiceAbbr() const { return m_svcAbbr; }
|
||||
QStringList getGroupNames() const { return m_groupNames; }
|
||||
int getPrio() const { return m_prio;}
|
||||
QStringList getProcNames() const { return m_svcProcNames; }
|
||||
bool hasCustomRecordReplayPlugin() const { return m_customRecordReplay; }
|
||||
bool getDevMode() const { return m_svcDevMode; }
|
||||
|
||||
bool isServiceExerciseIndependent() const { return m_exerciseDependency == ExerciseDependency::Global; }
|
||||
ExerciseDependency defaultExerciseDependency() const { return m_exerciseDependency; }
|
||||
|
||||
QMap<QString, QVector<QString> > getDbClass2TableMapping() const { return m_dbClassTables; }
|
||||
|
||||
|
||||
QMap<QString, QString> getStruct2BaseClassRelations() const { return m_struct2BaseClass; }
|
||||
QVector<ServiceStructInformation> getStructToGenerate() const { return m_structsToGenerate; }
|
||||
|
||||
|
||||
QMap<QString, TopicTypeInformation > getIdlStructInformation() const { return m_idlStructsToGenerate; }
|
||||
QVector<TopicTypeInformation> getIdlStructToGenerate() const
|
||||
{
|
||||
QVector<TopicTypeInformation> res;
|
||||
res.reserve(m_idlStructsToGenerate.size());
|
||||
auto it = m_idlStructsToGenerate.constBegin();
|
||||
while (it != m_idlStructsToGenerate.constEnd())
|
||||
{
|
||||
res.append(it.value());
|
||||
++it;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QSharedPointer<TableInformation> > getTables() const
|
||||
{
|
||||
return m_tables;
|
||||
}
|
||||
QMap<QString, QSharedPointer<ViewInformation> > getViews() const
|
||||
{
|
||||
return m_views;
|
||||
}
|
||||
QSharedPointer<TableInformation> getTable(const QString &table) const
|
||||
{
|
||||
return m_tables.value(table);
|
||||
}
|
||||
QVector<EnumInformation> getEnumerations() const
|
||||
{
|
||||
return m_enumerations;
|
||||
}
|
||||
QVector<IdlColumnInformation> getIdlColumns(const QString &structName) const
|
||||
{
|
||||
return m_idlStructsToGenerate.value(structName).columns;
|
||||
}
|
||||
|
||||
QVector<FunctionTopic> getFunctionTopics() const
|
||||
{
|
||||
return m_functionTopics;
|
||||
}
|
||||
QVector<TopicTypeInformation> getExternalTopicTypes() const
|
||||
{
|
||||
return m_externalTopicTypes;
|
||||
}
|
||||
|
||||
QString idlFileForService(const QString &serviceName) const
|
||||
{
|
||||
return getIdlFileForService(m_idlFiles, serviceName);
|
||||
}
|
||||
|
||||
QString xmlFileForService(const QString &serviceName) const
|
||||
{
|
||||
return getIdlFileForService(m_xmlFiles, serviceName);
|
||||
}
|
||||
|
||||
QMap<QString, bool> usedServices() const
|
||||
{
|
||||
return m_usedServices;
|
||||
}
|
||||
|
||||
QVector<CustomServiceFunctionInformation> getCustomFunctions() const
|
||||
{
|
||||
return m_customFunctions;
|
||||
}
|
||||
|
||||
|
||||
TopicTypeInformation loadExternalTopicType(const QString &externalServiceName, const QString &topicTypeName);
|
||||
EnumInformation getExternalEnumeration(const QString &externalServiceName, const QString &enumName, bool verbose);
|
||||
|
||||
static ExerciseDependency string2ExerciseDependency(const QString &str);
|
||||
|
||||
XmlReader(const XmlReader &) = delete;
|
||||
XmlReader &operator=(const XmlReader &) = delete;
|
||||
|
||||
private:
|
||||
void parseDBSserviceStructs(const QDomElement &rootElement);
|
||||
void parseDBTables(const QDomElement &rootElement);
|
||||
void parseDBViews(const QDomElement &rootElement);
|
||||
void parseEnumerations(const QDomElement &rootElement);
|
||||
void parseTopicTypes(const QDomElement &rootElement);
|
||||
void parseFunctionTopics(const QDomElement &rootElement);
|
||||
void parseCustomDtcFunctions(const QDomElement &rootElement);
|
||||
|
||||
static QString getAttribute(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional = false);
|
||||
static bool getAttributeBool(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional, bool defaultValue);
|
||||
static int getAttributeInt(const QDomElement &element,
|
||||
const QString &attributeName,
|
||||
bool bOptional = false, int defaultValue = 0);
|
||||
|
||||
ColumnInformation parseTableColumn(const QDomElement &column, const QString &tableName) const;
|
||||
IdlColumnInformation parseIdlStructColumn(const QDomElement &column) const;
|
||||
|
||||
QSharedPointer<ForeignKeyInformation> parseForeignKey(const QDomElement &foreignKey) const;
|
||||
ForeignKeyInformation::Endpoint parseForeignKeyEndpoint(const QString &foreignKeyName,
|
||||
const QDomElement &endpoint) const;
|
||||
ConstraintInformation parseConstraint(const QDomElement &constraint) const;
|
||||
CustomServiceFunctionInformation parseCustomFunction(const QDomElement &customFunc, CustomServiceFunctionInformation::Type funcType) const;
|
||||
DbNotifcationInformation parseDbNotification(const QDomElement &customFunc) const;
|
||||
bool loadExternalService(const QString &serviceName);
|
||||
void loadIdlInfofile(const QString &idlServiceInfoFile);
|
||||
QString getIdlFileForService(const QMap<QString, QString> &data, const QString &serviceName) const;
|
||||
QString serviceNameAbbreviation(const QString &serviceName) const;
|
||||
void getServiceNameInfoFromFilePath(const QVector<QStringRef> &parts);
|
||||
static QString serviceNamespaceFromFile(const QString &fn);
|
||||
|
||||
|
||||
QString m_svcNamespace;
|
||||
|
||||
QString m_svcAbbr;
|
||||
|
||||
QStringList m_svcProcNames;
|
||||
|
||||
bool m_customRecordReplay;
|
||||
|
||||
|
||||
ExerciseDependency m_exerciseDependency{ExerciseDependency::Exercise};
|
||||
|
||||
|
||||
QMap<QString, QVector<QString> > m_dbClassTables;
|
||||
|
||||
|
||||
QMap<QString, QString> m_struct2BaseClass;
|
||||
QVector<ServiceStructInformation> m_structsToGenerate;
|
||||
|
||||
QMap<QString, TopicTypeInformation> m_idlStructsToGenerate;
|
||||
|
||||
QVector<FunctionTopic> m_functionTopics;
|
||||
QVector<TopicTypeInformation> m_externalTopicTypes;
|
||||
QVector<CustomServiceFunctionInformation> m_customFunctions;
|
||||
|
||||
|
||||
QMap<QString, QSharedPointer<TableInformation> > m_tables;
|
||||
QMap<QString, QSharedPointer<ViewInformation> > m_views;
|
||||
QVector<EnumInformation> m_enumerations;
|
||||
QString m_errorString;
|
||||
|
||||
|
||||
QMap<QString, QSharedPointer<XmlReader> > m_externalXmlInformations;
|
||||
QMap<QString, QString> m_idlFiles;
|
||||
QMap<QString, QString> m_xmlFiles;
|
||||
QMap<QString, bool> m_usedServices;
|
||||
QMap<QString, QString> m_fullServiceName2Abbreviation;
|
||||
|
||||
QStringList m_groupNames;
|
||||
int m_prio;
|
||||
bool m_svcDevMode{false};
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user