+++ /dev/null
-#include <msp/strings/utils.h>
-#include "chainedtask.h"
-
-using namespace std;
-using namespace Msp;
-
-ChainedTask::ChainedTask(Task *t):
- current(0),
- final_status(RUNNING)
-{
- add_task(t);
-}
-
-ChainedTask::~ChainedTask()
-{
- for(Task *t: tasks)
- delete t;
-}
-
-void ChainedTask::add_task(Task *t)
-{
- tasks.push_back(t);
-}
-
-string ChainedTask::get_command() const
-{
- string cmd;
- for(Task *t: tasks)
- append(cmd, "\n", t->get_command());
- return cmd;
-}
-
-void ChainedTask::start()
-{
- prepare();
-
- current = 0;
- tasks[current]->start();
-}
-
-Task::Status ChainedTask::check()
-{
- while(current<tasks.size() && !process(tasks[current]->check())) ;
-
- return final_status;
-}
-
-Task::Status ChainedTask::wait()
-{
- while(current<tasks.size() && !process(tasks[current]->wait())) ;
-
- return final_status;
-}
-
-bool ChainedTask::process(Status sub_status)
-{
- if(sub_status==SUCCESS && current+1<tasks.size())
- {
- // The task succeeded and there's more to run
- ++current;
- tasks[current]->start();
- return true;
- }
-
- if(sub_status!=RUNNING)
- {
- // The task is not running anymore and either failed or was the last one
- current = tasks.size();
- final_status = sub_status;
- }
-
- return false;
-}