Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
progress_info.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2022, 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
9
10#ifndef __UTILS_PROGRESS_INFO_H__
11#define __UTILS_PROGRESS_INFO_H__
12
13#include <atomic>
14#include <mutex>
15#include <string>
16#include <utility>
17
18#include "utils/debug.h"
19
25
32{
33
34public:
35 enum Status
36 {
37 PENDING_START,
38 PENDING_CANCELLATION,
39 RUNNING,
40 COMPLETED,
41 };
42
43 enum CompletionType
44 {
45 CANCELLED,
46 HAS_WARNING,
47 HAS_ERROR,
48 SUCCESS,
49 };
50
51 Status get_status () const { return status_; };
52
53 CompletionType get_completion_type () const
54 {
55 z_return_val_if_fail (status_ == COMPLETED, HAS_ERROR);
56 return completion_type_;
57 }
58
63
67 void mark_completed (CompletionType type, const utils::Utf8String &msg);
68
72 utils::Utf8String get_message () const { return completion_str_; }
73
77 std::tuple<double, utils::Utf8String> get_progress ()
78 {
79 std::scoped_lock guard (m_);
80
81 return std::make_tuple (progress_, progress_str_);
82 }
83
87 void update_progress (double progress, const utils::Utf8String &msg);
88
89 bool pending_cancellation () const
90 {
91 return status_ == PENDING_CANCELLATION;
92 };
93
94private:
96 double progress_{};
97
99 Status status_{};
100
102 CompletionType completion_type_{};
103
106 utils::Utf8String completion_str_;
107
110 utils::Utf8String progress_str_;
111
114 // utils::Utf8String label_done_str;
115
117 std::mutex m_;
118};
119
123
124#endif
Generic progress info.
std::tuple< double, utils::Utf8String > get_progress()
To be called by the task caller.
void mark_completed(CompletionType type, const utils::Utf8String &msg)
To be called by the task itself.
void request_cancellation()
To be called by the task caller.
utils::Utf8String get_message() const
Returns a newly allocated string.
void update_progress(double progress, const utils::Utf8String &msg)
To be called by the task itself.
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38