ATLAS Offline Software
Loading...
Searching...
No Matches
VP1ChannelManager Class Reference

#include <VP1ChannelManager.h>

Inheritance diagram for VP1ChannelManager:
Collaboration diagram for VP1ChannelManager:

Classes

class  Imp

Signals

void uniquename_channelListChanged (const QStringList &)
void availableChannelListChanged (const QStringList &)
void availableUnusedChannelListChanged (const QStringList &)
void newChannelCreated (IVP1ChannelWidget *)
void channelUncreated (IVP1ChannelWidget *)

Public Member Functions

 VP1ChannelManager (VP1ExecutionScheduler *, VP1MainWindow *)
 ~VP1ChannelManager ()
QString loadPluginFile (const QString &filename)
bool unloadPluginFile (const QString &filename)
QStringList currentPluginFiles () const
QStringList channelsInPluginFile (const QString &filename) const
QStringList basename2UniqueNames (const QString &basename) const
bool deleteChannel (const QString &channeluniquename)
IVP1ChannelWidgetgetChannel (const QString &channelbasename, QString &err)
unsigned nActive (const QString &channelbasename) const
IVP1ChannelWidgetuniqueName2Channel (const QString &uniquename) const
bool hasRefreshingSystem (const QString &uniquename) const
QStringList uniquenames () const
bool uniqueNameExists (const QString &) const
bool baseNameExists (const QString &) const
bool channelWithBasenameIsLoaded (const QString &basename) const
QStringList serializePluginInfo () const
QWidget * getController (IVP1ChannelWidget *)
QString getIconLocation (const QString &channelname, const bool &isbasename=true)
QStringList availableChannelList ()

Private Attributes

Impm_d

Detailed Description

Definition at line 27 of file VP1ChannelManager.h.

Constructor & Destructor Documentation

◆ VP1ChannelManager()

VP1ChannelManager::VP1ChannelManager ( VP1ExecutionScheduler * sched,
VP1MainWindow * mw )

Definition at line 108 of file VP1ChannelManager.cxx.

108 : m_d(new Imp)
109{
110 m_d->channelmanager=this;
111 m_d->scheduler=sched;
112 m_d->mainwindow=mw;
113}

◆ ~VP1ChannelManager()

VP1ChannelManager::~VP1ChannelManager ( )

Definition at line 116 of file VP1ChannelManager.cxx.

117{
118 while(!m_d->uniquename_2_channel.empty())
119 deleteChannel(m_d->uniquename_2_channel.begin()->first);
120
121 std::map<QString,QPluginLoader*>::const_iterator it, itE = m_d->pluginfile_2_pluginloader.end();
122 for(it=m_d->pluginfile_2_pluginloader.begin();it!=itE;++it)
123 delete it->second;
124
125 for (QObject* o : m_d->additionalOwnedObjects)
126 delete o;
127 delete m_d;
128}
bool deleteChannel(const QString &channeluniquename)

Member Function Documentation

◆ availableChannelList()

QStringList VP1ChannelManager::availableChannelList ( )

Definition at line 498 of file VP1ChannelManager.cxx.

498 {
499 QStringList l;
500 std::map<QString,QString>::const_iterator it = m_d->basename_2_pluginfile.begin();
501 std::map<QString,QString>::const_iterator itE = m_d->basename_2_pluginfile.end();
502 for (;it!=itE;++it) {
503 l << it->first;
504 }
505 return l;
506}
l
Printing final latex table to .tex output file.

◆ availableChannelListChanged

void VP1ChannelManager::availableChannelListChanged ( const QStringList & )
signal

◆ availableUnusedChannelListChanged

void VP1ChannelManager::availableUnusedChannelListChanged ( const QStringList & )
signal

◆ basename2UniqueNames()

QStringList VP1ChannelManager::basename2UniqueNames ( const QString & basename) const

Definition at line 546 of file VP1ChannelManager.cxx.

546 {
547
548 if (m_d->basename_2_channels.find(basename)==m_d->basename_2_channels.end())
549 return QStringList();
550
551 std::set<IVP1ChannelWidget*>::const_iterator it = m_d->basename_2_channels[basename].begin();
552 std::set<IVP1ChannelWidget*>::const_iterator itE = m_d->basename_2_channels[basename].end();
553
554 QStringList l;
555 for (;it!=itE;++it) {
556 l << (*it)->unique_name();
557 }
558 return l;
559}
std::string basename(std::string name)
Definition utils.cxx:207

◆ baseNameExists()

bool VP1ChannelManager::baseNameExists ( const QString & basename) const

Definition at line 467 of file VP1ChannelManager.cxx.

467 {
468 return (m_d->basename_2_pluginfile.find(basename)!=m_d->basename_2_pluginfile.end());
469}

◆ channelsInPluginFile()

QStringList VP1ChannelManager::channelsInPluginFile ( const QString & filename) const

Definition at line 358 of file VP1ChannelManager.cxx.

358 {
359 if (m_d->pluginfile_2_basenamesAndFactory.find(filename)==m_d->pluginfile_2_basenamesAndFactory.end())
360 return QStringList();
361 return m_d->pluginfile_2_basenamesAndFactory[filename].first;
362}

◆ channelUncreated

void VP1ChannelManager::channelUncreated ( IVP1ChannelWidget * )
signal

◆ channelWithBasenameIsLoaded()

bool VP1ChannelManager::channelWithBasenameIsLoaded ( const QString & basename) const

Definition at line 562 of file VP1ChannelManager.cxx.

562 {
563 if (m_d->basename_2_channels.find(basename)==m_d->basename_2_channels.end())
564 return false;
565 return !m_d->basename_2_channels[basename].empty();
566}

◆ currentPluginFiles()

QStringList VP1ChannelManager::currentPluginFiles ( ) const

Definition at line 535 of file VP1ChannelManager.cxx.

535 {
536 std::map<QString,QPluginLoader*>::const_iterator it = m_d->pluginfile_2_pluginloader.begin();
537 std::map<QString,QPluginLoader*>::const_iterator itE = m_d->pluginfile_2_pluginloader.end();
538 QStringList l;
539 for(;it!=itE;++it) {
540 l<<it->first;
541 }
542 return l;
543}

◆ deleteChannel()

bool VP1ChannelManager::deleteChannel ( const QString & channeluniquename)

Definition at line 132 of file VP1ChannelManager.cxx.

132 {
133
134 //Find info:
135 assert(m_d->uniquename_2_channel.find(channeluniquename)!=m_d->uniquename_2_channel.end());
136 IVP1ChannelWidget * cw = m_d->uniquename_2_channel[channeluniquename];
137 QString bn = cw->name();
138 assert(m_d->basename_2_channels.find(bn)!=m_d->basename_2_channels.end());
139
140 //Remove channelwidget from maps, and delete it.
141 assert(m_d->basename_2_channels[bn].find(cw)!=m_d->basename_2_channels[bn].end());
142 m_d->basename_2_channels[bn].erase(m_d->basename_2_channels[bn].find(cw));
143 m_d->uniquename_2_channel.erase(m_d->uniquename_2_channel.find(channeluniquename));
144
145 m_d->scheduler->uncreateAndDelete(cw);//The actual uncreate()+delete might be postponed if a system is
146 //presently refreshing. But for all bookkeeping purposes it already
147 //happened!
148
150
151 //Remove controller from maps - and ensure the widget gets deleted
152 //in any case (it is a scrollarea, not the controller known by the
153 //actual channelwidget):
154 assert(m_d->channel_2_controller.find(cw)!=m_d->channel_2_controller.end());
155 m_d->channel_2_controller[cw]->deleteLater();
156 m_d->channel_2_controller.erase(m_d->channel_2_controller.find(cw));
157 assert(m_d->channel_2_controller.find(cw)==m_d->channel_2_controller.end());
158
159 //Finally, assign new cloneids to any remaining channels of the same basename:
160 //First wipe old info in uniquename_2_channel.
161 std::set<IVP1ChannelWidget*>::iterator it = m_d->basename_2_channels[bn].begin();
162 std::set<IVP1ChannelWidget*>::iterator itE = m_d->basename_2_channels[bn].end();
163 for (;it!=itE;++it) {
164 assert(m_d->uniquename_2_channel.find((*it)->unique_name())!=m_d->uniquename_2_channel.end());
165 m_d->uniquename_2_channel.erase(m_d->uniquename_2_channel.find((*it)->unique_name()));
166 }
167
168 it = m_d->basename_2_channels[bn].begin();
169 unsigned id(0);
170 for (;it!=itE;++it) {
171 (*it)->setCloneID(id++);
172 (*it)->unique_name();
173 assert(m_d->uniquename_2_channel.find((*it)->unique_name())==m_d->uniquename_2_channel.end());
174 m_d->uniquename_2_channel[(*it)->unique_name()]=(*it);
175 }
176
178 m_d->emit_basename_availableUnusedChannelListChanged();
179 return true;
180}
const QString & name() const
void channelUncreated(IVP1ChannelWidget *)
QStringList uniquenames() const
void uniquename_channelListChanged(const QStringList &)

◆ getChannel()

IVP1ChannelWidget * VP1ChannelManager::getChannel ( const QString & channelbasename,
QString & err )

Definition at line 403 of file VP1ChannelManager.cxx.

403 {
404 IVP1ChannelWidget * cw = m_d->constructChannel( channelbasename, err );
405 if (!cw)
406 return 0;
407 cw->setUpdatesEnabled(false);
408 cw->setCloneID(nActive(channelbasename));
409 assert(m_d->uniquename_2_channel.find(cw->unique_name())==m_d->uniquename_2_channel.end());
410 m_d->uniquename_2_channel[cw->unique_name()]=cw;
411 m_d->basename_2_channels[channelbasename].insert(cw);
412
414 m_d->scheduler->bringFromConstructedToReady(cw);//Fixme: should return bool
415 assert(cw->state()==IVP1ChannelWidget::READY);
416
417 assert(m_d->channel_2_controller.find(cw)==m_d->channel_2_controller.end());
418 QWidget * controller = cw->controllerWidget();
419 QScrollArea * scrollarea = new QScrollArea;
420 // controller->setParent(scrollarea);
421 scrollarea->setObjectName("VP1ControllerScrollArea");
422 scrollarea->setWidgetResizable(true);
423 scrollarea->setFrameShape(QFrame::NoFrame);
424 scrollarea->setFrameShadow(QFrame::Plain);
425
426
427 //scrollArea->setBackgroundRole(QPalette::Dark);
428 scrollarea->setWidget(controller);
429 m_d->channel_2_controller[cw] = scrollarea;
430
432 m_d->emit_basename_availableUnusedChannelListChanged();
434 cw->setUpdatesEnabled(true);
435
436 return cw;
437}
void setCloneID(unsigned id)
const QString unique_name() const
unsigned nActive(const QString &channelbasename) const
void newChannelCreated(IVP1ChannelWidget *)

◆ getController()

QWidget * VP1ChannelManager::getController ( IVP1ChannelWidget * cw)

Definition at line 440 of file VP1ChannelManager.cxx.

440 {
441 assert(m_d->channel_2_controller.find(cw)!=m_d->channel_2_controller.end());
442 return m_d->channel_2_controller[cw];
443}

◆ getIconLocation()

QString VP1ChannelManager::getIconLocation ( const QString & channelname,
const bool & isbasename = true )

Definition at line 588 of file VP1ChannelManager.cxx.

589{
590 if (!isbasename) {
591 IVP1ChannelWidget* cw = uniqueName2Channel(channelname);
592 if (!cw)
593 return "";
594 return m_d->channelTypeToIconLocation(cw->type());
595 }
596
597 if (m_d->basename2iconlocation.contains(channelname))
598 return m_d->basename2iconlocation[channelname];
599
600 //We have to briefly construct a channel in order to get its type.
601 //The following create and destruct maneouver is to get a proper
602 //cache of the icontext associated with the channel:
603 QString err;
604 IVP1ChannelWidget * cw = m_d->constructChannel( channelname, err, false /*don't init()*/ );
605 if (!cw)
606 return "";
607 cw->deleteControllers();
608 delete cw;
609 // cppcheck-suppress deallocuse
610 assert(m_d->channel_2_controller.find(cw)==m_d->channel_2_controller.end());
611
612 //Try again;
613 if (m_d->basename2iconlocation.contains(channelname))
614 return m_d->basename2iconlocation[channelname];
615 return "";
616}
virtual Type type() const =0
IVP1ChannelWidget * uniqueName2Channel(const QString &uniquename) const

◆ hasRefreshingSystem()

bool VP1ChannelManager::hasRefreshingSystem ( const QString & uniquename) const

Definition at line 581 of file VP1ChannelManager.cxx.

582{
583 IVP1ChannelWidget*cw = uniqueName2Channel(uniquename);
584 return cw ? cw->hasRefreshingSystem() : false;
585}

◆ loadPluginFile()

QString VP1ChannelManager::loadPluginFile ( const QString & filename)

Definition at line 229 of file VP1ChannelManager.cxx.

230{
231
232 VP1Msg::messageVerbose("VP1ChannelManager::loadPluginFile() - filename: " + filename);
233
234 QString bn = QFileInfo(filename).fileName();
235
236 if (m_d->pluginfile_2_basenamesAndFactory.find(filename)!=m_d->pluginfile_2_basenamesAndFactory.end()) {
237 return "Error: Plugin already loaded.";
238 } else {
239
240
241 QFileInfo fi(filename);
242 if (!fi.exists())
243 return "File does not exist";
244 if (!fi.isReadable())
245 return "File is not readable";
246
247 VP1Msg::messageVerbose("plugin path: " + fi.absoluteFilePath());
248 VP1Msg::messageVerbose("app path: " + QCoreApplication::applicationDirPath());
249 VP1Msg::messageVerbose("library path: " + QLibraryInfo::location(QLibraryInfo::PluginsPath));
250
251 QString pluginAbsPath = fi.absoluteFilePath();
252
253 QPluginLoader * loader = new QPluginLoader(pluginAbsPath);//Fixme: Ensure all loaders gets unloaded on shutdown (and thus deleted)
254 m_d->pluginfile_2_pluginloader[filename]=loader;
255
256 bool loadOk = loader->load();
257
258 if (!loadOk) {
259 VP1Msg::message("ERROR! Failed to load plugin. Error message: "+loader->errorString());
260
261 VP1Msg::message("Trying to load the 'dbg' build...");
262
263 /*
264 * when running VP1 sometimes (especially from the devval release) the
265 * load of the plugin fails silently...
266 * After a long investigation, I found that the problem is in the mismatch
267 * between the compilation flag of the main Qt application
268 * and the flag of the plugin modules.
269 * For example the main application is compiled in 'dbg', while the plugins
270 * are compiled in 'opt' mode...
271 * We still understand why...
272 * In the meantime I implemented a workaround: the 'opt' flag is replaced
273 * by the 'dbg' flag when the plugin fails to load.
274 *
275 */
276 // QString build = "x86_64-slc6-gcc47-opt";
277 //QString buildB = "x86_64-slc6-gcc47-dbg";
278 //pluginAbsPath.replace(build, buildB);
279
280 pluginAbsPath.replace("opt", "dbg");
281
282 loader = new QPluginLoader(pluginAbsPath);
283 loadOk = loader->load();
284
285 if (loadOk) VP1Msg::message("Ok! 'dbg' build of the plugin successfully loaded!");
286 else VP1Msg::message("ERROR!! Also the 'dbg' build failed to load!!");
287
288 }
289
290
291 QObject *plugin = loader->instance();
292
293
294 if (!plugin) {
295
296 bool error = loader->errorString().isNull();
297
298
299 QString errStr = "ERROR!!";
300 if (error)
301 errStr = QString("Did not find any compatible plugins in file");
302 else
303 errStr = loader->errorString();
304
305
306 return errStr;
307 }
308
309
310 IVP1ChannelWidgetFactory * fact = qobject_cast<IVP1ChannelWidgetFactory *>(plugin);
311 m_d->additionalOwnedObjects << plugin;
312
313
314 if (!fact)
315 return "Did not find any channel factory in plugin file";
316
317
318 QStringList providedbasenames = fact->channelWidgetsProvided();
319
320
321 if (providedbasenames.count()==0)
322 return "Found channel factory in plugin file, but no advertised channels!";
323
324
325 m_d->pluginfile_2_basenamesAndFactory[filename] = std::pair<QStringList,IVP1ChannelWidgetFactory *>(providedbasenames,fact);
326
327
328 for (const QString& bn : providedbasenames) {
329 if (m_d->basename_2_pluginfile.find(bn)!=m_d->basename_2_pluginfile.end())
330 return "Channels navp1 '"+bn+"' are already provided by plugin file "
331 +m_d->basename_2_pluginfile[bn]+" (ignoring other plugins in file '"+filename+"')";
332 }
333
334
335 for (const QString& bn : providedbasenames) {
336 m_d->basename_2_pluginfile[bn] = filename;
337 m_d->basename_2_channels[bn] = std::set<IVP1ChannelWidget*>();
338 }
339
340
341 m_d->emit_basename_availableChannelListChanged();
342 m_d->emit_basename_availableUnusedChannelListChanged();
343
344
345 //Fixme: check 20 chars.
346 }
347
348
349 m_d->mainwindow->addToMessageBox( "Successfully loaded "+bn, "color:#008b00" );
350 QString out = "providing channels: "+channelsInPluginFile(filename).join(", ");
351 m_d->mainwindow->addToMessageBox( out, "color:#008b00" );
352
353
354 return "";
355}
virtual QStringList channelWidgetsProvided() const =0
QStringList channelsInPluginFile(const QString &filename) const
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30

◆ nActive()

unsigned VP1ChannelManager::nActive ( const QString & channelbasename) const

Definition at line 446 of file VP1ChannelManager.cxx.

446 {
447 if (m_d->basename_2_channels.find(channelbasename)==m_d->basename_2_channels.end())
448 return 0;
449 return m_d->basename_2_channels[channelbasename].size();
450}

◆ newChannelCreated

void VP1ChannelManager::newChannelCreated ( IVP1ChannelWidget * )
signal

◆ serializePluginInfo()

QStringList VP1ChannelManager::serializePluginInfo ( ) const

Definition at line 523 of file VP1ChannelManager.cxx.

523 {
524 std::map<QString,std::pair<QStringList,IVP1ChannelWidgetFactory *> >::const_iterator
525 it, itE = m_d->pluginfile_2_basenamesAndFactory.end();
526
527 QStringList l;
528 for( it = m_d->pluginfile_2_basenamesAndFactory.begin(); it!=itE; ++it ) {
529 l<<QFileInfo(it->first).fileName();
530 }
531 return l;
532}

◆ uniqueName2Channel()

IVP1ChannelWidget * VP1ChannelManager::uniqueName2Channel ( const QString & uniquename) const

Definition at line 455 of file VP1ChannelManager.cxx.

455 {
456 if (m_d->uniquename_2_channel.find(uniquename)==m_d->uniquename_2_channel.end())
457 return 0;
458 return m_d->uniquename_2_channel[uniquename];
459}

◆ uniquename_channelListChanged

void VP1ChannelManager::uniquename_channelListChanged ( const QStringList & )
signal

◆ uniqueNameExists()

bool VP1ChannelManager::uniqueNameExists ( const QString & uniquename) const

Definition at line 462 of file VP1ChannelManager.cxx.

462 {
463 return (m_d->uniquename_2_channel.find(uniquename)!=m_d->uniquename_2_channel.end());
464}

◆ uniquenames()

QStringList VP1ChannelManager::uniquenames ( ) const

Definition at line 472 of file VP1ChannelManager.cxx.

472 {
473 QStringList l;
474 std::map<QString,IVP1ChannelWidget*>::iterator it = m_d->uniquename_2_channel.begin();
475 std::map<QString,IVP1ChannelWidget*>::iterator itE = m_d->uniquename_2_channel.end();
476
477 for (;it!=itE;++it)
478 l << it->first;
479
480 return l;
481}

◆ unloadPluginFile()

bool VP1ChannelManager::unloadPluginFile ( const QString & filename)

Definition at line 184 of file VP1ChannelManager.cxx.

184 {
185
186 VP1Msg::messageVerbose("VP1ChannelManager::unloadPluginFile()");
187
188 if (m_d->pluginfile_2_pluginloader.find(filename)==m_d->pluginfile_2_pluginloader.end())
189 return false;
190
191 assert(m_d->pluginfile_2_basenamesAndFactory.find(filename)!=m_d->pluginfile_2_basenamesAndFactory.end());
192 assert(m_d->pluginfile_2_pluginloader.find(filename)!=m_d->pluginfile_2_pluginloader.end());
193
194 //Find basenames provided by this plugin, as well as factory and pluginloader:
195 QStringList bns = channelsInPluginFile(filename);
196 IVP1ChannelWidgetFactory * fact = m_d->pluginfile_2_basenamesAndFactory.find(filename)->second.second;
197 QPluginLoader* loader = m_d->pluginfile_2_pluginloader[filename];
198
199 //Abort if any active channels are affected by this plugin:
200 for (const QString& bn : bns)
201 if (nActive(bn)>0)
202 return false;
203
204 //Delete factory:
205 delete fact;
206
207 //Unload:
208 bool success = loader->unload();
209 delete loader;
210
211 //Update maps:
212 m_d->pluginfile_2_basenamesAndFactory.erase(m_d->pluginfile_2_basenamesAndFactory.find(filename));
213 m_d->pluginfile_2_pluginloader.erase(m_d->pluginfile_2_pluginloader.find(filename));
214 for (const QString& bn : bns) {
215 m_d->basename_2_channels.erase(m_d->basename_2_channels.find(bn));
216 m_d->basename_2_pluginfile.erase(m_d->basename_2_pluginfile.find(bn));
217 }
218
219 //Emit signals regarding changes:
221 m_d->emit_basename_availableChannelListChanged();
222 m_d->emit_basename_availableUnusedChannelListChanged();
223
224 //Return:
225 return success;
226}

Member Data Documentation

◆ m_d

Imp* VP1ChannelManager::m_d
private

Definition at line 82 of file VP1ChannelManager.h.


The documentation for this class was generated from the following files: