Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
Executable
+87
@@ -0,0 +1,87 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
# Created by Mike Wille, SLSE, 2016-05-15
|
||||
#
|
||||
|
||||
|
||||
# LtsSessionDataDds
|
||||
SET(LtsSessionDataDds_SRCS
|
||||
lts_session_data_dds.cpp
|
||||
lts_session_data_dds.h
|
||||
)
|
||||
NGL_ADD_LIBRARY2(WS LtsSessionDataDds SHARED ${LtsSessionDataDds_SRCS})
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(LtsSessionDataDds
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
)
|
||||
NGL_TARGET_LINK_LIBRARIES(LtsSessionDataDds
|
||||
PRIVATE
|
||||
ddsconnector
|
||||
PUBLIC
|
||||
ddscore
|
||||
NGLLogger
|
||||
Qt5::Core
|
||||
)
|
||||
|
||||
|
||||
|
||||
# LtsSession
|
||||
SET(ltssession_SRCS
|
||||
lts_session_manager.h
|
||||
lts_session_manager.cpp
|
||||
lts_session.h
|
||||
lts_session.cpp
|
||||
lts_session_lock_handler.h
|
||||
lts_session_lock_handler.cpp
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY2(WS LtsSession SHARED ${ltssession_SRCS})
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(LtsSession
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(LtsSession
|
||||
PRIVATE
|
||||
Qt5::Network
|
||||
LtsMultiMonitor
|
||||
LtsSessionData
|
||||
ddsconnector
|
||||
LtsUtilsGuiDds # ReqHelpr & for Debug Menu ! TODO: rm on release!
|
||||
LtsNotification
|
||||
svcCoreClient # Core Ftc - for TLH
|
||||
OhpOnlineHelpViewerGuiPluginInterface
|
||||
Qt5::Svg
|
||||
PUBLIC
|
||||
LtsWidgets
|
||||
LtsSessionDataDds
|
||||
Qt5::Core
|
||||
GuiPluginInterface
|
||||
DataPluginInterface
|
||||
NGLLogger
|
||||
ProjectConfig
|
||||
)
|
||||
|
||||
|
||||
# LtsSessionData (avoid cross-deps between AppManager, Session and PluginManager)
|
||||
SET(LtsSessionData_SRCS
|
||||
lts_session_data.cpp
|
||||
lts_session_data.h
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY2(WS TOOLSSV TOOLSWS LtsSessionData SHARED ${LtsSessionData_SRCS})
|
||||
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(LtsSessionData
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(LtsSessionData
|
||||
PUBLIC
|
||||
Qt5::Core
|
||||
Qt5::Gui # QPixmap as Storage for Profile Picture
|
||||
ddscore
|
||||
)
|
||||
Executable
+1649
File diff suppressed because it is too large.
Load diff
Executable
+285
@@ -0,0 +1,285 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lts_session_data_dds.h"
|
||||
#include "lts_session_manager.h"
|
||||
|
||||
#include <LtsSession/ltssession_export.h>
|
||||
#include <LtsWidgets/lts_base.h>
|
||||
#include <QtCore/qobjectdefs.h>
|
||||
|
||||
#include <memory>
|
||||
#include <QMap>
|
||||
#include <QJsonObject>
|
||||
#include <QPointer>
|
||||
#include <QVector>
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LtsBackgroundWidget;
|
||||
class LtsTabWidget;
|
||||
class LtsBaseLayoutWidget;
|
||||
struct ExerciseData;
|
||||
class LtsDialog;
|
||||
class LtsDragIcon;
|
||||
}
|
||||
namespace LtsNotification
|
||||
{
|
||||
class LtsNotification;
|
||||
class LtsNotificationController;
|
||||
}
|
||||
namespace LtsPluginManager
|
||||
{
|
||||
struct PluginInstance;
|
||||
struct AppPluginInstance;
|
||||
}
|
||||
namespace DeveloperTools
|
||||
{
|
||||
class DevDialog;
|
||||
class AppWidget;
|
||||
}
|
||||
namespace Core
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Ftc;
|
||||
}
|
||||
}
|
||||
namespace OnlineHelp
|
||||
{
|
||||
class ForeignOnlineHelpViewerGuiInterface;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LTSSESSION_EXPORT LtsSession : public LtsSessionDataDds
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static bool s_valgrind;
|
||||
static int s_nextSessionId;
|
||||
|
||||
enum class PluginInstanceStatus
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
LOADED,
|
||||
FAILED,
|
||||
};
|
||||
|
||||
static QString appToString(LtsAppDescriptor::App app);
|
||||
static QString appIconFilename(LtsAppDescriptor::App app);
|
||||
static QIcon appToIcon(LtsAppDescriptor::App app);
|
||||
|
||||
explicit LtsSession(LtsSessionManager *sessionManager);
|
||||
~LtsSession();
|
||||
|
||||
QString toString() const;
|
||||
|
||||
LtsSessionManager *getSessionManager();
|
||||
bool init(const DdsConnectionParams &connParams,
|
||||
const QVector<LtsPluginManager::AppPluginInstance> &dataPluginList,
|
||||
const QVector<LtsPluginManager::AppPluginInstance> &guiPluginList, bool hidden);
|
||||
bool init(const dds::domain::DomainParticipant &dp,
|
||||
const DdsConnectionParams &connParams,
|
||||
const QVector<LtsPluginManager::AppPluginInstance> &dataPluginList,
|
||||
const QVector<LtsPluginManager::AppPluginInstance> &guiPluginList);
|
||||
void makeVisible();
|
||||
void setPayloadsEnabled() { m_payloads = true; }
|
||||
void aboutToClose();
|
||||
bool isInitializationDone() const { return m_initDone; }
|
||||
void presetBaseLayoutAsSecondaryWidget() { m_presetBaseLayoutAsSecondaryWidget = true; }
|
||||
|
||||
|
||||
|
||||
LtsWidgets::LtsDragIcon *addAction(const LtsWidgets::PluginData &plData, bool isFirstRun = false);
|
||||
void setMenuVisible(bool visible = true);
|
||||
bool removeMenuAction(LtsWidgets::LtsDragIcon *icon);
|
||||
int screenId() const;
|
||||
int screenContainerId() const;
|
||||
int screenTypeId() const;
|
||||
LtsAppDescriptor::App app() const;
|
||||
void setScreenIdPreset(int screenId) { m_screenIdPreset = screenId; }
|
||||
void setScreenContainerIdPreset(int screenPart) { m_screenContainerIdPreset = screenPart; }
|
||||
bool isForeverInvisible() const { return m_foreverInvisible; }
|
||||
|
||||
LtsNotification::LtsNotification *createNotification(const QString &identifier);
|
||||
|
||||
|
||||
|
||||
void setExerciseData(const LtsWidgets::ExerciseData &exerciseData);
|
||||
const LtsWidgets::ExerciseData *exerciseData() const;
|
||||
void setProfilePicture(const QPixmap &pixmap);
|
||||
void setBaseLayoutVisible() { m_hasBaseLayout = true; }
|
||||
bool isVisible() const { return (m_baseLayout != nullptr); }
|
||||
const QString &name() const { return m_name; }
|
||||
void setName(const QString &name) { m_name = name; }
|
||||
|
||||
|
||||
bool isChildOfSession(QWidget* child);
|
||||
LtsWidgets::LtsBaseLayoutWidget* baseLayout() { return m_baseLayout; }
|
||||
QWidget *baseLayoutWidget();
|
||||
void setMarkForDeletion() { m_markedForDeletion = true; }
|
||||
void doneInitializingSession();
|
||||
bool notifyUnsavedChanges();
|
||||
const QVector<LtsWidgets::LtsBackgroundWidget *> &bgWidgets() const { return m_bgWidgets; }
|
||||
|
||||
|
||||
bool widgetExists(const QString &menuGroup, const QString &identifier, LtsWidgets::LayoutArea area) const;
|
||||
|
||||
|
||||
bool addWidget(LtsWidgets::LtsDialog *widget,
|
||||
const QString &menuGroup,
|
||||
const QString &identifier,
|
||||
LtsWidgets::LayoutArea area = LtsWidgets::LayoutArea::eUnknown,
|
||||
bool setClosable = true);
|
||||
|
||||
LtsWidgets::LtsDialog *getWidget(const QString &menuGroup, const QString &identifier, LtsWidgets::LayoutArea area);
|
||||
bool focusTab(const QString &menuGroup, const QString &identifier, LtsWidgets::LayoutArea area);
|
||||
|
||||
|
||||
|
||||
LtsWidgets::LtsTabWidget *locateWidget(QWidget *widgetToLocate, LtsWidgets::LayoutArea area);
|
||||
|
||||
|
||||
|
||||
|
||||
void enableBaseLayoutMenu(bool on = true);
|
||||
|
||||
|
||||
|
||||
void enableBaseLayoutArea(LtsWidgets::LayoutArea area, bool on = true);
|
||||
|
||||
|
||||
|
||||
static int workstationIp();
|
||||
|
||||
|
||||
static QString workstationName();
|
||||
|
||||
|
||||
|
||||
QVector<LtsWidgets::PluginData> &missingRightActions() { return m_missingRightActions; }
|
||||
|
||||
void setSavegame(const QJsonObject &sg) { m_savegame = sg; }
|
||||
const QJsonObject &getSavegame() const { return m_savegame; }
|
||||
|
||||
void setHidden() { m_hidden = true; }
|
||||
|
||||
const QString workspaceId() const;
|
||||
void setWorkspaceId(const QString &newWorkspaceId);
|
||||
|
||||
LtsWidgets::ExcState exerciseState() const;
|
||||
|
||||
void setLoadedFromSavegame() { m_loadedFromSavegame = true; }
|
||||
bool isLoadedFromSavegame() const { return m_loadedFromSavegame; }
|
||||
void addDeveloperActions();
|
||||
void refetchActions();
|
||||
void setDependency(LtsSession *session);
|
||||
bool hasDependency(LtsSession *session) { return (m_dependency.data() == session); }
|
||||
LtsSession *dependency() const { return m_dependency; }
|
||||
|
||||
|
||||
void setNeedsToBeSuccessfullyPlaced(bool needed = true) { m_needsToBeSuccessfullyPlaced = needed; }
|
||||
|
||||
int id() const { return m_id; }
|
||||
|
||||
public slots:
|
||||
void slotExecuteNextPayload();
|
||||
void slotPluginInitDone();
|
||||
void slotShowOnlineHelp(const QString &fileName);
|
||||
|
||||
|
||||
private slots:
|
||||
void slotShowOperatorSettings();
|
||||
void slotSwap();
|
||||
void slotStapleTopicLockHandler(LtsWidgets::LtsDialog *widget);
|
||||
void slotStopWaitDialog();
|
||||
void slotStartPluginInit();
|
||||
void slotMonitorSelected();
|
||||
void delayScriptEditorStart();
|
||||
|
||||
signals:
|
||||
void signalInitializationAborted();
|
||||
void _signalDoneInitializingSession();
|
||||
void signalDoneInitializingSession();
|
||||
void signalClose();
|
||||
void signalLogout();
|
||||
void signalQuit();
|
||||
void signalStillAlive();
|
||||
void signalExerciseDataChanged();
|
||||
void signalScreenIdChanged(int screenId, int screenContainerId, int screenTypeId);
|
||||
void sessionAboutToBeDestroyed(LtsSession *session);
|
||||
void workspaceIdChanged(const QString &newWorkspaceId);
|
||||
void signalTakeOverBdv();
|
||||
void hideAllOtherBLWs(QObject *caller);
|
||||
void taskSwitch(QObject *caller);
|
||||
|
||||
private:
|
||||
friend class DeveloperTools::DevDialog;
|
||||
friend class DeveloperTools::AppWidget;
|
||||
friend class LtsSessionManager;
|
||||
|
||||
bool event(QEvent *e) override;
|
||||
void createBaseLayout();
|
||||
void initializePlugins(const QVector<LtsPluginManager::AppPluginInstance> &dataPluginList, const QVector<LtsPluginManager::AppPluginInstance> &guiPluginList);
|
||||
void initializeDataPlugins(const QVector<LtsPluginManager::AppPluginInstance> &dataPluginList);
|
||||
void initializeGuiPlugins(const QVector<LtsPluginManager::AppPluginInstance> &guiPluginList);
|
||||
bool tryInitGuiPlugin(const QString &guiPluginKey, std::shared_ptr<GuiPluginBase::Interface> &guiPlugin);
|
||||
void clearDataPluginInterfaces();
|
||||
void clearGuiPluginInterfaces();
|
||||
void executePayloads();
|
||||
void connectOnlineHelpButton(LtsWidgets::LtsDialog *widget);
|
||||
|
||||
void aboutToCloseTab(LtsWidgets::LayoutArea area);
|
||||
|
||||
QPointer<LtsSessionManager> m_sessionManager;
|
||||
QMap<int , std::shared_ptr<GuiPluginBase::Interface> > m_payloadPriorityMap;
|
||||
QList<std::shared_ptr<GuiPluginBase::Interface> > m_payloadList;
|
||||
LtsWidgets::LtsBackgroundWidget *m_mainBackground;
|
||||
bool m_hasBaseLayout;
|
||||
LtsWidgets::LtsBaseLayoutWidget *m_baseLayout;
|
||||
bool m_markedForDeletion;
|
||||
bool m_payloads;
|
||||
QVector<LtsNotification::LtsNotificationController *> m_notiCtlList;
|
||||
bool m_initDone;
|
||||
bool m_payloadsDone { false };
|
||||
bool m_menuVisible;
|
||||
|
||||
bool m_firstActionsFetch;
|
||||
LtsWidgets::ExerciseData *m_exerciseData;
|
||||
QVector<LtsWidgets::PluginData> m_missingRightActions;
|
||||
std::shared_ptr<Core::Interface::Ftc> m_coreFtc;
|
||||
GuiPluginBase::Interface *m_currentInitIfc;
|
||||
bool m_slotPluginInitDoneMutex;
|
||||
bool m_pluginInitDone;
|
||||
QJsonObject m_savegame;
|
||||
bool m_hidden;
|
||||
int m_screenId { -1 };
|
||||
int m_screenContainerId { -1 };
|
||||
int m_screenIdPreset { -1 };
|
||||
int m_screenContainerIdPreset { -1 };
|
||||
bool m_loadedFromSavegame;
|
||||
std::shared_ptr<OnlineHelp::ForeignOnlineHelpViewerGuiInterface> m_ohvIfc;
|
||||
bool m_foreverInvisible;
|
||||
QStringList m_failedFetches;
|
||||
QVector<LtsWidgets::LtsBackgroundWidget *> m_bgWidgets;
|
||||
QString m_workspaceId;
|
||||
bool m_needsToBeSuccessfullyPlaced { true };
|
||||
QString m_name;
|
||||
QTimer *m_blub { nullptr };
|
||||
QTimer *m_scriptEditorTimer { nullptr };
|
||||
int m_blub2;
|
||||
QPointer<LtsSession> m_dependency;
|
||||
bool m_presetBaseLayoutAsSecondaryWidget { false };
|
||||
int m_id;
|
||||
};
|
||||
|
||||
}
|
||||
Executable
+107
@@ -0,0 +1,107 @@
|
||||
#include "lts_session_data.h"
|
||||
|
||||
|
||||
namespace LtsSessionData
|
||||
{
|
||||
|
||||
struct LtsSessionDataHandler
|
||||
{
|
||||
LtsSessionData ltsSessionData;
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(LtsSessionDataHandler, s_ltsSessionData)
|
||||
|
||||
|
||||
LtsSessionData::LtsSessionData()
|
||||
: m_domainIdPreset(-1)
|
||||
, m_partitionIdPreset(-1)
|
||||
, m_partitionTypePreset(IDL::PartitionType::Any)
|
||||
, m_operatorId(-1)
|
||||
, m_scriptId(0)
|
||||
, m_showTerminalWindow(false)
|
||||
, m_requestedAppId(LtsAppDescriptor::App::Login)
|
||||
, m_workstationId(-1)
|
||||
, m_isTablet(false)
|
||||
, m_placeScriptScreens(false)
|
||||
{
|
||||
|
||||
setAsTablet(false);
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
LtsSessionData *LtsSessionData::getInstance()
|
||||
{
|
||||
return &s_ltsSessionData->ltsSessionData;
|
||||
}
|
||||
|
||||
|
||||
void LtsSessionData::loggedOut()
|
||||
{
|
||||
m_operatorId = -1;
|
||||
m_operatorRights.clear();
|
||||
m_operatorName.clear();
|
||||
m_showTerminalWindow = false;
|
||||
m_profilePicture = QPixmap();
|
||||
m_visibleParties.clear();
|
||||
}
|
||||
|
||||
|
||||
void LtsSessionData::removePresets()
|
||||
{
|
||||
|
||||
m_partitionIdPreset = -1;
|
||||
m_partitionTypePreset = IDL::PartitionType::Any;
|
||||
|
||||
m_operatorNamePreset.clear();
|
||||
m_passwordPreset.clear();
|
||||
}
|
||||
|
||||
|
||||
void LtsSessionData::clear()
|
||||
{
|
||||
removePresets();
|
||||
loggedOut();
|
||||
}
|
||||
|
||||
|
||||
bool LtsSessionData::hasOperatorRight(int operatorRight) const
|
||||
{
|
||||
if (operatorRight == 0)
|
||||
return true;
|
||||
if (m_operatorRights.contains(operatorRight))
|
||||
return true;
|
||||
return m_operatorRights.contains(-1);
|
||||
}
|
||||
|
||||
|
||||
bool LtsSessionData::isVisibleParty(int exerciseId, int partyId) const
|
||||
{
|
||||
for (const auto &visibleParties : m_visibleParties)
|
||||
{
|
||||
if (visibleParties.exerciseId != exerciseId)
|
||||
continue;
|
||||
return visibleParties.visibleParties.contains(partyId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const QVector<int> LtsSessionData::getVisibleParties(int exerciseId) const
|
||||
{
|
||||
for(auto visibleParties : m_visibleParties)
|
||||
{
|
||||
if (visibleParties.exerciseId == exerciseId)
|
||||
return visibleParties.visibleParties;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
void LtsSessionData::setAsTablet(bool isTablet)
|
||||
{
|
||||
m_isTablet = isTablet;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+133
@@ -0,0 +1,133 @@
|
||||
#pragma once
|
||||
|
||||
#include <LtsSession/ltssessiondata_export.h>
|
||||
#include <ProjectConfig/project_defines.h>
|
||||
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QPixmap>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QSet>
|
||||
#include <QVariant>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
namespace LtsSessionData
|
||||
{
|
||||
|
||||
struct PartiesByExercise
|
||||
{
|
||||
int exerciseId = 0;
|
||||
QVector<int> visibleParties;
|
||||
};
|
||||
|
||||
class LTSSESSIONDATA_EXPORT LtsSessionData
|
||||
{
|
||||
public:
|
||||
static LtsSessionData *getInstance();
|
||||
|
||||
|
||||
const QString &getOperatorNamePreset() const { return m_operatorNamePreset; }
|
||||
const QString &getPasswordPreset() const { return m_passwordPreset; }
|
||||
void setOperatorPreset(const QString &operatorName, const QString &password) { m_operatorNamePreset = operatorName; m_passwordPreset = password; }
|
||||
|
||||
int getDomainIdPreset() const { return m_domainIdPreset; }
|
||||
void setDomainIdPreset(int domainIdPreset) { m_domainIdPreset = domainIdPreset; }
|
||||
|
||||
QStringList getQosFile() const {return m_qosFile; }
|
||||
void setQosFile(const QStringList &qosFile) { m_qosFile = qosFile; }
|
||||
|
||||
int getPartitionIdPreset() const { return m_partitionIdPreset; }
|
||||
IDL::PartitionType getPartitionTypePreset() const { return m_partitionTypePreset; }
|
||||
void setPartitionPreset(const int partitionId, IDL::PartitionType partitionType) { m_partitionIdPreset = partitionId; m_partitionTypePreset = partitionType; }
|
||||
|
||||
|
||||
|
||||
void removePresets();
|
||||
|
||||
|
||||
|
||||
int getScriptId() const { return m_scriptId; }
|
||||
void setScriptId(int scriptId) { m_scriptId = scriptId; }
|
||||
|
||||
int getOperatorId() const { return m_operatorId; }
|
||||
void setOperatorId(int operatorId) { m_operatorId = operatorId; }
|
||||
|
||||
const QString &getOperatorName() const { return m_operatorName; }
|
||||
void setOperatorName(const QString &operatorName) { m_operatorName = operatorName; }
|
||||
|
||||
const QSet<int> &getOperatorRights() const { return m_operatorRights; }
|
||||
void setOperatorRights(const QSet<int> &operatorRights) { m_operatorRights = operatorRights; }
|
||||
bool hasOperatorRight(int operatorRight) const;
|
||||
|
||||
const QPixmap &getProfilePicture() const { return m_profilePicture; }
|
||||
void setProfilePicture(const QPixmap &profilePicture) { m_profilePicture = profilePicture; }
|
||||
|
||||
bool isVisibleParty(int exerciseId, int partyId) const;
|
||||
const QVector<PartiesByExercise> &getVisibleParties() const { return m_visibleParties; }
|
||||
const QVector<int> getVisibleParties(int exerciseId) const;
|
||||
void setVisibleParties(const QVector<PartiesByExercise> &visibleParties) { m_visibleParties = visibleParties; }
|
||||
|
||||
QUrl getTcpConnectionUrl() const { return m_tcpConnectionUrl; }
|
||||
void setTcpConnectionUrl(const QUrl &tcpConnectionUrl) { m_tcpConnectionUrl = tcpConnectionUrl; }
|
||||
|
||||
bool getShowTerminalWindow() const { return m_showTerminalWindow; }
|
||||
void setShowTerminalWindow(bool showTerminalWindow) { m_showTerminalWindow = showTerminalWindow; }
|
||||
|
||||
LtsAppDescriptor::App getRequestedAppId() const { return m_requestedAppId; }
|
||||
void setRequestedAppId(LtsAppDescriptor::App requestedAppId) { m_requestedAppId = requestedAppId; }
|
||||
|
||||
int getWorkstationId() const { return m_workstationId; }
|
||||
void setWorkstationId(int workstationId) { m_workstationId = workstationId; }
|
||||
|
||||
bool isTablet() const { return m_isTablet; }
|
||||
void setAsTablet(bool isTablet = true);
|
||||
|
||||
bool getPlaceScriptScreens() const { return m_placeScriptScreens; }
|
||||
void setPlaceScriptScreens(bool placeScriptScreens) { m_placeScriptScreens = placeScriptScreens; }
|
||||
|
||||
bool hasDebugFlag(const QString &debugFlag) const { return m_debugFlags.constEnd() != m_debugFlags.constFind(debugFlag); }
|
||||
QVariant debugFlagValue(const QString &debugFlag) const { QVariant result; auto it = m_debugFlags.constFind(debugFlag); if (it != m_debugFlags.constEnd()) result = *it; return result; }
|
||||
void setDebugFlagValue(const QString &debugFlag, const QVariant &value) { m_debugFlags.insert(debugFlag, value); }
|
||||
const QMap<QString, QVariant> &debugFlags() const { return m_debugFlags; }
|
||||
void removeDebugFlag(const QString &debugFlag) { m_debugFlags.remove(debugFlag); }
|
||||
|
||||
void clear();
|
||||
void loggedOut();
|
||||
|
||||
private:
|
||||
LtsSessionData();
|
||||
~LtsSessionData() = default;
|
||||
friend struct LtsSessionDataHandler;
|
||||
|
||||
|
||||
QString m_operatorNamePreset;
|
||||
QString m_passwordPreset;
|
||||
QStringList m_qosFile;
|
||||
QUrl m_tcpConnectionUrl;
|
||||
int m_domainIdPreset;
|
||||
int m_partitionIdPreset;
|
||||
IDL::PartitionType m_partitionTypePreset;
|
||||
|
||||
int m_operatorId;
|
||||
int m_scriptId;
|
||||
QString m_operatorName;
|
||||
bool m_showTerminalWindow;
|
||||
QSet<int> m_operatorRights;
|
||||
QPixmap m_profilePicture;
|
||||
QVector<PartiesByExercise> m_visibleParties;
|
||||
QMap<QString, QVariant> m_debugFlags;
|
||||
LtsAppDescriptor::App m_requestedAppId;
|
||||
int m_workstationId;
|
||||
bool m_isTablet;
|
||||
bool m_placeScriptScreens;
|
||||
};
|
||||
|
||||
static inline bool hasOperatorRight(int operatorRight)
|
||||
{
|
||||
auto instance = LtsSessionData::getInstance();
|
||||
return instance->hasOperatorRight(operatorRight);
|
||||
}
|
||||
|
||||
}
|
||||
+389
@@ -0,0 +1,389 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_session_data_dds.h"
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <DDS/DTC/generic_dtc_impl.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QSet>
|
||||
#include <QVector>
|
||||
#include <DDS/QosProfile/DDS_DefaultQos.h>
|
||||
#include <QDebug>
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class DdsConnectionContainer
|
||||
{
|
||||
struct DdsConnection : public DdsConnectionParams
|
||||
{
|
||||
std::weak_ptr<DDSConnector::DdsConnector> ddsConnector = std::weak_ptr<DDSConnector::DdsConnector>();
|
||||
|
||||
DdsConnection() = default;
|
||||
explicit DdsConnection(const DdsConnectionParams &p)
|
||||
: DdsConnectionParams(p)
|
||||
{}
|
||||
};
|
||||
QVector<DdsConnection> ddsConnections;
|
||||
public:
|
||||
|
||||
std::shared_ptr<DDSConnector::DdsConnector> findGlobalConnection()
|
||||
{
|
||||
for (int i = ddsConnections.size() - 1; i >= 0; --i)
|
||||
{
|
||||
const DdsConnection &conn = ddsConnections.at(i);
|
||||
if (conn.partitionType != IDL::PartitionType::Global)
|
||||
continue;
|
||||
auto ret = conn.ddsConnector.lock();
|
||||
if (ret != nullptr)
|
||||
return ret;
|
||||
|
||||
ddsConnections.removeAt(i);
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return std::shared_ptr<DDSConnector::DdsConnector>();
|
||||
}
|
||||
|
||||
std::shared_ptr<DDSConnector::DdsConnector> findConnection(const DdsConnectionParams &connParams)
|
||||
{
|
||||
for (int i = ddsConnections.size() - 1; i >= 0; --i)
|
||||
{
|
||||
const DdsConnection &conn = ddsConnections.at(i);
|
||||
if (conn != connParams)
|
||||
continue;
|
||||
auto ret = conn.ddsConnector.lock();
|
||||
if (ret != nullptr)
|
||||
return ret;
|
||||
|
||||
ddsConnections.removeAt(i);
|
||||
}
|
||||
return std::shared_ptr<DDSConnector::DdsConnector>();
|
||||
}
|
||||
|
||||
dds::domain::DomainParticipant findMatchingDomainParticipant(const DdsConnectionParams &connParams)
|
||||
{
|
||||
for (int i = ddsConnections.size() - 1; i >= 0; --i)
|
||||
{
|
||||
const DdsConnection &conn = ddsConnections.at(i);
|
||||
if (!connParams.hasSameDomainParams(conn))
|
||||
continue;
|
||||
auto ret = conn.ddsConnector.lock();
|
||||
if (ret != nullptr)
|
||||
return ret->getDomainParticipant();
|
||||
|
||||
ddsConnections.removeAt(i);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void insertConnection(const DdsConnectionParams &connParams,
|
||||
const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector)
|
||||
{
|
||||
DdsConnection val(connParams);
|
||||
val.ddsConnector = ddsConnector;
|
||||
|
||||
ddsConnections += val;
|
||||
}
|
||||
};
|
||||
Q_GLOBAL_STATIC(DdsConnectionContainer, s_ddsConnections)
|
||||
|
||||
|
||||
|
||||
class DataPluginContainer
|
||||
{
|
||||
public:
|
||||
struct DataPluginValue
|
||||
{
|
||||
QString identifier;
|
||||
std::weak_ptr<DataPluginBase::Interface> weakIfc;
|
||||
|
||||
bool operator==(const DataPluginValue &o) const
|
||||
{
|
||||
return identifier == o.identifier && weakIfc.lock().get() == o.weakIfc.lock().get();
|
||||
}
|
||||
};
|
||||
|
||||
QMap<DdsConnectionParams, QSet<DataPluginValue>> m_dataPlugins;
|
||||
public:
|
||||
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> findDataPlugins(const DdsConnectionParams &connParams);
|
||||
void insertDataPlugins(const DdsConnectionParams &connParams,
|
||||
const QMap<QString, std::shared_ptr<DataPluginBase::Interface>> &dataPlugins);
|
||||
};
|
||||
|
||||
uint qHash(const DataPluginContainer::DataPluginValue &val)
|
||||
{
|
||||
qint64 ptr = reinterpret_cast<qint64>(val.weakIfc.lock().get());
|
||||
return ::qHash(val.identifier) ^ ::qHash(ptr);
|
||||
}
|
||||
|
||||
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> DataPluginContainer::findDataPlugins(const DdsConnectionParams &connParams)
|
||||
{
|
||||
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> ret;
|
||||
DdsConnectionParams key(connParams);
|
||||
key.exerciseId = 0;
|
||||
|
||||
auto it = m_dataPlugins.find(key);
|
||||
if (it != m_dataPlugins.end())
|
||||
{
|
||||
QSet<DataPluginValue> &cont = it.value();
|
||||
auto itCont = cont.begin();
|
||||
while (itCont != cont.end())
|
||||
{
|
||||
auto spPlugin = itCont->weakIfc.lock();
|
||||
if (spPlugin)
|
||||
{
|
||||
ret[itCont->identifier] = spPlugin;
|
||||
++itCont;
|
||||
}
|
||||
else
|
||||
{
|
||||
itCont = cont.erase(itCont);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DataPluginContainer::insertDataPlugins(const DdsConnectionParams &connParams,
|
||||
const QMap<QString, std::shared_ptr<DataPluginBase::Interface>> &dataPlugins)
|
||||
{
|
||||
DdsConnectionParams key(connParams);
|
||||
key.exerciseId = 0;
|
||||
|
||||
QSet<DataPluginValue> cont;
|
||||
cont.reserve(dataPlugins.size());
|
||||
for (auto it = dataPlugins.begin(); it != dataPlugins.end(); ++it)
|
||||
{
|
||||
DataPluginValue val;
|
||||
val.identifier = it.key();
|
||||
val.weakIfc = it.value();
|
||||
cont += val;
|
||||
}
|
||||
|
||||
m_dataPlugins[key].unite(cont);
|
||||
}
|
||||
|
||||
Q_GLOBAL_STATIC(DataPluginContainer, s_dataPlugins)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LtsSessionDataDds::LtsSessionDataDds(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_exerciseId(-1)
|
||||
, m_emittedTime(0)
|
||||
, m_curMSecSinceEpoch(0)
|
||||
, m_active(true)
|
||||
, m_fetcher(nullptr)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.Session"))
|
||||
{}
|
||||
|
||||
LtsSessionDataDds::~LtsSessionDataDds()
|
||||
{
|
||||
m_dtcPartitionTime = nullptr;
|
||||
m_ddsConnector = nullptr;
|
||||
delete m_fetcher;
|
||||
}
|
||||
|
||||
bool LtsSessionDataDds::init(const DdsConnectionParams &connParams)
|
||||
{
|
||||
|
||||
m_ddsConnector = s_ddsConnections->findConnection(connParams);
|
||||
m_exerciseId = connParams.exerciseId;
|
||||
m_qosFileList = QStringList(connParams.qos_file);
|
||||
if (m_ddsConnector == nullptr)
|
||||
{
|
||||
|
||||
dds::domain::DomainParticipant dp = s_ddsConnections->findMatchingDomainParticipant(connParams);
|
||||
if (dp != nullptr)
|
||||
return init(dp, connParams);
|
||||
#ifdef WIN_32
|
||||
DDS::QosProfile::ConnectionType type = DDS::QosProfile::ConnectionType::Tablet;
|
||||
#else
|
||||
DDS::QosProfile::ConnectionType type = DDS::QosProfile::ConnectionType::Client;
|
||||
#endif
|
||||
|
||||
m_ddsConnector = std::make_shared<DDSConnector::DdsConnector>(connParams.domainId,
|
||||
connParams.partitionType,
|
||||
connParams.partitionId,
|
||||
connParams.exerciseId,
|
||||
type);
|
||||
s_ddsConnections()->insertConnection(connParams, m_ddsConnector);
|
||||
}
|
||||
return initInternal();
|
||||
}
|
||||
|
||||
bool LtsSessionDataDds::init(const dds::domain::DomainParticipant &dp, const DdsConnectionParams &connParams)
|
||||
{
|
||||
Q_ASSERT(dp.domain_id() == connParams.domainId);
|
||||
|
||||
m_ddsConnector = s_ddsConnections->findConnection(connParams);
|
||||
m_exerciseId = connParams.exerciseId;
|
||||
|
||||
|
||||
|
||||
QStringList qosList;
|
||||
if (!connParams.qos_file.isEmpty())
|
||||
{
|
||||
qosList.append(connParams.qos_file);
|
||||
}
|
||||
|
||||
if (!qosList.isEmpty())
|
||||
m_qosFileList = qosList;
|
||||
else
|
||||
m_qosFileList.clear();
|
||||
|
||||
#ifdef WIN_32
|
||||
DDS::QosProfile::ConnectionType type = DDS::QosProfile::ConnectionType::Tablet;
|
||||
#else
|
||||
DDS::QosProfile::ConnectionType type = DDS::QosProfile::ConnectionType::Client;
|
||||
#endif
|
||||
|
||||
if (m_ddsConnector == nullptr)
|
||||
{
|
||||
m_ddsConnector = std::make_shared<DDSConnector::DdsConnector>(dp,
|
||||
connParams.partitionType,
|
||||
type,
|
||||
connParams.partitionId
|
||||
);
|
||||
|
||||
|
||||
|
||||
s_ddsConnections()->insertConnection(connParams, m_ddsConnector);
|
||||
}
|
||||
return initInternal();
|
||||
}
|
||||
|
||||
Fetcher *LtsSessionDataDds::fetcher(const QString &yourPluginsName)
|
||||
{
|
||||
if (m_fetcher == nullptr)
|
||||
m_fetcher = new Fetcher(this, yourPluginsName);
|
||||
|
||||
return m_fetcher;
|
||||
}
|
||||
|
||||
QString LtsSessionDataDds::partitionTypeString(IDL::PartitionType partitionType)
|
||||
{
|
||||
switch (partitionType)
|
||||
{
|
||||
case IDL::PartitionType::AllExercises:
|
||||
return QStringLiteral("AllExercises");
|
||||
case IDL::PartitionType::Any:
|
||||
return QStringLiteral("Any");
|
||||
case IDL::PartitionType::Exercise:
|
||||
return QStringLiteral("Exercise");
|
||||
case IDL::PartitionType::Global:
|
||||
return QStringLiteral("Global");
|
||||
case IDL::PartitionType::Replay:
|
||||
return QStringLiteral("Replay");
|
||||
}
|
||||
|
||||
return QStringLiteral("Invalid (%1)").arg(int(partitionType));
|
||||
}
|
||||
|
||||
QString LtsSessionDataDds::toString() const
|
||||
{
|
||||
return QStringLiteral("(LtsSessionDataDds: id=%1, partitionId=%2, partitionType=%3(%4), exerciseId=%5)").arg((qulonglong)this).arg(partitionId()).arg(static_cast<int>(partitionType())).arg(partitionTypeString(partitionType())).arg(exerciseId());
|
||||
}
|
||||
|
||||
int LtsSessionDataDds::domainId() const
|
||||
{
|
||||
return m_ddsConnector ? m_ddsConnector->getDomainId() : -1;
|
||||
}
|
||||
|
||||
int LtsSessionDataDds::exerciseId() const
|
||||
{
|
||||
return m_exerciseId;
|
||||
}
|
||||
|
||||
int LtsSessionDataDds::partitionId() const
|
||||
{
|
||||
return m_ddsConnector ? m_ddsConnector->getPartitionId() : -1;
|
||||
}
|
||||
|
||||
IDL::PartitionType LtsSessionDataDds::partitionType() const
|
||||
{
|
||||
return m_ddsConnector ? m_ddsConnector->getPartitionType() : IDL::PartitionType::Global;
|
||||
}
|
||||
|
||||
QStringList LtsSessionDataDds::qosFile() const
|
||||
{
|
||||
return m_ddsConnector ? m_qosFileList : QStringList();
|
||||
}
|
||||
|
||||
QUrl LtsSessionDataDds::tcpConnectionUrl() const
|
||||
{
|
||||
return m_ddsConnector ? m_ddsConnector->getTcpConnectionUrl() : QUrl();
|
||||
}
|
||||
|
||||
DdsConnectionParams LtsSessionDataDds::connParams() const
|
||||
{
|
||||
DdsConnectionParams connParams;
|
||||
connParams.domainId = domainId();
|
||||
connParams.exerciseId = exerciseId();
|
||||
connParams.partitionId = partitionId();
|
||||
connParams.partitionType = partitionType();
|
||||
connParams.qos_file = qosFile();
|
||||
connParams.tcpConnectionUrl = tcpConnectionUrl();
|
||||
return connParams;
|
||||
}
|
||||
|
||||
|
||||
bool LtsSessionDataDds::initInternal()
|
||||
{
|
||||
if (!m_ddsConnector || !m_ddsConnector->init(m_qosFileList))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "DDS connector could not be initialized - session aborted!";
|
||||
m_ddsConnector = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
m_ddsConnectorGlobal = s_ddsConnections->findGlobalConnection();
|
||||
if (!m_ddsConnectorGlobal)
|
||||
m_ddsConnectorGlobal = m_ddsConnector;
|
||||
|
||||
m_dtcPartitionTime.reset(m_ddsConnector->createDTC<DTC::PartitionTimeImpl>());
|
||||
assert(m_dtcPartitionTime.get());
|
||||
|
||||
m_dtcPartitionTime->setSubscriberCallback([this](const Core::PartitionTime & data, DataModification)
|
||||
{
|
||||
m_curMSecSinceEpoch = data.timeStamp();
|
||||
emit partitionTimeChangedInternal();
|
||||
});
|
||||
connect(this, &LtsSessionDataDds::partitionTimeChangedInternal,
|
||||
this, &LtsSessionDataDds::onPartitionTimeChangedInternal, Qt::QueuedConnection);
|
||||
return true;
|
||||
}
|
||||
|
||||
void LtsSessionDataDds::onPartitionTimeChangedInternal()
|
||||
{
|
||||
if (!m_active)
|
||||
return;
|
||||
if (m_emittedTime == m_curMSecSinceEpoch)
|
||||
return;
|
||||
m_emittedTime = m_curMSecSinceEpoch;
|
||||
emit partitionTimeChanged(m_curMSecSinceEpoch);
|
||||
}
|
||||
|
||||
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> LtsSessionDataDds::availableDataPluginInterfaces() const
|
||||
{
|
||||
return s_dataPlugins->findDataPlugins(connParams());
|
||||
|
||||
}
|
||||
|
||||
void LtsSessionDataDds::addAvailablaeDataPluginInterfaces(const QMap<QString, std::shared_ptr<DataPluginBase::Interface>> &dataPlugins)
|
||||
{
|
||||
s_dataPlugins->insertDataPlugins(connParams(),
|
||||
dataPlugins);
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+349
@@ -0,0 +1,349 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QUrl>
|
||||
#include <memory>
|
||||
#include <DDS/Core/core_dtc_types.h>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <Common/ProjectConfig/project_defines.h>
|
||||
#include <LtsSession/ltssessiondatadds_export.h>
|
||||
|
||||
|
||||
namespace DataPluginBase { class Interface; }
|
||||
namespace DDSConnector { class DdsConnector; }
|
||||
namespace GuiPluginBase { class Interface; }
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
struct DdsConnectionParams
|
||||
{
|
||||
int domainId = -1;
|
||||
int partitionId = 0;
|
||||
int exerciseId = 0;
|
||||
IDL::PartitionType partitionType = IDL::PartitionType::Any;
|
||||
QUrl tcpConnectionUrl;
|
||||
QStringList qos_file;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
class LTSSESSIONDATADDS_EXPORT LtsSessionDataDds
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
|
||||
explicit LtsSessionDataDds(QObject *parent = nullptr);
|
||||
public:
|
||||
~LtsSessionDataDds();
|
||||
|
||||
bool init(const DdsConnectionParams &connParams);
|
||||
bool init(const dds::domain::DomainParticipant &dp,
|
||||
const DdsConnectionParams &connParams);
|
||||
|
||||
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; }
|
||||
|
||||
|
||||
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())
|
||||
{
|
||||
member = nullptr;
|
||||
ERROR_LOG(m_logger) << "Error initializing dtc/ftc for service " << T::identifier();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T, typename S>
|
||||
bool getForeignDataInterface(std::shared_ptr<S> &val) const
|
||||
{
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename S>
|
||||
bool getForeignDataInterface_NEW(std::shared_ptr<S> &val) const
|
||||
{
|
||||
|
||||
|
||||
for (const auto &i : m_dataPluginInterfaces)
|
||||
{
|
||||
val = std::dynamic_pointer_cast<S>(i);
|
||||
if (val)
|
||||
return true;
|
||||
}
|
||||
val.reset();
|
||||
DEBUG_LOG(m_logger) << "Trying to load foreign data ifc " << typeid(S).name() << " failed!"
|
||||
<< ", m_guiPluginInterfaces.size() = " << m_guiPluginInterfaces.size() << " - " << this;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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 (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;
|
||||
};
|
||||
|
||||
|
||||
class Fetcher
|
||||
{
|
||||
public:
|
||||
Fetcher(LtsSessionDataDds *sessionDataDds, const QString &caller)
|
||||
: m_sessionDataDds(sessionDataDds)
|
||||
, m_errors(false)
|
||||
, m_caller(caller)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.Fetcher"))
|
||||
, m_optional(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LtsSessionDataDds *m_sessionDataDds;
|
||||
bool m_errors;
|
||||
QString m_caller;
|
||||
QString m_whatWillNotWork;
|
||||
NGL::INGLLogger &m_logger;
|
||||
bool m_optional;
|
||||
QString m_resultType;
|
||||
QString m_getterFunctionType;
|
||||
|
||||
template <typename ForeignGuiInterface>
|
||||
void getForeignGuiInterface(std::shared_ptr<ForeignGuiInterface> &foreignGuiInterface, const QString &whatWillNotWork , bool optional)
|
||||
{
|
||||
if (!m_sessionDataDds->getForeignGuiInterface(foreignGuiInterface))
|
||||
{
|
||||
m_whatWillNotWork = whatWillNotWork;
|
||||
m_optional = optional;
|
||||
m_resultType = QString::fromUtf8(typeid(ForeignGuiInterface).name());
|
||||
m_getterFunctionType = QStringLiteral("gui interface");
|
||||
print();
|
||||
}
|
||||
}
|
||||
|
||||
bool status() const
|
||||
{
|
||||
return !m_errors;
|
||||
}
|
||||
|
||||
void print()
|
||||
{
|
||||
m_errors = true;
|
||||
|
||||
QString msg(QStringLiteral("%1 cannot find '%2' in %3 %4"));
|
||||
|
||||
if (m_optional)
|
||||
{
|
||||
INFO_LOG(m_logger) << msg.arg(m_caller, m_resultType, m_sessionDataDds->toString(), QStringLiteral("' - optional but %1 will not work").arg(m_whatWillNotWork));
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG(m_logger) << msg.arg(m_caller, m_resultType, m_sessionDataDds->toString(), QStringLiteral(" which is required"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
#include "lts_session_lock_handler.h"
|
||||
|
||||
#include <LtsWidgets/lts_message_dialog.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
|
||||
TopicLockHandler::TopicLockHandler()
|
||||
: QObject()
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.TopicLockHandler"))
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
TopicLockHandler::~TopicLockHandler()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
bool TopicLockHandler::init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc,
|
||||
int exerciseId)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
if (coreFtc == nullptr)
|
||||
return false;
|
||||
coreFtc->enableAll();
|
||||
m_exerciseId = exerciseId;
|
||||
m_coreFtc = coreFtc;
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TopicLockHandler::lock()
|
||||
{
|
||||
INFO_LOG(m_logger) << "LOCK " << m_topicInfo.topicName();
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << objStateAsString();
|
||||
|
||||
if (m_coreFtc == nullptr)
|
||||
return false;
|
||||
|
||||
if (m_locked)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << ": called lock while still locked! " << m_lockEntityId;
|
||||
Q_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto *sessionData = LtsSessionData::LtsSessionData::getInstance();
|
||||
|
||||
Core::TryLockEntityRequest req;
|
||||
req.id(m_lockEntityId);
|
||||
|
||||
req.entityTypeName(m_topicInfo.topicName().toStdString());
|
||||
req.entityId(m_topicInfo.entityId());
|
||||
req.exerciseId(m_exerciseId);
|
||||
|
||||
req.operatorId(sessionData->getOperatorId());
|
||||
req.workstationId(sessionData->getWorkstationId());
|
||||
|
||||
try
|
||||
{
|
||||
const Core::TryLockEntityReply reply(m_coreFtc->tryLockEntityRequest(req));
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << ": Reply received - state=" << objStateAsString()
|
||||
<< " - reply=" << reply;
|
||||
|
||||
if (reply.alreadyLocked().is_set())
|
||||
{
|
||||
const Core::LockEntityError &alreadyLocked = reply.alreadyLocked().get();
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << ": Topic already locked by ws " << alreadyLocked.workstationName() << " and op " << alreadyLocked.operatorName();
|
||||
|
||||
|
||||
|
||||
|
||||
const auto lockedBy(QStringLiteral("%2/%1").arg(QString::fromStdString(alreadyLocked.operatorName()), QString::fromStdString(alreadyLocked.workstationName())));
|
||||
|
||||
emit signalLockDialog(lockedBy);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << ": Topic NOT already locked";
|
||||
|
||||
Q_ASSERT(reply.id() > 0);
|
||||
m_locked = true;
|
||||
m_lockEntityId = reply.id();
|
||||
}
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << ": Failed to lock topic! " << err.what();
|
||||
Q_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TopicLockHandler::unlock()
|
||||
{
|
||||
INFO_LOG(m_logger) << "UNLOCK " << m_topicInfo.topicName() << " - " << m_lockEntityId;
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << objStateAsString();
|
||||
|
||||
if (m_coreFtc == nullptr)
|
||||
return false;
|
||||
|
||||
if (!m_locked)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << ": Tried to unlock while unlocked.. " << objStateAsString();
|
||||
Q_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_lockEntityId > 0);
|
||||
|
||||
const Core::TryUnlockEntityRequest req(m_lockEntityId);
|
||||
|
||||
|
||||
m_locked = false;
|
||||
m_lockEntityId = 0;
|
||||
|
||||
try
|
||||
{
|
||||
const auto reply(m_coreFtc->tryUnlockEntityRequest(req));
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << ": Reply received - state=" << objStateAsString()
|
||||
<< " - reply=" << reply;
|
||||
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << ": Topic unlocked!";
|
||||
}
|
||||
catch (const std::runtime_error &err)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << ": Failed to unlock topic! " << err.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
emit signalUnlockDialog();
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::string TopicLockHandler::objStateAsString() const
|
||||
{
|
||||
std::ostringstream o;
|
||||
o << " m_topicInfoId=" << m_lockEntityId
|
||||
<< ", entityId=" << m_topicInfo.entityId()
|
||||
<< ", exId=" << m_exerciseId
|
||||
<< ", lckd=" << m_locked
|
||||
<< ", asked=" << m_askedForLock
|
||||
<< ", delftrAnwr=" << m_deleteAfterAnswer;
|
||||
return o.str();
|
||||
}
|
||||
|
||||
|
||||
bool TopicLockHandler::slotUnlock()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " slotUnlock" << objStateAsString();
|
||||
return unlock();
|
||||
}
|
||||
|
||||
|
||||
void TopicLockHandler::slotTryLock(const LtsWidgets::TopicInfo &topicInfo)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START " << objStateAsString();
|
||||
|
||||
m_topicInfo = topicInfo;
|
||||
|
||||
if (m_topicInfo.topicName().isEmpty() || !topicInfo.isValid())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " no lockable topic, that's okay";
|
||||
return;
|
||||
}
|
||||
|
||||
lock();
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END " << objStateAsString();
|
||||
}
|
||||
|
||||
|
||||
void TopicLockHandler::slotFinalize()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START " << objStateAsString();
|
||||
|
||||
if (m_locked)
|
||||
{
|
||||
slotUnlock();
|
||||
}
|
||||
|
||||
deleteLater();
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END " << objStateAsString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TopicLockHanderData::TopicLockHanderData()
|
||||
: QObject()
|
||||
{
|
||||
}
|
||||
|
||||
void TopicLockHanderData::init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc, int exerciseId)
|
||||
{
|
||||
m_topicLockHandler = new TopicLockHandler();
|
||||
m_topicLockHandler->init(coreFtc, exerciseId);
|
||||
|
||||
connect(m_topicLockHandler.data(), &TopicLockHandler::signalLockDialog,
|
||||
this, &TopicLockHanderData::slotLock, Qt::UniqueConnection);
|
||||
connect(m_topicLockHandler.data(), &TopicLockHandler::signalUnlockDialog,
|
||||
this, &TopicLockHanderData::slotUnlock, Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
TopicLockHanderData::~TopicLockHanderData()
|
||||
{
|
||||
|
||||
if (m_topicLockHandler)
|
||||
m_topicLockHandler->slotFinalize();
|
||||
}
|
||||
|
||||
void TopicLockHanderData::unlock()
|
||||
{
|
||||
qDebug() << "Debugname=" << m_debugName << ": "
|
||||
<< " slotUnlock";
|
||||
if (m_topicLockHandler)
|
||||
m_topicLockHandler->slotUnlock();
|
||||
}
|
||||
|
||||
bool TopicLockHanderData::isLocked() const
|
||||
{
|
||||
if (!m_topicLockHandler)
|
||||
{
|
||||
qDebug() << "Debugname=" << m_debugName << ": "
|
||||
<< " isLocked -> no handler";
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Debugname=" << m_debugName << ": "
|
||||
<< " isLocked = " << m_topicLockHandler->isLocked();
|
||||
return m_topicLockHandler->isLocked();
|
||||
}
|
||||
|
||||
LtsWidgets::TopicInfo TopicLockHanderData::getTopicInfo() const
|
||||
{
|
||||
if (m_topicLockHandler)
|
||||
return m_topicLockHandler->getTopicInfo();
|
||||
return {};
|
||||
}
|
||||
|
||||
void TopicLockHanderData::slotTryLock(const LtsWidgets::TopicInfo &topicInfo)
|
||||
{
|
||||
qDebug() << "Debugname=" << m_debugName << ": "
|
||||
<< "slotTryLock " << m_topicLockHandler;
|
||||
if (!m_topicLockHandler)
|
||||
return;
|
||||
m_topicLockHandler->slotTryLock(topicInfo);
|
||||
}
|
||||
|
||||
|
||||
void TopicLockHanderData::slotLock(const QString &lockedBy)
|
||||
{
|
||||
|
||||
|
||||
qDebug() << "Debugname=" << m_debugName << ": "
|
||||
<< "slotLock";
|
||||
m_lockedBy = lockedBy;
|
||||
emit lockDataChanged();
|
||||
}
|
||||
|
||||
void TopicLockHanderData::slotUnlock()
|
||||
{
|
||||
qDebug() << "Debugname=" << m_debugName << ": "
|
||||
<< "slotUnlock";
|
||||
m_lockedBy.clear();
|
||||
emit lockDataChanged();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include <LtsSession/ltssession_export.h>
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <DDS/Core/core_ftc.h>
|
||||
|
||||
#include <QPointer>
|
||||
#include <memory>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LTSSESSION_EXPORT TopicLockHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TopicLockHandler();
|
||||
~TopicLockHandler();
|
||||
|
||||
bool init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc, int exerciseId);
|
||||
|
||||
bool isLocked() const { return m_locked; }
|
||||
LtsWidgets::TopicInfo getTopicInfo() const { return m_topicInfo; }
|
||||
|
||||
public slots:
|
||||
void slotTryLock(const LtsWidgets::TopicInfo &topicInfo);
|
||||
bool slotUnlock();
|
||||
void slotFinalize();
|
||||
|
||||
signals:
|
||||
void signalLockDialog(const QString &lockedBy);
|
||||
void signalUnlockDialog();
|
||||
|
||||
private:
|
||||
bool lock();
|
||||
bool unlock();
|
||||
std::string objStateAsString() const;
|
||||
|
||||
std::shared_ptr<Core::Interface::Ftc> m_coreFtc;
|
||||
|
||||
LtsWidgets::TopicInfo m_topicInfo;
|
||||
int m_lockEntityId{0};
|
||||
|
||||
int m_exerciseId{0};
|
||||
bool m_locked{false};
|
||||
bool m_askedForLock{false};
|
||||
bool m_deleteAfterAnswer{false};
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
|
||||
class LTSSESSION_EXPORT TopicLockHanderData : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TopicLockHanderData();
|
||||
~TopicLockHanderData();
|
||||
void init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc, int exerciseId);
|
||||
|
||||
void unlock();
|
||||
void slotTryLock(const LtsWidgets::TopicInfo &topicInfo);
|
||||
bool isLocked() const;
|
||||
LtsWidgets::TopicInfo getTopicInfo() const;
|
||||
const QString &getLockedBy() const { return m_lockedBy; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void lockDataChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotLock(const QString &lockedBy);
|
||||
void slotUnlock();
|
||||
public:
|
||||
QString m_debugName;
|
||||
private:
|
||||
QPointer<TopicLockHandler> m_topicLockHandler;
|
||||
QString m_lockedBy;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LtsSession/ltssession_export.h>
|
||||
#include <LtsPluginManager/lts_plugin_loader.h>
|
||||
#include <LtsPluginManager/lts_plugin_manager.h>
|
||||
#include <Common/ProjectConfig/project_defines.h>
|
||||
|
||||
#include <memory>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
namespace DeveloperTools
|
||||
{
|
||||
class AppWidget;
|
||||
}
|
||||
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSession;
|
||||
struct DdsConnectionParams;
|
||||
|
||||
class LTSSESSION_EXPORT LtsSessionManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LtsSessionManager();
|
||||
~LtsSessionManager();
|
||||
|
||||
|
||||
LtsSession *createSession(const DdsConnectionParams &connParams,
|
||||
bool hasBaseLayout = true,
|
||||
bool payloads = true,
|
||||
bool hidden = false);
|
||||
|
||||
|
||||
LtsSession *getSession(IDL::PartitionType partitionType, int partitionId);
|
||||
bool init(const DdsConnectionParams &connParams,
|
||||
const QVector<LtsPluginManager::AppPluginInstance> &dataPluginList,
|
||||
const QVector<LtsPluginManager::AppPluginInstance> &guiPluginList,
|
||||
LtsAppDescriptor::App appId, const QString &workspaceId,
|
||||
bool headless, bool hidden);
|
||||
int sessionCount() const { return m_sessionMap.count(); }
|
||||
LtsAppDescriptor::App appId() const { return m_appId; }
|
||||
bool isHeadless() const { return m_headless; }
|
||||
QVector<LtsSession *> sessions();
|
||||
void softQuit();
|
||||
|
||||
private:
|
||||
friend class DeveloperTools::DevDialog;
|
||||
friend class DeveloperTools::AppWidget;
|
||||
|
||||
struct SessionKey
|
||||
{
|
||||
SessionKey(IDL::PartitionType pt = IDL::PartitionType::Any, int pId = 0)
|
||||
: partitionType(pt)
|
||||
, partitionId(pId)
|
||||
{}
|
||||
IDL::PartitionType partitionType;
|
||||
int partitionId;
|
||||
|
||||
bool operator<(const SessionKey &o) const
|
||||
{
|
||||
if (partitionType != o.partitionType)
|
||||
return partitionType < o.partitionType;
|
||||
return partitionId < o.partitionId;
|
||||
}
|
||||
};
|
||||
|
||||
void logout();
|
||||
void addPayloads(LtsSession *session);
|
||||
|
||||
QMap<SessionKey, LtsSession *> m_sessionMap;
|
||||
QVector<LtsPluginManager::AppPluginInstance> m_dataPluginList;
|
||||
QVector<LtsPluginManager::AppPluginInstance> m_guiPluginList;
|
||||
LtsAppDescriptor::App m_appId;
|
||||
bool m_headless;
|
||||
NGL::INGLLogger &m_logger;
|
||||
|
||||
private slots:
|
||||
void slotCloseSession();
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
void signalStopBlock();
|
||||
void signalLogout();
|
||||
void signalQuit();
|
||||
void signalInitializationFinished();
|
||||
void signalInitializationAborted();
|
||||
void hideAllOtherBLWs(QObject *caller);
|
||||
void taskSwitch(QObject *caller);
|
||||
};
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user