241 lines
5.9 KiB
C++
Executable File
241 lines
5.9 KiB
C++
Executable File
|
|
|
|
|
|
|
|
#include "lts_session_manager.h"
|
|
#include "lts_session.h"
|
|
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <LtsPluginManager/lts_plugin_loader.h>
|
|
#include <LtsPluginManager/lts_plugin_manager.h>
|
|
#include <LtsWidgets/lts_wait_dialog.h>
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <PluginInterfaces/data_plugin_interface.h>
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
#include <DDS/DDSConnector/dds_connector.h>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
namespace LtsSession
|
|
{
|
|
|
|
LtsSessionManager::LtsSessionManager()
|
|
: QObject()
|
|
, m_appId(LtsAppDescriptor::App::Login)
|
|
, m_headless(false)
|
|
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.Manager"))
|
|
{}
|
|
|
|
|
|
LtsSessionManager::~LtsSessionManager()
|
|
{
|
|
|
|
|
|
for (auto i = m_sessionMap.begin(); i != m_sessionMap.end(); ++i)
|
|
{
|
|
LtsSession *session = i.value();
|
|
session->setInactive();
|
|
session->deleteLater();
|
|
}
|
|
}
|
|
|
|
bool LtsSessionManager::init(const DdsConnectionParams &connParams,
|
|
const QVector<LtsPluginManager::AppPluginInstance> &dataPluginList,
|
|
const QVector<LtsPluginManager::AppPluginInstance> &guiPluginList,
|
|
LtsAppDescriptor::App appId,
|
|
const QString &workspaceId,
|
|
bool headless,
|
|
bool hidden)
|
|
{
|
|
|
|
m_dataPluginList = dataPluginList;
|
|
m_guiPluginList = guiPluginList;
|
|
m_appId = appId;
|
|
m_headless = headless;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool bHasBaseLayout = connParams.exerciseId > 0;
|
|
|
|
LtsSession *session = createSession(connParams, bHasBaseLayout, true, hidden);
|
|
session->setWorkspaceId(workspaceId);
|
|
return session;
|
|
}
|
|
|
|
|
|
QVector<LtsSession *> LtsSessionManager::sessions()
|
|
{
|
|
return m_sessionMap.values().toVector();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
void LtsSessionManager::softQuit()
|
|
{
|
|
for (auto i = m_sessionMap.begin(); i != m_sessionMap.end(); ++i)
|
|
{
|
|
LtsSession *session = *i;
|
|
session->aboutToClose();
|
|
session->setInactive();
|
|
session->deleteLater();
|
|
}
|
|
|
|
m_sessionMap.clear();
|
|
|
|
emit hideAllOtherBLWs(nullptr);
|
|
|
|
QMetaObject::invokeMethod(this, &LtsSessionManager::signalQuit, Qt::QueuedConnection);
|
|
}
|
|
|
|
|
|
LtsSession *LtsSessionManager::createSession(const DdsConnectionParams &connParams,
|
|
bool hasBaseLayout,
|
|
bool payloads,
|
|
bool hidden)
|
|
{
|
|
LtsSession *session = getSession(connParams.partitionType, connParams.partitionId);
|
|
|
|
if (session != nullptr)
|
|
{
|
|
WARNING_LOG(m_logger) << "Tried to create a Session that already exists";
|
|
return nullptr;
|
|
}
|
|
|
|
session = new LtsSession(this);
|
|
|
|
connect(session, &LtsSession::signalQuit,
|
|
this, &LtsSessionManager::signalQuit);
|
|
|
|
|
|
connect(session, &LtsSession::signalClose,
|
|
this, &LtsSessionManager::slotCloseSession, Qt::QueuedConnection);
|
|
connect(session, &LtsSession::signalLogout,
|
|
this, &LtsSessionManager::signalLogout);
|
|
connect(session, &LtsSession::signalInitializationAborted,
|
|
this, &LtsSessionManager::signalInitializationAborted);
|
|
connect(session, &LtsSession::hideAllOtherBLWs,
|
|
this, &LtsSessionManager::hideAllOtherBLWs);
|
|
connect(session, &LtsSession::taskSwitch,
|
|
this, &LtsSessionManager::taskSwitch);
|
|
#ifdef LTS_DEBUG
|
|
connect(session, &LtsSession::signalStillAlive,
|
|
this, [this]()
|
|
{
|
|
LtsSession *session = qobject_cast<LtsSession *>(sender());
|
|
|
|
for (auto i = m_sessionMap.constBegin(); i != m_sessionMap.constEnd(); ++i)
|
|
{
|
|
if (i.value() == session)
|
|
return;
|
|
}
|
|
|
|
WARNING_LOG(m_logger) << "Previously deleted Session " << session->partitionId() << "/"
|
|
<< session->partitionType() << " is still alive!";
|
|
});
|
|
#endif
|
|
|
|
if (hasBaseLayout)
|
|
session->setBaseLayoutVisible();
|
|
|
|
if (payloads)
|
|
session->setPayloadsEnabled();
|
|
|
|
m_sessionMap[SessionKey(connParams.partitionType, connParams.partitionId)] = session;
|
|
|
|
|
|
LtsSession *globSession = getSession(IDL::PartitionType::Global, 0);
|
|
if (globSession && globSession->ddsConnector() && globSession->domainId() == connParams.domainId)
|
|
{
|
|
|
|
dds::domain::DomainParticipant dp = globSession->ddsConnector()->getDomainParticipant();
|
|
if (!session->init(dp, connParams, m_dataPluginList, m_guiPluginList))
|
|
{
|
|
session->deleteLater();
|
|
return nullptr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
|
|
|
|
if (!session->init(connParams, m_dataPluginList, m_guiPluginList, hidden))
|
|
{
|
|
session->deleteLater();
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
if (session->isInitializationDone())
|
|
QMetaObject::invokeMethod(this, &LtsSessionManager::signalInitializationFinished,
|
|
Qt::QueuedConnection);
|
|
else
|
|
connect(session, &LtsSession::signalDoneInitializingSession,
|
|
this, &LtsSessionManager::signalInitializationFinished,
|
|
Qt::QueuedConnection);
|
|
|
|
|
|
return session;
|
|
}
|
|
|
|
|
|
void LtsSessionManager::slotCloseSession()
|
|
{
|
|
LtsSession *session = qobject_cast<LtsSession *>(QObject::sender());
|
|
|
|
if (!session)
|
|
{
|
|
FATAL_LOG(m_logger) << "LtsSessionManager: slot called without object - so it cannot be deleted from the session list!";
|
|
return;
|
|
}
|
|
|
|
bool found = false;
|
|
for (auto i = m_sessionMap.begin(); i != m_sessionMap.end(); ++i)
|
|
{
|
|
if (i.value() == session)
|
|
{
|
|
const auto key = i.key();
|
|
session->aboutToClose();
|
|
session->setInactive();
|
|
session->deleteLater();
|
|
m_sessionMap.remove(key);
|
|
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!found)
|
|
FATAL_LOG(m_logger) << "LtsSessionManager: Cannot find Session in map!";
|
|
|
|
emit hideAllOtherBLWs(nullptr);
|
|
|
|
if (m_sessionMap.isEmpty())
|
|
emit signalQuit();
|
|
}
|
|
|
|
|
|
LtsSession *LtsSessionManager::getSession(IDL::PartitionType partitionType, int partitionId)
|
|
{
|
|
auto it = m_sessionMap.find(SessionKey(partitionType, partitionId));
|
|
|
|
if (it != m_sessionMap.end())
|
|
return it.value();
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
}
|