Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+294
@@ -0,0 +1,294 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Plugin Loader for Gui Plugins, keeps a list of *tc of all Plugins
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*
|
||||
* Created by Mike Wille, SLSE, 2016-05-20
|
||||
*/
|
||||
|
||||
#include "lts_plugin_manager.h"
|
||||
#include "Ui/lts_plugin_manager_dialog.h"
|
||||
|
||||
#include <LtsSession/lts_session_data_dds.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <LtsWidgets/lts_wait_dialog.h>
|
||||
#include <LtsPluginManager/lts_plugin_loader.h>
|
||||
#include <LtsSession/lts_session_manager.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <PluginInterfaces/data_plugin_interface.h>
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace LtsPluginManager
|
||||
{
|
||||
|
||||
LtsPluginManager::LtsPluginManager()
|
||||
: m_sessionManager(new LtsSession::LtsSessionManager)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsPluginManager"))
|
||||
, m_markedForDeletion(false)
|
||||
{
|
||||
connect(m_sessionManager, &LtsSession::LtsSessionManager::signalQuit,
|
||||
this, &LtsPluginManager::signalQuit);
|
||||
connect(m_sessionManager, &LtsSession::LtsSessionManager::signalLogout,
|
||||
this, &LtsPluginManager::signalLogout);
|
||||
connect(m_sessionManager, &LtsSession::LtsSessionManager::signalInitializationFinished,
|
||||
this, &LtsPluginManager::signalInitializationFinished);
|
||||
connect(m_sessionManager, &LtsSession::LtsSessionManager::signalInitializationAborted,
|
||||
this, &LtsPluginManager::signalInitializationAborted);
|
||||
connect(m_sessionManager, &LtsSession::LtsSessionManager::signalInitializationFinished,
|
||||
this, &LtsPluginManager::slotInitializationFinished);
|
||||
connect(m_sessionManager, &LtsSession::LtsSessionManager::taskSwitch,
|
||||
this, &LtsPluginManager::taskSwitch);
|
||||
connect(m_sessionManager, &LtsSession::LtsSessionManager::hideAllOtherBLWs,
|
||||
this, &LtsPluginManager::hideAllOtherBLWs);
|
||||
|
||||
QTimer *t = new QTimer(this);
|
||||
t->setInterval(1000);
|
||||
connect(t, &QTimer::timeout,
|
||||
this, &LtsPluginManager::signalStillAlive);
|
||||
t->start();
|
||||
}
|
||||
|
||||
|
||||
LtsPluginManager::~LtsPluginManager()
|
||||
{
|
||||
// qCritical() << "~LtsPluginManager";
|
||||
|
||||
delete m_sessionManager;
|
||||
}
|
||||
|
||||
|
||||
void LtsPluginManager::softQuit()
|
||||
{
|
||||
emit signalSoftQuit();
|
||||
}
|
||||
|
||||
|
||||
void LtsPluginManager::_softQuit()
|
||||
{
|
||||
m_sessionManager->softQuit();
|
||||
}
|
||||
|
||||
|
||||
QVector<LtsSession::LtsSession *> LtsPluginManager::sessions() const
|
||||
{
|
||||
return m_sessionManager->sessions();
|
||||
}
|
||||
|
||||
bool LtsPluginManager::hasSituationMapInstance(const LtsAppDescriptor::AppDescription &appDescription, bool alsoTestForScriptApp)
|
||||
{
|
||||
if (alsoTestForScriptApp && appDescription.id == LtsAppDescriptor::App::Scripts) // does not load sitmap itself, but starts sitmap app in background for playback!
|
||||
return true;
|
||||
|
||||
for (const LtsAppDescriptor::PluginInfo &pluginInfo : qAsConst(appDescription.pluginInfos))
|
||||
{
|
||||
if (pluginInfo.flags.testFlag(LtsAppDescriptor::PluginInfo::Flag::ACTIONS) &&
|
||||
(pluginInfo.iid == QStringLiteral("sitmap"))) // must match iid of appsJson / Q_PLUGIN_METADATA
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LtsPluginManager::hasSituationMapInstance() const
|
||||
{
|
||||
return hasSituationMapInstance(m_app);
|
||||
}
|
||||
|
||||
LtsSession::LtsSession *LtsPluginManager::getSession(IDL::PartitionType partitionType, int partitionId)
|
||||
{
|
||||
return m_sessionManager->getSession(partitionType, partitionId);
|
||||
}
|
||||
|
||||
|
||||
bool LtsPluginManager::startApp(const LtsAppDescriptor::AppDescription &app, bool headless,
|
||||
const LtsSession::DdsConnectionParams &connParams, const QString &workspaceId,
|
||||
bool hidden)
|
||||
{
|
||||
// if (QApplication::queryKeyboardModifiers() == Qt::ControlModifier)
|
||||
// m_pluginManagerDialog->show(); // only show plugin manager debug window, when CTRL pressed
|
||||
|
||||
LtsWidgets::LtsWaitDialogContainer wait;
|
||||
|
||||
m_app = app;
|
||||
LtsPluginLoader *pluginLoader = LtsPluginLoader::getInstance();
|
||||
|
||||
|
||||
// Data Plugins
|
||||
QVector<PluginInstance> dataPlugins;
|
||||
auto cb = [&](const PluginInstance &pi)
|
||||
{
|
||||
dataPlugins.append(pi);
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!pluginLoader->loadPlugins(PluginType::DATA, cb))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "PluginLoader failed to load data plugins - abort!";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Gui Plugins
|
||||
QVector<PluginInstance> guiPlugins;
|
||||
auto cbLoadPlugins = [&](const PluginInstance &pi)
|
||||
{
|
||||
guiPlugins.append(pi);
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!pluginLoader->loadPlugins(PluginType::GUI, cbLoadPlugins))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "PluginLoader failed to load gui plugins - abort!";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* OLD! Problem: there is only ONE 'PluginInstance', but everytime this block is executed,
|
||||
* flags, etc. are set. Therefore old flags have been overwritten, causing new Sessions
|
||||
* to start as the last app that was opened. */
|
||||
|
||||
// for (auto i1 = guiPlugins.begin(); i1 != guiPlugins.end(); ++i1) // check for errors
|
||||
// {
|
||||
// PluginInstance &pi = *i1;
|
||||
|
||||
// GuiPluginBase::Plugin *plugin = qobject_cast<GuiPluginBase::Plugin *>(pi.plugin);
|
||||
// if (!plugin)
|
||||
// {
|
||||
// qCritical() << "plugin" << pi.fileName << "not a gui plugin!";
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// plugin->setAppName(m_app.appName);
|
||||
|
||||
// // now add flags from requirement list ........
|
||||
// //qCritical() << "adding flags from requirement list:";
|
||||
|
||||
// bool found = false;
|
||||
// for (auto i2 = app.requiredPlugins.constBegin(); i2 != app.requiredPlugins.constEnd(); ++i2)
|
||||
// {
|
||||
// const LtsAppDescriptor::PluginInfo &rp = *i2;
|
||||
// //qCritical() << " > requirement: iid" << rp.iid << "type" << (int)rp.type << "flags" << rp.flags;
|
||||
|
||||
// if (rp.type == LtsAppDescriptor::PluginInfo::PluginType::GUI
|
||||
// && rp.iid == pi.pluginName)
|
||||
// {
|
||||
|
||||
|
||||
// plugin->setFlags(rp.flags);
|
||||
// plugin->setOptions(rp.options);
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// //qCritical() << "----- done -----";
|
||||
|
||||
// if (!found)
|
||||
// {
|
||||
// qCritical() << "Could not set flags for Plugin" << pi.pluginName << "from file" << pi.fileName;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// create DATA APIs
|
||||
QVector<AppPluginInstance> dataApiList;
|
||||
for (auto i = dataPlugins.constBegin(); i != dataPlugins.constEnd(); ++i)
|
||||
{
|
||||
const PluginInstance &pi = *i;
|
||||
|
||||
AppPluginInstance api;
|
||||
api.pluginInstance = pi; // copy
|
||||
api.m_appName = m_app.appName;
|
||||
api.m_appId = m_app.id;
|
||||
// NOTE: data plugins can't have flags, options, etc.
|
||||
|
||||
dataApiList.append(api);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// create GUI APIs
|
||||
QVector<AppPluginInstance> guiApiList;
|
||||
for (auto i = guiPlugins.constBegin(); i != guiPlugins.constEnd(); ++i)
|
||||
{
|
||||
const PluginInstance &pi = *i;
|
||||
|
||||
AppPluginInstance api;
|
||||
api.pluginInstance = pi; // copy
|
||||
api.m_appName = m_app.appName;
|
||||
api.m_appId = m_app.id;
|
||||
|
||||
// get flags & options for this API
|
||||
//bool found = false;
|
||||
for (auto i2 = app.pluginInfos.constBegin(); i2 != app.pluginInfos.constEnd(); ++i2)
|
||||
{
|
||||
const LtsAppDescriptor::PluginInfo &rp = *i2;
|
||||
//qCritical() << " > requirement: iid" << rp.iid << "type" << (int)rp.type << "flags" << rp.flags;
|
||||
|
||||
if (rp.type == LtsAppDescriptor::PluginInfo::PluginType::GUI
|
||||
&& rp.iid == pi.pluginName)
|
||||
{
|
||||
//qWarning() << "flag" << rp.flags << "for" << rp.iid;
|
||||
api.m_flags = rp.flags;
|
||||
api.m_options = rp.options;
|
||||
//found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if (!found)
|
||||
// {
|
||||
// qCritical() << "Could not set flags for Plugin" << pi.pluginName << "from file" << pi.fileName;
|
||||
// return false;
|
||||
// }
|
||||
|
||||
guiApiList.append(api);
|
||||
}
|
||||
|
||||
|
||||
// if (app.pluginInfos.count() < (dataPlugins.count() + guiPlugins.count()))
|
||||
// {
|
||||
// qCritical() << app.pluginInfos.count() << "plugins required, only" << (dataPlugins.count() + guiPlugins.count()) << "loaded ("<<dataPlugins.count()<<" data, "<<guiPlugins.count()<<" gui) !";
|
||||
// return false;
|
||||
// }
|
||||
|
||||
|
||||
LtsSession::DdsConnectionParams connParamsNew(connParams);
|
||||
if (!connParamsNew.isValid())
|
||||
{
|
||||
INFO_LOG(m_logger) << "Invalid connection params given - using default parameter";
|
||||
// exercise/Partition type from command line are handled inside exm_edit_gui_plugin.cpp / executePayload()
|
||||
connParamsNew.domainId = LtsSessionData::LtsSessionData::getInstance()->getDomainIdPreset();
|
||||
connParamsNew.partitionId = 0;
|
||||
connParamsNew.exerciseId = 0;
|
||||
connParamsNew.partitionType = IDL::PartitionType::Global;
|
||||
|
||||
|
||||
connParamsNew.tcpConnectionUrl = LtsSessionData::LtsSessionData::getInstance()->getTcpConnectionUrl();
|
||||
}
|
||||
if (LtsSessionData::LtsSessionData::getInstance()->getQosFile().size() > 0 && LtsSessionData::LtsSessionData::getInstance()->getQosFile().at(0).size() > 0)
|
||||
connParamsNew.qos_file = LtsSessionData::LtsSessionData::getInstance()->getQosFile();
|
||||
else
|
||||
connParamsNew.qos_file = QStringList();
|
||||
if (!m_sessionManager->init(connParamsNew,
|
||||
dataApiList,
|
||||
guiApiList,
|
||||
m_app.id,
|
||||
workspaceId,
|
||||
headless,
|
||||
hidden))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not create Global Session - abort.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace LtsPluginManager
|
||||
Reference in new issue
Block a user