Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::QueryController< T, Q > Class Template Reference

UI-owned adapter coordinating a fixed provider session and one long-lived Model. Operations require the creating UI thread and a live tree context, outside frames. Release/close before WidgetTree. Criteria and token owners are worker-safe; controller is not. Model data revisions are projection revisions; source provenance is exposed separately. More...

#include <model_query.hpp>

Public Member Functions

 ~QueryController ()
 Close on UI without joining workers; retained frames and rows stay immutable.
std::expected< QueryRequest< T, Q >, TreeError > submit (Query< T, Q > query)
 Submit explicit provider work; supersedes the previous generation after reservation succeeds.
std::expected< ModelFrame< T >, TreeError > pin () const
 Pin the existing model; query queue acceptance may still be awaiting application.
std::expected< ModelConsumer< T >, TreeError > openRange ()
 Open an unchanged low-level model interval consumer.
std::expected< void, TreeError > retryPublication ()
 Retry retained notification and detect exact projection application; UI-only. Call after dispatch and on WOULD_BLOCK/NO_MEMORY recovery; acceptance still needs a later dispatch.
std::expected< std::shared_ptr< const QuerySnapshot< T > >, TreeError > snapshot ()
 Inspect provenance of the model's currently applied projection.
std::expected< std::optional< QueryError >, TreeError > lastQueryError () const
 Inspect latest typed provider evaluation failure.
std::expected< std::optional< TreeError >, TreeError > lastError () const
 Inspect notification failure first, then existing model UI application failure.
std::expected< void, TreeError > close ()
 Idempotent UI closure; workers retain source/criteria but receive stop requests.

Static Public Member Functions

static std::expected< std::unique_ptr< QueryController >, TreeError > create (WidgetTree &tree, Node< Widget > context, std::shared_ptr< const ModelSnapshot< T > > source, std::unique_ptr< QueryProvider< T, Q > > provider, QueryOptions options={}, ModelOptions modelOptions={})
 Create an unqueried source projection and existing bounded scheduler endpoints.

Detailed Description

template<class T, class Q>
class portals::QueryController< T, Q >

UI-owned adapter coordinating a fixed provider session and one long-lived Model. Operations require the creating UI thread and a live tree context, outside frames. Release/close before WidgetTree. Criteria and token owners are worker-safe; controller is not. Model data revisions are projection revisions; source provenance is exposed separately.

Template Parameters
TImmutable domain row satisfying the snapshot ownership contract.
QOwning immutable domain criteria supporting destruction on any releasing thread.

Member Function Documentation

◆ close()

template<class T, class Q>
std::expected< void, TreeError > portals::QueryController< T, Q >::close ( )
inline

Idempotent UI closure; workers retain source/criteria but receive stop requests.

Returns
Success after disconnect, or WRONG_THREAD leaving ownership unchanged.

◆ create()

template<class T, class Q>
std::expected< std::unique_ptr< QueryController >, TreeError > portals::QueryController< T, Q >::create ( WidgetTree & tree,
Node< Widget > context,
std::shared_ptr< const ModelSnapshot< T > > source,
std::unique_ptr< QueryProvider< T, Q > > provider,
QueryOptions options = {},
ModelOptions modelOptions = {} )
inlinestatic

Create an unqueried source projection and existing bounded scheduler endpoints.

Parameters
treeUI tree which must outlive this controller.
contextLive owner node for all completion/publication endpoints.
sourceInitial immutable source pin, non-null; its values are initially presented unchanged.
providerNon-null owned provider, destroyed on UI after close.
optionsPositive finite query limits, captured into each token.
modelOptionsExisting model interval/consumer/work limits, unchanged by query limits.
Returns
UI controller, tree/thread/frame error, INVALID_ARGUMENT, IDENTITY_EXHAUSTED, or NO_MEMORY.

◆ lastError()

template<class T, class Q>
std::expected< std::optional< TreeError >, TreeError > portals::QueryController< T, Q >::lastError ( ) const
inline

Inspect notification failure first, then existing model UI application failure.

Returns
Sticky original failure, an empty optional, or UI/thread/tree error.

◆ lastQueryError()

template<class T, class Q>
std::expected< std::optional< QueryError >, TreeError > portals::QueryController< T, Q >::lastQueryError ( ) const
inline

Inspect latest typed provider evaluation failure.

Returns
Optional typed query error, or original UI/thread/tree error.

◆ openRange()

template<class T, class Q>
std::expected< ModelConsumer< T >, TreeError > portals::QueryController< T, Q >::openRange ( )
inline

Open an unchanged low-level model interval consumer.

Returns
Consumer owned independently of query generations, or original model/tree error.

◆ pin()

template<class T, class Q>
std::expected< ModelFrame< T >, TreeError > portals::QueryController< T, Q >::pin ( ) const
inline

Pin the existing model; query queue acceptance may still be awaiting application.

Returns
Immutable frame or UI/thread/tree/closed error.

◆ retryPublication()

template<class T, class Q>
std::expected< void, TreeError > portals::QueryController< T, Q >::retryPublication ( )
inline

Retry retained notification and detect exact projection application; UI-only. Call after dispatch and on WOULD_BLOCK/NO_MEMORY recovery; acceptance still needs a later dispatch.

Returns
Success for accepted/observed notification, or original tree/model/scheduler error.

◆ snapshot()

template<class T, class Q>
std::expected< std::shared_ptr< const QuerySnapshot< T > >, TreeError > portals::QueryController< T, Q >::snapshot ( )
inline

Inspect provenance of the model's currently applied projection.

Returns
Exact applied immutable wrapper, or original UI/thread/tree error.

◆ submit()

template<class T, class Q>
std::expected< QueryRequest< T, Q >, TreeError > portals::QueryController< T, Q >::submit ( Query< T, Q > query)
inline

Submit explicit provider work; supersedes the previous generation after reservation succeeds.

Parameters
queryOwning criteria, exact source pin and bounded page; older source revisions are rejected.
Returns
Worker token, tree/thread/frame error, INVALID_ARGUMENT, WOULD_BLOCK, NO_MEMORY, IDENTITY_EXHAUSTED, CALLBACK_FAILED if provider start throws, or CLOSED if provider start closes/cancels this token or synchronously submits a newer generation. Context removal returns its original tree error and cancels this token.

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