]> git.tdb.fi Git - builder.git/blobdiff - source/lib/task.h
Report timings of the build
[builder.git] / source / lib / task.h
index b0f56f470399446d7339b1508300c2f0fd89e59f..e493e3b188e99efaef18a81db22b266b3820d0f9 100644 (file)
@@ -2,10 +2,14 @@
 #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
@@ -24,20 +28,24 @@ public:
        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;
@@ -49,12 +57,18 @@ protected:
        /// 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