diff --git a/src/libs/utils/tasktree.cpp b/src/libs/utils/tasktree.cpp index 1aa66929c9b..0a47f156455 100644 --- a/src/libs/utils/tasktree.cpp +++ b/src/libs/utils/tasktree.cpp @@ -9,13 +9,13 @@ namespace Utils { namespace Tasking { -ExecuteInSequence sequential; -ExecuteInParallel parallel; -WorkflowPolicy stopOnError(TaskItem::WorkflowPolicy::StopOnError); -WorkflowPolicy continueOnError(TaskItem::WorkflowPolicy::ContinueOnError); -WorkflowPolicy stopOnDone(TaskItem::WorkflowPolicy::StopOnDone); -WorkflowPolicy continueOnDone(TaskItem::WorkflowPolicy::ContinueOnDone); -WorkflowPolicy optional(TaskItem::WorkflowPolicy::Optional); +Execute sequential(ExecuteMode::Sequential); +Execute parallel(ExecuteMode::Parallel); +Workflow stopOnError(WorkflowPolicy::StopOnError); +Workflow continueOnError(WorkflowPolicy::ContinueOnError); +Workflow stopOnDone(WorkflowPolicy::StopOnDone); +Workflow continueOnDone(WorkflowPolicy::ContinueOnDone); +Workflow optional(WorkflowPolicy::Optional); void TaskItem::addChildren(const QList &children) { @@ -95,8 +95,8 @@ public: TaskTreePrivate *m_taskTreePrivate = nullptr; TaskContainer *m_parentContainer = nullptr; - const TaskItem::ExecuteMode m_executeMode = TaskItem::ExecuteMode::Parallel; - TaskItem::WorkflowPolicy m_workflowPolicy = TaskItem::WorkflowPolicy::StopOnError; + const ExecuteMode m_executeMode = ExecuteMode::Parallel; + WorkflowPolicy m_workflowPolicy = WorkflowPolicy::StopOnError; const TaskItem::GroupHandler m_groupHandler; int m_taskCount = 0; GroupConfig m_groupConfig; @@ -241,7 +241,7 @@ void TaskContainer::start() m_currentIndex = 0; resetSuccessBit(); - if (m_executeMode == TaskItem::ExecuteMode::Sequential) { + if (m_executeMode == ExecuteMode::Sequential) { m_selectedChildren.at(m_currentIndex)->start(); return; } @@ -275,7 +275,7 @@ void TaskContainer::stop() if (!isRunning()) return; - if (m_executeMode == TaskItem::ExecuteMode::Sequential) { + if (m_executeMode == ExecuteMode::Sequential) { int skippedTaskCount = 0; for (int i = m_currentIndex + 1; i < m_selectedChildren.size(); ++i) skippedTaskCount += m_selectedChildren.at(i)->taskCount(); @@ -299,8 +299,8 @@ int TaskContainer::taskCount() const void TaskContainer::childDone(bool success) { - if ((m_workflowPolicy == TaskItem::WorkflowPolicy::StopOnDone && success) - || (m_workflowPolicy == TaskItem::WorkflowPolicy::StopOnError && !success)) { + if ((m_workflowPolicy == WorkflowPolicy::StopOnDone && success) + || (m_workflowPolicy == WorkflowPolicy::StopOnError && !success)) { stop(); invokeEndHandler(success); return; @@ -314,7 +314,7 @@ void TaskContainer::childDone(bool success) return; } - if (m_executeMode == TaskItem::ExecuteMode::Sequential) + if (m_executeMode == ExecuteMode::Sequential) m_selectedChildren.at(m_currentIndex)->start(); } @@ -348,8 +348,8 @@ void TaskContainer::resetSuccessBit() if (m_selectedChildren.isEmpty()) m_successBit = true; - if (m_workflowPolicy == TaskItem::WorkflowPolicy::StopOnDone - || m_workflowPolicy == TaskItem::WorkflowPolicy::ContinueOnDone) { + if (m_workflowPolicy == WorkflowPolicy::StopOnDone + || m_workflowPolicy == WorkflowPolicy::ContinueOnDone) { m_successBit = false; } else { m_successBit = true; @@ -358,10 +358,10 @@ void TaskContainer::resetSuccessBit() void TaskContainer::updateSuccessBit(bool success) { - if (m_workflowPolicy == TaskItem::WorkflowPolicy::Optional) + if (m_workflowPolicy == WorkflowPolicy::Optional) return; - if (m_workflowPolicy == TaskItem::WorkflowPolicy::StopOnDone - || m_workflowPolicy == TaskItem::WorkflowPolicy::ContinueOnDone) { + if (m_workflowPolicy == WorkflowPolicy::StopOnDone + || m_workflowPolicy == WorkflowPolicy::ContinueOnDone) { m_successBit = m_successBit || success; } else { m_successBit = m_successBit && success; diff --git a/src/libs/utils/tasktree.h b/src/libs/utils/tasktree.h index f313d53d4de..19bbad4043a 100644 --- a/src/libs/utils/tasktree.h +++ b/src/libs/utils/tasktree.h @@ -23,6 +23,27 @@ signals: 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 { ContinueAll, @@ -68,27 +89,6 @@ public: 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; } WorkflowPolicy workflowPolicy() const { return m_workflowPolicy; } TaskHandler taskHandler() const { return m_taskHandler; } @@ -136,22 +136,16 @@ public: Group(std::initializer_list children) { addChildren(children); } }; -class QTCREATOR_UTILS_EXPORT ExecuteInSequence : public TaskItem +class QTCREATOR_UTILS_EXPORT Execute : public TaskItem { 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: - ExecuteInParallel() : TaskItem(ExecuteMode::Parallel) {} -}; - -class QTCREATOR_UTILS_EXPORT WorkflowPolicy : public TaskItem -{ -public: - WorkflowPolicy(TaskItem::WorkflowPolicy policy) : TaskItem(policy) {} + Workflow(WorkflowPolicy policy) : TaskItem(policy) {} }; class QTCREATOR_UTILS_EXPORT OnGroupSetup : public TaskItem @@ -178,14 +172,13 @@ public: DynamicSetup(const GroupSetupHandler &handler) : TaskItem({{}, {}, {}, handler}) {} }; - -QTCREATOR_UTILS_EXPORT extern ExecuteInSequence sequential; -QTCREATOR_UTILS_EXPORT extern ExecuteInParallel parallel; -QTCREATOR_UTILS_EXPORT extern WorkflowPolicy stopOnError; -QTCREATOR_UTILS_EXPORT extern WorkflowPolicy continueOnError; -QTCREATOR_UTILS_EXPORT extern WorkflowPolicy stopOnDone; -QTCREATOR_UTILS_EXPORT extern WorkflowPolicy continueOnDone; -QTCREATOR_UTILS_EXPORT extern WorkflowPolicy optional; +QTCREATOR_UTILS_EXPORT extern Execute sequential; +QTCREATOR_UTILS_EXPORT extern Execute parallel; +QTCREATOR_UTILS_EXPORT extern Workflow stopOnError; +QTCREATOR_UTILS_EXPORT extern Workflow continueOnError; +QTCREATOR_UTILS_EXPORT extern Workflow stopOnDone; +QTCREATOR_UTILS_EXPORT extern Workflow continueOnDone; +QTCREATOR_UTILS_EXPORT extern Workflow optional; template class TaskAdapter : public TaskInterface diff --git a/tests/auto/utils/tasktree/tst_tasktree.cpp b/tests/auto/utils/tasktree/tst_tasktree.cpp index 11324841f3e..f25eb3c7ec3 100644 --- a/tests/auto/utils/tasktree/tst_tasktree.cpp +++ b/tests/auto/utils/tasktree/tst_tasktree.cpp @@ -322,7 +322,7 @@ void tst_TaskTree::processTree_data() QTest::newRow("SequentialError") << sequentialErrorRoot << sequentialErrorLog << true << false << 5; - const auto constructSimpleSequence = [=](const WorkflowPolicy &policy) { + const auto constructSimpleSequence = [=](const Workflow &policy) { return Group { policy, Process(std::bind(setupProcess, _1, 1), readResult),