X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftask.h;h=915ffe12a9e774f27adc9caede2736b59779492e;hb=d1f9551e05c9d341149eb490e05b1465d3d6b711;hp=1f59473fd14f135da7933d18993f4936458e2e1c;hpb=0368a9c1972ff5fd6cd8984901ff0bdbd86afc9f;p=builder.git diff --git a/source/task.h b/source/task.h index 1f59473..915ffe1 100644 --- a/source/task.h +++ b/source/task.h @@ -3,10 +3,12 @@ #include #include +#include /** Tasks are used to manage other programs and worker threads involved in the -build process. They are run asynchronously. +build process. They are run asynchronously by default, but a wait() method is +provided should it be necessary to wait for a task to finish. */ class Task { @@ -21,13 +23,37 @@ public: sigc::signal signal_finished; protected: - Task() { } + std::vector files; + bool unlink = false; + + Task() = default; public: virtual ~Task() { } + /** Associate the task with a file. */ + void add_file(const Msp::FS::Path &); + + /** If set to true, the associated files are removed before the task is + started. */ + void set_unlink(bool = true); + + /** Returns the command being executed for this task. Only makes sense if + an external command is involved. */ virtual std::string get_command() const = 0; + + /// Starts the task. virtual void start() = 0; + +protected: + /// Ensures that the output directory exists and removes files if necessary. + void prepare(); + +public: + /// Checks the status of the task and immediately returns. virtual Status check() = 0; + + /// Waits for the task to finish and returns its final status. + virtual Status wait() = 0; }; #endif