state indicator: simple forever-loop via statewait subprocess
This commit is contained in:
parent
de835e9e6e
commit
1aa1455f33
|
|
@ -61,6 +61,12 @@ void Ollie9pClient::setActiveSessionId(const QString &id)
|
||||||
m_agentId = "0";
|
m_agentId = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read initial state immediately (state, not statewait)
|
||||||
|
QByteArray stateOut = run9p({"read", agentPath() + "/state"});
|
||||||
|
QString stateStr = QString::fromUtf8(stateOut).trimmed();
|
||||||
|
if (!stateStr.isEmpty())
|
||||||
|
m_activeState = stateStr;
|
||||||
|
|
||||||
emit activeSessionIdChanged();
|
emit activeSessionIdChanged();
|
||||||
emit activeStateChanged();
|
emit activeStateChanged();
|
||||||
|
|
||||||
|
|
@ -195,25 +201,17 @@ void Ollie9pClient::onChatReadyRead()
|
||||||
|
|
||||||
void Ollie9pClient::onStateReadyRead()
|
void Ollie9pClient::onStateReadyRead()
|
||||||
{
|
{
|
||||||
|
// statewait returns the state string on stdout. Parse it and update.
|
||||||
QByteArray data = m_stateProc->readAllStandardOutput();
|
QByteArray data = m_stateProc->readAllStandardOutput();
|
||||||
QString state = QString::fromUtf8(data).trimmed();
|
QString state = QString::fromUtf8(data).trimmed();
|
||||||
if (!state.isEmpty()) {
|
if (!state.isEmpty()) {
|
||||||
// statewait returns one line per state change; take the last one
|
m_activeState = state;
|
||||||
QStringList lines = state.split('\n', Qt::SkipEmptyParts);
|
emit activeStateChanged();
|
||||||
if (!lines.isEmpty()) {
|
|
||||||
m_activeState = lines.last().trimmed();
|
|
||||||
emit activeStateChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// statewait exits after one read — restart it for continuous monitoring
|
|
||||||
m_stateProc->deleteLater();
|
|
||||||
m_stateProc = nullptr;
|
|
||||||
startStateStream();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ollie9pClient::onChatFinished(int, QProcess::ExitStatus)
|
void Ollie9pClient::onChatFinished(int, QProcess::ExitStatus)
|
||||||
{
|
{
|
||||||
// Chat stream ended — session was killed or connection lost
|
|
||||||
m_chatProc->deleteLater();
|
m_chatProc->deleteLater();
|
||||||
m_chatProc = nullptr;
|
m_chatProc = nullptr;
|
||||||
emit streamingDone();
|
emit streamingDone();
|
||||||
|
|
@ -221,11 +219,9 @@ void Ollie9pClient::onChatFinished(int, QProcess::ExitStatus)
|
||||||
|
|
||||||
void Ollie9pClient::onStateFinished(int, QProcess::ExitStatus)
|
void Ollie9pClient::onStateFinished(int, QProcess::ExitStatus)
|
||||||
{
|
{
|
||||||
// State process exited unexpectedly (not via onStateReadyRead restart)
|
m_stateProc->deleteLater();
|
||||||
if (m_stateProc) {
|
m_stateProc = nullptr;
|
||||||
m_stateProc->deleteLater();
|
startStateStream();
|
||||||
m_stateProc = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Helpers ---
|
// --- Helpers ---
|
||||||
|
|
|
||||||
Reference in New Issue