combiner.md

This commit is contained in:
JohannesItten
2026-07-09 15:49:35 +03:00
parent d2095d14d3
commit 3820d0eeb7
3 changed files with 167 additions and 7 deletions
+12 -1
View File
@@ -38,7 +38,9 @@ struct NodeProcess {
class StudioManager {
public:
StudioManager(fs::path bin_dir, std::string domain)
: bin_dir_(std::move(bin_dir)), domain_(std::move(domain)) {}
: bin_dir_(std::move(bin_dir))
, domain_(std::move(domain))
, save_path_(bin_dir_ / "last_graph.json") {}
~StudioManager() { shutdown(); }
@@ -53,6 +55,7 @@ public:
garbage_collect_locked();
try {
graph_ = parse_graph(graph_json);
save_graph_locked(graph_json);
start_all_locked();
} catch (const std::exception& e) {
err = e.what();
@@ -140,6 +143,7 @@ public:
private:
fs::path bin_dir_;
std::string domain_;
fs::path save_path_;
FlowGraph graph_;
std::vector<NodeProcess> processes_;
std::mutex mutex_;
@@ -235,6 +239,13 @@ private:
if (changed) notify(s);
}
void save_graph_locked(const nlohmann::json& j) {
std::ofstream f(save_path_);
if (f) f << j.dump(2);
else fprintf(stderr, "[studio-manager] warning: could not save graph to %s\n",
save_path_.c_str());
}
// ── static helpers ───────────────────────────────────────────────────────
static FlowGraph parse_graph(const nlohmann::json& j) {
+17 -6
View File
@@ -28,12 +28,23 @@ int main(int argc, char* argv[]) {
dmf::StudioManager manager(bin_dir, domain);
if (argc > 1) {
auto r = manager.load_graph_file(argv[1]);
if (r.value("type", "") == "error") {
fprintf(stderr, "[studio-manager] %s\n",
r.value("message", "load failed").c_str());
return 1;
{
bool clean = false;
const char* explicit_path = nullptr;
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "--clean") clean = true;
else explicit_path = argv[i];
}
fs::path load_path = explicit_path ? fs::path(explicit_path) : bin_dir / "last_graph.json";
if (!clean && fs::exists(load_path)) {
fprintf(stderr, "[studio-manager] restoring graph from %s\n", load_path.c_str());
auto r = manager.load_graph_file(load_path.string());
if (r.value("type", "") == "error") {
fprintf(stderr, "[studio-manager] %s\n",
r.value("message", "load failed").c_str());
if (explicit_path) return 1; // explicit path failure is fatal; auto-restore is not
}
}
}