Qt6 Migration: Complete migration with DDS/RTI support and build validation

Major Changes:
- Merged latest Qt5 devel content from dlbo (292 files changed, 7 new dirs)
- Consolidated forward-declarations and include folders
- Removed unneeded modules per Niklas' repo check list

Build System Fixes:
- Fixed CMake VERSION_GREATER syntax in ParticipantManagement/CMakeLists.txt
- Added VLC packages (libvlc-dev, vlc-plugin-base) to docker_build.sh
- Added PostgreSQL dev packages (libpq-dev, postgresql-server-dev-all) to Dockerfile
- Fixed locale warnings (ANSI_X3.4-1968 → C.UTF-8)
- Fixed ArcGIS SDK path warnings when BUILD_ARCGIS=OFF

Code Generation Fixes:
- Fixed IDL enum collisions (PortType→CorePortType/DdsutPortType, PdmEventType)
- Fixed Grantlee template svc_translation.cpp.grantlee:
  - Changed {{ idl_enum.name }}_def:: to {{ idl_enum.name }}::
  - Fixed .underlying() calls for C++11 scoped enums (enum class)
- Removed generated files from repo (moc_*, *_dtc.h, *_ftc.h)

Validation:
- BUILD_RTI=ON: SUCCESS
- BUILD_RTI=OFF: SUCCESS
- C++17 standard maintained for RTI 7.7 compatibility
- Ubuntu 26.04 Docker environment verified

Remaining Warnings (expected):
- BgViewer, KDChart, KDReports, Poppler-Qt6 not found (optional features)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
torstenandCopilot committed 2026-09-15 18:20:26 +00:00
1 parent f23384bb68
commit 7173785915
18662 files changed
+4115092 -5435

No files matched your search

@@ -4,54 +4,30 @@
# $Author$
#
message(STATUS "Lts/Common: Entering CodeGen")
ADD_SUBDIRECTORY(CodeGen)
message(STATUS "Lts/Common: Entering httq")
ADD_SUBDIRECTORY(httq)
#ADD_SUBDIRECTORY(LtsBotan)
message(STATUS "Lts/Common: Entering LtsCommandLineParser")
ADD_SUBDIRECTORY(LtsCommandLineParser)
message(STATUS "Lts/Common: Entering LtsCoordTrans")
ADD_SUBDIRECTORY(LtsCoordTrans)
message(STATUS "Lts/Common: Entering LtsCoordinate")
ADD_SUBDIRECTORY(LtsCoordinate)
message(STATUS "Lts/Common: Entering LtsElevation")
ADD_SUBDIRECTORY(LtsElevation)
message(STATUS "Lts/Common: Entering LtsLicence")
ADD_SUBDIRECTORY(LtsLicence)
message(STATUS "Lts/Common: Entering LtsPluginManager")
ADD_SUBDIRECTORY(LtsPluginManager)
message(STATUS "Lts/Common: Entering LtsSession")
ADD_SUBDIRECTORY(LtsSession)
message(STATUS "Lts/Common: Entering LtsUtils")
ADD_SUBDIRECTORY(LtsUtils)
message(STATUS "Lts/Common: Entering LtsWidgets")
ADD_SUBDIRECTORY(LtsWidgets)
ADD_SUBDIRECTORY(LtsAppDescriptor)
ADD_SUBDIRECTORY(LtsAppManager)
ADD_SUBDIRECTORY(LtsMultiMonitor)
ADD_SUBDIRECTORY(LtsCommandLineParser)
ADD_SUBDIRECTORY(LtsCoordinate)
ADD_SUBDIRECTORY(LtsCoordTrans)
ADD_SUBDIRECTORY(LtsElevation)
ADD_SUBDIRECTORY(LtsLicence)
ADD_SUBDIRECTORY(LtsLogin)
ADD_SUBDIRECTORY(LtsMultiMonitor)
ADD_SUBDIRECTORY(LtsNotification)
ADD_SUBDIRECTORY(LtsTimeline)
ADD_SUBDIRECTORY(LtsTimelineClassic)
ADD_SUBDIRECTORY(LtsPluginManager)
ADD_SUBDIRECTORY(LtsPrinting)
ADD_SUBDIRECTORY(LtsSerialPortQuerry)
IF(BUILD_RTI)
ADD_SUBDIRECTORY(LtsScriptTimeline)
ENDIF()
IF(BUILD_LTSWEBSOCKET)
ADD_SUBDIRECTORY(LtsWebSocket)
ENDIF()
ADD_SUBDIRECTORY(LtsProjectionWorkstation)
ADD_SUBDIRECTORY(LtsRestClient)
ADD_SUBDIRECTORY(LtsScriptTimeline)
ADD_SUBDIRECTORY(LtsSerialPortQuerry)
ADD_SUBDIRECTORY(LtsSession)
ADD_SUBDIRECTORY(LtsTimeline)
ADD_SUBDIRECTORY(LtsUtils)
ADD_SUBDIRECTORY(LtsVirtualKeyboard)
ADD_SUBDIRECTORY(LtsWebSocket)
ADD_SUBDIRECTORY(LtsWidgets)
ADD_SUBDIRECTORY(PluginInterfaces)
ADD_SUBDIRECTORY(ProjectConfig)
ADD_SUBDIRECTORY(TopicEditorBase) # TODO: rename / move ?
#ADD_SUBDIRECTORY(LtsEventTimeline)
#ADD_SUBDIRECTORY(LtsTranslator)
# Placeholder test scaffolding for incremental migration
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CommonUnitTestsPlaceholder/CMakeLists.txt")
add_subdirectory(CommonUnitTestsPlaceholder)
endif()
ADD_SUBDIRECTORY(TopicEditorBase)
@@ -1,54 +1,62 @@
/**
* @RDE_HEADER@
* Generate cpp structs from xml
* $Id: DaoGeneratorGrantlee.cpp 50446 2020-03-18 10:29:57Z ehrlicher $
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/25_02_refactoring/Lts/Common/CodeGen/DaoGeneratorGrantlee.cpp $
* $Author: ehrlicher $
*/
#include "DaoGeneratorGrantlee.h"
#include "StructBuilder.h"
#include <NGLLogger/INGLLogger.h>
#include <ktexttemplate/context.h>
#include <grantlee/context.h>
using namespace CodeGen;
DaoGeneratorGrantlee::DaoGeneratorGrantlee() : GeneratorGrantleeBase("CodeGen.DaoGeneratorGrantlee") {}
DaoGeneratorGrantlee::DaoGeneratorGrantlee()
: GeneratorGrantleeBase("CodeGen.DaoGeneratorGrantlee")
{}
bool DaoGeneratorGrantlee::init(const XmlReader* reader, StructBuilder* structBuilder)
bool DaoGeneratorGrantlee::init(const XmlReader *reader,
StructBuilder *structBuilder)
{
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
return false;
if (!GeneratorGrantleeBase::initInternal(reader, structBuilder))
return false;
if (reader->isServiceExerciseIndependent())
m_ctx->insert(QStringLiteral("isExerciseIndependent"), QLatin1String("1"));
// Is Service exercise-independent?
if (reader->isServiceExerciseIndependent())
m_ctx->insert(QStringLiteral("isExerciseIndependent"), QLatin1String("1"));
bool bHasDbNotifications = false;
QVector<DbStructWrapper*> vlServiceStructs;
QVector<DbStructWrapper*> vlStaticDataStructs;
const QVector<CompleteStructInformation> csiData = structBuilder->structInformations();
vlServiceStructs.reserve(csiData.size());
vlStaticDataStructs.reserve(csiData.size());
for (const CompleteStructInformation& csi : csiData)
{
DbStructWrapper* dbStructWrapper(new DbStructWrapper(csi, this));
bool bHasDbNotifications = false;
QVector<DbStructWrapper *> vlServiceStructs;
QVector<DbStructWrapper *> vlStaticDataStructs;
const QVector<CompleteStructInformation> csiData = structBuilder->structInformations();
vlServiceStructs.reserve(csiData.size());
vlStaticDataStructs.reserve(csiData.size());
for (const CompleteStructInformation &csi : csiData)
{
DbStructWrapper *dbStructWrapper(new DbStructWrapper(csi, this));
if (csi.hasStaticContent)
vlStaticDataStructs += dbStructWrapper;
else
vlServiceStructs += dbStructWrapper;
if (!csi.dbNotifications.isEmpty())
bHasDbNotifications = true;
}
if (csi.hasStaticContent)
vlStaticDataStructs += dbStructWrapper;
else
vlServiceStructs += dbStructWrapper;
if (!csi.dbNotifications.isEmpty())
bHasDbNotifications = true;
}
if (structBuilder->needPoint3d())
m_ctx->insert(QStringLiteral("need_point3d"), QLatin1String("1"));
if (structBuilder->needPgArrayInclude())
m_ctx->insert(QStringLiteral("need_pgarray"), QLatin1String("1"));
m_ctx->insert(QStringLiteral("cpp_structs"), QVariant::fromValue(vlServiceStructs));
m_ctx->insert(QStringLiteral("data_structs"), QVariant::fromValue(vlStaticDataStructs));
if (bHasDbNotifications)
m_ctx->insert(QStringLiteral("has_db_notifications"), QLatin1String("1"));
if (structBuilder->needPoint3d())
m_ctx->insert(QStringLiteral("need_point3d"), QLatin1String("1"));
if (structBuilder->needPgArrayInclude())
m_ctx->insert(QStringLiteral("need_pgarray"), QLatin1String("1"));
m_ctx->insert(QStringLiteral("cpp_structs"), QVariant::fromValue(vlServiceStructs));
m_ctx->insert(QStringLiteral("data_structs"), QVariant::fromValue(vlStaticDataStructs));
if (bHasDbNotifications)
m_ctx->insert(QStringLiteral("has_db_notifications"), QLatin1String("1"));
m_ctx->insert(QStringLiteral("library_target"), QStringLiteral("COMMON"));
m_ctx->insert(QStringLiteral("library_target"), QStringLiteral("COMMON"));
exportUsedServices(reader);
exportUsedServices(reader);
return true;
return true;
}
@@ -1,11 +1,16 @@
/**
* @RDE_HEADER@
* Generate cpp structs from xml
* $Id: DaoGeneratorGrantlee.h 50446 2020-03-18 10:29:57Z ehrlicher $
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/25_02_refactoring/Lts/Common/CodeGen/DaoGeneratorGrantlee.h $
* $Author: ehrlicher $
*/
#pragma once
#include "GeneratorGrantleeBase.h"
#include "GrantleeWrappers.h"
#include "StructBuilder.h"
#include <QtCore/QObject>
#include "GeneratorGrantleeBase.h"
#include "StructBuilder.h"
#include "GrantleeWrappers.h"
#include "codegen_export.h"
namespace CodeGen
{
@@ -13,12 +18,13 @@ struct CompleteStructInformation;
class StructBuilder;
class XmlReader;
class DaoGeneratorGrantlee final : public GeneratorGrantleeBase
{
Q_OBJECT
public:
explicit DaoGeneratorGrantlee();
Q_OBJECT
public:
explicit DaoGeneratorGrantlee();
bool init(const XmlReader* reader, StructBuilder* structBuilder) override;
bool init(const XmlReader *reader, StructBuilder *structBuilder) override;
};
} // namespace CodeGen
@@ -20,9 +20,9 @@ namespace {{ namespace }}
//
QString toString({{ idl_enum.name }} state)
{
switch(static_cast<int>(state))
switch(state)
{{% for idl_member in idl_enum.member %}
case static_cast<int>({{ idl_enum.name }}::{{ idl_member.key }}): return QCoreApplication::translate("{{ idl_enum.name }}", "{{ idl_member.key }}");
case {{ idl_enum.name }}::{{ idl_member.key }}: return QCoreApplication::translate("{{ idl_enum.name }}", "{{ idl_member.key }}");
{% endfor %}
default: break;
}
@@ -1,95 +1,104 @@
/**
* @RDE_HEADER@
* App Descriptor - Class to modify App Descriptor JSON Documents
* $Id$
* $HeadURL$
* $Author$
*
* Created by Mike Wille, SLSE, 2016-10-24
*/
#pragma once
#include <QtCore/QStringList>
#include <QtCore/QVector>
#include <QVector>
#include <QStringList>
#ifndef LTSAPPDESCRIPTOR_EXPORT
#ifdef BUILD_STATIC_LIBRARIES
#define LTSAPPDESCRIPTOR_EXPORT
#else
#if defined(MAKE_LTSAPPDESCRIPTOR_LIB)
#define LTSAPPDESCRIPTOR_EXPORT Q_DECL_EXPORT
#else
#define LTSAPPDESCRIPTOR_EXPORT Q_DECL_IMPORT
#endif
#endif
# ifdef BUILD_STATIC_LIBRARIES
# define LTSAPPDESCRIPTOR_EXPORT
# else
# if defined(MAKE_LTSAPPDESCRIPTOR_LIB)
# define LTSAPPDESCRIPTOR_EXPORT Q_DECL_EXPORT
# else
# define LTSAPPDESCRIPTOR_EXPORT Q_DECL_IMPORT
# endif
# endif
#endif
namespace LtsAppDescriptor
{
enum class App {
Login = -1,
Situation = 0,
ResourceManager = 1,
PlanEditor = 2,
BuildingViewer = 3,
OC = 4,
OrgChart = 5,
Scripts = 6,
Snapshot = 8,
SystemMonitor = 9,
Timeline = 10,
SymbolEditor = 11,
ScriptEditorEssentialsView = 12,
BaseDownloader = 13,
OnlineHelp = 14,
ThpSituationReplay = 15,
SituationTablet = 17,
SilhouetteEditor = 18,
Shootback = 19,
SAAs = 20,
enum class App
{
Login = -1,
Situation = 0,
ResourceManager = 1,
PlanEditor = 2,
BuildingViewer = 3,
OC = 4,
OrgChart = 5,
Scripts = 6,
// merged into Scripts (aka. ScriptEditor) ScriptPlayer = 7,
Snapshot = 8,
SystemMonitor = 9,
Timeline = 10,
SymbolEditor = 11,
ScriptEditorEssentialsView = 12,
BaseDownloader = 13,
OnlineHelp = 14,
ThpSituationReplay = 15,
SituationTablet = 17,
SilhouetteEditor = 18, // for L400P2
Shootback = 19, // for L400P2
SAAs = 20, //Schnittstelle Adapter Adler
};
struct PluginInfo
{
enum class PluginType {
UNKNOWN,
DATA,
GUI,
};
enum class PluginType
{
UNKNOWN,
DATA,
GUI,
GUI_ELEMENT,
};
enum class Flag {
UNKNOWN = 1 << 0,
ACTIONS = 1 << 1,
MAIN = 1 << 2,
PAYLOAD = 1 << 3,
OPTION = 1 << 4,
};
enum class Flag
{
UNKNOWN = 1 << 0,
ACTIONS = 1 << 1,
MAIN = 1 << 2,
PAYLOAD = 1 << 3,
OPTION = 1 << 4,
};
PluginType type = PluginType::UNKNOWN;
QString iid;
QFlags<Flag> flags;
QStringList options;
PluginType type = PluginType::UNKNOWN;
QString iid;
QFlags<Flag> flags;
QStringList options;
};
struct AppDescription
{
App id = App::Login;
bool active = false;
bool visible = true;
QString appName;
QVector<int> requiredAcls;
QVector<PluginInfo> pluginInfos;
App id = App::Login;
bool active = false;
bool visible = true;
QString appName;
QVector<int> requiredAcls;
QVector<PluginInfo> pluginInfos;
bool isValid() const
{
return !appName.isEmpty();
}
bool isValid() const { return !appName.isEmpty(); }
};
typedef QVector<AppDescription> AppDescriptionVector;
namespace LtsAppDescriptor
namespace LtsAppDescriptor // TODO: make qobject class singleton - for tr
{
LTSAPPDESCRIPTOR_EXPORT App appFromInteger(int i);
LTSAPPDESCRIPTOR_EXPORT AppDescriptionVector getAppDescriptionVector(const QByteArray& jsonDocument,
QStringList& lastErrors,
const QStringList& ignoredPlugins,
QString& loginPluginIid);
} // namespace LtsAppDescriptor
LTSAPPDESCRIPTOR_EXPORT AppDescriptionVector getAppDescriptionVector(const QByteArray &jsonDocument, QStringList &lastErrors,
const QStringList &ignoredPlugins, QString &loginPluginIid);
}
} // namespace LtsAppDescriptor
@@ -1,416 +1,464 @@
/**
* @RDE_HEADER@
* plugin loader helper function
* $Id$
* $HeadURL$
* $Author$
*
* Created by Christian Ehrlicher, SLSE, 2016-07-07
*/
#include "lts_plugin_loader.h"
#include <LtsAppDescriptor/lts_app_descriptor.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <LtsAppDescriptor/lts_app_descriptor.h>
#include <QCoreApplication>
#include <QDirIterator>
#include <QtCore/QFileInfo>
#include <QtCore/QJsonObject>
#include <QFileInfo>
#include <QJsonObject>
#include <QPluginLoader>
#include <QMutableListIterator>
#include <QtCore/QPluginLoader>
#include <utility>
#include <QDebug>
namespace LtsPluginManager
{
struct LtsPluginLoaderHandler
{
LtsPluginLoader ltsPluginLoader;
static NGL::INGLLogger& logger()
{
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsPluginLoader");
}
static void cleanupPluginLoader();
LtsPluginLoader ltsPluginLoader;
static NGL::INGLLogger &logger() { return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsPluginLoader"); }
static void cleanupPluginLoader();
};
Q_GLOBAL_STATIC(LtsPluginLoaderHandler, s_ltsPluginLoader)
void LtsPluginLoaderHandler::cleanupPluginLoader()
{
if (s_ltsPluginLoader.exists())
s_ltsPluginLoader->ltsPluginLoader.unloadAllPlugins();
if (s_ltsPluginLoader.exists())
s_ltsPluginLoader->ltsPluginLoader.unloadAllPlugins();
}
LtsPluginLoader* LtsPluginLoader::getInstance()
LtsPluginLoader *LtsPluginLoader::getInstance()
{
if (!s_ltsPluginLoader.exists())
qAddPostRoutine(&LtsPluginLoaderHandler::cleanupPluginLoader);
return &s_ltsPluginLoader->ltsPluginLoader;
if (!s_ltsPluginLoader.exists())
qAddPostRoutine(&LtsPluginLoaderHandler::cleanupPluginLoader);
return &s_ltsPluginLoader->ltsPluginLoader;
}
LtsPluginLoader::~LtsPluginLoader()
{
unloadAllPlugins();
unloadAllPlugins();
}
void LtsPluginLoader::unloadAllPlugins()
{
for (auto& pi : std::as_const(m_loadedPlugins))
{
QPluginLoader* pluginLoader = pi.pluginLoader;
for (auto &pi : qAsConst(m_loadedPlugins))
{
QPluginLoader *pluginLoader = pi.pluginLoader;
delete pluginLoader->instance();
delete pluginLoader->instance();
if (!pluginLoader->unload())
qWarning() << "~LtsPluginLoader: could not unload" << pi.pluginName << pluginLoader->errorString();
if (!pluginLoader->unload())
qWarning() << "~LtsPluginLoader: could not unload" << pi.pluginName << pluginLoader->errorString();
delete pluginLoader;
}
m_loadedPlugins.clear();
delete pluginLoader;
}
m_loadedPlugins.clear();
}
void LtsPluginLoader::checkPlugins(const QVector<LtsAppDescriptor::AppDescription>& appVector, QStringList& errors)
void LtsPluginLoader::checkPlugins(const QVector<LtsAppDescriptor::AppDescription> &appVector,
QStringList &errors /* out */)
{
NGL::INGLLogger& logger = LtsPluginLoaderHandler::logger();
if (appVector.isEmpty())
{
errors += QStringLiteral("No Apps available");
return;
}
QVector<PluginInstance> dataPlugins;
QVector<PluginInstance> guiPlugins;
auto addDataPluginFn = [&](const PluginInstance& pi) {
dataPlugins.append(pi);
return true;
};
auto addGuiPluginFn = [&](const PluginInstance& pi) {
guiPlugins.append(pi);
return true;
};
if (!loadPlugins(PluginType::DATA, addDataPluginFn))
{
errors += QStringLiteral("failed to load data plugins");
return;
}
if (!loadPlugins(PluginType::GUI, addGuiPluginFn))
{
errors += QStringLiteral("failed to load gui plugins");
return;
}
auto checkDuplicateIidsFn = [&](const QVector<PluginInstance>& plugins, const QString& pluginType) {
typedef QMap<QString, QString> IidMap;
IidMap iids;
for (auto i3 = plugins.constBegin(); i3 != plugins.constEnd(); ++i3)
{
const PluginInstance& pin = *i3;
auto iidFound = iids.constFind(pin.pluginName);
if (iidFound != iids.constEnd())
errors += QStringLiteral("Iid duplicate for %1 plugin '%2'").arg(pluginType, pin.pluginName);
else
iids.insert(pin.pluginName, pin.fullFileName);
}
};
checkDuplicateIidsFn(dataPlugins, QStringLiteral("data"));
checkDuplicateIidsFn(guiPlugins, QStringLiteral("gui"));
QVector<PluginInstance> plugins(dataPlugins + guiPlugins);
for (auto i1 = appVector.constBegin(); i1 != appVector.constEnd(); ++i1)
{
const LtsAppDescriptor::AppDescription& app = *i1;
const QVector<LtsAppDescriptor::PluginInfo>& piVector = app.pluginInfos;
for (auto i2 = piVector.constBegin(); i2 != piVector.constEnd(); i2++)
{
const LtsAppDescriptor::PluginInfo& pi = *i2;
bool found = false;
for (auto i3 = plugins.constBegin(); i3 != plugins.constEnd(); ++i3)
{
const PluginInstance& pin = *i3;
if (pi.iid == pin.pluginName)
{
found = true;
break;
}
}
if (!found)
{
ERROR_LOG(logger) << "Plugin with iid '" << pi.iid << "' was requested but was not loaded!";
errors +=
QStringLiteral("App '%1' requires plugin '%2' that could not be found.").arg(app.appName, pi.iid);
}
}
}
NGL::INGLLogger &logger = LtsPluginLoaderHandler::logger();
if (appVector.isEmpty())
{
errors += QStringLiteral("No Apps available");
return;
}
QVector<PluginInstance> dataPlugins;
QVector<PluginInstance> guiPlugins;
auto addDataPluginFn = [&](const PluginInstance &pi)
{
dataPlugins.append(pi);
return true;
};
auto addGuiPluginFn = [&](const PluginInstance &pi)
{
guiPlugins.append(pi);
return true;
};
if (!loadPlugins(PluginType::DATA, addDataPluginFn))
{
errors += QStringLiteral("failed to load data plugins");
return;
}
if (!loadPlugins(PluginType::GUI, addGuiPluginFn))
{
errors += QStringLiteral("failed to load gui plugins");
return;
}
// check for duplicate iids per plugin type
auto checkDuplicateIidsFn = [&](const QVector<PluginInstance> &plugins, const QString &pluginType)
{
typedef QMap<QString /*iid*/, QString /*filename*/> IidMap;
IidMap iids;
for (auto i3 = plugins.constBegin(); i3 != plugins.constEnd(); ++i3)
{
const PluginInstance &pin = *i3;
auto iidFound = iids.constFind(pin.pluginName);
if (iidFound != iids.constEnd())
errors += QStringLiteral("Iid duplicate for %1 plugin '%2'").arg(pluginType, pin.pluginName);
else
iids.insert(pin.pluginName, pin.fullFileName);
}
};
checkDuplicateIidsFn(dataPlugins, QStringLiteral("data"));
checkDuplicateIidsFn(guiPlugins, QStringLiteral("gui"));
QVector<PluginInstance> plugins(dataPlugins + guiPlugins);
// check if all in apps.json requested plugins are available
for (auto i1 = appVector.constBegin(); i1 != appVector.constEnd(); ++i1) // Apps
{
const LtsAppDescriptor::AppDescription &app = *i1;
//WARNING_LOG(logger) << "Checking app '"<<app.appName<<"'";
const QVector<LtsAppDescriptor::PluginInfo> &piVector = app.pluginInfos;
for (auto i2 = piVector.constBegin(); i2 != piVector.constEnd(); i2++) // App's Required Plugins
{
const LtsAppDescriptor::PluginInfo &pi = *i2;
bool found = false;
for (auto i3 = plugins.constBegin(); i3 != plugins.constEnd(); ++i3) // Available Plugins
{
const PluginInstance &pin = *i3;
if (pi.iid == pin.pluginName)
{
found = true;
break;
}
}
if (!found)
{
ERROR_LOG(logger) << "Plugin with iid '" << pi.iid << "' was requested but was not loaded!";
errors += QStringLiteral("App '%1' requires plugin '%2' that could not be found.").arg(app.appName, pi.iid);
}
}
}
return;
}
bool LtsPluginLoader::loadPlugins(PluginType requestedPluginType,
const std::function<bool(const PluginInstance&)>& loadPlugin,
const QStringList& requiredPlugins, const QString& specialTopicTypeFilter,
const QStringList& optionalPlugins)
const std::function<bool(const PluginInstance &)> &loadPlugin,
const QStringList &requiredPlugins,
const QString &specialTopicTypeFilter,
const QStringList &optionalPlugins)
{
NGL::INGLLogger& logger = LtsPluginLoaderHandler::logger();
Q_ASSERT(requestedPluginType != PluginType::UNKNOWN);
NGL::INGLLogger &logger = LtsPluginLoaderHandler::logger();
Q_ASSERT(requestedPluginType != PluginType::UNKNOWN); // do not allow to look for unknown
QStringList requiredPluginsList = requiredPlugins;
QStringList optionalPluginsList = optionalPlugins;
bool checkPluginsLists = (!requiredPluginsList.isEmpty()) || (!optionalPluginsList.isEmpty());
QStringList requiredPluginsList = requiredPlugins; // copy ...
QStringList optionalPluginsList = optionalPlugins; // copy ...
bool checkPluginsLists = (!requiredPluginsList.isEmpty()) || (!optionalPluginsList.isEmpty());
if (checkPluginsLists && !m_loadedPlugins.isEmpty())
if (checkPluginsLists && !m_loadedPlugins.isEmpty()) // only lookup of there is something to lookup TODO: faster to NOT do that check?
{
{
QMutableListIterator<QString> i1(requiredPluginsList); // delete all plugins from the to-load list that were cached
while (i1.hasNext())
{
const QString pluginName = i1.next().toLower();
QMap<PluginKey, PluginInstance>::iterator i2 = m_loadedPlugins.find(PluginKey(requestedPluginType, pluginName));
if (i2 != m_loadedPlugins.end())
{
QMutableListIterator<QString> i1(requiredPluginsList);
DEBUG_LOG(logger) << "Plugin " << pluginName << " already loaded, using that instance";
while (i1.hasNext())
{
const QString pluginName = i1.next().toLower();
if (loadPlugin)
loadPlugin(i2.value());
QMap<PluginKey, PluginInstance>::iterator i2 =
m_loadedPlugins.find(PluginKey(requestedPluginType, pluginName));
if (i2 != m_loadedPlugins.end())
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " already loaded, using that instance";
if (loadPlugin)
loadPlugin(i2.value());
i1.remove();
}
}
}
{
QMutableListIterator<QString> i1(optionalPluginsList);
while (i1.hasNext())
{
const QString pluginName = i1.next().toLower();
QMap<PluginKey, PluginInstance>::iterator i2 =
m_loadedPlugins.find(PluginKey(requestedPluginType, pluginName));
if (i2 != m_loadedPlugins.end())
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " already loaded, using that instance";
if (loadPlugin)
loadPlugin(i2.value());
i1.remove();
}
}
i1.remove();
}
}
}
QFileInfo libPathInfo(QCoreApplication::applicationDirPath() + QStringLiteral("/../lib/"));
QString libPath(libPathInfo.absolutePath());
if (!libPathInfo.exists())
{
libPathInfo.setFile(QCoreApplication::applicationFilePath());
libPath = libPathInfo.absolutePath();
{
QMutableListIterator<QString> i1(optionalPluginsList); // delete all plugins from the to-load list that were cached
while (i1.hasNext())
{
const QString pluginName = i1.next().toLower();
QMap<PluginKey, PluginInstance>::iterator i2 = m_loadedPlugins.find(PluginKey(requestedPluginType, pluginName));
if (i2 != m_loadedPlugins.end())
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " already loaded, using that instance";
if (loadPlugin)
loadPlugin(i2.value());
i1.remove();
}
}
}
}
QFileInfo libPathInfo(QCoreApplication::applicationDirPath() + QStringLiteral("/../lib/"));
QString libPath(libPathInfo.absolutePath());
if (!libPathInfo.exists())
{
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* In case of windows systems all libs are located in application directory. But can't
* use QCoreApplication::applicationDirPath here, because it points some times to the
* wrong directory.
* 2016/10/18 JT
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
libPathInfo.setFile(QCoreApplication::applicationFilePath());
libPath = libPathInfo.absolutePath();
}
#ifdef Q_OS_WIN
const QStringList nameFilter = QStringList(QStringLiteral("*Plugin*.dll"));
const QStringList nameFilter = QStringList(QStringLiteral("*Plugin*.dll"));
#else
const QStringList nameFilter = QStringList(QStringLiteral("*Plugin*.so"));
const QStringList nameFilter = QStringList(QStringLiteral("*Plugin*.so"));
#endif
static const QStringList pluginTypes({QStringLiteral("data"), QStringLiteral("gui"), QStringLiteral("topic_type"),
QStringLiteral("project"), QStringLiteral("style"),
QStringLiteral("special")});
static const QStringList pluginTypes({QStringLiteral("data"),
QStringLiteral("gui"),
QStringLiteral("topic_type"),
QStringLiteral("project"),
QStringLiteral("style"),
QStringLiteral("special"),
QStringLiteral("gui_element")}); // #warning TODO: recordreplay is a data plugin ?
QDirIterator pluginDir(libPath, nameFilter, QDir::Files);
while (pluginDir.hasNext())
QDirIterator pluginDir(libPath, nameFilter, QDir::Files);
while (pluginDir.hasNext())
{
pluginDir.next();
const QString filename = pluginDir.fileName();
if (filename.contains(QStringLiteral("PluginInterface"), Qt::CaseSensitive))
continue;
const QString absoluteFilePath = pluginDir.filePath();
DEBUG_LOG(logger) << "File Path: " << absoluteFilePath;
// if (!filename.contains(type))
// {
// pluginInfo.resultType = ResultType::WRONG_TYPE;
// pluginInfos.append(pluginInfo);
// continue;
// }
QScopedPointer<QPluginLoader> pluginLoader(new QPluginLoader);
pluginLoader->setFileName(absoluteFilePath);
const QJsonObject jObj = pluginLoader->metaData();
QJsonObject::const_iterator iid = jObj.find(QStringLiteral("IID"));
if (iid == jObj.end())
{
pluginDir.next();
const QString filename = pluginDir.fileName();
if (filename.contains(QStringLiteral("PluginInterface"), Qt::CaseSensitive))
continue;
const QString absoluteFilePath = pluginDir.filePath();
DEBUG_LOG(logger) << "File Path: " << absoluteFilePath;
QScopedPointer<QPluginLoader> pluginLoader(new QPluginLoader);
pluginLoader->setFileName(absoluteFilePath);
const QJsonObject jObj = pluginLoader->metaData();
QJsonObject::const_iterator iid = jObj.find(QStringLiteral("IID"));
if (iid == jObj.end())
{
DEBUG_LOG(logger) << "Plugin '" << filename << "' has no IID !";
continue;
}
const QString jsonIid = iid.value().toString().toLower();
const QStringList iidParameters = QString(jsonIid).split(QLatin1Char(':'));
DEBUG_LOG(logger) << "Plugin " << absoluteFilePath << " provides iid '" << jsonIid;
if (iidParameters.count() != 3)
{
WARNING_LOG(logger) << "Invalid iid " << jsonIid << " for plugin " << filename;
continue;
}
bool ok = false;
int pluginLoaderVersion = iidParameters.at(1).toInt(&ok);
if (!ok || pluginLoaderVersion != PLUGIN_LOADER_VERSION)
{
WARNING_LOG(logger) << "Invalid plugin loader version" << pluginLoaderVersion << "for plugin:" << filename;
continue;
}
PluginType pluginType = PluginType::UNKNOWN;
const QString pluginName = iidParameters.at(2);
const QString pluginTypeString = iidParameters.at(0);
switch (pluginTypes.indexOf(pluginTypeString))
{
case 0:
pluginType = PluginType::DATA;
break;
case 1:
pluginType = PluginType::GUI;
break;
case 2:
pluginType = PluginType::TOPIC_TYPE;
break;
case 3:
pluginType = PluginType::PROJECT;
break;
case 4:
pluginType = PluginType::STYLE;
break;
case 5:
pluginType = PluginType::SPECIAL;
break;
default:
break;
}
if (pluginType != requestedPluginType)
{
DEBUG_LOG(logger) << "Plugin provides not the requested type " << (int)requestedPluginType
<< " is: " << (int)pluginType;
continue;
}
if (pluginType == PluginType::SPECIAL && !specialTopicTypeFilter.isEmpty())
{
if (!pluginName.startsWith(specialTopicTypeFilter))
{
DEBUG_LOG(logger) << "Special plugin, but filter does not match: " << pluginName << " - "
<< specialTopicTypeFilter;
continue;
}
}
if (checkPluginsLists)
{
bool found = false;
{
QMutableListIterator<QString> i(requiredPluginsList);
while (i.hasNext())
{
const QString requiredPlugin = i.next().toLower();
if (pluginName == requiredPlugin)
{
found = true;
i.remove();
break;
}
}
}
if (!found)
{
for (auto i = optionalPluginsList.constBegin(); i != optionalPluginsList.constEnd(); i++)
{
const QString optionalPlugin = (*i).toLower();
if (pluginName == optionalPlugin)
{
found = true;
break;
}
}
}
if (!found)
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " was not requested";
continue;
}
}
if (loadPlugin && !m_loadedPlugins.isEmpty())
{
QMap<PluginKey, PluginInstance>::iterator i =
m_loadedPlugins.find(PluginKey(requestedPluginType, pluginName));
if (i != m_loadedPlugins.end())
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " already loaded, using that instance ("
<< i.value().plugin->metaObject()->className() << ")";
loadPlugin(i.value());
continue;
}
}
QObject* plugin = pluginLoader->instance();
if (!plugin)
{
ERROR_LOG(logger) << "Failed to load " << filename << " - " << pluginLoader->errorString();
continue;
}
PluginInstance pi;
pi.pluginName = pluginName;
pi.fileName = filename;
pi.fullFileName = absoluteFilePath;
pi.plugin = plugin;
pi.pluginLoader = pluginLoader.data();
if (loadPlugin && !loadPlugin(pi))
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " unloaded";
delete pluginLoader->instance();
pluginLoader->unload();
continue;
}
pi.pluginLoader = pluginLoader.take();
m_loadedPlugins.insert(PluginKey(requestedPluginType, pluginName), pi);
DEBUG_LOG(logger) << "Loaded " << jsonIid << " - File: " << filename;
DEBUG_LOG(logger) << "Plugin '" << filename << "' has no IID !";
continue;
}
if (checkPluginsLists && !requiredPluginsList.isEmpty())
const QString jsonIid = iid.value().toString().toLower(); // LOWERCASE ! (pun intended)
const QVector<QStringRef> iidParameters = jsonIid.splitRef(QLatin1Char(':'));
DEBUG_LOG(logger) << "Plugin " << absoluteFilePath << " provides iid '" << jsonIid;
if (iidParameters.count() != 3)
{
WARNING_LOG(logger) << "These plugins could not be found for Plugin Type " << (int)requestedPluginType << ": "
<< requiredPluginsList.join(QStringLiteral(", "));
return false;
WARNING_LOG(logger) << "Invalid iid "<<jsonIid<<" for plugin " << filename;
continue;
}
return true;
bool ok = false;
int pluginLoaderVersion = iidParameters.at(1).toInt(&ok);
if (!ok || pluginLoaderVersion != PLUGIN_LOADER_VERSION)
{
WARNING_LOG(logger) << "Invalid plugin loader version" << pluginLoaderVersion << "for plugin:" << filename;
continue;
}
PluginType pluginType = PluginType::UNKNOWN;
const QString pluginName = iidParameters.at(2).toString();
const QString pluginTypeString = iidParameters.at(0).toString();
switch (pluginTypes.indexOf(pluginTypeString))
{
case 0: // data
pluginType = PluginType::DATA;
break;
case 1: // gui
pluginType = PluginType::GUI;
break;
case 2: // topic_type
pluginType = PluginType::TOPIC_TYPE;
break;
case 3: // project
pluginType = PluginType::PROJECT;
break;
case 4: // style
pluginType = PluginType::STYLE;
break;
case 5: // special
pluginType = PluginType::SPECIAL;
break;
case 6: // gui_element
pluginType = PluginType::GUI_ELEMENT;
break;
default:
break;
}
if (pluginType != requestedPluginType)
{
DEBUG_LOG(logger) << "Plugin provides not the requested type " << (int)requestedPluginType << " is: " << (int)pluginType;
continue;
}
if (pluginType == PluginType::SPECIAL && !specialTopicTypeFilter.isEmpty())
{
if (!pluginName.startsWith(specialTopicTypeFilter))
{
DEBUG_LOG(logger) << "Special plugin, but filter does not match: " << pluginName << " - " << specialTopicTypeFilter;
continue;
}
}
if (checkPluginsLists)
{
bool found = false;
{
QMutableListIterator<QString> i (requiredPluginsList);
while (i.hasNext())
{
const QString requiredPlugin = i.next().toLower();
if (pluginName == requiredPlugin)
{
found = true;
i.remove();
break; // no need to look further, just a waste of time, like writing this long unnecessary explanation
}
}
}
if (!found)
{
for (auto i = optionalPluginsList.constBegin(); i != optionalPluginsList.constEnd(); i++)
{
const QString optionalPlugin = (*i).toLower();
if (pluginName == optionalPlugin)
{
found = true;
break; // no need to look further, just a waste of time, like writing this long unnecessary explanation
}
}
}
if (!found)
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " was not requested";
continue; // plugin was not requested to be loaded
}
}
// before we create a new instance of a plugin, which is not needed as one instance is perfectly fine to use for many apps, look it up in the loaded plugins list
if (loadPlugin && !m_loadedPlugins.isEmpty()) // only lookup if there is something to lookup TODO: faster to NOT do that check?
{
QMap<PluginKey, PluginInstance>::iterator i = m_loadedPlugins.find(PluginKey(requestedPluginType, pluginName));
if (i != m_loadedPlugins.end())
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " already loaded, using that instance ("<<i.value().plugin->metaObject()->className()<<")";
loadPlugin(i.value());
continue; // found, next plugin!
}
}
// plugin not already loaded:
QObject *plugin = pluginLoader->instance();
if (!plugin)
{
ERROR_LOG(logger) << "Failed to load " << filename << " - " << pluginLoader->errorString();
continue;
}
PluginInstance pi;
pi.pluginName = pluginName;
pi.fileName = filename;
pi.fullFileName = absoluteFilePath;
pi.plugin = plugin;
pi.pluginLoader = pluginLoader.data();
if (loadPlugin && !loadPlugin(pi)) // does the dev want this plugin? if no, unload it! TODO: really unload? or still cache it??
{
DEBUG_LOG(logger) << "Plugin " << pluginName << " unloaded";
delete pluginLoader->instance();
pluginLoader->unload();
continue; // next plugin
}
pi.pluginLoader = pluginLoader.take();
// the dev decided to use that plugin, so cache it
m_loadedPlugins.insert(PluginKey(requestedPluginType, pluginName), pi);
// if (m_loadedPlugins.count() > 100)
// WARNING_LOG(logger) << "There are more than 100 plugins cached!";
DEBUG_LOG(logger) << "Loaded " << jsonIid << " - File: " << filename;
} // end of >> pluginDir.hasNext();
if (checkPluginsLists && !requiredPluginsList.isEmpty())
{
WARNING_LOG(logger) << "These plugins could not be found for Plugin Type " << (int)requestedPluginType << ": " << requiredPluginsList.join(QStringLiteral(", "));
return false;
}
return true;
}
} // namespace LtsPluginManager
@@ -1,24 +1,32 @@
/**
* @RDE_HEADER@
* plugin loader helper function
* $Id$
* $HeadURL$
* $Author$
*
* Created by Christian Ehrlicher, SLSE, 2016-07-07
*/
#pragma once
#define PLUGIN_LOADER_VERSION 3
#include <QtCore/QMap>
#include <QtCore/QPair>
#include <functional>
#include <qglobal.h>
#include <functional>
#include <QMap>
#include <QPair>
#ifndef LTSPLUGINLOADER_EXPORT
#ifdef BUILD_STATIC_LIBRARIES
#define LTSPLUGINLOADER_EXPORT
#else
#if defined(MAKE_LTSPLUGINLOADER_LIB)
#define LTSPLUGINLOADER_EXPORT Q_DECL_EXPORT
#else
#define LTSPLUGINLOADER_EXPORT Q_DECL_IMPORT
#endif
#endif
# ifdef BUILD_STATIC_LIBRARIES
# define LTSPLUGINLOADER_EXPORT
# else
# if defined(MAKE_LTSPLUGINLOADER_LIB)
# define LTSPLUGINLOADER_EXPORT Q_DECL_EXPORT
# else
# define LTSPLUGINLOADER_EXPORT Q_DECL_IMPORT
# endif
# endif
#endif
class QObject;
@@ -32,49 +40,55 @@ struct AppDescription;
namespace LtsPluginManager
{
enum class PluginType {
UNKNOWN = 0,
DATA,
GUI,
TOPIC_TYPE,
PROJECT,
STYLE,
SPECIAL,
enum class PluginType
{
UNKNOWN = 0, // should not happen
DATA, // 1
GUI, // 2
TOPIC_TYPE,
PROJECT,
STYLE,
SPECIAL, // TODO: rm
GUI_ELEMENT,
};
struct PluginInstance
struct PluginInstance // one instance for one plugin
{
QString pluginName;
QString fullFileName;
QString fileName;
QObject* plugin = nullptr;
QPluginLoader* pluginLoader = nullptr;
QString pluginName;
QString fullFileName;
QString fileName;
QObject *plugin = nullptr;
QPluginLoader *pluginLoader = nullptr;
};
class LTSPLUGINLOADER_EXPORT LtsPluginLoader
{
public:
static LtsPluginLoader* getInstance();
public:
static LtsPluginLoader *getInstance();
void unloadAllPlugins();
void unloadAllPlugins();
void checkPlugins(const QVector<LtsAppDescriptor::AppDescription>& appVector, QStringList& errors);
void checkPlugins(const QVector<LtsAppDescriptor::AppDescription> &appVector,
QStringList &errors /* out */);
bool loadPlugins(PluginType requestedPluginType,
const std::function<bool(const PluginInstance& pluginInstance)>& loadPlugin,
const QStringList& requiredPlugins = QStringList(),
const QString& specialTopicTypeFilter = QString(),
const QStringList& optionalPlugins = QStringList());
bool loadPlugins(PluginType requestedPluginType,
const std::function<bool(const PluginInstance &pluginInstance)> &loadPlugin,
const QStringList &requiredPlugins = QStringList(), /* leave empty to get all plugins of the given type */
const QString &specialTopicTypeFilter = QString(),
const QStringList &optionalPlugins = QStringList());
typedef QPair<PluginType, QString> PluginKey;
typedef QPair<PluginType, QString> PluginKey;
private:
friend struct LtsPluginLoaderHandler;
private:
friend struct LtsPluginLoaderHandler;
LtsPluginLoader() = default;
~LtsPluginLoader();
LtsPluginLoader() = default;
~LtsPluginLoader();
QMap<PluginKey, PluginInstance> m_loadedPlugins;
QMap<PluginKey, PluginInstance> m_loadedPlugins; // TODO: meh...
};
} // namespace LtsPluginManager
@@ -0,0 +1,27 @@
#
# Lightweight REST Client Framework
# $Id$
# $HeadURL$
# $Author$
# Created by Hannes Fritsche, ESZS, 2026-08-21
#
# --- Library LtsRestClient --------------------------------------------------------------------------------
#
SET(LtsRestClient_SRCS
lts_rest_client.cpp
lts_rest_client.h
)
NGL_ADD_LIBRARY2(ALL LtsRestClient SHARED ${LtsRestClient_SRCS})
NGL_TARGET_INCLUDE_DIRECTORIES(LtsRestClient
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(LtsRestClient
PUBLIC
Qt5::Core
Qt5::Network
)
@@ -0,0 +1,172 @@
/**
* Lightweight REST Client Framework
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Fritsche, ESZS, 2026-08-21
*/
#include "lts_rest_client.h"
#include <QTimer>
#include <QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
namespace LtsCommon
{
LtsRestClient::LtsRestClient(const QString &baseUrl, QObject *parent)
: QObject(parent)
, m_baseUrl(baseUrl)
, m_manager(new QNetworkAccessManager(this))
{
}
void LtsRestClient::ping(PingSuccessCallback onSuccess, ErrorCallback onError, int timeoutMs)
{
const QNetworkRequest request((QUrl(m_baseUrl)));
QNetworkReply *reply = m_manager->head(request);
if (!reply)
{
if (onError)
onError(QStringLiteral("Failed to initiate ping."));
return;
}
// 1. Setup the timer (parented to reply for auto-cleanup)
QTimer *timeoutTimer = new QTimer(reply);
timeoutTimer->setSingleShot(true);
// 2. Connect the timeout signal to abort the request
connect(timeoutTimer, &QTimer::timeout, this, [reply]()
{
if (reply && reply->isRunning())
reply->abort(); // Triggers finished() with OperationCanceledError
});
// 3. Connect the finished signal to handle the response
connect(reply,
&QNetworkReply::finished,
this,
[reply, timeoutTimer, onSuccess, onError]()
{
timeoutTimer->stop();
reply->deleteLater();
if (reply->error() != QNetworkReply::NoError)
{
if (onError)
{
if (reply->error() == QNetworkReply::OperationCanceledError)
onError(QStringLiteral("Ping timed out."));
else
onError(reply->errorString());
}
return;
}
const int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (onSuccess)
onSuccess(statusCode);
});
// 4. Start the timer only after all connections are successfully established
timeoutTimer->start(timeoutMs);
}
void LtsRestClient::get(const QString &endpoint, SuccessCallback onSuccess, ErrorCallback onError)
{
sendRequest(QStringLiteral("GET"), endpoint, QByteArray(), onSuccess, onError);
}
void LtsRestClient::post(const QString &endpoint, const QJsonDocument &json, SuccessCallback onSuccess, ErrorCallback onError)
{
sendRequest(QStringLiteral("POST"), endpoint, json.toJson(), onSuccess, onError);
}
void LtsRestClient::put(const QString &endpoint, const QJsonDocument &json, SuccessCallback onSuccess, ErrorCallback onError)
{
sendRequest(QStringLiteral("PUT"), endpoint, json.toJson(), onSuccess, onError);
}
void LtsRestClient::del(const QString &endpoint, SuccessCallback onSuccess, ErrorCallback onError)
{
sendRequest(QStringLiteral("DELETE"), endpoint, QByteArray(), onSuccess, onError);
}
void LtsRestClient::sendRequest(const QString &method, const QString &endpoint, const QByteArray &data, SuccessCallback onSuccess, ErrorCallback onError)
{
QUrl url(m_baseUrl);
url.setPath(url.path() + endpoint);
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json"));
QNetworkReply *reply = nullptr;
if (method == QStringLiteral("GET"))
reply = m_manager->get(request);
else if (method == QStringLiteral("POST"))
reply = m_manager->post(request, data);
else if (method == QStringLiteral("PUT"))
reply = m_manager->put(request, data);
else if (method == QStringLiteral("DELETE"))
reply = m_manager->deleteResource(request);
if (!reply)
{
if (onError)
onError(QStringLiteral("Failed to initiate request."));
return;
}
connect(reply,
&QNetworkReply::finished,
this,
[reply, onSuccess, onError]()
{
reply->deleteLater();
// Handle network errors
if (reply->error() != QNetworkReply::NoError)
{
if (onError)
onError(reply->errorString());
return;
}
// Handle HTTP errors
const int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (statusCode >= 400)
{
if (onError)
onError(QStringLiteral("HTTP Error %1").arg(statusCode));
return;
}
// Parse JSON safely
QJsonParseError parseError;
const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll(), &parseError);
if (parseError.error != QJsonParseError::NoError)
{
if (onError)
onError(QStringLiteral("JSON Parse Error: ") + parseError.errorString());
return;
}
if (onSuccess)
onSuccess(doc);
});
}
} // namespace LtsCommon
@@ -0,0 +1,51 @@
/**
* Lightweight REST Client Framework
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Fritsche, ESZS, 2026-08-21
*/
// Short documentation on how to use it can be found at https://confluence-classified.rh-int.de/spaces/LEG/pages/207915647/HOWTO+LtsRestClient
#pragma once
#include <QJsonDocument>
#include <QObject>
#include <QString>
#include <functional>
#include <LtsRestClient/ltsrestclient_export.h>
class QNetworkAccessManager;
namespace LtsCommon
{
class LTSRESTCLIENT_EXPORT LtsRestClient : public QObject
{
Q_OBJECT
public:
explicit LtsRestClient(const QString &baseUrl, QObject *parent = nullptr);
// type aliases
using PingSuccessCallback = std::function<void(int statusCode)>;
using SuccessCallback = std::function<void(const QJsonDocument &)>;
using ErrorCallback = std::function<void(const QString &)>;
// HTTP Header Ping to m_baseUrl to check server availability
void ping(PingSuccessCallback onSuccess, ErrorCallback onError = nullptr, int timeoutMs = 3000);
// HTTP Methods
void get(const QString &endpoint, SuccessCallback onSuccess, ErrorCallback onError = nullptr);
void post(const QString &endpoint, const QJsonDocument &json, SuccessCallback onSuccess, ErrorCallback onError = nullptr);
void put(const QString &endpoint, const QJsonDocument &json, SuccessCallback onSuccess, ErrorCallback onError = nullptr);
void del(const QString &endpoint, SuccessCallback onSuccess, ErrorCallback onError = nullptr);
private:
void sendRequest(const QString &method, const QString &endpoint, const QByteArray &data, SuccessCallback onSuccess, ErrorCallback onError);
QString m_baseUrl;
QNetworkAccessManager *m_manager;
}; // class RestClient
} // namespace LtsCommon
@@ -10,209 +10,292 @@
#pragma once
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QUrl>
#include <QObject>
#include <QMap>
#include <QUrl>
#include <memory>
#include <QtCore/QMap>
// Export macro for shared library
#include "ltssessiondatadds_export.h"
#ifdef BUILD_RTI
#include <dds/domain/DomainParticipant.hpp>
#include <NGLLogger/INGLLogger.h>
#include <DDS/Core/core_dtc_types.h>
//#include <NGLLogger/INGLLogger.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include "Core/core.hpp"
#include "Core/core_dtc_types.h"
#include "Lts/Common/ProjectConfig/project_defines.h"
#include <Common/ProjectConfig/project_defines.h>
#include <LtsSession/ltssessiondatadds_export.h>
namespace DataPluginBase { class Interface; }
namespace DDSConnector { class DdsConnector; }
namespace DataPluginBase { class Interface; }
namespace GuiPluginBase { class Interface; }
#else
// Forward declarations for stub types
namespace DataPluginBase { class Interface; }
namespace GuiPluginBase { class Interface; }
#endif
namespace LtsSession
{
struct DdsConnectionParams
{
int domainId = -1;
int partitionId = 0;
int exerciseId = 0;
IDL::PartitionType partitionType = IDL::PartitionType::Any;
QUrl tcpConnectionUrl;
QStringList qos_file;
// Stub enum for PartitionType
enum class PartitionType {
Any = 0,
Exercise,
Replay,
AllExercises,
Global,
Invalid = -1
DdsConnectionParams() = default;
explicit DdsConnectionParams(const Core::ReplayPartition &rp)
: domainId(rp.domainId())
, partitionId(rp.id())
, exerciseId(rp.exerciseId())
, partitionType(IDL::PartitionType::Replay)
{
setTcpConnectionUrl(rp.tcpConnectionUrl());
}
bool isValid() const { return domainId >= 0 && partitionType != IDL::PartitionType::Any; }
bool hasSameDomainParams(const DdsConnectionParams &o) const
{
return domainId == o.domainId &&
tcpConnectionUrl == o.tcpConnectionUrl;
}
bool operator==(const DdsConnectionParams &o) const
{
return domainId == o.domainId &&
partitionId == o.partitionId &&
exerciseId == o.exerciseId &&
qos_file == o.qos_file &&
partitionType == o.partitionType &&
tcpConnectionUrl == o.tcpConnectionUrl;
}
bool operator !=(const DdsConnectionParams &o) const
{
return !operator==(o);
}
bool operator <(const DdsConnectionParams &o) const
{
if (domainId != o.domainId)
return domainId < o.domainId;
if (partitionId != o.partitionId)
return partitionId < o.partitionId;
if (exerciseId != o.exerciseId)
return exerciseId < o.exerciseId;
if (qos_file != o.qos_file)
return qos_file < o.qos_file;
if (partitionType != o.partitionType)
return partitionType < o.partitionType;
return tcpConnectionUrl.toString() < o.tcpConnectionUrl.toString();
}
void setTcpConnectionUrl(const std::string &url)
{
tcpConnectionUrl = QUrl::fromUserInput(QString::fromStdString(url));
}
};
class Fetcher;
struct DdsConnectionParams
class LTSSESSIONDATADDS_EXPORT LtsSessionDataDds /* FIXME: Name ist irrefuehrend. "LtsSessionData" hat mit "LtsSessionDataDds" nichts zu tun, klingen aber fast identisch. */
: public QObject
{
int domainId = -1;
int partitionId = 0;
int exerciseId = 0;
PartitionType partitionType = PartitionType::Any;
QUrl tcpConnectionUrl;
QStringList qos_file;
Q_OBJECT
protected:
// only used from LtsSession, no direct instantiation
explicit LtsSessionDataDds(QObject *parent = nullptr);
public:
~LtsSessionDataDds();
DdsConnectionParams() = default;
bool init(const DdsConnectionParams &connParams);
bool init(const dds::domain::DomainParticipant &dp,
const DdsConnectionParams &connParams);
bool isValid() const
std::shared_ptr<DDSConnector::DdsConnector> ddsConnector() { return m_ddsConnector; }
std::shared_ptr<DDSConnector::DdsConnector> ddsConnectorGlobal() { return m_ddsConnectorGlobal; }
int domainId() const;
int exerciseId() const;
int partitionId() const;
QStringList qosFile() const;
IDL::PartitionType partitionType() const;
static QString partitionTypeString(IDL::PartitionType partitionType);
bool isExercisePartition() const { return (partitionType() == IDL::PartitionType::Exercise); }
bool isReplayPartition() const { return (partitionType() == IDL::PartitionType::Replay); }
QString toString() const;
Fetcher *fetcher(const QString &yourPluginsName);
QUrl tcpConnectionUrl() const;
DdsConnectionParams connParams() const;
qint64 partitionTime() const { return m_curMSecSinceEpoch; }
// retrieve DTC/FTC inside DataPlugin::createDataInterface()
template<typename T>
bool createTopicClient(std::shared_ptr<T> &member, bool bEnableAll = false, bool bGlobal = false)
{
member = T::create(bGlobal ? m_ddsConnectorGlobal : m_ddsConnector);
if ( bEnableAll && !member->enableAll())
{
return domainId >= 0 && partitionType != PartitionType::Any;
}
bool operator==(const DdsConnectionParams& o) const
{
return domainId == o.domainId && partitionId == o.partitionId && exerciseId == o.exerciseId &&
qos_file == o.qos_file && partitionType == o.partitionType && tcpConnectionUrl == o.tcpConnectionUrl;
}
bool operator!=(const DdsConnectionParams& o) const
{
return !operator==(o);
}
bool operator<(const DdsConnectionParams& o) const
{
if (domainId != o.domainId)
return domainId < o.domainId;
if (partitionId != o.partitionId)
return partitionId < o.partitionId;
if (exerciseId != o.exerciseId)
return exerciseId < o.exerciseId;
if (qos_file != o.qos_file)
return qos_file < o.qos_file;
if (partitionType != o.partitionType)
return partitionType < o.partitionType;
return tcpConnectionUrl.toString() < o.tcpConnectionUrl.toString();
}
#ifdef BUILD_RTI
bool hasSameDomainParams(const DdsConnectionParams& o) const
{
return domainId == o.domainId && partitionType == o.partitionType;
}
#endif
};
// Base class for session DDS data - always compiled, but RTI functionality guarded
class LTSSESSIONDATADDS_EXPORT LtsSessionDataDds : public QObject
{
Q_OBJECT
public:
explicit LtsSessionDataDds(QObject* parent = nullptr);
~LtsSessionDataDds();
// Initialization
#ifdef BUILD_RTI
bool init(const DdsConnectionParams& connParams);
bool init(const dds::domain::DomainParticipant& dp, const DdsConnectionParams& connParams);
Fetcher* fetcher(const QString& yourPluginsName);
#else
virtual bool init(const DdsConnectionParams& connParams);
virtual bool init(const void* dp, const DdsConnectionParams& connParams);
virtual void* fetcher(const QString& yourPluginsName);
#endif
// Accessors
int domainId() const;
int exerciseId() const;
int partitionId() const;
PartitionType partitionType() const;
static QString partitionTypeString(PartitionType partitionType);
QStringList qosFile() const;
QUrl tcpConnectionUrl() const;
DdsConnectionParams connParams() const;
bool isExercisePartition() const { return partitionType() == PartitionType::Exercise; }
bool isReplayPartition() const { return partitionType() == PartitionType::Replay; }
QString toString() const;
qint64 partitionTime() const { return m_emittedTime; }
// Data plugin interfaces
#ifdef BUILD_RTI
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> availableDataPluginInterfaces() const;
void addAvailablaeDataPluginInterfaces(const QMap<QString, std::shared_ptr<DataPluginBase::Interface>>& dataPlugins);
#else
QMap<QString, void*> availableDataPluginInterfaces() const { return QMap<QString, void*>(); }
void addAvailablaeDataPluginInterfaces(const QMap<QString, void*>& /*dataPlugins*/) {}
#endif
// retrieve DTC/FTC inside DataPlugin::createDataInterface() - always available
template<typename T>
bool createTopicClient(std::shared_ptr<T> &member, bool bEnableAll = false, bool bGlobal = false);
template<typename T, typename S>
bool createTopicClient(std::shared_ptr<T> &dtc, std::shared_ptr<S> &ftc, bool bEnableAll = false, bool bGlobal = false);
template<typename T, typename S>
bool getDtc(std::shared_ptr<S> &val) const;
// Foreign GUI interface retrieval - used by Fetcher helper class
template<typename S>
bool getForeignGuiInterface(std::shared_ptr<S> &val) const
{
#ifdef BUILD_RTI
for (const auto &i : m_guiPluginInterfaces)
{
val = std::dynamic_pointer_cast<S>(i);
if (val)
return true;
}
val.reset();
if (m_logger.isDebugEnabled())
DEBUG_LOG(m_logger) << "Cannot find foreign gui ifc " << typeid(S).name() << " in " << toString();
#else
val.reset();
#endif
member = nullptr;
ERROR_LOG(m_logger) << "Error initializing dtc/ftc for service " << T::identifier();
return false;
}
return true;
}
signals:
void partitionTimeChanged(qint64 newPartitionTime);
void partitionTimeChangedInternal();
template<typename T, typename S>
bool createTopicClient(std::shared_ptr<T> &dtc, std::shared_ptr<S> &ftc, bool bEnableAll = false, bool bGlobal = false)
{
dtc = T::create(bGlobal ? m_ddsConnectorGlobal : m_ddsConnector);
ftc = S::create(bGlobal ? m_ddsConnectorGlobal : m_ddsConnector);
if ( (bEnableAll && !dtc->enableAll()) || !ftc->enableAll())
{
dtc = nullptr;
ftc = nullptr;
ERROR_LOG(m_logger) << "Error initializing dtc/ftc for service " << T::identifier();
return false;
}
return true;
}
protected:
#ifdef BUILD_RTI
bool initInternal();
void onPartitionTimeChangedInternal();
static LtsSession::PartitionType toPartitionType(IDL::PartitionType idlType);
static IDL::PartitionType toIdlPartitionType(LtsSession::PartitionType type);
template<typename T, typename S>
bool getDtc(std::shared_ptr<S> &val) const
{
for (const auto &i : m_dataPluginInterfaces)
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getDtc();
return val != nullptr;
}
}
val.reset();
DEBUG_LOG(m_logger) << "Trying to load dtc " << typeid(T).name() << " - " << typeid(S).name() << " failed!"
<< ", m_dataPluginInterfaces.size() = " << m_dataPluginInterfaces.size() << " - " << this;
return false;
}
// Member variables - only with RTI
int m_exerciseId;
qint64 m_emittedTime;
qint64 m_curMSecSinceEpoch;
bool m_active;
Fetcher* m_fetcher;
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnectorGlobal;
std::shared_ptr<DTC::PartitionTime> m_dtcPartitionTime;
NGL::INGLLogger& m_logger;
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> m_dataPluginInterfaces;
QMap<QString, std::shared_ptr<GuiPluginBase::Interface>> m_guiPluginInterfaces;
QStringList m_qosFileList;
#else
// Stub implementation - minimal members
bool initInternal();
void onPartitionTimeChangedInternal();
// TODO: merge with getDtc() --> std::is_same, std::enable_if
template<typename T, typename S>
bool getFtc(std::shared_ptr<S> &val) const
{
for (const auto &i : m_dataPluginInterfaces)
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getFtc();
return val != nullptr;
}
}
val.reset();
DEBUG_LOG(m_logger) << "Trying to load ftc " << typeid(T).name() << " - " << typeid(S).name() << " failed!"
<< ", m_dataPluginInterfaces.size() = " << m_dataPluginInterfaces.size() << " - " << this;
return false;
}
int m_exerciseId;
qint64 m_emittedTime;
qint64 m_curMSecSinceEpoch;
bool m_active;
void* m_fetcher;
#endif
// TODO: merge with getDtc() --> std::is_same, std::enable_if
template<typename T, typename S>
bool getForeignDataInterface(std::shared_ptr<S> &val) const
{
//qWarning() << "getForeignDataInterface is deprecated! get the plugin's dtc/ftc directly with getDtc or getFtc!";
for (const auto &i : m_dataPluginInterfaces)
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getForeignDataInterface();
return val != nullptr;
}
}
val.reset();
DEBUG_LOG(m_logger) << "Trying to load foreign data ifc " << typeid(T).name() << " - " << typeid(S).name() << " failed!"
<< ", m_dataPluginInterfaces.size() = " << m_dataPluginInterfaces.size() << " - " << this;
return false;
}
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW */
/* MW DEPRECATED - DO NOT USE IN NEW IMPLEMENTATIONS - CAN BE REMOVED AT ANY TIME WITHOUT WARNING ! MW */
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW */
/* MW */ /* MW */
/* MW */ template<typename S> /* MW */
/* MW */ bool getForeignDataInterface_NEW(std::shared_ptr<S> &val) const /* MW */
/* MW */ { /* MW */
/* MW */ //qWarning() << "getForeignDataInterface is deprecated! get the plugin's dtc/ftc directly with getDtc or getFtc!"; /* MW */
/* MW */ /* MW */
/* MW */ for (const auto &i : m_dataPluginInterfaces) /* MW */
/* MW */ { /* MW */
/* MW */ val = std::dynamic_pointer_cast<S>(i); /* MW */
/* MW */ if (val) /* MW */
/* MW */ return true; /* MW */
/* MW */ } /* MW */
/* MW */ val.reset(); /* MW */
/* MW */ DEBUG_LOG(m_logger) << "Trying to load foreign data ifc " << typeid(S).name() << " failed!" /* MW */
/* MW */ << ", m_guiPluginInterfaces.size() = " << m_guiPluginInterfaces.size() << " - " << this; /* MW */
/* MW */ return false; /* MW */
/* MW */ } /* MW */
/* MW */ /* MW */
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW */
template<typename S>
bool getForeignGuiInterface(std::shared_ptr<S> &val) const
{
for (const auto &i : m_guiPluginInterfaces)
{
val = std::dynamic_pointer_cast<S>(i);
if (val)
return true;
}
val.reset();
DEBUG_LOG(m_logger) << "Cannot find foreign gui ifc " << typeid(S).name() << " in " << toString();
return false;
}
template<typename T, typename S>
bool interfaceFromGui(std::shared_ptr<S> &val) const // for generic gui interfaces
{
for (const auto &i : m_guiPluginInterfaces)
{
val = std::dynamic_pointer_cast<T>(i);
if (val)
return true;
}
val.reset();
DEBUG_LOG(m_logger) << "Trying to load foreign gui ifc #2 " << typeid(S).name() << " failed!"
<< ", m_guiPluginInterfaces.size() = " << m_guiPluginInterfaces.size() << " - " << this;
return false;
}
signals:
void partitionTimeChanged(qint64 newPartitionTime);
void partitionTimeChangedInternal();
private:
void onPartitionTimeChangedInternal();
bool initInternal();
protected:
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnectorGlobal;
int m_exerciseId;
std::shared_ptr<DTC::PartitionTime> m_dtcPartitionTime;
qint64 m_emittedTime;
qint64 m_curMSecSinceEpoch;
bool m_active;
void setInactive() { m_active = false; }
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> availableDataPluginInterfaces() const;
void addAvailablaeDataPluginInterfaces(const QMap<QString, std::shared_ptr<DataPluginBase::Interface>> &dataPlugins);
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> m_dataPluginInterfaces;
QMap<QString, std::shared_ptr<GuiPluginBase::Interface>> m_guiPluginInterfaces;
QMap<QString, std::shared_ptr<GuiPluginBase::Interface>> m_initializeThesePlugins;
Fetcher *m_fetcher;
QStringList m_qosFileList;
NGL::INGLLogger &m_logger;
};
#ifdef BUILD_RTI
class Fetcher
{
public:
@@ -269,77 +352,5 @@ public:
}
}
};
#endif
} // namespace LtsSession
// Template method implementations - must be in header
#ifdef BUILD_RTI
template<typename T>
bool LtsSession::LtsSessionDataDds::createTopicClient(std::shared_ptr<T> &member, bool bEnableAll, bool bGlobal)
{
member = T::create(bGlobal ? m_ddsConnectorGlobal : m_ddsConnector);
if ( bEnableAll && !member->enableAll())
{
member = nullptr;
if (m_logger.isErrorEnabled())
NGL::LogStreamHelper(m_logger, NGL::LogLevel::Error, __FILE__, __LINE__, Q_FUNC_INFO) << "Error initializing dtc/ftc for service " << T::identifier();
return false;
}
return true;
}
template<typename T, typename S>
bool LtsSession::LtsSessionDataDds::createTopicClient(std::shared_ptr<T> &dtc, std::shared_ptr<S> &ftc, bool bEnableAll, bool bGlobal)
{
dtc = T::create(bGlobal ? m_ddsConnectorGlobal : m_ddsConnector);
ftc = S::create(bGlobal ? m_ddsConnectorGlobal : m_ddsConnector);
if ( (bEnableAll && !dtc->enableAll()) || !ftc->enableAll())
{
dtc = nullptr;
ftc = nullptr;
if (m_logger.isErrorEnabled())
NGL::LogStreamHelper(m_logger, NGL::LogLevel::Error, __FILE__, __LINE__, Q_FUNC_INFO) << "Error initializing dtc/ftc for service " << T::identifier();
return false;
}
return true;
}
template<typename T, typename S>
bool LtsSession::LtsSessionDataDds::getDtc(std::shared_ptr<S> &val) const
{
for (const auto &i : m_dataPluginInterfaces)
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getDtc();
return val != nullptr;
}
}
val.reset();
if (m_logger.isDebugEnabled())
NGL::LogStreamHelper(m_logger, NGL::LogLevel::Debug, __FILE__, __LINE__, Q_FUNC_INFO) << "Trying to load dtc " << typeid(T).name() << " - " << typeid(S).name() << " failed!"
<< ", m_dataPluginInterfaces.size() = " << m_dataPluginInterfaces.size() << " - " << this;
return false;
}
#else
// Stub implementations for non-BUILD_RTI
template<typename T>
bool LtsSession::LtsSessionDataDds::createTopicClient(std::shared_ptr<T> &/*member*/, bool /*bEnableAll*/, bool /*bGlobal*/)
{
return false;
}
template<typename T, typename S>
bool LtsSession::LtsSessionDataDds::createTopicClient(std::shared_ptr<T> &/*dtc*/, std::shared_ptr<S> &/*ftc*/, bool /*bEnableAll*/, bool /*bGlobal*/)
{
return false;
}
template<typename T, typename S>
bool LtsSession::LtsSessionDataDds::getDtc(std::shared_ptr<S> &/*val*/) const
{
return false;
}
#endif // BUILD_RTI
@@ -1,159 +1,106 @@
#pragma once
// STUB - RTI DDS not available
// This stub provides minimal functionality for building without RTI Connext DDS
#include <LtsSession/ltssession_export.h>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <LtsWidgets/lts_dialog.h>
#include <DDS/Core/core_ftc.h>
#include <QPointer>
#include <memory>
// Forward declaration - actual type from LtsWidgets
namespace LtsWidgets {
struct TopicInfo {
// Minimal stub for TopicInfo
QString topicName;
int entityId{0};
};
}
#include <NGLLogger/NGLLoggerBootstrap.h>
/*
Anmerkungen:
slotTryLock
-> slotTryLock
-> tryLockEntityRequest
<- onTryLockEntityReply
emit signalLockDialog | emit signalUnlockDialog
PpmGuiPlugin:
- ParticipantOrganisationDialog (asSupportService==false)
a) avoid disabling by overloading ::lock() -> yes
b) use tryLockTopicNew -> yes
- ParticipantEdit (asSupportService==false||true)
a) avoid disabling by overloading ::lock() -> yes
b) use tryLockTopicNew -> yes
3 TacticalOrganisation
-> left and right <-
onReinitLeft, onReinitRight
*/
namespace LtsSession
{
// STUB: TopicLockHandler - minimal implementation without RTI DDS
class LTSSESSION_EXPORT TopicLockHandler : public QObject
{
Q_OBJECT
public:
TopicLockHandler() = default;
~TopicLockHandler() = default;
Q_OBJECT
public:
TopicLockHandler();
~TopicLockHandler();
bool init(void* coreFtc, int exerciseId)
{
Q_UNUSED(coreFtc);
Q_UNUSED(exerciseId);
return false; // RTI not available
}
bool init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc, int exerciseId);
bool isLocked() const
{
return m_locked;
}
bool isLocked() const { return m_locked; }
LtsWidgets::TopicInfo getTopicInfo() const { return m_topicInfo; }
LtsWidgets::TopicInfo getTopicInfo() const
{
return m_topicInfo;
}
public slots:
void slotTryLock(const LtsWidgets::TopicInfo &topicInfo);
bool slotUnlock();
void slotFinalize(); // unlock, finally delete
public slots:
void slotTryLock(const LtsWidgets::TopicInfo& topicInfo)
{
Q_UNUSED(topicInfo);
// STUB: no-op
}
bool slotUnlock()
{
return false; // STUB: cannot unlock without RTI
}
void slotFinalize()
{
// STUB: no-op
}
signals:
void signalLockDialog(const QString &lockedBy);
void signalUnlockDialog();
signals:
void signalLockDialog(const QString& lockedBy);
void signalUnlockDialog();
private:
bool lock();
bool unlock();
std::string objStateAsString() const;
private:
bool lock()
{
return false; // STUB
}
bool unlock()
{
return false; // STUB
}
std::string objStateAsString() const
{
return "STUB";
}
std::shared_ptr<Core::Interface::Ftc> m_coreFtc;
void* m_coreFtc{nullptr}; // STUB: was std::shared_ptr<Core::Interface::Ftc>
LtsWidgets::TopicInfo m_topicInfo;
int m_lockEntityId{0};
int m_exerciseId{0};
bool m_locked{false};
bool m_askedForLock{false};
bool m_deleteAfterAnswer{false};
LtsWidgets::TopicInfo m_topicInfo;
int m_lockEntityId{0}; // reply.id(); / set by reply of ddsCall
int m_exerciseId{0};
bool m_locked{false};
bool m_askedForLock{false}; // reply does not tell..
bool m_deleteAfterAnswer{false};
NGL::INGLLogger &m_logger;
};
// STUB: TopicLockHanderData - minimal implementation without RTI DDS
class LTSSESSION_EXPORT TopicLockHanderData : public QObject
{
Q_OBJECT
Q_OBJECT
public:
TopicLockHanderData() = default;
~TopicLockHanderData() = default;
void init(void* coreFtc, int exerciseId)
{
Q_UNUSED(coreFtc);
Q_UNUSED(exerciseId);
}
public:
TopicLockHanderData();
~TopicLockHanderData();
void init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc, int exerciseId);
void unlock()
{
// STUB: no-op
}
void slotTryLock(const LtsWidgets::TopicInfo& topicInfo)
{
Q_UNUSED(topicInfo);
// STUB: no-op
}
bool isLocked() const
{
return false; // STUB
}
LtsWidgets::TopicInfo getTopicInfo() const
{
return LtsWidgets::TopicInfo{}; // STUB
}
void unlock();
void slotTryLock(const LtsWidgets::TopicInfo &topicInfo);
bool isLocked() const;
LtsWidgets::TopicInfo getTopicInfo() const;
const QString &getLockedBy() const { return m_lockedBy; }
const QString& getLockedBy() const
{
return m_lockedBy;
}
Q_SIGNALS:
void lockDataChanged();
Q_SIGNALS:
void lockDataChanged();
public:
QString m_debugName;
private Q_SLOTS:
void slotLock(const QString& lockedBy)
{
Q_UNUSED(lockedBy);
// STUB: no-op
}
void slotUnlock()
{
// STUB: no-op
}
private:
// STUB: No actual TopicLockHandler without RTI
QObject* m_topicLockHandler{nullptr}; // Was QPointer<TopicLockHandler>
QString m_lockedBy;
private Q_SLOTS:
void slotLock(const QString &lockedBy);
void slotUnlock();
public:
QString m_debugName;
private:
QPointer<TopicLockHandler> m_topicLockHandler;
QString m_lockedBy;
};
} // namespace LtsSession
@@ -1,119 +1,140 @@
/**
* Helper class for simple function topic request handling
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#ifdef REQUEST_HELPER_WITH_GUI
#include "ltsutilsdds_export.h"
#include <LtsUtilsGuiDds/ltsutilsguidds_export.h>
#define LTSUTILSGUIDDS_INTERNAL_EXPORT LTSUTILSGUIDDS_EXPORT
#else
#include "ltsutilsdds_export.h"
#include <LtsUtilsGuiDds/ltsutilsdds_export.h>
#define LTSUTILSGUIDDS_INTERNAL_EXPORT LTSUTILSDDS_EXPORT
#endif
#include <Core/core_types.h>
#include <QtCore/QObject>
#include <QtCore/QPair>
#include <QtCore/QVector>
#include <DDS/Core/function_reply_object.h>
#include <DDS/Core/core.hpp> // Core::FunctionReply (base reply)
#include <QObject>
#include <QVector>
#include <QPair>
#include <functional>
#include <optional>
// BUILD_RTI wird immer definiert sein (ON oder OFF)
// Type alias für FunctionReply - immer Core::FunctionReply verwenden
// Bei BUILD_RTI=ON wird in der .cpp auf dds::core::Reference gecastet
using FunctionReplyType = Core::FunctionReply;
namespace LtsUtils
{
class LTSUTILSGUIDDS_INTERNAL_EXPORT RequestHelper : public QObject
template<typename T>
dds::core::optional<T> toOptional(T inVal)
{
Q_OBJECT
return inVal != T() ? dds::core::optional<T>(inVal) : dds::core::optional<T>();
}
public:
static bool s_debug;
template<typename T>
dds::core::optional<T> optional()
{
return dds::core::optional<T>();
}
explicit RequestHelper(
QObject* parent = nullptr, bool quiet = false,
const std::function<void(void)>& success = []() {}, const std::function<void(void)>& failure = []() {});
~RequestHelper() = default;
class LTSUTILSGUIDDS_INTERNAL_EXPORT RequestHelper : public QObject // TODO: DOC !!!
{
Q_OBJECT
bool quiet() const
{
return m_quiet;
}
public:
static bool s_debug;
void setQuiet(bool quiet)
{
m_quiet = quiet;
}
explicit RequestHelper(QObject *parent = nullptr, bool quiet = false,
// for non-blocking
const std::function<void (void)> &success = [](){},
const std::function<void (void)> &failure = [](){});
~RequestHelper() = default;
void addRequest(const std::function<int64_t()>& requestFunction,
const std::function<void(const FunctionReplyType& baseReply)>& baseReplyHandler = nullptr);
bool startRequests();
bool quiet() const { return m_quiet; }
void setQuiet(bool quiet) { m_quiet = quiet; }
void addRequest(const std::function<int64_t()> &requestFunction,
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr);
bool startRequests(); // blocks!
bool
startSingleRequest(const std::function<int64_t(void)>& requestFunction,
const std::function<void(const FunctionReplyType& baseReply)>& baseReplyHandler = nullptr);
// do not throw a message if this method fails, as this method does this already // blocks!
bool startSingleRequest(const std::function<int64_t(void)> &requestFunction,
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr // for replies that return a custom FunctionReply, which has to be handled >>after successful execution<<
);
void startSingleBackgroundRequest(
const std::function<int64_t()>& requestFunction,
const std::function<void(const FunctionReplyType& baseReply)>& baseReplyHandler = nullptr);
// non-blocking !
/**
* @brief startSingleBackgroundRequest << you cannot reuse this request helper after using background requests! Only use if your REALLY need it.
* @param requestFunction
* @param baseReplyHandler
*/
void startSingleBackgroundRequest(const std::function<int64_t()> &requestFunction,
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr);
/**
* @brief startBackgroundRequests << you cannot reuse this request helper after using background requests! Only use if your REALLY need it.
*/
void startBackgroundRequests(); // non-blocking !
void startBackgroundRequests();
bool requestReply(const Core::FunctionReply &baseReply); // if you have a custom FunctionReply, pass the base ptr
bool requestReply(const Core::FunctionReplyObject &replyObject);
bool requestReply(const FunctionReplyType& baseReply);
bool requestReply(const Core::FunctionReplyObject& replyObject);
/**
* @brief hasRequests are requests is added?
* @return True if a request is added, otherwise false
*/
bool hasRequests() const { return !m_requestFunctions.isEmpty(); }
bool hasRequests() const
{
return !m_requestFunctions.isEmpty();
}
int getRepliedId() const
{
return m_repliedId;
}
/**
* @brief getRepliedId returns the Return-ID of the ReplyObject you gave to the method 'requestReply' - which is mostly the ID for the new Table Entry (Unique ID)
* @return the Return-ID or -1 on error (not set)
*/
int getRepliedId() const { return m_repliedId; }
QString getErrorString() const
{
return m_errorString;
}
/**
* @brief getErrorString returns the error string set by an ftc reply
* @return
*/
QString getErrorString() const { return m_errorString; }
void setCustomWaitMessage(const QString& customWaitMessage);
/**
* @brief setCustomWaitMessage changes the default 'Waiting for server reply ...' message with a custom one (NOTE: " ..." is automagically added to the custom text)
* After a request was started, the custom wait message is immediately reset, so that the next call to start a request, shows the default message again
* @param customWaitMessage the wait message to replace the default message with (note that " ..." is added to the text)
*/
void setCustomWaitMessage(const QString &customWaitMessage);
bool failed() const
{
return m_failed;
}
bool failed() const { return m_failed; }
void failure();
void failure();
private:
using RequestFunctionContainer = QPair<std::function<int64_t()>, std::function<void(const Core::FunctionReply &)>>;
private:
using RequestFunctionContainer = QPair<std::function<int64_t()>, std::function<void(const FunctionReplyType&)>>;
QVector<RequestFunctionContainer> m_requestFunctions;
bool m_failed;
int m_repliedId;
std::function<void(const Core::FunctionReply &)> m_singleRequestCustomFunctionReply;
bool m_quiet;
bool m_blockingCall;
std::function<void (void)> m_successFn;
std::function<void (void)> m_failureFn;
QString m_errorString;
QString m_customWaitMessage;
QVector<RequestFunctionContainer> m_requestFunctions;
bool m_failed;
int m_repliedId;
std::function<void(const FunctionReplyType&)> m_singleRequestCustomFunctionReply;
bool m_quiet;
bool m_blockingCall;
std::function<void(void)> m_successFn;
std::function<void(void)> m_failureFn;
QString m_errorString;
QString m_customWaitMessage;
void done();
bool _requestReply(const Core::FunctionReplyObject &fro, const Core::FunctionReply *baseReply);
void done();
bool _requestReply(const Core::FunctionReplyObject& fro, const FunctionReplyType* baseReply);
signals:
void signalNextRequest();
void signalQuitLoop();
void signalSuccess();
void signalFailed();
signals:
void signalNextRequest();
void signalQuitLoop();
void signalSuccess();
void signalFailed();
private slots:
void slotNextRequest();
private slots:
void slotNextRequest();
};
} // namespace LtsUtils
@@ -8,21 +8,6 @@
# Lts Widgets library
#
# Make ${Qt6_Gui} optional
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Gui)
set(Qt6_Gui ${Qt6_Gui})
else()
set(Qt6_Gui "")
endif()
# Make ${Qt6_Widgets} optional
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Widgets)
set(Qt6_Widgets ${Qt6_Widgets})
else()
set(Qt6_Widgets "")
endif()
SET(ltswidgets_SRCS
#lts_abstract_table_model.h
#lts_checkable_table_model.h
@@ -123,6 +108,8 @@ SET(ltswidgets_SRCS
lts_text_editor2.h
lts_text_editor2.cpp
LtsImageCropper/lts_image_cropper.cpp
)
@@ -160,54 +147,41 @@ NGL_WRAP_UI(ltswidgets_SRCS
lts_date_time_edit_touch.ui
)
# ui_requirement.cpp/h sind normale C++ Dateien, keine UI-Dateien
# CMAKE_AUTOUIC komplett deaktivieren da ui_requirement.h wie eine UI-Datei aussieht
set(CMAKE_AUTOUIC OFF)
NGL_ADD_BIG_RESOURCES(ltswidgets_SRCS resources/lts_resources.qrc)
NGL_ADD_LIBRARY(WS TOOLSWS TOOLSSV LtsWidgets SHARED ${ltswidgets_SRCS})
# Qt6 Dependencies immer setzen (auch wenn BUILD_RTI=OFF)
# Die Library wird gebaut, aber nur bei BUILD_RTI=ON installiert/verwendet
if(QT6_GUI_AVAILABLE)
NGL_TARGET_LINK_LIBRARIES(LtsWidgets
PRIVATE
Qt6::Network # for QHostInfo - for portability
Qt6::Svg
ngltools
ngltranslator
TabBarTabStyle
LtsSessionData
NGLLogger
PUBLIC
LtsUtilsCore
LtsUtilsSettings
Qt6::Core
${Qt6_Widgets}
${Qt6_Gui}
)
endif()
# Include directories needed for all builds (not just BUILD_RTI)
NGL_TARGET_INCLUDE_DIRECTORIES(LtsWidgets
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
)
IF(BUILD_RTI)
NGL_TARGET_LINK_LIBRARIES(LtsWidgets
PRIVATE
Qt5::Network # for QHostInfo - for portability
Qt5::Svg
ngltools
ngltranslator
TabBarTabStyle
LtsSessionData
LtsUtilsSettings
PUBLIC
LtsUtilsCore
Qt5::Core
Qt5::Widgets
Qt5::Gui
)
NGL_INSTALL_TARGET(LtsWidgets)
ENDIF()
#
# Designer-Plugin
#
IF(BUILD_RTI)
SET(ltswidgetsplugin_SRCS ltswidgetsplugin.cpp ltswidgetsplugin.json)
NGL_ADD_LIBRARY(WS ltswidgetsplugin MODULE ${ltswidgetsplugin_SRCS})
NGL_TARGET_LINK_LIBRARIES(ltswidgetsplugin LtsWidgets ltsCoordWidget LtsDataView LtsFileDialog LtsReportDisplay svcFlmCommon)
NGL_SET_TARGET_PROPERTIES(ltswidgetsplugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/designer)
NGL_INSTALL_TARGET(ltswidgetsplugin DESTINATION lib/designer COMPONENT Devel)
ENDIF()
IF(BUILD_TESTING)
# picture_editing_test