Adds initial intermediate qt6 porting state
This commit is contained in:
11247 files changed
+1891537
No files matched your search
@@ -0,0 +1,312 @@
|
||||
|
||||
|
||||
#include "lts_login.h"
|
||||
#include "logout_info_dialog.h"
|
||||
|
||||
#include <LtsPluginManager/lts_plugin_manager.h>
|
||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||
#include <LtsSession/lts_session_manager.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsWidgets/lts_wait_dialog.h>
|
||||
#include <LtsUtilsCore/dds_vector.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QProcess>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
namespace LtsLogin
|
||||
{
|
||||
const int logoutShutdownTimeout = 2 * 60;
|
||||
|
||||
LtsLogin::LtsLogin()
|
||||
: m_loginApp(nullptr)
|
||||
, m_shutdownAction(AssetManagement::ShutdownAction::NoAction)
|
||||
, m_isInLogoutDialog(false)
|
||||
{}
|
||||
|
||||
|
||||
LtsLogin::~LtsLogin()
|
||||
{
|
||||
delete m_loginApp;
|
||||
m_loginApp = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::login()
|
||||
{
|
||||
LtsAppDescriptor::PluginInfo opmDataPlugin;
|
||||
opmDataPlugin.iid = QStringLiteral("opm");
|
||||
opmDataPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||
|
||||
LtsAppDescriptor::PluginInfo pdmDataPlugin;
|
||||
pdmDataPlugin.iid = QStringLiteral("pdm");
|
||||
pdmDataPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||
|
||||
LtsAppDescriptor::PluginInfo asmDataPlugin;
|
||||
asmDataPlugin.iid = QStringLiteral("asm");
|
||||
asmDataPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||
|
||||
LtsAppDescriptor::PluginInfo srmDataPlugin;
|
||||
srmDataPlugin.iid = QStringLiteral("srm");
|
||||
srmDataPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::DATA;
|
||||
|
||||
LtsAppDescriptor::PluginInfo guiPlugin;
|
||||
guiPlugin.iid = m_loginPluginIid;
|
||||
guiPlugin.type = LtsAppDescriptor::PluginInfo::PluginType::GUI;
|
||||
guiPlugin.flags |= LtsAppDescriptor::PluginInfo::Flag::PAYLOAD;
|
||||
|
||||
QVector<LtsAppDescriptor::PluginInfo> plugins;
|
||||
plugins.append(opmDataPlugin);
|
||||
plugins.append(pdmDataPlugin);
|
||||
plugins.append(asmDataPlugin);
|
||||
plugins.append(srmDataPlugin);
|
||||
plugins.append(guiPlugin);
|
||||
|
||||
LtsAppDescriptor::AppDescription app;
|
||||
app.active = true;
|
||||
app.appName = QStringLiteral("Login");
|
||||
app.pluginInfos = plugins;
|
||||
|
||||
LtsSession::DdsConnectionParams connParams;
|
||||
connParams.domainId = LtsSessionData::LtsSessionData::getInstance()->getDomainIdPreset();
|
||||
connParams.tcpConnectionUrl = LtsSessionData::LtsSessionData::getInstance()->getTcpConnectionUrl();
|
||||
connParams.partitionType = IDL::PartitionType::Global;
|
||||
connParams.partitionId = 0;
|
||||
|
||||
m_loginApp = new LtsPluginManager::LtsPluginManager();
|
||||
bool result = m_loginApp->startApp(app, true, connParams);
|
||||
if (!result)
|
||||
{
|
||||
qWarning() << "no login plugin - probably an offline project";
|
||||
emit signalLoginDone();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
connect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
|
||||
this, [this]()
|
||||
{
|
||||
disconnect(m_loginApp, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
|
||||
this, nullptr);
|
||||
|
||||
LtsSession::LtsSession *session = getAdminSession();
|
||||
|
||||
if (!session)
|
||||
{
|
||||
qCritical() << "I cannot find the Admin Session :( - abort!";
|
||||
QMessageBox::critical(nullptr, tr("Error loading login app"), tr("Could not load login app - abort."));
|
||||
abort();
|
||||
}
|
||||
|
||||
if (session->isInitializationDone())
|
||||
QMetaObject::invokeMethod(this, &LtsLogin::slotLoginDone);
|
||||
else
|
||||
connect(session, &LtsSession::LtsSession::signalDoneInitializingSession,
|
||||
this, &LtsLogin::slotLoginDone, Qt::UniqueConnection);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::slotLoginDone()
|
||||
{
|
||||
LtsSession::LtsSession *session = getAdminSession();
|
||||
|
||||
if (session != nullptr)
|
||||
{
|
||||
disconnect(session, &LtsSession::LtsSession::signalDoneInitializingSession,
|
||||
this, &LtsLogin::slotLoginDone);
|
||||
|
||||
if (session->getDtc<AssetManagement::DataInterface>(m_asmDtc))
|
||||
{
|
||||
m_asmDtc->enableWorkstationLogout();
|
||||
connect(m_asmDtc.get(), &AssetManagement::Interface::Dtc::workstationLogoutChanged,
|
||||
this, &LtsLogin::slotLogoutShutdown);
|
||||
}
|
||||
else
|
||||
qWarning() << "LtsLogin: no asm dtc, no remote logout/shutdown!";
|
||||
}
|
||||
else
|
||||
{
|
||||
qCritical() << "LtsLogin: no admin session for login!!";
|
||||
QMessageBox::critical(nullptr, tr("Login error"), tr("Could not finalize login - abort."));
|
||||
abort();
|
||||
}
|
||||
|
||||
emit signalLoginDone();
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::showLogoutInformationDialog(AssetManagement::ShutdownAction action)
|
||||
{
|
||||
LogoutInformationDialog *lid = new LogoutInformationDialog(logoutShutdownTimeout, action, nullptr);
|
||||
connect(lid, &LogoutInformationDialog::accepted,
|
||||
this, [this, action]()
|
||||
{
|
||||
m_shutdownAction = action;
|
||||
m_isInLogoutDialog = false;
|
||||
emit signalLogout();
|
||||
});
|
||||
|
||||
connect(lid, &LogoutInformationDialog::rejected,
|
||||
this, [this]()
|
||||
{
|
||||
m_isInLogoutDialog = false;
|
||||
});
|
||||
|
||||
lid->show();
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::slotLogoutShutdown(const AssetManagement::WorkstationLogout &data, DataModification modType)
|
||||
{
|
||||
if (m_isInLogoutDialog)
|
||||
return;
|
||||
|
||||
if (m_asmDtc == nullptr || modType != DataModification::eAdded)
|
||||
return;
|
||||
|
||||
if (!m_asmDtc->isAssetEnabled())
|
||||
m_asmDtc->enableAsset();
|
||||
for (int id : data.ids())
|
||||
{
|
||||
if (QString::fromStdString(m_asmDtc->asset(id).name()).compare(LtsSession::LtsSession::workstationName(), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
m_isInLogoutDialog = true;
|
||||
showLogoutInformationDialog(data.shutdownAction());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LtsSession::LtsSession *LtsLogin::getAdminSession()
|
||||
{
|
||||
return m_loginApp->m_sessionManager->getSession(IDL::PartitionType::Global, 0);
|
||||
}
|
||||
|
||||
|
||||
void LtsLogin::logoff()
|
||||
{
|
||||
if (m_loginApp == nullptr)
|
||||
{
|
||||
qCritical() << "LtsLogin::logoff: missing login app!";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
LtsSession::LtsSession *datSession = getAdminSession();
|
||||
|
||||
if (!datSession)
|
||||
{
|
||||
qCritical() << "LtsLogin::logoff: no admin session for logout!";
|
||||
abort();
|
||||
}
|
||||
|
||||
int operatorId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
|
||||
int workstationId = LtsSessionData::LtsSessionData::getInstance()->getWorkstationId();
|
||||
|
||||
LtsSessionData::LtsSessionData::getInstance()->clear();
|
||||
|
||||
std::shared_ptr<OperatorManagement::Interface::Ftc> opmFtc;
|
||||
if (operatorId == -1 ||
|
||||
!datSession->getFtc<OperatorManagement::DataInterface>(opmFtc)
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
LtsUtils::OperatorSettings *os = LtsUtils::OperatorSettings::getInstance();
|
||||
|
||||
const QByteArray settings = os->exportSettings();
|
||||
|
||||
|
||||
const auto vec(LtsUtils::convert<std::vector<uint8_t>>(settings));
|
||||
os->clear();
|
||||
opmFtc->operatorGetSetSettingsRequest(OperatorManagement::OperatorGetSetSettingsRequest(operatorId, vec));
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
{
|
||||
qCritical() << "Saving operator settings failed!" << err.what();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<SituationReplayManagement::ForeignDataInterface> srmIfc;
|
||||
if (datSession->getForeignDataInterface<SituationReplayManagement::DataInterface>(srmIfc))
|
||||
{
|
||||
try
|
||||
{
|
||||
srmIfc->removeReplayPartitionsWorkstation(workstationId);
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
{
|
||||
qCritical() << "Removing reply partitions from this workstation failed!" << err.what();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
srmIfc->removeReplayPartitionsOperator(operatorId);
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
{
|
||||
qCritical() << "Removing reply partitions from this operator failed!" << err.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
opmFtc->operatorLogoutRequest(OperatorManagement::OperatorLogoutRequest(operatorId));
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
{
|
||||
qCritical() << "Logout failed!" << err.what();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
m_loginApp->deleteLater();
|
||||
m_loginApp = nullptr;
|
||||
|
||||
QString cmd;
|
||||
switch (m_shutdownAction.underlying())
|
||||
{
|
||||
case AssetManagement::ShutdownAction_def::Shutdown:
|
||||
#ifdef LTS_DEBUG
|
||||
cmd = QStringLiteral("xeyes");
|
||||
#else
|
||||
cmd = QStringLiteral("systemctl poweroff");
|
||||
#endif
|
||||
break;
|
||||
case AssetManagement::ShutdownAction_def::Reboot:
|
||||
#ifdef LTS_DEBUG
|
||||
cmd = QStringLiteral("kcalc");
|
||||
#else
|
||||
cmd = QStringLiteral("systemctl reboot");
|
||||
#endif
|
||||
break;
|
||||
case AssetManagement::ShutdownAction_def::Logout:
|
||||
case AssetManagement::ShutdownAction_def::NoAction:
|
||||
emit signalLogoffDone();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!cmd.isEmpty())
|
||||
{
|
||||
QProcess::startDetached(cmd);
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user