Something went wrong. Try again.
The agentic engineering control plane for the posthuman future
Something went wrong. Try again.
2.5 kB · 104 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105// PaneTable.cpp — see PaneTable.h for the policy notes.#include "PaneTable.h"
PaneTable::PaneTable(QObject* parent) : QObject(parent) {}
PaneTable::~PaneTable(){ const auto panes = m_panes; m_panes.clear(); for (auto* pane : std::as_const(panes)) { pane->pty.reset(); // Pty::close() runs via unique_ptr delete pane; }}
PaneTable::Pane* PaneTable::adopt(const SpawnSpec& spec, std::unique_ptr<Pty> pty){ auto* pane = new Pane; pane->paneId = spec.paneId; pane->pty = std::move(pty); pane->cwd = spec.cwd; pane->command = spec.command; pane->args = spec.args; pane->title = spec.title; pane->restart = spec.restart; pane->restartArgv = spec.restartArgv; pane->exited = false; m_panes.insert(spec.paneId, pane); return pane;}
PaneTable::Pane* PaneTable::find(const QString& paneId, bool liveOnly){ auto* pane = m_panes.value(paneId, nullptr); if (pane == nullptr || (liveOnly && pane->exited)) { return nullptr; } return pane;}
const PaneTable::Pane* PaneTable::find(const QString& paneId, bool liveOnly) const{ const auto* pane = m_panes.value(paneId, nullptr); if (pane == nullptr || (liveOnly && pane->exited)) { return nullptr; } return pane;}
bool PaneTable::contains(const QString& paneId) const{ return m_panes.contains(paneId);}
void PaneTable::markExited(const QString& paneId, int code){ auto* pane = m_panes.value(paneId, nullptr); if (pane == nullptr || pane->exited) { return; } pane->exited = true; pane->exitCode = code; pane->exitTimerValid = true; pane->exitTimer.start();}
int PaneTable::reclaimExpired(){ int reclaimed = 0; QStringList expired; for (auto it = m_panes.cbegin(); it != m_panes.cend(); ++it) { const Pane* pane = it.value(); if (!pane->exited) { continue; // live panes are retained indefinitely } if (pane->restart) { continue; // retained for the app's restart scan } if (pane->exitTimerValid && pane->exitTimer.elapsed() < kReclaimGraceMs) { continue; // inside the grace window } expired.append(it.key()); } for (const QString& id : expired) { killPane(id); ++reclaimed; emit paneReclaimed(id); } return reclaimed;}
void PaneTable::killPane(const QString& paneId){ auto* pane = m_panes.take(paneId); if (pane == nullptr) { return; } if (pane->pty != nullptr) { pane->pty->close(); // kills and reaps the child } delete pane;}