MCPcopy Create free account
hub / github.com/MITK/MITK / OnSessionExpired

Method OnSessionExpired

Modules/PythonSegmentationUI/src/QmitknnInteractiveToolGUI.cpp:1196–1237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1194}
1195
1196void QmitknnInteractiveToolGUI::OnSessionExpired()
1197{
1198 // The tool emits SessionExpiredEvent from two places (the heartbeat and a
1199 // mid-interaction failure). Handle only the first one: otherwise a second
1200 // event arriving before the deferred teardown below runs would stack a second
1201 // identical dialog. The flag is cleared in OnSessionEnded, so a later genuine
1202 // expiry of a new session still fires.
1203 if (m_SessionExpiredHandled)
1204 return;
1205
1206 m_SessionExpiredHandled = true;
1207
1208 // Stop beating immediately so a second timeout cannot queue another
1209 // teardown/dialog before the deferred AbortSession below runs. (OnSessionEnded
1210 // also stops the timer once the session is actually torn down.)
1211 m_HeartbeatTimer->stop();
1212
1213 // A remote session was lost. Tear it down on the next event-loop tick rather
1214 // than now: when this fires from within an interactor's event handling (a
1215 // connection loss detected mid-interaction), disabling/resetting interactors
1216 // inline is unsafe; deferring is also harmless when it fires from the
1217 // heartbeat timer (a proactive expiry). AbortSession() ends the session,
1218 // clears all prompts and the preview, and -- via SessionEndedEvent ->
1219 // OnSessionEnded -- reverts the widget to its pre-init state, so the user just
1220 // clicks Initialize to reconnect.
1221 QTimer::singleShot(0, this, [this]() {
1222 if (QCoreApplication::closingDown())
1223 return;
1224
1225 if (auto* tool = this->GetTool())
1226 tool->AbortSession();
1227
1228 const auto message = QString(
1229 "<h3 %1>Remote session ended</h3>"
1230 "<p %1>The connection to the nnInteractive server was lost or the session "
1231 "expired (idle timeout, server restart, or the server is at capacity).</p>"
1232 "<p %1>Your interactions were cleared. Click <em>Initialize</em> to start a "
1233 "new session.</p>").arg(LINE_HEIGHT_STYLE);
1234
1235 QMessageBox::warning(nullptr, "nnInteractive", message);
1236 });
1237}
1238
1239void QmitknnInteractiveToolGUI::ApplyCapabilityGating()
1240{

Callers

nothing calls this directly

Calls 4

GetToolMethod · 0.95
AbortSessionMethod · 0.80
QStringClass · 0.50
stopMethod · 0.45

Tested by

no test coverage detected