blob: 2027faff83eb43dbb8d9992057d7a1ecee0560e5 [file] [log] [blame]
Patrick Venturecf9b2192019-06-27 12:09:52 -07001#pragma once
2
3#include <cstdint>
4
5namespace host_tool
6{
7
8class ProgressInterface
9{
10 public:
11 virtual ~ProgressInterface() = default;
12
13 /** Update the progress by X bytes. This will inform any listening
14 * interfaces (just write to stdout mostly), and tick off as time passed.
15 */
16 virtual void updateProgress(std::int64_t bytes) = 0;
17 virtual void start(std::int64_t bytes) = 0;
William A. Kennington III0d5bb782021-01-19 15:50:42 -080018 virtual void finish() = 0;
19 virtual void abort() = 0;
Patrick Venturecf9b2192019-06-27 12:09:52 -070020};
21
22/**
23 * @brief A progress indicator that writes to stdout. It deliberately
24 * overwrites the same line when it's used, so it's advised to not interject
25 * other non-error messages.
26 */
27class ProgressStdoutIndicator : public ProgressInterface
28{
29 public:
30 ProgressStdoutIndicator() = default;
31
32 void updateProgress(std::int64_t bytes) override;
33 void start(std::int64_t bytes) override;
William A. Kennington III0d5bb782021-01-19 15:50:42 -080034 void finish() override;
35 void abort() override;
Patrick Venturecf9b2192019-06-27 12:09:52 -070036
37 private:
38 std::int64_t totalBytes = 0;
39 std::int64_t currentBytes = 0;
40};
41
42} // namespace host_tool