morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::client::Source Class Referenceabstract

An AppSource that also hands the shell what it mounts screens with, once it delivered a bundle. More...

#include <source.hpp>

Inheritance diagram for morph::client::Source:
morph::ui::AppSource morph::client::LocalSource morph::client::RemoteSource

Classes

struct  Transport
 What a concrete source opens with: the bridge's backend and the exchange the UI service is reached by. More...

Public Member Functions

ui::Dispatcher & dispatcher ()
 Where the screens' model calls go.
ui::Catalog catalog () const
 The catalog facts the screens load with.
std::vector< std::string > screens () const
 The screens the principal may open, in catalog order: each catalog entry that is available or public and whose document the bundle holds.
bool isPublic (std::string_view screenId) const
 Whether the catalog marks screenId public: a screen served before sign-in, such as a login screen.
void open (ui::AppContext &context, std::function< void(std::expected< ui::Bundle, ui::ConnectError >)> ready) final
 Opens the source: the transport, the bridge and the bundle, verified.
void switchBackend (ui::Backend backend, std::function< void(std::expected< void, std::string >)> done) final
 Refused: a switch between backends is the hosting layer's (spec 6 §9).
void close () final
 Drops a ready not yet delivered and releases the bridge, the transport and the bundle.
void signIn (std::string principal, std::string token, std::function< void(bool)> done)
 Installs a sign-in (spec 6 §5): a session built from the current one with principal and token replaced, carried by every later model call and UI-service request, then the catalog reloaded for it.
void signOut (std::function< void(bool)> done)
 Ends the session: back to the principal before any sign-in, with no token, and the catalog reloaded for it.
std::function< std::shared_ptr< ui::Document const >(std::string_view)> documents (std::function< void(ui::Refusal const &)> onRefused={})
 The lookup a DocumentScreenHost takes (DocumentScreenHostOptions::documents), over the loaded bundle: each screen the source lists, loaded against the current catalog facts the first time it is asked for after a load, so a shell of an application's own mounts with the same source.
ui::Bundle const * bundle () const noexcept
 The bundle the catalog currently lists.
ui::CatalogReply const * catalogReply () const noexcept
 The catalog for the current principal: its entries, what the principal may run, and the facts.
ui::SchemasByModel const & schemasByModel () const noexcept
 The schemas document of every model the catalog names, by model type, or why it did not arrive: what the explorer lists each model's actions from.
std::string const & principal () const noexcept
 The principal the source's session carries now.
std::optional< ui::FileTransfer > files () const
 The file side channel (files/1) over the source's exchange, carrying its session: what a screen's upload and download move bytes through.
void poll (std::function< void(std::vector< std::string > changed)> changed)
 One step of development reload (spec 5 §12): sends ui-hello, and when the manifest digest changed, fetches the changed bundle and the catalog for it. Nothing is sent while a poll is still in flight.
void onConnected (std::function< void()> const &listener) final
 Adds a listener called on the owner after each successful connect, the first included. On a reconnect the source first sends ui-hello again, so the new connection negotiates events, then calls the listeners.
void onEvent (std::function< void(wire::EventBody const &)> listener)
 Adds a listener for the events the server sends: what a shell hands to Session::deliverEvent.
ui::Watcher watcher ()
 What the session's SessionOptions::watcher sends the cache's watch changes through: watcherOver the source's exchange, stamping the session current at each send. Empty for a source whose transport carries no server events, such as an in-process one.
virtual std::string signedOutPrincipal () const
 The principal before any sign-in, which signOut returns to.
Public Member Functions inherited from morph::ui::AppSource
 AppSource (AppSource const &)=delete
AppSource & operator= (AppSource const &)=delete
 AppSource (AppSource &&)=delete
AppSource & operator= (AppSource &&)=delete
virtual void open (AppContext &context, std::function< void(std::expected< Bundle, ConnectError >)> ready)=0
 Connects (or, local, sets up the models), signs the user in natively if the application needs it, and delivers the bundle.

Protected Member Functions

virtual std::expected< Transport, ui::ConnectError > connect (ui::AppContext &context)=0
 Makes the transport on context.
virtual std::chrono::milliseconds openTimeout () const
 How long open waits for the bundle before it reports the source unreachable; zero waits forever.
virtual void disconnect ()
 Releases what connect made beside the backend; called by close, after the bridge is gone.
virtual void fetchSchemas (std::string const &modelType, std::function< void(std::expected< std::string, std::string >)> done)
 Fetches the {actionType: schema} document of one model type, which a form, collection or wizard node is built from. The default sends a schemas envelope over the source's exchange.
session::Context & requestSession () noexcept
 The session every request carries, for a source to fill before open sends anything.

Detailed Description

An AppSource that also hands the shell what it mounts screens with, once it delivered a bundle.

Opened, it holds a bridge over its backend, owned by the context's executor, and the verified bundle with its catalog. Everything it hands out is valid from a successful ready until close.

Definition at line 72 of file source.hpp.

Member Function Documentation

◆ dispatcher()

ui::Dispatcher & morph::client::Source::dispatcher ( )
nodiscard

Where the screens' model calls go.

Returns
The dispatcher over the source's bridge.
Exceptions
std::logic_errorbefore a bundle was delivered.

◆ catalog()

ui::Catalog morph::client::Source::catalog ( ) const
nodiscard

The catalog facts the screens load with.

Returns
The facts of the catalog reply; empty before a bundle was delivered.

◆ screens()

std::vector< std::string > morph::client::Source::screens ( ) const
nodiscard

The screens the principal may open, in catalog order: each catalog entry that is available or public and whose document the bundle holds.

Returns
Their ids.

◆ isPublic()

bool morph::client::Source::isPublic ( std::string_view screenId) const
nodiscard

Whether the catalog marks screenId public: a screen served before sign-in, such as a login screen.

Parameters
screenIdThe screen.
Returns
Whether it is listed and public.

◆ open()

void morph::client::Source::open ( ui::AppContext & context,
std::function< void(std::expected< ui::Bundle, ui::ConnectError >)> ready )
final

Opens the source: the transport, the bridge and the bundle, verified.

Parameters
contextThe running frontend's context.
readyCalled once, on the owner, unless close comes first.

◆ switchBackend()

void morph::client::Source::switchBackend ( ui::Backend backend,
std::function< void(std::expected< void, std::string >)> done )
finalvirtual

Refused: a switch between backends is the hosting layer's (spec 6 §9).

Parameters
backendIgnored.
doneCalled with the refusal.

Implements morph::ui::AppSource.

◆ close()

void morph::client::Source::close ( )
finalvirtual

Drops a ready not yet delivered and releases the bridge, the transport and the bundle.

Implements morph::ui::AppSource.

◆ signIn()

void morph::client::Source::signIn ( std::string principal,
std::string token,
std::function< void(bool)> done )

Installs a sign-in (spec 6 §5): a session built from the current one with principal and token replaced, carried by every later model call and UI-service request, then the catalog reloaded for it.

Parameters
principalThe principal the sign-in mutation answered.
tokenThe session token it answered; empty when the source's server needs none, as in process.
doneCalled once, on the owner, once the catalog for the new session is current, with whether it loaded; not called after close.

◆ signOut()

void morph::client::Source::signOut ( std::function< void(bool)> done)

Ends the session: back to the principal before any sign-in, with no token, and the catalog reloaded for it.

Parameters
doneAs signIn's.

◆ documents()

std::function< std::shared_ptr< ui::Document const >(std::string_view)> morph::client::Source::documents ( std::function< void(ui::Refusal const &)> onRefused = {})
nodiscard

The lookup a DocumentScreenHost takes (DocumentScreenHostOptions::documents), over the loaded bundle: each screen the source lists, loaded against the current catalog facts the first time it is asked for after a load, so a shell of an application's own mounts with the same source.

Parameters
onRefusedCalled with each document that does not load; may be empty.
Returns
The lookup, valid while the source lives; it answers null for a screen the source does not list or whose document does not load.

◆ bundle()

ui::Bundle const * morph::client::Source::bundle ( ) const
inlinenodiscardnoexcept

The bundle the catalog currently lists.

Returns
It; null before a bundle was delivered.

Definition at line 130 of file source.hpp.

◆ catalogReply()

ui::CatalogReply const * morph::client::Source::catalogReply ( ) const
inlinenodiscardnoexcept

The catalog for the current principal: its entries, what the principal may run, and the facts.

Returns
It; null before a bundle was delivered.

Definition at line 134 of file source.hpp.

◆ schemasByModel()

ui::SchemasByModel const & morph::client::Source::schemasByModel ( ) const
inlinenodiscardnoexcept

The schemas document of every model the catalog names, by model type, or why it did not arrive: what the explorer lists each model's actions from.

Returns
Them; empty before a bundle was delivered.

Definition at line 141 of file source.hpp.

◆ principal()

std::string const & morph::client::Source::principal ( ) const
inlinenodiscardnoexcept

The principal the source's session carries now.

Returns
It; empty for none.

Definition at line 145 of file source.hpp.

◆ files()

std::optional< ui::FileTransfer > morph::client::Source::files ( ) const
nodiscard

The file side channel (files/1) over the source's exchange, carrying its session: what a screen's upload and download move bytes through.

Returns
It, or nothing before the source is open.

◆ poll()

void morph::client::Source::poll ( std::function< void(std::vector< std::string > changed)> changed)

One step of development reload (spec 5 §12): sends ui-hello, and when the manifest digest changed, fetches the changed bundle and the catalog for it. Nothing is sent while a poll is still in flight.

Parameters
changedCalled on the owner once the changed bundle is current, with the ids of the documents it changed; not called for an unchanged digest, a failed poll, or after close.

◆ onConnected()

void morph::client::Source::onConnected ( std::function< void()> const & listener)
finalvirtual

Adds a listener called on the owner after each successful connect, the first included. On a reconnect the source first sends ui-hello again, so the new connection negotiates events, then calls the listeners.

Parameters
listenerCalled on the owner; it must stay callable while the source is open.

Reimplemented from morph::ui::AppSource.

◆ onEvent()

void morph::client::Source::onEvent ( std::function< void(wire::EventBody const &)> listener)

Adds a listener for the events the server sends: what a shell hands to Session::deliverEvent.

Parameters
listenerCalled on the owner, once per event, in the order they arrived.

◆ watcher()

ui::Watcher morph::client::Source::watcher ( )
nodiscard

What the session's SessionOptions::watcher sends the cache's watch changes through: watcherOver the source's exchange, stamping the session current at each send. Empty for a source whose transport carries no server events, such as an in-process one.

Returns
The watcher, or empty.

◆ signedOutPrincipal()

virtual std::string morph::client::Source::signedOutPrincipal ( ) const
inlinenodiscardvirtual

The principal before any sign-in, which signOut returns to.

Returns
It; empty for none.

Reimplemented in morph::client::LocalSource.

Definition at line 176 of file source.hpp.

◆ connect()

virtual std::expected< Transport, ui::ConnectError > morph::client::Source::connect ( ui::AppContext & context)
nodiscardprotectedpure virtual

Makes the transport on context.

Parameters
contextThe running frontend's context.
Returns
The transport, or why there is none.

Implemented in morph::client::LocalSource, and morph::client::RemoteSource.

◆ openTimeout()

virtual std::chrono::milliseconds morph::client::Source::openTimeout ( ) const
inlinenodiscardprotectedvirtual

How long open waits for the bundle before it reports the source unreachable; zero waits forever.

Returns
The bound.

Reimplemented in morph::client::RemoteSource.

Definition at line 197 of file source.hpp.

◆ disconnect()

virtual void morph::client::Source::disconnect ( )
inlineprotectedvirtual

Releases what connect made beside the backend; called by close, after the bridge is gone.

Reimplemented in morph::client::LocalSource.

Definition at line 200 of file source.hpp.

◆ fetchSchemas()

virtual void morph::client::Source::fetchSchemas ( std::string const & modelType,
std::function< void(std::expected< std::string, std::string >)> done )
protectedvirtual

Fetches the {actionType: schema} document of one model type, which a form, collection or wizard node is built from. The default sends a schemas envelope over the source's exchange.

Parameters
modelTypeThe model type id.
doneCalled once with the document's JSON text, or why there is none.

Reimplemented in morph::client::LocalSource.

◆ requestSession()

session::Context & morph::client::Source::requestSession ( )
inlinenodiscardprotectednoexcept

The session every request carries, for a source to fill before open sends anything.

Returns
It.

Definition at line 211 of file source.hpp.


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