ProxyWidget *DockContainer::loadModule(ConfigModule *module) { QApplication::setOverrideCursor(waitCursor); ProxyWidget *widget = _modulew->load(module); if(widget) { _module = module; connect(_module, SIGNAL(childClosed()), SLOT(removeModule())); connect(_module, SIGNAL(changed(ConfigModule *)), SIGNAL(changedModule(ConfigModule *))); connect(widget, SIGNAL(quickHelpChanged()), SLOT(quickHelpChanged())); raiseWidget(_modulew); emit newModule(widget->caption(), module->docPath(), widget->quickHelp()); } else { raiseWidget(_basew); emit newModule(_basew->caption(), "", ""); } QApplication::restoreOverrideCursor(); return widget; }
void BtInstallThread::slotStopInstall() { qDebug() << "BtInstallThread::slotStopInstall, installing" << m_module << "was cancelled"; if (!done) { done = true; qDebug() << "BtInstallThread::slotStopInstall 1"; m_iMgr.terminate(); this->terminate(); // It's dangerous to forcibly stop, but we will clean up the files qDebug() << "BtInstallThread::slotStopInstall 2"; //qApp->processEvents(); // wait to terminate for some secs. We rather let the execution go on and cleaning up to fail than the app to freeze this->wait(3000); qDebug() << "BtInstallThread::slotStopInstall 3"; qApp->processEvents(); // cleanup: remove the module, remove the temp files // Actually m_iMgr is unnecessary, it could be local in the run(). if (true) { qDebug() << "BtInstallThread::slotStopInstall 4"; // remove the installed module, just to be sure because mgr may // have been terminated when copying files removeModule(); qApp->processEvents(); removeTempFiles(); qApp->processEvents(); qDebug() << "BtInstallThread::slotStopInstall will emit installStopped..."; emit installStopped(m_module, m_source); qApp->processEvents(); } } qDebug() << "BtInstallThread::slotStopInstall end"; }
bool ICQMain::startModule(Profile *prof) { int startOrder = prof->getInteger("start_order", 0); // If start_order is 0 or null, disable it if (!startOrder) { logger->log(LOG_INFORMATION, "module %s is disabled\n", prof->getName()); return false; } Module *m = new Module; m->startOrder = startOrder; m->name = prof->getName(); string name = LINQ_LIB_DIR"/modules/"; name += prof->getName(); if (!m->load(name.c_str())) { logger->log(LOG_WARNING, "Can not load module %s\n", name.c_str()); delete m; return false; } int i = addModule(m); // If module initialization failed for some reason, remove it if (!m->listener->init(i, this, prof)) { ICQ_LOG("Module::init() failed\n"); removeModule(i); return false; } logger->log(LOG_INFORMATION, "module %s is loaded", m->name.c_str()); return true; }
// Stop a module by name bool ICQMain::stopModule(const char *name) { int i = getModuleIndex(name); if (i < 0) { ICQ_LOG("module %s not found\n", name); return false; } Module *m = getModule(i); if (!m) return false; // Stop all work first destroyThreads(); // Remove it from module list for (int e = 0; e < NUM_EVENTS; e++) moduleList[e].remove(m); // Walk through all sessions to remove it if (m->hasSessionEvent) sessionHash->walk(sessionWalker, m); // Remove and delete this module from system removeModule(i); // Recover previous work startThreads(); return true; }
void BtInstallThread::slotStopInstall() { qDebug() << "*************************************\nBtInstallThread::slotStopInstall" << m_module << "\n********************************"; if (!done) { done = true; qDebug() << "*********************************\nBtInstallThread::slotStopInstall, installing" << m_module << "was cancelled\n**************************************"; m_iMgr->terminate(); //this->terminate(); // It's dangerous to forcibly stop, but we will clean up the files qDebug() << "BtInstallThread::slotStopInstall 2"; //qApp->processEvents(); // wait to terminate for some secs. We rather let the execution go on and cleaning up to fail than the app to freeze int notRun = this->wait(200); if (notRun) { this->terminate(); this->wait(2); qDebug() << "installthread ("<< m_module << ") terminated, delete m_iMgr"; delete m_iMgr; // this makes sure the ftp library will be cleaned up in the destroyer m_iMgr = 0; } qDebug() << "BtInstallThread::slotStopInstall 3"; // cleanup: remove the module, remove the temp files if (true) { qDebug() << "BtInstallThread::slotStopInstall 4"; // remove the installed module, just to be sure because mgr may // have been terminated when copying files removeModule(); removeTempFiles(); qDebug() << "BtInstallThread::slotStopInstall will emit installStopped..."; emit installStopped(m_module, m_source); } } }
static Box* createAndRunModule(BoxedString* name, const std::string& fn, const std::string& module_path) { BoxedModule* module = createModule(name, fn.c_str()); Box* b_path = boxString(module_path); BoxedList* path_list = new BoxedList(); listAppendInternal(path_list, b_path); static BoxedString* path_str = internStringImmortal("__path__"); module->setattr(path_str, path_list, NULL); AST_Module* ast = caching_parse_file(fn.c_str(), /* future_flags = */ 0); assert(ast); try { compileAndRunModule(ast, module); } catch (ExcInfo e) { removeModule(name); throw e; } Box* r = getSysModulesDict()->getOrNull(name); if (!r) raiseExcHelper(ImportError, "Loaded module %.200s not found in sys.modules", name->c_str()); return r; }
void BtInstallThread::run() { qDebug() << "BtInstallThread::run, mod:" << m_module << "src:" << m_source << "dest:" << m_destination; emit preparingInstall(m_module, m_source); //make sure target/mods.d and target/modules exist QDir dir(m_destination); if (!dir.exists()) { dir.mkdir(m_destination); qDebug() << "made directory" << m_destination; } if (!dir.exists("modules")) { dir.mkdir("modules"); qDebug() << "made directory" << m_destination << "/modules"; } if (!dir.exists("mods.d")) { dir.mkdir("mods.d"); qDebug() << "made directory" << m_destination << "/mods.d"; } QObject::connect(&m_iMgr, SIGNAL(percentCompleted(int, int)), this, SLOT(slotManagerStatusUpdated(int, int))); QObject::connect(&m_iMgr, SIGNAL(downloadStarted()), this, SLOT(slotDownloadStarted())); //check whether it's an update. If yes, remove existing module first //TODO: silently removing without undo if the user cancels the update is WRONG!!! removeModule(); // manager for the destination path sword::SWMgr lMgr( m_destination.toLatin1() ); if (instbackend::isRemote(m_installSource)) { qDebug() << "calling install"; int status = m_iMgr.installModule(&lMgr, 0, m_module.toLatin1(), &m_installSource); if (status != 0) { qWarning() << "Error with install: " << status << "module:" << m_module; } else { done = true; emit installCompleted(m_module, m_source, status); } } else { //local source emit statusUpdated(m_module, 0); int status = m_iMgr.installModule(&lMgr, m_installSource.directory.c_str(), m_module.toLatin1()); if (status > 0) { qWarning() << "Error with install: " << status << "module:" << m_module; } else if (status == -1) { // it was terminated, do nothing } else { emit statusUpdated(m_module, 100); done = true; emit installCompleted(m_module, m_source, status); } } }
/*! \brief Remove the selected entity node */ void EntitiesTreeWidget::onRemove() { QTreeWidgetItem *item = currentItem(); if(!item){ return; } if(QMessageBox::question(this,"Removing","Are you sure to remove this item?") == QMessageBox::Yes){ if(item->parent() == applicationNode){ if(item->data(0,Qt::UserRole) == yarp::manager::APPLICATION){ yarp::manager::Application *app = (yarp::manager::Application*)item->data(0,Qt::UserRole + 1).toLongLong(); if(app){ QString appName = item->text(0); removeApplication(appName); } } }else if(item->parent() == resourcesNode){ if(item->data(0,Qt::UserRole) == yarp::manager::RESOURCE){ yarp::manager::Computer *res = (yarp::manager::Computer*)item->data(0,Qt::UserRole + 1).toLongLong(); if(res){ QString resName = item->text(0); removeResource(resName); } } }else if(item->parent() == modulesNode){ if(item->data(0,Qt::UserRole) == yarp::manager::MODULE){ yarp::manager::Module *mod = (yarp::manager::Module*)item->data(0,Qt::UserRole + 1).toLongLong(); if(mod){ QString modName = item->text(0); removeModule(modName); } } } while(item->childCount()>0){ delete item->takeChild(0); } if(item->parent()){ int index = item->parent()->indexOfChild(item); delete item->parent()->takeChild(index); } } }
void mitk::ConnectomicsSimulatedAnnealingPermutationModularity::CleanUp() { // delete empty modules, if any for( int loop( 0 ); loop < getNumberOfModules( &m_BestSolution ) ; loop++ ) { if( getNumberOfVerticesInModule( &m_BestSolution, loop ) < 1 ) { removeModule( &m_BestSolution, loop ); } } }
void PinkEngine::initModule(const Common::String &moduleName, const Common::String &pageName, Archive *saveFile) { if (_module) removeModule(); addModule(moduleName); if (saveFile) _module->loadState(*saveFile); debugC(6, kPinkDebugGeneral, "Module added"); _module->init(saveFile ? kLoadingSave : kLoadingNewGame, pageName); }
ICQMain::~ICQMain() { destroyThreads(); for (int i = 0; i < MAX_NUM_MODULES; i++) { if (modules[i]) removeModule(i); } delete c2s; delete sessionHash; delete logger; }
moduleDialog::moduleDialog(QWidget *parent) : QDialog(parent), ui(new Ui::moduleDialog) { ui->setupUi(this); connect(ui->addModuleButton,SIGNAL(clicked()),this,SLOT(addModule())); connect(ui->removeModuleButton,SIGNAL(clicked()),this,SLOT(removeModule())); connect(ui->moduleListView,SIGNAL(clicked(QModelIndex)),this,SLOT(updateModInfo(QModelIndex))); connect(ui->addChannelToModButton,SIGNAL(clicked()),this,SLOT(addChannelToMod())); connect(ui->removeChannelFromModChannel,SIGNAL(clicked()),this,SLOT(removeChannelFromMod())); connect(ui->moveChannelUpButton,SIGNAL(clicked()),this,SLOT(moveModChannelUp())); connect(ui->moveChannelDownButton,SIGNAL(clicked()),this,SLOT(moveModChannelDown())); connect(ui->idApplyButton,SIGNAL(clicked()),this,SLOT(applyModID())); connect(ui->doneButton,SIGNAL(clicked()),this,SLOT(close())); numberOfChannels=0; }
Box* createAndRunModule(BoxedString* name, const std::string& fn) { BoxedModule* module = createModule(name, fn.c_str()); AST_Module* ast = caching_parse_file(fn.c_str(), /* future_flags = */ 0); assert(ast); try { compileAndRunModule(ast, module); } catch (ExcInfo e) { removeModule(name); throw e; } Box* r = getSysModulesDict()->getOrNull(name); if (!r) raiseExcHelper(ImportError, "Loaded module %.200s not found in sys.modules", name->c_str()); return r; }
static Box* importSub(const std::string& name, BoxedString* full_name, Box* parent_module) { BoxedDict* sys_modules = getSysModulesDict(); if (sys_modules->d.find(full_name) != sys_modules->d.end()) { return sys_modules->d[full_name]; } BoxedList* path_list; if (parent_module == NULL || parent_module == None) { path_list = NULL; } else { static BoxedString* path_str = internStringImmortal("__path__"); path_list = static_cast<BoxedList*>(getattrInternal<ExceptionStyle::CXX>(parent_module, path_str)); if (path_list == NULL || path_list->cls != list_cls) { return None; } } SearchResult sr = findModule(name, full_name, path_list); if (sr.type != SearchResult::SEARCH_ERROR) { Box* module; try { if (sr.type == SearchResult::PY_SOURCE) module = createAndRunModule(full_name, sr.path); else if (sr.type == SearchResult::PKG_DIRECTORY) module = createAndRunModule(full_name, sr.path + "/__init__.py", sr.path); else if (sr.type == SearchResult::C_EXTENSION) module = importCExtension(full_name, name, sr.path); else if (sr.type == SearchResult::IMP_HOOK) { static BoxedString* loadmodule_str = internStringImmortal("load_module"); CallattrFlags callattr_flags{.cls_only = false, .null_on_nonexistent = false, .argspec = ArgPassSpec(1) }; module = callattr(sr.loader, loadmodule_str, callattr_flags, full_name, NULL, NULL, NULL, NULL); } else RELEASE_ASSERT(0, "%d", sr.type); } catch (ExcInfo e) { removeModule(full_name); throw e; } if (parent_module && parent_module != None) parent_module->setattr(internStringMortal(name), module, NULL); return module; }
void mitk::ConnectomicsSimulatedAnnealingPermutationModularity::permutateMappingModuleChange( ToModuleMapType *vertexToModuleMap, double currentTemperature, mitk::ConnectomicsNetwork::Pointer network ) { //the random number generators vnl_random rng( (unsigned int) rand() ); //randomly generate threshold const double threshold = rng.drand64( 0.0 , 1.0); //for deciding whether to join two modules or split one double splitThreshold = 0.5; //stores whether to join or two split bool joinModules( false ); //select random module int numberOfModules = getNumberOfModules( vertexToModuleMap ); unsigned long randomModuleA = rng.lrand32( numberOfModules - 1 ); //select the second module to join, if joining unsigned long randomModuleB = rng.lrand32( numberOfModules - 1 ); if( ( threshold < splitThreshold ) && ( randomModuleA != randomModuleB ) ) { joinModules = true; } if( joinModules ) { // this being an kommutative operation, we will always join B to A joinTwoModules( vertexToModuleMap, randomModuleA, randomModuleB ); //eliminate the empty module removeModule( vertexToModuleMap, randomModuleB ); } else { //split module splitModule( vertexToModuleMap, currentTemperature, network, randomModuleA ); } }
void mitk::ConnectomicsSimulatedAnnealingPermutationModularity::permutateMappingSingleNodeShift( ToModuleMapType *vertexToModuleMap, mitk::ConnectomicsNetwork::Pointer network ) { const int nodeCount = vertexToModuleMap->size(); const int moduleCount = getNumberOfModules( vertexToModuleMap ); // the random number generators vnl_random rng( (unsigned int) rand() ); unsigned long randomNode = rng.lrand32( nodeCount - 1 ); // move the node either to any existing module, or to its own //unsigned long randomModule = rng.lrand32( moduleCount ); unsigned long randomModule = rng.lrand32( moduleCount - 1 ); // do some sanity checks if ( nodeCount < 2 ) { // no sense in doing anything return; } const std::vector< VertexDescriptorType > allNodesVector = network->GetVectorOfAllVertexDescriptors(); ToModuleMapType::iterator iter = vertexToModuleMap->find( allNodesVector[ randomNode ] ); const int previousModuleNumber = iter->second; // if we move the node to its own module, do nothing if( previousModuleNumber == (long)randomModule ) { return; } iter->second = randomModule; if( getNumberOfVerticesInModule( vertexToModuleMap, previousModuleNumber ) < 1 ) { removeModule( vertexToModuleMap, previousModuleNumber ); } }
void mitk::ConnectomicsSimulatedAnnealingPermutationModularity::splitModule( ToModuleMapType *vertexToModuleMap, double currentTemperature, mitk::ConnectomicsNetwork::Pointer network, int moduleToSplit ) { if( m_Depth == 0 ) { // do nothing return; } // if the module contains only one node, no more division is sensible if( getNumberOfVerticesInModule( vertexToModuleMap, moduleToSplit ) < 2 ) { // do nothing return; } // create subgraph of the module, that is to be splitted mitk::ConnectomicsNetwork::Pointer subNetwork = mitk::ConnectomicsNetwork::New(); VertexToVertexMapType graphToSubgraphVertexMap; VertexToVertexMapType subgraphToGraphVertexMap; extractModuleSubgraph( vertexToModuleMap, network, moduleToSplit, subNetwork, &graphToSubgraphVertexMap, &subgraphToGraphVertexMap ); // The submap ToModuleMapType vertexToModuleSubMap; // run simulated annealing on the subgraph to determine how the module should be split if( m_Depth > 0 && m_StepSize > 0 ) { mitk::ConnectomicsSimulatedAnnealingManager::Pointer manager = mitk::ConnectomicsSimulatedAnnealingManager::New(); mitk::ConnectomicsSimulatedAnnealingPermutationModularity::Pointer permutation = mitk::ConnectomicsSimulatedAnnealingPermutationModularity::New(); mitk::ConnectomicsSimulatedAnnealingCostFunctionModularity::Pointer costFunction = mitk::ConnectomicsSimulatedAnnealingCostFunctionModularity::New(); permutation->SetCostFunction( costFunction.GetPointer() ); permutation->SetNetwork( subNetwork ); permutation->SetDepth( m_Depth - 1 ); permutation->SetStepSize( m_StepSize * 2 ); manager->SetPermutation( permutation.GetPointer() ); manager->RunSimulatedAnnealing( currentTemperature, m_StepSize * 2 ); vertexToModuleSubMap = permutation->GetMapping(); } // now carry the information over to the original map std::vector< int > moduleTranslationVector; moduleTranslationVector.resize( getNumberOfModules( &vertexToModuleSubMap ), 0 ); int originalNumber = getNumberOfModules( vertexToModuleMap ); // the new parts are added at the end for(unsigned int index( 0 ); index < moduleTranslationVector.size() ; index++) { moduleTranslationVector[ index ] = originalNumber + index; } ToModuleMapType::iterator iter2 = vertexToModuleSubMap.begin(); ToModuleMapType::iterator end2 = vertexToModuleSubMap.end(); while( iter2 != end2 ) { // translate vertex descriptor from subgraph to graph VertexDescriptorType key = subgraphToGraphVertexMap.find( iter2->first )->second; // translate module number from subgraph to graph int value = moduleTranslationVector[ iter2->second ]; // change the corresponding entry vertexToModuleMap->find( key )->second = value; iter2++; } // remove the now empty module, that was splitted removeModule( vertexToModuleMap, moduleToSplit ); }