#define TASK_H_
#include <string>
+#include <vector>
#include <sigc++/signal.h>
-#include <msp/fs/path.h>
+#include <msp/time/timedelta.h>
+#include <msp/time/timestamp.h>
+#include "libbuilder_api.h"
+
+class FileTarget;
/**
Tasks are used to manage other programs and worker threads involved in the
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
+class LIBBUILDER_API Task
{
public:
enum Status
sigc::signal<void, bool> signal_finished;
protected:
- std::vector<Msp::FS::Path> files;
+ std::vector<const FileTarget *> targets;
bool unlink = false;
+ Msp::Time::TimeStamp start_time;
+ Msp::Time::TimeDelta duration;
Task() = default;
public:
virtual ~Task() { }
- /** Associate the task with a file. */
- void add_file(const Msp::FS::Path &);
+ /** Associate the task with a target. */
+ void add_target(const FileTarget &);
/** If set to true, the associated files are removed before the task is
started. */
void set_unlink(bool = true);
+ const std::vector<const FileTarget *> &get_targets() const { return targets; }
+
/** Returns the command being executed for this task. Only makes sense if
an external command is involved. */
virtual std::string get_command() const = 0;
/// Ensures that the output directory exists and removes files if necessary.
void prepare();
+ void finished(bool);
+
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;
+
+ /** Returns the amount of time completing the task took. Only available
+ after the task has finished. */
+ const Msp::Time::TimeDelta &get_duration() const { return duration; }
};
#endif