diff options
| author | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-10-09 14:12:35 +0200 |
| commit | ffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch) | |
| tree | 1269efa852935b183daae4bb33a58d1b4d2ffb53 /widgets/JttyMmttyHandoff.hpp | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'widgets/JttyMmttyHandoff.hpp')
| -rw-r--r-- | widgets/JttyMmttyHandoff.hpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/widgets/JttyMmttyHandoff.hpp b/widgets/JttyMmttyHandoff.hpp new file mode 100644 index 00000000..9969674c --- /dev/null +++ b/widgets/JttyMmttyHandoff.hpp @@ -0,0 +1,78 @@ +// -*- Mode: C++ -*- +#ifndef JTTY_MMTTY_HANDOFF_HPP +#define JTTY_MMTTY_HANDOFF_HPP + +#include <QVector> +#include <QtGlobal> + +namespace Jtty +{ + class MmttyHandoff + { + public: + enum class SubmitAction + { + Reject, + Submit, + StopThenSubmit + }; + + explicit MmttyHandoff (int timeoutMs = 10000) + : timeoutMs_ {timeoutMs} + { + } + + int timeoutMs () const noexcept {return timeoutMs_;} + bool active () const noexcept {return waitingForStop_;} + bool empty () const noexcept {return requestIds_.isEmpty ();} + QVector<qint64> const& requestIds () const noexcept {return requestIds_;} + + static SubmitAction planSubmission (bool valid, bool jttySessionActive, + bool backendBusy) noexcept + { + if (!valid) return SubmitAction::Reject; + if (!jttySessionActive && backendBusy) { + return SubmitAction::StopThenSubmit; + } + return SubmitAction::Submit; + } + + bool queue (qint64 requestId) + { + if (requestIds_.size () >= 64) return false; + requestIds_.append (requestId); + return true; + } + void waitForStop () noexcept {waitingForStop_ = true;} + + bool stopCompleted () noexcept + { + if (!waitingForStop_) return false; + waitingForStop_ = false; + return true; + } + + QVector<qint64> expire () + { + auto const ids = requestIds_; + reset (); + return ids; + } + + void submitted (qint64 requestId) {requestIds_.removeOne (requestId);} + void abort () {reset ();} + + private: + void reset () + { + requestIds_.clear (); + waitingForStop_ = false; + } + + int timeoutMs_; + QVector<qint64> requestIds_; + bool waitingForStop_ {false}; + }; +} + +#endif |
