Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
progress_parser.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2#pragma once
3
4#include <functional>
5#include <string>
6#include <string_view>
7
8namespace pulp::platform {
9
12 std::string type;
13 std::string payload;
14};
15
29public:
30 using Callback = std::function<void(const ProgressEvent&)>;
31
32 explicit ProgressParser(Callback cb) : callback_(std::move(cb)) {}
33
36 void feed_line(std::string_view line) {
37 if (!line.starts_with("PROGRESS:")) return;
38 auto rest = line.substr(9); // after "PROGRESS:"
39 auto colon = rest.find(':');
40 if (colon == std::string_view::npos) {
41 // PROGRESS:TYPE (no payload)
42 if (callback_) callback_({std::string(rest), {}});
43 } else {
44 // PROGRESS:TYPE:PAYLOAD
45 if (callback_) callback_({
46 std::string(rest.substr(0, colon)),
47 std::string(rest.substr(colon + 1))
48 });
49 }
50 }
51
52private:
53 Callback callback_;
54};
55
56} // namespace pulp::platform
ProgressParser(Callback cb)
Definition progress_parser.hpp:32
std::function< void(const ProgressEvent &)> Callback
Definition progress_parser.hpp:30
void feed_line(std::string_view line)
Feed a line of output.
Definition progress_parser.hpp:36
Device capability vocabulary: one tier ladder, one thermal ladder, and the projection from observed i...
Definition child_process.hpp:15
STL namespace.
A structured progress event parsed from a PROGRESS:TYPE:PAYLOAD line.
Definition progress_parser.hpp:11
std::string payload
Everything after PROGRESS:TYPE:
Definition progress_parser.hpp:13
std::string type
e.g., "DOWNLOAD_START", "OVERALL", "ERROR"
Definition progress_parser.hpp:12