]> git.tdb.fi Git - builder.git/blob - source/task.h
Refactor transitive dependencies to work on all targets
[builder.git] / source / task.h
1 #ifndef TASK_H_
2 #define TASK_H_
3
4 #include <string>
5 #include <sigc++/signal.h>
6 #include <msp/fs/path.h>
7
8 /**
9 Tasks are used to manage other programs and worker threads involved in the
10 build process.  They are run asynchronously by default, but a wait() method is
11 provided should it be necessary to wait for a task to finish.
12 */
13 class Task
14 {
15 public:
16         enum Status
17         {
18                 RUNNING,
19                 SUCCESS,
20                 ERROR
21         };
22
23         sigc::signal<void, bool> signal_finished;
24
25         std::list<Msp::FS::Path> files;
26         bool unlink;
27
28 protected:
29         Task();
30 public:
31         virtual ~Task() { }
32
33         /** Associate the task with a file. */
34         void add_file(const Msp::FS::Path &);
35
36         /** If set to true, the associated files are removed before the task is
37         started. */
38         void set_unlink(bool = true);
39
40         /** Returns the command being executed for this task.  Only makes sense if
41         an external command is involved. */
42         virtual std::string get_command() const = 0;
43
44         /// Starts the task.
45         virtual void start() = 0;
46
47 protected:
48         /// Ensures that the output directory exists and removes files if necessary.
49         void prepare();
50
51 public:
52         /// Checks the status of the task and immediately returns.
53         virtual Status check() = 0;
54
55         /// Waits for the task to finish and returns its final status.
56         virtual Status wait() = 0;
57 };
58
59 #endif