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 <map>
5#include <mutex>
6#include <string>
7#include <thread>
8#include <vector>
9
10#include "absl/status/status.h"
11
12namespace yaze::editor {
13
15 public:
16 struct Snapshot {
17 bool started = false;
18 bool running = false;
19 bool finished = false;
20 bool cancel_requested = false;
21 bool can_cancel = false;
22 int exit_code = -1;
23 std::string command;
24 std::string directory;
25 std::string output;
26 std::string output_tail;
27 absl::Status status = absl::UnknownError("Task not started");
28 };
29
32
35
36 // Overrides affect only the child. An empty value replaces any inherited
37 // value with an empty string.
38 absl::Status Start(
39 const std::string& command, const std::string& directory,
40 const std::map<std::string, std::string>& environment = {});
41 void Cancel();
42 Snapshot GetSnapshot() const;
43 absl::Status Wait();
44
45 private:
46 void WorkerMain(std::string command, std::string directory,
47 std::vector<std::string> environment);
48#ifdef _WIN32
49 void WorkerMainWindows(std::string command, std::string directory,
50 std::vector<std::string> environment);
51#endif
52 void AppendOutput(const char* data, size_t size);
53 void Finalize(absl::Status status, int exit_code);
54 void JoinIfNeeded();
55
56 static std::string ComputeOutputTail(const std::string& output);
57
58 mutable std::mutex mutex_;
59 std::thread worker_;
60 bool started_ = false;
61 bool running_ = false;
62 bool finished_ = false;
63 bool cancel_requested_ = false;
64 int exit_code_ = -1;
65 int child_pid_ = -1;
66 std::string command_;
67 std::string directory_;
68 std::string output_;
69 std::string output_tail_;
70 absl::Status status_ = absl::UnknownError("Task not started");
71};
72
73} // namespace yaze::editor
74
75#endif // YAZE_APP_EDITOR_SYSTEM_BACKGROUND_COMMAND_TASK_H_
void Finalize(absl::Status status, int exit_code)
BackgroundCommandTask & operator=(const BackgroundCommandTask &)=delete
BackgroundCommandTask(const BackgroundCommandTask &)=delete
absl::Status Start(const std::string &command, const std::string &directory, const std::map< std::string, std::string > &environment={})
void WorkerMain(std::string command, std::string directory, std::vector< std::string > environment)
static std::string ComputeOutputTail(const std::string &output)
void AppendOutput(const char *data, size_t size)
Editors are the view controllers for the application.