-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_manager.hpp
More file actions
63 lines (51 loc) · 1.52 KB
/
Copy pathprocess_manager.hpp
File metadata and controls
63 lines (51 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include "droidcli_core.h"
#include <map>
#include <mutex>
namespace droidcli::cli {
// droidcli-infra (ARCHITECTURE.md's Modules diagram) - the OS-execution
// boundary droidcli-runtime launches/stops processes through and gets
// PID/liveness back from.
//
// Tracks external processes launched for launched_process connectors. Each
// process is keyed by a logical id (the connector id) so the host can launch,
// query (PID + running state), and stop it. Centralised so droidcli always
// knows the PID of every process it controls.
struct ProcessInfo {
core::String key;
core::String label;
core::String command;
core::String working_dir;
int64_t pid = 0;
bool running = false;
core::String status_text = "idle";
};
class ProcessManager {
public:
~ProcessManager();
// Launch `command` in `working_dir` under `key`, replacing (stopping) any prior
// process registered under the same key. Returns false + sets `error_out` on failure.
bool launch(
const core::String& key,
const core::String& label,
const core::String& working_dir,
const core::String& command,
core::String& error_out);
bool stop(const core::String& key, core::String& error_out);
core::Array<ProcessInfo> snapshot();
private:
struct Entry {
ProcessInfo info;
#ifdef _WIN32
void* job_handle = nullptr;
void* process_handle = nullptr;
#else
int pgid = 0;
#endif
};
void stop_locked(Entry& entry);
void refresh_locked(Entry& entry);
std::map<core::String, Entry> entries_;
std::mutex mutex_;
};
} // namespace droidcli::cli