void ThreadQueue::run(void) { data_t *prev; started = true; for(;;) { Semaphore::wait(); if(!started) sleep((timeout_t)~0); startQueue(); while(first) { runQueue(first->data); enterMutex(); prev = first; first = first->next; delete[] prev; if(!first) last = NULL; leaveMutex(); if(first) Semaphore::wait(); // demark semaphore } stopQueue(); } }
void Worker::start() { if (m_currentState == StoppedState) { startQueue(); } else if (m_currentState == PausedState) { resumeQueue(); } m_currentState = RunningState; emit currentStateChanged(m_currentState); }
void AMWorkflowManagerView::insertBeamlineAction(int index, AMBeamlineActionItem *action, bool startNow) { if(index < 0 || index > workflowQueue_->count()) { index = workflowQueue_->count(); } if(workflowQueue_->isEmpty()) workflowActions_->appendAction(action); else workflowActions_->addAction(workflowQueue_->indexOfHead()+index, action); if(startNow) startQueue(); }
/** * \brief Slot to handle toolbar actions * * This is just a dispatcher method that calls the appropriate acction * handler slot. */ void TaskMainWindow::handleToolbarAction(QAction *action) { debug(LOG_DEBUG, DEBUG_LOG, 0, "toolbar action called"); if (action == ui->actionStartQueue) { startQueue(); return; } if (action == ui->actionStopQueue) { stopQueue(); return; } if (action == ui->actionDelete) { deleteSelected(); return; } if (action == ui->actionDownload) { downloadSelected(); return; } }
AMWorkflowManagerView::AMWorkflowManagerView(QWidget *parent) : QWidget(parent) { currentSamplePlate_ = 0;//NULL samplePlateModel_ = 0;//NULL addActionMenu_ = 0;//NULL samplePlateAddActionMenu_ = 0;//NULL fiducializationMarkAddActionMenu_ = 0;//NULL samplePlateHoverIndex_ = 0; fiducializationMarkHoverIndex_ = 0; topFrame_ = new AMTopFrame("Workflow"); topFrame_->setIcon(QIcon(":/user-away.png")); startWorkflowButton_ = new QPushButton("Start This Workflow\nReady"); startWorkflowButton_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); addActionButton_ = new QPushButton("Add an Action"); addActionButton_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); QHBoxLayout *hl = new QHBoxLayout(); hl->addItem(new QSpacerItem(10, 10, QSizePolicy::MinimumExpanding, QSizePolicy::Preferred)); hl->addWidget(addActionButton_, 0, Qt::AlignRight); hl->addWidget(startWorkflowButton_, 0, Qt::AlignRight); connect(startWorkflowButton_, SIGNAL(clicked()), this, SLOT(startQueue())); connect(addActionButton_, SIGNAL(clicked()), this, SLOT(onAddActionButtonClicked())); workflowActions_ = new AMBeamlineActionsList(this); workflowQueue_ = new AMBeamlineActionsQueue(workflowActions_, this); workflowView_ = new AMBeamlineActionsListView(workflowActions_, workflowQueue_, this); connect(workflowView_, SIGNAL(copyRequested(AMBeamlineActionItem*)), this, SLOT(onCopyActionRequested(AMBeamlineActionItem*))); connect(workflowView_, SIGNAL(moveUpRequested(AMBeamlineActionItem*)), this, SLOT(onMoveUpActionRequested(AMBeamlineActionItem*))); connect(workflowView_, SIGNAL(moveDownRequested(AMBeamlineActionItem*)), this, SLOT(onMoveDownActionRequested(AMBeamlineActionItem*))); QScrollArea* scrollArea = new QScrollArea(); scrollArea->setWidget(workflowView_); scrollArea->setWidgetResizable(true); /// \bug Github issue GH-193: reviewWorkflowStatus() is never called, because the beamline may not be initiated yet here. Removing the connection, since in this case it was doing nothing anyways. // Removed: connect(AMBeamline::bl(), SIGNAL(beamlineScanningChanged(bool)), this, SLOT(reviewWorkflowStatus())); connect(workflowQueue_, SIGNAL(isRunningChanged(bool)), this, SLOT(reviewWorkflowStatus())); connect(workflowQueue_, SIGNAL(isEmptyChanged(bool)), this, SLOT(reviewWorkflowStatus())); // removed with adder: connect(workflowView_, SIGNAL(queueUpdated(int)), adder_, SLOT(onQueueUpdated(int))); // Darren added this. connect(workflowQueue_, SIGNAL(headChanged()), this, SIGNAL(headChanged())); // End of Darren's addition. vl_ = new QVBoxLayout(); vl_->addWidget(scrollArea); topFrame_->frameLayout()->addLayout(hl); QVBoxLayout *vl2 = new QVBoxLayout(); vl2->addWidget(topFrame_); vl2->addLayout(vl_); vl2->setContentsMargins(0,0,0,0); vl2->setSpacing(1); vl_->setContentsMargins(10, 5, 10, 10); vl_->setSpacing(5); hl->setContentsMargins(0, 2, 10, 2); hl->setSpacing(5); setLayout(vl2); }
Controller::Controller(const QString &filename, bool limited_mode, const QString &labelfile, QObject *parent) : QObject(parent), // initialize all pointers so we don't access them too early w/o notice im(nullptr), lm(nullptr), fm(nullptr), illumm(nullptr), gsm(nullptr), #ifdef WITH_SEG_MEANSHIFT cm(nullptr), #endif dvc(nullptr), queuethread(nullptr), subs(new Subscriptions) { // reset internal ROI state tracking resetROISpawned(); // start background task queue thread connect(&queue, SIGNAL(exception(std::exception_ptr, bool)), GerbilApplication::instance(), SLOT(handle_exception(std::exception_ptr,bool)), Qt::BlockingQueuedConnection); startQueue(); im = new ImageModel(queue, limited_mode, this); // load image cv::Rect dimensions = im->loadImage(filename); imgSize = cv::Size(dimensions.width, dimensions.height); // create gui (perform initUI before connecting signals!) window = new MainWindow(); window->initUI(filename); // initialize models initImage(); fm = new FalseColorModel(); initFalseColor(); // depends on ImageModel / initImage() // The order of connection is crucial for fm and Controller. // fm needs to get the signal first. Otherwise it will // hand out invalid cached data. connect(im, SIGNAL(imageUpdate(representation::t,SharedMultiImgPtr,bool)), fm, SLOT(processImageUpdate(representation::t,SharedMultiImgPtr,bool))); connect(im, SIGNAL(imageUpdate(representation::t,SharedMultiImgPtr,bool)), this, SLOT(processImageUpdate(representation::t,SharedMultiImgPtr,bool))); lm = new LabelingModel(this); initLabeling(dimensions); illumm = new IllumModel(&queue, this); initIlluminant(); gsm = new GraphSegmentationModel(&queue, this); initGraphSegmentation(); // depends on ImageModel / initImage() #ifdef WITH_SEG_MEANSHIFT cm = new ClusteringModel(this); #endif /* WITH_SEG_MEANSHIFT */ // initialize sub-controllers (after initializing the models...) dvc = new DistViewController(this, &queue, im); dvc->init(); // init dock widgets initDocks(); // connect slots/signals window->initSignals(this, dvc); /* TODO: better place. But do not use init model functions: * dvc are created after these are called */ connect(dvc, SIGNAL(requestOverlay(cv::Mat1b)), this, SIGNAL(requestOverlay(cv::Mat1b))); connect(lm, SIGNAL(newLabeling(const cv::Mat1s&, const QVector<QColor>&, bool)), dvc, SLOT(updateLabels(cv::Mat1s,QVector<QColor>,bool))); connect(lm, SIGNAL(partialLabelUpdate(const cv::Mat1s&,const cv::Mat1b&)), dvc, SLOT(updateLabelsPartially(const cv::Mat1s&,const cv::Mat1b&))); connect(dvc, SIGNAL(alterLabelRequested(short,cv::Mat1b,bool)), lm, SLOT(alterLabel(short,cv::Mat1b,bool))); connect(illumm, SIGNAL(newIlluminantCurve(QVector<multi_img::Value>)), dvc, SIGNAL(newIlluminantCurve(QVector<multi_img::Value>))); connect(illumm, SIGNAL(newIlluminantApplied(QVector<multi_img::Value>)), dvc, SIGNAL(newIlluminantApplied(QVector<multi_img::Value>))); #ifdef WITH_SEG_MEANSHIFT connect(cm, SIGNAL(subscribeRepresentation(QObject*,representation::t)), this, SLOT(subscribeRepresentation(QObject*,representation::t))); connect(cm, SIGNAL(unsubscribeRepresentation(QObject*,representation::t)), this, SLOT(unsubscribeRepresentation(QObject*,representation::t))); connect(im, SIGNAL(imageUpdate(representation::t,SharedMultiImgPtr,bool)), cm, SLOT(processImageUpdate(representation::t,SharedMultiImgPtr,bool))); #endif connect(this, SIGNAL(preROISpawn(cv::Rect,cv::Rect,std::vector<cv::Rect>,std::vector<cv::Rect>,bool)), dvc, SLOT(processPreROISpawn(cv::Rect,cv::Rect,std::vector<cv::Rect>,std::vector<cv::Rect>,bool))); connect(this, SIGNAL(postROISpawn(cv::Rect,cv::Rect,std::vector<cv::Rect>,std::vector<cv::Rect>,bool)), dvc, SLOT(processPostROISpawn(cv::Rect,cv::Rect,std::vector<cv::Rect>,std::vector<cv::Rect>,bool))); /* start with initial label or provided labeling * Do this after all signals are connected, and before initial ROI spawn! */ if (labelfile.isEmpty()) { lm->addLabel(); } else { lm->loadLabeling(labelfile); } /* Initial ROI images spawning. Do it before showing the window but after * all signals were connected! */ //GGDBGM("dimensions " << dimensions << endl); roi = dimensions; // initial ROI is image size, except: if (roi.area() > 262144) { // image is bigger than 512x512, start with a smaller ROI in center roi.width = std::min(roi.width, 512); roi.height = std::min(roi.height, 512); roi.x = 0.5*(dimensions.width - roi.width); roi.y = 0.5*(dimensions.height - roi.height); } GGDBGM("roi " << roi << endl); spawnROI(); // The IMG representation must always be subscribed. Otherwise all the logic // in ImageModel fails. So we subscribe the Controller forever. subscribeRepresentation(this, representation::IMG); GGDBGM("init distview subscriptions" << endl); dvc->initSubscriptions(); GGDBGM("init done, showing mainwindow" << endl); // we're done! show window window->show(); }
void MasterTimer::timerTickFunctions(QList<Universe *> universes) { // List of m_functionList indices that should be removed at the end of this // function. The functions at the indices have been stopped. QList<int> removeList; bool functionListHasChanged = false; bool stoppedAFunction = true; bool firstIteration = true; while (stoppedAFunction) { stoppedAFunction = false; removeList.clear(); for (int i = 0; i < m_functionList.size(); i++) { Function* function = m_functionList.at(i); if (function != NULL) { /* Run the function unless it's supposed to be stopped */ if (function->stopped() == false && m_stopAllFunctions == false) { if (firstIteration) function->write(this, universes); } else { // Clear function's parentList if (m_stopAllFunctions) function->stop(FunctionParent::master()); /* Function should be stopped instead */ function->postRun(this, universes); //qDebug() << "[MasterTimer] Add function (ID: " << function->id() << ") to remove list "; removeList << i; // Don't remove the item from the list just yet. functionListHasChanged = true; stoppedAFunction = true; } } } // Remove functions that need to be removed AFTER all functions have been run // for this round. This is done separately to prevent a case when a function // is first removed and then another is added (chaser, for example), keeping the // list's size the same, thus preventing the last added function from being run // on this round. The indices in removeList are automatically sorted because the // list is iterated with an int above from 0 to size, so iterating the removeList // backwards here will always remove the correct indices. QListIterator <int> it(removeList); it.toBack(); while (it.hasPrevious() == true) m_functionList.removeAt(it.previous()); firstIteration = false; } m_functionListMutex.lock(); while (m_startQueue.size() > 0) { QList<Function*> startQueue(m_startQueue); m_startQueue.clear(); m_functionListMutex.unlock(); foreach (Function* f, startQueue) { if (m_functionList.contains(f)) { f->postRun(this, universes); } else { m_functionList.append(f); functionListHasChanged = true; } f->preRun(this); f->write(this, universes); emit functionStarted(f->id()); } m_functionListMutex.lock(); } m_functionListMutex.unlock(); if (functionListHasChanged) emit functionListChanged(); }