//---------------------------------------------------------------------------- void ctkPluginFrameworkPrivate::shutdown(bool restart) { Locker sync(&lock); bool wasActive = false; switch (state) { case ctkPlugin::INSTALLED: case ctkPlugin::RESOLVED: shutdownDone_unlocked(false); break; case ctkPlugin::ACTIVE: wasActive = true; // Fall through case ctkPlugin::STARTING: if (shuttingDown.fetchAndAddOrdered(0) == 0) { try { const bool wa = wasActive; shuttingDown.fetchAndStoreOrdered(1); QtConcurrent::run(this, &ctkPluginFrameworkPrivate::shutdown0, restart, wa); } catch (const std::exception& e) { systemShuttingdownDone(ctkPluginFrameworkEvent(ctkPluginFrameworkEvent::PLUGIN_ERROR, this->q_func(), e)); } } break; case ctkPlugin::STOPPING: // Shutdown already inprogress, fall through case ctkPlugin::UNINSTALLED: break; } }
//---------------------------------------------------------------------------- void ctkPluginFrameworkPrivate::shutdown0(bool restart, bool wasActive) { try { { Locker sync(&lock); waitOnOperation(&lock, QString("Framework::") + (restart ? "update" : "stop"), true); operation = DEACTIVATING; state = ctkPlugin::STOPPING; } fwCtx->listeners.emitPluginChanged( ctkPluginEvent(ctkPluginEvent::STOPPING, this->q_func())); if (wasActive) { stopAllPlugins(); } { Locker sync(&lock); fwCtx->uninit(); shuttingDown.fetchAndStoreOrdered(0); shutdownDone_unlocked(restart); } if (restart) { if (wasActive) { q_func().toStrongRef()->start(); } else { init(); } } } catch (const ctkException& e) { shuttingDown.fetchAndStoreOrdered(0); systemShuttingdownDone(ctkPluginFrameworkEvent(ctkPluginFrameworkEvent::PLUGIN_ERROR, this->q_func(), e)); } }