bool PluginThread::initPlugin() { PluginManager* manager = Carbon::get()->getPluginManager(); //For new plugins, executable denotes the executable plugin, class mainScript the plugin caption and secondary script the plugin type (as integer) AbstractPlugin* plugin = manager->findPlugin(getTaskDefinition().getFirst(), getTaskDefinition().getSecond(), getTaskDefinition().getThird().compare("") == 0 ? -1 : getTaskDefinition().getThird().toInt()); if (plugin == 0) { LOG_ERROR() << "Could not initialize PluginThread because plugin to start with was not found."; mPlugin = 0; return false; } if (plugin->getPluginType() == PT_FRAME) { LOG_ERROR() << "Could not initialize PluginThread because plugin is of type AttachableFrame. AttachableFrame plugins can only be started in the main thread."; mPlugin = 0; return false; } if (plugin->getExecutionType() == AbstractPlugin::ET_NEVER) { LOG_ERROR() << "Could not initialize PluginThread because the plugin is not executable. It has to have an execution type of ONCE, LOOP or ANY."; mPlugin = 0; return false; } mPlugin = plugin; if (mPlugin->isQObject()) { //Connect to plugin update functions connect(mPlugin->getQObject(), SIGNAL(paused()), this, SLOT(pluginPaused())); connect(mPlugin->getQObject(), SIGNAL(running()), this, SLOT(pluginRunning())); connect(mPlugin->getQObject(), SIGNAL(finished()), this, SLOT(pluginFinished())); } return true; }
void PluginThread::updatePluginDelete(AbstractPlugin* plugin) { if (mPlugin == 0) return; if (plugin != mPlugin) return; //not this plugin //Plugin is going to be deleted by the SimulationManager. Should not be done before stopping the simulation, but the plugin is still existant. LOG_WARNING() << "A plugin running in a PluginThread is going to be removed without stopping the thread. Aborting plugin execution..."; stop(); int waited = 0; bool stopped = true; while (getExecutionState() != TES_FINISHED && getExecutionState() != TES_TERMINATED) { wait(20); if (waited == 100) //Wait 2 seconds { LOG_ERROR() << "Could not stop plugin. No response."; stopped = false; break; } } if (stopped) { LOG_INFO() << "Plugin " << mPlugin->getCaption() << " (" << mPlugin->getClassName() << ") stopped."; if (mPlugin->isQObject()) { disconnect(mPlugin->getQObject(), SIGNAL(paused()), this, SLOT(pluginPaused())); disconnect(mPlugin->getQObject(), SIGNAL(running()), this, SLOT(pluginRunning())); disconnect(mPlugin->getQObject(), SIGNAL(finished()), this, SLOT(pluginFinished())); } } mPlugin = 0; }
void sampleNetwork::readXML(QDomNode root){ printf("Reading Sample Network XML\n"); settings.readXML(root); emit pluginRunning(); }