Apply clang-format to Lts/Common and DTC/enum headers

- Formatted all CodeGen module files (9 files)
- Formatted LtsAppDescriptor module files
- Formatted LtsAppManager/AppChooser files
- Applied clang-format to all DTC and enum headers across modules
- Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/)

Cosmetic changes only, no functional modifications.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
torstenandCopilot committed 2026-08-19 14:46:29 +02:00
1 parent 1881d68aef
commit d6b6ffce7c
848 files changed
+89305 -100020

No files matched your search

File diff suppressed because it is too large. Load diff
+331 -230
View File
@@ -15,17 +15,13 @@
#include <LtsSession/ltssession_export.h>
#include <LtsWidgets/lts_base.h>
#include <QtCore/qobjectdefs.h> // for connections
#include <memory>
#include <QMap>
#include <QDebug>
#include <QJsonObject>
#include <QMap>
#include <QPointer>
#include <QVector>
#include <QDebug>
#include <QtCore/qobjectdefs.h> // for connections
#include <memory>
namespace LtsWidgets
{
@@ -35,285 +31,390 @@ class LtsBaseLayoutWidget;
struct ExerciseData;
class LtsDialog;
class LtsDragIcon;
}
} // namespace LtsWidgets
namespace LtsNotification
{
class LtsNotification;
class LtsNotificationController;
}
} // namespace LtsNotification
namespace LtsPluginManager
{
struct PluginInstance;
struct AppPluginInstance;
}
} // namespace LtsPluginManager
namespace DeveloperTools
{
class DevDialog;
class AppWidget;
}
} // namespace DeveloperTools
namespace Core
{
namespace Interface
{
class Ftc;
}
}
} // namespace Core
namespace OnlineHelp
{
class ForeignOnlineHelpViewerGuiInterface;
}
namespace LtsSession
{
class LTSSESSION_EXPORT LtsSession : public LtsSessionDataDds
{
Q_OBJECT
public:
static bool s_valgrind;
static int s_nextSessionId;
Q_OBJECT
public:
static bool s_valgrind;
static int s_nextSessionId;
enum class PluginInstanceStatus
{
UNKNOWN = 0,
LOADED,
FAILED, // e.g. fetchInterfaces gone wrong
};
enum class PluginInstanceStatus {
UNKNOWN = 0,
LOADED,
FAILED, // e.g. fetchInterfaces gone wrong
};
static QString appToString(LtsAppDescriptor::App app);
static QString appIconFilename(LtsAppDescriptor::App app);
static QIcon appToIcon(LtsAppDescriptor::App app);
static QString appToString(LtsAppDescriptor::App app);
static QString appIconFilename(LtsAppDescriptor::App app);
static QIcon appToIcon(LtsAppDescriptor::App app);
explicit LtsSession(LtsSessionManager *sessionManager);
~LtsSession();
explicit LtsSession(LtsSessionManager* sessionManager);
~LtsSession();
QString toString() const;
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; } // cannot be reverted
void aboutToClose();
bool isInitializationDone() const { return m_initDone; }
void presetBaseLayoutAsSecondaryWidget() { m_presetBaseLayoutAsSecondaryWidget = true; }
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();
/**
* @brief addAction - IMPORTANT: Actions have to be translated on retranslate by adding the same action (with same identifier)
* but with translated text & menu group! This replaces the text & menu group only. The pointer to the action stays the same.
* @param plData
* @param isFirstRun
* @return
*/
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; }
void setPayloadsEnabled()
{
m_payloads = true;
} // cannot be reverted
LtsNotification::LtsNotification *createNotification(const QString &identifier);
void aboutToClose();
bool isInitializationDone() const
{
return m_initDone;
}
void presetBaseLayoutAsSecondaryWidget()
{
m_presetBaseLayoutAsSecondaryWidget = true;
}
/**
* @brief setExerciseData is called by the ExerciseManagement plugin and sets the human reabale name of the exercise and puts the text into all base layouts of this session
* @param exerciseData the human reable exercise name of the current exercise
*/
void setExerciseData(const LtsWidgets::ExerciseData &exerciseData);
const LtsWidgets::ExerciseData *exerciseData() const;
void setProfilePicture(const QPixmap &pixmap);
void setBaseLayoutVisible() { m_hasBaseLayout = true; } // cannot be reverted after base layout was created (creation begins after all payloads have been executed OR if makeVisible was called)!
bool isVisible() const { return (m_baseLayout != nullptr); }
const QString &name() const { return m_name; }
void setName(const QString &name) { m_name = name; }
/**
* @brief isChildOfSession can be used to check if a fiven QWidget is part of the current Session's application
*
* @param child widget to check against.
* @return true if widget is child of session baselayout
*/
bool isChildOfSession(QWidget* child);
LtsWidgets::LtsBaseLayoutWidget* baseLayout() { return m_baseLayout; }
QWidget *baseLayoutWidget(); // prevents some classes to include LtsBaseLayoutWidget.h just to specify the blw as a parent widget
void setMarkForDeletion() { m_markedForDeletion = true; } // session not needed anymore after payloads? then mark for deletion and after payloads, this session will be deleted(Later)
void doneInitializingSession(); // TODO: private
bool notifyUnsavedChanges(); // true if NO unsaved changes
const QVector<LtsWidgets::LtsBackgroundWidget *> &bgWidgets() const { return m_bgWidgets; }
* @brief addAction - IMPORTANT: Actions have to be translated on retranslate by adding the same action (with same
* identifier) but with translated text & menu group! This replaces the text & menu group only. The pointer to the
* action stays the same.
* @param plData
* @param isFirstRun
* @return
*/
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;
// checks if a widget with the given data already exists
bool widgetExists(const QString &menuGroup, const QString &identifier, LtsWidgets::LayoutArea area) const;
/**
* @brief addWidget <exact copy of addWidget in LtsBaseLayoutWidget [is redirected to the coherent LtsBaseLayoutWidget]>
* keep identifier empty to prevent checking for existing tabs
* @return (see addWidget in LtsBaseLayoutWidget)
*/
bool addWidget(LtsWidgets::LtsDialog *widget,
const QString &menuGroup,
const QString &identifier,
LtsWidgets::LayoutArea area = LtsWidgets::LayoutArea::eUnknown,
bool setClosable = true);
void setScreenIdPreset(int screenId)
{
m_screenIdPreset = screenId;
}
LtsWidgets::LtsDialog *getWidget(const QString &menuGroup, const QString &identifier, LtsWidgets::LayoutArea area);
bool focusTab(const QString &menuGroup, const QString &identifier, LtsWidgets::LayoutArea area);
void setScreenContainerIdPreset(int screenPart)
{
m_screenContainerIdPreset = screenPart;
}
/** WARNING: do not save the returned value, as baseLayouts can die (which kills LtsTabWidget also), so reuse this method instead of saving the pointer to the LtsTabWidget
* @brief locateWidget locates the given widget 'widget' and returning the TabWidget on which it is on - widgets can be available in one of many LayoutAreas (TabWidgets) of many LtsBaseLayoutWidgets
* @param widgetToLocate the widget to look for in the given layoutArea which is located in one of many LtsBaseLayoutWidget
* @param area the area the widget is located
* @return LtsTabWidget on which the widget is located
*/
LtsWidgets::LtsTabWidget *locateWidget(QWidget *widgetToLocate, LtsWidgets::LayoutArea area);
bool isForeverInvisible() const
{
return m_foreverInvisible;
}
LtsNotification::LtsNotification* createNotification(const QString& identifier);
/**
* @brief enable/disable baseLayout menu
* @param on if true enable otherwise disable
*/
void enableBaseLayoutMenu(bool on = true);
/**
* @brief setExerciseData is called by the ExerciseManagement plugin and sets the human reabale name of the exercise
* and puts the text into all base layouts of this session
* @param exerciseData the human reable exercise name of the current exercise
*/
void setExerciseData(const LtsWidgets::ExerciseData& exerciseData);
const LtsWidgets::ExerciseData* exerciseData() const;
void setProfilePicture(const QPixmap& pixmap);
/**
* @brief enable/disable LayoutArea
* @param area the area to enable/disable
* @param on if true enable otherwise disable
*/
void enableBaseLayoutArea(LtsWidgets::LayoutArea area, bool on = true);
void setBaseLayoutVisible()
{
m_hasBaseLayout = true;
} // cannot be reverted after base layout was created (creation begins after all payloads have been executed OR if
// makeVisible was called)!
/**
* @brief Return the workstation ip for this workstation (== full ipv4 adress) - workstation id comes later from Asm
*/
static int workstationIp(); // really in LtsSession?
/**
* @brief Return the workstation name
*/
static QString workstationName(); // really in LtsSession?
bool isVisible() const
{
return (m_baseLayout != nullptr);
}
/**
* @brief missingRightActions Do not use.
* @return
*/
/*const*/ QVector<LtsWidgets::PluginData> &missingRightActions() /*const*/ { return m_missingRightActions; }
const QString& name() const
{
return m_name;
}
void setSavegame(const QJsonObject &sg) { m_savegame = sg; }
const QJsonObject &getSavegame() const { return m_savegame; }
void setName(const QString& name)
{
m_name = name;
}
void setHidden() { m_hidden = true; }
/**
* @brief isChildOfSession can be used to check if a fiven QWidget is part of the current Session's application
*
* @param child widget to check against.
* @return true if widget is child of session baselayout
*/
bool isChildOfSession(QWidget* child);
const QString workspaceId() const;
void setWorkspaceId(const QString &newWorkspaceId);
LtsWidgets::LtsBaseLayoutWidget* baseLayout()
{
return m_baseLayout;
}
LtsWidgets::ExcState exerciseState() const;
QWidget* baseLayoutWidget(); // prevents some classes to include LtsBaseLayoutWidget.h just to specify the blw as a
// parent widget
void setLoadedFromSavegame() { m_loadedFromSavegame = true; }
bool isLoadedFromSavegame() const { return m_loadedFromSavegame; }
void addDeveloperActions();
void refetchActions(); // Do not use.
void setDependency(LtsSession *session);
bool hasDependency(LtsSession *session) { return (m_dependency.data() == session); }
LtsSession *dependency() const { return m_dependency; }
void setMarkForDeletion()
{
m_markedForDeletion = true;
} // session not needed anymore after payloads? then mark for deletion and after payloads, this session will be
// deleted(Later)
// bogus.
void setNeedsToBeSuccessfullyPlaced(bool needed = true) { m_needsToBeSuccessfullyPlaced = needed; } // works even after session creation as 'slotStartPluginInit', which finalizes the session (creates blw, etc.) is called async!
void doneInitializingSession(); // TODO: private
bool notifyUnsavedChanges(); // true if NO unsaved changes
int id() const { return m_id; }
const QVector<LtsWidgets::LtsBackgroundWidget*>& bgWidgets() const
{
return m_bgWidgets;
}
public slots:
void slotExecuteNextPayload(); // NEVER call this directly, queue a signal to this slot !
void slotPluginInitDone(); // NEVER call this directly, queue a signal to this slot !
void slotShowOnlineHelp(const QString &fileName);
//void takeOverBdv();
// checks if a widget with the given data already exists
bool widgetExists(const QString& menuGroup, const QString& identifier, LtsWidgets::LayoutArea area) const;
/**
* @brief addWidget <exact copy of addWidget in LtsBaseLayoutWidget [is redirected to the coherent
* LtsBaseLayoutWidget]> keep identifier empty to prevent checking for existing tabs
* @return (see addWidget in LtsBaseLayoutWidget)
*/
bool addWidget(LtsWidgets::LtsDialog* widget, const QString& menuGroup, const QString& identifier,
LtsWidgets::LayoutArea area = LtsWidgets::LayoutArea::eUnknown, bool setClosable = true);
private slots:
void slotShowOperatorSettings();
void slotSwap();
void slotStapleTopicLockHandler(LtsWidgets::LtsDialog *widget);
void slotStopWaitDialog();
void slotStartPluginInit();
void slotMonitorSelected();
void delayScriptEditorStart();
LtsWidgets::LtsDialog* getWidget(const QString& menuGroup, const QString& identifier, LtsWidgets::LayoutArea area);
bool focusTab(const QString& menuGroup, const QString& identifier, LtsWidgets::LayoutArea area);
signals:
void signalInitializationAborted();
void _signalDoneInitializingSession(); // internal
void signalDoneInitializingSession(); // is called AFTER all payloads have been executed (on no payloads, called after session was created) FOR LTSLOGIN !
void signalClose(); // tells the session manager to close this session
void signalLogout();
void signalQuit(); // for payloads, so that they can quit an app
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);
/** WARNING: do not save the returned value, as baseLayouts can die (which kills LtsTabWidget also), so reuse this
* method instead of saving the pointer to the LtsTabWidget
* @brief locateWidget locates the given widget 'widget' and returning the TabWidget on which it is on - widgets can
* be available in one of many LayoutAreas (TabWidgets) of many LtsBaseLayoutWidgets
* @param widgetToLocate the widget to look for in the given layoutArea which is located in one of many
* LtsBaseLayoutWidget
* @param area the area the widget is located
* @return LtsTabWidget on which the widget is located
*/
LtsWidgets::LtsTabWidget* locateWidget(QWidget* widgetToLocate, LtsWidgets::LayoutArea area);
private:
friend class DeveloperTools::DevDialog;
friend class DeveloperTools::AppWidget;
friend class LtsSessionManager;
/**
* @brief enable/disable baseLayout menu
* @param on if true enable otherwise disable
*/
void enableBaseLayoutMenu(bool on = true);
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);
// TODO: AFTER FAT !! void stapleWidget(LtsWidgets::LtsDialog *dialog); // FIXME: HACK: because an LtsDialog can directly add widgets to the base layout and misses the staples...
void aboutToCloseTab(LtsWidgets::LayoutArea area);
/**
* @brief enable/disable LayoutArea
* @param area the area to enable/disable
* @param on if true enable otherwise disable
*/
void enableBaseLayoutArea(LtsWidgets::LayoutArea area, bool on = true);
QPointer<LtsSessionManager> m_sessionManager;
QMap<int /*priority*/, std::shared_ptr<GuiPluginBase::Interface> > m_payloadPriorityMap; // QMap automatically sorts by key on iteration and overwrites multiple occurences with the latest)
QList<std::shared_ptr<GuiPluginBase::Interface> > m_payloadList; // for payloads that don't care when they are executed (prio '9999' plugins)
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; // set by doneInitializingSession / signalDoneInitializingSession
bool m_payloadsDone { false }; // for debug
bool m_menuVisible;
//bool m_ignoreSignalInLoop = false;
bool m_firstActionsFetch;
LtsWidgets::ExerciseData *m_exerciseData;
QVector<LtsWidgets::PluginData> m_missingRightActions;
std::shared_ptr<Core::Interface::Ftc> m_coreFtc;
GuiPluginBase::Interface *m_currentInitIfc; // not owning
bool m_slotPluginInitDoneMutex;
bool m_pluginInitDone; // set by slotPluginInitDone
QJsonObject m_savegame;
bool m_hidden; // if true, does not create BLW
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; // if true, creates BLW but hides it and does not use MMM
QStringList m_failedFetches;
QVector<LtsWidgets::LtsBackgroundWidget *> m_bgWidgets;
QString m_workspaceId;
bool m_needsToBeSuccessfullyPlaced { true /* ALWAYS! */ /*false*/ }; // if set to true, 'signalDoneInitializingSession' will only be called after the blw was successfully placed by MMM (even works if MMM inavtive (off))
QString m_name;
QTimer *m_blub { nullptr };
QTimer *m_scriptEditorTimer { nullptr };
int m_blub2;
QPointer<LtsSession> m_dependency; // when MMM iprovides the screen selection for this app, it isn't allowed to replace apps that are dependencies of this app (e.g. logout bug)
bool m_presetBaseLayoutAsSecondaryWidget { false };
int m_id;
/**
* @brief Return the workstation ip for this workstation (== full ipv4 adress) - workstation id comes later from Asm
*/
static int workstationIp(); // really in LtsSession?
/**
* @brief Return the workstation name
*/
static QString workstationName(); // really in LtsSession?
/**
* @brief missingRightActions Do not use.
* @return
*/
/*const*/ QVector<LtsWidgets::PluginData>& missingRightActions() /*const*/
{
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(); // Do not use.
void setDependency(LtsSession* session);
bool hasDependency(LtsSession* session)
{
return (m_dependency.data() == session);
}
LtsSession* dependency() const
{
return m_dependency;
}
// bogus.
void setNeedsToBeSuccessfullyPlaced(bool needed = true)
{
m_needsToBeSuccessfullyPlaced = needed;
} // works even after session creation as 'slotStartPluginInit', which finalizes the session (creates blw, etc.) is
// called async!
int id() const
{
return m_id;
}
public slots:
void slotExecuteNextPayload(); // NEVER call this directly, queue a signal to this slot !
void slotPluginInitDone(); // NEVER call this directly, queue a signal to this slot !
void slotShowOnlineHelp(const QString& fileName);
// void takeOverBdv();
private slots:
void slotShowOperatorSettings();
void slotSwap();
void slotStapleTopicLockHandler(LtsWidgets::LtsDialog* widget);
void slotStopWaitDialog();
void slotStartPluginInit();
void slotMonitorSelected();
void delayScriptEditorStart();
signals:
void signalInitializationAborted();
void _signalDoneInitializingSession(); // internal
void signalDoneInitializingSession(); // is called AFTER all payloads have been executed (on no payloads, called
// after session was created) FOR LTSLOGIN !
void signalClose(); // tells the session manager to close this session
void signalLogout();
void signalQuit(); // for payloads, so that they can quit an app
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);
// TODO: AFTER FAT !! void stapleWidget(LtsWidgets::LtsDialog *dialog); // FIXME: HACK: because an LtsDialog can
// directly add widgets to the base layout and misses the staples...
void aboutToCloseTab(LtsWidgets::LayoutArea area);
QPointer<LtsSessionManager> m_sessionManager;
QMap<int /*priority*/, std::shared_ptr<GuiPluginBase::Interface>>
m_payloadPriorityMap; // QMap automatically sorts by key on iteration and overwrites multiple occurences with
// the latest)
QList<std::shared_ptr<GuiPluginBase::Interface>>
m_payloadList; // for payloads that don't care when they are executed (prio '9999' plugins)
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; // set by doneInitializingSession / signalDoneInitializingSession
bool m_payloadsDone{false}; // for debug
bool m_menuVisible;
// bool m_ignoreSignalInLoop = false;
bool m_firstActionsFetch;
LtsWidgets::ExerciseData* m_exerciseData;
QVector<LtsWidgets::PluginData> m_missingRightActions;
std::shared_ptr<Core::Interface::Ftc> m_coreFtc;
GuiPluginBase::Interface* m_currentInitIfc; // not owning
bool m_slotPluginInitDoneMutex;
bool m_pluginInitDone; // set by slotPluginInitDone
QJsonObject m_savegame;
bool m_hidden; // if true, does not create BLW
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; // if true, creates BLW but hides it and does not use MMM
QStringList m_failedFetches;
QVector<LtsWidgets::LtsBackgroundWidget*> m_bgWidgets;
QString m_workspaceId;
bool m_needsToBeSuccessfullyPlaced{
true /* ALWAYS! */ /*false*/}; // if set to true, 'signalDoneInitializingSession' will only be called after the
// blw was successfully placed by MMM (even works if MMM inavtive (off))
QString m_name;
QTimer* m_blub{nullptr};
QTimer* m_scriptEditorTimer{nullptr};
int m_blub2;
QPointer<LtsSession> m_dependency; // when MMM iprovides the screen selection for this app, it isn't allowed to
// replace apps that are dependencies of this app (e.g. logout bug)
bool m_presetBaseLayoutAsSecondaryWidget{false};
int m_id;
};
} // namespace LtsSession
+43 -58
View File
@@ -1,107 +1,92 @@
#include "lts_session_data.h"
namespace LtsSessionData
{
struct LtsSessionDataHandler
{
LtsSessionData ltsSessionData;
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)
: 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(true); // IMPORTANT: if you want to set this to true for testing, you have to set TABLET_MODE cmake flag to true, otherwise this will crash
setAsTablet(false);
// setAsTablet(true); // IMPORTANT: if you want to set this to true for testing, you have to set TABLET_MODE cmake
// flag to true, otherwise this will crash
setAsTablet(false);
clear();
clear();
}
LtsSessionData *LtsSessionData::getInstance()
LtsSessionData* LtsSessionData::getInstance()
{
return &s_ltsSessionData->ltsSessionData;
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();
m_operatorId = -1;
m_operatorRights.clear();
m_operatorName.clear();
m_showTerminalWindow = false;
m_profilePicture = QPixmap();
m_visibleParties.clear();
}
void LtsSessionData::removePresets()
{
//m_domainIdPreset = -1; keep domain ID !
m_partitionIdPreset = -1;
m_partitionTypePreset = IDL::PartitionType::Any; // FIXME: make invalid !?
// m_domainIdPreset = -1; keep domain ID !
m_partitionIdPreset = -1;
m_partitionTypePreset = IDL::PartitionType::Any; // FIXME: make invalid !?
m_operatorNamePreset.clear();
m_passwordPreset.clear();
m_operatorNamePreset.clear();
m_passwordPreset.clear();
}
void LtsSessionData::clear()
{
removePresets();
loggedOut();
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);
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;
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 {};
for (auto visibleParties : m_visibleParties)
{
if (visibleParties.exerciseId == exerciseId)
return visibleParties.visibleParties;
}
return {};
}
void LtsSessionData::setAsTablet(bool isTablet)
{
m_isTablet = isTablet;
//m_debugFlags.insert(QStringLiteral("isTablet"), isTablet);
m_isTablet = isTablet;
// m_debugFlags.insert(QStringLiteral("isTablet"), isTablet);
}
} // namespace LtsSessionData
+232 -89
View File
@@ -1,134 +1,277 @@
#pragma once
#include <LtsSession/ltssessiondata_export.h>
#include <Lts/Common/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 <LtsSession/ltssessiondata_export.h>
#include <QMap>
#include <QObject>
#include <QPixmap>
#include <QSet>
#include <QUrl>
#include <QVariant>
#include <QtCore/qglobal.h>
namespace LtsSessionData
{
struct PartiesByExercise
{
int exerciseId = 0;
QVector<int> visibleParties;
int exerciseId = 0;
QVector<int> visibleParties;
};
class LTSSESSIONDATA_EXPORT LtsSessionData
{
public:
static LtsSessionData *getInstance();
public:
static LtsSessionData* getInstance();
// Presets:
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; }
// Presets:
const QString& getOperatorNamePreset() const
{
return m_operatorNamePreset;
}
int getDomainIdPreset() const { return m_domainIdPreset; }
void setDomainIdPreset(int domainIdPreset) { m_domainIdPreset = domainIdPreset; }
const QString& getPasswordPreset() const
{
return m_passwordPreset;
}
QStringList getQosFile() const {return m_qosFile; }
void setQosFile(const QStringList &qosFile) { m_qosFile = qosFile; }
void setOperatorPreset(const QString& operatorName, const QString& password)
{
m_operatorNamePreset = operatorName;
m_passwordPreset = password;
}
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; }
int getDomainIdPreset() const
{
return m_domainIdPreset;
}
/**
* @brief removePresets IMPORTANT: call removePresets after using a Preset, otherwise other apps / sessions will pick these old Presets up..
*/
void removePresets();
void setDomainIdPreset(int domainIdPreset)
{
m_domainIdPreset = domainIdPreset;
}
QStringList getQosFile() const
{
return m_qosFile;
}
// Other:
int getScriptId() const { return m_scriptId; }
void setScriptId(int scriptId) { m_scriptId = scriptId; }
void setQosFile(const QStringList& qosFile)
{
m_qosFile = qosFile;
}
int getOperatorId() const { return m_operatorId; }
void setOperatorId(int operatorId) { m_operatorId = operatorId; }
int getPartitionIdPreset() const
{
return m_partitionIdPreset;
}
const QString &getOperatorName() const { return m_operatorName; }
void setOperatorName(const QString &operatorName) { m_operatorName = operatorName; }
IDL::PartitionType getPartitionTypePreset() const
{
return m_partitionTypePreset;
}
const QSet<int> &getOperatorRights() const { return m_operatorRights; }
void setOperatorRights(const QSet<int> &operatorRights) { m_operatorRights = operatorRights; } // Todo: Emit newOperatorRights() if changed?
bool hasOperatorRight(int operatorRight) const;
void setPartitionPreset(const int partitionId, IDL::PartitionType partitionType)
{
m_partitionIdPreset = partitionId;
m_partitionTypePreset = partitionType;
}
const QPixmap &getProfilePicture() const { return m_profilePicture; }
void setProfilePicture(const QPixmap &profilePicture) { m_profilePicture = profilePicture; }
/**
* @brief removePresets IMPORTANT: call removePresets after using a Preset, otherwise other apps / sessions will
* pick these old Presets up..
*/
void removePresets();
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; }
// Other:
int getScriptId() const
{
return m_scriptId;
}
QUrl getTcpConnectionUrl() const { return m_tcpConnectionUrl; }
void setTcpConnectionUrl(const QUrl &tcpConnectionUrl) { m_tcpConnectionUrl = tcpConnectionUrl; }
void setScriptId(int scriptId)
{
m_scriptId = scriptId;
}
bool getShowTerminalWindow() const { return m_showTerminalWindow; }
void setShowTerminalWindow(bool showTerminalWindow) { m_showTerminalWindow = showTerminalWindow; }
int getOperatorId() const
{
return m_operatorId;
}
LtsAppDescriptor::App getRequestedAppId() const { return m_requestedAppId; }
void setRequestedAppId(LtsAppDescriptor::App requestedAppId) { m_requestedAppId = requestedAppId; }
void setOperatorId(int operatorId)
{
m_operatorId = operatorId;
}
int getWorkstationId() const { return m_workstationId; }
void setWorkstationId(int workstationId) { m_workstationId = workstationId; }
const QString& getOperatorName() const
{
return m_operatorName;
}
bool isTablet() const { return m_isTablet; }
void setAsTablet(bool isTablet = true);
void setOperatorName(const QString& operatorName)
{
m_operatorName = operatorName;
}
bool getPlaceScriptScreens() const { return m_placeScriptScreens; }
void setPlaceScriptScreens(bool placeScriptScreens) { m_placeScriptScreens = placeScriptScreens; }
const QSet<int>& getOperatorRights() const
{
return m_operatorRights;
}
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 setOperatorRights(const QSet<int>& operatorRights)
{
m_operatorRights = operatorRights;
} // Todo: Emit newOperatorRights() if changed?
void clear();
void loggedOut();
bool hasOperatorRight(int operatorRight) const;
private:
LtsSessionData();
~LtsSessionData() = default;
friend struct LtsSessionDataHandler;
const QPixmap& getProfilePicture() const
{
return m_profilePicture;
}
// Presets to skip some Payloads
QString m_operatorNamePreset;
QString m_passwordPreset;
QStringList m_qosFile;
QUrl m_tcpConnectionUrl;
int m_domainIdPreset;
int m_partitionIdPreset;
IDL::PartitionType m_partitionTypePreset;
void setProfilePicture(const QPixmap& profilePicture)
{
m_profilePicture = profilePicture;
}
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;
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;
// Presets to skip some Payloads
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);
auto instance = LtsSessionData::getInstance();
return instance->hasOperatorRight(operatorRight);
}
} // namespace LtsSessionData
+247 -259
View File
@@ -9,13 +9,14 @@
*/
#include "lts_session_data_dds.h"
#include <DDS/DDSConnector/dds_connector.h>
#include <DDS/DTC/generic_dtc_impl.h>
#include <DDS/QosProfile/DDS_DefaultQos.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QDebug>
#include <QSet>
#include <QVector>
#include <DDS/QosProfile/DDS_DefaultQos.h>
#include <QDebug>
namespace LtsSession
{
@@ -30,370 +31,357 @@ 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)
struct DdsConnection : public DdsConnectionParams
{
const DdsConnection &conn = ddsConnections.at(i);
if (conn.partitionType != IDL::PartitionType::Global)
continue;
auto ret = conn.ddsConnector.lock();
if (ret != nullptr)
return ret;
// ddsConnector is a nullptr -> useless -> remove
ddsConnections.removeAt(i);
}
Q_ASSERT(false);
return std::shared_ptr<DDSConnector::DdsConnector>();
}
std::weak_ptr<DDSConnector::DdsConnector> ddsConnector = std::weak_ptr<DDSConnector::DdsConnector>();
std::shared_ptr<DDSConnector::DdsConnector> findConnection(const DdsConnectionParams &connParams)
{
for (int i = ddsConnections.size() - 1; i >= 0; --i)
DdsConnection() = default;
explicit DdsConnection(const DdsConnectionParams& p) : DdsConnectionParams(p) {}
};
QVector<DdsConnection> ddsConnections;
public:
std::shared_ptr<DDSConnector::DdsConnector> findGlobalConnection()
{
const DdsConnection &conn = ddsConnections.at(i);
if (conn != connParams)
continue;
auto ret = conn.ddsConnector.lock();
if (ret != nullptr)
return ret;
// ddsConnector is a nullptr -> useless -> remove
ddsConnections.removeAt(i);
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;
// ddsConnector is a nullptr -> useless -> remove
ddsConnections.removeAt(i);
}
Q_ASSERT(false);
return std::shared_ptr<DDSConnector::DdsConnector>();
}
return std::shared_ptr<DDSConnector::DdsConnector>();
}
dds::domain::DomainParticipant findMatchingDomainParticipant(const DdsConnectionParams &connParams)
{
for (int i = ddsConnections.size() - 1; i >= 0; --i)
std::shared_ptr<DDSConnector::DdsConnector> findConnection(const DdsConnectionParams& connParams)
{
const DdsConnection &conn = ddsConnections.at(i);
if (!connParams.hasSameDomainParams(conn))
continue;
auto ret = conn.ddsConnector.lock();
if (ret != nullptr)
return ret->getDomainParticipant();
// ddsConnector is a nullptr -> useless -> remove
ddsConnections.removeAt(i);
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;
// ddsConnector is a nullptr -> useless -> remove
ddsConnections.removeAt(i);
}
return std::shared_ptr<DDSConnector::DdsConnector>();
}
return nullptr;
}
void insertConnection(const DdsConnectionParams &connParams,
const std::shared_ptr<DDSConnector::DdsConnector> &ddsConnector)
{
DdsConnection val(connParams);
val.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();
// ddsConnector is a nullptr -> useless -> remove
ddsConnections.removeAt(i);
}
return nullptr;
}
ddsConnections += val;
}
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
public:
struct DataPluginValue
{
return identifier == o.identifier && weakIfc.lock().get() == o.weakIfc.lock().get();
}
};
QString identifier;
std::weak_ptr<DataPluginBase::Interface> weakIfc;
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);
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)
uint qHash(const DataPluginContainer::DataPluginValue& val)
{
qint64 ptr = reinterpret_cast<qint64>(val.weakIfc.lock().get());
return ::qHash(val.identifier) ^ ::qHash(ptr);
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>>
DataPluginContainer::findDataPlugins(const DdsConnectionParams& connParams)
{
QMap<QString, std::shared_ptr<DataPluginBase::Interface>> ret;
DdsConnectionParams key(connParams);
key.exerciseId = 0;
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 it = m_dataPlugins.find(key);
if (it != m_dataPlugins.end())
{
auto spPlugin = itCont->weakIfc.lock();
if (spPlugin)
{
ret[itCont->identifier] = spPlugin;
++itCont;
}
else
{
itCont = cont.erase(itCont);
}
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;
return ret;
}
void DataPluginContainer::insertDataPlugins(const DdsConnectionParams &connParams,
const QMap<QString, std::shared_ptr<DataPluginBase::Interface>> &dataPlugins)
void DataPluginContainer::insertDataPlugins(
const DdsConnectionParams& connParams, const QMap<QString, std::shared_ptr<DataPluginBase::Interface>>& dataPlugins)
{
DdsConnectionParams key(connParams);
key.exerciseId = 0;
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;
}
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);
m_dataPlugins[key].unite(cont);
}
Q_GLOBAL_STATIC(DataPluginContainer, s_dataPlugins)
//
// LtsSessionDataDds
//
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(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;
m_dtcPartitionTime = nullptr;
m_ddsConnector = nullptr;
delete m_fetcher;
}
bool LtsSessionDataDds::init(const DdsConnectionParams &connParams)
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)
{
// maybe we can at least find a useful DomainParticipant?
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, //same as partition Id in live but not in replay
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();
m_ddsConnector = s_ddsConnections->findConnection(connParams);
m_exerciseId = connParams.exerciseId;
m_qosFileList = QStringList(connParams.qos_file);
if (m_ddsConnector == nullptr)
{
// maybe we can at least find a useful DomainParticipant?
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;
DDS::QosProfile::ConnectionType type = DDS::QosProfile::ConnectionType::Tablet;
#else
DDS::QosProfile::ConnectionType type = DDS::QosProfile::ConnectionType::Client;
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();
m_ddsConnector = std::make_shared<DDSConnector::DdsConnector>(
connParams.domainId, connParams.partitionType, connParams.partitionId,
connParams.exerciseId, // same as partition Id in live but not in replay
type);
s_ddsConnections()->insertConnection(connParams, m_ddsConnector);
}
return initInternal();
}
Fetcher *LtsSessionDataDds::fetcher(const QString &yourPluginsName)
bool LtsSessionDataDds::init(const dds::domain::DomainParticipant& dp, const DdsConnectionParams& connParams)
{
if (m_fetcher == nullptr)
m_fetcher = new Fetcher(this, yourPluginsName);
Q_ASSERT(dp.domain_id() == connParams.domainId);
return m_fetcher;
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");
}
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));
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());
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;
return m_ddsConnector ? m_ddsConnector->getDomainId() : -1;
}
int LtsSessionDataDds::exerciseId() const
{
return m_exerciseId;
return m_exerciseId;
}
int LtsSessionDataDds::partitionId() const
{
return m_ddsConnector ? m_ddsConnector->getPartitionId() : -1;
return m_ddsConnector ? m_ddsConnector->getPartitionId() : -1;
}
IDL::PartitionType LtsSessionDataDds::partitionType() const
{
return m_ddsConnector ? m_ddsConnector->getPartitionType() : IDL::PartitionType::Global;
return m_ddsConnector ? m_ddsConnector->getPartitionType() : IDL::PartitionType::Global;
}
QStringList LtsSessionDataDds::qosFile() const
{
return m_ddsConnector ? m_qosFileList : QStringList();
return m_ddsConnector ? m_qosFileList : QStringList();
}
QUrl LtsSessionDataDds::tcpConnectionUrl() const
{
return m_ddsConnector ? m_ddsConnector->getTcpConnectionUrl() : QUrl();
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;
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;
}
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_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.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;
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);
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());
return s_dataPlugins->findDataPlugins(connParams());
}
void LtsSessionDataDds::addAvailablaeDataPluginInterfaces(const QMap<QString, std::shared_ptr<DataPluginBase::Interface>> &dataPlugins)
void LtsSessionDataDds::addAvailablaeDataPluginInterfaces(
const QMap<QString, std::shared_ptr<DataPluginBase::Interface>>& dataPlugins)
{
s_dataPlugins->insertDataPlugins(connParams(),
dataPlugins);
s_dataPlugins->insertDataPlugins(connParams(), dataPlugins);
}
} // namespace LtsSession
+285 -252
View File
@@ -12,15 +12,15 @@
#ifdef BUILD_RTI
// Full DDS implementation
#include <QObject>
#include <DDS/Core/core_dtc_types.h>
#include <QMap>
#include <QObject>
#include <QUrl>
#include <memory>
#include <DDS/Core/core_dtc_types.h>
//#include <NGLLogger/INGLLogger.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <Lts/Common/ProjectConfig/project_defines.h>
#include <LtsSession/ltssessiondatadds_export.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#else
// Stub implementation when BUILD_RTI=OFF
#include "lts_session_data_dds_stub.h"
@@ -28,250 +28,282 @@
#ifdef BUILD_RTI
namespace DataPluginBase
{
class Interface;
}
namespace DataPluginBase { class Interface; }
namespace DDSConnector { class DdsConnector; }
namespace GuiPluginBase { 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;
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());
}
DdsConnectionParams() = default;
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();
}
explicit DdsConnectionParams(const Core::ReplayPartition& rp)
: domainId(rp.domainId()), partitionId(rp.id()), exerciseId(rp.exerciseId()),
partitionType(IDL::PartitionType::Replay)
{
setTcpConnectionUrl(rp.tcpConnectionUrl());
}
void setTcpConnectionUrl(const std::string &url)
{
tcpConnectionUrl = QUrl::fromUserInput(QString::fromStdString(url));
}
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 /* FIXME: Name ist irrefuehrend. "LtsSessionData" hat mit "LtsSessionDataDds" nichts zu tun, klingen aber fast identisch. */
class LTSSESSIONDATADDS_EXPORT LtsSessionDataDds /* FIXME: Name ist irrefuehrend. "LtsSessionData" hat mit
"LtsSessionDataDds" nichts zu tun, klingen aber fast identisch. */
: public QObject
{
Q_OBJECT
protected:
// only used from LtsSession, no direct instantiation
explicit LtsSessionDataDds(QObject *parent = nullptr);
public:
~LtsSessionDataDds();
Q_OBJECT
protected:
// only used from LtsSession, no direct instantiation
explicit LtsSessionDataDds(QObject* parent = nullptr);
bool init(const DdsConnectionParams &connParams);
bool init(const dds::domain::DomainParticipant &dp,
const DdsConnectionParams &connParams);
public:
~LtsSessionDataDds();
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);
bool init(const DdsConnectionParams& connParams);
bool init(const dds::domain::DomainParticipant& dp, const DdsConnectionParams& connParams);
QUrl tcpConnectionUrl() const;
DdsConnectionParams connParams() const;
qint64 partitionTime() const { return m_curMSecSinceEpoch; }
// retrieve DTC/FTC inside DataPlugin::createDataInterface()
template<typename T>
bool createTopicClient(std::shared_ptr<T> &member, bool bEnableAll = false, bool bGlobal = false)
{
member = T::create(bGlobal ? m_ddsConnectorGlobal : m_ddsConnector);
if ( bEnableAll && !member->enableAll())
std::shared_ptr<DDSConnector::DdsConnector> ddsConnector()
{
member = nullptr;
ERROR_LOG(m_logger) << "Error initializing dtc/ftc for service " << T::identifier();
return false;
return m_ddsConnector;
}
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())
std::shared_ptr<DDSConnector::DdsConnector> ddsConnectorGlobal()
{
dtc = nullptr;
ftc = nullptr;
ERROR_LOG(m_logger) << "Error initializing dtc/ftc for service " << T::identifier();
return false;
return m_ddsConnectorGlobal;
}
return true;
}
template<typename T, typename S>
bool getDtc(std::shared_ptr<S> &val) const
{
for (const auto &i : m_dataPluginInterfaces)
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
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getDtc();
return val != nullptr;
}
return (partitionType() == IDL::PartitionType::Exercise);
}
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;
}
// TODO: merge with getDtc() --> std::is_same, std::enable_if
template<typename T, typename S>
bool getFtc(std::shared_ptr<S> &val) const
{
for (const auto &i : m_dataPluginInterfaces)
bool isReplayPartition() const
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getFtc();
return val != nullptr;
}
return (partitionType() == IDL::PartitionType::Replay);
}
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;
}
QString toString() const;
Fetcher* fetcher(const QString& yourPluginsName);
// TODO: merge with getDtc() --> std::is_same, std::enable_if
template<typename T, typename S>
bool getForeignDataInterface(std::shared_ptr<S> &val) const
{
//qWarning() << "getForeignDataInterface is deprecated! get the plugin's dtc/ftc directly with getDtc or getFtc!";
QUrl tcpConnectionUrl() const;
DdsConnectionParams connParams() const;
for (const auto &i : m_dataPluginInterfaces)
qint64 partitionTime() const
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getForeignDataInterface();
return val != nullptr;
}
return m_curMSecSinceEpoch;
}
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;
}
// retrieve DTC/FTC inside DataPlugin::createDataInterface()
template <typename T>
bool createTopicClient(std::shared_ptr<T>& member, bool bEnableAll = false, bool bGlobal = false)
{
member = T::create(bGlobal ? m_ddsConnectorGlobal : m_ddsConnector);
if (bEnableAll && !member->enableAll())
{
member = nullptr;
ERROR_LOG(m_logger) << "Error initializing dtc/ftc for service " << T::identifier();
return false;
}
return true;
}
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW */
/* MW DEPRECATED - DO NOT USE IN NEW IMPLEMENTATIONS - CAN BE REMOVED AT ANY TIME WITHOUT WARNING ! MW */
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW */
/* MW */ /* MW */
/* MW */ template<typename S> /* MW */
/* MW */ bool getForeignDataInterface_NEW(std::shared_ptr<S> &val) const /* MW */
/* MW */ { /* MW */
/* MW */ //qWarning() << "getForeignDataInterface is deprecated! get the plugin's dtc/ftc directly with getDtc or getFtc!"; /* MW */
/* MW */ /* MW */
/* MW */ for (const auto &i : m_dataPluginInterfaces) /* MW */
/* MW */ { /* MW */
/* MW */ val = std::dynamic_pointer_cast<S>(i); /* MW */
/* MW */ if (val) /* MW */
/* MW */ return true; /* MW */
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;
}
// TODO: merge with getDtc() --> std::is_same, std::enable_if
template <typename T, typename S> bool getFtc(std::shared_ptr<S>& val) const
{
for (const auto& i : m_dataPluginInterfaces)
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getFtc();
return val != nullptr;
}
}
val.reset();
DEBUG_LOG(m_logger) << "Trying to load ftc " << typeid(T).name() << " - " << typeid(S).name() << " failed!"
<< ", m_dataPluginInterfaces.size() = " << m_dataPluginInterfaces.size() << " - " << this;
return false;
}
// TODO: merge with getDtc() --> std::is_same, std::enable_if
template <typename T, typename S> bool getForeignDataInterface(std::shared_ptr<S>& val) const
{
// qWarning() << "getForeignDataInterface is deprecated! get the plugin's dtc/ftc directly with getDtc or
// getFtc!";
for (const auto& i : m_dataPluginInterfaces)
{
auto ifc = std::dynamic_pointer_cast<T>(i);
if (ifc)
{
val = ifc->getForeignDataInterface();
return val != nullptr;
}
}
val.reset();
DEBUG_LOG(m_logger) << "Trying to load foreign data ifc " << typeid(T).name() << " - " << typeid(S).name()
<< " failed!"
<< ", m_dataPluginInterfaces.size() = " << m_dataPluginInterfaces.size() << " - " << this;
return false;
}
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW
*/
/* MW DEPRECATED - DO NOT USE IN NEW IMPLEMENTATIONS - CAN BE REMOVED AT ANY TIME WITHOUT WARNING ! MW */
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW
*/
/* MW */ /* MW */
/* MW */ template <typename S> /* MW */
/* MW */ bool getForeignDataInterface_NEW(std::shared_ptr<S>& val) const /* MW */
/* MW */ { /* MW */
/* MW */ // qWarning() << "getForeignDataInterface is deprecated! get the plugin's dtc/ftc directly with getDtc
// or getFtc!"; /* MW */
/* MW */ /* MW */
/* MW */ for (const auto& i : m_dataPluginInterfaces) /* MW */
/* MW */ { /* MW */
/* MW */ val = std::dynamic_pointer_cast<S>(i); /* MW */
/* MW */ if (val) /* MW */
/* MW */ return true; /* MW */
/* MW */ } /* MW */
/* MW */ val.reset(); /* MW */
/* MW */ DEBUG_LOG(m_logger) << "Trying to load foreign data ifc " << typeid(S).name() << " failed!" /* MW */
/* MW */ << ", m_guiPluginInterfaces.size() = " << m_guiPluginInterfaces.size() << " - " << this; /* MW */
/* MW */ return false; /* MW */
/* MW */ val.reset(); /* MW */
/* MW */ DEBUG_LOG(m_logger) << "Trying to load foreign data ifc " << typeid(S).name()
<< " failed!" /* MW */
/* MW */
<< ", m_guiPluginInterfaces.size() = " << m_guiPluginInterfaces.size() << " - "
<< this; /* MW */
/* MW */ return false; /* MW */
/* MW */ } /* MW */
/* MW */ /* MW */
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW */
/* MW */ /* MW */
/* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW
*/
template<typename S>
bool getForeignGuiInterface(std::shared_ptr<S> &val) const
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();
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;
return false;
}
template<typename T, typename S>
bool interfaceFromGui(std::shared_ptr<S> &val) const // for generic gui interfaces
template <typename T, typename S> bool interfaceFromGui(std::shared_ptr<S>& val) const // for generic gui interfaces
{
for (const auto &i : m_guiPluginInterfaces)
{
val = std::dynamic_pointer_cast<T>(i);
if (val)
return true;
}
val.reset();
DEBUG_LOG(m_logger) << "Trying to load foreign gui ifc #2 " << typeid(S).name() << " failed!"
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;
return false;
}
signals:
@@ -290,75 +322,76 @@ protected:
qint64 m_emittedTime;
qint64 m_curMSecSinceEpoch;
bool m_active;
void setInactive() { m_active = false; }
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);
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;
Fetcher* m_fetcher;
QStringList m_qosFileList;
NGL::INGLLogger &m_logger;
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 /* only fill if optional */, bool optional)
{
if (!m_sessionDataDds->getForeignGuiInterface(foreignGuiInterface))
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)
{
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;
}
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;
void print()
{
m_errors = true;
QString msg(QStringLiteral("%1 cannot find '%2' in %3 %4"));
if (m_optional)
template <typename ForeignGuiInterface>
void getForeignGuiInterface(std::shared_ptr<ForeignGuiInterface>& foreignGuiInterface,
const QString& whatWillNotWork /* only fill if optional */, bool optional)
{
INFO_LOG(m_logger) << msg.arg(m_caller, m_resultType, m_sessionDataDds->toString(), QStringLiteral("' - optional but %1 will not work").arg(m_whatWillNotWork));
if (!m_sessionDataDds->getForeignGuiInterface(foreignGuiInterface))
{
m_whatWillNotWork = whatWillNotWork;
m_optional = optional;
m_resultType = QString::fromUtf8(typeid(ForeignGuiInterface).name());
m_getterFunctionType = QStringLiteral("gui interface");
print();
}
}
else // critical
bool status() const
{
ERROR_LOG(m_logger) << msg.arg(m_caller, m_resultType, m_sessionDataDds->toString(), QStringLiteral(" which is required"));
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 // critical
{
ERROR_LOG(m_logger) << msg.arg(m_caller, m_resultType, m_sessionDataDds->toString(),
QStringLiteral(" which is required"));
}
}
}
};
} // namespace LtsSession
@@ -6,11 +6,11 @@
#pragma once
#include <QObject>
#include <QMap>
#include <QUrl>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QUrl>
#include <memory>
namespace LtsSession
@@ -19,64 +19,137 @@ namespace LtsSession
// Stub DdsConnectionParams - minimal version without DDS dependencies
struct DdsConnectionParams
{
int domainId = -1;
int partitionId = 0;
int exerciseId = 0;
QUrl tcpConnectionUrl;
QStringList qos_file;
int domainId = -1;
int partitionId = 0;
int exerciseId = 0;
QUrl tcpConnectionUrl;
QStringList qos_file;
DdsConnectionParams() = default;
bool isValid() const { return false; } // Always invalid without DDS
bool hasSameDomainParams(const DdsConnectionParams &) const { return false; }
bool operator==(const DdsConnectionParams &) const { return false; }
bool operator!=(const DdsConnectionParams &) const { return true; }
bool operator<(const DdsConnectionParams &) const { return false; }
DdsConnectionParams() = default;
bool isValid() const
{
return false;
} // Always invalid without DDS
bool hasSameDomainParams(const DdsConnectionParams&) const
{
return false;
}
bool operator==(const DdsConnectionParams&) const
{
return false;
}
bool operator!=(const DdsConnectionParams&) const
{
return true;
}
bool operator<(const DdsConnectionParams&) const
{
return false;
}
};
// Forward declare internal classes
namespace DDSConnector { class DdsConnector; }
namespace DataPluginBase { class Interface; }
namespace GuiPluginBase { class Interface; }
namespace DDSConnector
{
class DdsConnector;
}
namespace DataPluginBase
{
class Interface;
}
namespace GuiPluginBase
{
class Interface;
}
// Stub LtsSessionDataDds class - minimal version without DDS functionality
class LtsSessionDataDds : public QObject
{
Q_OBJECT
public:
explicit LtsSessionDataDds(QObject *parent = nullptr) : QObject(parent) {}
~LtsSessionDataDds() override = default;
Q_OBJECT
public:
explicit LtsSessionDataDds(QObject* parent = nullptr) : QObject(parent) {}
bool init(const DdsConnectionParams &) { return false; }
std::shared_ptr<DDSConnector::DdsConnector> ddsConnector() { return nullptr; }
std::shared_ptr<DDSConnector::DdsConnector> ddsConnectorGlobal() { return nullptr; }
int domainId() const { return -1; }
int exerciseId() const { return -1; }
int partitionId() const { return -1; }
QStringList qosFile() const { return QStringList(); }
QString toString() const { return QStringLiteral("LtsSessionDataDds(stub)"); }
QUrl tcpConnectionUrl() const { return QUrl(); }
DdsConnectionParams connParams() const { return DdsConnectionParams(); }
qint64 partitionTime() const { return 0; }
~LtsSessionDataDds() override = default;
signals:
void partitionTimeChanged(qint64);
void partitionTimeChangedInternal();
bool init(const DdsConnectionParams&)
{
return false;
}
std::shared_ptr<DDSConnector::DdsConnector> ddsConnector()
{
return nullptr;
}
std::shared_ptr<DDSConnector::DdsConnector> ddsConnectorGlobal()
{
return nullptr;
}
int domainId() const
{
return -1;
}
int exerciseId() const
{
return -1;
}
int partitionId() const
{
return -1;
}
QStringList qosFile() const
{
return QStringList();
}
QString toString() const
{
return QStringLiteral("LtsSessionDataDds(stub)");
}
QUrl tcpConnectionUrl() const
{
return QUrl();
}
DdsConnectionParams connParams() const
{
return DdsConnectionParams();
}
qint64 partitionTime() const
{
return 0;
}
signals:
void partitionTimeChanged(qint64);
void partitionTimeChangedInternal();
};
// Stub Fetcher class
class Fetcher
{
public:
Fetcher(LtsSessionDataDds *, const QString &) {}
template <typename T>
void getForeignGuiInterface(std::shared_ptr<T> &, const QString &, bool) {}
bool status() const { return false; }
public:
Fetcher(LtsSessionDataDds*, const QString&) {}
template <typename T> void getForeignGuiInterface(std::shared_ptr<T>&, const QString&, bool) {}
bool status() const
{
return false;
}
};
} // namespace LtsSession
+165 -184
View File
@@ -1,290 +1,271 @@
#include "lts_session_lock_handler.h"
#include <LtsWidgets/lts_message_dialog.h>
#include <LtsSession/lts_session_data.h>
#include <LtsWidgets/lts_message_dialog.h>
#include <QDebug>
#include <sstream>
namespace LtsSession
{
TopicLockHandler::TopicLockHandler()
: QObject()
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.TopicLockHandler"))
: QObject(), m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.TopicLockHandler"))
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
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";
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)
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 << " START";
if (coreFtc == nullptr)
return false;
coreFtc->enableAll();
m_exerciseId = exerciseId;
m_coreFtc = coreFtc;
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
return true;
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();
INFO_LOG(m_logger) << "LOCK " << m_topicInfo.topicName();
TRACE_LOG(m_logger) << LOGFUNCTION << objStateAsString();
if (m_coreFtc == nullptr)
return false;
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); // m_lockEntityId > 0 means that a lock is updated
// svcKey :
req.entityTypeName(m_topicInfo.topicName().toStdString()/* + m_topicInfo.workspaceId().toStdString()*/);
req.entityId(m_topicInfo.entityId());
req.exerciseId(m_exerciseId);
// : svcKey
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()) //has_value not support on windows yet so we need depricated is_set
if (m_locked)
{
const Core::LockEntityError &alreadyLocked = reply.alreadyLocked().get();
INFO_LOG(m_logger) << LOGFUNCTION << ": Topic already locked by ws " << alreadyLocked.workstationName() << " and op " << alreadyLocked.operatorName();
// N. Thoden, 23.09.2020: Since Locking is more often, the dialog is annoying. So skip and pay attention to title
// LtsWidgets::LtsMessageDialog::showMessage(nullptr, fro.translated(), tr("Unable to lock data record"));
const auto lockedBy(QStringLiteral("%2/%1").arg(QString::fromStdString(alreadyLocked.operatorName()), QString::fromStdString(alreadyLocked.workstationName())));
emit signalLockDialog(lockedBy); // -> READ_ONLY / lock the dialog as the topic could not be locked
ERROR_LOG(m_logger) << LOGFUNCTION << ": called lock while still locked! " << m_lockEntityId;
Q_ASSERT(false);
return false;
}
else // lock was successful
const auto* sessionData = LtsSessionData::LtsSessionData::getInstance();
Core::TryLockEntityRequest req;
req.id(m_lockEntityId); // m_lockEntityId > 0 means that a lock is updated
// svcKey :
req.entityTypeName(m_topicInfo.topicName().toStdString() /* + m_topicInfo.workspaceId().toStdString()*/);
req.entityId(m_topicInfo.entityId());
req.exerciseId(m_exerciseId);
// : svcKey
req.operatorId(sessionData->getOperatorId());
req.workstationId(sessionData->getWorkstationId());
try
{
DEBUG_LOG(m_logger) << LOGFUNCTION << ": Topic NOT already locked";
const Core::TryLockEntityReply reply(m_coreFtc->tryLockEntityRequest(req));
Q_ASSERT(reply.id() > 0);
m_locked = true;
m_lockEntityId = reply.id(); // only set id if *new lock* was created
TRACE_LOG(m_logger) << LOGFUNCTION << ": Reply received - state=" << objStateAsString() << " - reply=" << reply;
if (reply.alreadyLocked().is_set()) // has_value not support on windows yet so we need depricated 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();
// N. Thoden, 23.09.2020: Since Locking is more often, the dialog is annoying. So skip and pay attention to
// title LtsWidgets::LtsMessageDialog::showMessage(nullptr, fro.translated(), tr("Unable to lock data
// record"));
const auto lockedBy(QStringLiteral("%2/%1").arg(QString::fromStdString(alreadyLocked.operatorName()),
QString::fromStdString(alreadyLocked.workstationName())));
emit signalLockDialog(lockedBy); // -> READ_ONLY / lock the dialog as the topic could not be locked
}
else // lock was successful
{
DEBUG_LOG(m_logger) << LOGFUNCTION << ": Topic NOT already locked";
Q_ASSERT(reply.id() > 0);
m_locked = true;
m_lockEntityId = reply.id(); // only set id if *new lock* was created
}
}
catch (const std::runtime_error& err)
{
ERROR_LOG(m_logger) << LOGFUNCTION << ": Failed to lock topic! " << err.what();
Q_ASSERT(false);
return false;
}
}
catch (const std::runtime_error &err)
{
ERROR_LOG(m_logger) << LOGFUNCTION << ": Failed to lock topic! " << err.what();
Q_ASSERT(false);
return false;
}
return true;
return true;
}
bool TopicLockHandler::unlock()
{
INFO_LOG(m_logger) << "UNLOCK " << m_topicInfo.topicName() << " - " << m_lockEntityId;
TRACE_LOG(m_logger) << LOGFUNCTION << objStateAsString();
INFO_LOG(m_logger) << "UNLOCK " << m_topicInfo.topicName() << " - " << m_lockEntityId;
TRACE_LOG(m_logger) << LOGFUNCTION << objStateAsString();
if (m_coreFtc == nullptr)
return false;
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;
}
if (!m_locked)
{
ERROR_LOG(m_logger) << LOGFUNCTION << ": Tried to unlock while unlocked.. " << objStateAsString();
Q_ASSERT(false);
return false;
}
Q_ASSERT(m_lockEntityId > 0); // if unlocking, we need an existing lock id!
Q_ASSERT(m_lockEntityId > 0); // if unlocking, we need an existing lock id!
const Core::TryUnlockEntityRequest req(m_lockEntityId);
const Core::TryUnlockEntityRequest req(m_lockEntityId);
// always set locked to false and remove id - so that a new call to lock is possible
m_locked = false;
m_lockEntityId = 0;
// always set locked to false and remove id - so that a new call to lock is possible
m_locked = false;
m_lockEntityId = 0;
try
{
const auto reply(m_coreFtc->tryUnlockEntityRequest(req));
try
{
const auto reply(m_coreFtc->tryUnlockEntityRequest(req));
TRACE_LOG(m_logger) << LOGFUNCTION << ": Reply received - state=" << objStateAsString()
<< " - reply=" << reply;
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;
}
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;
}
// success
emit signalUnlockDialog(); // -> READ_WRITE
// success
emit signalUnlockDialog(); // -> READ_WRITE
// TODO: emit signalUnlockDialog(); // unlock the dialog (initial state /*is*/ SHOULD be locked)
// TODO: emit signalUnlockDialog(); // unlock the dialog (initial state /*is*/ SHOULD be locked)
return true;
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();
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();
TRACE_LOG(m_logger) << LOGFUNCTION << " slotUnlock" << objStateAsString();
return unlock();
}
void TopicLockHandler::slotTryLock(const LtsWidgets::TopicInfo &topicInfo)
void TopicLockHandler::slotTryLock(const LtsWidgets::TopicInfo& topicInfo)
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START " << objStateAsString();
TRACE_LOG(m_logger) << LOGFUNCTION << " START " << objStateAsString();
m_topicInfo = topicInfo;
m_topicInfo = topicInfo;
if (m_topicInfo.topicName().isEmpty() || !topicInfo.isValid())
{
DEBUG_LOG(m_logger) << LOGFUNCTION << " no lockable topic, that's okay";
return;
}
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();
lock();
TRACE_LOG(m_logger) << LOGFUNCTION << " END " << objStateAsString();
}
void TopicLockHandler::slotFinalize()
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START " << objStateAsString();
TRACE_LOG(m_logger) << LOGFUNCTION << " START " << objStateAsString();
if (m_locked)
{
slotUnlock(); // only unlock if locked
}
if (m_locked)
{
slotUnlock(); // only unlock if locked
}
deleteLater();
deleteLater();
TRACE_LOG(m_logger) << LOGFUNCTION << " END " << objStateAsString();
TRACE_LOG(m_logger) << LOGFUNCTION << " END " << objStateAsString();
}
//******************************************************************************
// class TopicLockHanderData, used at TacticalOrganisation, OrgChart
//******************************************************************************
TopicLockHanderData::TopicLockHanderData()
: QObject()
{
}
TopicLockHanderData::TopicLockHanderData() : QObject() {}
void TopicLockHanderData::init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc, int exerciseId)
void TopicLockHanderData::init(const std::shared_ptr<Core::Interface::Ftc>& coreFtc, int exerciseId)
{
m_topicLockHandler = new TopicLockHandler();
m_topicLockHandler->init(coreFtc, 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);
connect(m_topicLockHandler.data(), &TopicLockHandler::signalLockDialog, this, &TopicLockHanderData::slotLock,
Qt::UniqueConnection);
connect(m_topicLockHandler.data(), &TopicLockHandler::signalUnlockDialog, this, &TopicLockHanderData::slotUnlock,
Qt::UniqueConnection);
}
TopicLockHanderData::~TopicLockHanderData()
{
// ensure cleanup: (must be delayed to process unlock) reply
if (m_topicLockHandler)
m_topicLockHandler->slotFinalize();
// ensure cleanup: (must be delayed to process unlock) reply
if (m_topicLockHandler)
m_topicLockHandler->slotFinalize();
}
void TopicLockHanderData::unlock()
{
qDebug() << "Debugname=" << m_debugName << ": "
<< " slotUnlock";
if (m_topicLockHandler)
m_topicLockHandler->slotUnlock();
qDebug() << "Debugname=" << m_debugName << ": "
<< " slotUnlock";
if (m_topicLockHandler)
m_topicLockHandler->slotUnlock();
}
bool TopicLockHanderData::isLocked() const
{
if (!m_topicLockHandler)
{
if (!m_topicLockHandler)
{
qDebug() << "Debugname=" << m_debugName << ": "
<< " isLocked -> no handler";
return false;
}
qDebug() << "Debugname=" << m_debugName << ": "
<< " isLocked -> no handler";
return false;
}
qDebug() << "Debugname=" << m_debugName << ": "
<< " isLocked = " << m_topicLockHandler->isLocked();
return m_topicLockHandler->isLocked();
<< " isLocked = " << m_topicLockHandler->isLocked();
return m_topicLockHandler->isLocked();
}
LtsWidgets::TopicInfo TopicLockHanderData::getTopicInfo() const
{
if (m_topicLockHandler)
return m_topicLockHandler->getTopicInfo();
return {};
if (m_topicLockHandler)
return m_topicLockHandler->getTopicInfo();
return {};
}
void TopicLockHanderData::slotTryLock(const LtsWidgets::TopicInfo &topicInfo)
void TopicLockHanderData::slotTryLock(const LtsWidgets::TopicInfo& topicInfo)
{
qDebug() << "Debugname=" << m_debugName << ": "
<< "slotTryLock " << m_topicLockHandler;
if (!m_topicLockHandler)
return;
m_topicLockHandler->slotTryLock(topicInfo);
qDebug() << "Debugname=" << m_debugName << ": "
<< "slotTryLock " << m_topicLockHandler;
if (!m_topicLockHandler)
return;
m_topicLockHandler->slotTryLock(topicInfo);
}
void TopicLockHanderData::slotLock(const QString &lockedBy)
void TopicLockHanderData::slotLock(const QString& lockedBy)
{
// TopicLockHanderData *sender = qobject_cast<QTcpServer *>(sender());
// TopicLockHanderData *sender = qobject_cast<QTcpServer *>(sender());
qDebug() << "Debugname=" << m_debugName << ": "
<< "slotLock";
m_lockedBy = lockedBy;
emit lockDataChanged();
qDebug() << "Debugname=" << m_debugName << ": "
<< "slotLock";
m_lockedBy = lockedBy;
emit lockDataChanged();
}
void TopicLockHanderData::slotUnlock()
{
qDebug() << "Debugname=" << m_debugName << ": "
<< "slotUnlock";
m_lockedBy.clear();
emit lockDataChanged();
qDebug() << "Debugname=" << m_debugName << ": "
<< "slotUnlock";
m_lockedBy.clear();
emit lockDataChanged();
}
} // namespace LtsSession
+61 -53
View File
@@ -2,16 +2,13 @@
#ifdef BUILD_RTI
#include <DDS/Core/core_ftc.h>
#include <LtsSession/ltssession_export.h>
#include <LtsWidgets/lts_dialog.h>
#include <DDS/Core/core_ftc.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QPointer>
#include <memory>
#include <NGLLogger/NGLLoggerBootstrap.h>
/*
Anmerkungen:
slotTryLock
@@ -38,73 +35,84 @@ namespace LtsSession
{
class LTSSESSION_EXPORT TopicLockHandler : public QObject
{
Q_OBJECT
public:
TopicLockHandler();
~TopicLockHandler();
Q_OBJECT
public:
TopicLockHandler();
~TopicLockHandler();
bool init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc, int exerciseId);
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; }
bool isLocked() const
{
return m_locked;
}
public slots:
void slotTryLock(const LtsWidgets::TopicInfo &topicInfo);
bool slotUnlock();
void slotFinalize(); // unlock, finally delete
LtsWidgets::TopicInfo getTopicInfo() const
{
return m_topicInfo;
}
signals:
void signalLockDialog(const QString &lockedBy);
void signalUnlockDialog();
public slots:
void slotTryLock(const LtsWidgets::TopicInfo& topicInfo);
bool slotUnlock();
void slotFinalize(); // unlock, finally delete
private:
bool lock();
bool unlock();
std::string objStateAsString() const;
signals:
void signalLockDialog(const QString& lockedBy);
void signalUnlockDialog();
std::shared_ptr<Core::Interface::Ftc> m_coreFtc;
private:
bool lock();
bool unlock();
std::string objStateAsString() const;
LtsWidgets::TopicInfo m_topicInfo;
int m_lockEntityId{0}; // reply.id(); / set by reply of ddsCall
std::shared_ptr<Core::Interface::Ftc> m_coreFtc;
int m_exerciseId{0};
bool m_locked{false};
bool m_askedForLock{false}; // reply does not tell..
bool m_deleteAfterAnswer{false};
LtsWidgets::TopicInfo m_topicInfo;
int m_lockEntityId{0}; // reply.id(); / set by reply of ddsCall
NGL::INGLLogger &m_logger;
int m_exerciseId{0};
bool m_locked{false};
bool m_askedForLock{false}; // reply does not tell..
bool m_deleteAfterAnswer{false};
NGL::INGLLogger& m_logger;
};
class LTSSESSION_EXPORT TopicLockHanderData : public QObject
{
Q_OBJECT
Q_OBJECT
public:
TopicLockHanderData();
~TopicLockHanderData();
void init(const std::shared_ptr<Core::Interface::Ftc> &coreFtc, int exerciseId);
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; }
void unlock();
void slotTryLock(const LtsWidgets::TopicInfo& topicInfo);
bool isLocked() const;
LtsWidgets::TopicInfo getTopicInfo() const;
Q_SIGNALS:
void lockDataChanged();
const QString& getLockedBy() const
{
return m_lockedBy;
}
private Q_SLOTS:
void slotLock(const QString &lockedBy);
void slotUnlock();
public:
QString m_debugName;
private:
QPointer<TopicLockHandler> m_topicLockHandler;
QString 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;
};
} // namespace LtsSession
#else // BUILD_RTI
@@ -8,12 +8,10 @@
#include <LtsSession/ltssession_export.h>
#include <LtsWidgets/lts_dialog.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QObject>
#include <QPointer>
#include <memory>
#include <QObject>
#include <NGLLogger/NGLLoggerBootstrap.h>
namespace LtsSession
{
@@ -21,61 +19,100 @@ namespace LtsSession
// Stub TopicLockHandler class - minimal version without DDS functionality
class LTSSESSION_EXPORT TopicLockHandler : public QObject
{
Q_OBJECT
public:
explicit TopicLockHandler(QObject *parent = nullptr) : QObject(parent)
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.TopicLockHandler"))
{}
~TopicLockHandler() override = default;
Q_OBJECT
public:
explicit TopicLockHandler(QObject* parent = nullptr)
: QObject(parent),
m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.TopicLockHandler"))
{
}
bool init(const void * /*coreFtc*/, int /*exerciseId*/) { return false; }
~TopicLockHandler() override = default;
bool isLocked() const { return false; }
LtsWidgets::TopicInfo getTopicInfo() const { return LtsWidgets::TopicInfo(); }
bool init(const void* /*coreFtc*/, int /*exerciseId*/)
{
return false;
}
public slots:
void slotTryLock(const LtsWidgets::TopicInfo & /*topicInfo*/) {}
bool slotUnlock() { return false; }
void slotFinalize() { deleteLater(); }
bool isLocked() const
{
return false;
}
signals:
void signalLockDialog(const QString & /*lockedBy*/) {}
void signalUnlockDialog() {}
LtsWidgets::TopicInfo getTopicInfo() const
{
return LtsWidgets::TopicInfo();
}
private:
NGL::INGLLogger &m_logger;
public slots:
void slotTryLock(const LtsWidgets::TopicInfo& /*topicInfo*/) {}
bool slotUnlock()
{
return false;
}
void slotFinalize()
{
deleteLater();
}
signals:
void signalLockDialog(const QString& /*lockedBy*/) {}
void signalUnlockDialog() {}
private:
NGL::INGLLogger& m_logger;
};
class LTSSESSION_EXPORT TopicLockHanderData : public QObject
{
Q_OBJECT
Q_OBJECT
public:
explicit TopicLockHanderData(QObject *parent = nullptr) : QObject(parent) {}
~TopicLockHanderData() override = default;
void init(const void * /*coreFtc*/, int /*exerciseId*/) {}
public:
explicit TopicLockHanderData(QObject* parent = nullptr) : QObject(parent) {}
void unlock() {}
void slotTryLock(const LtsWidgets::TopicInfo & /*topicInfo*/) {}
bool isLocked() const { return false; }
LtsWidgets::TopicInfo getTopicInfo() const { return LtsWidgets::TopicInfo(); }
const QString &getLockedBy() const { return m_lockedBy; }
~TopicLockHanderData() override = default;
Q_SIGNALS:
void lockDataChanged();
void init(const void* /*coreFtc*/, int /*exerciseId*/) {}
private Q_SLOTS:
void slotLock(const QString & /*lockedBy*/) {}
void slotUnlock() {}
void unlock() {}
public:
QString m_debugName;
private:
QPointer<TopicLockHandler> m_topicLockHandler;
QString m_lockedBy;
void slotTryLock(const LtsWidgets::TopicInfo& /*topicInfo*/) {}
bool isLocked() const
{
return false;
}
LtsWidgets::TopicInfo getTopicInfo() const
{
return LtsWidgets::TopicInfo();
}
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;
};
} // namespace LtsSession
+147 -163
View File
@@ -8,15 +8,15 @@
* Created by Mike Wille, SLSE, 2016-05-15
*/
#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 <LtsWidgets/lts_wait_dialog.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <PluginInterfaces/data_plugin_interface.h>
#include <PluginInterfaces/gui_plugin_interface.h>
#ifdef BUILD_RTI
@@ -25,228 +25,212 @@
#include <QDebug>
namespace LtsSession
{
LtsSessionManager::LtsSessionManager()
: QObject()
, m_appId(LtsAppDescriptor::App::Login)
, m_headless(false)
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.Manager"))
{}
: QObject(), m_appId(LtsAppDescriptor::App::Login), m_headless(false),
m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsSession.Manager"))
{
}
LtsSessionManager::~LtsSessionManager()
{
// qCritical() << "~LtsSessionManager";
// qCritical() << "~LtsSessionManager";
for (auto i = m_sessionMap.begin(); i != m_sessionMap.end(); ++i)
{
LtsSession *session = i.value();
session->setInactive();
session->deleteLater();
}
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 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) // TODO: what to return ?
{
// TODO: check if maps empty?
m_dataPluginList = dataPluginList;
m_guiPluginList = guiPluginList;
m_appId = appId;
m_headless = headless;
// TODO: check if maps empty?
m_dataPluginList = dataPluginList;
m_guiPluginList = guiPluginList;
m_appId = appId;
m_headless = headless;
// shortcut: on first login etc. we go through ExerciseChooser to select an exercise
// but when we're already in the exercise and starting an app from within,
// we don't want to have the exercise chooser a second time -> directly go through app
// and show the base layout
// shortcut: on first login etc. we go through ExerciseChooser to select an exercise
// but when we're already in the exercise and starting an app from within,
// we don't want to have the exercise chooser a second time -> directly go through app
// and show the base layout
// ????? Der Kommentar stimmt leider nicht. Loest leider nicht das Problem.
// ????? Der Kommentar stimmt leider nicht. Loest leider nicht das Problem.
bool bHasBaseLayout = connParams.exerciseId > 0;
bool bHasBaseLayout = connParams.exerciseId > 0;
LtsSession *session = createSession(connParams, bHasBaseLayout, true, hidden); // start Admin Session (for login, etc.)
session->setWorkspaceId(workspaceId);
return session;
LtsSession* session =
createSession(connParams, bHasBaseLayout, true, hidden); // start Admin Session (for login, etc.)
session->setWorkspaceId(workspaceId);
return session;
}
QVector<LtsSession *> LtsSessionManager::sessions()
QVector<LtsSession*> LtsSessionManager::sessions()
{
return m_sessionMap.values().toVector();
return m_sessionMap.values().toVector();
// QVector<LtsSession *> result;
// for (auto i = m_sessionMap.begin(); i != m_sessionMap.end(); ++i)
// result.append(i.value());
// QVector<LtsSession *> result;
// for (auto i = m_sessionMap.begin(); i != m_sessionMap.end(); ++i)
// result.append(i.value());
// return result;
// return result;
}
void LtsSessionManager::softQuit()
{
for (auto i = m_sessionMap.begin(); i != m_sessionMap.end(); ++i)
{
LtsSession *session = *i;
session->aboutToClose();
session->setInactive();
session->deleteLater();
}
for (auto i = m_sessionMap.begin(); i != m_sessionMap.end(); ++i)
{
LtsSession* session = *i;
session->aboutToClose();
session->setInactive();
session->deleteLater();
}
m_sessionMap.clear();
m_sessionMap.clear();
emit hideAllOtherBLWs(nullptr); // for tablet mode! shows another hidden session from some other app or maybe the same app, after the visible one was hidden
emit hideAllOtherBLWs(nullptr); // for tablet mode! shows another hidden session from some other app or maybe the
// same app, after the visible one was hidden
QMetaObject::invokeMethod(this, &LtsSessionManager::signalQuit, Qt::QueuedConnection); // wait until all Session's deleteLater is done
QMetaObject::invokeMethod(this, &LtsSessionManager::signalQuit,
Qt::QueuedConnection); // wait until all Session's deleteLater is done
}
LtsSession *LtsSessionManager::createSession(const DdsConnectionParams &connParams,
bool hasBaseLayout,
bool payloads,
LtsSession* LtsSessionManager::createSession(const DdsConnectionParams& connParams, bool hasBaseLayout, bool payloads,
bool hidden)
{
LtsSession *session = getSession(connParams.partitionType, connParams.partitionId);
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);
// QueuedConnection since Qt5.9.1 seems to send the buttonRelease event again when entering an
// eventloop within this slot. Not yet clear why this happens
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 (session != nullptr)
{
if (i.value() == session)
return;
WARNING_LOG(m_logger) << "Tried to create a Session that already exists";
return nullptr;
}
WARNING_LOG(m_logger) << "Previously deleted Session " << session->partitionId() << "/"
<< session->partitionType() << " is still alive!";
});
session = new LtsSession(this);
connect(session, &LtsSession::signalQuit, this, &LtsSessionManager::signalQuit);
// QueuedConnection since Qt5.9.1 seems to send the buttonRelease event again when entering an
// eventloop within this slot. Not yet clear why this happens
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(); // after payloads are done (if any), the base layout will be created
if (hasBaseLayout)
session->setBaseLayoutVisible(); // after payloads are done (if any), the base layout will be created
if (payloads)
session->setPayloadsEnabled();
if (payloads)
session->setPayloadsEnabled();
m_sessionMap[SessionKey(connParams.partitionType, connParams.partitionId)] = session;
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)) // init not successful? return invalid ptr
LtsSession* globSession = getSession(IDL::PartitionType::Global, 0);
if (globSession && globSession->ddsConnector() && globSession->domainId() == connParams.domainId)
{
session->deleteLater();
return nullptr;
}
}
else
{
/*
* init SOLLTE asynchron ablaufen.
* init läuft aber synchron, da die Payloads der Plugins DIrectConnections benutzen.
* AUf QueuedCOnnections umbauen ist schwerer, da init mit einem SessionCount von 0 rechnet, da init blocking ist und es daher nicht zum aufruf m_sessionMap[...] = ...; kommt......
*/
if (!session->init(connParams, m_dataPluginList, m_guiPluginList, hidden)) // init not successful? return invalid ptr
dds::domain::DomainParticipant dp = globSession->ddsConnector()->getDomainParticipant();
if (!session->init(dp, connParams, m_dataPluginList,
m_guiPluginList)) // init not successful? return invalid ptr
{
session->deleteLater();
return nullptr;
}
}
else
{
session->deleteLater();
return nullptr;
/*
* init SOLLTE asynchron ablaufen.
* init läuft aber synchron, da die Payloads der Plugins DIrectConnections benutzen.
* AUf QueuedCOnnections umbauen ist schwerer, da init mit einem SessionCount von 0 rechnet, da init blocking
* ist und es daher nicht zum aufruf m_sessionMap[...] = ...; kommt......
*/
if (!session->init(connParams, m_dataPluginList, m_guiPluginList,
hidden)) // init not successful? return invalid ptr
{
session->deleteLater();
return nullptr;
}
}
}
if (session->isInitializationDone())
QMetaObject::invokeMethod(this, &LtsSessionManager::signalInitializationFinished, Qt::QueuedConnection);
else
connect(session, &LtsSession::signalDoneInitializingSession, this,
&LtsSessionManager::signalInitializationFinished, Qt::QueuedConnection);
if (session->isInitializationDone())
QMetaObject::invokeMethod(this, &LtsSessionManager::signalInitializationFinished,
Qt::QueuedConnection);
else
connect(session, &LtsSession::signalDoneInitializingSession,
this, &LtsSessionManager::signalInitializationFinished,
Qt::QueuedConnection);
return session;
return session;
}
void LtsSessionManager::slotCloseSession()
{
LtsSession *session = qobject_cast<LtsSession *>(QObject::sender());
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)
if (!session)
{
const auto key = i.key();
session->aboutToClose();
session->setInactive();
session->deleteLater();
m_sessionMap.remove(key); // when destruction takes a long time, a new session may have been added which invalidated the iterator
found = true;
break;
FATAL_LOG(m_logger)
<< "LtsSessionManager: slot called without object - so it cannot be deleted from the session list!";
return;
}
}
if (!found)
FATAL_LOG(m_logger) << "LtsSessionManager: Cannot find Session in map!";
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); // when destruction takes a long time, a new session may have been added which
// invalidated the iterator
emit hideAllOtherBLWs(nullptr); // for tablet mode! shows another hidden session from some other app or maybe the same app, after the visible one was hidden
found = true;
break;
}
}
if (m_sessionMap.isEmpty()) // quit app if all sessions closed
emit signalQuit();
if (!found)
FATAL_LOG(m_logger) << "LtsSessionManager: Cannot find Session in map!";
emit hideAllOtherBLWs(nullptr); // for tablet mode! shows another hidden session from some other app or maybe the
// same app, after the visible one was hidden
if (m_sessionMap.isEmpty()) // quit app if all sessions closed
emit signalQuit();
}
LtsSession *LtsSessionManager::getSession(IDL::PartitionType partitionType, int partitionId)
LtsSession* LtsSessionManager::getSession(IDL::PartitionType partitionType, int partitionId)
{
auto it = m_sessionMap.find(SessionKey(partitionType, partitionId));
auto it = m_sessionMap.find(SessionKey(partitionType, partitionId));
if (it != m_sessionMap.end()) // session found? return it!
return it.value();
if (it != m_sessionMap.end()) // session found? return it!
return it.value();
return nullptr; // not found
return nullptr; // not found
}
} // namespace LtsSession
+77 -69
View File
@@ -10,28 +10,26 @@
#pragma once
#include <LtsSession/ltssession_export.h>
#include <Lts/Common/ProjectConfig/project_defines.h>
#include <LtsPluginManager/lts_plugin_loader.h>
#include <LtsPluginManager/lts_plugin_manager.h>
#include <Lts/Common/ProjectConfig/project_defines.h>
#include <memory>
#include <QString>
#include <QObject>
#include <QVector>
#include <LtsSession/ltssession_export.h>
#include <QMap>
#include <QObject>
#include <QString>
#include <QVector>
#include <memory>
namespace NGL
{
class INGLLogger;
}
namespace DeveloperTools
{
class AppWidget;
}
namespace LtsSession
{
class LtsSession;
@@ -39,76 +37,86 @@ struct DdsConnectionParams;
class LTSSESSION_EXPORT LtsSessionManager : public QObject
{
Q_OBJECT
Q_OBJECT
public:
LtsSessionManager();
~LtsSessionManager();
public:
LtsSessionManager();
~LtsSessionManager();
// create a new session, return old session if already exists [allowClosingSession => true => base layout close = close session | false => base layout close = base layout hide + session still open]
LtsSession *createSession(const DdsConnectionParams &connParams,
bool hasBaseLayout = true,
bool payloads = true,
bool hidden = false);
// return an already created session or null
// create a new session, return old session if already exists [allowClosingSession => true => base layout close =
// close session | false => base layout close = base layout hide + session still open]
LtsSession* createSession(const DdsConnectionParams& connParams, bool hasBaseLayout = true, bool payloads = true,
bool hidden = false);
// return an already created session or null
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();
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);
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
int sessionCount() const
{
if (partitionType != o.partitionType)
return partitionType < o.partitionType;
return partitionId < o.partitionId;
return m_sessionMap.count();
}
};
void logout();
void addPayloads(LtsSession *session);
LtsAppDescriptor::App appId() const
{
return m_appId;
}
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;
bool isHeadless() const
{
return m_headless;
}
private slots:
void slotCloseSession();
QVector<LtsSession*> sessions();
void softQuit();
signals:
/**
* @brief signalStopBlock (see slotCloseRequest)
*/
void signalStopBlock();
void signalLogout();
void signalQuit();
void signalInitializationFinished();
void signalInitializationAborted();
void hideAllOtherBLWs(QObject *caller);
void taskSwitch(QObject *caller);
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:
/**
* @brief signalStopBlock (see slotCloseRequest)
*/
void signalStopBlock();
void signalLogout();
void signalQuit();
void signalInitializationFinished();
void signalInitializationAborted();
void hideAllOtherBLWs(QObject* caller);
void taskSwitch(QObject* caller);
};
} // namespace LtsSession