Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
#
# $Id$
# $HeadURL$
# $Author$
#
# Created by Mike Wille, SLSE, 2016-08-24
#
ADD_SUBDIRECTORY(Data)
ADD_SUBDIRECTORY(Gui)
#
# Resource Management Gui Plugin Interface
#
ADD_INTERFACE_LIBRARY(SaaGuiPluginInterface
${CMAKE_CURRENT_SOURCE_DIR}/saa_gui_plugin_interface.h
${CMAKE_CURRENT_SOURCE_DIR}/../../
GuiPluginInterface
Qt5::Core
)
#
# Data Plugin Interface
#
ADD_INTERFACE_LIBRARY(SaaDataPluginInterface
${CMAKE_CURRENT_SOURCE_DIR}/saa_data_plugin_interface.h
${CMAKE_CURRENT_SOURCE_DIR}/..
DataPluginInterface
)
+38
View File
@@ -0,0 +1,38 @@
/**
* @RDE_HEADER@
* Logging for SAAInterfaceAdapterAdler Plugin
* $Id$
* $HeadURL$
* $Author$
*/
#include "logger.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
namespace SAAInterfaceAdapterAdler
{
LOGGER_T getLogger(const char *name)
{
static const char ns[] = "SAA.";
std::string loggerName;
const size_t len = strlen(name);
loggerName.reserve(sizeof(ns) + len);
loggerName.append(ns, sizeof(ns) - 1);
loggerName.append(name, len);
try
{
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
getNGLLogger(loggerName);
}
catch (const std::exception &ex)
{
fprintf(stderr, "Error retrieving logger: %s", ex.what());
abort();
}
}
} // namespace EffectManagement
+26
View File
@@ -0,0 +1,26 @@
/**
* @RDE_HEADER@
* Logging for SAAInterfaceAdapterAdler Plugin
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <NGLLogger/INGLLogger.h>
namespace SAAInterfaceAdapterAdler
{
using LOGGER_T = NGL::INGLLogger &;
LOGGER_T getLogger(const char *name);
inline LOGGER_T getLogger(const QString &loggerName)
{
return getLogger(loggerName.toUtf8().constData());
}
} // namespace EffectManagement
+70
View File
@@ -0,0 +1,70 @@
#pragma once
#include <QProcess>
#include <QJsonDocument>
#include <QJsonObject>
#include <ParticipantManagement/ppm_enums.hpp>
namespace SAAUtils
{
struct PingItem
{
int assetId = -1;
QString host;
int port;
QProcess *process = nullptr;
bool reachable = false;
bool connected = false;
};
struct AsmAssetProps
{
AsmAssetProps(const QString &properties)
{
if (properties.isEmpty())
return;
const QJsonObject propObj = QJsonDocument::fromJson(properties.toUtf8()).object();
if (propObj.contains(QStringLiteral("credentials")) )
{
const QJsonObject adlerObj = propObj[QStringLiteral("credentials")].toObject();
exId = propObj.value(QStringLiteral("exerciseId")).toInt(-1);
userName = adlerObj.value(QStringLiteral("username")).toString();
password = adlerObj.value(QStringLiteral("password")).toString();
host = adlerObj.value(QStringLiteral("host")).toString();
port = adlerObj.value(QStringLiteral("port")).toInt(-1);
}
}
bool hasCredential() const { return (!userName.isEmpty() && !password.isEmpty()); }
bool hasExerciseId() const { return exId > 0;}
QString userName;
QString password;
QString host;
int port=-1;
int exId = -1;
};
struct SaaProps
{
SaaProps(const QString &properties)
{
if ( properties.isEmpty())
return;
const QJsonObject propertiesObj = QJsonDocument::fromJson(properties.toUtf8()).object();
if (!propertiesObj.contains(QStringLiteral("Adler")) )
return;
const QJsonObject adlerObj = propertiesObj[QStringLiteral("Adler")].toObject();
isConnected = (adlerObj.value(QStringLiteral("saaConnectedState")).toInt() == ParticipantManagement::ConnectState::Connected);
name = adlerObj.value(QStringLiteral("SaaName")).toString(QStringLiteral(""));
assetId = adlerObj.value(QStringLiteral("assetId")).toInt(-1);
}
bool hasAsset() const { return assetId > 0; }
QString name;
QString ipAdress;
int assetId = -1;
bool isConnected = false;
};
} // namespace SAAUtils
+21
View File
@@ -0,0 +1,21 @@
#
# $Id$
# $HeadURL$
# $Author$
# Created by Mike Wille, SLSE, 2016-09-06
#
#
# Data Plugin
#
NGL_ADD_LIBRARY(WS SaaDataPlugin MODULE saa_data_plugin.cpp saa_data_plugin.h)
NGL_TARGET_LINK_LIBRARIES(SaaDataPlugin
Qt5::Core
SaaDataPluginInterface
svcExmClient
svcPpmClient
svcAsmClient
NGLLogger
LtsSessionDataDds
)
NGL_INSTALL_TARGET(SaaDataPlugin)
+39
View File
@@ -0,0 +1,39 @@
/**
* @RDE_HEADER@
* Data Plugin for ExerciseManangement
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, SLSE, 2016-02-29
*/
#include "saa_data_plugin.h"
#include <DDS/DDSConnector/dds_connector.h>
#include <LtsSession/lts_session_data_dds.h>
namespace SAAInterfaceAdapterAdler
{
std::shared_ptr<DataPluginBase::Interface> DataPlugin::createDataInterface(LtsSession::LtsSessionDataDds *session)
{
std::shared_ptr<ParticipantManagement::Interface::Dtc> dtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> ftc;
if (!session->createTopicClient(dtc, ftc))
return std::shared_ptr<DataPluginBase::Interface>();
return std::make_shared<DataInterfaceImpl>(session, dtc, ftc);
}
DataInterfaceImpl::DataInterfaceImpl(LtsSession::LtsSessionDataDds *session,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ppmFtc)
: DataInterface()
, m_ppmDtc(ppmDtc)
, m_ppmFtc(ppmFtc)
, m_session(session)
{}
} // namespace SAAInterfaceAdapterAdler
+57
View File
@@ -0,0 +1,57 @@
/**
* @RDE_HEADER@
* Data Plugin for ExerciseManangement
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, SLSE, 2016-02-29
*/
#pragma once
#include <PluginInterfaces/data_plugin_interface.h>
#include <Plugins/SAAs/saa_data_plugin_interface.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/ppm_ftc.h>
namespace SAAInterfaceAdapterAdler
{
class DataPlugin final : public QObject, public DataPluginBase::Plugin
{
Q_PLUGIN_METADATA(IID "data:3:saa")
Q_INTERFACES(DataPluginBase::Plugin)
Q_OBJECT
public:
DataPlugin() = default;
~DataPlugin() = default;
QString pluginName() const override { return QStringLiteral("SAAInterfaceAdapterAdler"); }
std::shared_ptr<DataPluginBase::Interface> createDataInterface(LtsSession::LtsSessionDataDds *session) override;
bool availableInPartition(IDL::PartitionType partition) const override
{
return partition == IDL::PartitionType::Exercise /*||
partition == IDL::PartitionType::Global*/;
}
};
class DataInterfaceImpl final : public DataInterface
{
public:
DataInterfaceImpl(LtsSession::LtsSessionDataDds *session,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ppmFtc);
std::shared_ptr<ParticipantManagement::Interface::Dtc> getDtc() override { return m_ppmDtc; }
std::shared_ptr<ParticipantManagement::Interface::Ftc> getFtc() override { return m_ppmFtc; }
private:
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ppmFtc;
LtsSession::LtsSessionDataDds *m_session;
};
} // namespace SAAInterfaceAdapterAdler
+42
View File
@@ -0,0 +1,42 @@
#
# $Id$
# $HeadURL$
# $Author$
# Created by Christian Ehrlicher, SLSE, 2016-02-29
#
SET(src
../Common/logger.cpp
../Common/logger.h
../Common/saa_utils.h
SAAChooser/saa_chooser.cpp
SAAChooser/saa_chooser.cpp
saa_dialog_model.cpp
saa_dialog_model.h
saa_gui_plugin.cpp
saa_gui_plugin.h
)
NGL_WRAP_UI(src
SAAChooser/saa_chooser.ui
)
NGL_ADD_LIBRARY(WS SaaGuiPlugin MODULE ${src})
NGL_TARGET_LINK_LIBRARIES(SaaGuiPlugin
NGLLogger
SaaGuiPluginInterface
SaaDataPluginInterface
AsmDataPluginInterface
Qt5::Widgets
svcPpmCommon
LtsWidgets
LtsDataView
LtsUtilsGuiDds
LtsSession
LtsSessionData
)
NGL_INSTALL_TARGET(SaaGuiPlugin)
+260
View File
@@ -0,0 +1,260 @@
/**
* @RDE_HEADER@
* SAAChooser
* $Id$
* $HeadURL$
* $Author$
*
* Created by Steve Kemayou, ESZS, 2025-10-16
*/
#include <ConnectDialog/connect_dialog_nt.h>
#include <LtsSession/lts_session_manager.h>
#include <LtsWidgets/lts_message_dialog.h>
#include <LtsWidgets/lts_global_wait_dialog.h>
#include <QAbstractItemView>
#include <saa_dialog_model.h>
#include "saa_chooser.h"
#include "ui_saa_chooser.h"
#include <QProcess>
#include <QTimer>
namespace SAAInterfaceAdapterAdler
{
SaaChooser::SaaChooser(QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
, m_ui(new Ui::SaaChooser)
, m_close(false)
, m_selected(false)
, m_pingTimer(new QTimer(this))
, m_logger(getLogger("SaaChooser"))
{
m_ui->setupUi(this);
m_pingTimer->setInterval(15000); // ping saa each 30 sec.
setOnlineHelpFilename(QStringLiteral("Extras-SAA"));
}
SaaChooser::~SaaChooser()
{
delete m_ui;
}
void SaaChooser::retranslate()
{
translate(m_ui, tr("SAA"));
}
bool SaaChooser::init(LtsSession::LtsSession *session)
{
m_session = session;
delete m_model;
m_model = new SaaDialogModel(this);
m_model->initModel(m_session);
m_ui->widget->setModel(m_model);
#ifndef LTS_DEBUG
m_ui->widget->hideColumn(SaaDialogModel::Id);
#endif
m_ui->widget->setSortingEnabled(false);
m_ui->widget->setSortIndicator(-1, Qt::AscendingOrder);
m_ui->widget->resizeSection(SaaDialogModel::Columns::Name, 300);
m_ui->widget->resizeSection(SaaDialogModel::Columns::Connected, 300);
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setText(tr("Start"));
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setIcon(QIcon(QStringLiteral("icon:saa_remote_desktop.svg")));
m_buttonBox->connectButton(LtsWidgets::DialogButton::Show, this, &SaaChooser::slotSelectSaa);
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
this, &SaaChooser::enaDisa);
enaDisa();
connect(m_pingTimer, &QTimer::timeout, this, &SaaChooser::startPingSaa);
startPingSaa();
m_pingTimer->start(); // timer to pin saa each .. sec. currently 30sec.
return true;
}
QString SaaChooser::rdesktopCodeToString(RdesktopCodes code)
{
switch(code)
{
case RdesktopCodes::FailedToConnect:
return tr("Failed to connect to remote host");
break;
case RdesktopCodes::ConnectionRefused:
return tr("Connection refused by remote host");
break;
case RdesktopCodes::UnableToConnect:
return tr("Unable to connect to remote host");
break;
case RdesktopCodes::DnsError:
return tr("DNS resolution failed to remote host");
break;
case RdesktopCodes::ConnectionTimeOut:
return tr("Connection timed out");
break;
case RdesktopCodes::NetworkError:
return tr("Remote network error");
case RdesktopCodes::AuthenticationError:
return tr("SAA Authentification failed");
case RdesktopCodes::Unknown:
default:
return tr("Unknown rdesktop error");
break;
}
}
/*!
* \brief SaaChooser::getRdesktopInterpretation
* Protocol Reason Codes
* \param code
* \return
*/
SaaChooser::RdesktopCodes SaaChooser::getRdesktopInterpretation(int code) const
{
DEBUG_LOG(m_logger)<<">> getRdesktopInterpretation: rdesktop error code: "<<code;
switch (code)
{
case 0:
case 62: // on client exit
return RdesktopCodes::Normal;
case 76:
return RdesktopCodes::FailedToConnect;
case 77:
return RdesktopCodes::ConnectionTimeOut;
case 78:
return RdesktopCodes::ConnectionRefused;
case 79:
return RdesktopCodes::NetworkError;
case 80:
case 81:
return RdesktopCodes::DnsError;
case 82:
return RdesktopCodes::AuthenticationError;
default:
return RdesktopCodes::Unknown;
}
}
bool SaaChooser::normalExit(int code) const
{
DEBUG_LOG(m_logger)<<">> process finished!! exitCode: "<<code;
return getRdesktopInterpretation(code) == RdesktopCodes::Normal;
}
void SaaChooser::startPingSaa()
{
if (!m_model)
return;
m_model->pingAllSaa();
}
void SaaChooser::slotSelectSaa()
{
const QModelIndex curIdx = m_ui->widget->currentIndex();
if (!curIdx.isValid())
return;
const AssetManagement::Asset asset = m_model->getRowData(curIdx.row());
const SAAUtils::AsmAssetProps assetProps(QString::fromStdString(asset.properties()));
QPointer<QProcess> process = new QProcess(this);
///------------- QProcess::finished
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, [this, process, asset](int code, QProcess::ExitStatus)
{
if (process != qobject_cast<QProcess * >(sender()))
return;
// set connected to false and update view
if (m_model)
m_model->saaConnected(asset.id(), false);
QString errMsg = QString::fromUtf8(process->readAllStandardError());
if (!normalExit(code))
new LtsWidgets::LtsMessageDialogNew(this, rdesktopCodeToString(getRdesktopInterpretation(code)));
if (!process.isNull())
process->deleteLater();
});
//------------- QProcess::readyReadStandardError
connect(process, &QProcess::readyReadStandardError,
this, [this, process]()
{
if (process != qobject_cast<QProcess *>(sender()) || process.isNull())
return;
ERROR_LOG(m_logger) << ">> SAA Remote desktop: error:" << process->readAllStandardError();
});
//------------- QProcess::readyReadStandardOutput
connect(process, &QProcess::readyReadStandardOutput,
this, [this, process]()
{
if (process != qobject_cast<QProcess *>(sender()) || process.isNull())
return;
INFO_LOG(m_logger) << ">> SAA Remote desktop: " << process->readAllStandardOutput();
});
///------------- QProcess::errorOccurred
connect(process, &QProcess::errorOccurred,
this, [this, process, asset](QProcess::ProcessError )
{
if (process != qobject_cast<QProcess *>(sender()) || process.isNull())
return;
if (process->state() != QProcess::Running)
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
WARNING_LOG(m_logger)<<">> saa with id ("<<asset.id()<<")"<<" started ";
//new LtsWidgets::LtsMessageDialogNew(this, tr("SAA Remote desktop process error: %1.").arg(process->errorString()));
});
///------------- QProcess::started
connect(process, &QProcess::started,
this, [this, asset]()
{
WARNING_LOG(m_logger)<<">> saa with id ("<<asset.id()<<")"<<" started ";
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
// set connected to true and update view
if (m_model)
m_model->saaConnected(asset.id(), true);
});
const QString saaIp = QStringLiteral("%1:%2").arg(assetProps.host).arg(assetProps.port);
QStringList args;
const QString program = QStringLiteral("rdesktop");
args <<QStringLiteral("-g")<<QStringLiteral(" 1920x1100")
<< QStringLiteral("-u")<< assetProps.userName
<< QStringLiteral("-p")<< assetProps.password
<< saaIp;
DEBUG_LOG(m_logger)<<">> Process rdesktop: "<<args.join(QStringLiteral(" "));
process->start(program, args);
if (!process->waitForStarted())
{
ERROR_LOG(m_logger) << "Could not start saa process "<<process->program() <<" " << process->arguments().join(QStringLiteral(" "));
process->deleteLater();
}
}
void SaaChooser::enaDisa()
{
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setEnabled(false);
const QModelIndex curIdx = m_ui->widget->currentIndex();
if (!curIdx.isValid())
return;
const AssetManagement::Asset &asset = m_model->getRowData(curIdx.row());
SAAUtils::AsmAssetProps assetProps(QString::fromStdString(asset.properties()));
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setEnabled(assetProps.hasCredential());
}
void SaaChooser::tableColumnOrganiserSetting()
{
//LtsColumnOrganiser
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
}
} // namespace SAAInterfaceAdapterAdler
+85
View File
@@ -0,0 +1,85 @@
/**
* @RDE_HEADER@
* SAAChooser
* $Id$
* $HeadURL$
* $Author$
*
* Created by Steve Kemayou, ESZS, 2025-10-16
*/
#pragma once
#include <LtsWidgets/lts_dialog.h>
#include <LtsSession/lts_session.h>
#include <SAAs/Common/logger.h>
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <SAAs/Common/saa_utils.h>
#include <QDialog>
#include <QJsonDocument>
#include <QJsonObject>
namespace Ui {
class SaaChooser;
}
namespace ParticipantManagement {
class Party;
}
namespace SAAInterfaceAdapterAdler
{
class SaaDialogModel;
class SaaChooser final : public LtsWidgets::LtsDialog
{
Q_OBJECT
public:
explicit SaaChooser(QWidget *parent = nullptr);
~SaaChooser();
void retranslate() override;
bool init(LtsSession::LtsSession *session);
enum class RdesktopCodes
{
Normal,
FailedToConnect,
ConnectionRefused,
UnableToConnect,
DnsError,
ConnectionTimeOut,
NetworkError,
AuthenticationError,
Unknown
};
QString rdesktopCodeToString(RdesktopCodes code);
RdesktopCodes getRdesktopInterpretation(int code) const;
bool normalExit(int code) const;
private slots:
void startPingSaa();
void slotSelectSaa();
void enaDisa();
private:
void tableColumnOrganiserSetting() override;
Ui::SaaChooser *m_ui;
SaaDialogModel *m_model{nullptr};
LtsSession::LtsSession *m_session{nullptr};
bool m_close;
bool m_selected;
QTimer *m_pingTimer;
LOGGER_T m_logger;
};
}//namespace SAAInterfaceAdapterAdler
+45
View File
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SaaChooser</class>
<widget class="QWidget" name="SaaChooser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>589</width>
<height>305</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="LtsDataView::LtsDataView" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>250</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsDataView::LtsDataView</class>
<extends>QWidget</extends>
<header>LtsDataView/lts_data_view.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
+308
View File
@@ -0,0 +1,308 @@
/**
* @RDE_HEADER@
* SaaDialogModel
* $Id$
* $HeadURL$
* $Author$
*
* Created by Steve Kemayou, ESZS, 2025-10-15
*/
#include <ParticipantManagement/ppm_data_plugin_interface.h>
#include <ParticipantManagement/ppm_translation.h>
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
#include <SAAs/Common/saa_utils.h>
#include <ngltools/ngltools_dtg.h>
#include "saa_dialog_model.h"
namespace SAAInterfaceAdapterAdler
{
using namespace SAAUtils;
SaaDialogModel::SaaDialogModel(QObject *parent)
: LtsWidgets::LtsAbstractTableModel<AssetManagement::Asset>({tr("Id"), tr("Name"), tr("scenario is running"), tr("Used by Party")}, parent)
, m_ppmDtc(nullptr)
, m_logger(getLogger("SaaDialogModel"))
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
}
SaaDialogModel::~SaaDialogModel()
{
stopPing();
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
}
bool SaaDialogModel::initModel(LtsSession::LtsSession *session)
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
m_session = session;
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << " ppmDtc not set!!! " << m_logger.getLoggerName();
return false;
}
if (!m_session->getDtc<AssetManagement::DataInterface>(m_asmDtc))
{
ERROR_LOG(m_logger) << " asmDtc not set!!! " << m_logger.getLoggerName();
return false;
}
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::partyChanged, this, &SaaDialogModel::onPartyDataChanged);
connect(m_asmDtc.get(), &AssetManagement::Interface::Dtc::assetChanged, this, &SaaDialogModel::slotAssetChanged);
m_asmDtc->assets(
[this](const AssetManagement::Asset &asset)
{
if (asset.id() <= 1 || asset.assetTypeId() != AssetManagement::AssetType_def::AdlerSAA)
return;
AsmAssetProps asmProps(QString::fromStdString(asset.properties()));
if (asmProps.hasExerciseId() && asmProps.exId != m_session->exerciseId())
return;
// set init Saa ping item list
PingItem pi;
pi.assetId = asset.id();
pi.process = new QProcess(this);
pi.host = asmProps.host; // asset column name is ip addr
pi.port = asmProps.port; // test
m_saaPingItems.insert(asset.id(), pi);
//--
onDataChanged(asset, DataModification::eAdded);
});
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
return true;
}
void SaaDialogModel::pingAllSaa()
{
DEBUG_LOG(m_logger) << "====> pingAllSaa: saaList count: " << m_saaPingItems.count();
if (m_saaPingItems.isEmpty())
return;
// iterate over saa list and start ping for each one.
for (auto &pi : m_saaPingItems)
{
// clean up previous process if exists
if (pi.process)
{
pi.process->kill();
pi.process->deleteLater();
pi.process = nullptr;
}
// create new process
pi.process = new QProcess(this);
// on finished check exit code
connect(pi.process,
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this,
[this, &pi](int exitCode, QProcess::ExitStatus)
{
ParticipantManagement::Party party;
getPartyWithAssetId(pi.assetId, party);
DEBUG_LOG(m_logger) << " ping assetId: " << pi.assetId << " reacheable ? " << (exitCode == 0) << " Szenar ? " << (party.id() > 0) << " Ip: " << pi.host
<< " PortNumb: " << pi.port;
pi.reachable = (exitCode == 0);
pi.process->kill();
pi.process->deleteLater();
pi.process = nullptr;
});
QStringList args = {QStringLiteral("-z"), QStringLiteral("-w"), QStringLiteral("1"), pi.host, QString::number(pi.port)};
pi.process->start(QStringLiteral("nc"), args);
}
updateView();
}
void SaaDialogModel::saaConnected(int assetId, bool state)
{
PingItem &saaItem = m_saaPingItems[assetId];
saaItem.connected = state;
}
void SaaDialogModel::stopPing()
{
WARNING_LOG(m_logger) << ">> stop ping saa...";
for (auto &pi : m_saaPingItems)
{
// clean up previous process if exists
if (pi.process)
{
WARNING_LOG(m_logger) << ">> kill process saaId: " << pi.assetId;
pi.process->kill();
pi.process->deleteLater();
pi.process = nullptr;
}
}
m_saaPingItems.clear();
}
void SaaDialogModel::updateView()
{
beginResetModel();
endResetModel();
}
void SaaDialogModel::onPartyDataChanged(const ParticipantManagement::Party &data, DataModification modType)
{
Q_UNUSED(modType)
DEBUG_LOG(m_logger) << ">>> SAA Dialog Party Data Changed: " << data.id() << " properties: " << data.properties();
update();
}
bool SaaDialogModel::isFiltered(const AssetManagement::Asset &data, DataModification modType) const
{
// no pool and support
if (data.id() <= 1 || data.assetTypeId() != AssetManagement::AssetType_def::AdlerSAA)
return true;
// only the current saa for current ex is viewed
AsmAssetProps asmProps(QString::fromStdString(data.properties()));
if (asmProps.hasExerciseId() && asmProps.exId != m_session->exerciseId())
return true;
return LtsWidgets::LtsAbstractTableModel<AssetManagement::Asset>::isFiltered(data, modType);
}
void SaaDialogModel::slotAssetChanged(const AssetManagement::Asset &data, DataModification modType)
{
// no pool and support
if (data.id() <= 1 || data.assetTypeId() != AssetManagement::AssetType_def::AdlerSAA)
return;
AsmAssetProps asmProps(QString::fromStdString(data.properties()));
if (asmProps.hasExerciseId() && asmProps.exId != m_session->exerciseId())
return;
switch (modType)
{
case DataModification::eAdded:
{
onDataChanged(data, DataModification::eAdded);
PingItem pi;
pi.assetId = data.id();
pi.process = new QProcess(this);
pi.host = asmProps.host;
pi.port = asmProps.port;
m_saaPingItems.insert(data.id(), pi);
}
break;
case DataModification::eModified:
{
onDataChanged(data, DataModification::eModified);
PingItem pi = m_saaPingItems.take(data.id());
if (pi.process != nullptr && pi.process->state() != QProcess::NotRunning)
{
pi.process->kill();
pi.process->deleteLater();
}
pi.process = nullptr;
pi.assetId = data.id();
pi.host = asmProps.host;
pi.port = asmProps.port;
pi.connected = false;
pi.reachable = false;
pi.process = new QProcess(this);
m_saaPingItems.insert(data.id(), pi);
}
break;
case DataModification::eRemoved:
onDataChanged(data, DataModification::eRemoved);
auto pi = m_saaPingItems.take(data.id()); // take will remove item from list
if (pi.process != nullptr && pi.process->state() != QProcess::NotRunning)
{
pi.process->kill();
pi.process->deleteLater();
}
pi.process = nullptr;
break;
}
}
void SaaDialogModel::getPartyWithAssetId(int assetId, ParticipantManagement::Party &party) const
{
const auto &partys = m_ppmDtc->partys();
for (const auto &p : partys)
{
SaaProps saaprops(QString::fromStdString(p.properties()));
if (!saaprops.hasAsset())
continue;
if (saaprops.assetId == assetId)
{
party = p;
return;
}
}
}
QVariant SaaDialogModel::data(const QModelIndex &index, int role) const
{
if (!indexIsValid(index))
return {};
const AssetManagement::Asset &asset = m_vecData.at(index.row());
const AsmAssetProps assetProps(QString::fromStdString(asset.properties()));
// check first that asset is saa and is connected to current exercise
ParticipantManagement::Party party;
if (asset.assetTypeId() == AssetManagement::AssetType_def::AdlerSAA && assetProps.hasExerciseId())
getPartyWithAssetId(asset.id(), party);
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case Id:
return asset.id();
case Name:
return QString::fromStdString(asset.name());
case IsUseByParty:
return party.id() > 0 ? ParticipantManagement::trPartyName(party.name()) : QStringLiteral("--");
default:
return {};
}
}
else if (role == Qt::DecorationRole)
{
if (index.column() != Connected)
return {};
/// green: ping = 1 | szenar = 1
/// gray: ping = 0 | szenar = 0
/// red: ping = 0 | szenar = 1
/// yellow: ping = 1 | szenar = 0
static const QIcon green(QLatin1String("icon:green_light.svg"));
static const QIcon red(QLatin1String("icon:red_light.svg"));
static const QIcon yellow(QLatin1String("icon:yellow_light.svg"));
static const QIcon gray(QLatin1String("icon:gray_light.svg"));
const bool reacheable = m_saaPingItems.value(asset.id()).reachable;
switch (index.column())
{
case Connected:
{
const bool szenar = (party.id() > 0); // entry is assetId available in party.properties
if (szenar && reacheable)
return green;
if (szenar && !reacheable)
return red;
if (!szenar && reacheable)
return yellow;
return gray;
}
default:
return {};
}
}
return {};
}
} // namespace SAAInterfaceAdapterAdler
+66
View File
@@ -0,0 +1,66 @@
/**
* @RDE_HEADER@
* SaaDialogModel
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <LtsWidgets/lts_abstract_table_model.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <AssetManagement/asm_dtc.h>
#include <LtsSession/lts_session.h>
#include <SAAs/Common/logger.h>
#include <SAAs/Common/saa_utils.h>
#include <QJsonDocument>
#include <QJsonObject>
namespace SAAInterfaceAdapterAdler
{
using namespace SAAUtils;
class SaaDialogModel final : public LtsWidgets::LtsAbstractTableModel<AssetManagement::Asset>
{
Q_OBJECT
public:
explicit SaaDialogModel(QObject *parent = nullptr);
~SaaDialogModel();
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override final;
bool initModel(LtsSession::LtsSession *session);
enum Columns
{
Id,
Name,
Connected,
IsUseByParty
};
/// Ping saas handling
void pingAllSaa();
void saaConnected(int assetId, bool state);
protected:
void stopPing();
void updateView();
void onPartyDataChanged(const ParticipantManagement::Party &data, DataModification modType);
void getPartyWithAssetId(int assetId, ParticipantManagement::Party &party)const;
private:
bool isFiltered(const AssetManagement::Asset &data, DataModification modType) const override;
void slotAssetChanged(const AssetManagement::Asset &data, DataModification modType);
private:
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
QHash<int/*assetId*/, PingItem> m_saaPingItems;
LtsSession::LtsSession *m_session{nullptr};
LOGGER_T m_logger;
};
} // namespace InfrastructureManagement
+73
View File
@@ -0,0 +1,73 @@
/**
* @RDE_HEADER@
* GUI Plugin for SAA
* $Id$
* $HeadURL$
* $Author$
* Created by Steve Kemayou, ESZS, 2025-10-15
*/
#include "saa_gui_plugin.h"
#include <LtsWidgets/lts_dialog.h>
#include <AreaEffectSimulation/aes_operator_rights.h>
#include <LtsSession/lts_session.h>
#include <LtsSession/lts_session_data.h>
#include <LtsUtilsSettings/settings.h>
#include <ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
#include <SAAChooser/saa_chooser.h>
#include <SAAs/Common/logger.h>
#include <QProcess>
namespace SAAInterfaceAdapterAdler
{
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
{
return std::make_shared<InterfaceImpl>(session);
}
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
: GuiPluginBase::Interface(session, getLogger("SAAInterfaceGuiPlugin"))
{
}
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
{
QVector<LtsWidgets::PluginData> ret;
LtsWidgets::PluginData plData;
plData.menuText = tr("SAAs");
plData.menuIcon = QIcon(QLatin1String("icon:saa_remote_desktop.svg"));
plData.identifier = QLatin1String("SaaList");
plData.layoutArea = LtsWidgets::LayoutArea::eDialogTab;
plData.operatorRight = OperatorRights::AdlerAdministration::AdlerAdministrationShow;
plData.exercisePart = LtsWidgets::ExercisePart::eSpecial;
plData.menuGroup = tr("SAA");
plData.createWidgetFunc = [this](QWidget * parent)
{
return onShowSaaChooser(parent);
};
ret.append(plData);
return ret;
}
bool InterfaceImpl::fetchInterfaces()
{
return m_session->getDtc<AssetManagement::DataInterface>(m_asmDtc);
}
void InterfaceImpl::clearInterfaces()
{
m_asmDtc = nullptr;
}
LtsWidgets::LtsDialog *InterfaceImpl::onShowSaaChooser(QWidget *parent)
{
SaaChooser *dialog = new SaaChooser(parent);
dialog->init(m_session);
return dialog;
}
}
// namespace SAAInterfaceAdapterAdler
+61
View File
@@ -0,0 +1,61 @@
/**
* @RDE_HEADER@
* Gui Plugin for SAAs
* $Id$
* $HeadURL$
* $Author$
* Created by Steve Kemayou, ESZS, 2025-10-16
*/
#pragma once
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Common/ProjectConfig/project_defines.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <AssetManagement/asm_dtc.h>
#include <QPointer>
class QProcess;
namespace SAAInterfaceAdapterAdler
{
class GuiPlugin final : public QObject, public GuiPluginBase::Plugin
{
Q_PLUGIN_METADATA(IID "gui:3:saa")
Q_INTERFACES(GuiPluginBase::Plugin)
Q_OBJECT
public:
explicit GuiPlugin() = default;
~GuiPlugin() = default;
QString pluginName() override { return QStringLiteral("SAAInterfaceAdapterAdlerGuiPlugin"); }
std::shared_ptr<GuiPluginBase::Interface> createGuiInterface(LtsSession::LtsSession *session) override;
bool availableInPartition(IDL::PartitionType partition) const override { return partition==IDL::PartitionType::Exercise; }
};
class InterfaceImpl final : public QObject, public GuiPluginBase::Interface
{
Q_OBJECT
public:
explicit InterfaceImpl(LtsSession::LtsSession *session);
QVector<LtsWidgets::PluginData> getActions() override;
QString menuGroup() const override { return tr("SAA"); }
bool fetchInterfaces() override;
void clearInterfaces() override;
private slots:
LtsWidgets::LtsDialog *onShowSaaChooser(QWidget *parent);
Q_SIGNALS:
void signalSuccess();
private:
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
};
} // namespace SAAInterfaceAdapterAdler
+30
View File
@@ -0,0 +1,30 @@
/**
* @RDE_HEADER@
* HMI Plugin for SAAInterfaceAdapterAdler (Interface for access from other Plugins)
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, SLSE, 2016-02-29
*/
#pragma once
#include <PluginInterfaces/data_plugin_interface.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/ppm_ftc.h>
namespace SAAInterfaceAdapterAdler
{
/**
* @brief The DataInterface class provides the Topics Clients only for the GUI Plugins
*/
class DataInterface : public DataPluginBase::Interface
{
public:
using DataPluginBase::Interface::Interface;
virtual std::shared_ptr<ParticipantManagement::Interface::Dtc> getDtc() = 0;
virtual std::shared_ptr<ParticipantManagement::Interface::Ftc> getFtc() = 0;
};
} // namespace SAAInterfaceAdapterAdler
+21
View File
@@ -0,0 +1,21 @@
/**
* @RDE_HEADER@
* HMI Plugin for SAAInterfaceAdapterAdler (Interface for access from other Plugins)
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, SLSE, 2016-02-29
*/
#pragma once
namespace SAAInterfaceAdapterAdler
{
class ForeignGuiInterface
{
public:
ForeignGuiInterface() = default;
virtual ~ForeignGuiInterface() = default;
};
} // namespace SAAInterfaceAdapterAdler