Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::Application Class Reference

One UI owner for scheduler, tree, routing and a single terminal run. All calls/destruction except requestStop require the creating thread. Scene owns typed nodes and bindings; release them before this object. Terminal I/O never runs inside layout/paint. No automatic recovery follows uncertain output. Run is single-use, including failed/closed sessions. More...

#include <application.hpp>

Public Member Functions

 ~Application ()
 Finish an active session, then release routing/tree before the scheduler. Destroy on the UI owner thread. An active session's borrowed scene, observer and terminal must remain alive through this call; a completed session retains no borrowed scene callbacks.
 Application (const Application &)=delete
Application & operator= (const Application &)=delete
Scheduler & scheduler () noexcept
WidgetTree & tree () noexcept
EventRouter & router () noexcept
Node< Widget > root () const noexcept
SchedulerTime now () const noexcept
WidthPolicy widthPolicy () const noexcept
BackgroundExecutor * background () noexcept
void requestStop () noexcept
 Worker-safe while this owner lives; wakes scheduler and cancels terminal waits.
std::expected< void, ApplicationError > start (ApplicationScene &scene, ApplicationReadyTerminal &terminal, std::stop_token stop={})
 Start the single permitted ready-only session, without waiting or running a frame.
std::expected< ApplicationStep, ApplicationError > step ()
 Service one bounded input/dispatch/render/output cycle without waiting. Uses existing input/scheduler/preparation budgets and at most one frame and one flush. User callbacks and ready transport operations must themselves return in bounded time. EOF preserves run's cutoff: it drains admitted input/output, without waiting for a frame deadline.
ApplicationStats stats () const noexcept
std::expected< ApplicationStats, ApplicationError > run (ApplicationScene &scene, std::stop_token stop={})
 Open standard input/output and restore them before returning. Requires the default steady clock; an injected clock returns INVALID_OPTIONS before opening. EOF finishes decoding, delivers admitted CONTROL and flushes submitted output. It does not wait for future frame deadlines or promise a final repaint of accepted changes.
std::expected< ApplicationStats, ApplicationError > run (ApplicationScene &scene, ApplicationTerminal &terminal, std::stop_token stop={})
 Run against a borrowed custom terminal; always close before returning once accepted. EOF has the same cutoff as the native overload: no final repaint or frame-cap exception. Finite replay must leave time before EOF when it needs a final visible frame.

Static Public Member Functions

static std::expected< std::unique_ptr< Application >, ApplicationError > create (ApplicationOptions options={}, SchedulerClock clock={})

Detailed Description

One UI owner for scheduler, tree, routing and a single terminal run. All calls/destruction except requestStop require the creating thread. Scene owns typed nodes and bindings; release them before this object. Terminal I/O never runs inside layout/paint. No automatic recovery follows uncertain output. Run is single-use, including failed/closed sessions.

Member Function Documentation

◆ background()

BackgroundExecutor * portals::Application::background ( )
noexcept
Returns
Borrowed executor for this session, or null when no background service was requested. UI-only. Never own or join the returned executor in a scene or callback. A borrowed host executor outlives cleanup; a default executor is available only during a synchronous run.

◆ create()

std::expected< std::unique_ptr< Application >, ApplicationError > portals::Application::create ( ApplicationOptions options = {},
SchedulerClock clock = {} )
static
Parameters
optionsPositive finite policies, copied into the owner.
clockBorrowed monotonic millisecond service; null reader uses steady_clock.
Returns
UI owner or explicit options/component/allocation error. Caller argument allocations are outside this boundary; arbitrary noexcept user constructors cannot be made recoverable.

◆ now()

SchedulerTime portals::Application::now ( ) const
noexcept
Returns
Current monotonic logical milliseconds; injected clock must not move backwards.

◆ root()

Node< Widget > portals::Application::root ( ) const
noexcept
Returns
Checked root observer valid until the tree closes.

◆ router()

EventRouter & portals::Application::router ( )
noexcept
Returns
Borrowed UI event router.

◆ run() [1/2]

std::expected< ApplicationStats, ApplicationError > portals::Application::run ( ApplicationScene & scene,
ApplicationTerminal & terminal,
std::stop_token stop = {} )

Run against a borrowed custom terminal; always close before returning once accepted. EOF has the same cutoff as the native overload: no final repaint or frame-cap exception. Finite replay must leave time before EOF when it needs a final visible frame.

Parameters
sceneBorrowed scene which must outlive this call.
terminalExclusive transport borrowed through cleanup; no ownership transfer.
stopOptional caller cancellation signal.
Returns
Owning totals or detailed first failure and separate restoration error. The caller has already opened this terminal: default background startup occurs before scene callbacks, not before that external open. Final owned join follows the terminal close attempt.

◆ run() [2/2]

std::expected< ApplicationStats, ApplicationError > portals::Application::run ( ApplicationScene & scene,
std::stop_token stop = {} )

Open standard input/output and restore them before returning. Requires the default steady clock; an injected clock returns INVALID_OPTIONS before opening. EOF finishes decoding, delivers admitted CONTROL and flushes submitted output. It does not wait for future frame deadlines or promise a final repaint of accepted changes.

Parameters
sceneBorrowed scene which must outlive this call.
stopOptional caller cancellation signal.
Returns
Owning totals or detailed first failure and separate restoration error. Opt-in background workers start before native terminal open. After stop, coroutine retirement and terminal close attempt, a final explicit join may wait for cooperative user work.

◆ scheduler()

Scheduler & portals::Application::scheduler ( )
noexcept
Returns
Borrowed UI scheduler; publishers may retain its closed channel state.

◆ start()

std::expected< void, ApplicationError > portals::Application::start ( ApplicationScene & scene,
ApplicationReadyTerminal & terminal,
std::stop_token stop = {} )

Start the single permitted ready-only session, without waiting or running a frame.

Parameters
sceneBorrowed scene which must outlive session cleanup, including destructor cleanup.
terminalExclusive bounded transport borrowed through cleanup; no ownership transfer.
stopCaller cancellation signal sampled at start and each step; retained safely until cleanup.
Returns
Success, or the first start failure after cleanup once start was accepted. Wrong-thread, reentrant and repeated starts reject without changing the active session.

◆ stats()

ApplicationStats portals::Application::stats ( ) const
noexcept
Returns
Owning cumulative totals; call only on the UI owner thread outside concurrent operations.

◆ step()

std::expected< ApplicationStep, ApplicationError > portals::Application::step ( )

Service one bounded input/dispatch/render/output cycle without waiting. Uses existing input/scheduler/preparation budgets and at most one frame and one flush. User callbacks and ready transport operations must themselves return in bounded time. EOF preserves run's cutoff: it drains admitted input/output, without waiting for a frame deadline.

Returns
Owning cumulative progress and completion, or the retained first failure after cleanup. NOT_STARTED, WRONG_THREAD and REENTRANT_OPERATION reject without stopping a session.

◆ tree()

WidgetTree & portals::Application::tree ( )
noexcept
Returns
Borrowed UI tree; observing handles do not extend its lifetime.

◆ widthPolicy()

WidthPolicy portals::Application::widthPolicy ( ) const
noexcept
Returns
Shared width policy for text created by the scene.

The documentation for this class was generated from the following file: