forked from qt-creator/qt-creator
TaskItem: Move enums outside of TaskItem
Change-Id: If8a2b285bf9d9bd5a5b7222c13772c1a873daf23 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -9,13 +9,13 @@
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
namespace Tasking {
|
namespace Tasking {
|
||||||
|
|
||||||
ExecuteInSequence sequential;
|
Execute sequential(ExecuteMode::Sequential);
|
||||||
ExecuteInParallel parallel;
|
Execute parallel(ExecuteMode::Parallel);
|
||||||
WorkflowPolicy stopOnError(TaskItem::WorkflowPolicy::StopOnError);
|
Workflow stopOnError(WorkflowPolicy::StopOnError);
|
||||||
WorkflowPolicy continueOnError(TaskItem::WorkflowPolicy::ContinueOnError);
|
Workflow continueOnError(WorkflowPolicy::ContinueOnError);
|
||||||
WorkflowPolicy stopOnDone(TaskItem::WorkflowPolicy::StopOnDone);
|
Workflow stopOnDone(WorkflowPolicy::StopOnDone);
|
||||||
WorkflowPolicy continueOnDone(TaskItem::WorkflowPolicy::ContinueOnDone);
|
Workflow continueOnDone(WorkflowPolicy::ContinueOnDone);
|
||||||
WorkflowPolicy optional(TaskItem::WorkflowPolicy::Optional);
|
Workflow optional(WorkflowPolicy::Optional);
|
||||||
|
|
||||||
void TaskItem::addChildren(const QList<TaskItem> &children)
|
void TaskItem::addChildren(const QList<TaskItem> &children)
|
||||||
{
|
{
|
||||||
@@ -95,8 +95,8 @@ public:
|
|||||||
|
|
||||||
TaskTreePrivate *m_taskTreePrivate = nullptr;
|
TaskTreePrivate *m_taskTreePrivate = nullptr;
|
||||||
TaskContainer *m_parentContainer = nullptr;
|
TaskContainer *m_parentContainer = nullptr;
|
||||||
const TaskItem::ExecuteMode m_executeMode = TaskItem::ExecuteMode::Parallel;
|
const ExecuteMode m_executeMode = ExecuteMode::Parallel;
|
||||||
TaskItem::WorkflowPolicy m_workflowPolicy = TaskItem::WorkflowPolicy::StopOnError;
|
WorkflowPolicy m_workflowPolicy = WorkflowPolicy::StopOnError;
|
||||||
const TaskItem::GroupHandler m_groupHandler;
|
const TaskItem::GroupHandler m_groupHandler;
|
||||||
int m_taskCount = 0;
|
int m_taskCount = 0;
|
||||||
GroupConfig m_groupConfig;
|
GroupConfig m_groupConfig;
|
||||||
@@ -241,7 +241,7 @@ void TaskContainer::start()
|
|||||||
m_currentIndex = 0;
|
m_currentIndex = 0;
|
||||||
resetSuccessBit();
|
resetSuccessBit();
|
||||||
|
|
||||||
if (m_executeMode == TaskItem::ExecuteMode::Sequential) {
|
if (m_executeMode == ExecuteMode::Sequential) {
|
||||||
m_selectedChildren.at(m_currentIndex)->start();
|
m_selectedChildren.at(m_currentIndex)->start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ void TaskContainer::stop()
|
|||||||
if (!isRunning())
|
if (!isRunning())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_executeMode == TaskItem::ExecuteMode::Sequential) {
|
if (m_executeMode == ExecuteMode::Sequential) {
|
||||||
int skippedTaskCount = 0;
|
int skippedTaskCount = 0;
|
||||||
for (int i = m_currentIndex + 1; i < m_selectedChildren.size(); ++i)
|
for (int i = m_currentIndex + 1; i < m_selectedChildren.size(); ++i)
|
||||||
skippedTaskCount += m_selectedChildren.at(i)->taskCount();
|
skippedTaskCount += m_selectedChildren.at(i)->taskCount();
|
||||||
@@ -299,8 +299,8 @@ int TaskContainer::taskCount() const
|
|||||||
|
|
||||||
void TaskContainer::childDone(bool success)
|
void TaskContainer::childDone(bool success)
|
||||||
{
|
{
|
||||||
if ((m_workflowPolicy == TaskItem::WorkflowPolicy::StopOnDone && success)
|
if ((m_workflowPolicy == WorkflowPolicy::StopOnDone && success)
|
||||||
|| (m_workflowPolicy == TaskItem::WorkflowPolicy::StopOnError && !success)) {
|
|| (m_workflowPolicy == WorkflowPolicy::StopOnError && !success)) {
|
||||||
stop();
|
stop();
|
||||||
invokeEndHandler(success);
|
invokeEndHandler(success);
|
||||||
return;
|
return;
|
||||||
@@ -314,7 +314,7 @@ void TaskContainer::childDone(bool success)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_executeMode == TaskItem::ExecuteMode::Sequential)
|
if (m_executeMode == ExecuteMode::Sequential)
|
||||||
m_selectedChildren.at(m_currentIndex)->start();
|
m_selectedChildren.at(m_currentIndex)->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,8 +348,8 @@ void TaskContainer::resetSuccessBit()
|
|||||||
if (m_selectedChildren.isEmpty())
|
if (m_selectedChildren.isEmpty())
|
||||||
m_successBit = true;
|
m_successBit = true;
|
||||||
|
|
||||||
if (m_workflowPolicy == TaskItem::WorkflowPolicy::StopOnDone
|
if (m_workflowPolicy == WorkflowPolicy::StopOnDone
|
||||||
|| m_workflowPolicy == TaskItem::WorkflowPolicy::ContinueOnDone) {
|
|| m_workflowPolicy == WorkflowPolicy::ContinueOnDone) {
|
||||||
m_successBit = false;
|
m_successBit = false;
|
||||||
} else {
|
} else {
|
||||||
m_successBit = true;
|
m_successBit = true;
|
||||||
@@ -358,10 +358,10 @@ void TaskContainer::resetSuccessBit()
|
|||||||
|
|
||||||
void TaskContainer::updateSuccessBit(bool success)
|
void TaskContainer::updateSuccessBit(bool success)
|
||||||
{
|
{
|
||||||
if (m_workflowPolicy == TaskItem::WorkflowPolicy::Optional)
|
if (m_workflowPolicy == WorkflowPolicy::Optional)
|
||||||
return;
|
return;
|
||||||
if (m_workflowPolicy == TaskItem::WorkflowPolicy::StopOnDone
|
if (m_workflowPolicy == WorkflowPolicy::StopOnDone
|
||||||
|| m_workflowPolicy == TaskItem::WorkflowPolicy::ContinueOnDone) {
|
|| m_workflowPolicy == WorkflowPolicy::ContinueOnDone) {
|
||||||
m_successBit = m_successBit || success;
|
m_successBit = m_successBit || success;
|
||||||
} else {
|
} else {
|
||||||
m_successBit = m_successBit && success;
|
m_successBit = m_successBit && success;
|
||||||
|
|||||||
@@ -23,6 +23,27 @@ signals:
|
|||||||
void done(bool success);
|
void done(bool success);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ExecuteMode {
|
||||||
|
Sequential, // default
|
||||||
|
Parallel
|
||||||
|
};
|
||||||
|
|
||||||
|
// 4 policies:
|
||||||
|
// 1. When all children finished with done -> report done, otherwise:
|
||||||
|
// a) Report error on first error and stop executing other children (including their subtree)
|
||||||
|
// b) On first error - wait for all children to be finished and report error afterwards
|
||||||
|
// 2. When all children finished with error -> report error, otherwise:
|
||||||
|
// a) Report done on first done and stop executing other children (including their subtree)
|
||||||
|
// b) On first done - wait for all children to be finished and report done afterwards
|
||||||
|
|
||||||
|
enum class WorkflowPolicy {
|
||||||
|
StopOnError, // 1a - Will report error on any child error, otherwise done (if all children were done)
|
||||||
|
ContinueOnError, // 1b - the same. When no children it reports done.
|
||||||
|
StopOnDone, // 2a - Will report done on any child done, otherwise error (if all children were error)
|
||||||
|
ContinueOnDone, // 2b - the same. When no children it reports done. (?)
|
||||||
|
Optional // Returns always done after all children finished
|
||||||
|
};
|
||||||
|
|
||||||
enum class GroupAction
|
enum class GroupAction
|
||||||
{
|
{
|
||||||
ContinueAll,
|
ContinueAll,
|
||||||
@@ -68,27 +89,6 @@ public:
|
|||||||
GroupSetupHandler m_dynamicSetupHandler = {};
|
GroupSetupHandler m_dynamicSetupHandler = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ExecuteMode {
|
|
||||||
Parallel, // default
|
|
||||||
Sequential
|
|
||||||
};
|
|
||||||
|
|
||||||
// 4 policies:
|
|
||||||
// 1. When all children finished with done -> report done, otherwise:
|
|
||||||
// a) Report error on first error and stop executing other children (including their subtree)
|
|
||||||
// b) On first error - wait for all children to be finished and report error afterwards
|
|
||||||
// 2. When all children finished with error -> report error, otherwise:
|
|
||||||
// a) Report done on first done and stop executing other children (including their subtree)
|
|
||||||
// b) On first done - wait for all children to be finished and report done afterwards
|
|
||||||
|
|
||||||
enum class WorkflowPolicy {
|
|
||||||
StopOnError, // 1a - Will report error on any child error, otherwise done (if all children were done)
|
|
||||||
ContinueOnError, // 1b - the same. When no children it reports done.
|
|
||||||
StopOnDone, // 2a - Will report done on any child done, otherwise error (if all children were error)
|
|
||||||
ContinueOnDone, // 2b - the same. When no children it reports done. (?)
|
|
||||||
Optional // Returns always done after all children finished
|
|
||||||
};
|
|
||||||
|
|
||||||
ExecuteMode executeMode() const { return m_executeMode; }
|
ExecuteMode executeMode() const { return m_executeMode; }
|
||||||
WorkflowPolicy workflowPolicy() const { return m_workflowPolicy; }
|
WorkflowPolicy workflowPolicy() const { return m_workflowPolicy; }
|
||||||
TaskHandler taskHandler() const { return m_taskHandler; }
|
TaskHandler taskHandler() const { return m_taskHandler; }
|
||||||
@@ -136,22 +136,16 @@ public:
|
|||||||
Group(std::initializer_list<TaskItem> children) { addChildren(children); }
|
Group(std::initializer_list<TaskItem> children) { addChildren(children); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT ExecuteInSequence : public TaskItem
|
class QTCREATOR_UTILS_EXPORT Execute : public TaskItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExecuteInSequence() : TaskItem(ExecuteMode::Sequential) {}
|
Execute(ExecuteMode mode) : TaskItem(mode) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT ExecuteInParallel : public TaskItem
|
class QTCREATOR_UTILS_EXPORT Workflow : public TaskItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExecuteInParallel() : TaskItem(ExecuteMode::Parallel) {}
|
Workflow(WorkflowPolicy policy) : TaskItem(policy) {}
|
||||||
};
|
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT WorkflowPolicy : public TaskItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
WorkflowPolicy(TaskItem::WorkflowPolicy policy) : TaskItem(policy) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT OnGroupSetup : public TaskItem
|
class QTCREATOR_UTILS_EXPORT OnGroupSetup : public TaskItem
|
||||||
@@ -178,14 +172,13 @@ public:
|
|||||||
DynamicSetup(const GroupSetupHandler &handler) : TaskItem({{}, {}, {}, handler}) {}
|
DynamicSetup(const GroupSetupHandler &handler) : TaskItem({{}, {}, {}, handler}) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QTCREATOR_UTILS_EXPORT extern Execute sequential;
|
||||||
QTCREATOR_UTILS_EXPORT extern ExecuteInSequence sequential;
|
QTCREATOR_UTILS_EXPORT extern Execute parallel;
|
||||||
QTCREATOR_UTILS_EXPORT extern ExecuteInParallel parallel;
|
QTCREATOR_UTILS_EXPORT extern Workflow stopOnError;
|
||||||
QTCREATOR_UTILS_EXPORT extern WorkflowPolicy stopOnError;
|
QTCREATOR_UTILS_EXPORT extern Workflow continueOnError;
|
||||||
QTCREATOR_UTILS_EXPORT extern WorkflowPolicy continueOnError;
|
QTCREATOR_UTILS_EXPORT extern Workflow stopOnDone;
|
||||||
QTCREATOR_UTILS_EXPORT extern WorkflowPolicy stopOnDone;
|
QTCREATOR_UTILS_EXPORT extern Workflow continueOnDone;
|
||||||
QTCREATOR_UTILS_EXPORT extern WorkflowPolicy continueOnDone;
|
QTCREATOR_UTILS_EXPORT extern Workflow optional;
|
||||||
QTCREATOR_UTILS_EXPORT extern WorkflowPolicy optional;
|
|
||||||
|
|
||||||
template <typename Task>
|
template <typename Task>
|
||||||
class TaskAdapter : public TaskInterface
|
class TaskAdapter : public TaskInterface
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ void tst_TaskTree::processTree_data()
|
|||||||
QTest::newRow("SequentialError") << sequentialErrorRoot << sequentialErrorLog
|
QTest::newRow("SequentialError") << sequentialErrorRoot << sequentialErrorLog
|
||||||
<< true << false << 5;
|
<< true << false << 5;
|
||||||
|
|
||||||
const auto constructSimpleSequence = [=](const WorkflowPolicy &policy) {
|
const auto constructSimpleSequence = [=](const Workflow &policy) {
|
||||||
return Group {
|
return Group {
|
||||||
policy,
|
policy,
|
||||||
Process(std::bind(setupProcess, _1, 1), readResult),
|
Process(std::bind(setupProcess, _1, 1), readResult),
|
||||||
|
|||||||
Reference in New Issue
Block a user