yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
background_command_task.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SYSTEM_BACKGROUND_COMMAND_TASK_H_
2#define YAZE_APP_EDITOR_SYSTEM_BACKGROUND_COMMAND_TASK_H_
3
4#include <mutex>
5#include <string>
6#include <thread>
7
8#include "absl/status/status.h"
9
10namespace yaze::editor {
11
13 public:
14 struct Snapshot {
15 bool started = false;
16 bool running = false;
17 bool finished = false;
18 bool cancel_requested = false;
19 bool can_cancel = false;
20 int exit_code = -1;
21 std::string command;
22 std::string directory;
23 std::string output;
24 std::string output_tail;
25 absl::Status status = absl::UnknownError("Task not started");
26 };
27
30
33
34 absl::Status Start(const std::string& command, const std::string& directory);
35 void Cancel();
36 Snapshot GetSnapshot() const;
37 absl::Status Wait();
38
39 private:
40 void WorkerMain(std::string command, std::string directory);
41 void AppendOutput(const char* data, size_t size);
42 void Finalize(absl::Status status, int exit_code);
43 void JoinIfNeeded();
44
45 static std::string ComputeOutputTail(const std::string& output);
46
47 mutable std::mutex mutex_;
48 std::thread worker_;
49 bool started_ = false;
50 bool running_ = false;
51 bool finished_ = false;
52 bool cancel_requested_ = false;
53 int exit_code_ = -1;
54 int child_pid_ = -1;
55 std::string command_;
56 std::string directory_;
57 std::string output_;
58 std::string output_tail_;
59 absl::Status status_ = absl::UnknownError("Task not started");
60};
61
62} // namespace yaze::editor
63
64#endif // YAZE_APP_EDITOR_SYSTEM_BACKGROUND_COMMAND_TASK_H_
void Finalize(absl::Status status, int exit_code)
void WorkerMain(std::string command, std::string directory)
BackgroundCommandTask & operator=(const BackgroundCommandTask &)=delete
BackgroundCommandTask(const BackgroundCommandTask &)=delete
static std::string ComputeOutputTail(const std::string &output)
absl::Status Start(const std::string &command, const std::string &directory)
void AppendOutput(const char *data, size_t size)
Editors are the view controllers for the application.