Introducing a way to abort a task from one of its job, using it to skip highlight tasks if nothing to highlight

This commit is contained in:
samcake 2018-02-14 17:36:46 -08:00
parent 33690e09b7
commit 246ac25d0a
3 changed files with 55 additions and 4 deletions

View file

@ -453,6 +453,10 @@ void SelectionToHighlight::run(const render::RenderContextPointer& renderContext
}
}
}
if (numLayers == 0) {
renderContext->abortTask();
}
}
void ExtractSelectionName::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) {

View file

@ -0,0 +1,35 @@
//
// Task.cpp
// task/src/task
//
// Created by Sam Gateau on 2/14/2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Task.h"
using namespace task;
JobContext::JobContext(const QLoggingCategory& category) :
profileCategory(category) {
assert(&category);
}
JobContext::~JobContext() {
}
void JobContext::resetTaskFlow() {
_doAbortTask = false;
}
void JobContext::abortTask() {
_doAbortTask = true;
}
bool JobContext::doAbortTask() const {
return _doAbortTask;
}

View file

@ -29,13 +29,21 @@ class JobNoIO {};
class JobContext {
public:
JobContext(const QLoggingCategory& category) : profileCategory(category) {
assert(&category);
}
virtual ~JobContext() {}
JobContext(const QLoggingCategory& category);
virtual ~JobContext();
std::shared_ptr<JobConfig> jobConfig { nullptr };
const QLoggingCategory& profileCategory;
// control flow commands
void resetTaskFlow();
void abortTask();
// Check command flow
bool doAbortTask() const;
protected:
bool _doAbortTask{ false };
};
using JobContextPointer = std::shared_ptr<JobContext>;
@ -308,6 +316,10 @@ public:
if (config->alwaysEnabled || config->enabled) {
for (auto job : TaskConcept::_jobs) {
job.run(jobContext);
if (jobContext->doAbortTask()) {
jobContext->resetTaskFlow();
return;
}
}
}
}